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"
28 #include "helperfuncs.h"
30 #include "commands/cmd_nick.h"
32 extern ServerConfig* Config;
34 extern std::vector<Module*> modules;
35 extern std::vector<ircd_module*> factory;
38 void cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
40 char oldnick[NICKMAX];
44 log(DEBUG,"not enough params for handle_nick");
49 log(DEBUG,"invalid parameter passed to handle_nick");
52 if (!parameters[0][0])
54 log(DEBUG,"zero length new nick passed to handle_nick");
59 log(DEBUG,"invalid user passed to handle_nick");
64 log(DEBUG,"invalid old nick passed to handle_nick");
67 if (irc::string(user->nick) == irc::string(parameters[0]))
69 /* If its exactly the same, even case, dont do anything. */
70 if (!strcmp(user->nick,parameters[0]))
72 /* Its a change of case. People insisted that they should be
73 * able to do silly things like this even though the RFC says
74 * the nick AAA is the same as the nick aaa.
76 log(DEBUG,"old nick is new nick, not updating hash (case change only)");
77 strlcpy(oldnick, user->nick, NICKMAX - 1);
79 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
82 if (user->registered == REG_ALL)
83 WriteCommon(user,"NICK %s",parameters[0]);
84 strlcpy(user->nick, parameters[0], NICKMAX - 1);
85 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));
90 if ((*parameters[0] == ':') && (*(parameters[0]+1) != 0))
94 if (matches_qline(parameters[0]))
96 WriteOpers("*** Q-Lined nickname %s from %s!%s@%s: %s",parameters[0],user->nick,user->ident,user->host,matches_qline(parameters[0]));
97 WriteServ(user->fd,"432 %s %s :Invalid nickname: %s",user->nick,parameters[0],matches_qline(parameters[0]));
100 if ((Find(parameters[0])) && (Find(parameters[0]) != user))
102 WriteServ(user->fd,"433 %s %s :Nickname is already in use.",user->nick,parameters[0]);
106 if ((isnick(parameters[0]) == 0) && (IS_LOCAL(user)))
108 WriteServ(user->fd,"432 %s %s :Erroneous Nickname",user->nick,parameters[0]);
112 if (user->registered == REG_ALL)
115 FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(user,parameters[0]));
117 // if a module returns true, the nick change is silently forbidden.
121 WriteCommon(user,"NICK %s",parameters[0]);
125 strlcpy(oldnick, user->nick, NICKMAX - 1);
127 /* change the nick of the user in the users_hash */
128 user = ReHashNick(user->nick, parameters[0]);
129 /* actually change the nick within the record */
131 if (!user->nick) return;
133 strlcpy(user->nick, parameters[0], NICKMAX - 1);
135 log(DEBUG,"new nick set: %s",user->nick);
137 if (user->registered < REG_NICKUSER)
139 user->registered = (user->registered | REG_NICK);
140 // dont attempt to look up the dns until they pick a nick... because otherwise their pointer WILL change
141 // and unless we're lucky we'll get a duff one later on.
142 //user->dns_done = (!lookup_dns(user->nick));
143 //if (user->dns_done)
144 // log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
146 if (Config->NoUserDns)
148 user->dns_done = true;
153 // initialize their dns lookup thread
154 pthread_attr_t attribs;
155 pthread_attr_init(&attribs);
156 pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_DETACHED);
157 if (pthread_create(&user->dnsthread, &attribs, dns_task, (void *)user) != 0)
159 log(DEBUG,"Failed to create DNS lookup thread for user %s: %s",user->nick, strerror(errno));
162 user->dns_done = (!lookup_dns(user->nick));
164 log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
168 if (user->registered == REG_NICKUSER)
170 /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
171 FOREACH_MOD(I_OnUserRegister,OnUserRegister(user));
172 //ConnectUser(user,NULL);
174 if (user->registered == REG_ALL)
176 FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick));