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"
20 #include "configreader.h"
27 #include "helperfuncs.h"
29 #include "commands/cmd_nick.h"
31 extern InspIRCd* ServerInstance;
33 extern std::vector<Module*> modules;
34 extern std::vector<ircd_module*> factory;
37 void cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
39 char oldnick[NICKMAX];
43 log(DEBUG,"not enough params for handle_nick");
48 log(DEBUG,"invalid parameter passed to handle_nick");
51 if (!parameters[0][0])
53 log(DEBUG,"zero length new nick passed to handle_nick");
58 log(DEBUG,"invalid user passed to handle_nick");
63 log(DEBUG,"invalid old nick passed to handle_nick");
66 if (irc::string(user->nick) == irc::string(parameters[0]))
68 /* If its exactly the same, even case, dont do anything. */
69 if (!strcmp(user->nick,parameters[0]))
71 /* Its a change of case. People insisted that they should be
72 * able to do silly things like this even though the RFC says
73 * the nick AAA is the same as the nick aaa.
75 log(DEBUG,"old nick is new nick, not updating hash (case change only)");
76 strlcpy(oldnick, user->nick, NICKMAX - 1);
78 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
81 if (user->registered == REG_ALL)
82 user->WriteCommon("NICK %s",parameters[0]);
83 strlcpy(user->nick, parameters[0], NICKMAX - 1);
84 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
89 if ((*parameters[0] == ':') && (*(parameters[0]+1) != 0))
93 if (matches_qline(parameters[0]))
95 ServerInstance->WriteOpers("*** Q-Lined nickname %s from %s!%s@%s: %s",parameters[0],user->nick,user->ident,user->host,matches_qline(parameters[0]));
96 user->WriteServ("432 %s %s :Invalid nickname: %s",user->nick,parameters[0],matches_qline(parameters[0]));
99 if ((ServerInstance->FindNick(parameters[0])) && (ServerInstance->FindNick(parameters[0]) != user))
101 user->WriteServ("433 %s %s :Nickname is already in use.",user->nick,parameters[0]);
105 if ((isnick(parameters[0]) == 0) && (IS_LOCAL(user)))
107 user->WriteServ("432 %s %s :Erroneous Nickname",user->nick,parameters[0]);
111 if (user->registered == REG_ALL)
114 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
116 // if a module returns true, the nick change is silently forbidden.
120 user->WriteCommon("NICK %s",parameters[0]);
124 strlcpy(oldnick, user->nick, NICKMAX - 1);
126 /* change the nick of the user in the users_hash */
127 user = user->UpdateNickHash(parameters[0]);
128 /* actually change the nick within the record */
130 if (!user->nick) return;
132 strlcpy(user->nick, parameters[0], NICKMAX - 1);
134 log(DEBUG,"new nick set: %s",user->nick);
136 if (user->registered < REG_NICKUSER)
138 user->registered = (user->registered | REG_NICK);
139 // dont attempt to look up the dns until they pick a nick... because otherwise their pointer WILL change
140 // and unless we're lucky we'll get a duff one later on.
141 //user->dns_done = (!lookup_dns(user->nick));
142 //if (user->dns_done)
143 // log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
145 if (ServerInstance->Config->NoUserDns)
147 user->dns_done = true;
151 user->StartDNSLookup();
153 log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
156 if (user->registered == REG_NICKUSER)
158 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
159 FOREACH_MOD(I_OnUserRegister,OnUserRegister(user));
160 //ConnectUser(user,NULL);
162 if (user->registered == REG_ALL)
164 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));