1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
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[MAX_DESCRIPTORS];
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 - 1);
107 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
110 if (user->registered == 7)
111 WriteCommon(user,"NICK %s",parameters[0]);
112 strlcpy(user->nick, parameters[0], NICKMAX - 1);
113 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
118 if ((*parameters[0] == ':') && (*(parameters[0]+1) != 0))
122 if (matches_qline(parameters[0]))
124 WriteOpers("*** Q-Lined nickname %s from %s!%s@%s: %s",parameters[0],user->nick,user->ident,user->host,matches_qline(parameters[0]));
125 WriteServ(user->fd,"432 %s %s :Invalid nickname: %s",user->nick,parameters[0],matches_qline(parameters[0]));
128 if ((Find(parameters[0])) && (Find(parameters[0]) != user))
130 WriteServ(user->fd,"433 %s %s :Nickname is already in use.",user->nick,parameters[0]);
134 if (isnick(parameters[0]) == 0)
136 WriteServ(user->fd,"432 %s %s :Erroneous Nickname",user->nick,parameters[0]);
140 if (user->registered == 7)
143 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
145 // if a module returns true, the nick change is silently forbidden.
149 WriteCommon(user,"NICK %s",parameters[0]);
153 strlcpy(oldnick, user->nick, NICKMAX - 1);
155 /* change the nick of the user in the users_hash */
156 user = ReHashNick(user->nick, parameters[0]);
157 /* actually change the nick within the record */
159 if (!user->nick) return;
161 strlcpy(user->nick, parameters[0], NICKMAX - 1);
163 log(DEBUG,"new nick set: %s",user->nick);
165 if (user->registered < 3)
167 user->registered = (user->registered | 2);
168 // dont attempt to look up the dns until they pick a nick... because otherwise their pointer WILL change
169 // and unless we're lucky we'll get a duff one later on.
170 //user->dns_done = (!lookup_dns(user->nick));
171 //if (user->dns_done)
172 // log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
175 // initialize their dns lookup thread
176 if (pthread_create(&user->dnsthread, NULL, dns_task, (void *)user) != 0)
178 log(DEBUG,"Failed to create DNS lookup thread for user %s",user->nick);
181 user->dns_done = (!lookup_dns(user->nick));
183 log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
187 if (user->registered == 3)
189 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
190 FOREACH_MOD(I_OnUserRegister,OnUserRegister(user));
191 //ConnectUser(user,NULL);
193 if (user->registered == 7)
195 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));