1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2005 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
23 #include "inspircd_config.h"
25 #include <ext/hash_map>
33 #include "helperfuncs.h"
35 #include "inspstring.h"
40 #define nspace __gnu_cxx
45 enum ServerState { LISTENER, CONNECTING, WAIT_AUTH_1, WAIT_AUTH_2, CONNECTED };
47 typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, irc::StrHashComp> user_hash;
48 extern user_hash clientlist;
50 const char* OneToEither[] = { "PRIVMSG", "NOTICE", NULL };
51 const char* OneToMany[] = { "NICK", "QUIT", "JOIN", "PART", "MODE", "INVITE", "KICK", "KILL", NULL };
52 const char* OneToOne[] = { "REHASH", "DIE", "TRACE", "WHOIS", NULL };
57 bool DoOneToOne(std::string prefix, std::string command, std::deque<std::string> params, std::string target);
58 bool DoOneToAllButSender(std::string prefix, std::string command, std::deque<std::string> params, std::string omit);
59 bool DoOneToMany(std::string prefix, std::string command, std::deque<std::string> params);
64 std::vector<TreeServer*> Children;
65 std::string ServerName;
66 std::string ServerDesc;
67 std::string VersionString;
70 TreeSocket* Socket; // for directly connected servers this points at the socket object
80 UserCount = OperCount = 0;
83 TreeServer(std::string Name, std::string Desc) : ServerName(Name), ServerDesc(Desc)
87 UserCount = OperCount = 0;
90 TreeServer(std::string Name, std::string Desc, TreeServer* Above, TreeSocket* Sock) : Parent(Above), ServerName(Name), ServerDesc(Desc), Socket(Sock)
93 UserCount = OperCount = 0;
98 return this->ServerName;
101 std::string GetDesc()
103 return this->ServerDesc;
106 std::string GetVersion()
108 return this->VersionString;
113 return this->UserCount;
118 return this->OperCount;
121 TreeSocket* GetSocket()
126 TreeServer* GetParent()
131 unsigned int ChildCount()
133 return Children.size();
136 TreeServer* GetChild(unsigned int n)
138 if (n < Children.size())
148 void AddChild(TreeServer* Child)
150 Children.push_back(Child);
153 bool DelChild(TreeServer* Child)
155 for (std::vector<TreeServer*>::iterator a = Children.begin(); a < Children.end(); a++)
173 std::string SendPass;
174 std::string RecvPass;
177 /* $ModDesc: Povides a spanning tree server link protocol */
181 TreeServer *TreeRoot;
182 std::vector<Link> LinkBlocks;
184 TreeServer* RouteEnumerate(TreeServer* Current, std::string ServerName)
186 if (Current->GetName() == ServerName)
188 for (unsigned int q = 0; q < Current->ChildCount(); q++)
190 TreeServer* found = RouteEnumerate(Current->GetChild(q),ServerName);
199 // Returns the locally connected server we must route a
200 // message through to reach server 'ServerName'. This
201 // only applies to one-to-one and not one-to-many routing.
202 TreeServer* BestRouteTo(std::string ServerName)
204 log(DEBUG,"Finding best route to %s",ServerName.c_str());
205 // first, find the server by recursively walking the tree
206 TreeServer* Found = RouteEnumerate(TreeRoot,ServerName);
207 // did we find it? If not, they did something wrong, abort.
210 log(DEBUG,"Failed to find %s by walking tree!",ServerName.c_str());
215 // The server exists, follow its parent nodes until
216 // the parent of the current is 'TreeRoot', we know
217 // then that this is a directly-connected server.
218 while ((Found) && (Found->GetParent() != TreeRoot))
220 Found = Found->GetParent();
222 log(DEBUG,"Route to %s is via %s",ServerName.c_str(),Found->GetName().c_str());
227 bool LookForServer(TreeServer* Current, std::string ServerName)
229 if (ServerName == Current->GetName())
231 for (unsigned int q = 0; q < Current->ChildCount(); q++)
233 if (LookForServer(Current->GetChild(q),ServerName))
241 void RFindServer(TreeServer* Current, std::string ServerName)
243 if ((ServerName == Current->GetName()) && (!Found))
246 log(DEBUG,"Found server %s desc %s",Current->GetName().c_str(),Current->GetDesc().c_str());
251 for (unsigned int q = 0; q < Current->ChildCount(); q++)
254 RFindServer(Current->GetChild(q),ServerName);
260 TreeServer* FindServer(std::string ServerName)
263 RFindServer(TreeRoot,ServerName);
267 bool IsServer(std::string ServerName)
269 return LookForServer(TreeRoot,ServerName);
272 class TreeSocket : public InspSocket
275 std::string in_buffer;
276 ServerState LinkState;
277 std::string InboundServerName;
278 std::string InboundDescription;
282 TreeSocket(std::string host, int port, bool listening, unsigned long maxtime)
283 : InspSocket(host, port, listening, maxtime)
285 Srv->Log(DEBUG,"Create new listening");
287 this->LinkState = LISTENER;
290 TreeSocket(std::string host, int port, bool listening, unsigned long maxtime, std::string ServerName)
291 : InspSocket(host, port, listening, maxtime)
293 Srv->Log(DEBUG,"Create new outbound");
295 this->LinkState = CONNECTING;
298 TreeSocket(int newfd, char* ip)
299 : InspSocket(newfd, ip)
301 Srv->Log(DEBUG,"Associate new inbound");
302 this->LinkState = WAIT_AUTH_1;
305 virtual bool OnConnected()
307 if (this->LinkState == CONNECTING)
309 Srv->SendOpers("*** Connection to "+myhost+"["+this->GetIP()+"] established.");
310 // we should send our details here.
311 // if the other side is satisfied, they send theirs.
312 // we do not need to change state here.
313 for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
315 if (x->Name == this->myhost)
317 // found who we're supposed to be connecting to, send the neccessary gubbins.
318 this->WriteLine("SERVER "+Srv->GetServerName()+" "+x->SendPass+" 0 :"+Srv->GetServerDescription());
323 log(DEBUG,"Outbound connection ERROR: Could not find the right link block!");
327 virtual void OnError(InspSocketError e)
331 virtual int OnDisconnect()
336 // recursively send the server tree with distances as hops
337 void SendServers(TreeServer* Current, TreeServer* s, int hops)
340 for (unsigned int q = 0; q < Current->ChildCount(); q++)
342 TreeServer* recursive_server = Current->GetChild(q);
343 if (recursive_server != s)
345 // :source.server SERVER server.name hops :Description
346 snprintf(command,1024,":%s SERVER %s * %d :%s",Current->GetName().c_str(),recursive_server->GetName().c_str(),hops,recursive_server->GetDesc().c_str());
347 this->WriteLine(command);
348 // down to next level
349 this->SendServers(recursive_server, s, hops+1);
354 bool ForceJoin(std::string source, std::deque<std::string> params)
356 if (params.size() < 1)
358 for (unsigned int channelnum = 0; channelnum < params.size(); channelnum++)
360 // process one channel at a time, applying modes.
361 char* channel = (char*)params[channelnum].c_str();
362 char permissions = *channel;
379 userrec* who = Srv->FindNick(source);
383 chanrec* chan = Srv->FindChannel(channel);
384 if ((chan) && (*chan->key))
388 Srv->JoinUserToChannel(who,channel,key);
392 modelist[0] = channel;
394 modelist[2] = who->nick;
395 Srv->SendMode(modelist,3,who);
397 DoOneToAllButSender(source,"FJOIN",params,who->server);
403 bool IntroduceClient(std::string source, std::deque<std::string> params)
405 if (params.size() < 8)
407 // NICK age nick host dhost ident +modes ip :gecos
409 std::string nick = params[1];
410 std::string host = params[2];
411 std::string dhost = params[3];
412 std::string ident = params[4];
413 time_t age = atoi(params[0].c_str());
414 std::string modes = params[5];
415 std::string ip = params[6];
416 std::string gecos = params[7];
417 char* tempnick = (char*)nick.c_str();
418 log(DEBUG,"Introduce client %s!%s@%s",tempnick,ident.c_str(),host.c_str());
420 user_hash::iterator iter;
421 iter = clientlist.find(tempnick);
422 if (iter != clientlist.end())
425 log(DEBUG,"Nick collision on %s!%s@%s",tempnick,ident.c_str(),host.c_str());
429 clientlist[tempnick] = new userrec();
430 clientlist[tempnick]->fd = FD_MAGIC_NUMBER;
431 strlcpy(clientlist[tempnick]->nick, tempnick,NICKMAX);
432 strlcpy(clientlist[tempnick]->host, host.c_str(),160);
433 strlcpy(clientlist[tempnick]->dhost, dhost.c_str(),160);
434 clientlist[tempnick]->server = (char*)FindServerNamePtr(source.c_str());
435 strlcpy(clientlist[tempnick]->ident, ident.c_str(),IDENTMAX);
436 strlcpy(clientlist[tempnick]->fullname, gecos.c_str(),MAXGECOS);
437 clientlist[tempnick]->registered = 7;
438 clientlist[tempnick]->signon = age;
439 strlcpy(clientlist[tempnick]->ip,ip.c_str(),16);
440 for (int i = 0; i < MAXCHANS; i++)
442 clientlist[tempnick]->chans[i].channel = NULL;
443 clientlist[tempnick]->chans[i].uc_modes = 0;
445 DoOneToAllButSender(source,"NICK",params,source);
449 // send all users and their channels
450 void SendUsers(TreeServer* Current)
453 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
455 snprintf(data,MAXBUF,":%s NICK %lu %s %s %s %s +%s %s :%s",u->second->server,(unsigned long)u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->modes,u->second->ip,u->second->fullname);
456 this->WriteLine(data);
457 if (strchr(u->second->modes,'o'))
459 this->WriteLine(":"+std::string(u->second->nick)+" OPERTYPE "+std::string(u->second->oper));
461 char* chl = chlist(u->second,u->second);
464 this->WriteLine(":"+std::string(u->second->nick)+" FJOIN "+std::string(chl));
469 void DoBurst(TreeServer* s)
471 log(DEBUG,"Beginning network burst");
472 Srv->SendOpers("*** Bursting to "+s->GetName()+".");
473 this->WriteLine("BURST");
475 this->SendServers(TreeRoot,s,1);
476 // Send users and their channels
478 // TODO: Send everything else (channel modes etc)
479 this->WriteLine("ENDBURST");
482 virtual bool OnDataReady()
484 char* data = this->Read();
487 this->in_buffer += data;
488 while (in_buffer.find("\n") != std::string::npos)
490 char* line = (char*)in_buffer.c_str();
491 std::string ret = "";
492 while ((*line != '\n') && (strlen(line)))
497 if ((*line == '\n') || (*line == '\r'))
500 if (!this->ProcessLine(ret))
506 return (data != NULL);
509 int WriteLine(std::string line)
511 return this->Write(line + "\r\n");
514 bool Error(std::deque<std::string> params)
516 if (params.size() < 1)
518 std::string Errmsg = params[0];
519 std::string SName = myhost;
520 if (InboundServerName != "")
522 SName = InboundServerName;
524 Srv->SendOpers("*** ERROR from "+SName+": "+Errmsg);
525 // we will return false to cause the socket to close.
529 bool RemoteServer(std::string prefix, std::deque<std::string> params)
531 if (params.size() < 4)
533 std::string servername = params[0];
534 std::string password = params[1];
535 int hops = atoi(params[2].c_str());
536 std::string description = params[3];
539 this->WriteLine("ERROR :Protocol error - Introduced remote server with incorrect hopcount!");
542 TreeServer* ParentOfThis = FindServer(prefix);
545 this->WriteLine("ERROR :Protocol error - Introduced remote server from unknown server "+prefix);
548 TreeServer* Node = new TreeServer(servername,description,ParentOfThis,NULL);
549 ParentOfThis->AddChild(Node);
550 DoOneToAllButSender(prefix,"SERVER",params,prefix);
551 Srv->SendOpers("*** Server "+prefix+" introduced server "+servername+" ("+description+")");
555 bool Outbound_Reply_Server(std::deque<std::string> params)
557 if (params.size() < 4)
559 std::string servername = params[0];
560 std::string password = params[1];
561 int hops = atoi(params[2].c_str());
564 this->WriteLine("ERROR :Server too far away for authentication");
567 std::string description = params[3];
568 for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
570 if ((x->Name == servername) && (x->RecvPass == password))
572 // Begin the sync here. this kickstarts the
573 // other side, waiting in WAIT_AUTH_2 state,
574 // into starting their burst, as it shows
576 this->LinkState = CONNECTED;
577 // we should add the details of this server now
578 // to the servers tree, as a child of the root
580 TreeServer* Node = new TreeServer(servername,description,TreeRoot,this);
581 TreeRoot->AddChild(Node);
586 this->WriteLine("ERROR :Invalid credentials");
590 bool Inbound_Server(std::deque<std::string> params)
592 if (params.size() < 4)
594 std::string servername = params[0];
595 std::string password = params[1];
596 int hops = atoi(params[2].c_str());
599 this->WriteLine("ERROR :Server too far away for authentication");
602 std::string description = params[3];
603 for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
605 if ((x->Name == servername) && (x->RecvPass == password))
607 Srv->SendOpers("*** Verified incoming server connection from "+servername+"["+this->GetIP()+"] ("+description+")");
608 this->InboundServerName = servername;
609 this->InboundDescription = description;
610 // this is good. Send our details: Our server name and description and hopcount of 0,
611 // along with the sendpass from this block.
612 this->WriteLine("SERVER "+Srv->GetServerName()+" "+x->SendPass+" 0 :"+Srv->GetServerDescription());
613 // move to the next state, we are now waiting for THEM.
614 this->LinkState = WAIT_AUTH_2;
618 this->WriteLine("ERROR :Invalid credentials");
622 std::deque<std::string> Split(std::string line)
624 std::deque<std::string> n;
625 std::stringstream s(line);
626 std::string param = "";
632 if ((param.c_str()[0] == ':') && (item))
634 char* str = (char*)param.c_str();
644 param = param + " " + append;
654 bool ProcessLine(std::string line)
656 Srv->SendToModeMask("o",WM_AND,"inbound-line: '"+line+"'");
658 std::deque<std::string> params = this->Split(line);
659 std::string command = "";
660 std::string prefix = "";
661 if (((params[0].c_str())[0] == ':') && (params.size() > 1))
665 char* pref = (char*)prefix.c_str();
677 switch (this->LinkState)
682 // Waiting for SERVER command from remote server. Server initiating
683 // the connection sends the first SERVER command, listening server
684 // replies with theirs if its happy, then if the initiator is happy,
685 // it starts to send its net sync, which starts the merge, otherwise
686 // it sends an ERROR.
687 if (command == "SERVER")
689 return this->Inbound_Server(params);
691 else if (command == "ERROR")
693 return this->Error(params);
697 // Waiting for start of other side's netmerge to say they liked our
699 if (command == "SERVER")
701 // cant do this, they sent it to us in the WAIT_AUTH_1 state!
705 else if (command == "BURST")
707 this->LinkState = CONNECTED;
708 Node = new TreeServer(InboundServerName,InboundDescription,TreeRoot,this);
709 TreeRoot->AddChild(Node);
712 else if (command == "ERROR")
714 return this->Error(params);
719 this->WriteLine("ERROR :Internal error -- listening socket accepted its own descriptor!!!");
723 if (command == "SERVER")
725 // another server we connected to, which was in WAIT_AUTH_1 state,
726 // has just sent us their credentials. If we get this far, theyre
727 // happy with OUR credentials, and they are now in WAIT_AUTH_2 state.
728 // if we're happy with this, we should send our netburst which
729 // kickstarts the merge.
730 return this->Outbound_Reply_Server(params);
734 // This is the 'authenticated' state, when all passwords
735 // have been exchanged and anything past this point is taken
737 std::string target = "";
738 if ((command == "NICK") && (params.size() > 1))
740 return this->IntroduceClient(prefix,params);
742 else if (command == "FJOIN")
744 return this->ForceJoin(prefix,params);
746 else if (command == "SERVER")
748 return this->RemoteServer(prefix,params);
752 // not a special inter-server command.
753 // Emulate the actual user doing the command,
754 // this saves us having a huge ugly parser.
755 userrec* who = Srv->FindNick(prefix);
756 std::string sourceserv = this->myhost;
757 if (this->InboundServerName != "")
759 sourceserv = this->InboundServerName;
764 target = who->server;
765 char* strparams[127];
766 for (unsigned int q = 0; q < params.size(); q++)
768 strparams[q] = (char*)params[q].c_str();
770 log(DEBUG,"*** CALL COMMAND HANDLER FOR %s, SOURCE: '%s'",command.c_str(),who->nick);
771 Srv->CallCommandHandler(command, strparams, params.size(), who);
775 // its not a user. Its either a server, or somethings screwed up.
776 if (IsServer(prefix))
778 target = Srv->GetServerName();
782 log(DEBUG,"Command with unknown origin '%s'",prefix.c_str());
786 return DoOneToAllButSender(prefix,command,params,sourceserv);
795 virtual void OnTimeout()
797 if (this->LinkState = CONNECTING)
799 Srv->SendOpers("*** CONNECT: Connection to "+myhost+" timed out.");
803 virtual void OnClose()
807 virtual int OnIncomingConnection(int newsock, char* ip)
809 TreeSocket* s = new TreeSocket(newsock, ip);
815 bool DoOneToAllButSender(std::string prefix, std::string command, std::deque<std::string> params, std::string omit)
817 log(DEBUG,"ALLBUTONE: Comes from %s SHOULD NOT go back to %s",prefix.c_str(),omit.c_str());
818 // TODO: Special stuff with privmsg and notice
819 std::string FullLine = ":" + prefix + " " + command;
820 for (unsigned int x = 0; x < params.size(); x++)
822 FullLine = FullLine + " " + params[x];
824 for (unsigned int x = 0; x < TreeRoot->ChildCount(); x++)
826 TreeServer* Route = TreeRoot->GetChild(x);
828 // The route has a socket (its a direct connection)
829 // The route isnt the one to be omitted
830 // The route isnt the path to the one to be omitted
831 if ((Route->GetSocket()) && (Route->GetName() != omit) && (BestRouteTo(omit) != Route))
833 TreeSocket* Sock = Route->GetSocket();
834 log(DEBUG,"Sending to %s",Route->GetName().c_str());
835 Sock->WriteLine(FullLine);
841 bool DoOneToMany(std::string prefix, std::string command, std::deque<std::string> params)
843 std::string FullLine = ":" + prefix + " " + command;
844 for (unsigned int x = 0; x < params.size(); x++)
846 FullLine = FullLine + " " + params[x];
848 for (unsigned int x = 0; x < TreeRoot->ChildCount(); x++)
850 TreeServer* Route = TreeRoot->GetChild(x);
851 if (Route->GetSocket())
853 TreeSocket* Sock = Route->GetSocket();
854 Sock->WriteLine(FullLine);
860 bool DoOneToOne(std::string prefix, std::string command, std::deque<std::string> params, std::string target)
862 TreeServer* Route = BestRouteTo(target);
865 std::string FullLine = ":" + prefix + " " + command;
866 for (unsigned int x = 0; x < params.size(); x++)
868 FullLine = FullLine + " " + params[x];
870 if (Route->GetSocket())
872 TreeSocket* Sock = Route->GetSocket();
873 Sock->WriteLine(FullLine);
879 log(DEBUG,"Could not route message with target %s: %s",target.c_str(),command.c_str());
885 class ModuleSpanningTree : public Module
887 std::vector<TreeSocket*> Bindings;
892 void ReadConfiguration(bool rebind)
896 for (int j =0; j < Conf->Enumerate("bind"); j++)
898 std::string Type = Conf->ReadValue("bind","type",j);
899 std::string IP = Conf->ReadValue("bind","address",j);
900 long Port = Conf->ReadInteger("bind","port",j,true);
901 if (Type == "servers")
907 TreeSocket* listener = new TreeSocket(IP.c_str(),Port,true,10);
908 if (listener->GetState() == I_LISTENING)
910 Srv->AddSocket(listener);
911 Bindings.push_back(listener);
915 log(DEFAULT,"m_spanningtree: Warning: Failed to bind server port %d",Port);
923 for (int j =0; j < Conf->Enumerate("link"); j++)
926 L.Name = Conf->ReadValue("link","name",j);
927 L.IPAddr = Conf->ReadValue("link","ipaddr",j);
928 L.Port = Conf->ReadInteger("link","port",j,true);
929 L.SendPass = Conf->ReadValue("link","sendpass",j);
930 L.RecvPass = Conf->ReadValue("link","recvpass",j);
931 LinkBlocks.push_back(L);
932 log(DEBUG,"m_spanningtree: Read server %s with host %s:%d",L.Name.c_str(),L.IPAddr.c_str(),L.Port);
939 Conf = new ConfigReader;
942 // Create the root of the tree
943 TreeRoot = new TreeServer(Srv->GetServerName(),Srv->GetServerDescription());
945 ReadConfiguration(true);
948 void ShowLinks(TreeServer* Current, userrec* user, int hops)
950 std::string Parent = TreeRoot->GetName();
951 if (Current->GetParent())
953 Parent = Current->GetParent()->GetName();
955 for (unsigned int q = 0; q < Current->ChildCount(); q++)
957 ShowLinks(Current->GetChild(q),user,hops+1);
959 WriteServ(user->fd,"364 %s %s %s :%d %s",user->nick,Current->GetName().c_str(),Parent.c_str(),hops,Current->GetDesc().c_str());
962 void HandleLinks(char** parameters, int pcnt, userrec* user)
964 ShowLinks(TreeRoot,user,0);
965 WriteServ(user->fd,"365 %s * :End of /LINKS list.",user->nick);
969 void HandleLusers(char** parameters, int pcnt, userrec* user)
974 void ShowMap(TreeServer* Current, userrec* user, int depth, char matrix[32][80])
976 for (int t = 0; t < depth; t++)
978 matrix[line][t] = ' ';
980 strlcpy(&matrix[line][depth],Current->GetName().c_str(),80);
982 //WriteServ(user->fd,"006 %s :%s%s",user->nick,header,Current->GetName().c_str());
983 for (unsigned int q = 0; q < Current->ChildCount(); q++)
985 ShowMap(Current->GetChild(q),user,depth+2,matrix);
989 // Yes, this is smart (and odd). You may all praise me now.
990 // After looking over how others did this, with tons of ugly
991 // maths combined with lots of recursion, i decided to approach
992 // this in a very different way. To cut down on the recursion,
993 // as users may be able to trigger this command, the algorithm
994 // renders the map 'backwards' without recursion after it has
995 // correctly placed the servers into the lines.
996 void HandleMap(char** parameters, int pcnt, userrec* user)
999 for (unsigned int t = 0; t < 32; t++)
1001 matrix[line][0] = '\0';
1004 ShowMap(TreeRoot,user,0,matrix);
1005 for (int l = 1; l < line; l++)
1007 int first_nonspace = 0;
1008 while (matrix[l][first_nonspace] == ' ')
1013 matrix[l][first_nonspace] = '-';
1014 matrix[l][first_nonspace-1] = '`';
1016 while ((matrix[l2][first_nonspace-1] == ' ') || (matrix[l2][first_nonspace-1] == '`'))
1018 matrix[l2][first_nonspace-1] = '|';
1022 for (int t = 0; t < line; t++)
1024 WriteServ(user->fd,"006 %s :%s",user->nick,&matrix[t][0]);
1026 WriteServ(user->fd,"007 %s :End of /MAP",user->nick);
1030 int HandleSquit(char** parameters, int pcnt, userrec* user)
1035 int HandleConnect(char** parameters, int pcnt, userrec* user)
1037 for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
1039 if (Srv->MatchText(x->Name.c_str(),parameters[0]))
1041 WriteServ(user->fd,"NOTICE %s :*** CONNECT: Connecting to server: %s (%s:%d)",user->nick,x->Name.c_str(),x->IPAddr.c_str(),x->Port);
1042 TreeSocket* newsocket = new TreeSocket(x->IPAddr,x->Port,false,10,x->Name);
1043 Srv->AddSocket(newsocket);
1047 WriteServ(user->fd,"NOTICE %s :*** CONNECT: No matching server could be found in the config file.",user->nick);
1051 virtual int OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user)
1053 if (command == "CONNECT")
1055 return this->HandleConnect(parameters,pcnt,user);
1057 else if (command == "SQUIT")
1059 return this->HandleSquit(parameters,pcnt,user);
1061 else if (command == "MAP")
1063 this->HandleMap(parameters,pcnt,user);
1066 else if (command == "LUSERS")
1068 this->HandleLusers(parameters,pcnt,user);
1071 else if (command == "LINKS")
1073 this->HandleLinks(parameters,pcnt,user);
1079 virtual void OnUserMessage(userrec* user, void* dest, int target_type, std::string text)
1081 if (target_type == TYPE_USER)
1083 // route private messages which are targetted at clients only to the server
1084 // which needs to receive them
1085 userrec* d = (userrec*)dest;
1086 if ((std::string(d->server) != Srv->GetServerName()) && (std::string(user->server) == Srv->GetServerName()))
1088 std::deque<std::string> params;
1090 params.push_back(d->nick);
1091 params.push_back(":"+text);
1092 DoOneToOne(user->nick,"PRIVMSG",params,d->server);
1097 virtual void OnUserJoin(userrec* user, chanrec* channel)
1099 // Only do this for local users
1100 if (std::string(user->server) == Srv->GetServerName())
1102 log(DEBUG,"**** User on %s JOINS %s",user->server,channel->name);
1103 std::deque<std::string> params;
1105 params.push_back(channel->name);
1108 log(DEBUG,"**** With key %s",channel->key);
1109 // if the channel has a key, force the join by emulating the key.
1110 params.push_back(channel->key);
1112 DoOneToMany(user->nick,"JOIN",params);
1116 virtual void OnUserPart(userrec* user, chanrec* channel)
1118 if (std::string(user->server) == Srv->GetServerName())
1120 log(DEBUG,"**** User on %s PARTS %s",user->server,channel->name);
1121 std::deque<std::string> params;
1123 params.push_back(channel->name);
1124 DoOneToMany(user->nick,"PART",params);
1128 virtual ~ModuleSpanningTree()
1133 virtual Version GetVersion()
1135 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
1140 class ModuleSpanningTreeFactory : public ModuleFactory
1143 ModuleSpanningTreeFactory()
1147 ~ModuleSpanningTreeFactory()
1151 virtual Module * CreateModule()
1153 return new ModuleSpanningTree;
1159 extern "C" void * init_module( void )
1161 return new ModuleSpanningTreeFactory;