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"
45 #include "helperfuncs.h"
47 #include "socketengine.h"
49 #include "command_parse.h"
52 extern ServerConfig* Config;
53 extern InspIRCd* ServerInstance;
55 extern std::vector<Module*> modules;
56 extern std::vector<ircd_module*> factory;
58 extern user_hash clientlist;
59 extern chan_hash chanlist;
60 extern whowas_hash whowas;
61 extern std::vector<userrec*> all_opers;
62 extern std::vector<userrec*> local_users;
63 extern userrec* fd_ref_table[65536];
65 void cmd_nick::Handle (char **parameters, int pcnt, userrec *user)
69 log(DEBUG,"not enough params for handle_nick");
74 log(DEBUG,"invalid parameter passed to handle_nick");
77 if (!parameters[0][0])
79 log(DEBUG,"zero length new nick passed to handle_nick");
84 log(DEBUG,"invalid user passed to handle_nick");
89 log(DEBUG,"invalid old nick passed to handle_nick");
92 if (!strcasecmp(user->nick,parameters[0]))
94 log(DEBUG,"old nick is new nick, skipping");
99 if (strlen(parameters[0]) > 1)
101 if (parameters[0][0] == ':')
106 if (matches_qline(parameters[0]))
108 WriteOpers("*** Q-Lined nickname %s from %s!%s@%s: %s",parameters[0],user->nick,user->ident,user->host,matches_qline(parameters[0]));
109 WriteServ(user->fd,"432 %s %s :Invalid nickname: %s",user->nick,parameters[0],matches_qline(parameters[0]));
112 if ((Find(parameters[0])) && (Find(parameters[0]) != user))
114 WriteServ(user->fd,"433 %s %s :Nickname is already in use.",user->nick,parameters[0]);
118 if (isnick(parameters[0]) == 0)
120 WriteServ(user->fd,"432 %s %s :Erroneous Nickname",user->nick,parameters[0]);
124 if (user->registered == 7)
127 FOREACH_RESULT(OnUserPreNick(user,parameters[0]));
129 // if a module returns true, the nick change is silently forbidden.
133 WriteCommon(user,"NICK %s",parameters[0]);
137 char oldnick[NICKMAX];
138 strlcpy(oldnick,user->nick,NICKMAX);
140 /* change the nick of the user in the users_hash */
141 user = ReHashNick(user->nick, parameters[0]);
142 /* actually change the nick within the record */
144 if (!user->nick) return;
146 strlcpy(user->nick, parameters[0],NICKMAX);
148 log(DEBUG,"new nick set: %s",user->nick);
150 if (user->registered < 3)
152 user->registered = (user->registered | 2);
153 // dont attempt to look up the dns until they pick a nick... because otherwise their pointer WILL change
154 // and unless we're lucky we'll get a duff one later on.
155 //user->dns_done = (!lookup_dns(user->nick));
156 //if (user->dns_done)
157 // log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
160 // initialize their dns lookup thread
161 if (pthread_create(&user->dnsthread, NULL, dns_task, (void *)user) != 0)
163 log(DEBUG,"Failed to create DNS lookup thread for user %s",user->nick);
166 user->dns_done = (!lookup_dns(user->nick));
168 log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
172 if (user->registered == 3)
174 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
175 FOREACH_MOD OnUserRegister(user);
178 if (user->registered == 7)
180 FOREACH_MOD OnUserPostNick(user,oldnick);