[NeoStats-Devel] [Commits] r2772 - in trunk: include modules/extauth modules/hostserv modules/limitserv modules/protocol modules/quoteserv modules/statserv modules/textserv src

[email protected] Thu, 25 Aug 2005 06:23:08 +1000
Newsgroups gmane.comp.neostats.devel
Message-ID <[email protected]>
Author: Mark
Date: Thu Aug 25 04:23:01 2005
New Revision: 2772

Modified:
   trunk/include/hash.h
   trunk/include/neostats.h
   trunk/modules/extauth/extauth.c
   trunk/modules/hostserv/hostserv.c
   trunk/modules/limitserv/main.c
   trunk/modules/protocol/asuka.c
   trunk/modules/protocol/ircup10.c
   trunk/modules/protocol/ircup10base.c
   trunk/modules/protocol/nefarious.c
   trunk/modules/protocol/unreal32.c
   trunk/modules/quoteserv/main.c
   trunk/modules/statserv/server.c
   trunk/modules/statserv/stats.c
   trunk/modules/textserv/main.c
   trunk/src/bans.c
   trunk/src/bots.c
   trunk/src/channels.c
   trunk/src/commands.c
   trunk/src/ctcp.c
   trunk/src/dcc.c
   trunk/src/exclude.c
   trunk/src/hash.c
   trunk/src/ircprotocol.c
   trunk/src/ircrecv.c
   trunk/src/log.c
   trunk/src/modules.c
   trunk/src/nsdba.c
   trunk/src/servers.c
   trunk/src/settings.c
   trunk/src/sock.c
   trunk/src/timer.c
   trunk/src/users.c
Log:
more comments and core tidy ups

Modified: trunk/include/hash.h
==============================================================================
--- trunk/include/hash.h	(original)
+++ trunk/include/hash.h	Thu Aug 25 04:23:01 2005
@@ -261,6 +261,8 @@
 EXPORTFUNC 	void hnode_create_insert (hash_t *, void *, const void *);
 EXPORTFUNC 	hnode_t *hnode_find (hash_t * hash, const void *key);
 
+EXPORTFUNC 	extern void hash_delete_destroy_node( hash_t *, hnode_t * );
+EXPORTFUNC 	extern void hash_scan_delete_destroy_node( hash_t *hash, hnode_t *node );
 
 #ifdef __cplusplus
 }

Modified: trunk/include/neostats.h
==============================================================================
--- trunk/include/neostats.h	(original)
+++ trunk/include/neostats.h	Thu Aug 25 04:23:01 2005
@@ -978,6 +978,10 @@
 	unsigned int modnum;
 	/** status flag for synch, error, etc */
 	unsigned int status;
+	/** moddata flags */
+	unsigned int userdatacnt;
+	unsigned int serverdatacnt;
+	unsigned int channeldatacnt;
 #ifdef USE_PERL
 	MOD_TYPE modtype;
 	struct PerlModInfo *pm;
@@ -1013,7 +1017,7 @@
 /* Get current run level module pointer */
 #define GET_CUR_MODULE() RunModule[RunLevel]
 /* Get current run level module index */
-#define GET_CUR_MODNUM() RunModule[RunLevel]->modnum
+#define GET_CUR_MODULE_INDEX() RunModule[RunLevel]->modnum
 /* Get current run level module name */
 #define GET_CUR_MODNAME() RunModule[RunLevel]->info->name
 /* Get current run level module version */

Modified: trunk/modules/extauth/extauth.c
==============================================================================
--- trunk/modules/extauth/extauth.c	(original)
+++ trunk/modules/extauth/extauth.c	Thu Aug 25 04:23:01 2005
@@ -194,9 +194,8 @@
 	node = hash_lookup( accesshash, cmdparams->av[1] );
 	if( node ) 
 	{
-		AccessEntry *access =( AccessEntry * )hnode_get( node );
-		hash_delete( accesshash, node );
-		hnode_destroy( node );
+		AccessEntry *access = ( AccessEntry * )hnode_get( node );
+		hash_delete_destroy_node( accesshash, node );
 		ns_free( access );
 		DBADelete( "AccessList", cmdparams->av[1] );
 		irc_prefmsg( NULL, cmdparams->source, "Deleted %s from access list", cmdparams->av[1] );
@@ -319,7 +318,7 @@
 	AccessEntry *access;
 
 	dlog( DEBUG2, "ModAuthUser for %s", u->name );
-	access =( AccessEntry *)hnode_find( accesshash, u->name );
+	access = ( AccessEntry *)hnode_find( accesshash, u->name );
 	if( access) 
 	{
 		ircsnprintf( hostmask, USERHOSTLEN, "%s@%s", u->user->username, u->user->hostname );

Modified: trunk/modules/hostserv/hostserv.c
==============================================================================
--- trunk/modules/hostserv/hostserv.c	(original)
+++ trunk/modules/hostserv/hostserv.c	Thu Aug 25 04:23:01 2005
@@ -493,9 +493,8 @@
 	SET_SEGV_LOCATION();
 	hash_scan_begin( &hs, banhash );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL ) {
-		ban =( ( banentry * )hnode_get( hn ) );
-		hash_delete( banhash, hn );
-		hnode_destroy( hn );
+		ban = ( ( banentry * )hnode_get( hn ) );
+		hash_scan_delete_destroy_node( banhash, hn );
 		ns_free( ban );
 	}
 	hash_destroy( banhash );
@@ -554,7 +553,7 @@
 	hash_scan_begin( &hs, banhash );
 	irc_prefmsg( hs_bot, cmdparams->source, "Banned vhosts" );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL ) {
-		ban =( ( banentry * )hnode_get( hn ) );
+		ban = ( ( banentry * )hnode_get( hn ) );
 		irc_prefmsg( hs_bot, cmdparams->source, "%d - %s added by %s for %s", i, ban->host, ban->who, ban->reason );
 		i++;
 	}
@@ -623,16 +622,15 @@
 		return NS_ERR_NEED_MORE_PARAMS;
 	hash_scan_begin( &hs, banhash );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL ) {
-		ban =( banentry * )hnode_get( hn );
+		ban = ( banentry * )hnode_get( hn );
 		if( ircstrcasecmp( ban->host, cmdparams->av[1] ) == 0 ) {
-			hash_scan_delete( banhash, hn );
 			irc_prefmsg( hs_bot, cmdparams->source, 
 				"Deleted %s from the banned vhost list", cmdparams->av[1] );
 			CommandReport( hs_bot, "%s deleted %s from the banned vhost list",
 				cmdparams->source->name, cmdparams->av[1] );
 			nlog( LOG_NOTICE, "%s deleted %s from the banned vhost list",
 				cmdparams->source->name, cmdparams->av[1] );
-			hnode_destroy( hn );
+			hash_scan_delete_destroy_node( banhash, hn );
 			DBADelete( "bans", ban->host );
 			ns_free( ban );
 			return NS_SUCCESS;
@@ -734,7 +732,7 @@
 	}
 	hash_scan_begin( &hs, banhash );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL ) {
-		ban =( banentry * ) hnode_get( hn );
+		ban = ( banentry * ) hnode_get( hn );
 		if( match( ban->host, cmdparams->av[2] ) ) {
 			irc_prefmsg( hs_bot, cmdparams->source, 
 				"%s has been matched against the vhost ban %s",
@@ -957,7 +955,7 @@
 		irc_prefmsg( hs_bot, cmdparams->source, "No vhost for user %s", cmdparams->av[0] );
 		return NS_SUCCESS;
 	}
-	vhe =( vhostentry * ) lnode_get( hn );
+	vhe = ( vhostentry * ) lnode_get( hn );
 	irc_prefmsg( hs_bot, cmdparams->source, "removed vhost %s for %s",
 		vhe->nick, vhe->vhost );
 	nlog( LOG_NOTICE, "%s removed the vhost %s for %s", 

Modified: trunk/modules/limitserv/main.c
==============================================================================
--- trunk/modules/limitserv/main.c	(original)
+++ trunk/modules/limitserv/main.c	Thu Aug 25 04:23:01 2005
@@ -151,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
@@ -189,7 +189,7 @@
 	hash_scan_begin( &hs, qshash );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL ) 
 	{
-		db =( ( ls_channel * )hnode_get( hn ) );
+		db = ( ( ls_channel * )hnode_get( hn ) );
 		if( FindChannel( db->name ) )
 			irc_part( ls_bot, db->name, NULL);
 	}
@@ -273,9 +273,8 @@
 	hash_scan_begin( &hs, qshash );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL )
 	{
-		db =( ( ls_channel * )hnode_get( hn ) );
-		hash_delete( qshash, hn );
-		hnode_destroy( hn );
+		db = ( ( ls_channel * )hnode_get( hn ) );
+		hash_delete_destroy_node( qshash, hn );
 		ns_free( db );
 	}
 	hash_destroy( qshash );
@@ -339,7 +338,7 @@
 	irc_prefmsg( ls_bot, cmdparams->source, "channels" );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL )
 	{
-		db =( ( ls_channel * )hnode_get( hn ) );
+		db = ( ( ls_channel * )hnode_get( hn ) );
 		irc_prefmsg( ls_bot, cmdparams->source, "%s", db->name );
 	}
 	irc_prefmsg( ls_bot, cmdparams->source, "End of list." );
@@ -366,17 +365,16 @@
 	hash_scan_begin( &hs, qshash );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL )
 	{
-		db =( ls_channel * )hnode_get( hn );
+		db = ( ls_channel * )hnode_get( hn );
 		if( ircstrcasecmp( db->name, cmdparams->av[0] ) == 0 )
 		{
-			hash_scan_delete( qshash, hn );
 			irc_prefmsg( ls_bot, cmdparams->source, 
 				"Deleted %s from the channel list", cmdparams->av[0] );
 			CommandReport( ls_bot, "%s deleted %s from the channel list",
 				cmdparams->source->name, cmdparams->av[0] );
 			nlog( LOG_NOTICE, "%s deleted %s from the channel list",
 				cmdparams->source->name, cmdparams->av[0] );
-			hnode_destroy( hn );
+			hash_scan_delete_destroy_node( qshash, hn );
 			DBADelete( "channels", db->name );
 			ns_free( db );
 			return NS_SUCCESS;
@@ -468,7 +466,7 @@
 		while( ( hn = hash_scan_next( &hs ) ) != NULL ) 
 		{
 			Channel *c;
-			db =( ( ls_channel * )hnode_get( hn ) );
+			db = ( ( ls_channel * )hnode_get( hn ) );
 			c = FindChannel( db->name );
 			if( c )
 				ManageLimit( db->name, c->users, cmdparams->channel->limit, 1 );

Modified: trunk/modules/protocol/asuka.c
==============================================================================
--- trunk/modules/protocol/asuka.c	(original)
+++ trunk/modules/protocol/asuka.c	Thu Aug 25 04:23:01 2005
@@ -323,7 +323,7 @@
 		const char *sethost = NULL;
 		int param;
 
-		modes =( argv[5][0] == '+' ) ? argv[5]: NULL;
+		modes = ( argv[5][0] == '+' ) ? argv[5]: NULL;
 		if( modes ) {
 			param = 6;
 			for( modeptr = modes; *modeptr; ++modeptr ) {

Modified: trunk/modules/protocol/ircup10.c
==============================================================================
--- trunk/modules/protocol/ircup10.c	(original)
+++ trunk/modules/protocol/ircup10.c	Thu Aug 25 04:23:01 2005
@@ -292,7 +292,7 @@
 		const char *account = NULL;
 		int param;
 
-		modes =( argv[5][0] == '+' ) ? argv[5]: NULL;
+		modes = ( argv[5][0] == '+' ) ? argv[5]: NULL;
 		if( modes ) {
 			param = 6;
 			for( modeptr = modes; *modeptr; ++modeptr ) {

Modified: trunk/modules/protocol/ircup10base.c
==============================================================================
--- trunk/modules/protocol/ircup10base.c	(original)
+++ trunk/modules/protocol/ircup10base.c	Thu Aug 25 04:23:01 2005
@@ -412,7 +412,7 @@
 				char *s, *t;
 				char modechar = 0;
 			
-				t =( char *)argv[param];
+				t = ( char *)argv[param];
 				while( *( s = t ) ) {
 					t = s + strcspn( s, "," );
 					if( *t )

Modified: trunk/modules/protocol/nefarious.c
==============================================================================
--- trunk/modules/protocol/nefarious.c	(original)
+++ trunk/modules/protocol/nefarious.c	Thu Aug 25 04:23:01 2005
@@ -443,7 +443,7 @@
 		const char *fakehost = NULL;
 		int param;
 
-		modes =( argv[5][0] == '+' ) ? argv[5]: NULL;
+		modes = ( argv[5][0] == '+' ) ? argv[5]: NULL;
 		if( modes ) {
 			param = 6;
 			for( modeptr = modes; *modeptr; ++modeptr ) {

Modified: trunk/modules/protocol/unreal32.c
==============================================================================
--- trunk/modules/protocol/unreal32.c	(original)
+++ trunk/modules/protocol/unreal32.c	Thu Aug 25 04:23:01 2005
@@ -465,7 +465,7 @@
 			if( target ) {
 				if( tarindex >= targsize )
 					return( -1 );
-				target[tarindex] =( unsigned char )( pos - Base64 ) << 2;
+				target[tarindex] = ( unsigned char )( pos - Base64 ) << 2;
 			}
 			state = 1;
 			break;
@@ -474,7 +474,7 @@
 				if( tarindex + 1 >= targsize )
 					return( -1 );
 				target[tarindex]   |= ( pos - Base64 ) >> 4;
-				target[tarindex+1]  =( unsigned char )( ( pos - Base64 ) & 0x0f )
+				target[tarindex+1]  = ( unsigned char )( ( pos - Base64 ) & 0x0f )
 							<< 4 ;
 			}
 			tarindex++;
@@ -485,7 +485,7 @@
 				if( tarindex + 1 >= targsize )
 					return( -1 );
 				target[tarindex]   |= ( pos - Base64 ) >> 2;
-				target[tarindex+1]  =( unsigned char )( ( pos - Base64 ) & 0x03 )
+				target[tarindex+1]  = ( unsigned char )( ( pos - Base64 ) & 0x03 )
 							<< 6;
 			}
 			tarindex++;
@@ -495,7 +495,7 @@
 			if( target ) {
 				if( tarindex >= targsize )
 					return( -1 );
-				target[tarindex] |=( pos - Base64 );
+				target[tarindex] |= ( pos - Base64 );
 			}
 			tarindex++;
 			state = 0;

Modified: trunk/modules/quoteserv/main.c
==============================================================================
--- trunk/modules/quoteserv/main.c	(original)
+++ trunk/modules/quoteserv/main.c	Thu Aug 25 04:23:01 2005
@@ -284,8 +284,7 @@
 	hash_scan_begin( &hs, qshash );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL ) {
 		db = ( ( database * )hnode_get( hn ) );
-		hash_delete( qshash, hn );
-		hnode_destroy( hn );
+		hash_delete_destroy_node( qshash, hn );
 		qs_free_database( db );
 	}
 	hash_destroy( qshash );
@@ -361,7 +360,7 @@
 	hash_scan_begin( &hs, qshash );
 	irc_prefmsg( qs_bot, cmdparams->source, "Databases" );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL ) {
-		db =( ( database * )hnode_get( hn ) );
+		db = ( ( database * )hnode_get( hn ) );
 		irc_prefmsg( qs_bot, cmdparams->source, "%d - %s", i, db->name );
 		i++;
 	}
@@ -388,16 +387,15 @@
 	SET_SEGV_LOCATION();
 	hash_scan_begin( &hs, qshash );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL ) {
-		db =( database * )hnode_get( hn );
+		db = ( database * )hnode_get( hn );
 		if( ircstrcasecmp( db->name, cmdparams->av[0] ) == 0 ) {
-			hash_scan_delete( qshash, hn );
 			irc_prefmsg( qs_bot, cmdparams->source, 
 				"Deleted %s from the database list", cmdparams->av[0] );
 			CommandReport( qs_bot, "%s deleted %s from the database list",
 				cmdparams->source->name, cmdparams->av[0] );
 			nlog( LOG_NOTICE, "%s deleted %s from the database list",
 				cmdparams->source->name, cmdparams->av[0] );
-			hnode_destroy( hn );
+			hash_scan_delete_destroy_node( qshash, hn );
 			DBADelete( "databases", db->name );
 			ns_free( db );
 			return NS_SUCCESS;
@@ -444,7 +442,7 @@
 			while( ( hn = hash_scan_next( &hs ) ) != NULL )
 			{
 				i++;
-				db =( database * )hnode_get( hn );
+				db = ( database * )hnode_get( hn );
 				if( i == randdb )
 					break;
 			}

Modified: trunk/modules/statserv/server.c
==============================================================================
--- trunk/modules/statserv/server.c	(original)
+++ trunk/modules/statserv/server.c	Thu Aug 25 04:23:01 2005
@@ -120,7 +120,7 @@
 {
 	serverstat *stats;
 
-	stats =( serverstat * )hnode_find( serverstathash, name );
+	stats = ( serverstat * )hnode_find( serverstathash, name );
 	if( !stats )
 		dlog( DEBUG2, "findserverstats (%s) - not found", name );
 	return stats;
@@ -255,7 +255,7 @@
 {
 	serverstat *ss;
 	
-	ss =( serverstat * ) GetServerModValue( s );
+	ss = ( serverstat * ) GetServerModValue( s );
 	ss->ts_lastseen = me.now;
 	IncStatistic( &ss->splits );
 	ClearServerModValue( s );
@@ -291,7 +291,7 @@
 {
 	serverstat *ss;
 
-	ss =( serverstat * ) GetServerModValue( s );
+	ss = ( serverstat * ) GetServerModValue( s );
 	if( !ss )
 		return;
 	if( s->server->ping > ss->highest_ping )
@@ -351,7 +351,7 @@
 	{
 		s = hnode_get( sn );
 		printf( "%d %s %s (%s)\n", level, s->name, s->uplink ? s->uplink->name : "", uplink );
-		ss =( serverstat * ) GetServerModValue( s );
+		ss = ( serverstat * ) GetServerModValue( s );
 		if( ( level == 0 ) &&( s->uplinkname[0] == 0 ) )
 		{
 			/* its the root server */
@@ -469,9 +469,8 @@
 	node = hash_lookup( serverstathash, cmdparams->av[1] );
 	if( node )
 	{
-		ss =( serverstat * )hnode_get( node );
-		hash_delete( serverstathash, node );
-		hnode_destroy( node );
+		ss = ( serverstat * )hnode_get( node );
+		hash_delete_destroy_node( serverstathash, node );
 		ns_free( ss );
 		irc_prefmsg( ss_bot, cmdparams->source, "Removed %s from the database.",
 			cmdparams->av[1] );
@@ -766,8 +765,7 @@
 	{
 		ss = hnode_get( sn );
 		ClearServerModValue( ss->s );
-		hash_scan_delete( serverstathash, sn );
-		hnode_destroy( sn );
+		hash_scan_delete_destroy_node( serverstathash, sn );
 		ns_free( ss );
 	}
 	hash_destroy( serverstathash );

Modified: trunk/modules/statserv/stats.c
==============================================================================
--- trunk/modules/statserv/stats.c	(original)
+++ trunk/modules/statserv/stats.c	Thu Aug 25 04:23:01 2005
@@ -91,7 +91,7 @@
 
 void AverageStatisticEntry( statisticentry *stat, unsigned int current )
 {
-	stat->average =( stat->max + current ) / 2;
+	stat->average = ( stat->max + current ) / 2;
 }
 
 /** @brief AverageStatistic

Modified: trunk/modules/textserv/main.c
==============================================================================
--- trunk/modules/textserv/main.c	(original)
+++ trunk/modules/textserv/main.c	Thu Aug 25 04:23:01 2005
@@ -527,8 +527,7 @@
 		{
 			channame = ( ( char * )hnode_get( hn ) );
 			irc_part( db->botptr, channame, "" );
-			hash_delete( db->chanhash, hn );
-			hnode_destroy( hn );
+			hash_scan_delete_destroy_node( db->chanhash, hn );
 			ns_free( channame );
 		}
 		irc_quit( db->botptr, "" );
@@ -590,7 +589,7 @@
 	hn = hash_lookup( tshash, bce->name );
 	if( hn != NULL )
 	{
-		db =( ( dbbot * )hnode_get( hn ) );
+		db = ( ( dbbot * )hnode_get( hn ) );
 		if( hash_lookup( db->chanhash, bce->channel) == NULL ) 
 		{
 			channame = ns_calloc( MAXCHANLEN );
@@ -645,7 +644,7 @@
 	hash_scan_begin( &hs, tshash );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL )
 	{
-		db =( ( dbbot * )hnode_get( hn ) );
+		db = ( ( dbbot * )hnode_get( hn ) );
 		JoinBot( db );
 	}
 	return NS_SUCCESS;
@@ -669,10 +668,9 @@
 	SET_SEGV_LOCATION();
 	hash_scan_begin( &hs, tshash );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL ) {
-		db =( ( dbbot * )hnode_get( hn ) );
+		db = ( ( dbbot * )hnode_get( hn ) );
 		PartBot( db );
-		hash_delete( tshash, hn );
-		hnode_destroy( hn );
+		hash_scan_delete_destroy_node( tshash, hn );
 		ns_free( db );
 	}
 	hash_destroy( tshash );
@@ -776,7 +774,7 @@
 	hash_scan_begin( &hs, tshash );
 	irc_prefmsg( ts_bot, cmdparams->source, "Bots" );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL ) {
-		db =( ( dbbot * )hnode_get( hn ) );
+		db = ( ( dbbot * )hnode_get( hn ) );
 		irc_prefmsg( ts_bot, cmdparams->source, "%s (%s@%s), %s, %s, %s", db->tsbot.botname, db->tsbot.botuser, db->tsbot.bothost, db->tsbot.public ? "Public" : "Private", db->tsbot.dbname, db->tsbot.channel );
 	}
 	irc_prefmsg( ts_bot, cmdparams->source, "End of list." );
@@ -804,7 +802,7 @@
 	SET_SEGV_LOCATION();
 	hash_scan_begin( &hs, tshash );
 	while( ( hn = hash_scan_next( &hs ) ) != NULL ) {
-		db =( dbbot * )hnode_get( hn );
+		db = ( dbbot * )hnode_get( hn );
 		if( ircstrcasecmp( db->tsbot.botname, cmdparams->av[0] ) == 0 ) {
 			hash_scan_begin( &hs2, db->chanhash );
 			while( ( hn2 = hash_scan_next( &hs2 ) ) != NULL )
@@ -817,14 +815,13 @@
 				ns_free( botchan );
 			}
 			PartBot( db );
-			hash_scan_delete( tshash, hn );
 			irc_prefmsg( ts_bot, cmdparams->source, 
 				"Deleted %s from the Bot list", cmdparams->av[0] );
 			CommandReport( ts_bot, "%s deleted %s from the Bot list",
 				cmdparams->source->name, cmdparams->av[0] );
 			nlog( LOG_NOTICE, "%s deleted %s from the Bot list",
 				cmdparams->source->name, cmdparams->av[0] );
-			hnode_destroy( hn );
+			hash_scan_delete_destroy_node( tshash, hn );
 			DBADelete( "Bots", db->tsbot.botname );
 			ns_free( db );
 			return NS_SUCCESS;
@@ -1001,8 +998,7 @@
 	strlcpy( botchan, db->tsbot.botname, MAXNICK+MAXCHANLEN );
 	strlcat( botchan, channame, MAXNICK+MAXCHANLEN );
 	DBADelete( "BotChans", botchan );
-	hash_delete( db->chanhash, hn );
-	hnode_destroy( hn );
+	hash_delete_destroy_node( db->chanhash, hn );
 	ns_free( channame );
 	ns_free( botchan );
 	return NS_SUCCESS;

Modified: trunk/src/bans.c
==============================================================================
--- trunk/src/bans.c	(original)
+++ trunk/src/bans.c	Thu Aug 25 04:23:01 2005
@@ -171,8 +171,7 @@
 	cmdparams->param = ( char * )ban;
 	SendAllModuleEvent( EVENT_DELBAN, cmdparams );
 	ns_free( cmdparams );
-	hash_delete( banhash, bansnode );
-	hnode_destroy( bansnode );
+	hash_delete_destroy_node( banhash, bansnode );
 	ns_free( ban );
 }
 
@@ -229,8 +228,7 @@
 	hash_scan_begin( &hs, banhash );
 	while( ( bansnode = hash_scan_next( &hs ) ) != NULL  ) {
 		ban = hnode_get( bansnode );
-		hash_delete( banhash, bansnode );
-		hnode_destroy( bansnode );
+		hash_scan_delete_destroy_node( banhash, bansnode );
 		ns_free( ban );
 	}
 	hash_destroy( banhash );

Modified: trunk/src/bots.c
==============================================================================
--- trunk/src/bots.c	(original)
+++ trunk/src/bots.c	Thu Aug 25 04:23:01 2005
@@ -35,6 +35,8 @@
 #include "ctcp.h"
 #include "exclude.h"
 
+#define IS_CTCP_MSG( msg ) ( msg[0] == '\1' )
+
 #define BOT_TABLE_SIZE		100		/* Max number of bots */
 #define NICK_TRIES			5		/* Number of attempts for nick generation */
 
@@ -93,12 +95,14 @@
 	if( UserLevel( u ) >= NS_ULEVEL_OPER )	
 		return NS_FALSE;
 	/* calculate and test flood values */
-	if( ( me.now - u->user->tslastmsg ) > nsconfig.msgsampletime ) {
+	if( ( me.now - u->user->tslastmsg ) > nsconfig.msgsampletime )
+	{
 		u->user->tslastmsg = me.now;
 		u->user->flood = 0;
 		return NS_FALSE;
 	}
-	if( u->user->flood >= nsconfig.msgthreshold ) {
+	if( u->user->flood >= nsconfig.msgthreshold )
+	{
 		nlog( LOG_NORMAL, "FLOODING: %s!%s@%s", u->name, u->user->username, u->user->hostname );
 		irc_svskill( ns_botptr, u, _( "%s!%s (Flooding Services)" ), me.name, ns_botptr->name );
 		return NS_TRUE;
@@ -197,24 +201,30 @@
 	char *chan;
 
 	SET_SEGV_LOCATION();
-	if( cmdparams->param[0] == nsconfig.cmdchar[0] ) {
+	if( cmdparams->param[0] == nsconfig.cmdchar[0] )
+	{
 		/* skip over command char */
 		cmdparams->param ++;
 		cmdflag = 1;
 	}
 	hash_scan_begin( &bs, bothash );
-	while( ( bn = hash_scan_next( &bs ) ) != NULL ) {
+	while( ( bn = hash_scan_next( &bs ) ) != NULL )
+	{
 		botptr = hnode_get( bn );
 		/* Use an internal flag for handling DEAF so we can fake support
 		 * on IRCd's which do not have the mode natively
 		 */
-		if( !( botptr->flags & BOT_FLAG_DEAF ) ) {
+		if( !( botptr->flags & BOT_FLAG_DEAF ) )
+		{
 			cm = list_first( botptr->u->user->chans );
-			while( cm ) {	
+			while( cm )
+			{	
 				chan = ( char * ) lnode_get( cm );
 				cmdparams->bot = botptr;
-				if( ircstrcasecmp( cmdparams->channel->name, chan ) == 0 ) {
-					if( !cmdflag || !( botptr->flags & BOT_FLAG_SERVICEBOT ) || run_bot_cmd( cmdparams, cmdflag ) != NS_SUCCESS ) {
+				if( ircstrcasecmp( cmdparams->channel->name, chan ) == 0 )
+				{
+					if( !cmdflag || !( botptr->flags & BOT_FLAG_SERVICEBOT ) || run_bot_cmd( cmdparams, cmdflag ) != NS_SUCCESS )
+					{
 						/* Reset message if we have stripped cmdchar */
 						if( cmdflag )
 							cmdparams->param --;
@@ -250,13 +260,18 @@
 	SET_SEGV_LOCATION();
 	cmdparams = ( CmdParams* ) ns_calloc( sizeof( CmdParams ) );
 	/* Check origin validity */
-	if( process_origin( cmdparams, origin ) ) {
+	if( process_origin( cmdparams, origin ) )
+	{
 		/* Find target bot */
-		if( process_target_user( cmdparams, av[0] ) ) {
+		if( process_target_user( cmdparams, av[0] ) )
+		{
 			cmdparams->param = av[ac - 1];
-			if( av[ac - 1][0] == '\1' ) {
+			if( IS_CTCP_MSG( cmdparams->param ) )
+			{
 				ctcp_notice( cmdparams );
-			} else {
+			}
+			else
+			{
 				SendModuleEvent( EVENT_NOTICE, cmdparams, cmdparams->bot->moduleptr );
 			}
 		}		
@@ -282,12 +297,17 @@
 
 	SET_SEGV_LOCATION();
 	cmdparams = ( CmdParams* ) ns_calloc( sizeof(CmdParams ) );
-	if( process_origin( cmdparams, origin ) ) {
-		if( process_target_chan( cmdparams, av[0] ) ) {
+	if( process_origin( cmdparams, origin ) )
+	{
+		if( process_target_chan( cmdparams, av[0] ) )
+		{
 			cmdparams->param = av[ac - 1];
-			if( av[ac - 1][0] == '\1' ) {
+			if( IS_CTCP_MSG( cmdparams->param ) )
+			{
 				ctcp_cnotice( cmdparams );
-			} else {
+			}
+			else
+			{
 				bot_chan_event( EVENT_CNOTICE, cmdparams );
 			}
 		}
@@ -313,16 +333,22 @@
 
 	SET_SEGV_LOCATION();
 	cmdparams = ( CmdParams* ) ns_calloc( sizeof(CmdParams ) );
-	if( process_origin( cmdparams, origin ) ) {
+	if( process_origin( cmdparams, origin ) )
+	{
 		/* Find target bot */
-		if( process_target_user( cmdparams, av[0] ) ) {
+		if( process_target_user( cmdparams, av[0] ) )
+		{
 			cmdparams->param = av[ac - 1];
 			/* Check CTCP first to avoid Unknown command messages later */
-			if( av[ac - 1][0] == '\1' ) {
+			if( IS_CTCP_MSG( cmdparams->param ) )
+			{
 				ctcp_private( cmdparams );
-			} else {
+			}
+			else
+			{
 				if( !( cmdparams->bot->flags & BOT_FLAG_SERVICEBOT ) ||
-					run_bot_cmd( cmdparams, 0 ) == NS_FAILURE ) {
+					run_bot_cmd( cmdparams, 0 ) == NS_FAILURE )
+				{
 					SendModuleEvent( EVENT_PRIVATE, cmdparams, cmdparams->bot->moduleptr );
 				}
 			}
@@ -349,12 +375,17 @@
 
 	SET_SEGV_LOCATION();
 	cmdparams = ( CmdParams* ) ns_calloc( sizeof(CmdParams ) );
-	if( process_origin( cmdparams, origin ) ) {
-		if( process_target_chan( cmdparams, av[0] ) ) {
+	if( process_origin( cmdparams, origin ) )
+	{
+		if( process_target_chan( cmdparams, av[0] ) )
+		{
 			cmdparams->param = av[ac - 1];
-			if( av[ac - 1][0] == '\1' ) {
+			if( IS_CTCP_MSG( cmdparams->param ) )
+			{
 				ctcp_cprivate( cmdparams );
-			} else {
+			}
+			else
+			{
 				bot_chan_event( EVENT_CPRIVATE, cmdparams );
 			}
 		}
@@ -377,9 +408,8 @@
 
 	SET_SEGV_LOCATION(); 
 	bot = ( Bot * ) hnode_find( bothash, bot_name );
-	if( !bot ) {
+	if( !bot )
 		dlog( DEBUG3, "FindBot: %s not found", bot_name );
-	}
 	return bot;
 }
 
@@ -400,15 +430,16 @@
 
 	SET_SEGV_LOCATION();
 	bn = hash_lookup( bothash, bot_name );
-	if( !bn ) {
+	if( !bn )
+	{
+		nlog( LOG_WARNING, "DelBot: %s not found", bot_name );
 		return NS_FAILURE;
 	}
 	botptr = hnode_get( bn );
 	del_all_bot_cmds( botptr );
 	del_bot_info_settings( botptr );
 	del_all_bot_settings( botptr );
-	hash_delete( bothash, bn );
-	hnode_destroy( bn );
+	hash_delete_destroy_node( bothash, bn );
 	ns_free( botptr );
 	return NS_SUCCESS;
 }
@@ -430,8 +461,9 @@
 
 	SET_SEGV_LOCATION();
 	bn = hash_lookup( bothash, botptr->name );
-	if( !bn ) {
-		nlog( LOG_NOTICE, "BotNickChange: Couldn't find bot %s in bot list", botptr->name );
+	if( !bn )
+	{
+		nlog( LOG_WARNING, "BotNickChange: %s not found", botptr->name );
 		return NS_FAILURE;
 	}
 	/* remove old hash entry */
@@ -463,17 +495,18 @@
 	SET_SEGV_LOCATION();
 	irc_prefmsg( ns_botptr, cmdparams->source, __( "Module Bot List:", cmdparams->source ) );
 	hash_scan_begin( &bs, bothash );
-	while( ( bn = hash_scan_next( &bs ) ) != NULL ) {
+	while( ( bn = hash_scan_next( &bs ) ) != NULL )
+	{
 		botptr = hnode_get( bn );
-		if( ( botptr->flags & 0x80000000 ) ) {
+		if( ( botptr->flags & 0x80000000 ) )
 			irc_prefmsg( ns_botptr, cmdparams->source, __( "NeoStats", cmdparams->source ) );
-		} else {
+		else
 			irc_prefmsg( ns_botptr, cmdparams->source, __( "Module: %s", cmdparams->source ), botptr->moduleptr->info->name );
-		}
 		irc_prefmsg( ns_botptr, cmdparams->source, __( "Bot: %s", cmdparams->source ), botptr->name );
 		cm = list_first( botptr->u->user->chans );
 		irc_prefmsg( ns_botptr, cmdparams->source, __( "Channels:", cmdparams->source ) );
-		while( cm ) {
+		while( cm )
+		{
 			irc_prefmsg( ns_botptr, cmdparams->source, "    %s", ( char * ) lnode_get( cm ) );
 			cm = list_next( botptr->u->user->chans, cm );
 		}
@@ -499,9 +532,11 @@
 	hscan_t hscan;
 
 	hash_scan_begin( &hscan, bothash );
-	while( ( modnode = hash_scan_next( &hscan ) ) != NULL ) {
+	while( ( modnode = hash_scan_next( &hscan ) ) != NULL )
+	{
 		botptr = hnode_get( modnode );
-		if( botptr->moduleptr == mod_ptr ) {
+		if( botptr->moduleptr == mod_ptr )
+		{
 			dlog( DEBUG1, "Deleting module %s bot %s", mod_ptr->info->name, botptr->name );
 			irc_quit( botptr, _( "Module Unloaded" ) );
 		}
@@ -524,7 +559,8 @@
 	Bot *botptr;
 
 	SET_SEGV_LOCATION();
-	if( hash_isfull( bothash ) ) {
+	if( hash_isfull( bothash ) )
+	{
 		nlog( LOG_CRITICAL, "new_bot: Failed to create bot %s, bot list is full", bot_name );
 		return NULL;
 	}
@@ -679,18 +715,21 @@
 
 	SET_SEGV_LOCATION();
 	modptr = GET_CUR_MODULE();
-	if( !IsModuleInSynch( modptr ) ) {
+	if( !IsModuleInSynch( modptr ) )
+	{
 		nlog( LOG_WARNING, "Module %s attempted to init a bot %s but is not yet synched", modptr->info->name, botinfo->nick );
 		SetModuleError( modptr );
 		return NULL;
 	}
 	/* In single bot mode, just add all commands and settings to main bot */
-	if( nsconfig.singlebotmode && ns_botptr ) {
+	if( nsconfig.singlebotmode && ns_botptr )
+	{
 		add_bot_cmd_list( ns_botptr, botinfo->bot_cmd_list );
 		add_bot_setting_list( ns_botptr, botinfo->bot_setting_list );
 		return(ns_botptr );
 	}
-	if( GetBotNick( botinfo, nick ) == NS_FAILURE ) {
+	if( GetBotNick( botinfo, nick ) == NS_FAILURE )
+	{
 		nlog( LOG_WARNING, "Failed to find free nick for bot %s", botinfo->nick );
 		return NULL;
 	}
@@ -704,7 +743,8 @@
 	botptr->flags = botinfo->flags;
 	ConnectBot( botptr );
 	/* Only add commands and settings for service bots */
-	if( botptr->flags & BOT_FLAG_SERVICEBOT ) {
+	if( botptr->flags & BOT_FLAG_SERVICEBOT )
+	{
 		add_bot_cmd_list( botptr, botinfo->bot_cmd_list );
 		add_bot_setting_list( botptr, botinfo->bot_setting_list );
 		/* Do not add set botinfo options for root bot */
@@ -745,12 +785,15 @@
 	hash_scan_begin( &bs, bothash );
 	cmdparams = ns_calloc( sizeof( CmdParams ) );
 	cmdparams->channel = c;
-	while( ( bn = hash_scan_next( &bs ) ) != NULL ) {
+	while( ( bn = hash_scan_next( &bs ) ) != NULL )
+	{
 		cmdparams->bot = hnode_get( bn );
 		cm = list_first( cmdparams->bot->u->user->chans );
-		while( cm ) {
+		while( cm )
+		{
 			chan = ( char * ) lnode_get( cm );
-			if( ircstrcasecmp( cmdparams->channel->name, chan ) == 0 ) {
+			if( ircstrcasecmp( cmdparams->channel->name, chan ) == 0 )
+			{
 				/* Force the bot to leave the channel */
 				irc_part( cmdparams->bot, cmdparams->channel->name, NULL );
 				/* Tell the module we kicked them out */
@@ -763,6 +806,17 @@
 	ns_free( cmdparams );
 }
 
+/** @brief AllocBotModPtr
+ *
+ *  Allocate memory for a module pointer for a bot
+ *  NeoStats core use only.
+ *
+ *  @param pBot pointer to bot to lookup pointer for
+ *  @param size to allocate
+ *
+ *  @return pointer to allocated memory
+ */
+
 void *AllocBotModPtr( Bot *pBot, int size )
 {
 	void *ptr;
@@ -771,37 +825,85 @@
 	return ptr;
 }
 
+/** @brief FreeBotModPtr
+ *
+ *  Free memory for a module pointer for a bot
+ *  NeoStats core use only.
+ *
+ *  @param pBot pointer to bot to lookup pointer for
+ *
+ *  @return none
+ */
+
 void FreeBotModPtr( Bot *pBot )
 {
-	ns_free( pBot->moddata );
+	if( pBot )
+		ns_free( pBot->moddata );
 }
 
+/** @brief GetBotModPtr
+ *
+ *  Retrieve module pointer for a bot
+ *  NeoStats core use only.
+ *
+ *  @param pBot pointer to bot to lookup pointer for
+ *
+ *  @return none
+ */
+
 void* GetBotModPtr( const Bot *pBot )
 {
-	return pBot->moddata;
+	if( pBot )
+		return pBot->moddata;
+	return NULL;
 }
 
+/** @brief ClearBotModValue
+ *
+ *  Clear module value for a bot
+ *  NeoStats core use only.
+ *
+ *  @param pBot pointer to bot to lookup pointer for
+ *
+ *  @return none
+ */
+
 void ClearBotModValue( Bot *pBot )
 {
 	if( pBot )
-	{
 		pBot->moddata = NULL;
-	}
 }
 
+/** @brief SetBotModValue
+ *
+ *  Set module value for a bot
+ *  NeoStats core use only.
+ *
+ *  @param pBot pointer to bot to lookup pointer for
+ *  @param data pointer to set
+ *
+ *  @return none
+ */
+
 void SetBotModValue( Bot *pBot, void *data )
 {
 	if( pBot )
-	{
 		pBot->moddata = data;
-	}
 }
 
+/** @brief GetBotModValue
+ *
+ *  Retrieve module value for a bot
+ *  NeoStats core use only.
+ *
+ *  @param pBot pointer to bot to lookup pointer for
+ *
+ *  @return none
+ */
+
 void *GetBotModValue( const Bot *pBot )
 {
 	if( pBot )
-	{
 		return pBot->moddata;
-	}
 	return NULL;	
 }

Modified: trunk/src/channels.c
==============================================================================
--- trunk/src/channels.c	(original)
+++ trunk/src/channels.c	Thu Aug 25 04:23:01 2005
@@ -48,9 +48,17 @@
 /* temp buffer to save kick info for IRCu */
 static char savekicker[MAXHOST];
 static char savekickreason[BUFSIZE];
-/** @brief Module data flags */
-static unsigned int fchannelmoddata = 0;
-static unsigned int moddatacnt[NUM_MODULES];
+
+/** @brief comparechanmember
+ *
+ *  list helper for channel members
+ *  Channel subsystem use only.
+ *
+ *  @param key1
+ *  @param key2
+ *
+ *  @return results of comparison
+ */
 
 int comparechanmember( const void *key1, const void *key2 )
 {
@@ -58,7 +66,6 @@
 	return ircstrcasecmp( cm->u->name, key2 );
 }
 
-
 /** @brief ChanPartHandler
  *
  *  list handler for channel parts
@@ -90,7 +97,8 @@
 void PartAllChannels( Client *u, const char *reason )
 {
 	os_memset( quitreason, 0, BUFSIZE );
-	if( reason ) {
+	if( reason )
+	{
 		strlcpy( quitreason, reason, BUFSIZE );
 		strip_mirc_codes( quitreason );
 	}
@@ -116,22 +124,21 @@
 	Channel *c;
 
 	c = FindChannel( chan );
-	if( !c ) {
+	if( !c )
+	{
 		nlog( LOG_WARNING, "ChannelTopic: can't find channel %s", chan );
 		return;
 	}
-	if( topic ) {
+	if( topic )
 		strlcpy( c->topic, topic, BUFSIZE );
-	} else {
+	else
 		c->topic[0] = 0;
-	}
 	strlcpy( c->topicowner, owner, MAXHOST );
 	c->topictime = ( ts ) ? atoi( ts ) : me.now;
 	cmdparams = (CmdParams *) ns_calloc( sizeof( CmdParams ) );
 	cmdparams->source = FindUser( owner );
-	if( !cmdparams->source ) {
+	if( !cmdparams->source )
 		cmdparams->source = FindServer( owner );
-	}
 	cmdparams->channel = c;
 	SendAllModuleEvent( EVENT_TOPIC, cmdparams );
 	ns_free( cmdparams );
@@ -151,16 +158,15 @@
 	CmdParams *cmdparams;
 	Channel *c;
 
-	if( hash_isfull( channelhash ) ) {
+	if( hash_isfull( channelhash ) )
+	{
 		nlog( LOG_CRITICAL, "new_chan: channel hash is full" );
 		return NULL;
 	}
 	c = ns_calloc( sizeof( Channel ) );
 	strlcpy( c->name, chan, MAXCHANLEN );
 	if( ircstrcasecmp( me.serviceschan, chan ) == 0 )
-	{
 		c->flags |= CHANNEL_FLAG_ME;
-	}
 	hnode_create_insert( channelhash, c, c->name );
 	c->members = list_create( CHANNEL_MEM_SIZE );
 	c->modeparms = list_create( CHANNEL_MAXMODES );
@@ -194,7 +200,8 @@
 	SET_SEGV_LOCATION();
 	dlog( DEBUG2, "del_chan: deleting channel %s", c->name );
 	cn = hash_lookup( channelhash, c->name );
-	if( !cn ) {
+	if( !cn )
+	{
 		nlog( LOG_WARNING, "del_chan: channel %s not found.", c->name );
 		return;
 	}
@@ -205,8 +212,7 @@
 	ns_free( cmdparams );
 	list_destroy_auto( c->modeparms );
 	list_destroy( c->members );
-	hash_delete( channelhash, cn );
-	hnode_destroy( cn );
+	hash_delete_destroy_node( channelhash, cn );
 	ns_free( c );
 }
 
@@ -226,14 +232,13 @@
 	lnode_t *un;
 
 	un = list_find( u->user->chans, c->name, comparef );
-	if( !un ) {
+	if( !un )
 		nlog( LOG_WARNING, "del_user_channel: %s not found in channel %s", u->name, c->name );
-	} else {
+	else
 		list_delete_destroy_node( u->user->chans, un );
-	}
 }
 
-/** @brief del_user_channel
+/** @brief del_channel_member
  *
  *  Deletes channel member record
  *  Channel subsystem use only.
@@ -250,7 +255,8 @@
 	lnode_t *un;
 	
 	un = list_find( c->members, u->name, comparechanmember );
-	if( !un ) {
+	if( !un )
+	{
 		nlog( LOG_WARNING, "%s isn't a member of channel %s", u->name, c->name );
 		return;
 	}
@@ -273,9 +279,12 @@
 
 static void CheckEmptyChannel( Channel *c )
 {
-	if( c->users <= 0 ) {
+	if( c->users <= 0 )
+	{
 		del_chan( c );
-	} else if( ( c->neousers > 0 ) && ( c->neousers == c->users ) ) {
+	}
+	else if( ( c->neousers > 0 ) && ( c->neousers == c->users ) )
+	{
 		/* all real users have left the channel */
 		handle_dead_channel( c );
 	}
@@ -303,36 +312,41 @@
 	SET_SEGV_LOCATION();
 	dlog( DEBUG2, "KickChannel: %s kicked %s from %s for %s", kickby, kicked, chan, kickreason ? kickreason : "no reason" );
 	u = FindUser( kicked );
-	if( !u ) {
+	if( !u )
+	{
 		nlog( LOG_WARNING, "KickChannel: user %s not found", kicked );
 		return;
 	}
 	c = FindChannel( chan );
-	if( !c ) {
+	if( !c )
+	{
 		nlog( LOG_WARNING, "KickChannel: channel %s not found", chan );
 		return;
 	} 
 	/* If PROTOCOL_KICKPART then we will also get part so DO NOT REMOVE USER or send event yet */
-	if( ircd_srv.protocol & PROTOCOL_KICKPART ) {
+	if( ircd_srv.protocol & PROTOCOL_KICKPART )
+	{
 		u->flags |= CLIENT_FLAG_ZOMBIE;
 		strlcpy( savekicker, kickby, MAXHOST );
 		if( kickreason )
 			strlcpy( savekickreason, kickreason, BUFSIZE );
 		else 
 			savekickreason[0] = 0;
-	} else {
+	}
+	else
+	{
 		del_user_channel( c, u );
 		del_channel_member( c, u );
 		cmdparams = (CmdParams *) ns_calloc( sizeof( CmdParams ) );
 		cmdparams->target = u;
 		cmdparams->channel = c;
 		cmdparams->source = FindUser( kickby );
-		if( !cmdparams->source ) {
+		if( !cmdparams->source )
 			cmdparams->source = FindServer( kickby );
-		}
 		cmdparams->param = (char *)kickreason;
 		SendAllModuleEvent( EVENT_KICK, cmdparams );
-		if( IsMe( u ) ) {
+		if( IsMe( u ) )
+		{
 			/* its one of our bots */
 			cmdparams->bot = u->user->bot;
 			SendModuleEvent( EVENT_KICKBOT, cmdparams, u->user->bot->moduleptr );
@@ -363,12 +377,14 @@
 
 	SET_SEGV_LOCATION();
 	dlog( DEBUG2, "PartChannel: parting %s from %s", u->name, chan );
-	if( !u ) {
+	if( !u )
+	{
 		nlog( LOG_WARNING, "PartChannel: trying to part NULL user from %s", chan );
 		return;
 	}
 	c = FindChannel( chan );
-	if( !c ) {
+	if( !c )
+	{
 		nlog( LOG_WARNING, "PartChannel: channel %s not found", chan );
 		return;
 	}
@@ -381,12 +397,12 @@
 		u->flags &= ~CLIENT_FLAG_ZOMBIE;
 		cmdparams->target = u;
 		cmdparams->source = FindUser( savekicker );
-		if( !cmdparams->source ) {
+		if( !cmdparams->source )
 			cmdparams->source = FindServer( savekicker );
-		}
 		cmdparams->param = savekickreason[0] ? savekickreason : NULL;
 		SendAllModuleEvent( EVENT_KICK, cmdparams );
-		if( IsMe( u ) ) {
+		if( IsMe( u ) )
+		{
 			/* its one of our bots */
 			cmdparams->bot = u->user->bot;
 			SendModuleEvent( EVENT_KICKBOT, cmdparams, u->user->bot->moduleptr );
@@ -397,7 +413,8 @@
 	cmdparams->source = u;
 	cmdparams->param = (char *) reason;
 	SendAllModuleEvent( EVENT_PART, cmdparams );
-	if( IsMe( u ) ) {
+	if( IsMe( u ) )
+	{
 		/* its one of our bots */
 		SendModuleEvent( EVENT_PARTBOT, cmdparams, u->user->bot->moduleptr );
 		c->neousers --;
@@ -406,20 +423,20 @@
 	ns_free( cmdparams );
 }
 
-/** @brief Process a user joining a channel
+/** @brief JoinChannel
  *
- * joins a user to a channel and raises JOINCHAN event and if required NEWCHAN events
- * if the channel is new, a new channel record is requested and defaults are set
- * if its one of our bots, also update the botchanlist
  *
- * @param u The User structure of the user joining the channel
- * @param chan the channel name
+ *  joins a user to a channel and raises JOINCHAN event and if required NEWCHAN events
+ *  if the channel is new, a new channel record is requested and defaults are set
+ *  if its one of our bots, also update the botchanlist
  *
- * @returns Nothing
+ *  @param nick of user joining
+ *  @param chan name of channel
+ *
+ *  @return none
 */
 
-void
-JoinChannel( const char *nick, const char *chan )
+void JoinChannel( const char *nick, const char *chan )
 {
 	CmdParams *cmdparams;
 	Client *u;
@@ -428,28 +445,33 @@
 	
 	SET_SEGV_LOCATION();
 	u = FindUser( nick );
-	if( !u ) {
+	if( !u )
+	{
 		nlog( LOG_WARNING, "JoinChannel: tried to join unknown user %s to channel %s", nick, chan );
 		return;
 	}
-	if( !ircstrcasecmp( "0", chan ) ) {
+	if( !ircstrcasecmp( "0", chan ) )
+	{
 		/* join 0 is actually part all chans */
 		dlog( DEBUG2, "JoinChannel: parting %s from all channels", u->name );
 		PartAllChannels( u, NULL );
 		return;
 	}
 	c = FindChannel( chan );
-	if( !c ) {
+	if( !c )
+	{
 		/* its a new Channel */
 		dlog( DEBUG2, "JoinChannel: new channel %s", chan );
 		c = new_chan( chan );
 	}
 	/* add this users details to the channel members hash */
-	if( list_find( c->members, u->name, comparechanmember ) ) {
+	if( list_find( c->members, u->name, comparechanmember ) )
+	{
 		nlog( LOG_WARNING, "JoinChannel: tried to add %s to channel %s but they are already a member", u->name, chan );
 		return;
 	}
-	if( list_isfull( c->members ) ) {
+	if( list_isfull( c->members ) )
+	{
 		nlog( LOG_CRITICAL, "JoinChannel: channel %s member list is full", c->name );
 		return;
 	}
@@ -460,7 +482,8 @@
 	cm->flags = 0;
 	lnode_create_append( c->members, cm );
 	c->users++;
-	if( list_isfull( u->user->chans ) ) {
+	if( list_isfull( u->user->chans ) )
+	{
 		nlog( LOG_CRITICAL, "JoinChannel: user %s member list is full", u->name );
 		return;
 	}
@@ -468,7 +491,8 @@
 	cmdparams = (CmdParams *) ns_calloc( sizeof( CmdParams ) );
 	cmdparams->source = u;
 	cmdparams->channel = c;
-	if( IsMe( u ) ) {
+	if( IsMe( u ) )
+	{
 		/* its one of our bots */
 		c->neousers ++;
 	}
@@ -477,14 +501,15 @@
 	dlog( DEBUG3, "JoinChannel: cur users %s %d (list %d)", c->name, c->users,( int )list_count( c->members ) );
 }
 
-/** @brief Dump Channel information
+/** @brief ListChannelMembers
  *
- * dump either the entire channel list, or a single channel detail. Used for debugging
- * sends the output to the services channel
+ *  List channel members
+ *  sends the output to the services channel
  *
- * @param chan the channel name to dump, or NULL for all channels
+ *  @param cmdparams
+ *  @param c pointer to channel
  *
- * @returns Nothing
+ *  @return none
 */
 
 static void ListChannelMembers( CmdParams * cmdparams, Channel *c )
@@ -494,15 +519,29 @@
 
 	irc_prefmsg( ns_botptr, cmdparams->source, __( "Members:    %d (List %d)", cmdparams->source ), c->users,( int )list_count( c->members ) );
 	cmn = list_first( c->members );
-	while( cmn ) {
+	while( cmn )
+	{
 		cm = lnode_get( cmn );
 		irc_prefmsg( ns_botptr, cmdparams->source, __( "            %s Modes %s Joined: %ld", cmdparams->source ), cm->u->name, CmodeMaskToString( cm->flags ),( long )cm->tsjoin );
 		cmn = list_next( c->members, cmn );
 	}
 }
 
-static void ListChannel( CmdParams * cmdparams, Channel *c )
+/** @brief ListChannel
+ *
+ *  Report channels
+ *
+ *  @param c pointer to channel
+ *  @param v cmdparams
+ *
+ *  @returns none
+*/
+
+static int ListChannel( Channel *c, void *v )
 {
+	CmdParams *cmdparams;
+
+	cmdparams = ( CmdParams * ) v;
 	irc_prefmsg( ns_botptr, cmdparams->source, __( "Channel:    %s", cmdparams->source ), c->name );
 	irc_prefmsg( ns_botptr, cmdparams->source, __( "Created:    %ld", cmdparams->source ),( long )c->creationtime );
 	irc_prefmsg( ns_botptr, cmdparams->source, __( "TopicOwner: %s TopicTime: %ld Topic: %s", cmdparams->source ), c->topicowner,( long )c->topictime, c->topic );
@@ -511,33 +550,38 @@
 	ListChannelModes( cmdparams, c );
 	ListChannelMembers( cmdparams, c );
 	irc_prefmsg( ns_botptr, cmdparams->source, "========================================" );
+	return NS_FALSE;
 }
 
+/** @brief ListChannels
+ *
+ *  Report channels
+ *
+ *  @param cmdparams
+ *  @param chan
+ *
+ *  @returns none
+*/
+
 void ListChannels( CmdParams * cmdparams, const char *chan )
 {
-	hnode_t *cn;
-	hscan_t sc;
 	Channel *c;
 
 	if( !nsconfig.debug )
 		return;
 	SET_SEGV_LOCATION();
 	irc_prefmsg( ns_botptr, cmdparams->source, __( "================CHANLIST================",cmdparams->source ) );
-	if( !chan ) {
-		irc_prefmsg( ns_botptr, cmdparams->source, __( "Channels %d", cmdparams->source ),( int )hash_count( channelhash ) );
-		hash_scan_begin( &sc, channelhash );
-		while( ( cn = hash_scan_next( &sc ) ) != NULL ) {
-			c = hnode_get( cn );
-			ListChannel( cmdparams, c );
-		}
-	} else {
+	if( chan )
+	{
 		c = FindChannel( chan );
-		if( c ) {
-			ListChannel( cmdparams, c );
-		} else {
+		if( c )
+			ListChannel( c, cmdparams );
+		else
 			irc_prefmsg( ns_botptr, cmdparams->source, __( "ListChannels: can't find channel %s", cmdparams->source ), chan );
-		}
+		return;
 	}
+	irc_prefmsg( ns_botptr, cmdparams->source, __( "Channels %d", cmdparams->source ),( int )hash_count( channelhash ) );
+	ProcessChannelList( ListChannel, cmdparams );
 }
 
 /** @brief FindChannel
@@ -554,9 +598,8 @@
 	Channel *c;
 
 	c = ( Channel * )hnode_find( channelhash, chan );
-	if( !c ) {
+	if( !c )
 		dlog( DEBUG3, "FindChannel: %s not found", chan );
-	}
 	return c;
 }
 
@@ -572,12 +615,10 @@
 
 int IsChannelMember( const Channel *c, const Client *u ) 
 {
-	if( !u || !c ) {
+	if( !u || !c )
 		return NS_FALSE;
-	}
-	if( list_find( c->members, u->name, comparechanmember ) ) {
+	if( list_find( c->members, u->name, comparechanmember ) )
 		return NS_TRUE;
-	}
 	return NS_FALSE;
 }
 
@@ -599,14 +640,13 @@
 
 	u = FindUser( nick );
 	c = FindChannel( chan );
-	if( !u || !c ) {
+	if( !u || !c )
 		return NS_FALSE;
-	}
 	cm = lnode_find( c->members, nick, comparechanmember );
-	if( cm ) {
-		if( cm->flags & flag ) {
+	if( cm )
+	{
+		if( cm->flags & flag )
 			return NS_TRUE;
-		}
 	}	
 	return NS_FALSE;
 }
@@ -624,7 +664,8 @@
 int InitChannels( void )
 {
 	channelhash = hash_create( CHANNEL_TABLE_SIZE, 0, 0 );
-	if( !channelhash )	{
+	if( !channelhash )
+	{
 		nlog( LOG_CRITICAL, "Unable to create channel hash" );
 		return NS_FAILURE;
 	}
@@ -646,6 +687,15 @@
 	hash_destroy( channelhash );
 }
 
+/** @brief GetRandomChannel
+ *
+ *  find random channel
+ *
+ *  @params none
+ *
+ *  @return Channel pointer selected or NULL if none
+ */
+
 Channel *GetRandomChannel( void ) 
 {
 	hscan_t cs;
@@ -654,14 +704,13 @@
 	
 	curno = 0;
 	randno = hrand( hash_count( channelhash ), 1 );	
-	if( randno == -1 ) {
+	if( randno == -1 )
 		return NULL;
-	}
 	hash_scan_begin( &cs, channelhash );
-	while( ( cn = hash_scan_next( &cs ) ) != NULL ) {
-		if( curno == randno ) {
+	while( ( cn = hash_scan_next( &cs ) ) != NULL )
+	{
+		if( curno == randno )
 			return(( Channel * )hnode_get( cn ) );
-		}
 		curno++;
 	}
 	nlog( LOG_WARNING, "GetRandomChannel() ran out of channels?" );
@@ -672,8 +721,8 @@
  *
  *  find random channel member
  *
- *  @params uge use global exclusions
  *  @params c channel to select member from
+ *  @params uge use global exclusions
  *
  *  @return Client pointer selected or NULL if none
  */
@@ -702,6 +751,16 @@
 }
 
 
+/** @brief GetRandomChannelKey
+ *
+ *  Generate a random channel key
+ *  NeoStats core use only.
+ *
+ *  @param length to generate
+ *
+ *  @return pointer to allocated key
+ */
+
 char *GetRandomChannelKey( int length ) 
 {
 	int i;
@@ -718,6 +777,17 @@
 	return key;
 }
 
+/** @brief ProcessChannelList
+ *
+ *  Walk channel list and call handler for each channel
+ *  NeoStats core use only.
+ *
+ *  @param handler to call
+ *  @param v optional pointer
+ *
+ *  @return NS_SUCCESS
+ */
+
 int ProcessChannelList( ChannelListHandler handler, void *v )
 {
 	hnode_t *node;
@@ -726,7 +796,8 @@
 
 	SET_SEGV_LOCATION();
 	hash_scan_begin( &scan, channelhash );
-	while( ( node = hash_scan_next( &scan ) ) != NULL ) {
+	while( ( node = hash_scan_next( &scan ) ) != NULL )
+	{
 		c = hnode_get( node );
 		if( handler( c, v ) == NS_TRUE )
 			break;
@@ -734,13 +805,26 @@
 	return NS_SUCCESS;
 }
 
+/** @brief ProcessChannelMembers
+ *
+ *  Walk channel member list and call handler for each member
+ *  NeoStats core use only.
+ *
+ *  @param c channel to process
+ *  @param handler to call
+ *  @param v optional pointer
+ *
+ *  @return NS_SUCCESS
+ */
+
 int ProcessChannelMembers( Channel *c, ChannelMemberListHandler handler, void *v )
 {
  	ChannelMember *cm;
 	lnode_t *cmn;
 
 	cmn = list_first( c->members );
-	while( cmn ) {
+	while( cmn )
+	{
 		cm = lnode_get( cmn );
 		if( handler( c, cm, v ) == NS_TRUE )
 			break;
@@ -749,83 +833,150 @@
 	return NS_SUCCESS;
 }
 
+/** @brief AllocChannelModPtr
+ *
+ *  Allocate memory for a module pointer for a channel
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to channel to add pointer for
+ *  @param size to allocate
+ *
+ *  @return pointer to allocated memory
+ */
+
 void *AllocChannelModPtr( Channel* c, int size )
 {
 	void *ptr;
 	ptr = ns_calloc( size );
-	c->modptr[GET_CUR_MODNUM()] = ptr;
-	fchannelmoddata |= ( 1 << GET_CUR_MODNUM() );
-	moddatacnt[GET_CUR_MODNUM()]++;
+	c->modptr[GET_CUR_MODULE_INDEX()] = ptr;
+	GET_CUR_MODULE()->channeldatacnt++;
 	return ptr;
 }
 
+/** @brief FreeChannelModPtr
+ *
+ *  Free memory for a module pointer for a channel
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to channel to free pointer for
+ *
+ *  @return none
+ */
+
 void FreeChannelModPtr( Channel *c )
 {
-	ns_free( c->modptr[GET_CUR_MODNUM()] );
-	moddatacnt[GET_CUR_MODNUM()]--;
-	if( moddatacnt[GET_CUR_MODNUM()] == 0 )
-	{
-		fchannelmoddata &= ~( 1 << GET_CUR_MODNUM() );
-	}
+	ns_free( c->modptr[GET_CUR_MODULE_INDEX()] );
+	GET_CUR_MODULE()->channeldatacnt--;
 }
 
+/** @brief GetChannelModPtr
+ *
+ *  Retrieve module pointer for a channel
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to channel to lookup pointer for
+ *
+ *  @return none
+ */
+
 void* GetChannelModPtr( const Channel *c )
 {
-	return c->modptr[GET_CUR_MODNUM()];
+	if( c )
+		return c->modptr[GET_CUR_MODULE_INDEX()];
+	return NULL;
 }
 
+/** @brief ClearChannelModValue
+ *
+ *  Clear module value for a channel
+ *  NeoStats core use only.
+ *
+ *  @param c pointer to channel to clear
+ *
+ *  @return none
+ */
+
 void ClearChannelModValue( Channel *c )
 {
 	if( c )
 	{
-		c->modvalue[GET_CUR_MODNUM()] = NULL;
-		moddatacnt[GET_CUR_MODNUM()]--;
-	}
-	if( moddatacnt[GET_CUR_MODNUM()] == 0 )
-	{
-		fchannelmoddata &= ~( 1 << GET_CUR_MODNUM() );
+		c->modvalue[GET_CUR_MODULE_INDEX()] = NULL;
+		GET_CUR_MODULE()->channeldatacnt--;
 	}
 }
 
+/** @brief SetChannelModValue
+ *
+ *  Set module value for a channel
+ *  NeoStats core use only.
+ *
+ *  @param c pointer to channel to set
+ *  @param data pointer to set
+ *
+ *  @return none
+ */
+
 void SetChannelModValue( Channel *c, void *data )
 {
 	if( c )
 	{
-		c->modvalue[GET_CUR_MODNUM()] = data;
-		fchannelmoddata |= ( 1 << GET_CUR_MODNUM() );
-		moddatacnt[GET_CUR_MODNUM()]++;
+		c->modvalue[GET_CUR_MODULE_INDEX()] = data;
+		GET_CUR_MODULE()->channeldatacnt++;
 	}
 }
 
+/** @brief GetChannelModValue
+ *
+ *  Retrieve module value for a channel
+ *  NeoStats core use only.
+ *
+ *  @param c pointer to channel to lookup pointer for
+ *
+ *  @return none
+ */
+
 void *GetChannelModValue( const Channel *c )
 {
 	if( c )
-	{
-		return c->modvalue[GET_CUR_MODNUM()];
-	}
+		return c->modvalue[GET_CUR_MODULE_INDEX()];
 	return NULL;	
 }
 
-void CleanupChannelModdata( int index )
+/** @brief CleanupChannelModdataHandler
+ *
+ *  Cleanup channel moddata
+ *
+ *  @param c pointer to channel
+ *  @param v not used
+ *
+ *  @return none
+ */
+
+static int CleanupChannelModdataHandler( Channel *c, void *v )
 {
-	hnode_t *node;
-	hscan_t scan;
-	Channel *c;
+	if( c->modptr[GET_CUR_MODULE_INDEX()] )
+		ns_free( c->modptr[GET_CUR_MODULE_INDEX()] );		
+	c->modvalue[GET_CUR_MODULE_INDEX()] = NULL;
+	return NS_FALSE;
+}
 
+/** @brief CleanupChannelModdata
+ *
+ *  Clear module data values and pointer left set by an unloaded module
+ *  NeoStats core use only.
+ *
+ *  @param index of module to clear
+ *
+ *  @return none
+ */
+
+void CleanupChannelModdata( int index )
+{
 	SET_SEGV_LOCATION();
-	if (fchannelmoddata & (1 << index)) {
-		if( moddatacnt[index] > 0 ) {
-			nlog( LOG_WARNING, "Cleaning up channels after dirty module!" );
-			hash_scan_begin( &scan, channelhash );
-			while( ( node = hash_scan_next( &scan ) ) != NULL ) {
-				c = hnode_get( node );
-				if( c->modptr[index] ) {
-					ns_free( c->modptr[index] );		
-				}
-				c->modvalue[index] = NULL;
-			}
-		}
-		fchannelmoddata &= ~( 1 << index );
-		moddatacnt[index] = 0;
+	if( GET_CUR_MODULE()->channeldatacnt > 0 )
+	{
+		nlog( LOG_WARNING, "Cleaning up channels after dirty module!" );
+		ProcessChannelList( CleanupChannelModdataHandler, NULL );
 	}
+	GET_CUR_MODULE()->channeldatacnt = 0;
 }

Modified: trunk/src/commands.c
==============================================================================
--- trunk/src/commands.c	(original)
+++ trunk/src/commands.c	Thu Aug 25 04:23:01 2005
@@ -278,8 +278,7 @@
 	cmdnode = hash_lookup( cmd_hash, cmd_ptr->cmd );
 	if( cmdnode ) {
 		dlog( DEBUG3, "deleting command %s from services bot",( ( bot_cmd* )hnode_get( cmdnode ) )->cmd );
-		hash_delete( cmd_hash, cmdnode );
-		hnode_destroy( cmdnode );
+		hash_delete_destroy_node( cmd_hash, cmdnode );
 #if USE_PERL
 		if (IS_PERL_MOD(cmd_ptr->modptr)) {
 			ns_free(cmd_ptr->cmd);
@@ -353,8 +352,7 @@
 	hash_scan_begin( &hs, bot_ptr->botcmds );
 	while( ( cmdnode = hash_scan_next( &hs ) ) != NULL ) {
 		dlog( DEBUG3, "deleting command %s from services bot",( ( bot_cmd* )hnode_get( cmdnode ) )->cmd );
-		hash_delete( bot_ptr->botcmds, cmdnode );
-		hnode_destroy( cmdnode );
+		hash_scan_delete_destroy_node( bot_ptr->botcmds, cmdnode );
 	}
 	/* Destroy command */
 	hash_destroy( bot_ptr->botcmds );

Modified: trunk/src/ctcp.c
==============================================================================
--- trunk/src/ctcp.c	(original)
+++ trunk/src/ctcp.c	Thu Aug 25 04:23:01 2005
@@ -83,7 +83,7 @@
 			len = strlen( cmd->cmd );
 			if( ircstrncasecmp( cmd->cmd, cmdparams->param, len  ) == 0 )
 			{
-				cmdparams->param +=( len + 1 );		
+				cmdparams->param += ( len + 1 );		
 				if( cmd->req_handler ) {
 					cmd->req_handler( cmdparams );
 				}
@@ -107,7 +107,7 @@
 			len = strlen( cmd->cmd );
 			if( ircstrncasecmp( cmd->cmd, cmdparams->param, len  ) == 0 )
 			{
-				cmdparams->param +=( len + 1 );		
+				cmdparams->param += ( len + 1 );		
 				if( cmd->rpl_handler ) {
 					cmd->rpl_handler( cmdparams );
 				}

Modified: trunk/src/dcc.c
==============================================================================
--- trunk/src/dcc.c	(original)
+++ trunk/src/dcc.c	Thu Aug 25 04:23:01 2005
@@ -110,7 +110,7 @@
 
 static void DCCGotAddr( void *data, adns_answer *a )
 {
-	Client *u =( Client * )data;
+	Client *u = ( Client * )data;
 
 	if( a && a->nrrs > 0 && u && a->status == adns_s_ok )
 	{
@@ -157,7 +157,7 @@
 
 	dccnode = list_first( dcclist );
 	while( dccnode ) {
-		todcc =( Client * )lnode_get( dccnode );
+		todcc = ( Client * )lnode_get( dccnode );
 		dcc_write( todcc, buf );
 		dccnode = list_next( dcclist, dccnode );
 	}
@@ -168,8 +168,8 @@
 {
 	static char buf[BUFSIZE];
 	char *cmd;
-	char *line =( char * )rline;
-	Client *dcc =( Client * )arg;
+	char *line = ( char * )rline;
+	Client *dcc = ( Client * )arg;
 	CmdParams *cmdparams;
 
 	strcpy( buf, line );
@@ -183,7 +183,7 @@
 		}
    		*cmd = 0;
    		cmd++;
-		cmdparams =( CmdParams* ) ns_calloc( sizeof( CmdParams ) );
+		cmdparams = ( CmdParams* ) ns_calloc( sizeof( CmdParams ) );
 		cmdparams->source = dcc;
 		if( cmdparams->source ) {
 			cmdparams->target = FindUser( buf + 1 );
@@ -236,7 +236,7 @@
 
 static int dcc_error( int sock_no, void *name )
 {
-	Sock *sock =( Sock * )name;
+	Sock *sock = ( Sock * )name;
 	if( sock->data )
 		DelDCCClient( sock->data );
 	else
@@ -256,7 +256,7 @@
 		len = strlen( cmd->cmd );
 		if( ircstrncasecmp( cmd->cmd, cmdparams->param, len  ) == 0 )
 		{
-			cmdparams->param +=( len + 1 );		
+			cmdparams->param += ( len + 1 );		
 			if( cmd->req_handler )
 				cmd->req_handler( cmdparams );
 			return NS_SUCCESS;
@@ -321,7 +321,7 @@
 	dccnode = list_first( dcclist );
 	while( dccnode )
 	{
-		dcc =( Client * )lnode_get( dccnode );
+		dcc = ( Client * )lnode_get( dccnode );
 		DCCChatDisconnect( dcc );
 		ns_free( dcc );
 		dccnode = list_next( dcclist, dccnode );

Modified: trunk/src/exclude.c
==============================================================================
--- trunk/src/exclude.c	(original)
+++ trunk/src/exclude.c	Thu Aug 25 04:23:01 2005
@@ -212,7 +212,7 @@
 
 static int new_mod_exclude( void *data, int size )
 {
-	new_exclude( excludelists[GET_CUR_MODNUM()], data );
+	new_exclude( excludelists[GET_CUR_MODULE_INDEX()], data );
 	return NS_FALSE;
 }
 
@@ -759,7 +759,7 @@
 		dlog( DEBUG1, "User %s excluded as neostats or module user.", u->name );
 		return NS_TRUE;
 	}
-	return ProcessExcludeList( excludelists[GET_CUR_MODNUM()], ModExcludeUserHandler, ( void * )u );
+	return ProcessExcludeList( excludelists[GET_CUR_MODULE_INDEX()], ModExcludeUserHandler, ( void * )u );
 }
 
 /** @brief ns_do_exclude_server
@@ -828,7 +828,7 @@
 {
 	Exclude *foundexclude;
 
-	foundexclude = FindExclude( excludelists[GET_CUR_MODNUM()], NS_EXCLUDE_SERVER, s->name );
+	foundexclude = FindExclude( excludelists[GET_CUR_MODULE_INDEX()], NS_EXCLUDE_SERVER, s->name );
 	if( foundexclude )
 	{
 		dlog( DEBUG1, "Excluding server %s against %s", s->name, foundexclude->pattern );
@@ -857,7 +857,7 @@
 		dlog( DEBUG1, "Excluding services channel %s", c->name );
 		return NS_TRUE;
 	}
-	foundexclude = FindExclude( excludelists[GET_CUR_MODNUM()], NS_EXCLUDE_CHANNEL, c->name );
+	foundexclude = FindExclude( excludelists[GET_CUR_MODULE_INDEX()], NS_EXCLUDE_CHANNEL, c->name );
 	if( foundexclude )
 	{
 		dlog( DEBUG1, "Excluding channel %s against %s", c->name, foundexclude->pattern );

Modified: trunk/src/hash.c
==============================================================================
--- trunk/src/hash.c	(original)
+++ trunk/src/hash.c	Thu Aug 25 04:23:01 2005
@@ -914,3 +914,21 @@
 	}
 	return hnode_get (hn);
 }
+
+/*
+ * Delete node from hash and free it
+ */
+void hash_delete_destroy_node( hash_t *hash, hnode_t *node )
+{
+	hash_delete( hash, node );
+	hnode_destroy( node );
+}
+
+/*
+ * Delete node from hash and free it
+ */
+void hash_scan_delete_destroy_node( hash_t *hash, hnode_t *node )
+{
+	hash_scan_delete( hash, node );
+	hnode_destroy( node );
+}

Modified: trunk/src/ircprotocol.c
==============================================================================
--- trunk/src/ircprotocol.c	(original)
+++ trunk/src/ircprotocol.c	Thu Aug 25 04:23:01 2005
@@ -75,7 +75,7 @@
 	while( ircd_cmd_ptr->name )
 	{
 		if( !ircstrcasecmp( *ircd_cmd_ptr->name, cmd ) || 
-		 ( ( ircd_srv.protocol & PROTOCOL_TOKEN ) && ircd_cmd_ptr->token && !ircstrcasecmp( *ircd_cmd_ptr->token, cmd ) ) ) {
+		  ( ( ircd_srv.protocol & PROTOCOL_TOKEN ) && ircd_cmd_ptr->token && !ircstrcasecmp( *ircd_cmd_ptr->token, cmd ) ) ) {
 			if( ircd_cmd_ptr->handler )
 			{
 				dlog( DEBUG3, "process_ircd_cmd: running command %s", *ircd_cmd_ptr->name );
@@ -199,9 +199,9 @@
  *    :<source> <command> <param1> <paramN> :<last parameter>
  *    <source> <command> <param1> <paramN> :<last parameter>
  *
- *  @param notused
- *  @param rline
- *  @param len
+ *  @param notused Justin????
+ *  @param rline Justin????
+ *  @param len Justin????
  *
  *  @return NS_SUCCESS if succeeds, NS_FAILURE if not 
  */
@@ -209,7 +209,7 @@
 int parsep10( void *notused, void *rline, size_t len )
 {
 	char origin[64], cmd[64], *coreLine;
-	char *line =( char * )rline;
+	char *line = ( char * )rline;
 	int cmdptr = 0;
 	int ac = 0;
 	char **av = NULL;

Modified: trunk/src/ircrecv.c
==============================================================================
--- trunk/src/ircrecv.c	(original)
+++ trunk/src/ircrecv.c	Thu Aug 25 04:23:01 2005
@@ -1257,7 +1257,7 @@
 		c = FindUser( origin );
 		if( c )
 		{
-			cmdparams =( CmdParams* )ns_calloc( sizeof( CmdParams ) );
+			cmdparams = ( CmdParams* )ns_calloc( sizeof( CmdParams ) );
 			cmdparams->source = c;
 			cmdparams->param = ( char * )message;
 			SendAllModuleEvent( EVENT_GLOBOPS, cmdparams );
@@ -1288,7 +1288,7 @@
 		c = FindUser( origin );
 		if( c )
 		{
-			cmdparams =( CmdParams* )ns_calloc( sizeof( CmdParams ) );
+			cmdparams = ( CmdParams* )ns_calloc( sizeof( CmdParams ) );
 			cmdparams->source = c;
 			cmdparams->param = ( char * )message;
 			SendAllModuleEvent( EVENT_WALLOPS, cmdparams );
@@ -1319,7 +1319,7 @@
 		c = FindUser( origin );
 		if( c )
 		{
-			cmdparams =( CmdParams* )ns_calloc( sizeof( CmdParams ) );
+			cmdparams = ( CmdParams* )ns_calloc( sizeof( CmdParams ) );
 			cmdparams->source = c;
 			cmdparams->param = ( char * )message;
 			SendAllModuleEvent( EVENT_CHATOPS, cmdparams );
@@ -1381,7 +1381,7 @@
 			s->server->ping -= me.ulag;
 		if( IsMe( s ) )
 			me.ulag = me.s->server->ping;
-		cmdparams =( CmdParams* )ns_calloc( sizeof( CmdParams ) );
+		cmdparams = ( CmdParams* )ns_calloc( sizeof( CmdParams ) );
 		cmdparams->source = s;
 		SendAllModuleEvent( EVENT_PONG, cmdparams );
 		ns_free( cmdparams );
@@ -1702,7 +1702,7 @@
 void do_join( const char *nick, const char *chanlist, const char *keys )
 {
 	char *s, *t;
-	t =( char *)chanlist;
+	t = ( char *)chanlist;
 	while( *( s = t ) ) {
 		t = s + strcspn( s, "," );
 		if( *t )
@@ -2145,11 +2145,12 @@
 	do_nickchange( oldnick, newnick, ts );
 }
 
-/** @brief 
+/** @brief do_sethost
  *
- *  
+ *  SETHOST handler
  *
- *  @param 
+ *  @param nick of user to change
+ *  @param host to change to
  *
  *  @return none
  */
@@ -2167,11 +2168,12 @@
 	}
 }
 
-/** @brief 
+/** @brief do_setident
  *
- *  
+ *  SETIDENT handler
  *
- *  @param 
+ *  @param nick of user to change
+ *  @param ident to change to
  *
  *  @return none
  */
@@ -2189,11 +2191,12 @@
 	}
 }
 
-/** @brief 
+/** @brief do_chghost
  *
- *  
+ *  CHGHOST handler
  *
- *  @param 
+ *  @param nick of user to change
+ *  @param host to change to
  *
  *  @return none
  */
@@ -2203,19 +2206,21 @@
 	Client *u;
 
 	u = FindUser( nick );
-	if( u ) {
-		dlog( DEBUG1, "do_chghost: setting host of user %s to %s", nick, host );
-		strlcpy( u->user->hostname,( char *)host, MAXHOST );
-	} else {
+	if( !u )
+	{
 		nlog( LOG_WARNING, "do_chghost: user %s not found", nick );
+		return;
 	}
+	dlog( DEBUG1, "do_chghost: setting host of user %s to %s", nick, host );
+	strlcpy( u->user->hostname,( char *)host, MAXHOST );
 }
 
-/** @brief 
+/** @brief do_chgident
  *
- *  
+ *  CHGIDENT handler
  *
- *  @param 
+ *  @param nick of user to change
+ *  @param ident to change to
  *
  *  @return none
  */
@@ -2225,19 +2230,21 @@
 	Client *u;
 
 	u = FindUser( nick );
-	if( u ) {
-		dlog( DEBUG1, "do_chgident: setting ident of user %s to %s", nick, ident );
-		strlcpy( u->user->username,( char *)ident, MAXHOST );
-	} else {
+	if( !u )
+	{
 		nlog( LOG_WARNING, "do_chgident: user %s not found", nick );
+		return;
 	}
+	dlog( DEBUG1, "do_chgident: setting ident of user %s to %s", nick, ident );
+	strlcpy( u->user->username,( char *)ident, MAXHOST );
 }
 
-/** @brief 
+/** @brief do_chgname
  *
- *  
+ *  CHGNAME handler
  *
- *  @param 
+ *  @param nick of user to change
+ *  @param realname to change to
  *
  *  @return none
  */
@@ -2247,28 +2254,11 @@
 	Client *u;
 
 	u = FindUser( nick );
-	if( u ) {
-		dlog( DEBUG1, "do_chgname: setting realname of user %s to %s", nick, realname );
-		strlcpy( u->info,( char *)realname, MAXHOST );
-	} else {
+	if( !u )
+	{
 		nlog( LOG_WARNING, "do_chgname: user %s not found", nick );
+		return;
 	}
+	dlog( DEBUG1, "do_chgname: setting realname of user %s to %s", nick, realname );
+	strlcpy( u->info,( char *)realname, MAXHOST );
 }
-
-/** @brief 
- *
- *  
- *
- *  @param 
- *
- *  @return none
- */
-
-MODULEFUNC void send_akill( const char *source, const char *host, const char *ident, const char *setby, const unsigned long length, const char *reason, const unsigned long ts );
-MODULEFUNC void send_rakill( const char *source, const char *host, const char *ident );
-MODULEFUNC void send_sqline( const char *source, const char *mask, const char *reason );
-MODULEFUNC void send_unsqline( const char *source, const char *mask );
-MODULEFUNC void send_sgline( const char *source, const char *mask, const char *reason );
-MODULEFUNC void send_unsgline( const char *source, const char *mask );
-MODULEFUNC void send_zline( const char *source, const char *mask, const char *reason );
-MODULEFUNC void send_unzline( const char *source, const char *mask );

Modified: trunk/src/log.c
==============================================================================
--- trunk/src/log.c	(original)
+++ trunk/src/log.c	Thu Aug 25 04:23:01 2005
@@ -179,8 +179,7 @@
 			fclose( logentry->logfile );
 			logentry->logfile = NULL;
 		}
-		hash_scan_delete( logs, hn );
-		hnode_destroy( hn );
+		hash_scan_delete_destroy_node( logs, hn );
 		ns_free( logentry );
 	}
 }

Modified: trunk/src/modules.c
==============================================================================
--- trunk/src/modules.c	(original)
+++ trunk/src/modules.c	Thu Aug 25 04:23:01 2005
@@ -135,7 +135,7 @@
 		ModSynch = ns_dlsym( ( int * ) module_ptr->handle, "ModSynch" );
 		if( ModSynch ) {
 			SET_RUN_LEVEL( module_ptr );
-			err =( *ModSynch )(); 
+			err = ( *ModSynch )(); 
 			RESET_RUN_LEVEL();
 		}
 		SET_SEGV_LOCATION();
@@ -305,7 +305,7 @@
 		return NULL;
 	}
 	/* Allocate module */
-	mod_ptr =( Module * ) ns_calloc( sizeof( Module ) );
+	mod_ptr = ( Module * ) ns_calloc( sizeof( Module ) );
 	dlog( DEBUG1, "Module internal name: %s", infoptr->name );
 	dlog( DEBUG1, "Module description: %s", infoptr->description );
 	mod_ptr->info = infoptr;
@@ -340,7 +340,7 @@
 	SET_SEGV_LOCATION();
 	SET_RUN_LEVEL( mod_ptr );
 	DBAOpenDatabase();
-	err =( *ModInit )(); 
+	err = ( *ModInit )(); 
 	RESET_RUN_LEVEL();
 	if( err < 1 || IsModuleError( mod_ptr ) ) {
 		load_module_error( u, modfilename, __( "See %s.log for further information.",u ), mod_ptr->info->name );
@@ -363,7 +363,7 @@
 		}
 	}
 	cmd = ns_calloc( sizeof( CmdParams ) );
-	cmd->param =( char* )infoptr->name;
+	cmd->param = ( char* )infoptr->name;
 	SendAllModuleEvent( EVENT_MODULELOAD, cmd );
 	ns_free( cmd );
 	if( u ) {
@@ -530,8 +530,7 @@
 	 * during signoff 
 	 */
 	dlog( DEBUG1, "Deleting Module %s from Hash", modname );
-	hash_delete( modulehash, modnode );		
-	hnode_destroy( modnode );
+	hash_delete_destroy_node( modulehash, modnode );		
 
 	/* now determine if its perl, or standard module */
 	if( IS_STD_MOD( mod_ptr ) ) {
@@ -560,7 +559,7 @@
 		FiniModExcludes( mod_ptr );
 	}
 	cmdparams = ns_calloc( sizeof( CmdParams ) );
-	cmdparams->param =( char* )modname;
+	cmdparams->param = ( char* )modname;
 	SendAllModuleEvent( EVENT_MODULEUNLOAD, cmdparams );
 	ns_free( cmdparams );
 	RESET_RUN_LEVEL();
@@ -576,6 +575,10 @@
 		unload_perlmod( mod_ptr );
 #endif
 	}
+	/* Cleanup moddata */
+	CleanupUserModdata( moduleindex );
+	CleanupServerModdata( moduleindex );
+	CleanupChannelModdata( moduleindex );
 	RESET_RUN_LEVEL();
 	ns_free( mod_ptr );
 	/* free the module number */
@@ -583,10 +586,6 @@
 		dlog( DEBUG1, "Free %d from Module Numbers", moduleindex );
 		ModList[moduleindex] = NULL;
 	}
-	/* Cleanup moddata */
-	CleanupUserModdata( moduleindex );
-	CleanupServerModdata( moduleindex );
-	CleanupChannelModdata( moduleindex );
 	return NS_SUCCESS;
 }
 
@@ -630,7 +629,7 @@
 		switch( set_ptr->type ) {
 			case SET_TYPE_BOOLEAN:
 				if( DBAFetchConfigBool( set_ptr->option, set_ptr->varptr ) != NS_SUCCESS ) {
-					*( int * )set_ptr->varptr =( int )set_ptr->defaultval;
+					*( int * )set_ptr->varptr = ( int )set_ptr->defaultval;
 					DBAStoreConfigBool( set_ptr->option, set_ptr->varptr );
 				}
 				if( set_ptr->handler ) {
@@ -639,7 +638,7 @@
 				break;
 			case SET_TYPE_INT:
 				if( DBAFetchConfigInt( set_ptr->option, set_ptr->varptr ) != NS_SUCCESS ) {
-					*( int * )set_ptr->varptr =( int )set_ptr->defaultval;
+					*( int * )set_ptr->varptr = ( int )set_ptr->defaultval;
 					DBAStoreConfigInt( set_ptr->option, set_ptr->varptr );
 				}
 				if( set_ptr->handler ) {

Modified: trunk/src/nsdba.c
==============================================================================
--- trunk/src/nsdba.c	(original)
+++ trunk/src/nsdba.c	Thu Aug 25 04:23:01 2005
@@ -155,13 +155,11 @@
 			tbe = (tableentry *) hnode_get( tnode );
 			dlog(DEBUG5, "Closing Table %s", tbe->name);
 			DBACloseTable( tbe->table );
-			hash_scan_delete( dbe->tablehash, tnode );
-			hnode_destroy( tnode );
+			hash_scan_delete_destroy_node( dbe->tablehash, tnode );
 			ns_free( tbe );
 		}
 		hash_destroy( dbe->tablehash );
-		hash_scan_delete( dbhash, node );
-		hnode_destroy( node );
+		hash_scan_delete_destroy_node( dbhash, node );
 		ns_free( dbe );
 	}
 	hash_destroy( dbhash );
@@ -228,13 +226,11 @@
 			tbe = (tableentry *) hnode_get( tnode );
 			dlog(DEBUG5, "Closing Table %s", tbe->name);
 			DBMCloseTable( tbe->handle );
-			hash_delete( dbe->tablehash, tnode );
-			hnode_destroy( tnode );
+			hash_scan_delete_destroy_node( dbe->tablehash, tnode );
 			ns_free( tbe );
 		}
 		hash_destroy( dbe->tablehash );
-		hash_delete( dbhash, node );
-		hnode_destroy( node );
+		hash_delete_destroy_node( dbhash, node );
 		ns_free( dbe );
 	}
 	return NS_SUCCESS;
@@ -337,8 +333,7 @@
 	{
 		tbe = (tableentry *)hnode_get( node );
 		DBMCloseTable( tbe->handle );
-		hash_delete( dbhash, node );
-		hnode_destroy( node );
+		hash_delete_destroy_node( dbhash, node );
 		ns_free( tbe );
 	}
 	return NS_SUCCESS;

Modified: trunk/src/servers.c
==============================================================================
--- trunk/src/servers.c	(original)
+++ trunk/src/servers.c	Thu Aug 25 04:23:01 2005
@@ -23,6 +23,10 @@
 ** $Id$
 */
 
+/*  TODO:
+ *  - Deprecate GetServerHash()
+ */
+
 #include "neostats.h"
 #include "protocol.h"
 #include "exclude.h"
@@ -34,359 +38,573 @@
 #define SERVER_TABLE_SIZE	-1
 
 static hash_t *serverhash;
-/** @brief Module data flags */
-static unsigned int fservermoddata = 0;
 
-static unsigned int moddatacnt[NUM_MODULES];
+/** @brief new_server
+ *
+ *  Create a new server Client struct
+ *  NeoStats core use only.
+ *
+ *  @param name of server to create
+ *
+ *  @return pointer to Client or NULL if fails
+ */
 
-static Client *
-new_server (const char *name)
+static Client * new_server( const char *name )
 {
 	Client *s;
 
 	SET_SEGV_LOCATION();
-	if (hash_isfull (serverhash)) {
-		nlog (LOG_CRITICAL, "new_ban: server hash is full");
+	if( hash_isfull( serverhash ) )
+	{
+		nlog( LOG_CRITICAL, "new_ban: server hash is full" );
 		return NULL;
 	}
-	dlog(DEBUG2, "new_server: %s", name);
-	s = ns_calloc (sizeof (Client));
-	strlcpy (s->name, name, MAXHOST);
-	s->server = ns_calloc (sizeof (Server));
-	hnode_create_insert (serverhash, s, s->name);
+	dlog( DEBUG2, "new_server: %s", name );
+	s = ns_calloc( sizeof( Client ) );
+	strlcpy( s->name, name, MAXHOST );
+	s->server = ns_calloc( sizeof( Server ) );
+	hnode_create_insert( serverhash, s, s->name );
 	me.servercount++;
 	return s;
 }
 
-Client *
-AddServer (const char *name, const char *uplink, const char* hops, const char *numeric, const char *infoline)
+/** @brief AddServer
+ *
+ *  Add a user to NeoStats
+ *  NeoStats core use only.
+ *
+ *  @param name
+ *  @param uplink
+ *  @param hops
+ *  @param numeric
+ *  @param infoline
+ *
+ *  @return pointer to Client or NULL if fails
+ */
+
+Client *AddServer( const char *name, const char *uplink, const char *hops, const char *numeric, const char *infoline )
 {
-	CmdParams * cmdparams;
+	CmdParams *cmdparams;
 	Client *s;
 
-	dlog(DEBUG1, "AddServer: %s", name);
-	s = new_server (name);
-	if(hops) {
-		s->server->hops = atoi (hops);
-	}
-	if (uplink) {
-		strlcpy (s->uplinkname, uplink, MAXHOST);
-		s->uplink = FindServer (uplink);
+	dlog( DEBUG1, "AddServer: %s", name );
+	s = new_server( name );
+	if( hops )
+		s->server->hops = atoi( hops );
+	if( uplink )
+	{
+		strlcpy( s->uplinkname, uplink, MAXHOST );
+		s->uplink = FindServer( uplink );
 	} 
-	if (infoline) {
-		strlcpy (s->info, infoline, MAXINFO);
-	}
-	if (numeric) {
-		s->server->numeric =  atoi(numeric);
-	}
+	if( infoline )
+		strlcpy( s->info, infoline, MAXINFO );
+	if( numeric )
+		s->server->numeric =  atoi( numeric );
 	s->tsconnect = me.now;
-	if (!ircstrcasecmp(name, me.name)) {
+	if( !ircstrcasecmp( name, me.name ) )
 		s->flags |= CLIENT_FLAG_ME;
-	}
 	/* check exclusions */
-	ns_do_exclude_server(s);
+	ns_do_exclude_server( s );
 	/* run the module event for a new server. */
-	cmdparams = (CmdParams*) ns_calloc (sizeof(CmdParams));
+	cmdparams = ( CmdParams * ) ns_calloc( sizeof( CmdParams ) );
 	cmdparams->source = s;
-	SendAllModuleEvent (EVENT_SERVER, cmdparams);
-	ns_free (cmdparams);
-	return(s);
-}
+	SendAllModuleEvent( EVENT_SERVER, cmdparams );
+	ns_free( cmdparams );
+	return( s );
+}
+
+/** @brief del_server_leaves
+ *
+ *  Remove a all leaves of this server from NeoStats for use with NOQUIT
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to hub Client to remove
+ *
+ *  @return none
+ */
 
-static void del_server_leaves (Client * hub)
+static void del_server_leaves( Client * hub )
 {
 	Client *s;
 	hscan_t ss;
 	hnode_t *sn;
 
-	dlog(DEBUG1, "del_server_leaves: %s", hub->name);
-	hash_scan_begin (&ss, serverhash);
-	while ((sn = hash_scan_next (&ss)) != NULL) {
-		s = hnode_get (sn);
-		if(ircstrcasecmp (hub->name, s->uplinkname) == 0) {
-			dlog(DEBUG1, "del_server_leaves: server %s had uplink %s", s->name, hub->name);
-			DelServer (s->name, hub->name);
+	dlog( DEBUG1, "del_server_leaves: %s", hub->name );
+	hash_scan_begin( &ss, serverhash );
+	while( ( sn = hash_scan_next( &ss ) ) != NULL )
+	{
+		s = hnode_get( sn );
+		if( ircstrcasecmp( hub->name, s->uplinkname ) == 0 )
+		{
+			dlog( DEBUG1, "del_server_leaves: server %s had uplink %s", s->name, hub->name );
+			DelServer( s->name, hub->name );
 		}
 	}
 }
 
-void 
-DelServer (const char *name, const char* reason)
+/** @brief DelServer
+ *
+ *  Remove a server from NeoStats
+ *  NeoStats core use only.
+ *
+ *  @param name of server to remove
+ *  @param reason
+ *
+ *  @return none
+ */
+
+void DelServer( const char *name, const char *reason )
 {
-	CmdParams * cmdparams;
+	CmdParams *cmdparams;
 	Client *s;
 	hnode_t *sn;
 
-	dlog(DEBUG1, "DelServer: %s", name);
-	sn = hash_lookup (serverhash, name);
-	if (!sn) {
-		nlog (LOG_WARNING, "DelServer: squit from unknown server %s", name);
+	dlog( DEBUG1, "DelServer: %s", name );
+	sn = hash_lookup( serverhash, name );
+	if( !sn )
+	{
+		nlog( LOG_WARNING, "DelServer: squit from unknown server %s", name );
 		return;
 	}
-	s = hnode_get (sn);
-	if(ircd_srv.protocol & PROTOCOL_NOQUIT) {
-		del_server_leaves (s);
-		QuitServerUsers (s);
+	s = hnode_get( sn );
+	if( ircd_srv.protocol & PROTOCOL_NOQUIT )
+	{
+		del_server_leaves( s );
+		QuitServerUsers( s );
 	}
 	me.servercount--;
 	/* run the event for delete server */
-	cmdparams = (CmdParams*) ns_calloc (sizeof(CmdParams));
+	cmdparams = ( CmdParams * ) ns_calloc( sizeof( CmdParams ) );
 	cmdparams->source = s;
-	if(reason) {
-		cmdparams->param = (char*)reason;
-	}
-	SendAllModuleEvent (EVENT_SQUIT, cmdparams);
-	ns_free (cmdparams);
-	hash_delete (serverhash, sn);
-	hnode_destroy (sn);
-	ns_free (s->server);
-	ns_free (s);
-}
+	if( reason )
+		cmdparams->param = ( char *)reason;
+	SendAllModuleEvent( EVENT_SQUIT, cmdparams );
+	ns_free( cmdparams );
+	hash_delete_destroy_node( serverhash, sn );
+	ns_free( s->server );
+	ns_free( s );
+}
+
+/** @brief find_server_base64
+ *
+ *  Find server based on base 64 representation
+ *  NeoStats core use only.
+ *
+ *  @param num numeric to find
+ *
+ *  @return pointer to Client or NULL if fails
+ */
 
-Client *
-find_server_base64 (const char *num)
+Client *find_server_base64( const char *num )
 {
 	Client *s;
 	hscan_t ss;
 	hnode_t *sn;
 
-	hash_scan_begin (&ss, serverhash);
-	while ((sn = hash_scan_next (&ss)) != NULL) {
-		s = hnode_get (sn);
-		if(strncmp(s->name64, num, BASE64SERVERSIZE) == 0) {
-			dlog(DEBUG1, "find_server_base64: %s -> %s", num, s->name);
+	hash_scan_begin( &ss, serverhash );
+	while( ( sn = hash_scan_next( &ss ) ) != NULL )
+	{
+		s = hnode_get( sn );
+		if( strncmp( s->name64, num, BASE64SERVERSIZE ) == 0 )
+		{
+			dlog( DEBUG1, "find_server_base64: %s -> %s", num, s->name );
 			return s;
 		}
 	}
-	dlog(DEBUG3, "find_server_base64: %s not found!", num);
+	dlog( DEBUG3, "find_server_base64: %s not found!", num );
 	return NULL;
 }
 
-Client *FindServer (const char *name)
+/** @brief FindServer
+ *
+ *  Find server based on name
+ *  NeoStats core use only.
+ *
+ *  @param name to find
+ *
+ *  @return pointer to Client or NULL if fails
+ */
+
+Client *FindServer( const char *name )
 {
 	hnode_t *sn;
 
-	sn = hash_lookup (serverhash, name);
-	if (sn) {
-		return (Client *) hnode_get (sn);
-	}
-	dlog(DEBUG3, "FindServer: %s not found!", name);
+	sn = hash_lookup( serverhash, name );
+	if( sn )
+		return( Client * ) hnode_get( sn );
+	dlog( DEBUG3, "FindServer: %s not found!", name );
 	return NULL;
 }
 
-static void 
-dumpserver (Client *s)
+/** @brief dumpserver
+ *
+ *  Report server information
+ *  NeoStats core use only.
+ *
+ *  @param s pointer to server
+ *  @param v not used
+ *
+ *  @return none
+ */
+
+static int dumpserver( Client *s, void *v )
 {
 	/* Calculate uptime as uptime from server plus uptime of NeoStats */
-	time_t uptime = s->server->uptime  + (me.now - me.ts_boot);
+	time_t uptime = s->server->uptime  + ( me.now - me.ts_boot );
 
-	if(ircd_srv.protocol & PROTOCOL_B64SERVER) {
-		irc_chanalert (ns_botptr, _("Server: %s (%s)"), s->name, s->name64);
-	} else {
-		irc_chanalert (ns_botptr, _("Server: %s"), s->name);
-	}
-	irc_chanalert (ns_botptr, _("Version: %s"), s->version);
-	irc_chanalert (ns_botptr, _("Uptime:  %ld day%s, %02ld:%02ld:%02ld"), ( uptime / TS_ONE_DAY ), (uptime / TS_ONE_DAY == 1) ? "" : "s", ((uptime / TS_ONE_HOUR) % 24), ((uptime / TS_ONE_MINUTE) % TS_ONE_MINUTE), (uptime % 60) );
-	irc_chanalert (ns_botptr, _("Flags:   %x"), s->flags);
-	irc_chanalert (ns_botptr, _("Uplink:  %s"), s->uplink ? s->uplink->name : "");
-	irc_chanalert (ns_botptr, "========================================");
-}
+	if( ircd_srv.protocol & PROTOCOL_B64SERVER )
+		irc_chanalert( ns_botptr, _( "Server: %s (%s)" ), s->name, s->name64 );
+	else
+		irc_chanalert( ns_botptr, _( "Server: %s" ), s->name );
+	irc_chanalert( ns_botptr, _( "Version: %s" ), s->version );
+	irc_chanalert( ns_botptr, _( "Uptime:  %ld day%s, %02ld:%02ld:%02ld" ),( uptime / TS_ONE_DAY ),( uptime / TS_ONE_DAY == 1 ) ? "" : "s",( ( uptime / TS_ONE_HOUR ) % 24 ),( ( uptime / TS_ONE_MINUTE ) % TS_ONE_MINUTE ),( uptime % 60 ) );
+	irc_chanalert( ns_botptr, _( "Flags:   %x" ), s->flags );
+	irc_chanalert( ns_botptr, _( "Uplink:  %s" ), s->uplink ? s->uplink->name : "" );
+	irc_chanalert( ns_botptr, "========================================" );
+	return NS_FALSE;
+}
+
+/** @brief ListServers
+ *
+ *  Report current server list
+ *  NeoStats core use only.
+ *
+ *  @param name
+ *
+ *  @return none
+ */
 
-void
-ListServers (const char *name)
+void ListServers( const char *name )
 {
-	Client *s;
-	hscan_t ss;
-	hnode_t *sn;
+	irc_chanalert( ns_botptr, _( "===============SERVERLIST===============" ) );
+	if( name )
+	{
+		Client *s;
 
-	irc_chanalert (ns_botptr, _("===============SERVERLIST==============="));
-	if (!name) {
-		hash_scan_begin (&ss, serverhash);
-		while ((sn = hash_scan_next (&ss)) != NULL) {
-			s = hnode_get (sn);
-			dumpserver (s);
-		}
-	} else {
-		s = FindServer (name);
-		if (s) {
-			dumpserver (s);
-		} else {
-			irc_chanalert (ns_botptr, _("ListServers: can't find server %s"), name);
-		}
+		s = FindServer( name );
+		if( s )
+			dumpserver( s, NULL );
+		else
+			irc_chanalert( ns_botptr, _( "ListServers: can't find server %s" ), name );
+		return;
 	}
+	ProcessServerList( dumpserver, NULL );
 }
 
+/** @brief InitServers
+ *
+ *  Init server subsystem
+ *  NeoStats core use only.
+ *
+ *  @param none
+ *
+ *  @return NS_SUCCESS if succeeds, NS_FAILURE if not 
+ */
 
-
-int 
-InitServers (void)
+int InitServers( void )
 {
 	Client* s;
 	
-	serverhash = hash_create (SERVER_TABLE_SIZE, 0, 0);
-	if (!serverhash) {
-		nlog (LOG_CRITICAL, "Unable to create server hash");
+	serverhash = hash_create( SERVER_TABLE_SIZE, 0, 0 );
+	if( !serverhash )
+	{
+		nlog( LOG_CRITICAL, "Unable to create server hash" );
 		return NS_FAILURE;
 	}
-	s = AddServer (me.name, NULL, 0, NULL, me.infoline);
+	s = AddServer( me.name, NULL, 0, NULL, me.infoline );
 	strlcpy( s->version, me.version, VERSIONSIZE );
 	return NS_SUCCESS;
 }
 
 
-void
-PingServers (void)
-{
-	Client *s;
-	hscan_t ss;
-	hnode_t *sn;
+/** @brief PingServer
+ *
+ *  Ping server
+ *  NeoStats core use only.
+ *
+ *  @param s pointer to server
+ *  @param v not used
+ *
+ *  @return none
+ */
+
+static int PingServer( Client *s, void *v )
+{
+	if( IsMe( s ) )
+		s->server->ping = 0;
+	else
+		irc_ping( me.name, me.name, s->name );
+	return NS_FALSE;
+}
+
+/** @brief PingServers
+ *
+ *  Ping each server
+ *  NeoStats core use only.
+ *
+ *  @param none
+ *
+ *  @return none
+ */
 
-	if(!IsNeoStatsSynched())
+void PingServers( void )
+{
+	if( !IsNeoStatsSynched() )
 		return;
-	dlog(DEBUG3, "Sending pings...");
+	dlog( DEBUG3, "Sending pings..." );
 	me.ulag = 0;
-	hash_scan_begin (&ss, serverhash);
-	while ((sn = hash_scan_next (&ss)) != NULL) {
-		s = hnode_get (sn);
-		if( IsMe( s ) ) {
-			s->server->ping = 0;
-			continue;
-		}
-		irc_ping (me.name, me.name, s->name);
-	}
+	ProcessServerList( PingServer, NULL );
 }
 
-void 
-FiniServers (void)
+/** @brief FiniServers
+ *
+ *  Fini server subsystem
+ *  NeoStats core use only.
+ *
+ *  @param none
+ *
+ *  @return none
+ */
+
+void FiniServers( void )
 {
 	Client *s;
 	hnode_t *sn;
 	hscan_t hs;
 
-	hash_scan_begin(&hs, serverhash);
-	while ((sn = hash_scan_next(&hs)) != NULL ) {
-		s = hnode_get (sn);
-		hash_delete (serverhash, sn);
-		hnode_destroy (sn);
-		ns_free (s->server);
-		ns_free (s);
-	}
-	hash_destroy(serverhash);
-}
+	hash_scan_begin( &hs, serverhash );
+	while( ( sn = hash_scan_next( &hs ) ) != NULL )
+	{
+		s = hnode_get( sn );
+		hash_scan_delete_destroy_node( serverhash, sn );
+		ns_free( s->server );
+		ns_free( s );
+	}
+	hash_destroy( serverhash );
+}
+
+/** @brief ProcessServerList
+ *
+ *  Walk server list and call handler for each server
+ *  NeoStats core use only.
+ *
+ *  @param handler to call
+ *  @param v optional pointer
+ *
+ *  @return NS_SUCCESS
+ */
 
-int ProcessServerList (ServerListHandler handler, void *v)
+int ProcessServerList( ServerListHandler handler, void *v )
 {
 	hnode_t *node;
 	hscan_t scan;
 	Client *ss;
 
 	SET_SEGV_LOCATION();
-	hash_scan_begin(&scan, serverhash);
-	while ((node = hash_scan_next(&scan)) != NULL) {
-		ss = hnode_get(node);
-		if (handler (ss, v) == NS_TRUE)
+	hash_scan_begin( &scan, serverhash );
+	while( ( node = hash_scan_next( &scan ) ) != NULL )
+	{
+		ss = hnode_get( node );
+		if( handler( ss, v ) == NS_TRUE )
 			break;
 	}
 	return NS_SUCCESS;
 }
 
-void RequestServerUptimes (void)
-{
-	Client *s;
-	hscan_t ss;
-	hnode_t *sn;
-
-	hash_scan_begin (&ss, serverhash);
-	while ((sn = hash_scan_next (&ss)) != NULL) {
-		s = hnode_get (sn);
-		if( !IsMe( s ) ) {
-			irc_stats( ns_botptr->u->name, 'u', s->name );
-		}
-	}
-}
+/** @brief RequestServerUptime
+ *
+ *  Request uptime of a server
+ *
+ *  @param s pointer to server
+ *  @param v not used
+ *
+ *  @return none
+ */
+
+static int RequestServerUptime( Client *s, void *v )
+{
+	if( !IsMe( s ) )
+		irc_stats( ns_botptr->u->name, 'u', s->name );
+	return NS_FALSE;
+}
+
+/** @brief RequestServerUptimes
+ *
+ *  Request uptime of all servers
+ *  NeoStats core use only.
+ *
+ *  @param none
+ *
+ *  @return none
+ */
+
+void RequestServerUptimes( void )
+{
+	ProcessServerList( RequestServerUptime, NULL );
+}
+
+/** @brief GetServerHash
+ *
+ *  GetServerHash
+ *  NeoStats core use only.
+ *
+ *  @param none
+ *
+ *  @return server hash
+ */
 
-hash_t *GetServerHash (void)
+hash_t *GetServerHash( void )
 {
 	return serverhash;
 }
 
-void *AllocServerModPtr (Client* s, int size)
+/** @brief AllocServerModPtr
+ *
+ *  Allocate memory for a module pointer for a server
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to client to add pointer for
+ *  @param size to allocate
+ *
+ *  @return pointer to allocated memory
+ */
+
+void *AllocServerModPtr( Client* s, int size )
 {
 	void *ptr;
-	ptr = ns_calloc (size);
-	s->modptr[GET_CUR_MODNUM()] = ptr;
-	fservermoddata |= (1 << GET_CUR_MODNUM());
-	moddatacnt[GET_CUR_MODNUM()]++;
+	ptr = ns_calloc( size );
+	s->modptr[GET_CUR_MODULE_INDEX()] = ptr;
+	GET_CUR_MODULE()->serverdatacnt++;
 	return ptr;
 }
 
-void FreeServerModPtr (Client* s)
+/** @brief FreeServerModPtr
+ *
+ *  Free memory for a module pointer for a server
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to client to free pointer for
+ *
+ *  @return none
+ */
+
+void FreeServerModPtr( Client* s )
 {
-	ns_free (s->modptr[GET_CUR_MODNUM()]);
-	moddatacnt[GET_CUR_MODNUM()]--;
-	if (moddatacnt[GET_CUR_MODNUM()] == 0)
+	if( s )
 	{
-		fservermoddata &= ~(1 << GET_CUR_MODNUM());
+		ns_free( s->modptr[GET_CUR_MODULE_INDEX()] );
+		GET_CUR_MODULE()->serverdatacnt--;
 	}
 }
 
-void* GetServerModPtr (const Client* s)
+/** @brief GetServerModPtr
+ *
+ *  Retrieve module pointer for a server
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to client to lookup pointer for
+ *
+ *  @return none
+ */
+
+void* GetServerModPtr( const Client* s )
 {
-	return s->modptr[GET_CUR_MODNUM()];
+	if( s )
+		return s->modptr[GET_CUR_MODULE_INDEX()];
+	return NULL;	
 }
 
-void ClearServerModValue (Client* s)
+/** @brief ClearServerModValue
+ *
+ *  Clear module value for a server
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to client to clear
+ *
+ *  @return none
+ */
+
+void ClearServerModValue( Client* s )
 {
-	if (s)
-	{
-		s->modvalue[GET_CUR_MODNUM()] = NULL;
-		moddatacnt[GET_CUR_MODNUM()]--;
-	}
-	if (moddatacnt[GET_CUR_MODNUM()] == 0)
+	if( s )
 	{
-		fservermoddata &= ~(1 << GET_CUR_MODNUM());
+		s->modvalue[GET_CUR_MODULE_INDEX()] = NULL;
+		GET_CUR_MODULE()->serverdatacnt--;
 	}
 }
 
-void SetServerModValue (Client* s, void *data)
+/** @brief SetServerModValue 
+ *
+ *  Set module value for a server
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to client to set
+ *  @param data pointer to set
+ *
+ *  @return none
+ */
+
+void SetServerModValue( Client* s, void *data )
 {
-	if (s)
+	if( s )
 	{
-		s->modvalue[GET_CUR_MODNUM()] = data;
-		fservermoddata |= (1 << GET_CUR_MODNUM());
-		moddatacnt[GET_CUR_MODNUM()]++;
+		s->modvalue[GET_CUR_MODULE_INDEX()] = data;
+		GET_CUR_MODULE()->serverdatacnt++;
 	}
 }
 
-void *GetServerModValue (const Client* s)
+/** @brief GetServerModValue 
+ *
+ *  Retrieve module value for a server
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to client to lookup pointer for
+ *
+ *  @return none
+ */
+
+void *GetServerModValue( const Client* s )
 {
-	if (s)
-	{
-		return s->modvalue[GET_CUR_MODNUM()];
-	}
+	if( s )
+		return s->modvalue[GET_CUR_MODULE_INDEX()];
 	return NULL;	
 }
 
-void CleanupServerModdata (int index)
-{
-	hnode_t *node;
-	hscan_t scan;
-	Client *s;
+/** @brief CleanupServerModdataHandler
+ *
+ *  Cleanup server moddata
+ *
+ *  @param s pointer to server
+ *  @param v not used
+ *
+ *  @return none
+ */
+
+static int CleanupServerModdataHandler( Client *s, void *v )
+{
+	if( s->modptr[GET_CUR_MODULE_INDEX()] )
+		ns_free( s->modptr[GET_CUR_MODULE_INDEX()] );		
+	s->modvalue[GET_CUR_MODULE_INDEX()] = NULL;
+	return NS_FALSE;
+}
+
+/** @brief CleanupServerModdata
+ *
+ *  Clear module data values and pointer left set by an unloaded module
+ *  NeoStats core use only.
+ *
+ *  @param index of module to clear
+ *
+ *  @return none
+ */
 
+void CleanupServerModdata( int index )
+{
 	SET_SEGV_LOCATION();
-	if (fservermoddata & (1 << index)) {
-		hash_scan_begin(&scan, serverhash);
-		if (moddatacnt[index] > 0) {
-			nlog (LOG_WARNING, "Cleaning up servers after dirty module!");
-			while ((node = hash_scan_next(&scan)) != NULL) {
-				s = hnode_get(node);
-				if (s->modptr[index]) {
-					ns_free (s->modptr[index]);		
-				}
-				s->modvalue[index] = NULL;
-			}
-		}
-		fservermoddata &= ~(1 << index);	
-		moddatacnt[index] = 0;
+	if( GET_CUR_MODULE()->serverdatacnt > 0 )
+	{
+		nlog( LOG_WARNING, "Cleaning up servers after dirty module!" );
+		ProcessServerList( CleanupServerModdataHandler, NULL );
 	}
+	GET_CUR_MODULE()->serverdatacnt = 0;
 }

Modified: trunk/src/settings.c
==============================================================================
--- trunk/src/settings.c	(original)
+++ trunk/src/settings.c	Thu Aug 25 04:23:01 2005
@@ -545,8 +545,7 @@
 	
 	setnode = hash_lookup( set_hash, set_ptr->option );
 	if( setnode ) {
-		hash_delete( set_hash, setnode );
-		hnode_destroy( setnode );
+		hash_delete_destroy_node( set_hash, setnode );
 		return NS_SUCCESS;
 	}
 	return NS_FAILURE;
@@ -636,8 +635,7 @@
 	/* Cycle through command hash and delete each command */
 	hash_scan_begin( &hs, bot_ptr->botsettings );
 	while( ( setnode = hash_scan_next( &hs ) ) != NULL ) {
-		hash_delete( bot_ptr->botsettings, setnode );
-		hnode_destroy( setnode );
+		hash_scan_delete_destroy_node( bot_ptr->botsettings, setnode );
 	}
 	/* Destroy command */
 	hash_destroy( bot_ptr->botsettings );

Modified: trunk/src/sock.c
==============================================================================
--- trunk/src/sock.c	(original)
+++ trunk/src/sock.c	Thu Aug 25 04:23:01 2005
@@ -914,8 +914,7 @@
 	if( ( sn = hash_lookup( sockethash, sock->name ) ) != NULL ) {
 		sock = hnode_get( sn );
 		dlog( DEBUG2, "DelSock: deleting socket %s from module %s", sock->name, sock->moduleptr->info->name );
-		hash_delete( sockethash, sn );
-		hnode_destroy( sn );
+		hash_delete_destroy_node( sockethash, sn );
 		ns_free( sock );
 		return NS_SUCCESS;
 	}
@@ -945,8 +944,7 @@
 		{
 			dlog( DEBUG1, "del_sockets: deleting socket %s from module %s", sock->name, mod_ptr->info->name );
    			CloseSock( sock );
-			hash_scan_delete( sockethash, socknode );
-			hnode_destroy( socknode );
+			hash_scan_delete_destroy_node( sockethash, socknode );
 			ns_free( sock );
 		}
 	}

Modified: trunk/src/timer.c
==============================================================================
--- trunk/src/timer.c	(original)
+++ trunk/src/timer.c	Thu Aug 25 04:23:01 2005
@@ -30,6 +30,7 @@
 #include "log.h"
 #include "timer.h"
 #include "event.h"
+#include "main.h"
 
 #define TIMER_TABLE_SIZE	300	/* Number of Timers */
 
@@ -39,362 +40,427 @@
 static int midnight = 0;
 static time_t lastservertimesync = 0;
 
-static int is_midnight (void);
-static void run_mod_timers (int ismidnight);
+static int is_midnight( void );
+static void run_mod_timers( int ismidnight );
 
 static struct event *timers;
 
+/** @brief InitTimers
+ *
+ *  Init timer subsystem
+ *  NeoStats core use only.
+ *
+ *  @param none
+ *
+ *  @return NS_SUCCESS if succeeds, NS_FAILURE if not 
+ */
 
-int InitTimers (void)
+int InitTimers( void )
 {
 	struct timeval tv;
 
-	timerhash = hash_create (TIMER_TABLE_SIZE, 0, 0);
-	if(!timerhash) {
-		nlog (LOG_CRITICAL, "Unable to create timer hash");
+	timerhash = hash_create( TIMER_TABLE_SIZE, 0, 0 );
+	if( !timerhash )
+	{
+		nlog( LOG_CRITICAL, "Unable to create timer hash" );
 		return NS_FAILURE;
 	}
-	timers = os_malloc(sizeof(struct event));
+	timers = os_malloc( sizeof( struct event ) );
 
-	timerclear(&tv);
+	timerclear( &tv );
 	tv.tv_sec = 1;
 
-	event_set(timers, 0, EV_TIMEOUT|EV_PERSIST, CheckTimers_cb, NULL);
-	event_add(timers, &tv);
+	event_set( timers, 0, EV_TIMEOUT|EV_PERSIST, CheckTimers_cb, NULL );
+	event_add( timers, &tv );
 
 	return NS_SUCCESS;
 }
 
-void FiniTimers (void)
+/** @brief FiniTimers
+ *
+ *  Fini timer subsystem
+ *  NeoStats core use only.
+ *
+ *  @param none
+ *
+ *  @return none
+ */
+
+void FiniTimers( void )
 {
-	event_del(timers);
-	os_free(timers);
-	hash_destroy (timerhash);
+	event_del( timers );
+	os_free( timers );
+	hash_destroy( timerhash );
 }
 
-void
-CheckTimers_cb (int notused, short event, void *arg)
+/** @brief CheckTimers_cb
+ *
+ *  CheckTimers_cb
+ *  NeoStats core use only.
+ *
+ *  @param notused Justin????
+ *  @param event Justin????
+ *  @param arg Justin????
+ *
+ *  @return none
+ */
+
+void CheckTimers_cb( int notused, short event, void *arg )
 {
 	struct timeval tv;
 
 
 	SET_SEGV_LOCATION();
-	timerclear(&tv);
+	timerclear( &tv );
 	tv.tv_sec = 1;
-	if (me.now - me.tslastping > nsconfig.pingtime) {
-		PingServers ();
+	if( me.now - me.tslastping > nsconfig.pingtime )
+	{
+		PingServers();
 		me.tslastping = me.now;
 		/* flush log files */
-		fflush (NULL);
+		fflush( NULL );
 	}
-	if (IsNeoStatsSynched() && nsconfig.setservertimes) {
-		if((me.now - lastservertimesync) > nsconfig.setservertimes) {
+	if( IsNeoStatsSynched() && nsconfig.setservertimes )
+	{
+		if( ( me.now - lastservertimesync ) > nsconfig.setservertimes )
+		{
 			/* The above check does not need to be exact, but 
 			   setting times ought to be so reset me.now */
-			me.now = time (NULL);
-			irc_svstime (ns_botptr, NULL, me.now);
+			update_time_now();
+			irc_svstime( ns_botptr, NULL, me.now );
 			lastservertimesync = me.now;
 		}
 	}
-	if (is_midnight () == 1 && midnight == 0) {
-		dlog (DEBUG1, "Its midnight!!! -> %s", sctime (me.now));
-		run_mod_timers (1);
-		ResetLogs ();
+	if( is_midnight() && midnight == 0 )
+	{
+		dlog( DEBUG1, "Midnight (%s)", sctime( me.now ) );
+		run_mod_timers( 1 );
+		ResetLogs();
 		midnight = 1;
-	} else {
-		run_mod_timers (0);
-		if (midnight == 1 && is_midnight () == 0)
+	}
+	else
+	{
+		run_mod_timers( 0 );
+		if( midnight == 1 && is_midnight() == 0 )
 			midnight = 0;
 	}
 	
 	/* re-add this timeout */
-	event_add(timers, &tv);
+	event_add( timers, &tv );
 }
 
-static int
-is_midnight (void)
+/** @brief is_midnight
+ *
+ *  Determine midnight
+ *  Timer subsystem use only.
+ *
+ *  @param none
+ *
+ *  @return 1 if midnight else 0
+ */
+
+static int is_midnight( void )
 {
-	struct tm *ltm = localtime (&me.now);
+	struct tm *ltm = localtime( &me.now );
 
-	if (ltm->tm_hour == 0 && ltm->tm_min == 0) {
+	if( ltm->tm_hour == 0 && ltm->tm_min == 0 )
 		return 1;
-	}
 	return 0;
 }
 
-/** @brief create new timer
+/** @brief create new new_timer
  *
- * For core use only, creates a timer
+ *  For core use only, creates a timer
  *
- * @param name the name of new timer
+ *  @param name of new timer
  * 
- * @return pointer to new timer on success, NULL on error
-*/
-static Timer *
-new_timer (const char *name)
+ *  @return pointer to new timer on success, NULL on error
+ */
+
+static Timer *new_timer( const char *name )
 {
 	Timer *timer;
 
 	SET_SEGV_LOCATION();
-	if (hash_isfull (timerhash)) {
-		nlog (LOG_WARNING, "new_timer: timer hash is full");
+	if( hash_isfull( timerhash ) )
+	{
+		nlog( LOG_WARNING, "new_timer: timer hash is full" );
 		return NULL;
 	}
-	dlog (DEBUG2, "new_timer: %s", name);
-	timer = ns_calloc (sizeof (Timer));
-	strlcpy (timer->name, name, MAX_MOD_NAME);
-	hnode_create_insert (timerhash, timer, name);
+	dlog( DEBUG2, "new_timer: %s", name );
+	timer = ns_calloc( sizeof( Timer ) );
+	strlcpy( timer->name, name, MAX_MOD_NAME );
+	hnode_create_insert( timerhash, timer, name );
 	return timer;
 }
 
-/** @brief find timer
+/** @brief FindTimer
  *
- * For core use only, finds a timer in the current list of timers
+ *  Finds a timer in the current list of timers
  *
- * @param name the name of timer to find
+ *  @param name the name of timer to find
  * 
- * @return pointer to timer if found, NULL if not found
-*/
-Timer *
-FindTimer (const char *name)
+ *  @return pointer to timer if found, NULL if not found
+ */
+
+Timer *FindTimer( const char *name )
 {
 	Timer *t;
 
-	t = (Timer *)hnode_find (timerhash, name);
-	if (!t) {
-		dlog (DEBUG3, "FindTimer: %s not found", name);
-	}
+	t = ( Timer * )hnode_find( timerhash, name );
+	if( !t )
+		dlog( DEBUG3, "FindTimer: %s not found", name );
 	return t;
 }
 
-/** @brief add a timer to the timer list
+/** @brief AddTimer
  *
- * For module use. Adds a timer with the given function to the timer list
+ *  For module use. Adds a timer with the given function to the timer list
  *
- * @param handler the name of function to register with this timer
- * @param name the name of timer to register
- * @param mod_name the name of module registering the timer
- * @param interval the interval at which the timer triggers in seconds
+ *  @param type of timer
+ *  @param handler for timer
+ *  @param name of timer
+ *  @param interval the interval at which the timer triggers in seconds
+ *  @param userptr Justin????
  * 
- * @return NS_SUCCESS if added, NS_FAILURE if not 
-*/
-int
-AddTimer (TIMER_TYPE type, timer_handler handler, const char *name, int interval, void *userptr)
+ *  @return NS_SUCCESS if added, NS_FAILURE if not 
+ */
+
+int AddTimer( TIMER_TYPE type, timer_handler handler, const char *name, int interval, void *userptr )
 {
 	Timer *timer;
 	Module* moduleptr;
 
 	SET_SEGV_LOCATION();
 	moduleptr = GET_CUR_MODULE();
-	if (handler == NULL) {
-		nlog (LOG_WARNING, "Module %s timer %s does not exist", moduleptr->info->name, name);
+	if( handler == NULL )
+	{
+		nlog( LOG_WARNING, "Module %s timer %s does not exist", moduleptr->info->name, name );
 		return NS_FAILURE;
 	}
-	if (FindTimer (name)) {
-		nlog (LOG_WARNING, "Module %s timer %s already exists. Not adding.", moduleptr->info->name, name);
+	if( FindTimer( name ) )
+	{
+		nlog( LOG_WARNING, "Module %s timer %s already exists. Not adding.", moduleptr->info->name, name );
 		return NS_FAILURE;
 	}
-	timer = new_timer (name);
-	if (timer) {
+	timer = new_timer( name );
+	if( timer )
+	{
 		timer->type = type;
 		timer->interval = interval;
 		timer->lastrun = me.now;
 		timer->moduleptr = moduleptr;
 		timer->handler = handler;
 		timer->userptr = userptr;
-		dlog (DEBUG2, "AddTimer: Module %s added timer %s", moduleptr->info->name, name);
+		dlog( DEBUG2, "AddTimer: Module %s added timer %s", moduleptr->info->name, name );
 		return NS_SUCCESS;
 	}
 	return NS_FAILURE;
 }
 
-/** @brief delete a timer from the timer list
+/** @brief DelTimer
  *
- * For module use. Deletes a timer with the given name from the timer list
+ *  Deletes a timer with the given name from the timer list
+ *  For module use.
  *
- * @param name the name of timer to delete
+ *  @param name the name of timer to delete
  * 
- * @return NS_SUCCESS if deleted, NS_FAILURE if not found
-*/
-int
-DelTimer (const char *name)
+ *  @return NS_SUCCESS if deleted, NS_FAILURE if not found
+ */
+
+int DelTimer( const char *name )
 {
 	Timer *timer;
 	hnode_t *tn;
 
 	SET_SEGV_LOCATION();
-	tn = hash_lookup (timerhash, name);
-	if (tn) {
-		timer = hnode_get (tn);
-		dlog(DEBUG2, "DelTimer: removed timer %s for module %s", name, timer->moduleptr->info->name);
-		hash_delete (timerhash, tn);
-		hnode_destroy (tn);
+	tn = hash_lookup( timerhash, name );
+	if( tn )
+	{
+		timer = hnode_get( tn );
+		dlog( DEBUG2, "DelTimer: removed timer %s for module %s", name, timer->moduleptr->info->name );
+		hash_delete_destroy_node( timerhash, tn );
 #ifdef USE_PERL
-		if (IS_PERL_MOD(timer->moduleptr)) {
-			ns_free(timer->userptr);
-		}
+		if( IS_PERL_MOD( timer->moduleptr ) )
+			ns_free( timer->userptr );
 #endif
-		ns_free (timer);
+		ns_free( timer );
 		return NS_SUCCESS;
 	}
 	return NS_FAILURE;
 }
 
-/** @brief delete all timers from the timer list for given module
+/** @brief del_timers
  *
- * For core use. 
+ *  delete all timers from the timer list for given module
+ *  For core use. 
  *
- * @param 
+ *  @param mod_ptr pointer to module to delete timers from
  * 
- * @return NS_SUCCESS if deleted, NS_FAILURE if not found
-*/
-int
-del_timers (Module *mod_ptr)
+ *  @return NS_SUCCESS if deleted, NS_FAILURE if not found
+ */
+
+int del_timers( Module *mod_ptr )
 {
 	Timer *timer;
 	hnode_t *tn;
 	hscan_t hscan;
 
-	hash_scan_begin (&hscan, timerhash);
-	while ((tn = hash_scan_next (&hscan)) != NULL) {
-		timer = hnode_get (tn);
-		if (timer->moduleptr == mod_ptr) {
-			dlog(DEBUG1, "del_timers: deleting timer %s from module %s.", timer->name, mod_ptr->info->name);
-			hash_delete (timerhash, tn);
-			hnode_destroy (tn);
-			ns_free (timer);
+	hash_scan_begin( &hscan, timerhash );
+	while( ( tn = hash_scan_next( &hscan ) ) != NULL )
+	{
+		timer = hnode_get( tn );
+		if( timer->moduleptr == mod_ptr )
+		{
+			dlog( DEBUG1, "del_timers: deleting timer %s from module %s.", timer->name, mod_ptr->info->name );
+			hash_scan_delete_destroy_node( timerhash, tn );
+			ns_free( timer );
 		}
 	}
 	return NS_SUCCESS;
 }
 
-/** @brief delete a timer from the timer list
+/** @brief SetTimerInterval
  *
- * For module use. Deletes a timer with the given name from the timer list
+ *  For module use. Sets interval for timer
  *
- * @param name the name of timer to delete
+ *  @param name of timer to set
+ *  @param interval to set
  * 
- * @return NS_SUCCESS if deleted, NS_FAILURE if not found
-*/
-int
-SetTimerInterval (const char *name, int interval)
+ *  @return NS_SUCCESS if deleted, NS_FAILURE if not found
+ */
+
+int SetTimerInterval( const char *name, int interval )
 {
 	Timer *timer;
 
 	SET_SEGV_LOCATION();
-	timer = (Timer *)hnode_find (timerhash, name);
-	if (timer) {
+	timer = ( Timer * )hnode_find( timerhash, name );
+	if( timer )
+	{
 		timer->interval = interval;
-		dlog (DEBUG2, "SetTimerInterval: timer interval for %s (%s) set to %d", name, timer->moduleptr->info->name, interval);
+		dlog( DEBUG2, "SetTimerInterval: timer interval for %s (%s) set to %d", name, timer->moduleptr->info->name, interval );
 		return NS_SUCCESS;
 	}
 	return NS_FAILURE;
 }
 
-/** @brief list timers in use
+/** @brief ns_cmd_timerlist
  *
- * NeoStats command to list the current timers from IRC
+ *  NeoStats command to list the current timers from IRC
  *
- * @param u pointer to user structure of the user issuing the request
+ *  @param cmdparams
  * 
- * @return none
+ *  @return none
 */
-int
-ns_cmd_timerlist (CmdParams* cmdparams)
+
+int ns_cmd_timerlist( CmdParams* cmdparams )
 {
 	Timer *timer = NULL;
 	hscan_t ts;
 	hnode_t *tn;
 
 	SET_SEGV_LOCATION();
-	irc_prefmsg (ns_botptr, cmdparams->source, __("Timer List:", cmdparams->source));
-	hash_scan_begin (&ts, timerhash);
-	while ((tn = hash_scan_next (&ts)) != NULL) {
-		timer = hnode_get (tn);
-		irc_prefmsg (ns_botptr, cmdparams->source, "%s:", timer->moduleptr->info->name);
-		irc_prefmsg (ns_botptr, cmdparams->source, __("Timer: %s", cmdparams->source), timer->name);
-		irc_prefmsg (ns_botptr, cmdparams->source, __("Interval: %ld", cmdparams->source), (long)timer->interval);
-		irc_prefmsg (ns_botptr, cmdparams->source, __("Next run in: %ld", cmdparams->source), (long)(timer->interval - (me.now - timer->lastrun)));
+	irc_prefmsg( ns_botptr, cmdparams->source, __( "Timer List:", cmdparams->source ) );
+	hash_scan_begin( &ts, timerhash );
+	while( ( tn = hash_scan_next( &ts ) ) != NULL )
+	{
+		timer = hnode_get( tn );
+		irc_prefmsg( ns_botptr, cmdparams->source, "%s:", timer->moduleptr->info->name );
+		irc_prefmsg( ns_botptr, cmdparams->source, __( "Timer: %s", cmdparams->source ), timer->name );
+		irc_prefmsg( ns_botptr, cmdparams->source, __( "Interval: %ld", cmdparams->source ),( long )timer->interval );
+		irc_prefmsg( ns_botptr, cmdparams->source, __( "Next run in: %ld", cmdparams->source ),( long )( timer->interval -( me.now - timer->lastrun ) ) );
 	}
-	irc_prefmsg (ns_botptr, cmdparams->source, __("End of list.", cmdparams->source));
+	irc_prefmsg( ns_botptr, cmdparams->source, __( "End of list.", cmdparams->source ) );
 	return 0;
 }
 
-/** @brief run pending module timer functions
+/** @brief run_mod_timers
  *
- * NeoStats command to run pending timer functions
+ *  NeoStats command to run pending timer functions
  *
- * @param none
+ *  @param ismidnight whether we are at midnight
  * 
- * @return none
-*/
-static void
-run_mod_timers (int ismidnight)
+ *  @return none
+ */
+
+static void run_mod_timers( int ismidnight )
 {
 	struct tm *ts;
 	Timer *timer = NULL;
 	hscan_t tscan;
 	hnode_t *tn;
 
-	ts = gmtime(&me.now);
+	ts = gmtime( &me.now );
 	/* First, lets see if any modules have a function that is due to run..... */
-	hash_scan_begin (&tscan, timerhash);
-	while ((tn = hash_scan_next (&tscan)) != NULL) {
+	hash_scan_begin( &tscan, timerhash );
+	while( ( tn = hash_scan_next( &tscan ) ) != NULL )
+	{
 		SET_SEGV_LOCATION();
-		timer = hnode_get (tn);
+		timer = hnode_get( tn );
 		/* If a module is not yet synched, reset it's lastrun */
-		if( !IsModuleSynched( timer->moduleptr ) ) {
-			timer->lastrun = (int) me.now;
-		} else {
-			switch (timer->type) {
+		if( !IsModuleSynched( timer->moduleptr ) )
+		{
+			timer->lastrun = ( int ) me.now;
+		}
+		else
+		{
+			switch( timer->type )
+			{
 				/* TIMER_TYPE_DAILY */
 				case TIMER_TYPE_MIDNIGHT:
-					if (!ismidnight)
+					if( !ismidnight )
 						continue;
 					break;
 				case TIMER_TYPE_WEEKLY:
-					if (!ismidnight)
+					if( !ismidnight )
 						continue;
-					if (ts->tm_wday != 0)
+					if( ts->tm_wday != 0 )
 						continue;
 					break;
 				case TIMER_TYPE_MONTHLY:
-					if (!ismidnight)
+					if( !ismidnight )
 						continue;
-					if (ts->tm_mday != 1)
+					if( ts->tm_mday != 1 )
 						continue;
 					break;
 				case TIMER_TYPE_INTERVAL:
-					if (me.now - timer->lastrun < timer->interval) 
+					if( me.now - timer->lastrun < timer->interval ) 
 						continue;
 					break;
 				case TIMER_TYPE_COUNTDOWN:
-					if (me.now - timer->lastrun < timer->interval) {
-						timer->interval -= (me.now - timer->lastrun);
+					if( me.now - timer->lastrun < timer->interval )
+					{
+						timer->interval -= ( me.now - timer->lastrun );
 						timer->lastrun = me.now;
  						continue;
 					}
 					break;
 			}
-			if (setjmp (sigvbuf) == 0) {
-				dlog (DEBUG3, "run_mod_timers: Running timer %s for module %s", timer->name, timer->moduleptr->info->name);
-				SET_RUN_LEVEL (timer->moduleptr);
-				if (timer->handler (timer->userptr) < 0) {
-					dlog (DEBUG2, "run_mod_timers: Deleting Timer %s for Module %s as requested", timer->name, timer->moduleptr->info->name);
-					hash_scan_delete (timerhash, tn);
-					hnode_destroy (tn);
-					ns_free (timer);
-				} else {
-					timer->lastrun = (int) me.now;
+			if( setjmp( sigvbuf ) == 0 )
+			{
+				dlog( DEBUG3, "run_mod_timers: Running timer %s for module %s", timer->name, timer->moduleptr->info->name );
+				SET_RUN_LEVEL( timer->moduleptr );
+				if( timer->handler( timer->userptr ) < 0 )
+				{
+					dlog( DEBUG2, "run_mod_timers: Deleting Timer %s for Module %s as requested", timer->name, timer->moduleptr->info->name );
+					hash_scan_delete_destroy_node( timerhash, tn );
+					ns_free( timer );
+				}
+				else
+				{
+					timer->lastrun = ( int ) me.now;
 				}
 				RESET_RUN_LEVEL();
-				if (timer->type == TIMER_TYPE_COUNTDOWN) {
-					hash_scan_delete (timerhash, tn);
-					hnode_destroy (tn);
-					ns_free (timer);
+				if( timer->type == TIMER_TYPE_COUNTDOWN )
+				{
+					hash_scan_delete_destroy_node( timerhash, tn );
+					ns_free( timer );
 				}
-			} else {
-				nlog (LOG_CRITICAL, "run_mod_timers: setjmp() failed, can't call module %s", timer->moduleptr->info->name);
+			}
+			else
+			{
+				nlog( LOG_CRITICAL, "run_mod_timers: setjmp() failed, can't call module %s", timer->moduleptr->info->name );
 			}
 		}
 	}

Modified: trunk/src/users.c
==============================================================================
--- trunk/src/users.c	(original)
+++ trunk/src/users.c	Thu Aug 25 04:23:01 2005
@@ -40,161 +40,230 @@
 #define USER_TABLE_SIZE	-1
 #define MAXJOINCHANS	-1
 
+/** List of online users */
 static hash_t *userhash;
-/** @brief Module data flags */
-static unsigned int fusermoddata = 0;
 
-static unsigned int moddatacnt[NUM_MODULES];
+/** @brief new_user
+ *
+ *  Create a new user Client struct
+ *  NeoStats core use only.
+ *
+ *  @param nick of user to create
+ *
+ *  @return pointer to Client or NULL if fails
+ */
 
-static Client *new_user (const char *nick)
+static Client *new_user( const char *nick )
 {
 	Client *u;
 
 	SET_SEGV_LOCATION();
-	if (hash_isfull (userhash)) {
-		nlog (LOG_CRITICAL, "new_user: user hash is full");
+	if( hash_isfull( userhash ) )
+	{
+		nlog( LOG_CRITICAL, "new_user: user hash is full" );
 		return NULL;
 	}
-	dlog (DEBUG2, "new_user: %s", nick);
-	u = ns_calloc (sizeof (Client));
-	strlcpy (u->name, nick, MAXNICK);
-	u->user = ns_calloc (sizeof (User));
-	hnode_create_insert (userhash, u, u->name);
+	dlog( DEBUG2, "new_user: %s", nick );
+	u = ns_calloc( sizeof( Client ) );
+	strlcpy( u->name, nick, MAXNICK );
+	u->user = ns_calloc( sizeof( User ) );
+	hnode_create_insert( userhash, u, u->name );
 	me.usercount++;
 	return u;
 }
 
-static void lookupnickip (void *data, adns_answer *a) 
+/** @brief lookupnickip
+ *
+ *  DNS callback for IP lookups
+ *  NeoStats core use only.
+ *
+ *  @param data
+ *  @param a
+ *
+ *  @return none
+ */
+
+static void lookupnickip( void *data, adns_answer *a ) 
 {
 	CmdParams *cmdparams;
 	Client *u;
 	
-	u = FindUser ((char *)data);
-	if (a && a->nrrs > 0 && u && a->status == adns_s_ok) {
+	u = FindUser( ( char * )data );
+	if( a && a->nrrs > 0 && u && a->status == adns_s_ok )
+	{
 		u->ip.s_addr = a->rrs.addr->addr.inet.sin_addr.s_addr;
-		strlcpy (u->hostip, inet_ntoa (u->ip), HOSTIPLEN);
-		if (u->ip.s_addr > 0) {
-			cmdparams = (CmdParams*) ns_calloc (sizeof(CmdParams));
+		strlcpy( u->hostip, inet_ntoa( u->ip ), HOSTIPLEN );
+		if( u->ip.s_addr > 0 )
+		{
+			cmdparams = ( CmdParams* ) ns_calloc( sizeof( CmdParams ) );
 			cmdparams->source = u;	
-			SendAllModuleEvent (EVENT_NICKIP, cmdparams);
-			ns_free (cmdparams);
+			SendAllModuleEvent( EVENT_NICKIP, cmdparams );
+			ns_free( cmdparams );
 		}
 	} 
 }
 
-static int process_ip (const char *nick, const char *host)
+/** @brief process_ip
+ *
+ *  Setup DNS callback for IP lookups
+ *  NeoStats core use only.
+ *
+ *  @param nick
+ *  @param host
+ *
+ *  @return IP address
+ */
+
+static int process_ip( const char *nick, const char *host )
 {
 	unsigned long ipaddress = 0;
 	struct in_addr *ipad;
 	int res;
 
 	/* first, if the u->host is a ip address, just convert it */
-	ipad = ns_calloc (sizeof(struct in_addr));
-	res = inet_aton (host, ipad);
-	if (res > 0) {
+	ipad = ns_calloc( sizeof( struct in_addr ) );
+	res = inet_aton( host, ipad );
+	if( res > 0 )
+	{
 		/* its valid */
-		ipaddress = htonl (ipad->s_addr);
-		ns_free (ipad);
-	} else {		
+		ipaddress = htonl( ipad->s_addr );
+		ns_free( ipad );
+	}
+	else
+	{		
 		/* kick of a dns reverse lookup for this host */
-		dns_lookup ((char *)host, adns_r_addr, lookupnickip, (void *)nick);
+		dns_lookup( ( char * )host, adns_r_addr, lookupnickip,( void * )nick );
 		ipaddress = 0;
 	}		
 	return ipaddress;
 }
 
-Client *AddUser (const char *nick, const char *user, const char *host, 
+/** @brief AddUser
+ *
+ *  Add a user to NeoStats
+ *  NeoStats core use only.
+ *
+ *  @param nick
+ *  @param user
+ *  @param host
+ *  @param realname
+ *  @param server
+ *  @param ip
+ *  @param TS
+ *  @param numeric
+ *
+ *  @return pointer to Client or NULL if fails
+ */
+
+Client *AddUser( const char *nick, const char *user, const char *host, 
 	const char *realname, const char *server, const char *ip, const char *TS, 
-	const char *numeric)
+	const char *numeric )
 {
 	CmdParams *cmdparams;
 	unsigned long ipaddress = 0;
 	Client *u;
 
 	SET_SEGV_LOCATION();
-	u = FindUser (nick);
-	if (u) {
-		nlog (LOG_WARNING, "AddUser: trying to add a user that already exists %s", nick);
+	u = FindUser( nick );
+	if( u )
+	{
+		nlog( LOG_WARNING, "AddUser: trying to add a user that already exists %s", nick );
 		return NULL;
 	}
-	dlog (DEBUG2, "AddUser: %s (%s@%s) %s (%d) -> %s at %s", nick, user, host, realname, (int)htonl (ipaddress), server, TS);
-	u = new_user (nick);
-	if (!u) {
+	dlog( DEBUG2, "AddUser: %s (%s@%s) %s (%d) -> %s at %s", nick, user, host, realname,( int )htonl( ipaddress ), server, TS );
+	u = new_user( nick );
+	if( !u )
 		return NULL;
-	}
-	if (ip) {
-		ipaddress = strtoul (ip, NULL, 10);
-	} else if (!(ircd_srv.protocol&PROTOCOL_NICKIP) && me.want_nickip == 1) {
-		ipaddress = process_ip (u->name, host);
-	}
-	u->tsconnect = TS ? strtoul (TS, NULL, 10) : me.now;
+	if( ip )
+		ipaddress = strtoul( ip, NULL, 10 );
+	else if( !( ircd_srv.protocol&PROTOCOL_NICKIP ) && me.want_nickip == 1 )
+		ipaddress = process_ip( u->name, host );
+	u->tsconnect = TS ? strtoul( TS, NULL, 10 ) : me.now;
 	if( ( time( NULL ) - u->tsconnect ) > nsconfig.splittime )
 		u->flags |= NS_FLAGS_NETJOIN;
-	strlcpy (u->user->hostname, host, MAXHOST);
-	strlcpy (u->user->vhost, host, MAXHOST);
+	strlcpy( u->user->hostname, host, MAXHOST );
+	strlcpy( u->user->vhost, host, MAXHOST );
 	ircsnprintf( u->user->userhostmask, USERHOSTLEN, "%s!%s@%s", nick, user, host );
 	strlcpy( u->user->uservhostmask, u->user->userhostmask, USERHOSTLEN );
-	strlcpy (u->user->username, user, MAXUSER);
-	strlcpy (u->info, realname, MAXREALNAME);
+	strlcpy( u->user->username, user, MAXUSER );
+	strlcpy( u->info, realname, MAXREALNAME );
 	u->user->ulevel = -1;
-	u->uplink = FindServer (server);
+	u->uplink = FindServer( server );
 	u->uplink->server->users++;
 	u->user->tslastmsg = me.now;
-	u->user->chans = list_create (MAXJOINCHANS);
-	u->ip.s_addr = htonl (ipaddress);
-	strlcpy (u->hostip, inet_ntoa (u->ip), HOSTIPLEN);
-	if (IsMe(u->uplink)) {
+	u->user->chans = list_create( MAXJOINCHANS );
+	u->ip.s_addr = htonl( ipaddress );
+	strlcpy( u->hostip, inet_ntoa( u->ip ), HOSTIPLEN );
+	if( IsMe( u->uplink ) )
 		u->flags |= CLIENT_FLAG_ME;
-	}
 	/* check if the user is excluded */
-	ns_do_exclude_user(u);
-	if ((ircd_srv.protocol & PROTOCOL_B64NICK) && numeric) {
-		set_nick_base64 (u->name, numeric);
-	}
-	cmdparams = (CmdParams*) ns_calloc (sizeof(CmdParams));
+	ns_do_exclude_user( u );
+	if( ( ircd_srv.protocol & PROTOCOL_B64NICK ) && numeric )
+		set_nick_base64( u->name, numeric );
+	cmdparams = ( CmdParams* ) ns_calloc( sizeof( CmdParams ) );
 	cmdparams->source = u;	
-	SendAllModuleEvent (EVENT_SIGNON, cmdparams);
-	if (me.want_nickip == 1 && ipaddress != 0) {
-		/* only fire this event if we have the nickip and some module wants it */
-		SendAllModuleEvent (EVENT_NICKIP, cmdparams);
-	}
-	ns_free (cmdparams);
+	SendAllModuleEvent( EVENT_SIGNON, cmdparams );
+	/* Send EVENT_NICKIP if we have it and a module wants it */
+	if( me.want_nickip == 1 && ipaddress != 0 )
+		SendAllModuleEvent( EVENT_NICKIP, cmdparams );
+	ns_free( cmdparams );
 	/* Send CTCP VERSION request if we are configured to do so */
-	if (IsNeoStatsSynched() && me.versionscan && !IsExcluded(u) && !IsMe(u)) {
-		irc_ctcp_version_req (ns_botptr, u);
-	}
+	if( IsNeoStatsSynched() && me.versionscan && !IsExcluded( u ) && !IsMe( u ) )
+		irc_ctcp_version_req( ns_botptr, u );
 	return u;
 }
 
-static void deluser (Client *u)
+/** @brief deluser
+ *
+ *  Remove a user from NeoStats
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to Client to remove
+ *
+ *  @return none
+ */
+
+static void deluser( Client *u )
 {
 	hnode_t *un;
 
-	un = hash_lookup (userhash, u->name);
-	if (!un) {
-		nlog (LOG_WARNING, "deluser: %s failed!", u->name);
+	un = hash_lookup( userhash, u->name );
+	if( !un )
+	{
+		nlog( LOG_WARNING, "deluser: %s failed!", u->name );
 		return;
 	}
 	/* if its one of our bots, remove it from the modlist */
-	if (IsMe(u)) {
-		DelBot (u->name);
-	}
-	hash_delete (userhash, un);
-	hnode_destroy (un);
-	list_destroy (u->user->chans);
+	if( IsMe( u ) )
+		DelBot( u->name );
+	hash_delete_destroy_node( userhash, un );
+	list_destroy( u->user->chans );
 	if( u->uplink )
 		u->uplink->server->users--;
-	if( IsAway( u ) ) {
+	if( IsAway( u ) )
+	{
 		me.awaycount--;
-		if (u->uplink)
+		if( u->uplink )
 			u->uplink->server->awaycount--;
 	}
-	ns_free (u->user);
-	ns_free (u);
+	ns_free( u->user );
+	ns_free( u );
 	me.usercount--;
 }
 
-void KillUser (const char* source, const char *nick, const char *reason)
+/** @brief KillUser
+ *
+ *  Process IRC KILL
+ *  NeoStats core use only.
+ *
+ *  @param source of kill
+ *  @param nick to kill
+ *  @param reason for kill
+ *
+ *  @return none
+ */
+
+void KillUser( const char *source, const char *nick, const char *reason )
 {
 	char *killbuf;
 	char *killreason;
@@ -204,409 +273,588 @@
 	Client *u;
 
 	SET_SEGV_LOCATION();
-	dlog (DEBUG2, "KillUser: %s", nick);
-	u = FindUser (nick);
-	if (!u) {
-		nlog (LOG_WARNING, "KillUser: %s failed!", nick);
+	dlog( DEBUG2, "KillUser: %s", nick );
+	u = FindUser( nick );
+	if( !u )
+	{
+		nlog( LOG_WARNING, "KillUser: %s failed!", nick );
 		return;
 	}
-	PartAllChannels (u, reason);
+	PartAllChannels( u, reason );
 	/* run the event to delete a user */
-	cmdparams = (CmdParams*) ns_calloc (sizeof(CmdParams));
+	cmdparams = ( CmdParams* ) ns_calloc( sizeof( CmdParams ) );
 	cmdparams->target = u;
-	killbuf = sstrdup(reason);
-	ac = split_buf (killbuf, &av, 0);
-	killreason = joinbuf (av, ac, 1);
+	killbuf = sstrdup( reason );
+	ac = split_buf( killbuf, &av, 0 );
+	killreason = joinbuf( av, ac, 1 );
 	cmdparams->param = killreason;
-	cmdparams->source = FindUser (source);
-	if (cmdparams->source)
+	cmdparams->source = FindUser( source );
+	if( cmdparams->source )
 	{
-		SendAllModuleEvent (EVENT_KILL, cmdparams);
-		SendAllModuleEvent (EVENT_GLOBALKILL, cmdparams);
+		SendAllModuleEvent( EVENT_KILL, cmdparams );
+		SendAllModuleEvent( EVENT_GLOBALKILL, cmdparams );
 	}
 	else
 	{
-		cmdparams->source = FindServer (source);
-		SendAllModuleEvent (EVENT_KILL, cmdparams);
-		SendAllModuleEvent (EVENT_SERVERKILL, cmdparams); 		
+		cmdparams->source = FindServer( source );
+		SendAllModuleEvent( EVENT_KILL, cmdparams );
+		SendAllModuleEvent( EVENT_SERVERKILL, cmdparams ); 		
 	}
 	/* if its one of our bots inform the module */
-	if (IsMe(u)) {
+	if( IsMe( u ) )
+	{
 		cmdparams->bot = u->user->bot;
-		nlog (LOG_NOTICE, "KillUser: deleting bot %s as it was killed", u->name);
-		SendModuleEvent (EVENT_BOTKILL, cmdparams, u->user->bot->moduleptr);
+		nlog( LOG_NOTICE, "KillUser: deleting bot %s as it was killed", u->name );
+		SendModuleEvent( EVENT_BOTKILL, cmdparams, u->user->bot->moduleptr );
 	}
-	deluser (u);
-	ns_free (killbuf);
-	ns_free (killreason);
-	ns_free (av);
-	ns_free (cmdparams);
+	deluser( u );
+	ns_free( killbuf );
+	ns_free( killreason );
+	ns_free( av );
+	ns_free( cmdparams );
 }
 
-void QuitUser (const char *nick, const char *reason)
+/** @brief QuitUser
+ *
+ *  Process IRC QUIT
+ *  NeoStats core use only.
+ *
+ *  @param nick which quit
+ *  @param reason for quit
+ *
+ *  @return none
+ */
+
+void QuitUser( const char *nick, const char *reason )
 {
 	CmdParams *cmdparams;
 	Client *u;
 
 	SET_SEGV_LOCATION();
-	dlog (DEBUG2, "QuitUser: %s", nick);
-	u = FindUser (nick);
-	if (!u) {
-		nlog (LOG_WARNING, "QuitUser: %s failed!", nick);
+	dlog( DEBUG2, "QuitUser: %s", nick );
+	u = FindUser( nick );
+	if( !u )
+	{
+		nlog( LOG_WARNING, "QuitUser: %s failed!", nick );
 		return;
 	}
-	PartAllChannels (u, reason);
+	PartAllChannels( u, reason );
 	/* run the event to delete a user */
-	cmdparams = (CmdParams*) ns_calloc (sizeof(CmdParams));
+	cmdparams = ( CmdParams* ) ns_calloc( sizeof( CmdParams ) );
 	cmdparams->source = u;
-	if (reason) {
-		cmdparams->param = (char*)reason;
-	}
-	SendAllModuleEvent (EVENT_QUIT, cmdparams);
-	/* RX: :m , :[irc.foonet.com] Local kill by Mark (testing) */
-	if (strstr (reason, "Local kill by") && 
-		strstr (reason, "[") && 
-		strstr (reason, "]"))
+	if( reason )
+		cmdparams->param = ( char *)reason;
+	SendAllModuleEvent( EVENT_QUIT, cmdparams );
+	/* RX: :m , :[irc.foonet.com] Local kill by Mark( testing ) */
+	if( strstr( reason, "Local kill by" ) && 
+		strstr( reason, "[" ) && 
+		strstr( reason, "]" ) )
 	{
 		char *killbuf;
 		char *killreason;
 		char** av;
 		int ac = 0;
 
-		killbuf = sstrdup (cmdparams->param);
-		ac = split_buf (killbuf, &av, 0);
-		killreason = joinbuf(av, ac, 5);
-		cmdparams->source = FindUser (av[4]);
+		killbuf = sstrdup( cmdparams->param );
+		ac = split_buf( killbuf, &av, 0 );
+		killreason = joinbuf( av, ac, 5 );
+		cmdparams->source = FindUser( av[4] );
 		cmdparams->target = u;
 		cmdparams->param = killreason;
-		SendAllModuleEvent (EVENT_LOCALKILL, cmdparams);
-		ns_free (killbuf);
-		ns_free (killreason);
-		ns_free (av);
+		SendAllModuleEvent( EVENT_LOCALKILL, cmdparams );
+		ns_free( killbuf );
+		ns_free( killreason );
+		ns_free( av );
 	}
-	deluser (u);
-	ns_free (cmdparams);
+	deluser( u );
+	ns_free( cmdparams );
 }
 
-void UserAway (const char *nick, const char *awaymsg)
+/** @brief UserAway
+ *
+ *  Process IRC AWAY
+ *  NeoStats core use only.
+ *
+ *  @param nick which quit
+ *  @param awaymsg
+ *
+ *  @return none
+ */
+
+void UserAway( const char *nick, const char *awaymsg )
 {
 	CmdParams *cmdparams;
 	Client *u;
 
-	u = FindUser (nick);
-	if (!u) {
-		nlog (LOG_WARNING, "UserAway: unable to find user %s for away", nick);
+	u = FindUser( nick );
+	if( !u )
+	{
+		nlog( LOG_WARNING, "UserAway: unable to find user %s for away", nick );
 		return;
 	}
-	if (awaymsg) {
-		strlcpy (u->user->awaymsg, awaymsg, MAXHOST);
-	} else {
+	if( awaymsg )
+		strlcpy( u->user->awaymsg, awaymsg, MAXHOST );
+	else
 		u->user->awaymsg[0] = 0;
-	}
-	cmdparams = (CmdParams*) ns_calloc (sizeof(CmdParams));
+	cmdparams = ( CmdParams* ) ns_calloc( sizeof( CmdParams ) );
 	cmdparams->source = u;
-	if( IsAway( u ) && ( !awaymsg ) ) {
+	if( IsAway( u ) &&( !awaymsg ) )
+	{
 		u->user->is_away = 0;
 		me.awaycount--;
 		u->uplink->server->awaycount--;
-	} else if( !IsAway( u ) && ( awaymsg ) ) {
+	}
+	else if( !IsAway( u ) &&( awaymsg ) )
+	{
 		u->user->is_away = 1;
 		me.awaycount++;
 		u->uplink->server->awaycount++;
 	}
-	SendAllModuleEvent (EVENT_AWAY, cmdparams);
-	ns_free (cmdparams);
+	SendAllModuleEvent( EVENT_AWAY, cmdparams );
+	ns_free( cmdparams );
 }
 
-void UserNickChange (const char *oldnick, const char *newnick, const char *ts)
+/** @brief UserNickChange
+ *
+ *  Process IRC NICK
+ *  NeoStats core use only.
+ *
+ *  @param oldnick
+ *  @param newnick
+ *  @param ts
+ *
+ *  @return none
+ */
+
+void UserNickChange( const char *oldnick, const char *newnick, const char *ts )
 {
 	CmdParams *cmdparams;
 	hnode_t *un;
 	Client *u;
 
 	SET_SEGV_LOCATION();
-	dlog (DEBUG2, "UserNickChange: %s -> %s", oldnick, newnick);
-	un = hash_lookup (userhash, oldnick);
-	if (!un) {
-		nlog (LOG_WARNING, "UserNickChange: can't find user %s", oldnick);
+	dlog( DEBUG2, "UserNickChange: %s -> %s", oldnick, newnick );
+	un = hash_lookup( userhash, oldnick );
+	if( !un )
+	{
+		nlog( LOG_WARNING, "UserNickChange: can't find user %s", oldnick );
 		return;
 	}
-	u = (Client *) hnode_get (un);
-	hash_delete (userhash, un);
-	strlcpy (u->name, newnick, MAXNICK);
+	u = ( Client * ) hnode_get( un );
+	hash_delete( userhash, un );
+	strlcpy( u->name, newnick, MAXNICK );
 	ircsnprintf( u->user->userhostmask, USERHOSTLEN, "%s!%s@%s", u->name, u->user->username, u->user->hostname );
 	ircsnprintf( u->user->uservhostmask, USERHOSTLEN, "%s!%s@%s", u->name, u->user->username, u->user->vhost );
-	if (ts) {
-		u->tsconnect = atoi (ts);
-	} else {
-		u->tsconnect = me.now;
-	}
-	ns_do_exclude_user(u);
-	hash_insert (userhash, un, u->name);
-	cmdparams = (CmdParams*) ns_calloc (sizeof(CmdParams));
+	u->tsconnect = ts ? atoi( ts ) : me.now;
+	ns_do_exclude_user( u );
+	hash_insert( userhash, un, u->name );
+	cmdparams = ( CmdParams* ) ns_calloc( sizeof( CmdParams ) );
 	cmdparams->source = u;
-	cmdparams->param = (char *)oldnick;
-	SendAllModuleEvent (EVENT_NICK, cmdparams);
-	ns_free (cmdparams);
-	if (IsMe(u)) {
-		BotNickChange (u->user->bot, newnick);
-	}
+	cmdparams->param = ( char * )oldnick;
+	SendAllModuleEvent( EVENT_NICK, cmdparams );
+	ns_free( cmdparams );
+	if( IsMe( u ) )
+		BotNickChange( u->user->bot, newnick );
 	return;
 }
 
-Client *find_user_base64 (const char *num)
+/** @brief find_user_base64
+ *
+ *  Find user based on base 64 representation
+ *  NeoStats core use only.
+ *
+ *  @param num numeric to find
+ *
+ *  @return pointer to Client or NULL if fails
+ */
+
+Client *find_user_base64( const char *num )
 {
 	Client *u;
 	hnode_t *un;
 	hscan_t us;
 
-	hash_scan_begin (&us, userhash);
-	while ((un = hash_scan_next (&us)) != NULL) {
-		u = hnode_get (un);
-		if (strncmp (u->name64, num, BASE64NICKSIZE) == 0) {
-			dlog (DEBUG1, "find_user_base64: %s -> %s", num, u->name);
+	hash_scan_begin( &us, userhash );
+	while( ( un = hash_scan_next( &us ) ) != NULL )
+	{
+		u = hnode_get( un );
+		if( strncmp( u->name64, num, BASE64NICKSIZE ) == 0 )
+		{
+			dlog( DEBUG1, "find_user_base64: %s -> %s", num, u->name );
 			return u;
 		}
 	}
-	dlog (DEBUG3, "find_user_base64: %s not found", num);
+	dlog( DEBUG3, "find_user_base64: %s not found", num );
 	return NULL;
 }
 
-Client *FindUser (const char *nick)
+/** @brief FindUser
+ *
+ *  Find user based on nick
+ *  NeoStats core use only.
+ *
+ *  @param nick to find
+ *
+ *  @return pointer to Client or NULL if fails
+ */
+
+Client *FindUser( const char *nick )
 {
 	Client *u;
 
-	u = (Client *)hnode_find (userhash, nick);
-	if (!u) {
-		dlog (DEBUG3, "FindUser: %s not found", nick);
-	}
+	u = ( Client * )hnode_find( userhash, nick );
+	if( !u )
+		dlog( DEBUG3, "FindUser: %s not found", nick );
 	return u;
 }
 
-int InitUsers (void)
+/** @brief InitUsers
+ *
+ *  Init user subsystem
+ *  NeoStats core use only.
+ *
+ *  @param none
+ *
+ *  @return NS_SUCCESS if succeeds, NS_FAILURE if not 
+ */
+
+int InitUsers( void )
 {
-	userhash = hash_create (USER_TABLE_SIZE, 0, 0);
-	if (!userhash)	{
-		nlog (LOG_CRITICAL, "Unable to create user hash");
+	userhash = hash_create( USER_TABLE_SIZE, 0, 0 );
+	if( !userhash )
+	{
+		nlog( LOG_CRITICAL, "Unable to create user hash" );
 		return NS_FAILURE;
 	}
-
 	return NS_SUCCESS;
 }
 
-static int dumpuser (Client *u, void* v)
+/** @brief dumpuser
+ *
+ *  Report user information
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to client to report
+ *  @param v pointer to cmdparams
+ *
+ *  @return NS_FALSE
+ */
+
+static int dumpuser( Client *u, void* v )
 {
 	CmdParams *cmdparams;
 	lnode_t *cm;
 	int i = 0;
 
-	cmdparams = (CmdParams *) v;
-	if (ircd_srv.protocol & PROTOCOL_B64NICK) {
-		irc_prefmsg (ns_botptr, cmdparams->source, __("User:     %s!%s@%s (%s)", cmdparams->source), u->name, u->user->username, u->user->hostname, u->name64);
-	} else {
-		irc_prefmsg (ns_botptr, cmdparams->source, __("User:     %s!%s@%s", cmdparams->source), u->name, u->user->username, u->user->hostname);
-	}
-	irc_prefmsg (ns_botptr, cmdparams->source, __("IP:       %s", cmdparams->source), u->hostip);
-	irc_prefmsg (ns_botptr, cmdparams->source, __("Vhost:    %s", cmdparams->source), u->user->vhost);
-	irc_prefmsg (ns_botptr, cmdparams->source, __("Flags:    0x%x", cmdparams->source), u->flags);
-	irc_prefmsg (ns_botptr, cmdparams->source, __("Modes:    %s (0x%x)", cmdparams->source), UmodeMaskToString(u->user->Umode), u->user->Umode);
-	irc_prefmsg (ns_botptr, cmdparams->source, __("Smodes:   %s (0x%x)", cmdparams->source), SmodeMaskToString(u->user->Smode), u->user->Smode);
-	if( IsAway( u ) ) {
-		irc_prefmsg (ns_botptr, cmdparams->source, __("Away:     %s", cmdparams->source), u->user->awaymsg);
-	}
-	irc_prefmsg (ns_botptr, cmdparams->source, __("Version:  %s", cmdparams->source), u->version);
-
-	cm = list_first (u->user->chans);
-	while (cm) {
-		if (i==0) {
-			irc_prefmsg (ns_botptr, cmdparams->source, __("Channels: %s", cmdparams->source), (char *) lnode_get (cm));
-		} else {
-			irc_prefmsg (ns_botptr, cmdparams->source, "          %s", (char *) lnode_get (cm));
-		}
-		cm = list_next (u->user->chans, cm);
+	cmdparams = ( CmdParams * ) v;
+	if( ircd_srv.protocol & PROTOCOL_B64NICK )
+		irc_prefmsg( ns_botptr, cmdparams->source, __( "User:     %s!%s@%s (%s)", cmdparams->source ), u->name, u->user->username, u->user->hostname, u->name64 );
+	else
+		irc_prefmsg( ns_botptr, cmdparams->source, __( "User:     %s!%s@%s", cmdparams->source ), u->name, u->user->username, u->user->hostname );
+	irc_prefmsg( ns_botptr, cmdparams->source, __( "IP:       %s", cmdparams->source ), u->hostip );
+	irc_prefmsg( ns_botptr, cmdparams->source, __( "Vhost:    %s", cmdparams->source ), u->user->vhost );
+	irc_prefmsg( ns_botptr, cmdparams->source, __( "Flags:    0x%x", cmdparams->source ), u->flags );
+	irc_prefmsg( ns_botptr, cmdparams->source, __( "Modes:    %s( 0x%x )", cmdparams->source ), UmodeMaskToString( u->user->Umode ), u->user->Umode );
+	irc_prefmsg( ns_botptr, cmdparams->source, __( "Smodes:   %s( 0x%x )", cmdparams->source ), SmodeMaskToString( u->user->Smode ), u->user->Smode );
+	if( IsAway( u ) )
+		irc_prefmsg( ns_botptr, cmdparams->source, __( "Away:     %s", cmdparams->source ), u->user->awaymsg );
+	irc_prefmsg( ns_botptr, cmdparams->source, __( "Version:  %s", cmdparams->source ), u->version );
+
+	cm = list_first( u->user->chans );
+	while( cm )
+	{
+		if( i==0 )
+			irc_prefmsg( ns_botptr, cmdparams->source, __( "Channels: %s", cmdparams->source ),( char * ) lnode_get( cm ) );
+		else
+			irc_prefmsg( ns_botptr, cmdparams->source, "          %s",( char * ) lnode_get( cm ) );
+		cm = list_next( u->user->chans, cm );
 		i++;
 	}
-	irc_prefmsg (ns_botptr, cmdparams->source, "========================================");
+	irc_prefmsg( ns_botptr, cmdparams->source, "========================================" );
 	return NS_FALSE;
 }
 
-void ListUsers (CmdParams *cmdparams, const char *nick)
+/** @brief ListUsers
+ *
+ *  Report current user list
+ *  NeoStats core use only.
+ *
+ *  @param cmdparams
+ *  @param nick
+ *
+ *  @return none
+ */
+
+void ListUsers( CmdParams *cmdparams, const char *nick )
 {
 	Client *u;
 
-	if (!nsconfig.debug)
+	if( !nsconfig.debug )
 		return;
 	SET_SEGV_LOCATION();
-	irc_prefmsg (ns_botptr, cmdparams->source, __("================USERLIST================", cmdparams->source));
-	if (!nick) {
-		ProcessUserList (dumpuser, cmdparams);
-	} else {
-		u = FindUser (nick);
-		if (u) {
-			dumpuser (u, (void *)cmdparams);
-		} else {
-			irc_prefmsg (ns_botptr, cmdparams->source, __("ListUsers: can't find user %s", cmdparams->source), nick);
-		}
+	irc_prefmsg( ns_botptr, cmdparams->source, __( "================USERLIST================", cmdparams->source ) );
+	if( !nick )
+	{
+		ProcessUserList( dumpuser, cmdparams );
+		return;
 	}
+	u = FindUser( nick );
+	if( u )
+		dumpuser( u,( void * )cmdparams );
+	else
+		irc_prefmsg( ns_botptr, cmdparams->source, __( "ListUsers: can't find user %s", cmdparams->source ), nick );
 }
 
-int UserLevel (Client *u)
+/** @brief UserLevel
+ *
+ *  Calculate user authentication level
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to client to authenticate
+ *
+ *  @return user level
+ */
+
+int UserLevel( Client *u )
 {
 	/* Have we already calculated the user level? */
-	if (u->user->ulevel != -1) {
+	if( u->user->ulevel != -1 )
 		return u->user->ulevel;
-	}
-	u->user->ulevel = AuthUser(u);
+	u->user->ulevel = AuthUser( u );
 	/* Set user level so we no longer need to calculate */
-	dlog (DEBUG1, "UserLevel for %s is %d", u->name, u->user->ulevel);
+	dlog( DEBUG1, "UserLevel for %s set to %d", u->name, u->user->ulevel );
 	return u->user->ulevel;
 }
 
-void SetUserVhost (const char *nick, const char *vhost) 
+/** @brief SetUserVhost
+ *
+ *  Process IRC VHOST
+ *  NeoStats core use only.
+ *
+ *  @param nick to set vhost for
+ *  @param vhost to set
+ *
+ *  @return none
+ */
+
+void SetUserVhost( const char *nick, const char *vhost ) 
 {
 	Client *u;
 
-	u = FindUser (nick);
-	dlog (DEBUG1, "Vhost %s", vhost);
-	if (u) {
-		strlcpy (u->user->vhost, vhost, MAXHOST);
+	u = FindUser( nick );
+	dlog( DEBUG1, "Vhost %s", vhost );
+	if( u )
+	{
+		strlcpy( u->user->vhost, vhost, MAXHOST );
 		ircsnprintf( u->user->uservhostmask, USERHOSTLEN, "%s!%s@%s", nick, u->user->username, vhost );
 		/* sethost on Unreal doesn't send +xt, but /umode +x sends +x 
-		* so, we will never be 100% sure about +t 
-		*/
-		if (ircd_srv.features&FEATURE_UMODECLOAK) {
+		 * so, we will never be 100% sure about +t 
+		 */
+		if( ircd_srv.features&FEATURE_UMODECLOAK )
 			u->user->Umode |= UMODE_HIDE;
-		}
 	}
 }
 
-void UserMode (const char *nick, const char *modes)
+/** @brief UserMode
+ *
+ *  Process IRC MODE
+ *  NeoStats core use only.
+ *
+ *  @param nick to change mode for
+ *  @param modes to set
+ *
+ *  @return none
+ */
+
+void UserMode( const char *nick, const char *modes )
 {
 	CmdParams *cmdparams;
 	Client *u;
 	long oldmode;
 
 	SET_SEGV_LOCATION();
-	dlog (DEBUG1, "UserMode: user %s modes %s", nick, modes);
-	u = FindUser (nick);
-	if (!u) {
-		nlog (LOG_WARNING, "UserMode: mode change for unknown user %s %s", nick, modes);
+	dlog( DEBUG1, "UserMode: user %s modes %s", nick, modes );
+	u = FindUser( nick );
+	if( !u )
+	{
+		nlog( LOG_WARNING, "UserMode: mode change for unknown user %s %s", nick, modes );
 		return;
 	}
 	/* Reset user level so it will be recalculated */
 	u->user->ulevel = -1;
-	strlcpy (u->user->modes, modes, MODESIZE);
+	strlcpy( u->user->modes, modes, MODESIZE );
 	oldmode = u->user->Umode;
-	u->user->Umode |= UmodeStringToMask (modes);
-	if (ircd_srv.features&FEATURE_UMODECLOAK) {
+	u->user->Umode |= UmodeStringToMask( modes );
+	if( ircd_srv.features&FEATURE_UMODECLOAK )
+	{
 		/* Do we have a hidden host any more? */
-		if ((oldmode & UMODE_HIDE) && (!(u->user->Umode & UMODE_HIDE))) {
-			strlcpy (u->user->vhost, u->user->hostname, MAXHOST);
-		}
+		if( ( oldmode & UMODE_HIDE ) &&( !( u->user->Umode & UMODE_HIDE ) ) )
+			strlcpy( u->user->vhost, u->user->hostname, MAXHOST );
 	}
-	dlog (DEBUG1, "UserMode: modes for %s now %x", u->name, u->user->Umode);
-	cmdparams = (CmdParams*) ns_calloc (sizeof(CmdParams));
+	dlog( DEBUG1, "UserMode: modes for %s now %x", u->name, u->user->Umode );
+	cmdparams = ( CmdParams* ) ns_calloc( sizeof( CmdParams ) );
 	cmdparams->source = u;	
-	cmdparams->param = (char*)modes;
-	SendAllModuleEvent (EVENT_UMODE, cmdparams);
-	ns_free (cmdparams);
+	cmdparams->param = ( char *)modes;
+	SendAllModuleEvent( EVENT_UMODE, cmdparams );
+	ns_free( cmdparams );
 }
 
-void UserSMode (const char *nick, const char *modes)
+/** @brief UserSMode
+ *
+ *  Process IRC SMODE
+ *  NeoStats core use only.
+ *
+ *  @param nick to change smode for
+ *  @param smodes to set
+ *
+ *  @return none
+ */
+
+void UserSMode( const char *nick, const char *modes )
 {
 	CmdParams *cmdparams;
 	Client *u;
 
 	SET_SEGV_LOCATION();
-	dlog (DEBUG1, "UserSMode: user %s smodes %s", nick, modes);
-	u = FindUser (nick);
-	if (!u) {
-		nlog (LOG_WARNING, "UserSMode: smode change for unknown user %s %s", nick, modes);
+	dlog( DEBUG1, "UserSMode: user %s smodes %s", nick, modes );
+	u = FindUser( nick );
+	if( !u )
+	{
+		nlog( LOG_WARNING, "UserSMode: smode change for unknown user %s %s", nick, modes );
 		return;
 	}
 	/* Reset user level so it will be recalculated */
 	u->user->ulevel = -1;
-	u->user->Smode |= SmodeStringToMask(modes);
-	dlog (DEBUG1, "UserSMode: smode for %s is now %x", u->name, u->user->Smode);
-	cmdparams = (CmdParams*) ns_calloc (sizeof(CmdParams));
+	u->user->Smode |= SmodeStringToMask( modes );
+	dlog( DEBUG1, "UserSMode: smode for %s is now %x", u->name, u->user->Smode );
+	cmdparams = ( CmdParams* ) ns_calloc( sizeof( CmdParams ) );
 	cmdparams->source = u;	
-	cmdparams->param = (char*)modes;
-	SendAllModuleEvent (EVENT_SMODE, cmdparams);
-	ns_free (cmdparams);
+	cmdparams->param = ( char *)modes;
+	SendAllModuleEvent( EVENT_SMODE, cmdparams );
+	ns_free( cmdparams );
 }
 
-void SetUserServicesTS (const char *nick, const char *ts) 
+/** @brief SetUserServicesTS
+ *
+ *  Process services time stamp
+ *  NeoStats core use only.
+ *
+ *  @param nick
+ *  @param ts
+ *
+ *  @return none
+ */
+
+void SetUserServicesTS( const char *nick, const char *ts ) 
 {
 	Client *u;
 
-	u = FindUser (nick);
-	if (u) {
-		u->user->servicestamp = strtoul(ts, NULL, 10);
-	}
+	u = FindUser( nick );
+	if( u )
+		u->user->servicestamp = strtoul( ts, NULL, 10 );
 }
 
-/* @brief Free up all the user structs and free memory. Called when we close down
+/** @brief FiniUsers
  *
+ *  Fini user subsystem
+ *  NeoStats core use only.
+ *
+ *  @param none
+ *
+ *  @return none
  */
-void FiniUsers (void)
+
+void FiniUsers( void )
 {
 	Client *u;
 	hnode_t *un;
 	hscan_t hs;
 
 	SET_SEGV_LOCATION();
-	hash_scan_begin (&hs, userhash);
-	while ((un = hash_scan_next (&hs)) != NULL) {
-		u = hnode_get (un);
-		PartAllChannels (u, NULL);
+	hash_scan_begin( &hs, userhash );
+	while( ( un = hash_scan_next( &hs ) ) != NULL )
+	{
+		u = hnode_get( un );
+		PartAllChannels( u, NULL );
 		/* something is wrong if its our bots */
-		if (IsMe(u)) {
-			nlog (LOG_NOTICE, "FiniUsers called with a neostats bot online: %s", u->name);
-		}
-		hash_scan_delete (userhash, un);
-		hnode_destroy (un);
-		list_destroy (u->user->chans);
-		ns_free (u->user);
-		ns_free (u);
+		if( IsMe( u ) )
+			nlog( LOG_NOTICE, "FiniUsers called with a neostats bot online: %s", u->name );
+		hash_scan_delete_destroy_node( userhash, un );
+		list_destroy( u->user->chans );
+		ns_free( u->user );
+		ns_free( u );
 	}
-	hash_destroy (userhash);
+	hash_destroy( userhash );
 }
 
-void QuitServerUsers (Client *s)
+/** @brief QuitServerUsers
+ *
+ *  Remove all users from a given server for use with NOQUIT protocols
+ *  NeoStats core use only.
+ *
+ *  @param s pointer to server to quit users of
+ *
+ *  @return none
+ */
+
+void QuitServerUsers( Client *s )
 {
 	Client *u;
 	hnode_t *un;
 	hscan_t hs;
 
 	SET_SEGV_LOCATION();
-	hash_scan_begin (&hs, userhash);
-	while ((un = hash_scan_next (&hs)) != NULL) {
-		u = hnode_get (un);
-		if (u->uplink == s) 
+	hash_scan_begin( &hs, userhash );
+	while( ( un = hash_scan_next( &hs ) ) != NULL )
+	{
+		u = hnode_get( un );
+		if( u->uplink == s ) 
 		{
-			dlog (DEBUG1, "QuitServerUsers: deleting %s from %s", u->name, s->name);
-			QuitUser (u->name, s->name);
+			dlog( DEBUG1, "QuitServerUsers: deleting %s from %s", u->name, s->name );
+			QuitUser( u->name, s->name );
 		}
 	}
 }
 
-int ProcessUserList (UserListHandler handler, void *v)
+/** @brief ProcessUserList
+ *
+ *  Walk user list and call handler for each user
+ *  NeoStats core use only.
+ *
+ *  @param handler to call
+ *  @param v optional pointer
+ *
+ *  @return NS_SUCCESS
+ */
+
+int ProcessUserList( UserListHandler handler, void *v )
 {
 	Client *u;
 	hscan_t scan;
 	hnode_t *node;
 
 	SET_SEGV_LOCATION();
-	hash_scan_begin (&scan, userhash);
-	while ((node = hash_scan_next (&scan)) != NULL) {
-		u = hnode_get (node);
-		if (handler (u, v) == NS_TRUE)
+	hash_scan_begin( &scan, userhash );
+	while( ( node = hash_scan_next( &scan ) ) != NULL )
+	{
+		u = hnode_get( node );
+		if( handler( u, v ) == NS_TRUE )
 			break;
 	}
 	return NS_SUCCESS;
 }
 
-void AddFakeUser (const char *mask)
+/** @brief AddFakeUser
+ *
+ *  Adds fake user to NeoStats
+ *  NeoStats core use only.
+ *
+ *  @param mask of fake user
+ *
+ *  @return none
+ */
+
+void AddFakeUser( const char *mask )
 {
 	char maskcopy[MAXHOST];
 	char *nick;
@@ -615,31 +863,41 @@
 	Client *u;
 
 	SET_SEGV_LOCATION();
-	strlcpy (maskcopy, mask, MAXHOST);
-	nick = strtok (maskcopy, "!");
-	user = strtok (NULL, "@");
-	host = strtok (NULL, "");
-	u = FindUser (nick);
-	if (u) {
-		nlog (LOG_WARNING, "AddUser: trying to add a user that already exists %s", nick);
+	strlcpy( maskcopy, mask, MAXHOST );
+	nick = strtok( maskcopy, "!" );
+	user = strtok( NULL, "@" );
+	host = strtok( NULL, "" );
+	u = FindUser( nick );
+	if( u )
+	{
+		nlog( LOG_WARNING, "AddUser: trying to add a user that already exists %s", nick );
 		return;
 	}
-	u = new_user (nick);
-	if (!u) {
+	u = new_user( nick );
+	if( !u )
 		return;
-	}
 	u->tsconnect = me.now;
-	strlcpy (u->user->hostname, host, MAXHOST);
-	strlcpy (u->user->vhost, host, MAXHOST);
-	strlcpy (u->user->username, user, MAXUSER);
-	strlcpy (u->info, "fake user", MAXREALNAME);
+	strlcpy( u->user->hostname, host, MAXHOST );
+	strlcpy( u->user->vhost, host, MAXHOST );
+	strlcpy( u->user->username, user, MAXUSER );
+	strlcpy( u->info, "fake user", MAXREALNAME );
 	ircsnprintf( u->user->userhostmask, USERHOSTLEN, "%s!%s@%s", nick, user, host );
 	strlcpy( u->user->uservhostmask, u->user->userhostmask, USERHOSTLEN );
 	u->user->tslastmsg = me.now;
-	u->user->chans = list_create (MAXJOINCHANS);
+	u->user->chans = list_create( MAXJOINCHANS );
 }
 
-void DelFakeUser (const char *mask)
+/** @brief DelFakeUser
+ *
+ *  Delete fake user from NeoStats
+ *  NeoStats core use only.
+ *
+ *  @param mask of fake user
+ *
+ *  @return none
+ */
+
+void DelFakeUser( const char *mask )
 {
 	char maskcopy[MAXHOST];
 	char *nick;
@@ -648,96 +906,156 @@
 	Client *u;
 
 	SET_SEGV_LOCATION();
-	strlcpy (maskcopy, mask, MAXHOST);
-	nick = strtok (maskcopy, "!");
-	user = strtok (NULL, "@");
-	host = strtok (NULL, "");
-	u = FindUser (nick);
-	deluser (u);
+	strlcpy( maskcopy, mask, MAXHOST );
+	nick = strtok( maskcopy, "!" );
+	user = strtok( NULL, "@" );
+	host = strtok( NULL, "" );
+	u = FindUser( nick );
+	deluser( u );
 }
 
-hash_t *GetUserHash (void)
-{
-	return userhash;
-}
+/** @brief AllocUserModPtr
+ *
+ *  Allocate memory for a module pointer for a user
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to client to add pointer for
+ *  @param size to allocate
+ *
+ *  @return pointer to allocated memory
+ */
 
-void *AllocUserModPtr (Client* u, int size)
+void *AllocUserModPtr( Client* u, int size )
 {
 	void *ptr;
-	ptr = ns_calloc (size);
-	u->modptr[GET_CUR_MODNUM()] = ptr;
-	fusermoddata |= (1 << GET_CUR_MODNUM());
-	moddatacnt[GET_CUR_MODNUM()]++;
+	ptr = ns_calloc( size );
+	u->modptr[GET_CUR_MODULE_INDEX()] = ptr;
+	GET_CUR_MODULE()->userdatacnt++;
 	return ptr;
 }
 
-void FreeUserModPtr (Client* u)
+/** @brief FreeUserModPtr
+ *
+ *  Free memory for a module pointer for a user
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to client to free pointer for
+ *
+ *  @return none
+ */
+
+void FreeUserModPtr( Client* u )
 {
-	ns_free (u->modptr[GET_CUR_MODNUM()]);
-	moddatacnt[GET_CUR_MODNUM()]--;
-	if (moddatacnt[GET_CUR_MODNUM()] == 0)
-	{
-		fusermoddata &= ~(1 << GET_CUR_MODNUM());
-	}
+	ns_free( u->modptr[GET_CUR_MODULE_INDEX()] );
+	GET_CUR_MODULE()->userdatacnt--;
 }
 
-void* GetUserModPtr (const Client* u)
+/** @brief GetUserModPtr
+ *
+ *  Retrieve module pointer for a user
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to client to lookup pointer for
+ *
+ *  @return none
+ */
+
+void* GetUserModPtr( const Client* u )
 {
-	return u->modptr[GET_CUR_MODNUM()];
+	return u->modptr[GET_CUR_MODULE_INDEX()];
 }
 
-void ClearUserModValue (Client *u)
+/** @brief ClearUserModValue
+ *
+ *  Clear module value for a user
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to client to clear
+ *
+ *  @return none
+ */
+
+void ClearUserModValue( Client *u )
 {
-	if (u)
+	if( u )
 	{
-		u->modvalue[GET_CUR_MODNUM()] = NULL;
-		moddatacnt[GET_CUR_MODNUM()]--;
-	}
-	if (moddatacnt[GET_CUR_MODNUM()] == 0)
-	{
-		fusermoddata &= ~(1 << GET_CUR_MODNUM());
+		u->modvalue[GET_CUR_MODULE_INDEX()] = NULL;
+		GET_CUR_MODULE()->userdatacnt--;
 	}
 }
 
-void SetUserModValue (Client *u, void *data)
+/** @brief SetUserModValue
+ *
+ *  Set module value for a user
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to client to set
+ *  @param data pointer to set
+ *
+ *  @return none
+ */
+
+void SetUserModValue( Client *u, void *data )
 {
-	if (u)
+	if( u )
 	{
-		u->modvalue[GET_CUR_MODNUM()] = data;
-		fusermoddata |= (1 << GET_CUR_MODNUM());
-		moddatacnt[GET_CUR_MODNUM()]++;
+		u->modvalue[GET_CUR_MODULE_INDEX()] = data;
+		GET_CUR_MODULE()->userdatacnt++;
 	}
 }
 
-void *GetUserModValue (const Client *u)
+/** @brief GetUserModValue
+ *
+ *  Retrieve module value for a user
+ *  NeoStats core use only.
+ *
+ *  @param u pointer to client to lookup pointer for
+ *
+ *  @return none
+ */
+
+void *GetUserModValue( const Client *u )
 {
-	if (u)
-	{
-		return u->modvalue[GET_CUR_MODNUM()];
-	}
+	if( u )
+		return u->modvalue[GET_CUR_MODULE_INDEX()];
 	return NULL;	
 }
 
-void CleanupUserModdata (int index)
+/** @brief CleanupUserModdataHandler
+ *
+ *  Cleanup user moddata
+ *
+ *  @param u pointer to user
+ *  @param v not used
+ *
+ *  @return none
+ */
+
+static int CleanupUserModdataHandler( Client *u, void *v )
 {
-	Client *u;
-	hscan_t scan;
-	hnode_t *node;
+	if( u->modptr[GET_CUR_MODULE_INDEX()] )
+		ns_free( u->modptr[GET_CUR_MODULE_INDEX()] );		
+	u->modvalue[GET_CUR_MODULE_INDEX()] = NULL;
+	return NS_FALSE;
+}
+
+/** @brief CleanupUserModdata
+ *
+ *  Clear module data values and pointer left set by an unloaded module
+ *  NeoStats core use only.
+ *
+ *  @param index of module to clear
+ *
+ *  @return none
+ */
 
+void CleanupUserModdata( int index )
+{
 	SET_SEGV_LOCATION();
-	if (fusermoddata & (1 << index)) {
-		hash_scan_begin (&scan, userhash);
-		if (moddatacnt[index] > 0) {
-			nlog (LOG_WARNING, "Cleaning up users after dirty module!");
-			while ((node = hash_scan_next (&scan)) != NULL) {
-				u = hnode_get (node);
-				if (u->modptr[index]) {
-					ns_free (u->modptr[index]);		
-				}
-				u->modvalue[index] = NULL;
-			}
-		}
-		fusermoddata &= ~(1 << index);
-		moddatacnt[index] = 0;
+	if( GET_CUR_MODULE()->userdatacnt > 0 )
+	{
+		nlog( LOG_WARNING, "Cleaning up users after dirty module!" );
+		ProcessServerList( CleanupUserModdataHandler, NULL );
 	}
+	GET_CUR_MODULE()->userdatacnt = 0;
 }