]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/uid.cpp
Reset the already_sent IDs during slow garbage collection
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / uid.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "commands.h"
16
17 #include "utils.h"
18 #include "link.h"
19 #include "treesocket.h"
20 #include "treeserver.h"
21 #include "resolvers.h"
22
23 CmdResult CommandUID::Handle(const parameterlist &params, User* serversrc)
24 {
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
29          */
30         if (params.size() < 10)
31                 return CMD_INVALID;
32
33         time_t age_t = ConvToInt(params[1]);
34         time_t signon = ConvToInt(params[7]);
35         std::string empty;
36         std::string modestr(params[8]);
37
38         TreeServer* remoteserver = Utils->FindServer(serversrc->server);
39
40         if (!remoteserver)
41                 return CMD_INVALID;
42         /* Check parameters for validity before introducing the client, discovered by dmb */
43         if (!age_t)
44                 return CMD_INVALID;
45         if (!signon)
46                 return CMD_INVALID;
47         if (modestr[0] != '+')
48                 return CMD_INVALID;
49         TreeSocket* sock = remoteserver->GetRoute()->GetSocket();
50
51         /* check for collision */
52         user_hash::iterator iter = ServerInstance->Users->clientlist->find(params[2]);
53
54         if (iter != ServerInstance->Users->clientlist->end())
55         {
56                 /*
57                  * Nick collision.
58                  */
59                 int collide = sock->DoCollision(iter->second, age_t, params[5], modestr, params[0]);
60                 ServerInstance->Logs->Log("m_spanningtree",DEBUG,"*** Collision on %s, collide=%d", params[2].c_str(), collide);
61
62                 if (collide != 1)
63                 {
64                         /* remote client changed, make sure we change their nick for the hash too */
65                         const_cast<parameterlist&>(params)[2] = params[0];
66                 }
67         }
68
69         /* IMPORTANT NOTE: For remote users, we pass the UUID in the constructor. This automatically
70          * sets it up in the UUID hash for us.
71          */
72         User* _new = NULL;
73         try
74         {
75                 _new = new RemoteUser(params[0], remoteserver->GetName());
76         }
77         catch (...)
78         {
79                 return CMD_INVALID;
80         }
81         (*(ServerInstance->Users->clientlist))[params[2]] = _new;
82         _new->nick = params[2];
83         _new->host = params[3];
84         _new->dhost = params[4];
85         _new->ident = params[5];
86         _new->fullname = params[params.size() - 1];
87         _new->registered = REG_ALL;
88         _new->signon = signon;
89         _new->age = age_t;
90
91         /* we need to remove the + from the modestring, so we can do our stuff */
92         std::string::size_type pos_after_plus = modestr.find_first_not_of('+');
93         if (pos_after_plus != std::string::npos)
94         modestr = modestr.substr(pos_after_plus);
95
96         unsigned int paramptr = 9;
97         for (std::string::iterator v = modestr.begin(); v != modestr.end(); v++)
98         {
99                 if (*v == '+')
100                         continue;
101
102                 /* For each mode thats set, increase counter */
103                 ModeHandler* mh = ServerInstance->Modes->FindMode(*v, MODETYPE_USER);
104
105                 if (mh)
106                 {
107                         if (mh->GetNumParams(true))
108                         {
109                                 if (paramptr >= params.size() - 1)
110                                         return CMD_INVALID;
111                                 std::string mp = params[paramptr++];
112                                 /* IMPORTANT NOTE:
113                                  * All modes are assumed to succeed here as they are being set by a remote server.
114                                  * Modes CANNOT FAIL here. If they DO fail, then the failure is ignored. This is important
115                                  * to note as all but one modules currently cannot ever fail in this situation, except for
116                                  * m_servprotect which specifically works this way to prevent the mode being set ANYWHERE
117                                  * but here, at client introduction. You may safely assume this behaviour is standard and
118                                  * will not change in future versions if you want to make use of this protective behaviour
119                                  * yourself.
120                                  */
121                                 mh->OnModeChange(_new, _new, NULL, mp, true);
122                         }
123                         else
124                                 mh->OnModeChange(_new, _new, NULL, empty, true);
125                         _new->SetMode(*v, true);
126                 }
127         }
128
129         /* now we've done with modes processing, put the + back for remote servers */
130         if (modestr[0] != '+')
131                 modestr = "+" + modestr;
132
133         _new->SetClientIP(params[6].c_str());
134
135         ServerInstance->Users->AddGlobalClone(_new);
136         remoteserver->SetUserCount(1); // increment by 1
137
138         bool dosend = true;
139
140         if ((Utils->quiet_bursts && remoteserver->bursting) || ServerInstance->SilentULine(_new->server))
141                 dosend = false;
142
143         if (dosend)
144                 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());
145
146         FOREACH_MOD(I_OnPostConnect,OnPostConnect(_new));
147
148         return CMD_SUCCESS;
149 }
150
151 CmdResult CommandFHost::Handle(const parameterlist &params, User* src)
152 {
153         if (params.size() < 1)
154                 return CMD_INVALID;
155         if (IS_SERVER(src))
156                 return CMD_FAILURE;
157         src->ChangeDisplayedHost(params[0].c_str());
158         return CMD_SUCCESS;
159 }
160
161 CmdResult CommandFIdent::Handle(const parameterlist &params, User* src)
162 {
163         if (params.size() < 1)
164                 return CMD_INVALID;
165         if (IS_SERVER(src))
166                 return CMD_FAILURE;
167         src->ChangeIdent(params[0].c_str());
168         return CMD_SUCCESS;
169 }
170
171 CmdResult CommandFName::Handle(const parameterlist &params, User* src)
172 {
173         if (params.size() < 1)
174                 return CMD_INVALID;
175         if (IS_SERVER(src))
176                 return CMD_FAILURE;
177         src->ChangeName(params[0].c_str());
178         return CMD_SUCCESS;
179 }
180