00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef lint
00021 static const char rcsid[] = "$Id: nicklist.c,v 1.11 2005-11-26 23:41:03 stdarg Exp $";
00022 #endif
00023
00024 #include "server.h"
00025
00026 char **nick_list = NULL;
00027 int nick_list_index = -1;
00028 int nick_list_len = 0;
00029 int nick_list_cycled = 0;
00030
00031 void try_next_nick()
00032 {
00033 const char *nick;
00034
00035 nick = nick_get_next();
00036 if (!nick) {
00037 putlog(LOG_MISC, "*", _("Using random nick because %s."),
00038 nick_list_len ? _("none of the defined nicks are valid") : _("there are no nicks defined"));
00039 try_random_nick();
00040 return;
00041 }
00042 printserv(SERVER_QUICK, "NICK %s\r\n", nick);
00043 }
00044
00045 void try_random_nick()
00046 {
00047 printserv(SERVER_QUICK, "NICK egg%d\r\n", random());
00048 }
00049
00050 void nick_list_on_connect()
00051 {
00052 nick_list_index = -1;
00053 nick_list_cycled = 0;
00054 }
00055
00056
00057 const char *nick_get_next()
00058 {
00059 if (nick_list_len <= 0) return(NULL);
00060 nick_list_index++;
00061 if (nick_list_index >= nick_list_len) {
00062 if (nick_list_cycled) return(NULL);
00063 nick_list_cycled = 1;
00064 nick_list_index = 0;
00065 }
00066
00067 return(nick_list[nick_list_index]);
00068 }
00069
00070
00071 int nick_add(const char *nick)
00072 {
00073 nick_list = realloc(nick_list, sizeof(char *) * (nick_list_len+1));
00074 nick_list[nick_list_len] = strdup(nick);
00075 nick_list_len++;
00076 return(0);
00077 }
00078
00079
00080 int nick_del(int num)
00081 {
00082 if (num < 0 || num >= nick_list_len) return(-1);
00083
00084 free(nick_list[num]);
00085 memmove(nick_list + num, nick_list + num + 1, sizeof(*nick_list) * (nick_list_len - num - 1));
00086 nick_list_len--;
00087 if (num < nick_list_index) nick_list_index--;
00088
00089 return(0);
00090 }
00091
00092
00093 int nick_clear()
00094 {
00095 int i;
00096
00097 for (i = 0; i < nick_list_len; i++) free(nick_list[i]);
00098 if (nick_list) free(nick_list);
00099 nick_list = NULL;
00100 nick_list_len = 0;
00101
00102 return(0);
00103 }
00104
00105
00106 int nick_find(const char *nick)
00107 {
00108 int i;
00109
00110 for (i = 0; i < nick_list_len; i++) {
00111 if (!nick || !strcasecmp(nick_list[i], nick)) return(i);
00112 }
00113 return(-1);
00114 }