1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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 * ---------------------------------------------------
18 #include "treeserver.h"
20 #include "treesocket.h"
21 #include "resolvers.h"
22 #include "handshaketimer.h"
24 /* $ModDep: m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h m_hash.h m_spanningtree/handshaketimer.h */
26 bool TreeSocket::ParseUID(const std::string &source, parameterlist ¶ms)
28 /** Do we have enough parameters:
29 * 0 1 2 3 4 5 6 7 8 9 (n-1)
30 * UID uuid age nick host dhost ident ip.string signon +modes (modepara) :gecos
32 if (params.size() < 10)
34 this->SendError("Invalid client introduction (wanted 10 or more parameters, got " + (params.empty() ? "0" : ConvToStr(params.size())) + "!)");
38 time_t age_t = ConvToInt(params[1]);
39 time_t signon = ConvToInt(params[7]);
42 TreeServer* remoteserver = Utils->FindServer(source);
46 this->SendError("Invalid client introduction (Unknown server "+source+")");
49 /* Check parameters for validity before introducing the client, discovered by dmb */
52 this->SendError("Invalid client introduction (Invalid TS?)");
57 this->SendError("Invalid client introduction (Invalid signon?)");
60 else if (params[8][0] != '+')
62 this->SendError("Invalid client introduction (Malformed MODE sequence?)");
66 /* check for collision */
67 user_hash::iterator iter = ServerInstance->Users->clientlist->find(params[2]);
69 if (iter != ServerInstance->Users->clientlist->end())
74 int collide = this->DoCollision(iter->second, age_t, params[5], params[8], params[0]);
75 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"*** Collision on %s, collide=%d", params[2].c_str(), collide);
79 /* remote client changed, make sure we change their nick for the hash too */
80 params[2] = params[0];
84 /* IMPORTANT NOTE: For remote users, we pass the UUID in the constructor. This automatically
85 * sets it up in the UUID hash for us.
90 _new = new User(params[0]);
94 this->SendError("Protocol violation - Duplicate UUID '" + params[0] + "' on introduction of new user");
97 (*(ServerInstance->Users->clientlist))[params[2]] = _new;
98 _new->SetFd(FD_MAGIC_NUMBER);
99 _new->nick.assign(params[2], 0, MAXBUF);
100 _new->host.assign(params[3], 0, 64);
101 _new->dhost.assign(params[4], 0, 64);
102 _new->server = ServerInstance->FindServerNamePtr(remoteserver->GetName().c_str());
103 _new->ident.assign(params[5], 0, MAXBUF);
104 _new->fullname.assign(params[params.size() - 1], 0, MAXBUF);
105 _new->registered = REG_ALL;
106 _new->signon = signon;
109 /* we need to remove the + from the modestring, so we can do our stuff */
110 std::string::size_type pos_after_plus = params[8].find_first_not_of('+');
111 if (pos_after_plus != std::string::npos)
112 params[8] = params[8].substr(pos_after_plus);
114 unsigned int paramptr = 9;
115 for (std::string::iterator v = params[8].begin(); v != params[8].end(); v++)
120 /* For each mode thats set, increase counter */
121 ModeHandler* mh = ServerInstance->Modes->FindMode(*v, MODETYPE_USER);
125 if (mh->GetNumParams(true))
128 * All modes are assumed to succeed here as they are being set by a remote server.
129 * Modes CANNOT FAIL here. If they DO fail, then the failure is ignored. This is important
130 * to note as all but one modules currently cannot ever fail in this situation, except for
131 * m_servprotect which specifically works this way to prevent the mode being set ANYWHERE
132 * but here, at client introduction. You may safely assume this behaviour is standard and
133 * will not change in future versions if you want to make use of this protective behaviour
136 if (paramptr < params.size() - 1)
137 mh->OnModeChange(_new, _new, NULL, params[paramptr++], true);
140 this->SendError(std::string("Broken UID command, expected a parameter for user mode '")+(*v)+"' but there aren't enough parameters in the command!");
145 mh->OnModeChange(_new, _new, NULL, empty, true);
146 _new->SetMode(*v, true);
151 this->SendError(std::string("Warning: Broken UID command, unknown user mode '")+(*v)+"' in the mode string! (mismatched module?)");
156 /* now we've done with modes processing, put the + back for remote servers */
157 if (params[8][0] != '+')
158 params[8] = "+" + params[8];
160 _new->SetClientIP(params[6].c_str());
162 ServerInstance->Users->AddGlobalClone(_new);
163 remoteserver->SetUserCount(1); // increment by 1
167 if ((this->Utils->quiet_bursts && remoteserver->bursting) || ServerInstance->SilentULine(_new->server))
171 ServerInstance->SNO->WriteToSnoMask('C',"Client connecting at %s: %s!%s@%s [%s] [%s]", _new->server, _new->nick.c_str(), _new->ident.c_str(), _new->host.c_str(), _new->GetIPString(), _new->fullname.c_str());
173 params[params.size() - 1] = ":" + params[params.size() - 1];
174 Utils->DoOneToAllButSender(source, "UID", params, source);
176 FOREACH_MOD(I_OnPostConnect,OnPostConnect(_new));