00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "module.h"
00017
00018 int listOut(User * u);
00019 void myHostServHelp(User * u);
00020
00027 int AnopeInit(int argc, char **argv)
00028 {
00029 Command *c;
00030
00031 moduleAddAuthor("Anope");
00032 moduleAddVersion("$Id: hs_list.c 1265 2007-08-26 15:33:06Z geniusdex $");
00033 moduleSetType(CORE);
00034
00035 c = createCommand("LIST", listOut, is_services_oper, -1, -1,
00036 HOST_HELP_LIST, HOST_HELP_LIST, HOST_HELP_LIST);
00037 moduleAddCommand(HOSTSERV, c, MOD_UNIQUE);
00038 moduleSetHostHelp(myHostServHelp);
00039
00040 return MOD_CONT;
00041 }
00042
00046 void AnopeFini(void)
00047 {
00048
00049 }
00050
00051
00052
00057 void myHostServHelp(User * u)
00058 {
00059 if (is_services_oper(u)) {
00060 notice_lang(s_HostServ, u, HOST_HELP_CMD_LIST);
00061 }
00062 }
00063
00069 int listOut(User * u)
00070 {
00071 char *key = strtok(NULL, "");
00072 struct tm *tm;
00073 char buf[BUFSIZE];
00074 int counter = 1;
00075 int from = 0, to = 0;
00076 char *tmp = NULL;
00077 char *s = NULL;
00078 int display_counter = 0;
00079 HostCore *head = NULL;
00080 HostCore *current;
00081
00082 head = hostCoreListHead();
00083
00084 current = head;
00085 if (current == NULL)
00086 notice_lang(s_HostServ, u, HOST_EMPTY);
00087 else {
00092 if (key) {
00093 if (key[0] == '#') {
00094 tmp = myStrGetOnlyToken((key + 1), '-', 0);
00095 if (!tmp) {
00096 notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
00097 return MOD_CONT;
00098 }
00099 for (s = tmp; *s; s++) {
00100 if (!isdigit(*s)) {
00101 free(tmp);
00102 notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
00103 return MOD_CONT;
00104 }
00105 }
00106 from = atoi(tmp);
00107 free(tmp);
00108 tmp = myStrGetTokenRemainder(key, '-', 1);
00109 if (!tmp) {
00110 notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
00111 return MOD_CONT;
00112 }
00113 for (s = tmp; *s; s++) {
00114 if (!isdigit(*s)) {
00115 free(tmp);
00116 notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE);
00117 return MOD_CONT;
00118 }
00119 }
00120 to = atoi(tmp);
00121 free(tmp);
00122 key = NULL;
00123 }
00124 }
00125
00126 while (current != NULL) {
00127 if (key) {
00128 if (((match_wild_nocase(key, current->nick))
00129 || (match_wild_nocase(key, current->vHost)))
00130 && (display_counter < NSListMax)) {
00131 display_counter++;
00132 tm = localtime(¤t->time);
00133 strftime_lang(buf, sizeof(buf), u,
00134 STRFTIME_DATE_TIME_FORMAT, tm);
00135 if (current->vIdent) {
00136 notice_lang(s_HostServ, u, HOST_IDENT_ENTRY,
00137 counter, current->nick,
00138 current->vIdent, current->vHost,
00139 current->creator, buf);
00140 } else {
00141 notice_lang(s_HostServ, u, HOST_ENTRY, counter,
00142 current->nick, current->vHost,
00143 current->creator, buf);
00144 }
00145 }
00146 } else {
00151 if ((((counter >= from) && (counter <= to))
00152 || ((from == 0) && (to == 0)))
00153 && (display_counter < NSListMax)) {
00154 display_counter++;
00155 tm = localtime(¤t->time);
00156 strftime_lang(buf, sizeof(buf), u,
00157 STRFTIME_DATE_TIME_FORMAT, tm);
00158 if (current->vIdent) {
00159 notice_lang(s_HostServ, u, HOST_IDENT_ENTRY,
00160 counter, current->nick,
00161 current->vIdent, current->vHost,
00162 current->creator, buf);
00163 } else {
00164 notice_lang(s_HostServ, u, HOST_ENTRY, counter,
00165 current->nick, current->vHost,
00166 current->creator, buf);
00167 }
00168 }
00169 }
00170 counter++;
00171 current = current->next;
00172 }
00173 if (key) {
00174 notice_lang(s_HostServ, u, HOST_LIST_KEY_FOOTER, key,
00175 display_counter);
00176 } else {
00177 if (from != 0) {
00178 notice_lang(s_HostServ, u, HOST_LIST_RANGE_FOOTER, from,
00179 to);
00180 } else {
00181 notice_lang(s_HostServ, u, HOST_LIST_FOOTER,
00182 display_counter);
00183 }
00184 }
00185 }
00186 return MOD_CONT;
00187 }