[NeoStats-Devel] [Commits] r2630 - in trunk: include src

[email protected]
Newsgroups gmane.comp.neostats.devel
Message-ID <[email protected]>
Author: DNB
Date: Mon May 30 09:19:11 2005
New Revision: 2630

Modified:
   trunk/include/neostats.h
   trunk/src/bots.c
Log:
GenerateBotNick updates

Modified: trunk/include/neostats.h
==============================================================================
--- trunk/include/neostats.h	(original)
+++ trunk/include/neostats.h	Mon May 30 09:19:11 2005
@@ -1267,6 +1267,9 @@
 
 EXPORTFUNC int irc_ctcp_time_req( Bot* botptr, Client* target );
 
+/* bots.c */
+EXPORTFUNC int GenerateBotNick( char *nickbuf, int stublen );
+
 /* users.c */
 EXPORTFUNC Client *FindUser( const char *nick );
 EXPORTFUNC int UserLevel( Client *u );
@@ -1501,7 +1504,7 @@
 EXPORTFUNC int os_sock_write( OS_SOCKET s, const char *buf, int len );
 EXPORTFUNC int os_sock_sendto( OS_SOCKET s, const char* buf, int len, int flags, const struct sockaddr* to, int tolen );
 EXPORTFUNC int os_sock_read( OS_SOCKET s, char *buf, int len );
-EXPORTFUNC int os_sock_recvfrom( OS_SOCKET s, char* buf, int len, int flags, struct sockaddr* from, int* fromlen );
+EXPORTFUNC int os_sock_recvfrom( OS_SOCKET s, char* buf, int len, int flags, struct sockaddr* from, int* fromlen );
 EXPORTFUNC int os_sock_set_nonblocking( OS_SOCKET s );
 EXPORTFUNC int os_sock_connect( OS_SOCKET s, const struct sockaddr* name, int namelen );
 EXPORTFUNC OS_SOCKET os_sock_socket( int socket_family, int socket_type, int protocol );
@@ -1511,8 +1514,8 @@
 EXPORTFUNC int os_sock_ioctl( OS_SOCKET s, int cmd, void* argp );
 EXPORTVAR int os_sock_errno;
 EXPORTFUNC char *os_sock_getlasterrorstring( void );
-EXPORTFUNC char *os_sock_strerror( const int sockerrno );
-EXPORTFUNC int os_sock_select( int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, struct timeval* timeout );
+EXPORTFUNC char *os_sock_strerror( const int sockerrno );
+EXPORTFUNC int os_sock_select( int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, struct timeval* timeout );
 
 /* Memory functions */
 EXPORTFUNC void *os_memset( void *dest, int c, size_t count );
@@ -1520,21 +1523,21 @@
 EXPORTFUNC void *os_malloc( size_t size );
 EXPORTFUNC void os_free( void *ptr );
 
-#ifdef WIN32
-#define OS_SOCK_EMSGSIZE                WSAEMSGSIZE
-#define OS_SOCK_EAGAIN                  WSAEPROCLIM
-#define OS_SOCK_ENOBUFS					WSAENOBUFS 
-#define OS_SOCK_EWOULDBLOCK				WSAEWOULDBLOCK
-#define OS_SOCK_EINPROGRESS				WSAEINPROGRESS
-#define OS_SOCK_EINTR					WSAEINTR
-#else
-#define OS_SOCK_EMSGSIZE                EMSGSIZE
-#define OS_SOCK_EAGAIN                  EAGAIN
-#define OS_SOCK_ENOBUFS					ENOBUFS 
-#define OS_SOCK_EWOULDBLOCK				EWOULDBLOCK
-#define OS_SOCK_EINPROGRESS				EINPROGRESS
-#define OS_SOCK_EINTR					EINTR
-#endif
+#ifdef WIN32
+#define OS_SOCK_EMSGSIZE                WSAEMSGSIZE
+#define OS_SOCK_EAGAIN                  WSAEPROCLIM
+#define OS_SOCK_ENOBUFS					WSAENOBUFS 
+#define OS_SOCK_EWOULDBLOCK				WSAEWOULDBLOCK
+#define OS_SOCK_EINPROGRESS				WSAEINPROGRESS
+#define OS_SOCK_EINTR					WSAEINTR
+#else
+#define OS_SOCK_EMSGSIZE                EMSGSIZE
+#define OS_SOCK_EAGAIN                  EAGAIN
+#define OS_SOCK_ENOBUFS					ENOBUFS 
+#define OS_SOCK_EWOULDBLOCK				EWOULDBLOCK
+#define OS_SOCK_EINPROGRESS				EINPROGRESS
+#define OS_SOCK_EINTR					EINTR
+#endif
 
 /* 
  * Module Interface 

Modified: trunk/src/bots.c
==============================================================================
--- trunk/src/bots.c	(original)
+++ trunk/src/bots.c	Mon May 30 09:19:11 2005
@@ -540,28 +540,36 @@
 /** @brief GenerateBotNick
  *
  *  find a new nick based on the passed nick
- *  Bot subsystem use only.
  *
- *  @param botinfo pointer to bot description
  *  @param pointer to nick buffer
+ *  @param length of passed nick stub
+ *  @param number of characters to add to nick
+ *  @param number of digits to add to nick
  *
  *  @return NS_SUCCESS if succeeds, NS_FAILURE if not 
  */
 
-static int GenerateBotNick( char *nickbuf, int stublen )
+int GenerateBotNick( char *nickbuf, int stublen, int alphacount, int numcount)
 {
-	/* find free nick from Bot nick */
-	/* if room, add random number between 0 and 9 */
-	if( ( stublen + 1 ) < MAXNICK )
+	int i;
+	
+	for ( i = 0 ; i < alphacount ; i++ )
 	{
-		nickbuf[stublen++] = ( ( rand() % 10 ) + 48 );
-		nickbuf[stublen] = '\0';
+		/* if room, add random letter */
+		if( ( stublen + 1 ) < MAXNICK )
+		{
+			nickbuf[stublen++] = ( ( rand() % 26 ) + 97 );
+			nickbuf[stublen] = '\0';
+		}
 	}
-	/* if room, add random letter */
-	if( ( stublen + 1 ) < MAXNICK )
+	for ( i = 0 ; i < numcount ; i++ )
 	{
-		nickbuf[stublen++] = ( ( rand() % 26 ) + 97 );
-		nickbuf[stublen] = '\0';
+		/* if room, add random number between 0 and 9 */
+		if( ( stublen + 1 ) < MAXNICK )
+		{
+			nickbuf[stublen++] = ( ( rand() % 10 ) + 48 );
+			nickbuf[stublen] = '\0';
+		}
 	}
 	if( FindUser( nickbuf ) )
 	{
@@ -604,7 +612,7 @@
 	stublen = strlen( nickbuf );
 	for( i = 0 ; i < NICK_TRIES ; i++ )
 	{
-		if( GenerateBotNick( nickbuf, stublen ) == NS_SUCCESS )
+		if( GenerateBotNick( nickbuf, stublen , (i + 1) , (i + 1)) == NS_SUCCESS )
 			return NS_SUCCESS;
 	}
 	/* Try to auto generate a nick from bot alt nick */
@@ -614,7 +622,7 @@
 		stublen = strlen( nickbuf );
 		for( i = 0 ; i < NICK_TRIES ; i++ )
 		{
-			if( GenerateBotNick( nickbuf, stublen ) == NS_SUCCESS )
+			if( GenerateBotNick( nickbuf, stublen , (i + 1) , (i + 1)) == NS_SUCCESS )
 				return NS_SUCCESS;
 		}
 	}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.