]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/treesocket2.cpp
Add server.cpp, handles all stuff related to the server command. treesocket2.cpp...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treesocket2.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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/cmd_whois.h"
16 #include "commands/cmd_stats.h"
17 #include "socket.h"
18 #include "wildcard.h"
19 #include "xline.h"
20 #include "transport.h"
21 #include "socketengine.h"
22
23 #include "m_spanningtree/main.h"
24 #include "m_spanningtree/utils.h"
25 #include "m_spanningtree/treeserver.h"
26 #include "m_spanningtree/link.h"
27 #include "m_spanningtree/treesocket.h"
28 #include "m_spanningtree/resolvers.h"
29 #include "m_spanningtree/handshaketimer.h"
30
31 /* $ModDep: m_spanningtree/timesynctimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */
32
33 static std::map<std::string, std::string> warned;       /* Server names that have had protocol violation warnings displayed for them */
34
35 int TreeSocket::WriteLine(std::string line)
36 {
37         Instance->Log(DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
38         line.append("\r\n");
39         return this->Write(line);
40 }
41
42
43 /* Handle ERROR command */
44 bool TreeSocket::Error(std::deque<std::string> &params)
45 {
46         if (params.size() < 1)
47                 return false;
48         this->Instance->SNO->WriteToSnoMask('l',"ERROR from %s: %s",(!InboundServerName.empty() ? InboundServerName.c_str() : myhost.c_str()),params[0].c_str());
49         /* we will return false to cause the socket to close. */
50         return false;
51 }
52
53 void TreeSocket::Split(const std::string &line, std::deque<std::string> &n)
54 {
55         n.clear();
56         irc::tokenstream tokens(line);
57         std::string param;
58         while (tokens.GetToken(param))
59         {
60                 n.push_back(param);
61         }
62         return;
63 }
64
65 bool TreeSocket::ProcessLine(std::string &line)
66 {
67         std::deque<std::string> params;
68         irc::string command;
69         std::string prefix;
70
71         line = line.substr(0, line.find_first_of("\r\n"));
72
73         if (line.empty())
74                 return true;
75
76         Instance->Log(DEBUG, "S[%d] I %s", this->GetFd(), line.c_str());
77
78         this->Split(line.c_str(),params);
79         
80         if (params.empty())
81                 return true;
82         
83         if ((params[0][0] == ':') && (params.size() > 1))
84         {
85                 prefix = params[0].substr(1);
86                 params.pop_front();
87                 
88                 if (prefix.empty())
89                 {
90                         this->SendError("BUG (?) Empty prefix recieved.");
91                         return false;
92                 }
93         }
94         
95         command = params[0].c_str();
96         params.pop_front();
97
98         switch (this->LinkState)
99         {
100                 TreeServer* Node;
101
102                 case WAIT_AUTH_1:
103                         /*
104                          * State WAIT_AUTH_1:
105                          *  Waiting for SERVER command from remote server. Server initiating
106                          *  the connection sends the first SERVER command, listening server
107                          *  replies with theirs if its happy, then if the initiator is happy,
108                          *  it starts to send its net sync, which starts the merge, otherwise
109                          *  it sends an ERROR.
110                          */
111                         if (command == "PASS")
112                         {
113                                 /*
114                                  * Ignore this silently. Some services packages insist on sending PASS, even
115                                  * when it is not required (i.e. by us). We have to ignore this here, otherwise
116                                  * as it's an unknown command (effectively), it will cause the connection to be
117                                  * closed, which probably isn't what people want. -- w00t
118                                  */
119                         }
120                         else if (command == "SERVER")
121                         {
122                                 return this->Inbound_Server(params);
123                         }
124                         else if (command == "ERROR")
125                         {
126                                 return this->Error(params);
127                         }
128                         else if (command == "USER")
129                         {
130                                 this->SendError("Client connections to this port are prohibited.");
131                                 return false;
132                         }
133                         else if (command == "CAPAB")
134                         {
135                                 return this->Capab(params);
136                         }
137                         else
138                         {
139                                 // XXX ...wtf.
140                                 irc::string error = "Invalid command in negotiation phase: " + command;
141                                 this->SendError(assign(error));
142                                 return false;
143                         }
144                 break;
145                 case WAIT_AUTH_2:
146                         /*
147                          * State WAIT_AUTH_2:
148                          *  We have sent SERVER to the other side of the connection. Now we're waiting for them to start BURST.
149                          *  The other option at this stage of things, of course, is for them to close our connection thanks
150                          *  to invalid credentials.. -- w
151                          */
152                         if (command == "SERVER")
153                         {
154                                 /*
155                                  * Connection is either attempting to re-auth itself (stupid) or sending netburst without sending BURST.
156                                  * Both of these aren't allowable, so block them here. -- w
157                                  */
158                                 this->SendError("You may not re-authenticate or commence netburst without sending BURST.");
159                                 return true;
160                         }
161                         else if (command == "BURST")
162                         {
163                                 if (params.size() && Utils->EnableTimeSync)
164                                 {
165                                         bool we_have_delta = (Instance->Time(false) != Instance->Time(true));
166                                         time_t them = atoi(params[0].c_str());
167                                         time_t delta = them - Instance->Time(false);
168                                         if ((delta < -600) || (delta > 600))
169                                         {
170                                                 Instance->SNO->WriteToSnoMask('l',"\2ERROR\2: Your clocks are out by %d seconds (this is more than five minutes). Link aborted, \2PLEASE SYNC YOUR CLOCKS!\2",abs(delta));
171                                                 SendError("Your clocks are out by "+ConvToStr(abs(delta))+" seconds (this is more than five minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!");
172                                                 return false;
173                                         }
174                                         else if ((delta < -30) || (delta > 30))
175                                         {
176                                                 Instance->SNO->WriteToSnoMask('l',"\2WARNING\2: Your clocks are out by %d seconds. Please consider synching your clocks.", abs(delta));
177                                         }
178
179                                         if (!Utils->MasterTime && !we_have_delta)
180                                         {
181                                                 this->Instance->SetTimeDelta(delta);
182                                                 // Send this new timestamp to any other servers
183                                                 Utils->DoOneToMany(Instance->Config->GetSID(), "TIMESET", params);
184                                         }
185                                 }
186                                 this->LinkState = CONNECTED;
187                                 Link* lnk = Utils->FindLink(InboundServerName);
188
189                                 Node = new TreeServer(this->Utils, this->Instance, InboundServerName, InboundDescription, InboundSID, Utils->TreeRoot, this, lnk ? lnk->Hidden : false);
190
191                                 if (Node->DuplicateID())
192                                 {
193                                         this->SendError("Server ID "+InboundSID+" already exists on the network!");
194                                         this->Instance->SNO->WriteToSnoMask('l',"Server \2"+InboundServerName+"\2 being introduced from \2" + prefix + "\2 denied, server ID already exists on the network. Closing link.");
195                                         return false;
196                                 }
197
198                                 Utils->TreeRoot->AddChild(Node);
199                                 params.clear();
200                                 params.push_back(InboundServerName);
201                                 params.push_back("*");
202                                 params.push_back("1");
203                                 params.push_back(InboundSID);
204                                 params.push_back(":"+InboundDescription);
205                                 Utils->DoOneToAllButSender(Instance->Config->GetSID(),"SERVER",params,InboundServerName);
206                                 Node->bursting = true;
207                                 this->DoBurst(Node);
208                         }
209                         else if (command == "ERROR")
210                         {
211                                 return this->Error(params);
212                         }
213                         else if (command == "CAPAB")
214                         {
215                                 return this->Capab(params);
216                         }
217
218                 break;
219                 case LISTENER:
220                         /*
221                          * This really shouldn't happen.
222                          */
223                         this->SendError("Internal error -- listening socket accepted its own descriptor!!!");
224                         return false;
225                 break;
226                 case CONNECTING:
227                         /*
228                          * State CONNECTING:
229                          *  We're connecting (OUTGOING) to another server. They are in state WAIT_AUTH_1 until they verify
230                          *  our credentials, when they proceed into WAIT_AUTH_2 and send SERVER to us. We then send BURST
231                          *  + our netburst, which will put them into CONNECTED state. -- w
232                          */
233                         if (command == "SERVER")
234                         {
235                                 // Our credentials have been accepted, send netburst. (this puts US into the CONNECTED state)
236                                 return this->Outbound_Reply_Server(params);
237                         }
238                         else if (command == "ERROR")
239                         {
240                                 return this->Error(params);
241                         }
242                         else if (command == "CAPAB")
243                         {
244                                 return this->Capab(params);
245                         }
246                 break;
247                 case CONNECTED:
248                         /*
249                         * State CONNECTED:
250                          *  Credentials have been exchanged, we've gotten their 'BURST' (or sent ours).
251                          *  Anything from here on should be accepted a little more reasonably.
252                          */
253                         if (!prefix.empty())
254                         {
255                                 /*
256                                  * Check for fake direction here, and drop any instances that are found.
257                                  * What is fake direction? Imagine the following server setup:
258                                  *    0AA <-> 0AB <-> 0AC
259                                  * Fake direction would be 0AC sending a message to 0AB claiming to be from
260                                  * 0AA, or something similar. Basically, a message taking a path that *cannot*
261                                  * be correct.
262                                  *
263                                  * When would this be seen?
264                                  * Well, hopefully never. It could be caused by race conditions, bugs, or
265                                  * "miscreant" servers, though, so let's check anyway. -- w
266                                  */
267                                 std::string direction = prefix;
268
269                                 User *t = this->Instance->FindUUID(prefix);
270                                 if (t)
271                                 {
272                                         direction = t->server;
273                                 }
274
275                                 TreeServer* route_back_again = Utils->BestRouteTo(direction);
276                                 if ((!route_back_again) || (route_back_again->GetSocket() != this))
277                                 {
278                                         if (route_back_again)
279                                                 Instance->Log(DEBUG,"Protocol violation: Fake direction in command '%s' from connection '%s'",line.c_str(),this->GetName().c_str());
280                                         return true;
281                                 }
282                                 /* Fix by brain:
283                                  * When there is activity on the socket, reset the ping counter so
284                                  * that we're not wasting bandwidth pinging an active server.
285                                  */
286                                 route_back_again->SetNextPingTime(time(NULL) + Utils->PingFreq);
287                                 route_back_again->SetPingFlag();
288                         }
289                         else
290                         {
291                                 /*
292                                  * Empty prefix from a server to server link:
293                                  *  This is somewhat bad/naughty, so let's set the prefix
294                                  *  to be the link that we got it from, so we don't break anything. -- w
295                                  */
296                                 TreeServer* n = Utils->FindServer(GetName());
297                                 if (n)
298                                         prefix = n->GetID();
299                                 else
300                                         prefix = GetName();
301                         }
302
303                         /*
304                          * First up, check for any malformed commands (e.g. MODE without a timestamp)
305                          * and rewrite commands where necessary (SVSMODE -> MODE for services). -- w
306                          */
307                         if (command == "MODE")
308                         {
309                                 if (params.size() >= 2)
310                                 {
311                                         Channel* channel = Instance->FindChan(params[0]);
312                                         if (channel)
313                                         {
314                                                 User* x = Instance->FindNick(prefix);
315                                                 if (x)
316                                                 {
317                                                         if (warned.find(x->server) == warned.end())
318                                                         {
319                                                                 Instance->Log(DEFAULT,"WARNING: I revceived modes '%s' from another server '%s'. This is not compliant with InspIRCd. Please check that server for bugs.", params[1].c_str(), x->server);
320                                                                 Instance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending nonstandard modes: '%s MODE %s' where FMODE should be used, and may cause desyncs.", x->server, x->nick, params[1].c_str());
321                                                                 warned[x->server] = x->nick;
322                                                         }
323                                                 }
324                                         }
325                                 }
326                         }
327                         else if (command == "SVSMODE")
328                         {
329                                 command = "MODE";
330                         }
331
332
333                         /*
334                          * Now, check for (and parse) commands as appropriate. -- w
335                          */     
336                 
337                         /* Find the server that this command originated from, used in the handlers below */
338                         TreeServer *ServerSource = Utils->FindServer(prefix);
339
340                         /* Find the link we just got this from so we don't bounce it back incorrectly */
341                         std::string sourceserv = this->myhost;
342                         if (!this->InboundServerName.empty())
343                         {
344                                 sourceserv = this->InboundServerName;
345                         }
346
347                         /*
348                          * XXX one of these days, this needs to be moved into class Commands.
349                          */
350                         if (command == "UID")
351                         {
352                                 return this->ParseUID(prefix, params);
353                         }
354                         else if (command == "FJOIN")
355                         {
356                                 return this->ForceJoin(prefix,params);
357                         }
358                         else if (command == "STATS")
359                         {
360                                 return this->Stats(prefix, params);
361                         }
362                         else if (command == "MOTD")
363                         {
364                                 return this->Motd(prefix, params);
365                         }
366                         else if (command == "KILL" && ServerSource)
367                         {
368                                 // Kill from a server
369                                 return this->RemoteKill(prefix,params);
370                         }
371                         else if (command == "MODULES")
372                         {
373                                 return this->Modules(prefix, params);
374                         }
375                         else if (command == "ADMIN")
376                         {
377                                 return this->Admin(prefix, params);
378                         }
379                         else if (command == "SERVER")
380                         {
381                                 return this->RemoteServer(prefix,params);
382                         }
383                         else if (command == "ERROR")
384                         {
385                                 return this->Error(params);
386                         }
387                         else if (command == "OPERTYPE")
388                         {
389                                 return this->OperType(prefix,params);
390                         }
391                         else if (command == "FMODE")
392                         {
393                                 return this->ForceMode(prefix,params);
394                         }
395                         else if (command == "FTOPIC")
396                         {
397                                 return this->ForceTopic(prefix,params);
398                         }
399                         else if (command == "REHASH")
400                         {
401                                 return this->RemoteRehash(prefix,params);
402                         }
403                         else if (command == "METADATA")
404                         {
405                                 return this->MetaData(prefix,params);
406                         }
407                         else if (command == "PING")
408                         {
409                                 return this->LocalPing(prefix,params);
410                         }
411                         else if (command == "PONG")
412                         {
413                                 return this->LocalPong(prefix,params);
414                         }
415                         else if (command == "VERSION")
416                         {
417                                 return this->ServerVersion(prefix,params);
418                         }
419                         else if (command == "FHOST")
420                         {
421                                 return this->ChangeHost(prefix,params);
422                         }
423                         else if (command == "FNAME")
424                         {
425                                 return this->ChangeName(prefix,params);
426                         }
427                         else if (command == "ADDLINE")
428                         {
429                                 return this->AddLine(prefix,params);
430                         }
431                         else if (command == "DELLINE")
432                         {
433                                 return this->DelLine(prefix,params);
434                         }
435                         else if (command == "SVSNICK")
436                         {
437                                 return this->ForceNick(prefix,params);
438                         }
439                         else if (command == "OPERQUIT")
440                         {
441                                 return this->OperQuit(prefix,params);
442                         }
443                         else if (command == "IDLE")
444                         {
445                                 return this->Whois(prefix,params);
446                         }
447                         else if (command == "PUSH")
448                         {
449                                 return this->Push(prefix,params);
450                         }
451                         else if (command == "TIMESET")
452                         {
453                                 return this->HandleSetTime(prefix, params);
454                         }
455                         else if (command == "TIME")
456                         {
457                                 return this->Time(prefix,params);
458                         }
459                         else if ((command == "KICK") && (Utils->IsServer(prefix)))
460                         {
461                                 if (params.size() == 3)
462                                 {
463                                         User* user = this->Instance->FindNick(params[1]);
464                                         Channel* chan = this->Instance->FindChan(params[0]);
465                                         if (user && chan)
466                                         {
467                                                 if (!chan->ServerKickUser(user, params[2].c_str(), false))
468                                                         /* Yikes, the channels gone! */
469                                                         delete chan;
470                                         }
471                                 }
472
473                                 return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
474                         }
475                         else if (command == "SVSJOIN")
476                         {
477                                 return this->ServiceJoin(prefix,params);
478                         }
479                         else if (command == "SVSPART")
480                         {
481                                 return this->ServicePart(prefix,params);
482                         }
483                         else if (command == "SQUIT")
484                         {
485                                 if (params.size() == 2)
486                                 {
487                                         this->Squit(Utils->FindServer(params[0]),params[1]);
488                                 }
489                                 return true;
490                         }
491                         else if (command == "OPERNOTICE")
492                         {
493                                 if (params.size() >= 1)
494                                         Instance->SNO->WriteToSnoMask('A', "From " + prefix + ": " + params[0]);
495                                 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
496                         }
497                         else if (command == "MODENOTICE")
498                         {
499                                 if (params.size() >= 2)
500                                 {
501                                         Instance->Users->WriteMode(params[0].c_str(), WM_AND, "*** From %s: %s", prefix.c_str(), params[1].c_str());
502                                 }
503                                 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
504                         }
505                         else if (command == "SNONOTICE")
506                         {
507                                 if (params.size() >= 2)
508                                 {
509                                         Instance->SNO->WriteToSnoMask(*(params[0].c_str()), "From " + prefix + ": "+ params[1]);
510                                 }
511                                 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
512                         }
513                         else if (command == "BURST")
514                         {
515                                 // Set prefix server as bursting
516                                 if (!ServerSource)
517                                 {
518                                         this->Instance->SNO->WriteToSnoMask('l', "WTF: Got BURST from a nonexistant server(?): %s", prefix.c_str());
519                                         return false;
520                                 }
521                                 
522                                 ServerSource->bursting = true;
523                                 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
524                         }
525                         else if (command == "ENDBURST")
526                         {
527                                 if (!ServerSource)
528                                 {
529                                         this->Instance->SNO->WriteToSnoMask('l', "WTF: Got ENDBURST from a nonexistant server(?): %s", prefix.c_str());
530                                         return false;
531                                 }
532                                 
533                                 ServerSource->FinishBurst();
534                                 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
535                         }
536                         else if (command == "MODE")
537                         {
538                                 // Server-prefix MODE.
539                                 const char* modelist[MAXPARAMETERS];
540                                 for (size_t i = 0; i < params.size(); i++)
541                                         modelist[i] = params[i].c_str();
542                                         
543                                 // Insert into the parser
544                                 this->Instance->SendMode(modelist, params.size(), this->Instance->FakeClient);
545                                 
546                                 // Pass out to the network
547                                 return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
548                         }
549                         else
550                         {
551                                 /*
552                                  * Not a special s2s command. Emulate the user doing it.
553                                  * This saves us having a huge ugly command parser again.
554                                  */
555                                 User *who = this->Instance->FindUUID(prefix);
556
557                                 if (!who)
558                                 {
559                                         // this looks ugly because command is an irc::string
560                                         this->SendError("Command (" + std::string(command.c_str()) + ") from unknown prefix (" + prefix + ")! Dropping link.");
561                                         return false;
562                                 }
563
564                                 if (command == "NICK")
565                                 {
566                                         if (params.size() != 2)
567                                         {
568                                                 SendError("Protocol violation: NICK message without TS - :"+std::string(who->uuid)+" NICK "+params[0]);
569                                                 return false;
570                                         }
571                                         /* Update timestamp on user when they change nicks */
572                                         who->age = atoi(params[1].c_str());
573
574                                         /*
575                                          * On nick messages, check that the nick doesnt already exist here.
576                                          * If it does, perform collision logic.
577                                          */
578                                         User* x = this->Instance->FindNickOnly(params[0]);
579                                         if ((x) && (x != who))
580                                         {
581                                                 int collideret = 0;
582                                                 /* x is local, who is remote */
583                                                 collideret = this->DoCollision(x, who->age, who->ident, who->GetIPString(), who->uuid);
584                                                 if (collideret != 1)
585                                                 {
586                                                         /*
587                                                          * Remote client lost, or both lost, parsing this nickchange would be
588                                                          * pointless, as the incoming client's server will soon recieve SVSNICK to
589                                                          * change its nick to its UID. :) -- w00t
590                                                          */
591                                                         return true;
592                                                 }
593                                         }
594                                 }
595                                         
596                                 // its a user
597                                 const char* strparams[127];
598                                 for (unsigned int q = 0; q < params.size(); q++)
599                                 {
600                                         strparams[q] = params[q].c_str();
601                                 }
602
603                                 switch (this->Instance->CallCommandHandler(command.c_str(), strparams, params.size(), who))
604                                 {
605                                         case CMD_INVALID:
606                                                 // command is irc::string, hence ugliness
607                                                 this->SendError("Unrecognised or malformed command '" + std::string(command.c_str()) + "' -- possibly loaded mismatched modules");
608                                                 return false;
609                                                 break;
610                                         /*
611                                          * CMD_LOCALONLY is aliased to CMD_FAILURE, so this won't go out onto the network.
612                                          */
613                                         case CMD_FAILURE:
614                                                 return true;
615                                                 break;
616                                         default:
617                                                 /* CMD_SUCCESS and CMD_USER_DELETED fall through here */
618                                                 break;
619                                 }
620
621                                 return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
622
623                         }
624                         return true;
625                         break; // end of state CONNECTED (phew).
626         }
627         return true;
628 }
629
630 std::string TreeSocket::GetName()
631 {
632         std::string sourceserv = this->myhost;
633         if (!this->InboundServerName.empty())
634         {
635                 sourceserv = this->InboundServerName;
636         }
637         return sourceserv;
638 }
639
640 void TreeSocket::OnTimeout()
641 {
642         if (this->LinkState == CONNECTING)
643         {
644                 Utils->Creator->RemoteMessage(NULL, "CONNECT: Connection to \002%s\002 timed out.", myhost.c_str());
645                 Link* MyLink = Utils->FindLink(myhost);
646                 if (MyLink)
647                         Utils->DoFailOver(MyLink);
648         }
649 }
650
651 void TreeSocket::OnClose()
652 {
653         // Test fix for big fuckup
654         if (this->LinkState != CONNECTED)
655                 return;
656
657         // Connection closed.
658         // If the connection is fully up (state CONNECTED)
659         // then propogate a netsplit to all peers.
660         std::string quitserver = this->myhost;
661         if (!this->InboundServerName.empty())
662         {
663                 quitserver = this->InboundServerName;
664         }
665         TreeServer* s = Utils->FindServer(quitserver);
666         if (s)
667         {
668                 Squit(s,"Remote host closed the connection");
669         }
670
671         if (!quitserver.empty())
672         {
673                 Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' failed.",quitserver.c_str());
674                 time_t server_uptime = Instance->Time() - this->age;    
675                 if (server_uptime)
676                         Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
677         }
678 }
679
680 int TreeSocket::OnIncomingConnection(int newsock, char* ip)
681 {
682         /* To prevent anyone from attempting to flood opers/DDoS by connecting to the server port,
683          * or discovering if this port is the server port, we don't allow connections from any
684          * IPs for which we don't have a link block.
685          */
686         bool found = false;
687
688         found = (std::find(Utils->ValidIPs.begin(), Utils->ValidIPs.end(), ip) != Utils->ValidIPs.end());
689         if (!found)
690         {
691                 for (std::vector<std::string>::iterator i = Utils->ValidIPs.begin(); i != Utils->ValidIPs.end(); i++)
692                         if (irc::sockets::MatchCIDR(ip, (*i).c_str()))
693                                 found = true;
694
695                 if (!found)
696                 {
697                         Utils->Creator->RemoteMessage(NULL,"Server connection from %s denied (no link blocks with that IP address)", ip);
698                         Instance->SE->Close(newsock);
699                         return false;
700                 }
701         }
702
703         TreeSocket* s = new TreeSocket(this->Utils, this->Instance, newsock, ip, this->Hook);
704         s = s; /* Whinge whinge whinge, thats all GCC ever does. */
705         return true;
706 }