1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
19 #include "treesocket.h"
20 #include "treeserver.h"
21 #include "resolvers.h"
23 CmdResult CommandUID::Handle(const parameterlist ¶ms, User* serversrc)
25 SpanningTreeUtilities* Utils = ((ModuleSpanningTree*)(Module*)creator)->Utils;
26 /** Do we have enough parameters:
27 * 0 1 2 3 4 5 6 7 8 9 (n-1)
28 * UID uuid age nick host dhost ident ip.string signon +modes (modepara) :gecos
30 if (params.size() < 10)
33 time_t age_t = ConvToInt(params[1]);
34 time_t signon = ConvToInt(params[7]);
36 std::string modestr(params[8]);
38 TreeServer* remoteserver = Utils->FindServer(serversrc->server);
42 /* Is this a valid UID, and not misrouted? */
43 if (params[0].length() != 9 || params[0].substr(0,3) != serversrc->uuid)
45 /* Check parameters for validity before introducing the client, discovered by dmb */
50 if (modestr[0] != '+')
52 TreeSocket* sock = remoteserver->GetRoute()->GetSocket();
54 /* check for collision */
55 user_hash::iterator iter = ServerInstance->Users->clientlist->find(params[2]);
57 if (iter != ServerInstance->Users->clientlist->end())
62 int collide = sock->DoCollision(iter->second, age_t, params[5], modestr, params[0]);
63 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"*** Collision on %s, collide=%d", params[2].c_str(), collide);
67 /* remote client lost, make sure we change their nick for the hash too
69 * This alters the line that will be sent to other servers, which
70 * commands normally shouldn't do; hence the required const_cast.
72 const_cast<parameterlist&>(params)[2] = params[0];
76 /* IMPORTANT NOTE: For remote users, we pass the UUID in the constructor. This automatically
77 * sets it up in the UUID hash for us.
82 _new = new RemoteUser(params[0], remoteserver->GetName());
86 ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Duplicate UUID %s in client introduction", params[0].c_str());
89 (*(ServerInstance->Users->clientlist))[params[2]] = _new;
90 _new->nick = params[2];
91 _new->host = params[3];
92 _new->dhost = params[4];
93 _new->ident = params[5];
94 _new->fullname = params[params.size() - 1];
95 _new->registered = REG_ALL;
96 _new->signon = signon;
99 /* we need to remove the + from the modestring, so we can do our stuff */
100 std::string::size_type pos_after_plus = modestr.find_first_not_of('+');
101 if (pos_after_plus != std::string::npos)
102 modestr = modestr.substr(pos_after_plus);
104 unsigned int paramptr = 9;
105 for (std::string::iterator v = modestr.begin(); v != modestr.end(); v++)
107 /* For each mode thats set, increase counter */
108 ModeHandler* mh = ServerInstance->Modes->FindMode(*v, MODETYPE_USER);
112 if (mh->GetNumParams(true))
114 if (paramptr >= params.size() - 1)
116 std::string mp = params[paramptr++];
118 * All modes are assumed to succeed here as they are being set by a remote server.
119 * Modes CANNOT FAIL here. If they DO fail, then the failure is ignored. This is important
120 * to note as all but one modules currently cannot ever fail in this situation, except for
121 * m_servprotect which specifically works this way to prevent the mode being set ANYWHERE
122 * but here, at client introduction. You may safely assume this behaviour is standard and
123 * will not change in future versions if you want to make use of this protective behaviour
126 mh->OnModeChange(_new, _new, NULL, mp, true);
129 mh->OnModeChange(_new, _new, NULL, empty, true);
130 _new->SetMode(*v, true);
134 /* now we've done with modes processing, put the + back for remote servers */
135 if (modestr[0] != '+')
136 modestr = "+" + modestr;
138 _new->SetClientIP(params[6].c_str());
140 ServerInstance->Users->AddGlobalClone(_new);
141 remoteserver->SetUserCount(1); // increment by 1
145 if ((Utils->quiet_bursts && remoteserver->bursting) || ServerInstance->SilentULine(_new->server))
149 ServerInstance->SNO->WriteToSnoMask('C',"Client connecting at %s: %s!%s@%s [%s] [%s]", _new->server.c_str(), _new->nick.c_str(), _new->ident.c_str(), _new->host.c_str(), _new->GetIPString(), _new->fullname.c_str());
151 FOREACH_MOD(I_OnPostConnect,OnPostConnect(_new));
156 CmdResult CommandFHost::Handle(const parameterlist ¶ms, User* src)
158 if (params.size() < 1)
162 src->ChangeDisplayedHost(params[0].c_str());
166 CmdResult CommandFIdent::Handle(const parameterlist ¶ms, User* src)
168 if (params.size() < 1)
172 src->ChangeIdent(params[0].c_str());
176 CmdResult CommandFName::Handle(const parameterlist ¶ms, User* src)
178 if (params.size() < 1)
182 src->ChangeName(params[0].c_str());