cvs: embed /php-irssi channel.c server.c /php-irssi/examples autoop.php

[email protected] ("Wez Furlong") Tue, 01 Apr 2003 15:00:48 -0000
Newsgroups php.embed.cvs
Message-ID <cvswez1049209248@cvsserver>
wez		Tue Apr  1 10:00:48 2003 EDT

  Modified files:              
    /embed/php-irssi	channel.c server.c 
    /embed/php-irssi/examples	autoop.php 
  Log:
  Fix $channel->nicks so that it actually works.
  Enhance auto-op script to perform auto-opping when ops is received and not only
  when new clients connect.
  
  
  
Index: embed/php-irssi/channel.c
diff -u embed/php-irssi/channel.c:1.8 embed/php-irssi/channel.c:1.9
--- embed/php-irssi/channel.c:1.8	Tue Apr  1 07:28:04 2003
+++ embed/php-irssi/channel.c	Tue Apr  1 10:00:47 2003
@@ -14,7 +14,7 @@
   +----------------------------------------------------------------------+
   | Author: Wez Furlong <[email protected]>                                    |
   +----------------------------------------------------------------------+
-  $Id: channel.c,v 1.8 2003/04/01 12:28:04 wez Exp $
+  $Id: channel.c,v 1.9 2003/04/01 15:00:47 wez Exp $
 */
 #include "php-irssi.h"
 #define PHP_IRSSI_PROTOS_ONLY
@@ -66,10 +66,17 @@
 	PHP_IRSSI_CHANNEL_REC_PROP_READER_HEAD();
 
 	if (strcmp(member, "nicks") == 0) {
-		GSList *list;
+		GSList *list, *the_list;
+		zval *tmp;
 
 		list = nicklist_getnicks(channel);
-		php_irssi_export_GList(*retval, list, PIAT_NICK);
+
+		array_init(*retval);
+		for (the_list = list; the_list != NULL; the_list = the_list->next) {
+			MAKE_STD_ZVAL(tmp);
+			php_irssi_export_NICK(tmp, channel, the_list->data TSRMLS_CC);
+			add_next_index_zval(*retval, tmp);
+		}
 		g_slist_free(list);
 
 		return SUCCESS;
Index: embed/php-irssi/server.c
diff -u embed/php-irssi/server.c:1.7 embed/php-irssi/server.c:1.8
--- embed/php-irssi/server.c:1.7	Tue Apr  1 07:28:04 2003
+++ embed/php-irssi/server.c	Tue Apr  1 10:00:47 2003
@@ -14,7 +14,7 @@
   +----------------------------------------------------------------------+
   | Author: Wez Furlong <[email protected]>                                    |
   +----------------------------------------------------------------------+
-  $Id: server.c,v 1.7 2003/04/01 12:28:04 wez Exp $
+  $Id: server.c,v 1.8 2003/04/01 15:00:47 wez Exp $
 */
 
 #include "php-irssi.h"
@@ -64,7 +64,6 @@
 
 	PHP_IRSSI_SERVER_REC_PROP_READER_FOOT();
 }
-
 
 PHP_FUNCTION(server_privmsg)
 {
Index: embed/php-irssi/examples/autoop.php
diff -u embed/php-irssi/examples/autoop.php:1.1 embed/php-irssi/examples/autoop.php:1.2
--- embed/php-irssi/examples/autoop.php:1.1	Tue Apr  1 08:45:34 2003
+++ embed/php-irssi/examples/autoop.php	Tue Apr  1 10:00:47 2003
@@ -1,5 +1,5 @@
 <?php
-/* $Id: autoop.php,v 1.1 2003/04/01 13:45:34 wez Exp $
+/* $Id: autoop.php,v 1.2 2003/04/01 15:00:47 wez Exp $
  *
  * Autoop.
  *
@@ -40,27 +40,34 @@
 		irssi_settings_set_str('autoop_oplist', base64_encode(serialize($AutoOpList)));
 	}
 
-	function handle_massjoin(/* CHANNEL */ $channel, /* array of NICK */ $nicks)
+	function get_autoop_masks($channame)
 	{
 		global $AutoOpList;
-
+		
 		$masks = array();
-
-		if (!$channel->chanop) {
-			/* can't give ops if we don't have it :) */
-			return;
-		}
-
-		if (isset($AutoOpList[$channel->name])) {
-			$masks[] = implode(' ', $AutoOpList[$channel->name]);
+		if (isset($AutoOpList[$channame])) {
+			$masks[] = implode(' ', $AutoOpList[$channame]);
 		}
 		if (isset($AutoOpList['*'])) {
 			$masks[] = implode(' ', $AutoOpList['*']);
 		}
 
 		$masks = implode(' ', $masks);
+
+		return $masks;
+	}
+
+	function handle_massjoin(/* CHANNEL */ $channel, /* array of NICK */ $nicks)
+	{
+
+		if (!$channel->chanop) {
+			/* can't give ops if we don't have it :) */
+			return;
+		}
+
 		$server = $channel->server;
 		$to_op = array();
+		$masks = AutoOp::get_autoop_masks($channel->name);
 		
 		foreach ($nicks as $nick) {
 			if ($server->masks_match($masks, $nick->nick, $nick->host)) {
@@ -73,11 +80,46 @@
 		}
 	}
 
+	function handle_mode(/* SERVER */ $server, $commandstr, $sourcenick, $sourceaddr)
+	{
+		list($channame, $modestr, $nicks) = explode(' ', $commandstr, 3);
+		
+		/* get the correct channel object */
+		$channels = $server->channels;
+		foreach ($channels as $channel) {
+			if ($channels->name == $channame) {
+				break;
+			}
+		}
+
+		if (!$channel->chanop) {
+			/* can't give ops if we don't have it */
+			return;
+		}
+
+		$masks = AutoOp::get_autoop_masks($channame);
+		$to_op = array();
+		
+		/* op everyone that is not an op and who is on the op-list */
+		$nicks = $channel->nicks;
+		foreach ($nicks as $nick) {
+			if (!$nick->op && $server->masks_match($masks, $nick->nick, $nick->host)) {
+				$to_op[] = $nick->nick;
+			}
+		}
+
+		if (count($to_op)) {
+			$channel->command('op ' . implode(' ', $to_op));
+		}
+		
+	}
+
 }
 
 irssi_settings_add_str('autoop', 'autoop_oplist', '');
 irssi_command_bind('autoop', array('AutoOp', 'cmd_autoop'));
 irssi_signal_add('massjoin', array('AutoOp', 'handle_massjoin'), IRSSI_SIGNAL_PRIORITY_LOW);
+irssi_signal_add('event mode', array('AutoOp', 'handle_mode'), IRSSI_SIGNAL_PRIORITY_LOW);
 
 /* keyed by channel */
 $GLOBALS['AutoOpList'] = irssi_settings_get_str('autoop_oplist');