unrealircd- supernets unrealircd source & configuration |
git clone git://git.acid.vegas/unrealircd.git |
Log | Files | Refs | Archive | README | LICENSE |
svsnick.c (3580B)
1 /* 2 * IRC - Internet Relay Chat, src/modules/svsnick.c 3 * (C) 2001 The UnrealIRCd Team 4 * 5 * svsnick command 6 * 7 * See file AUTHORS in IRC package for additional names of 8 * the programmers. 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 1, or (at your option) 13 * any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 */ 24 25 #include "unrealircd.h" 26 27 CMD_FUNC(cmd_svsnick); 28 29 #define MSG_SVSNICK "SVSNICK" 30 31 ModuleHeader MOD_HEADER 32 = { 33 "svsnick", 34 "5.0", 35 "command /svsnick", 36 "UnrealIRCd Team", 37 "unrealircd-6", 38 }; 39 40 MOD_INIT() 41 { 42 CommandAdd(modinfo->handle, MSG_SVSNICK, cmd_svsnick, MAXPARA, CMD_SERVER); 43 MARK_AS_OFFICIAL_MODULE(modinfo); 44 return MOD_SUCCESS; 45 } 46 47 MOD_LOAD() 48 { 49 return MOD_SUCCESS; 50 } 51 52 MOD_UNLOAD() 53 { 54 return MOD_SUCCESS; 55 } 56 /* 57 ** cmd_svsnick 58 ** parv[1] = old nickname 59 ** parv[2] = new nickname 60 ** parv[3] = timestamp 61 */ 62 CMD_FUNC(cmd_svsnick) 63 { 64 Client *acptr; 65 Client *ocptr; /* Other client */ 66 MessageTag *mtags = NULL; 67 char nickname[NICKLEN+1]; 68 char oldnickname[NICKLEN+1]; 69 time_t ts; 70 71 if (!IsSvsCmdOk(client) || parc < 4 || (strlen(parv[2]) > NICKLEN)) 72 return; /* This looks like an error anyway -Studded */ 73 74 if (hunt_server(client, NULL, "SVSNICK", 1, parc, parv) != HUNTED_ISME) 75 return; /* Forwarded, done */ 76 77 strlcpy(nickname, parv[2], sizeof(nickname)); 78 if (do_nick_name(nickname) == 0) 79 return; 80 81 if (!(acptr = find_user(parv[1], NULL))) 82 return; /* User not found, bail out */ 83 84 if ((ocptr = find_client(nickname, NULL)) && ocptr != acptr) /* Collision */ 85 { 86 exit_client(acptr, NULL, 87 "Nickname collision due to forced " 88 "nickname change, your nick was overruled"); 89 return; 90 } 91 92 /* if the new nickname is identical to the old one, ignore it */ 93 if (!strcmp(acptr->name, nickname)) 94 return; 95 96 strlcpy(oldnickname, acptr->name, sizeof(oldnickname)); 97 98 if (acptr != ocptr) 99 acptr->umodes &= ~UMODE_REGNICK; 100 ts = atol(parv[3]); 101 102 /* no 'recv_mtags' here, we do not inherit from SVSNICK but generate a new NICK event */ 103 new_message(acptr, NULL, &mtags); 104 mtag_add_issued_by(&mtags, client, recv_mtags); 105 RunHook(HOOKTYPE_LOCAL_NICKCHANGE, acptr, mtags, nickname); 106 sendto_local_common_channels(acptr, acptr, 0, mtags, ":%s NICK :%s", acptr->name, nickname); 107 sendto_one(acptr, mtags, ":%s NICK :%s", acptr->name, nickname); 108 sendto_server(NULL, 0, 0, mtags, ":%s NICK %s :%lld", acptr->id, nickname, (long long)ts); 109 110 add_history(acptr, 1, WHOWAS_EVENT_NICK_CHANGE); 111 acptr->lastnick = ts; /* needs to be done AFTER add_history() */ 112 del_from_client_hash_table(acptr->name, acptr); 113 114 unreal_log(ULOG_INFO, "nick", "FORCED_NICK_CHANGE", acptr, 115 "$client.details has been forced to change their nickname to $new_nick_name", 116 log_data_string("new_nick_name", nickname)); 117 118 strlcpy(acptr->name, nickname, sizeof acptr->name); 119 add_to_client_hash_table(nickname, acptr); 120 RunHook(HOOKTYPE_POST_LOCAL_NICKCHANGE, acptr, mtags, oldnickname); 121 free_message_tags(mtags); 122 }