2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "treesocket.h"
28 #include "treeserver.h"
29 #include "resolvers.h"
31 CmdResult CommandUID::Handle(const parameterlist ¶ms, User* serversrc)
33 SpanningTreeUtilities* Utils = ((ModuleSpanningTree*)(Module*)creator)->Utils;
34 /** Do we have enough parameters:
35 * 0 1 2 3 4 5 6 7 8 9 (n-1)
36 * UID uuid age nick host dhost ident ip.string signon +modes (modepara) :gecos
38 time_t age_t = ConvToInt(params[1]);
39 time_t signon = ConvToInt(params[7]);
41 std::string modestr(params[8]);
43 TreeServer* remoteserver = Utils->FindServer(serversrc->server);
47 /* Is this a valid UID, and not misrouted? */
48 if (params[0].length() != 9 || params[0].substr(0,3) != serversrc->uuid)
50 /* Check parameters for validity before introducing the client, discovered by dmb */
55 if (modestr[0] != '+')
57 TreeSocket* sock = remoteserver->GetRoute()->GetSocket();
59 /* check for collision */
60 User* const collideswith = ServerInstance->FindNickOnly(params[2]);
62 if ((collideswith) && (collideswith->registered != REG_ALL))
64 // User that the incoming user is colliding with is not fully registered, we force nick change the
65 // unregistered user to their uuid and tell them what happened
66 collideswith->WriteFrom(collideswith, "NICK %s", collideswith->uuid.c_str());
67 collideswith->WriteNumeric(433, "%s %s :Nickname overruled.", collideswith->nick.c_str(), collideswith->nick.c_str());
69 // Clear the bit before calling User::ChangeNick() to make it NOT run the OnUserPostNick() hook
70 collideswith->registered &= ~REG_NICK;
71 collideswith->ChangeNick(collideswith->uuid, true);
73 else if (collideswith)
78 int collide = sock->DoCollision(collideswith, age_t, params[5], params[6], params[0]);
79 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"*** Collision on %s, collide=%d", params[2].c_str(), collide);
83 /* remote client lost, make sure we change their nick for the hash too
85 * This alters the line that will be sent to other servers, which
86 * commands normally shouldn't do; hence the required const_cast.
88 const_cast<parameterlist&>(params)[2] = params[0];
92 /* IMPORTANT NOTE: For remote users, we pass the UUID in the constructor. This automatically
93 * sets it up in the UUID hash for us.
98 _new = new RemoteUser(params[0], remoteserver->GetName());
102 ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Duplicate UUID %s in client introduction", params[0].c_str());
105 (*(ServerInstance->Users->clientlist))[params[2]] = _new;
106 _new->nick = params[2];
107 _new->host = params[3];
108 _new->dhost = params[4];
109 _new->ident = params[5];
110 _new->fullname = params[params.size() - 1];
111 _new->registered = REG_ALL;
112 _new->signon = signon;
115 /* we need to remove the + from the modestring, so we can do our stuff */
116 std::string::size_type pos_after_plus = modestr.find_first_not_of('+');
117 if (pos_after_plus != std::string::npos)
118 modestr = modestr.substr(pos_after_plus);
120 unsigned int paramptr = 9;
121 for (std::string::iterator v = modestr.begin(); v != modestr.end(); v++)
123 /* For each mode thats set, increase counter */
124 ModeHandler* mh = ServerInstance->Modes->FindMode(*v, MODETYPE_USER);
128 if (mh->GetNumParams(true))
130 if (paramptr >= params.size() - 1)
132 std::string mp = params[paramptr++];
134 * All modes are assumed to succeed here as they are being set by a remote server.
135 * Modes CANNOT FAIL here. If they DO fail, then the failure is ignored. This is important
136 * to note as all but one modules currently cannot ever fail in this situation, except for
137 * m_servprotect which specifically works this way to prevent the mode being set ANYWHERE
138 * but here, at client introduction. You may safely assume this behaviour is standard and
139 * will not change in future versions if you want to make use of this protective behaviour
142 mh->OnModeChange(_new, _new, NULL, mp, true);
145 mh->OnModeChange(_new, _new, NULL, empty, true);
146 _new->SetMode(*v, true);
150 /* now we've done with modes processing, put the + back for remote servers */
151 if (modestr[0] != '+')
152 modestr = "+" + modestr;
154 _new->SetClientIP(params[6].c_str());
156 ServerInstance->Users->AddGlobalClone(_new);
157 remoteserver->SetUserCount(1); // increment by 1
161 if ((Utils->quiet_bursts && remoteserver->bursting) || ServerInstance->SilentULine(_new->server))
165 ServerInstance->SNO->WriteToSnoMask('C',"Client connecting at %s: %s (%s) [%s]", _new->server.c_str(), _new->GetFullRealHost().c_str(), _new->GetIPString(), _new->fullname.c_str());
167 FOREACH_MOD(I_OnPostConnect,OnPostConnect(_new));
172 CmdResult CommandFHost::Handle(const parameterlist ¶ms, User* src)
176 src->ChangeDisplayedHost(params[0].c_str());
180 CmdResult CommandFIdent::Handle(const parameterlist ¶ms, User* src)
184 src->ChangeIdent(params[0].c_str());
188 CmdResult CommandFName::Handle(const parameterlist ¶ms, User* src)
192 src->ChangeName(params[0].c_str());