]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/uid.cpp
Remove trailing whitespace from various source files.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / uid.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
7  *
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.
11  *
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
15  * details.
16  *
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/>.
19  */
20
21
22 #include "inspircd.h"
23 #include "commands.h"
24
25 #include "utils.h"
26 #include "treeserver.h"
27 #include "remoteuser.h"
28
29 CmdResult CommandUID::HandleServer(TreeServer* remoteserver, CommandBase::Params& params)
30 {
31         /**
32          *      0    1    2    3    4    5        6        7     8        9       (n-1)
33          * UID uuid age nick host dhost ident ip.string signon +modes (modepara) :real
34          */
35         time_t age_t = ServerCommand::ExtractTS(params[1]);
36         time_t signon = ServerCommand::ExtractTS(params[7]);
37         std::string empty;
38         const std::string& modestr = params[8];
39
40         // Check if the length of the uuid is correct and confirm the sid portion of the uuid matches the sid of the server introducing the user
41         if (params[0].length() != UIDGenerator::UUID_LENGTH || params[0].compare(0, 3, remoteserver->GetID()))
42                 throw ProtocolException("Bogus UUID");
43         // Sanity check on mode string: must begin with '+'
44         if (modestr[0] != '+')
45                 throw ProtocolException("Invalid mode string");
46
47         // See if there is a nick collision
48         User* collideswith = ServerInstance->FindNickOnly(params[2]);
49         if ((collideswith) && (collideswith->registered != REG_ALL))
50         {
51                 // User that the incoming user is colliding with is not fully registered, we force nick change the
52                 // unregistered user to their uuid and tell them what happened
53                 LocalUser* const localuser = static_cast<LocalUser*>(collideswith);
54                 localuser->OverruleNick();
55         }
56         else if (collideswith)
57         {
58                 // The user on this side is registered, handle the collision
59                 bool they_change = Utils->DoCollision(collideswith, remoteserver, age_t, params[5], params[6], params[0], "UID");
60                 if (they_change)
61                 {
62                         // The client being introduced needs to change nick to uuid, change the nick in the message before
63                         // processing/forwarding it. Also change the nick TS to CommandSave::SavedTimestamp.
64                         age_t = CommandSave::SavedTimestamp;
65                         params[1] = ConvToStr(CommandSave::SavedTimestamp);
66                         params[2] = params[0];
67                 }
68         }
69
70         /* For remote users, we pass the UUID they sent to the constructor.
71          * If the UUID already exists User::User() throws an exception which causes this connection to be closed.
72          */
73         RemoteUser* _new = new SpanningTree::RemoteUser(params[0], remoteserver);
74         ServerInstance->Users->clientlist[params[2]] = _new;
75         _new->nick = params[2];
76         _new->ChangeRealHost(params[3], false);
77         _new->ChangeDisplayedHost(params[4]);
78         _new->ident = params[5];
79         _new->ChangeRealName(params.back());
80         _new->registered = REG_ALL;
81         _new->signon = signon;
82         _new->age = age_t;
83
84         unsigned int paramptr = 9;
85
86         for (std::string::const_iterator v = modestr.begin(); v != modestr.end(); ++v)
87         {
88                 // Accept more '+' chars, for now
89                 if (*v == '+')
90                         continue;
91
92                 /* For each mode thats set, find the mode handler and set it on the new user */
93                 ModeHandler* mh = ServerInstance->Modes->FindMode(*v, MODETYPE_USER);
94                 if (!mh)
95                         throw ProtocolException("Unrecognised mode '" + std::string(1, *v) + "'");
96
97                 if (mh->NeedsParam(true))
98                 {
99                         if (paramptr >= params.size() - 1)
100                                 throw ProtocolException("Out of parameters while processing modes");
101                         std::string mp = params[paramptr++];
102                         /* IMPORTANT NOTE:
103                          * All modes are assumed to succeed here as they are being set by a remote server.
104                          * Modes CANNOT FAIL here. If they DO fail, then the failure is ignored. This is important
105                          * to note as all but one modules currently cannot ever fail in this situation, except for
106                          * m_servprotect which specifically works this way to prevent the mode being set ANYWHERE
107                          * but here, at client introduction. You may safely assume this behaviour is standard and
108                          * will not change in future versions if you want to make use of this protective behaviour
109                          * yourself.
110                          */
111                         mh->OnModeChange(_new, _new, NULL, mp, true);
112                 }
113                 else
114                         mh->OnModeChange(_new, _new, NULL, empty, true);
115                 _new->SetMode(mh, true);
116         }
117
118         _new->SetClientIP(params[6]);
119
120         ServerInstance->Users->AddClone(_new);
121         remoteserver->UserCount++;
122
123         bool dosend = true;
124
125         if ((Utils->quiet_bursts && remoteserver->IsBehindBursting()) || _new->server->IsSilentULine())
126                 dosend = false;
127
128         if (dosend)
129                 ServerInstance->SNO->WriteToSnoMask('C',"Client connecting at %s: %s (%s) [%s]", remoteserver->GetName().c_str(), _new->GetFullRealHost().c_str(), _new->GetIPString().c_str(), _new->GetRealName().c_str());
130
131         FOREACH_MOD(OnPostConnect, (_new));
132
133         return CMD_SUCCESS;
134 }
135
136 CmdResult CommandFHost::HandleRemote(RemoteUser* src, Params& params)
137 {
138         src->ChangeDisplayedHost(params[0]);
139         return CMD_SUCCESS;
140 }
141
142 CmdResult CommandFIdent::HandleRemote(RemoteUser* src, Params& params)
143 {
144         src->ChangeIdent(params[0]);
145         return CMD_SUCCESS;
146 }
147
148 CmdResult CommandFName::HandleRemote(RemoteUser* src, Params& params)
149 {
150         src->ChangeRealName(params[0]);
151         return CMD_SUCCESS;
152 }
153
154 CommandUID::Builder::Builder(User* user)
155         : CmdBuilder(TreeServer::Get(user)->GetID(), "UID")
156 {
157         push(user->uuid);
158         push_int(user->age);
159         push(user->nick);
160         push(user->GetRealHost());
161         push(user->GetDisplayedHost());
162         push(user->ident);
163         push(user->GetIPString());
164         push_int(user->signon);
165         push(user->GetModeLetters(true));
166         push_last(user->GetRealName());
167 }