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)
70 log(DEBUG,"not enough params for handle_nick");
75 log(DEBUG,"invalid parameter passed to handle_nick");
78 if (!parameters[0][0])
80 log(DEBUG,"zero length new nick passed to handle_nick");
85 log(DEBUG,"invalid user passed to handle_nick");
90 log(DEBUG,"invalid old nick passed to handle_nick");
93 if (!strcasecmp(user->nick,parameters[0]))
95 log(DEBUG,"old nick is new nick, skipping");
100 if (strlen(parameters[0]) > 1)
102 if (parameters[0][0] == ':')
107 if (matches_qline(parameters[0]))
109 WriteOpers("*** Q-Lined nickname %s from %s!%s@%s: %s",parameters[0],user->nick,user->ident,user->host,matches_qline(parameters[0]));
110 WriteServ(user->fd,"432 %s %s :Invalid nickname: %s",user->nick,parameters[0],matches_qline(parameters[0]));
113 if ((Find(parameters[0])) && (Find(parameters[0]) != user))
115 WriteServ(user->fd,"433 %s %s :Nickname is already in use.",user->nick,parameters[0]);
119 if (isnick(parameters[0]) == 0)
121 WriteServ(user->fd,"432 %s %s :Erroneous Nickname",user->nick,parameters[0]);
125 if (user->registered == 7)
128 FOREACH_RESULT(OnUserPreNick(user,parameters[0]));
130 // if a module returns true, the nick change is silently forbidden.
134 WriteCommon(user,"NICK %s",parameters[0]);
138 char oldnick[NICKMAX];
139 strlcpy(oldnick,user->nick,NICKMAX);
141 /* change the nick of the user in the users_hash */
142 user = ReHashNick(user->nick, parameters[0]);
143 /* actually change the nick within the record */
145 if (!user->nick) return;
147 strlcpy(user->nick, parameters[0],NICKMAX);
149 log(DEBUG,"new nick set: %s",user->nick);
151 if (user->registered < 3)
153 user->registered = (user->registered | 2);
154 // dont attempt to look up the dns until they pick a nick... because otherwise their pointer WILL change
155 // and unless we're lucky we'll get a duff one later on.
156 //user->dns_done = (!lookup_dns(user->nick));
157 //if (user->dns_done)
158 // log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
161 // initialize their dns lookup thread
162 if (pthread_create(&user->dnsthread, NULL, dns_task, (void *)user) != 0)
164 log(DEBUG,"Failed to create DNS lookup thread for user %s",user->nick);
167 user->dns_done = (!lookup_dns(user->nick));
169 log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
173 if (user->registered == 3)
175 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
176 FOREACH_MOD OnUserRegister(user);
179 if (user->registered == 7)
181 FOREACH_MOD OnUserPostNick(user,oldnick);