/** * The /hs group command. * @param u The user who issued the command * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. **/ int do_group(User * u) { NickAlias *na; HostCore *tmp; char *vHost = NULL; char *vIdent = NULL; char *creator = NULL; HostCore *head = NULL; time_t time; boolean found = false; head = hostCoreListHead(); if ((na = findnick(u->nick))) { if (na->status & NS_IDENTIFIED) { tmp = findHostCore(head, u->nick, &found); if (found) { if (tmp == NULL) { tmp = head; /* incase first in list */ } else if (tmp->next) { /* we dont want the previous entry were not inserting! */ tmp = tmp->next; /* jump to the next */ } vHost = sstrdup(tmp->vHost); if (tmp->vIdent) vIdent = sstrdup(tmp->vIdent); creator = sstrdup(tmp->creator); time = tmp->time; do_hs_sync(na->nc, vIdent, vHost, creator, time); if (tmp->vIdent) { notice_lang(s_HostServ, u, HOST_IDENT_GROUP, na->nc->display, vIdent, vHost); } else { notice_lang(s_HostServ, u, HOST_GROUP, na->nc->display, vHost); } free(vHost); if (vIdent) free(vIdent); free(creator); } else { notice_lang(s_HostServ, u, HOST_NOT_ASSIGNED); } } else { notice_lang(s_HostServ, u, HOST_ID); } } else { notice_lang(s_HostServ, u, HOST_NOT_REGED); } return MOD_CONT; }
/** * The /hs list command. * @param u The user who issued the command * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. **/ int listOut(User * u) { char *key = strtok(NULL, ""); struct tm *tm; char buf[BUFSIZE]; int counter = 1; int from = 0, to = 0; char *tmp = NULL; char *s = NULL; int display_counter = 0; HostCore *head = NULL; HostCore *current; head = hostCoreListHead(); current = head; if (current == NULL) notice_lang(s_HostServ, u, HOST_EMPTY); else { /** * Do a check for a range here, then in the next loop * we'll only display what has been requested.. **/ if (key) { if (key[0] == '#') { tmp = myStrGetOnlyToken((key + 1), '-', 0); /* Read FROM out */ if (!tmp) { notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE); return MOD_CONT; } for (s = tmp; *s; s++) { if (!isdigit(*s)) { free(tmp); notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE); return MOD_CONT; } } from = atoi(tmp); free(tmp); tmp = myStrGetTokenRemainder(key, '-', 1); /* Read TO out */ if (!tmp) { notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE); return MOD_CONT; } for (s = tmp; *s; s++) { if (!isdigit(*s)) { free(tmp); notice_lang(s_ChanServ, u, LIST_INCORRECT_RANGE); return MOD_CONT; } } to = atoi(tmp); free(tmp); key = NULL; } } while (current != NULL) { if (key) { if (((match_wild_nocase(key, current->nick)) || (match_wild_nocase(key, current->vHost))) && (display_counter < NSListMax)) { display_counter++; tm = localtime(¤t->time); strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm); if (current->vIdent) { notice_lang(s_HostServ, u, HOST_IDENT_ENTRY, counter, current->nick, current->vIdent, current->vHost, current->creator, buf); } else { notice_lang(s_HostServ, u, HOST_ENTRY, counter, current->nick, current->vHost, current->creator, buf); } } } else { /** * List the host if its in the display range, and not more * than NSListMax records have been displayed... **/ if ((((counter >= from) && (counter <= to)) || ((from == 0) && (to == 0))) && (display_counter < NSListMax)) { display_counter++; tm = localtime(¤t->time); strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm); if (current->vIdent) { notice_lang(s_HostServ, u, HOST_IDENT_ENTRY, counter, current->nick, current->vIdent, current->vHost, current->creator, buf); } else { notice_lang(s_HostServ, u, HOST_ENTRY, counter, current->nick, current->vHost, current->creator, buf); } } } counter++; current = current->next; } if (key) { notice_lang(s_HostServ, u, HOST_LIST_KEY_FOOTER, key, display_counter); } else { if (from != 0) { notice_lang(s_HostServ, u, HOST_LIST_RANGE_FOOTER, from, to); } else { notice_lang(s_HostServ, u, HOST_LIST_FOOTER, display_counter); } } } return MOD_CONT; }