unrealircd- supernets unrealircd source & configuration |
git clone git://git.acid.vegas/unrealircd.git |
Log | Files | Refs | Archive | README | LICENSE |
whowas.c (3145B)
1 /* 2 * IRC - Internet Relay Chat, src/modules/out.c 3 * (C) 2004 The UnrealIRCd Team 4 * 5 * See file AUTHORS in IRC package for additional names of 6 * the programmers. 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 1, or (at your option) 11 * any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 */ 22 23 #include "unrealircd.h" 24 25 CMD_FUNC(cmd_whowas); 26 27 #define MSG_WHOWAS "WHOWAS" 28 29 ModuleHeader MOD_HEADER 30 = { 31 "whowas", 32 "5.0", 33 "command /whowas", 34 "UnrealIRCd Team", 35 "unrealircd-6", 36 }; 37 38 MOD_INIT() 39 { 40 CommandAdd(modinfo->handle, MSG_WHOWAS, cmd_whowas, MAXPARA, CMD_USER); 41 MARK_AS_OFFICIAL_MODULE(modinfo); 42 return MOD_SUCCESS; 43 } 44 45 MOD_LOAD() 46 { 47 return MOD_SUCCESS; 48 } 49 50 MOD_UNLOAD() 51 { 52 return MOD_SUCCESS; 53 } 54 55 /* externally defined functions */ 56 extern WhoWas MODVAR WHOWAS[NICKNAMEHISTORYLENGTH]; 57 extern WhoWas MODVAR *WHOWASHASH[WHOWAS_HASH_TABLE_SIZE]; 58 59 /* 60 ** cmd_whowas 61 ** parv[1] = nickname queried 62 */ 63 CMD_FUNC(cmd_whowas) 64 { 65 char request[BUFSIZE]; 66 WhoWas *temp; 67 int cur = 0; 68 int max = -1, found = 0; 69 char *p, *nick; 70 71 if (parc < 2) 72 { 73 sendnumeric(client, ERR_NONICKNAMEGIVEN); 74 return; 75 } 76 77 if (parc > 2) 78 max = atoi(parv[2]); 79 80 if (parc > 3) 81 { 82 if (hunt_server(client, recv_mtags, "WHOWAS", 3, parc, parv)) 83 return; /* Not for us */ 84 } 85 86 if (!MyConnect(client) && (max > 20)) 87 max = 20; 88 89 strlcpy(request, parv[1], sizeof(request)); 90 p = strchr(request, ','); 91 if (p) 92 *p = '\0'; /* cut off at first */ 93 94 nick = request; 95 temp = WHOWASHASH[hash_whowas_name(nick)]; 96 found = 0; 97 for (; temp; temp = temp->next) 98 { 99 if (!mycmp(nick, temp->name)) 100 { 101 sendnumeric(client, RPL_WHOWASUSER, temp->name, 102 temp->username, 103 BadPtr(temp->virthost) ? temp->hostname : temp->virthost, 104 temp->realname); 105 if (!BadPtr(temp->ip) && ValidatePermissionsForPath("client:see:ip",client,NULL,NULL,NULL)) 106 { 107 sendnumericfmt(client, RPL_WHOISHOST, "%s :was connecting from %s@%s %s", 108 temp->name, 109 temp->username, temp->hostname, 110 temp->ip ? temp->ip : ""); 111 } 112 if (IsOper(client) && !BadPtr(temp->account)) 113 { 114 sendnumericfmt(client, RPL_WHOISLOGGEDIN, "%s %s :was logged in as", 115 temp->name, 116 temp->account); 117 } 118 if (!((find_uline(temp->servername)) && !IsOper(client) && HIDE_ULINES)) 119 { 120 sendnumeric(client, RPL_WHOISSERVER, temp->name, temp->servername, 121 myctime(temp->logoff)); 122 } 123 cur++; 124 found++; 125 } 126 if (max > 0 && cur >= max) 127 break; 128 } 129 if (!found) 130 sendnumeric(client, ERR_WASNOSUCHNICK, nick); 131 132 sendnumeric(client, RPL_ENDOFWHOWAS, request); 133 }