1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2005 ChatSpike-Dev.
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
19 #include "inspircd_config.h"
21 #include "inspircd_io.h"
25 #include <ext/hash_map>
43 #include "inspstring.h"
46 #include "helperfuncs.h"
48 #include "socketengine.h"
50 #include "command_parse.h"
53 extern ServerConfig* Config;
54 extern InspIRCd* ServerInstance;
56 extern std::vector<Module*> modules;
57 extern std::vector<ircd_module*> factory;
59 extern user_hash clientlist;
60 extern chan_hash chanlist;
61 extern whowas_hash whowas;
62 extern std::vector<userrec*> all_opers;
63 extern std::vector<userrec*> local_users;
64 extern userrec* fd_ref_table[65536];
66 void cmd_nick::Handle (char **parameters, int pcnt, userrec *user)
68 char oldnick[NICKMAX];
72 log(DEBUG,"not enough params for handle_nick");
77 log(DEBUG,"invalid parameter passed to handle_nick");
80 if (!parameters[0][0])
82 log(DEBUG,"zero length new nick passed to handle_nick");
87 log(DEBUG,"invalid user passed to handle_nick");
92 log(DEBUG,"invalid old nick passed to handle_nick");
95 if (irc::string(user->nick) == irc::string(parameters[0]))
97 /* If its exactly the same, even case, dont do anything. */
98 if (!strcmp(user->nick,parameters[0]))
100 /* Its a change of case. People insisted that they should be
101 * able to do silly things like this even though the RFC says
102 * the nick AAA is the same as the nick aaa.
104 log(DEBUG,"old nick is new nick, not updating hash (case change only)");
105 strlcpy(oldnick,user->nick,NICKMAX);
107 FOREACH_RESULT(OnUserPreNick(user,parameters[0]));
110 strlcpy(user->nick,parameters[0],NICKMAX);
111 if (user->registered == 7)
112 WriteCommon(user,"NICK %s",parameters[0]);
113 FOREACH_MOD OnUserPostNick(user,oldnick);
118 if (strlen(parameters[0]) > 1)
120 if (parameters[0][0] == ':')
125 if (matches_qline(parameters[0]))
127 WriteOpers("*** Q-Lined nickname %s from %s!%s@%s: %s",parameters[0],user->nick,user->ident,user->host,matches_qline(parameters[0]));
128 WriteServ(user->fd,"432 %s %s :Invalid nickname: %s",user->nick,parameters[0],matches_qline(parameters[0]));
131 if ((Find(parameters[0])) && (Find(parameters[0]) != user))
133 WriteServ(user->fd,"433 %s %s :Nickname is already in use.",user->nick,parameters[0]);
137 if (isnick(parameters[0]) == 0)
139 WriteServ(user->fd,"432 %s %s :Erroneous Nickname",user->nick,parameters[0]);
143 if (user->registered == 7)
146 FOREACH_RESULT(OnUserPreNick(user,parameters[0]));
148 // if a module returns true, the nick change is silently forbidden.
152 WriteCommon(user,"NICK %s",parameters[0]);
156 strlcpy(oldnick,user->nick,NICKMAX);
158 /* change the nick of the user in the users_hash */
159 user = ReHashNick(user->nick, parameters[0]);
160 /* actually change the nick within the record */
162 if (!user->nick) return;
164 strlcpy(user->nick, parameters[0],NICKMAX);
166 log(DEBUG,"new nick set: %s",user->nick);
168 if (user->registered < 3)
170 user->registered = (user->registered | 2);
171 // dont attempt to look up the dns until they pick a nick... because otherwise their pointer WILL change
172 // and unless we're lucky we'll get a duff one later on.
173 //user->dns_done = (!lookup_dns(user->nick));
174 //if (user->dns_done)
175 // log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
178 // initialize their dns lookup thread
179 if (pthread_create(&user->dnsthread, NULL, dns_task, (void *)user) != 0)
181 log(DEBUG,"Failed to create DNS lookup thread for user %s",user->nick);
184 user->dns_done = (!lookup_dns(user->nick));
186 log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
190 if (user->registered == 3)
192 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
193 FOREACH_MOD OnUserRegister(user);
196 if (user->registered == 7)
198 FOREACH_MOD OnUserPostNick(user,oldnick);