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 std::vector<userrec*> all_opers;
62 extern std::vector<userrec*> local_users;
63 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
65 void cmd_nick::Handle (char **parameters, int pcnt, userrec *user)
67 char oldnick[NICKMAX];
71 log(DEBUG,"not enough params for handle_nick");
76 log(DEBUG,"invalid parameter passed to handle_nick");
79 if (!parameters[0][0])
81 log(DEBUG,"zero length new nick passed to handle_nick");
86 log(DEBUG,"invalid user passed to handle_nick");
91 log(DEBUG,"invalid old nick passed to handle_nick");
94 if (irc::string(user->nick) == irc::string(parameters[0]))
96 /* If its exactly the same, even case, dont do anything. */
97 if (!strcmp(user->nick,parameters[0]))
99 /* Its a change of case. People insisted that they should be
100 * able to do silly things like this even though the RFC says
101 * the nick AAA is the same as the nick aaa.
103 log(DEBUG,"old nick is new nick, not updating hash (case change only)");
104 strlcpy(oldnick, user->nick, NICKMAX - 1);
106 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
109 if (user->registered == 7)
110 WriteCommon(user,"NICK %s",parameters[0]);
111 strlcpy(user->nick, parameters[0], NICKMAX - 1);
112 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
117 if ((*parameters[0] == ':') && (*(parameters[0]+1) != 0))
121 if (matches_qline(parameters[0]))
123 WriteOpers("*** Q-Lined nickname %s from %s!%s@%s: %s",parameters[0],user->nick,user->ident,user->host,matches_qline(parameters[0]));
124 WriteServ(user->fd,"432 %s %s :Invalid nickname: %s",user->nick,parameters[0],matches_qline(parameters[0]));
127 if ((Find(parameters[0])) && (Find(parameters[0]) != user))
129 WriteServ(user->fd,"433 %s %s :Nickname is already in use.",user->nick,parameters[0]);
133 if (isnick(parameters[0]) == 0)
135 WriteServ(user->fd,"432 %s %s :Erroneous Nickname",user->nick,parameters[0]);
139 if (user->registered == 7)
142 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
144 // if a module returns true, the nick change is silently forbidden.
148 WriteCommon(user,"NICK %s",parameters[0]);
152 strlcpy(oldnick, user->nick, NICKMAX - 1);
154 /* change the nick of the user in the users_hash */
155 user = ReHashNick(user->nick, parameters[0]);
156 /* actually change the nick within the record */
158 if (!user->nick) return;
160 strlcpy(user->nick, parameters[0], NICKMAX - 1);
162 log(DEBUG,"new nick set: %s",user->nick);
164 if (user->registered < 3)
166 user->registered = (user->registered | 2);
167 // dont attempt to look up the dns until they pick a nick... because otherwise their pointer WILL change
168 // and unless we're lucky we'll get a duff one later on.
169 //user->dns_done = (!lookup_dns(user->nick));
170 //if (user->dns_done)
171 // log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
174 // initialize their dns lookup thread
175 if (pthread_create(&user->dnsthread, NULL, dns_task, (void *)user) != 0)
177 log(DEBUG,"Failed to create DNS lookup thread for user %s",user->nick);
180 user->dns_done = (!lookup_dns(user->nick));
182 log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
186 if (user->registered == 3)
188 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
189 FOREACH_MOD(I_OnUserRegister,OnUserRegister(user));
190 //ConnectUser(user,NULL);
192 if (user->registered == 7)
194 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));