[NeoStats-Devel] [Commits] r2701 - in trunk: . modules/limitserv

[email protected] Fri, 12 Aug 2005 23:03:13 +1000
Newsgroups gmane.comp.neostats.devel
Message-ID <[email protected]>
Author: Fish
Date: Fri Aug 12 21:03:07 2005
New Revision: 2701

Modified:
   trunk/TODO
   trunk/modules/limitserv/help.c
   trunk/modules/limitserv/limitserv.h
   trunk/modules/limitserv/main.c
Log:
fix up limitserv to have a buffer (for large channels)

Modified: trunk/TODO
==============================================================================
--- trunk/TODO	(original)
+++ trunk/TODO	Fri Aug 12 21:03:07 2005
@@ -5,6 +5,5 @@
 
 
 LIMITSERV: doesn't join channels correctly on add etc.
-QUOTESERV: hangs when loading a database. 
 SecureServ: version scans default to disabled.
 SecureServ: Version scans are fubar.

Modified: trunk/modules/limitserv/help.c
==============================================================================
--- trunk/modules/limitserv/help.c	(original)
+++ trunk/modules/limitserv/help.c	Fri Aug 12 21:03:07 2005
@@ -59,3 +59,9 @@
 	"Whether to join channels managed by limitserv",
 	NULL
 };
+
+const char *help_set_limitbuffer[] = {
+	"\2LIMITBUFFER <number>\2",
+	"Sets the number of extra user slots allocated when adjusting the limit",
+	NULL
+};

Modified: trunk/modules/limitserv/limitserv.h
==============================================================================
--- trunk/modules/limitserv/limitserv.h	(original)
+++ trunk/modules/limitserv/limitserv.h	Fri Aug 12 21:03:07 2005
@@ -28,3 +28,4 @@
 extern const char *help_list[];
 
 extern const char *help_set_join[];
+extern const char *help_set_limitbuffer[];

Modified: trunk/modules/limitserv/main.c
==============================================================================
--- trunk/modules/limitserv/main.c	(original)
+++ trunk/modules/limitserv/main.c	Fri Aug 12 21:03:07 2005
@@ -29,6 +29,7 @@
 }ls_channel;
 
 int joinchannels = 0;
+int limitbuffer = 1;
 
 /** Bot command function prototypes */
 static int cmd_add( CmdParams *cmdparams );
@@ -41,6 +42,7 @@
 
 /** Setting callback prototypes */
 static int set_join_cb( CmdParams* cmdparams, SET_REASON reason );
+static int set_limitbuffer_cb( CmdParams* cmdparams, SET_REASON reason );
 
 
 /** hash to store ls_channel and bot info */
@@ -82,7 +84,8 @@
 /** Bot setting table */
 static bot_setting ls_settings[]=
 {
-	{"JOIN",	&joinchannels,	SET_TYPE_BOOLEAN,	0, 0, 		NS_ULEVEL_ADMIN, NULL,	help_set_join,	set_join_cb,	( void* )0	},
+	{"JOIN",		&joinchannels,	SET_TYPE_BOOLEAN,	0, 0, 		NS_ULEVEL_ADMIN, NULL,	help_set_join,	set_join_cb,	( void* )0	},
+	{"LIMITBUFFER", 	&limitbuffer, 	SET_TYPE_INT,	0, 100,		NS_ULEVEL_ADMIN, NULL,	help_set_limitbuffer, set_limitbuffer_cb, (void *)1	},
 	{NULL,		NULL,			0,					0, 0, 		0,				 NULL,	NULL,			NULL	},
 };
 
@@ -121,13 +124,18 @@
 	static char limitsize[10];
 	int limit;
 
-	limit = curlimit;
+	if (curlimit > 0) {
+		limit = curlimit;
+	} else {
+		limit = users;
+	}
 	if( add )
-		limit++;
+		limit = users + limitbuffer;
 	else
-		limit--;
+		limit = users - limitbuffer;
+
 	if( limit <= users )
-		limit = ( users + 1 );
+		limit = ( users + limitbuffer );
 	ircsnprintf( limitsize, 10, "%d", limit );	
 	irc_cmode( ls_bot, name, "+l", limitsize );
 }
@@ -143,24 +151,24 @@
 
 static void JoinChannels( void )
 {
-	ls_channel *db;
-	hnode_t *hn;
-	hscan_t hs;
-
-	hash_scan_begin( &hs, qshash );
-	while( ( hn = hash_scan_next( &hs ) ) != NULL ) 
-	{
-		Channel *c;
-
-		db =( ( ls_channel * )hnode_get( hn ) );
-		c = FindChannel( db->name );
-		if( c )
-		{
-			if( joinchannels )
-				irc_join (ls_bot, db->name, "+o");
-			ManageLimit( db->name, c->users, 0, 1 );
-		}
-	}
+       ls_channel *db;
+       hnode_t *hn;
+       hscan_t hs;
+
+       hash_scan_begin( &hs, qshash );
+       while( ( hn = hash_scan_next( &hs ) ) != NULL ) 
+       {
+               Channel *c;
+
+               db =( ( ls_channel * )hnode_get( hn ) );
+               c = FindChannel( db->name );
+               if( c )
+               {
+                       if( joinchannels )
+                               irc_join (ls_bot, db->name, "+o");
+                       ManageLimit( db->name, c->users, 0, 1 );
+               }
+       }
 }
 
 /** @brief PartChannels
@@ -446,3 +454,25 @@
 	}
 	return NS_SUCCESS;
 }
+
+static int set_limitbuffer_cb( CmdParams* cmdparams, SET_REASON reason )
+{
+	ls_channel *db;
+	hnode_t *hn;
+	hscan_t hs;
+
+	SET_SEGV_LOCATION();
+	if( reason == SET_CHANGE )
+	{
+		hash_scan_begin( &hs, qshash );
+		while( ( hn = hash_scan_next( &hs ) ) != NULL ) 
+		{
+			Channel *c;
+			db =( ( ls_channel * )hnode_get( hn ) );
+			c = FindChannel( db->name );
+			if( c )
+				ManageLimit( db->name, c->users, cmdparams->channel->limit, 1 );
+		}
+	}
+	return NS_SUCCESS;
+}