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"
23 /* $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 */
25 bool TreeSocket::ParseUID(const std::string &source, parameterlist ¶ms)
27 /** Do we have enough parameters:
28 * 0 1 2 3 4 5 6 7 8 9 (n-1)
29 * UID uuid age nick host dhost ident ip.string signon +modes (modepara) :gecos
31 if (params.size() < 10)
33 this->SendError("Invalid client introduction (wanted 10 or more parameters, got " + (params.empty() ? "0" : ConvToStr(params.size())) + "!)");
37 time_t age_t = ConvToInt(params[1]);
38 time_t signon = ConvToInt(params[7]);
41 TreeServer* remoteserver = Utils->FindServer(source);
45 this->SendError("Invalid client introduction (Unknown server "+source+")");
48 /* Check parameters for validity before introducing the client, discovered by dmb */
51 this->SendError("Invalid client introduction (Invalid TS?)");
56 this->SendError("Invalid client introduction (Invalid signon?)");
59 else if (params[8][0] != '+')
61 this->SendError("Invalid client introduction (Malformed MODE sequence?)");
65 /* check for collision */
66 user_hash::iterator iter = ServerInstance->Users->clientlist->find(params[2]);
68 if (iter != ServerInstance->Users->clientlist->end())
73 int collide = this->DoCollision(iter->second, age_t, params[5], params[8], params[0]);
74 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"*** Collision on %s, collide=%d", params[2].c_str(), collide);
78 /* remote client changed, make sure we change their nick for the hash too */
79 params[2] = params[0];
83 /* IMPORTANT NOTE: For remote users, we pass the UUID in the constructor. This automatically
84 * sets it up in the UUID hash for us.
89 _new = new RemoteUser(params[0], remoteserver->GetName());
93 this->SendError("Protocol violation - Duplicate UUID '" + params[0] + "' on introduction of new user");
96 (*(ServerInstance->Users->clientlist))[params[2]] = _new;
97 _new->nick.assign(params[2], 0, MAXBUF);
98 _new->host.assign(params[3], 0, 64);
99 _new->dhost.assign(params[4], 0, 64);
100 _new->ident.assign(params[5], 0, MAXBUF);
101 _new->fullname.assign(params[params.size() - 1], 0, MAXBUF);
102 _new->registered = REG_ALL;
103 _new->signon = signon;
106 /* we need to remove the + from the modestring, so we can do our stuff */
107 std::string::size_type pos_after_plus = params[8].find_first_not_of('+');
108 if (pos_after_plus != std::string::npos)
109 params[8] = params[8].substr(pos_after_plus);
111 unsigned int paramptr = 9;
112 for (std::string::iterator v = params[8].begin(); v != params[8].end(); v++)
117 /* For each mode thats set, increase counter */
118 ModeHandler* mh = ServerInstance->Modes->FindMode(*v, MODETYPE_USER);
122 if (mh->GetNumParams(true))
125 * All modes are assumed to succeed here as they are being set by a remote server.
126 * Modes CANNOT FAIL here. If they DO fail, then the failure is ignored. This is important
127 * to note as all but one modules currently cannot ever fail in this situation, except for
128 * m_servprotect which specifically works this way to prevent the mode being set ANYWHERE
129 * but here, at client introduction. You may safely assume this behaviour is standard and
130 * will not change in future versions if you want to make use of this protective behaviour
133 if (paramptr < params.size() - 1)
134 mh->OnModeChange(_new, _new, NULL, params[paramptr++], true);
137 this->SendError(std::string("Broken UID command, expected a parameter for user mode '")+(*v)+"' but there aren't enough parameters in the command!");
142 mh->OnModeChange(_new, _new, NULL, empty, true);
143 _new->SetMode(*v, true);
148 this->SendError(std::string("Warning: Broken UID command, unknown user mode '")+(*v)+"' in the mode string! (mismatched module?)");
153 /* now we've done with modes processing, put the + back for remote servers */
154 if (params[8][0] != '+')
155 params[8] = "+" + params[8];
157 _new->SetClientIP(params[6].c_str());
159 ServerInstance->Users->AddGlobalClone(_new);
160 remoteserver->SetUserCount(1); // increment by 1
164 if ((this->Utils->quiet_bursts && remoteserver->bursting) || ServerInstance->SilentULine(_new->server))
168 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());
170 params[params.size() - 1] = ":" + params[params.size() - 1];
171 Utils->DoOneToAllButSender(source, "UID", params, source);
173 FOREACH_MOD(I_OnPostConnect,OnPostConnect(_new));