static int whowas_do(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) { struct Whowas *temp; int cur = 0; int max = -1, found = 0; char *p, *nick; if(parc < 2 || BadPtr(parv[1])) { sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN), me.name, parv[0]); return 0; } if(parc > 2) max = atoi(parv[2]); if(parc > 3) if(hunt_server(client_p, source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv)) return 0; if((p = strchr(parv[1], ','))) *p = '\0'; nick = parv[1]; temp = WHOWASHASH[hash_whowas_name(nick)]; found = 0; for (; temp; temp = temp->next) { if(!irccmp(nick, temp->name)) { sendto_one(source_p, form_str(RPL_WHOWASUSER), me.name, parv[0], temp->name, temp->username, (IsOperAdmin(source_p))? temp->hostname : temp->rhostname, temp->realname); if(ConfigServerHide.hide_servers && !IsOper(source_p)) sendto_one(source_p, form_str(RPL_WHOISSERVER), me.name, parv[0], temp->name, ServerInfo.network_name, myctime(temp->logoff)); else sendto_one(source_p, form_str(RPL_WHOISSERVER), me.name, parv[0], temp->name, temp->servername, myctime(temp->logoff)); cur++; found++; } if(max > 0 && cur >= max) break; } if(!found) sendto_one(source_p, form_str(ERR_WASNOSUCHNICK), me.name, parv[0], nick); sendto_one(source_p, form_str(RPL_ENDOFWHOWAS), me.name, parv[0], parv[1]); return 0; }
/* ** m_whowas ** parv[0] = sender prefix ** parv[1] = nickname queried */ DLLFUNC CMD_FUNC(m_whowas) { aWhowas *temp; int cur = 0; int max = -1, found = 0; char *p, *nick; if (parc < 2) { sendto_one(sptr, err_str(ERR_NONICKNAMEGIVEN), me.name, parv[0]); return 0; } if (parc > 2) max = atoi(parv[2]); if (parc > 3) if (hunt_server_token(cptr, sptr, MSG_WHOWAS, TOK_WHOWAS, "%s %s :%s", 3, parc, parv)) return 0; if (!MyConnect(sptr) && (max > 20)) max = 20; p = (char *)strchr(parv[1], ','); if (p) *p = '\0'; nick = parv[1]; temp = WHOWASHASH[hash_whowas_name(nick)]; found = 0; for (; temp; temp = temp->next) { if (!mycmp(nick, temp->name)) { sendto_one(sptr, rpl_str(RPL_WHOWASUSER), me.name, parv[0], temp->name, temp->username, (IsOper(sptr) ? temp->hostname : (*temp->virthost != '\0') ? temp->virthost : temp->hostname), temp->realname); if (!((Find_uline(temp->servername)) && !IsOper(sptr) && HIDE_ULINES)) sendto_one(sptr, rpl_str(RPL_WHOISSERVER), me.name, parv[0], temp->name, temp->servername, myctime(temp->logoff)); cur++; found++; } if (max > 0 && cur >= max) break; } if (!found) sendto_one(sptr, err_str(ERR_WASNOSUCHNICK), me.name, parv[0], nick); sendto_one(sptr, rpl_str(RPL_ENDOFWHOWAS), me.name, parv[0], parv[1]); return 0; }
/* * m_whowas - generic message handler * * parv[0] = sender prefix * parv[1] = nickname queried * parv[2] = maximum returned items (optional, default is unlimited) * parv[3] = remote server target (Opers only, max returned items 20) */ int m_whowas(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { struct Whowas *temp; int cur = 0; int max = -1, found = 0; char *p, *nick, *s; if (parc < 2) { send_reply(sptr, ERR_NONICKNAMEGIVEN); return 0; } if (parc > 2) max = atoi(parv[2]); if (parc > 3) if (hunt_server_cmd(sptr, CMD_WHOWAS, cptr, 1, "%s %s :%C", 3, parc, parv)) return 0; parv[1] = canonize(parv[1]); if (!MyConnect(sptr) && (max > 20)) max = 20; /* Set max replies at 20 */ for (s = parv[1]; (nick = ircd_strtok(&p, s, ",")); s = 0) { /* Search through bucket, finding all nicknames that match */ found = 0; for (temp = whowashash[hash_whowas_name(nick)]; temp; temp = temp->hnext) { if (0 == ircd_strcmp(nick, temp->name)) { send_reply(sptr, RPL_WHOWASUSER, temp->name, temp->username, temp->hostname, temp->realname); if (IsAnOper(sptr) && temp->realhost) send_reply(sptr, RPL_WHOISACTUALLY, temp->name, temp->username, temp->realhost, "<untracked>"); send_reply(sptr, RPL_WHOISSERVER, temp->name, (feature_bool(FEAT_HIS_WHOIS_SERVERNAME) && !IsOper(sptr)) ? feature_str(FEAT_HIS_SERVERNAME) : temp->servername, myctime(temp->logoff)); if (temp->away) send_reply(sptr, RPL_AWAY, temp->name, temp->away); cur++; found++; } if (max >= 0 && cur >= max) break; } if (!found) send_reply(sptr, ERR_WASNOSUCHNICK, nick); /* To keep parv[1] intact for ENDOFWHOWAS */ if (p) p[-1] = ','; } send_reply(sptr, RPL_ENDOFWHOWAS, parv[1]); return 0; }
struct Client *get_history(const char *nick, time_t timelimit) { struct Whowas *temp; int blah; timelimit = rb_current_time() - timelimit; blah = hash_whowas_name(nick); temp = WHOWASHASH[blah]; for (; temp; temp = temp->next) { if (irccmp(nick, temp->name)) continue; if (temp->logoff < timelimit) continue; return temp->online; } return NULL; }
void add_history(struct Client *client_p, int online) { struct Whowas *who = &WHOWAS[whowas_next]; s_assert(NULL != client_p); if(client_p == NULL) return; if(who->hashv != -1) { if(who->online) del_whowas_from_clist(&(who->online->whowas), who); del_whowas_from_list(&WHOWASHASH[who->hashv], who); } who->hashv = hash_whowas_name(client_p->name); who->logoff = rb_current_time(); /* * NOTE: strcpy ok here, the sizes in the client struct MUST * match the sizes in the whowas struct */ rb_strlcpy(who->name, client_p->name, sizeof(who->name)); strcpy(who->username, client_p->username); strcpy(who->hostname, client_p->host); strcpy(who->realname, client_p->info); strcpy(who->suser, client_p->user->suser); if(!EmptyString(client_p->sockhost) && strcmp(client_p->sockhost, "0") && show_ip(NULL, client_p)) strcpy(who->sockhost, client_p->sockhost); else who->sockhost[0] = '\0'; who->servername = scache_get_name(client_p->servptr->serv->nameinfo); if(online) { who->online = client_p; add_whowas_to_clist(&(client_p->whowas), who); } else who->online = NULL; add_whowas_to_list(&WHOWASHASH[who->hashv], who); whowas_next++; if(whowas_next == NICKNAMEHISTORYLENGTH) whowas_next = 0; }
void add_history(aClient* cptr, int online) { aWhowas* who = &WHOWAS[whowas_next]; assert(0 != cptr); if (who->hashv != -1) { if (who->online) del_whowas_from_clist(&(who->online->whowas),who); del_whowas_from_list(&WHOWASHASH[who->hashv], who); } who->hashv = hash_whowas_name(cptr->name); who->logoff = CurrentTime; /* * NOTE: strcpy ok here, the sizes in the client struct MUST * match the sizes in the whowas struct */ strncpy_irc(who->name, cptr->name, NICKLEN); who->name[NICKLEN] = '\0'; strcpy(who->username, cptr->username); strcpy(who->hostname, cptr->host); strcpy(who->realname, cptr->info); /* Its not string copied, a pointer to the scache hash is copied -Dianora */ /* strncpy_irc(who->servername, cptr->user->server, HOSTLEN); */ who->servername = cptr->user->server; if (online) { who->online = cptr; add_whowas_to_clist(&(cptr->whowas), who); } else who->online = NULL; add_whowas_to_list(&WHOWASHASH[who->hashv], who); whowas_next++; if (whowas_next == NICKNAMEHISTORYLENGTH) whowas_next = 0; }
void add_history(struct Client *client_p, int online) { struct Whowas *who = &WHOWAS[whowas_next]; s_assert(NULL != client_p); if (client_p == NULL) return; if (who->hashv != -1) { if (who->online) del_whowas_from_clist(&(who->online->whowas), who); del_whowas_from_list(&WHOWASHASH[who->hashv], who); } who->hashv = hash_whowas_name(client_p->name); who->logoff = rb_current_time(); strcpy(who->name, client_p->name); strcpy(who->username, client_p->username); strcpy(who->hostname, client_p->host); strcpy(who->virthost, client_p->virthost); strcpy(who->realname, client_p->info); who->cloak = IsCloaked(client_p); who->servername = client_p->servptr->name; if (online) { who->online = client_p; add_whowas_to_clist(&(client_p->whowas), who); } else who->online = NULL; add_whowas_to_list(&WHOWASHASH[who->hashv], who); whowas_next++; if (whowas_next == NICKNAMEHISTORYLENGTH) whowas_next = 0; }
void add_history(struct Client *client_p, int online) { struct Whowas *who = &WHOWAS[whowas_next]; s_assert(NULL != client_p); if(client_p == NULL) return; if(who->hashv != -1) { if(who->online) del_whowas_from_clist(&(who->online->whowas), who); del_whowas_from_list(&WHOWASHASH[who->hashv], who); } who->hashv = hash_whowas_name(client_p->name); who->logoff = CurrentTime; /* * NOTE: strcpy ok here, the sizes in the client struct MUST * match the sizes in the whowas struct */ strlcpy(who->name, client_p->name, sizeof(who->name)); strcpy(who->username, client_p->username); strcpy(who->hostname, client_p->host); strcpy(who->realname, client_p->info); who->servername = client_p->user->server; if(online) { who->online = client_p; add_whowas_to_clist(&(client_p->whowas), who); } else who->online = NULL; add_whowas_to_list(&WHOWASHASH[who->hashv], who); whowas_next++; if(whowas_next == NICKNAMEHISTORYLENGTH) whowas_next = 0; }
/* ** m_whowas ** parv[1] = nickname queried */ static int m_whowas(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) { struct Whowas *temp; int cur = 0; int max = -1, found = 0; char *p; const char *nick; char tbuf[26]; static time_t last_used = 0L; if(!IsOper(source_p)) { if((last_used + ConfigFileEntry.pace_wait_simple) > rb_current_time()) { sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name, "WHOWAS"); sendto_one(source_p, form_str(RPL_ENDOFWHOWAS), me.name, source_p->name, parv[1]); return 0; } else last_used = rb_current_time(); } if(parc > 2) max = atoi(parv[2]); #if 0 if(parc > 3) if(hunt_server(client_p, source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv)) return 0; #endif if((p = strchr(parv[1], ','))) *p = '\0'; nick = parv[1]; temp = WHOWASHASH[hash_whowas_name(nick)]; found = 0; for (; temp; temp = temp->next) { if(!irccmp(nick, temp->name)) { sendto_one(source_p, form_str(RPL_WHOWASUSER), me.name, source_p->name, temp->name, temp->username, temp->hostname, temp->realname); if (MyOper(source_p) && !EmptyString(temp->sockhost)) #if 0 sendto_one(source_p, form_str(RPL_WHOWASREAL), me.name, source_p->name, temp->name, "<untracked>", temp->sockhost); #else sendto_one_numeric(source_p, RPL_WHOISACTUALLY, form_str(RPL_WHOISACTUALLY), temp->name, temp->sockhost); #endif if (!EmptyString(temp->suser)) sendto_one_numeric(source_p, RPL_WHOISLOGGEDIN, "%s %s :was logged in as", temp->name, temp->suser); if(SeesServers(source_p)) sendto_one_numeric(source_p, RPL_WHOISSERVER, form_str(RPL_WHOISSERVER), temp->name, temp->servername, rb_ctime(temp->logoff, tbuf, sizeof(tbuf))); else sendto_one_numeric(source_p, RPL_WHOISSERVER, form_str(RPL_WHOISSERVER), temp->name, source_p->servptr->mname, rb_ctime(temp->logoff, tbuf, sizeof(tbuf))); cur++; found++; } if(max > 0 && cur >= max) break; } if(!found) sendto_one(source_p, form_str(ERR_WASNOSUCHNICK), me.name, source_p->name, nick); sendto_one(source_p, form_str(RPL_ENDOFWHOWAS), me.name, source_p->name, parv[1]); return 0; }
/* ** m_whowas ** parv[0] = sender prefix ** parv[1] = nickname queried */ int m_whowas(aClient *cptr, aClient *sptr, int parc, char *parv[]) { aWhowas *temp; int cur = 0; int max = -1, found = 0; char *p, *nick; /* char *s; */ static time_t last_used=0L; if (parc < 2) { sendto_one(sptr, form_str(ERR_NONICKNAMEGIVEN), me.name, parv[0]); return 0; } if (parc > 2) max = atoi(parv[2]); if (parc > 3) if (hunt_server(cptr,sptr,":%s WHOWAS %s %s :%s", 3,parc,parv)) return 0; if(!IsAnOper(sptr) && !MyConnect(sptr)) /* pace non local requests */ { if((last_used + WHOIS_WAIT) > CurrentTime) { return 0; } else { last_used = CurrentTime; } } if (!MyConnect(sptr) && (max > 20)) max = 20; /* for (s = parv[1]; (nick = strtoken(&p, s, ",")); s = NULL) */ p = strchr(parv[1],','); if(p) *p = '\0'; nick = parv[1]; temp = WHOWASHASH[hash_whowas_name(nick)]; found = 0; for(;temp;temp=temp->next) { if (!irccmp(nick, temp->name)) { sendto_one(sptr, form_str(RPL_WHOWASUSER), me.name, parv[0], temp->name, temp->username, temp->hostname, temp->realname); sendto_one(sptr, form_str(RPL_WHOISSERVER), me.name, parv[0], temp->name, #ifdef SERVERHIDE IsAnOper(sptr) ? temp->servername : NETWORK_NAME, #else temp->servername, #endif myctime(temp->logoff)); cur++; found++; } if (max > 0 && cur >= max) break; } if (!found) sendto_one(sptr, form_str(ERR_WASNOSUCHNICK), me.name, parv[0], nick); sendto_one(sptr, form_str(RPL_ENDOFWHOWAS), me.name, parv[0], parv[1]); return 0; }