diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-04 20:39:24 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-04 20:39:24 +0000 |
commit | 30d3b0f863f0c791be99c878bfa8b389b66b8797 (patch) | |
tree | 1bfa666b565832ac23f29ac5fa7ad32513fe2b86 | |
parent | c28743098f7af004a7d6271a9e588903c6d02ef1 (diff) |
Added remote version stuffs
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2165 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | src/modules/m_spanningtree.cpp | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp index 6e0bb76da..c3eb7f8b1 100644 --- a/src/modules/m_spanningtree.cpp +++ b/src/modules/m_spanningtree.cpp @@ -88,6 +88,7 @@ class TreeServer ServerDesc = ""; VersionString = ""; UserCount = OperCount = 0; + VersionString = GetVersionString(); } TreeServer(std::string Name, std::string Desc) : ServerName(Name), ServerDesc(Desc) @@ -95,6 +96,7 @@ class TreeServer Parent = NULL; VersionString = ""; UserCount = OperCount = 0; + VersionString = GetVersionString(); } TreeServer(std::string Name, std::string Desc, TreeServer* Above, TreeSocket* Sock) : Parent(Above), ServerName(Name), ServerDesc(Desc), Socket(Sock) @@ -161,6 +163,16 @@ class TreeServer return this->Parent; } + std::string GetVersion() + { + return VersionString; + } + + void SetVersion(std::string Version) + { + VersionString = Version; + } + unsigned int ChildCount() { return Children.size(); @@ -312,6 +324,23 @@ void RFindServer(TreeServer* Current, std::string ServerName) return; } +void RFindServerMask(TreeServer* Current, std::string ServerName) +{ + if (Srv->MatchText(Current->GetName(),ServerName) && (!Found)) + { + Found = Current; + return; + } + if (!Found) + { + for (unsigned int q = 0; q < Current->ChildCount(); q++) + { + if (!Found) + RFindServerMask(Current->GetChild(q),ServerName); + } + } +} + TreeServer* FindServer(std::string ServerName) { Found = NULL; @@ -319,6 +348,13 @@ TreeServer* FindServer(std::string ServerName) return Found; } +TreeServer* FindServerMask(std::string ServerName) +{ + Found = NULL; + RFindServerMask(TreeRoot,ServerName); + return Found; +} + bool IsServer(std::string ServerName) { return LookForServer(TreeRoot,ServerName); @@ -400,6 +436,7 @@ class TreeSocket : public InspSocket // :source.server SERVER server.name hops :Description snprintf(command,1024,":%s SERVER %s * %d :%s",Current->GetName().c_str(),recursive_server->GetName().c_str(),hops,recursive_server->GetDesc().c_str()); this->WriteLine(command); + this->WriteLine(":"+recursive_server->GetName()+" VERSION :"+recursive_server->GetVersion()); // down to next level this->SendServers(recursive_server, s, hops+1); } @@ -758,6 +795,8 @@ class TreeSocket : public InspSocket { Srv->SendOpers("*** Bursting to "+s->GetName()+"."); this->WriteLine("BURST"); + // send our version string + this->WriteLine(":"+s->GetName()+" VERSION :"+GetVersionString()); // Send server tree this->SendServers(TreeRoot,s,1); // Send users and their channels @@ -880,6 +919,18 @@ class TreeSocket : public InspSocket } return true; } + + bool ServerVersion(std::string prefix, std::deque<std::string> params) + { + if (params.size() < 1) + return true; + TreeServer* ServerSource = FindServer(prefix); + if (ServerSource) + { + ServerSource->SetVersion(params[0]); + } + return true; + } bool LocalPing(std::string prefix, std::deque<std::string> params) { @@ -1193,6 +1244,10 @@ class TreeSocket : public InspSocket { return this->LocalPong(prefix,params); } + else if (command == "VERSION") + { + return this->ServerVersion(prefix,params); + } else if (command == "SQUIT") { if (params.size() == 2) @@ -1643,7 +1698,7 @@ class ModuleSpanningTree : public Module int HandleSquit(char** parameters, int pcnt, userrec* user) { - TreeServer* s = FindServer(parameters[0]); + TreeServer* s = FindServerMask(parameters[0]); if (s) { TreeSocket* sock = s->GetSocket(); @@ -1712,6 +1767,21 @@ class ModuleSpanningTree : public Module } } } + + int HandleVersion(char** parameters, int pcnt, userrec* user) + { + // we've already checked if pcnt > 0, so this is safe + TreeServer* found = FindServerMask(parameters[0]); + if (found) + { + std::string Version = found->GetVersion(); + WriteServ(user->fd,"351 %s :%s",user->nick,Version.c_str()); + } + else + { + WriteServ(user->fd,"402 %s :No such server",parameters[0]); + } + } int HandleConnect(char** parameters, int pcnt, userrec* user) { @@ -1763,6 +1833,11 @@ class ModuleSpanningTree : public Module this->HandleLinks(parameters,pcnt,user); return 1; } + else if ((command == "VERSION") && (pcnt > 0)) + { + this->HandleVersion(parameters,pcnt,user); + return 1; + } else if (Srv->IsValidModuleCommand(command, pcnt, user)) { // this bit of code cleverly routes all module commands |