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