]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/treesocket2.cpp
fixed some indentation and spacing in modules
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treesocket2.cpp
index f668b906185e2fc295448f44e1d14bf09040073d..5a6a9f301e731d67867dfcfc53b90209c8f2e4fd 100644 (file)
 
 /* $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 */
 
-static std::map<std::string, std::string> warned;       /* Server names that have had protocol violation warnings displayed for them */
-
-int TreeSocket::WriteLine(std::string line)
+void TreeSocket::WriteLine(std::string line)
 {
-       Instance->Log(DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
+       Instance->Logs->Log("m_spanningtree",DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
        line.append("\r\n");
-       return this->Write(line);
+       this->Write(line);
 }
 
 
@@ -50,975 +48,6 @@ bool TreeSocket::Error(std::deque<std::string> &params)
        return false;
 }
 
-bool TreeSocket::Modules(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.empty())
-               return true;
-
-       if (!this->Instance->MatchText(this->Instance->Config->ServerName, params[0]))
-       {
-               /* Pass it on, not for us */
-               Utils->DoOneToOne(prefix, "MODULES", params, params[0]);
-               return true;
-       }
-
-       char strbuf[MAXBUF];
-       std::deque<std::string> par;
-       par.push_back(prefix);
-       par.push_back("");
-
-       User* source = this->Instance->FindNick(prefix);
-       if (!source)
-               return true;
-
-       std::vector<std::string> module_names = Instance->Modules->GetAllModuleNames(0);
-
-       for (unsigned int i = 0; i < module_names.size(); i++)
-       {
-               Module* m = Instance->Modules->Find(module_names[i]);
-               Version V = m->GetVersion();
-               char modulename[MAXBUF];
-               char flagstate[MAXBUF];
-               *flagstate = 0;
-               if (V.Flags & VF_STATIC)
-                       strlcat(flagstate,", static",MAXBUF);
-               if (V.Flags & VF_VENDOR)
-                       strlcat(flagstate,", vendor",MAXBUF);
-               if (V.Flags & VF_COMMON)
-                       strlcat(flagstate,", common",MAXBUF);
-               if (V.Flags & VF_SERVICEPROVIDER)
-                       strlcat(flagstate,", service provider",MAXBUF);
-               if (!flagstate[0])
-                       strcpy(flagstate,"  <no flags>");
-               strlcpy(modulename,module_names[i].c_str(),256);
-               if (*source->oper)
-               {
-                       snprintf(strbuf, MAXBUF, "::%s 900 %s :0x%08lx %d.%d.%d.%d %s (%s)",Instance->Config->ServerName,source->nick,(unsigned long)m,
-                                       V.Major,V.Minor,V.Revision,V.Build,ServerConfig::CleanFilename(modulename),flagstate+2);
-               }
-               else
-               {
-                       snprintf(strbuf, MAXBUF, "::%s 900 %s :%s",Instance->Config->ServerName,source->nick,ServerConfig::CleanFilename(modulename));
-               }
-               par[1] = strbuf;
-               Utils->DoOneToOne(Instance->Config->GetSID(), "PUSH", par, source->server);
-       }
-       snprintf(strbuf, MAXBUF, "::%s 901 %s :End of MODULES list", Instance->Config->ServerName, source->nick);
-       par[1] = strbuf;
-       Utils->DoOneToOne(Instance->Config->GetSID(), "PUSH", par, source->server);
-       return true;
-}
-
-/** remote MOTD. leet, huh? */
-bool TreeSocket::Motd(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() > 0)
-       {
-               if (this->Instance->MatchText(this->Instance->Config->ServerName, params[0]))
-               {
-                       /* It's for our server */
-                       string_list results;
-                       User* source = this->Instance->FindNick(prefix);
-
-                       if (source)
-                       {
-                               std::deque<std::string> par;
-                               par.push_back(prefix);
-                               par.push_back("");
-
-                               if (!Instance->Config->MOTD.size())
-                               {
-                                       par[1] = std::string("::")+Instance->Config->ServerName+" 422 "+source->nick+" :Message of the day file is missing.";
-                                       Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
-                                       return true;
-                               }
-
-                               par[1] = std::string("::")+Instance->Config->ServerName+" 375 "+source->nick+" :"+Instance->Config->ServerName+" message of the day";
-                               Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
-
-                               for (unsigned int i = 0; i < Instance->Config->MOTD.size(); i++)
-                               {
-                                       par[1] = std::string("::")+Instance->Config->ServerName+" 372 "+source->nick+" :- "+Instance->Config->MOTD[i];
-                                       Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
-                               }
-
-                               par[1] = std::string("::")+Instance->Config->ServerName+" 376 "+source->nick+" :End of message of the day.";
-                               Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
-                       }
-               }
-               else
-               {
-                       /* Pass it on */
-                       User* source = this->Instance->FindNick(prefix);
-                       if (source)
-                               Utils->DoOneToOne(prefix, "MOTD", params, params[0]);
-               }
-       }
-       return true;
-}
-
-/** remote ADMIN. leet, huh? */
-bool TreeSocket::Admin(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() > 0)
-       {
-               if (this->Instance->MatchText(this->Instance->Config->ServerName, params[0]))
-               {
-                       /* It's for our server */
-                       string_list results;
-                       User* source = this->Instance->FindNick(prefix);
-                       if (source)
-                       {
-                               std::deque<std::string> par;
-                               par.push_back(prefix);
-                               par.push_back("");
-                               par[1] = std::string("::")+Instance->Config->ServerName+" 256 "+source->nick+" :Administrative info for "+Instance->Config->ServerName;
-                               Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
-                               par[1] = std::string("::")+Instance->Config->ServerName+" 257 "+source->nick+" :Name     - "+Instance->Config->AdminName;
-                               Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
-                               par[1] = std::string("::")+Instance->Config->ServerName+" 258 "+source->nick+" :Nickname - "+Instance->Config->AdminNick;
-                               Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
-                               par[1] = std::string("::")+Instance->Config->ServerName+" 258 "+source->nick+" :E-Mail   - "+Instance->Config->AdminEmail;
-                               Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
-                       }
-               }
-               else
-               {
-                       /* Pass it on */
-                       User* source = this->Instance->FindNick(prefix);
-                       if (source)
-                               Utils->DoOneToOne(prefix, "ADMIN", params, params[0]);
-               }
-       }
-       return true;
-}
-
-bool TreeSocket::Stats(const std::string &prefix, std::deque<std::string> &params)
-{
-       /* Get the reply to a STATS query if it matches this servername,
-        * and send it back as a load of PUSH queries
-        */
-       if (params.size() > 1)
-       {
-               if (this->Instance->MatchText(this->Instance->Config->ServerName, params[1]))
-               {
-                       /* It's for our server */
-                       string_list results;
-                       User* source = this->Instance->FindNick(prefix);
-                       if (source)
-                       {
-                               std::deque<std::string> par;
-                               par.push_back(prefix);
-                               par.push_back("");
-                               DoStats(this->Instance, *(params[0].c_str()), source, results);
-                               for (size_t i = 0; i < results.size(); i++)
-                               {
-                                       par[1] = "::" + results[i];
-                                       Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
-                               }
-                       }
-               }
-               else
-               {
-                       /* Pass it on */
-                       User* source = this->Instance->FindNick(prefix);
-                       if (source)
-                               Utils->DoOneToOne(source->uuid, "STATS", params, params[1]);
-               }
-       }
-       return true;
-}
-
-
-/** Because the core won't let users or even SERVERS set +o,
- * we use the OPERTYPE command to do this.
- */
-bool TreeSocket::OperType(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() != 1)
-               return true;
-       std::string opertype = params[0];
-       User* u = this->Instance->FindNick(prefix);
-       if (u)
-       {
-               if (!u->IsModeSet('o'))
-                       this->Instance->Users->all_opers.push_back(u);
-               u->modes[UM_OPERATOR] = 1;
-               strlcpy(u->oper,opertype.c_str(),NICKMAX-1);
-               Utils->DoOneToAllButSender(u->nick,"OPERTYPE",params,u->server);
-
-               TreeServer* remoteserver = Utils->FindServer(u->server);
-               bool dosend = true;
-
-               if (this->Utils->quiet_bursts)
-               {
-                       /*
-                        * If quiet bursts are enabled, and server is bursting or silent uline (i.e. services),
-                        * then do nothing. -- w00t
-                        */
-                       if (
-                               remoteserver->bursting ||
-                               this->Instance->SilentULine(this->Instance->FindServerNamePtr(u->server))
-                          )
-                       {
-                               dosend = false;
-                       }
-               }
-
-               if (dosend)
-                       this->Instance->SNO->WriteToSnoMask('o',"From %s: User %s (%s@%s) is now an IRC operator of type %s",u->server, u->nick,u->ident,u->host,irc::Spacify(opertype.c_str()));
-       }
-       return true;
-}
-
-/** Because Andy insists that services-compatible servers must
- * implement SVSNICK and SVSJOIN, that's exactly what we do :p
- */
-bool TreeSocket::ForceNick(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 3)
-               return true;
-
-       User* u = this->Instance->FindNick(params[0]);
-
-       if (u)
-       {
-               Utils->DoOneToAllButSender(prefix,"SVSNICK",params,prefix);
-
-               if (IS_LOCAL(u))
-               {
-                       std::deque<std::string> par;
-                       par.push_back(params[1]);
-
-                       if (!u->ForceNickChange(params[1].c_str()))
-                       {
-                               /* buh. UID them */
-                               if (!u->ForceNickChange(u->uuid))
-                               {
-                                       User::QuitUser(this->Instance, u, "Nickname collision");
-                                       return true;
-                               }
-                       }
-
-                       u->age = atoi(params[2].c_str());
-               }
-       }
-
-       return true;
-}
-
-bool TreeSocket::OperQuit(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 1)
-               return true;
-
-       User* u = this->Instance->FindNick(prefix);
-
-       if (u)
-       {
-               u->SetOperQuit(params[0]);
-               params[0] = ":" + params[0];
-               Utils->DoOneToAllButSender(prefix,"OPERQUIT",params,prefix);
-       }
-       return true;
-}
-
-bool TreeSocket::ServiceJoin(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 2)
-               return true;
-
-       if (!this->Instance->IsChannel(params[1].c_str()))
-               return true;
-
-       User* u = this->Instance->FindNick(params[0]);
-
-       if (u)
-       {
-               /* only join if it's local, otherwise just pass it on! */
-               if (IS_LOCAL(u))
-                       Channel::JoinUser(this->Instance, u, params[1].c_str(), false, "", false, Instance->Time());
-               Utils->DoOneToAllButSender(prefix,"SVSJOIN",params,prefix);
-       }
-       return true;
-}
-
-bool TreeSocket::ServicePart(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 2)
-               return true;
-
-       if (!this->Instance->IsChannel(params[1].c_str()))
-               return true;
-
-       User* u = this->Instance->FindNick(params[0]);
-       Channel* c = this->Instance->FindChan(params[1]);
-
-       if (u)
-       {
-               /* only part if it's local, otherwise just pass it on! */
-               if (IS_LOCAL(u))
-                       if (!c->PartUser(u, "Services forced part"))
-                               delete c;
-               Utils->DoOneToAllButSender(prefix,"SVSPART",params,prefix);
-       }
-
-       return true;
-}
-
-bool TreeSocket::RemoteRehash(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 1)
-               return false;
-
-       std::string servermask = params[0];
-
-       if (this->Instance->MatchText(this->Instance->Config->ServerName,servermask))
-       {
-               this->Instance->SNO->WriteToSnoMask('l',"Remote rehash initiated by \002"+prefix+"\002.");
-               this->Instance->RehashServer();
-               Utils->ReadConfiguration(true);
-               InitializeDisabledCommands(Instance->Config->DisabledCommands, Instance);
-       }
-       Utils->DoOneToAllButSender(prefix,"REHASH",params,prefix);
-       return true;
-}
-
-bool TreeSocket::RemoteKill(const std::string &prefix, std::deque<std::string> &params)
-{       
-       if (params.size() != 2)
-               return true;
-
-       User* who = this->Instance->FindNick(params[0]);
-
-       if (who)
-       {
-               /* Prepend kill source, if we don't have one */          
-               if (*(params[1].c_str()) != '[')
-               {
-                       params[1] = "[" + prefix + "] Killed (" + params[1] +")";
-               }
-               std::string reason = params[1];
-               params[1] = ":" + params[1];
-               Utils->DoOneToAllButSender(prefix,"KILL",params,prefix);
-               // NOTE: This is safe with kill hiding on, as RemoteKill is only reached if we have a server prefix.
-               // in short this is not executed for USERS.
-               who->Write(":%s KILL %s :%s (%s)", prefix.c_str(), who->nick, prefix.c_str(), reason.c_str());
-               User::QuitUser(this->Instance,who,reason);
-       }
-       return true;
-}
-
-bool TreeSocket::LocalPong(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 1)
-               return true;
-
-       if (params.size() == 1)
-       {
-               TreeServer* ServerSource = Utils->FindServer(prefix);
-               if (ServerSource)
-               {
-                       ServerSource->SetPingFlag();
-                       timeval t;
-                       gettimeofday(&t, NULL);
-                       long ts = (t.tv_sec * 1000) + (t.tv_usec / 1000);
-                       ServerSource->rtt = ts - ServerSource->LastPingMsec;
-               }
-       }
-       else
-       {
-               std::string forwardto = params[1];
-               if (forwardto == Instance->Config->GetSID() || forwardto == Instance->Config->ServerName)
-               {
-                       /*
-                        * this is a PONG for us
-                        * if the prefix is a user, check theyre local, and if they are,
-                        * dump the PONG reply back to their fd. If its a server, do nowt.
-                        * Services might want to send these s->s, but we dont need to yet.
-                        */
-                       User* u = this->Instance->FindNick(prefix);
-                       if (u)
-                       {
-                               u->WriteServ("PONG %s %s",params[0].c_str(),params[1].c_str());
-                       }
-               }
-               else
-               {
-                       // not for us, pass it on :)
-                       Utils->DoOneToOne(prefix,"PONG",params,forwardto);
-               }
-       }
-
-       return true;
-}
-
-bool TreeSocket::MetaData(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 2)
-               return true;
-       else if (params.size() < 3)
-               params.push_back("");
-       TreeServer* ServerSource = Utils->FindServer(prefix);
-       if (ServerSource)
-       {
-               if (params[0] == "*")
-               {
-                       FOREACH_MOD_I(this->Instance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_OTHER,NULL,params[1],params[2]));
-               }
-               else if (*(params[0].c_str()) == '#')
-               {
-                       Channel* c = this->Instance->FindChan(params[0]);
-                       if (c)
-                       {
-                               FOREACH_MOD_I(this->Instance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_CHANNEL,c,params[1],params[2]));
-                       }
-               }
-               else if (*(params[0].c_str()) != '#')
-               {
-                       User* u = this->Instance->FindNick(params[0]);
-                       if (u)
-                       {
-                               FOREACH_MOD_I(this->Instance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_USER,u,params[1],params[2]));
-                       }
-               }
-       }
-
-       params[2] = ":" + params[2];
-       Utils->DoOneToAllButSender(prefix,"METADATA",params,prefix);
-       return true;
-}
-
-bool TreeSocket::ServerVersion(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 1)
-               return true;
-
-       TreeServer* ServerSource = Utils->FindServer(prefix);
-
-       if (ServerSource)
-       {
-               ServerSource->SetVersion(params[0]);
-       }
-       params[0] = ":" + params[0];
-       Utils->DoOneToAllButSender(prefix,"VERSION",params,prefix);
-       return true;
-}
-
-bool TreeSocket::ChangeHost(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 1)
-               return true;
-       User* u = this->Instance->FindNick(prefix);
-
-       if (u)
-       {
-               u->ChangeDisplayedHost(params[0].c_str());
-               Utils->DoOneToAllButSender(prefix,"FHOST",params,u->server);
-       }
-       return true;
-}
-
-bool TreeSocket::AddLine(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 6)
-       {
-               this->Instance->SNO->WriteToSnoMask('x',"%s sent me a malformed ADDLINE of type %s.",prefix.c_str(),params[0].c_str());
-               return true;
-       }
-
-       XLineFactory* xlf = Instance->XLines->GetFactory(params[0]);
-
-       if (!xlf)
-       {
-               this->Instance->SNO->WriteToSnoMask('x',"%s sent me an unknown ADDLINE type (%s).",prefix.c_str(),params[0].c_str());
-               return true;
-       }
-
-       XLine* xl = xlf->Generate(Instance->Time(), atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
-       xl->SetCreateTime(atoi(params[3].c_str()));
-       if (Instance->XLines->AddLine(xl,NULL))
-       {
-               if (xl->duration)
-               {
-                       this->Instance->SNO->WriteToSnoMask('x',"%s added %s%s on %s to expire on %s (%s).",prefix.c_str(),params[0].c_str(),params[0].length() == 1 ? "LINE" : "",
-                                       params[1].c_str(),Instance->TimeString(xl->expiry).c_str(),params[5].c_str());
-               }
-               else
-               {
-                       this->Instance->SNO->WriteToSnoMask('x',"%s added permanent %s%s on %s (%s).",prefix.c_str(),params[0].c_str(),params[0].length() == 1 ? "LINE" : "",
-                                       params[1].c_str(),params[5].c_str());
-               }
-               params[5] = ":" + params[5];
-
-               User* u = Instance->FindNick(prefix);
-               Utils->DoOneToAllButSender(prefix, "ADDLINE", params, u ? u->server : prefix);
-               TreeServer *remoteserver = Utils->FindServer(u ? u->server : prefix);
-               
-               if (!remoteserver->bursting)
-               {
-                       Instance->XLines->ApplyLines();
-               }
-       }
-       else
-               delete xl;
-
-       return true;
-}
-
-bool TreeSocket::DelLine(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 2)
-               return true;
-
-       User* user = Instance->FindNick(prefix);
-
-       /* NOTE: No check needed on 'user', this function safely handles NULL */
-       if (Instance->XLines->DelLine(params[0].c_str(), params[1], user))
-       {
-               this->Instance->SNO->WriteToSnoMask('x',"%s removed %s%s on %s.", prefix.c_str(),
-                               params[0].c_str(), params[0].length() == 1 ? "LINE" : "", params[1].c_str());
-               Utils->DoOneToAllButSender(prefix,"DELLINE", params, prefix);
-       }
-       return true;
-}
-
-bool TreeSocket::ChangeName(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 1)
-               return true;
-       User* u = this->Instance->FindNick(prefix);
-       if (u)
-       {
-               u->ChangeName(params[0].c_str());
-               params[0] = ":" + params[0];
-               Utils->DoOneToAllButSender(prefix,"FNAME",params,u->server);
-       }
-       return true;
-}
-
-bool TreeSocket::Whois(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 1)
-               return true;
-       User* u = this->Instance->FindNick(prefix);
-       if (u)
-       {
-               // an incoming request
-               if (params.size() == 1)
-               {
-                       User* x = this->Instance->FindNick(params[0]);
-                       if ((x) && (IS_LOCAL(x)))
-                       {
-                               User* x = this->Instance->FindNick(params[0]);
-                               char signon[MAXBUF];
-                               char idle[MAXBUF];
-                               snprintf(signon, MAXBUF, "%lu", (unsigned long)x->signon);
-                               snprintf(idle, MAXBUF, "%lu", (unsigned long)abs((x->idle_lastmsg) - Instance->Time(true)));
-                               std::deque<std::string> par;
-                               par.push_back(prefix);
-                               par.push_back(signon);
-                               par.push_back(idle);
-                               // ours, we're done, pass it BACK
-                               Utils->DoOneToOne(params[0], "IDLE", par, u->server);
-                       }
-                       else
-                       {
-                               // not ours pass it on
-                               if (x)
-                                       Utils->DoOneToOne(prefix, "IDLE", params, x->server);
-                       }
-               }
-               else if (params.size() == 3)
-               {
-                       std::string who_did_the_whois = params[0];
-                       User* who_to_send_to = this->Instance->FindNick(who_did_the_whois);
-                       if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
-                       {
-                               // an incoming reply to a whois we sent out
-                               std::string nick_whoised = prefix;
-                               unsigned long signon = atoi(params[1].c_str());
-                               unsigned long idle = atoi(params[2].c_str());
-                               if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
-                               {
-                                       do_whois(this->Instance, who_to_send_to, u, signon, idle, nick_whoised.c_str());
-                               }
-                       }
-                       else
-                       {
-                               // not ours, pass it on
-                               if (who_to_send_to)
-                                       Utils->DoOneToOne(prefix, "IDLE", params, who_to_send_to->server);
-                       }
-               }
-       }
-       return true;
-}
-
-bool TreeSocket::Push(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 2)
-               return true;
-       User* u = this->Instance->FindNick(params[0]);
-       if (!u)
-               return true;
-       if (IS_LOCAL(u))
-       {
-               u->Write(params[1]);
-       }
-       else
-       {
-               // continue the raw onwards
-               params[1] = ":" + params[1];
-               Utils->DoOneToOne(prefix,"PUSH",params,u->server);
-       }
-       return true;
-}
-
-bool TreeSocket::HandleSetTime(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (!params.size() || !Utils->EnableTimeSync)
-               return true;
-
-       bool force = false;
-
-       if ((params.size() == 2) && (params[1] == "FORCE"))
-               force = true;
-
-       time_t them = atoi(params[0].c_str());
-       time_t us = Instance->Time(false);
-
-       time_t diff = them - us;
-
-       Utils->DoOneToAllButSender(prefix, "TIMESET", params, prefix);
-
-       if (force || (them != us))
-       {
-               time_t old = Instance->SetTimeDelta(diff);
-               Instance->Log(DEBUG, "TS (diff %d) from %s applied (old delta was %d)", diff, prefix.c_str(), old);
-       }
-
-       return true;
-}
-
-bool TreeSocket::Time(const std::string &prefix, std::deque<std::string> &params)
-{
-       // :source.server TIME remote.server sendernick
-       // :remote.server TIME source.server sendernick TS
-       if (params.size() == 2)
-       {
-               // someone querying our time?
-               if (this->Instance->Config->ServerName == params[0] || this->Instance->Config->GetSID() == params[0])
-               {
-                       User* u = this->Instance->FindNick(params[1]);
-                       if (u)
-                       {
-                               params.push_back(ConvToStr(Instance->Time(false)));
-                               params[0] = prefix;
-                               Utils->DoOneToOne(this->Instance->Config->GetSID(),"TIME",params,params[0]);
-                       }
-               }
-               else
-               {
-                       // not us, pass it on
-                       User* u = this->Instance->FindNick(params[1]);
-                       if (u)
-                               Utils->DoOneToOne(prefix,"TIME",params,params[0]);
-               }
-       }
-       else if (params.size() == 3)
-       {
-               // a response to a previous TIME
-               User* u = this->Instance->FindNick(params[1]);
-               if ((u) && (IS_LOCAL(u)))
-               {
-                       time_t rawtime = atol(params[2].c_str());
-                       struct tm * timeinfo;
-                       timeinfo = localtime(&rawtime);
-                       char tms[26];
-                       snprintf(tms,26,"%s",asctime(timeinfo));
-                       tms[24] = 0;
-                       u->WriteServ("391 %s %s :%s",u->nick,prefix.c_str(),tms);
-               }
-               else
-               {
-                       if (u)
-                               Utils->DoOneToOne(prefix,"TIME",params,u->server);
-               }
-       }
-       return true;
-}
-
-bool TreeSocket::LocalPing(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 1)
-               return true;
-       if (params.size() == 1)
-       {
-               std::string stufftobounce = params[0];
-               this->WriteLine(std::string(":")+this->Instance->Config->GetSID()+" PONG "+stufftobounce);
-               return true;
-       }
-       else
-       {
-               std::string forwardto = params[1];
-               if (forwardto == this->Instance->Config->ServerName || forwardto == this->Instance->Config->GetSID())
-               {
-                       // this is a ping for us, send back PONG to the requesting server
-                       params[1] = params[0];
-                       params[0] = forwardto;
-                       Utils->DoOneToOne(forwardto,"PONG",params,params[1]);
-               }
-               else
-               {
-                       // not for us, pass it on :)
-                       Utils->DoOneToOne(prefix,"PING",params,forwardto);
-               }
-               return true;
-       }
-}
-
-/** TODO: This creates a total mess of output and needs to really use irc::modestacker.
- */
-bool TreeSocket::RemoveStatus(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 1)
-               return true;
-       Channel* c = Instance->FindChan(params[0]);
-       if (c)
-       {
-               for (char modeletter = 'A'; modeletter <= 'z'; modeletter++)
-               {
-                       ModeHandler* mh = Instance->Modes->FindMode(modeletter, MODETYPE_CHANNEL);
-                       if (mh)
-                               mh->RemoveMode(c);
-               }
-       }
-       return true;
-}
-
-bool TreeSocket::RemoteServer(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 5)
-       {
-               SendError("Protocol error - Missing SID");
-               return false;
-       }
-
-       std::string servername = params[0];
-       std::string password = params[1];
-       // hopcount is not used for a remote server, we calculate this ourselves
-       std::string sid = params[3];
-       std::string description = params[4];
-       TreeServer* ParentOfThis = Utils->FindServer(prefix);
-       if (!ParentOfThis)
-       {
-               this->SendError("Protocol error - Introduced remote server from unknown server "+prefix);
-               return false;
-       }
-       if (!this->Instance->IsSID(sid))
-       {
-               this->SendError("Invalid format server ID: "+sid+"!");
-               return false;
-       }
-       TreeServer* CheckDupe = Utils->FindServer(servername);
-       if (CheckDupe)
-       {
-               this->SendError("Server "+servername+" already exists!");
-               this->Instance->SNO->WriteToSnoMask('l',"Server \2"+servername+"\2 being introduced from \2" + prefix + "\2 denied, already exists. Closing link with " + prefix);
-               return false;
-       }
-
-       Link* lnk = Utils->FindLink(servername);
-
-       TreeServer *Node = new TreeServer(this->Utils, this->Instance, servername, description, sid, ParentOfThis,NULL, lnk ? lnk->Hidden : false);
-
-       if (Node->DuplicateID())
-       {
-               this->SendError("Server ID "+sid+" already exists on the network!");
-               this->Instance->SNO->WriteToSnoMask('l',"Server \2"+servername+"\2 being introduced from \2" + prefix + "\2 denied, server ID already exists on the network. Closing link with " + prefix);
-               return false;
-       }
-
-       ParentOfThis->AddChild(Node);
-       params[4] = ":" + params[4];
-       Utils->DoOneToAllButSender(prefix,"SERVER",params,prefix);
-       this->Instance->SNO->WriteToSnoMask('l',"Server \002"+prefix+"\002 introduced server \002"+servername+"\002 ("+description+")");
-       return true;
-}
-
-bool TreeSocket::ComparePass(const std::string &ours, const std::string &theirs)
-{
-       if ((!strncmp(ours.c_str(), "HMAC-SHA256:", 12)) || (!strncmp(theirs.c_str(), "HMAC-SHA256:", 12)))
-       {
-               /* One or both of us specified hmac sha256, but we don't have sha256 module loaded!
-                * We can't allow this password as valid.
-                */
-               if (!Instance->Modules->Find("m_sha256.so") || !Utils->ChallengeResponse)
-                               return false;
-               else
-                       /* Straight string compare of hashes */
-                       return ours == theirs;
-       }
-       else
-               /* Straight string compare of plaintext */
-               return ours == theirs;
-}
-
-bool TreeSocket::Outbound_Reply_Server(std::deque<std::string> &params)
-{
-       if (params.size() < 5)
-       {
-               SendError("Protocol error - Missing SID");
-               return false;
-       }
-
-       irc::string servername = params[0].c_str();
-       std::string sname = params[0];
-       std::string password = params[1];
-       std::string sid = params[3];
-       std::string description = params[4];
-       int hops = atoi(params[2].c_str());
-
-       this->InboundServerName = sname;
-       this->InboundDescription = description;
-       this->InboundSID = sid;
-
-       if (!sentcapab)
-               this->SendCapabilities();
-
-       if (hops)
-       {
-               this->SendError("Server too far away for authentication");
-               this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication");
-               return false;
-       }
-
-       if (!this->Instance->IsSID(sid))
-       {
-               this->SendError("Invalid format server ID: "+sid+"!");
-               return false;
-       }
-
-       for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
-       {
-               if ((x->Name == servername) && ((ComparePass(this->MakePass(x->RecvPass,this->GetOurChallenge()),password)) || (x->RecvPass == password && (this->GetTheirChallenge().empty()))))
-               {
-                       TreeServer* CheckDupe = Utils->FindServer(sname);
-                       if (CheckDupe)
-                       {
-                               this->SendError("Server "+sname+" already exists on server "+CheckDupe->GetParent()->GetName()+"!");
-                               this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+CheckDupe->GetParent()->GetName());
-                               return false;
-                       }
-                       // Begin the sync here. this kickstarts the
-                       // other side, waiting in WAIT_AUTH_2 state,
-                       // into starting their burst, as it shows
-                       // that we're happy.
-                       this->LinkState = CONNECTED;
-                       // we should add the details of this server now
-                       // to the servers tree, as a child of the root
-                       // node.
-
-                       TreeServer *Node = new TreeServer(this->Utils, this->Instance, sname, description, sid, Utils->TreeRoot, this, x->Hidden);
-
-                       if (Node->DuplicateID())
-                       {
-                               this->SendError("Server ID "+sid+" already exists on the network!");
-                               this->Instance->SNO->WriteToSnoMask('l',"Server \2"+assign(servername)+"\2 being introduced denied, server ID already exists on the network. Closing link.");
-                               return false;
-                       }
-
-                       Utils->TreeRoot->AddChild(Node);
-                       params[4] = ":" + params[4];
-                       Utils->DoOneToAllButSender(Instance->Config->GetSID(),"SERVER",params,sname);
-                       Node->bursting = true;
-                       this->DoBurst(Node);
-                       return true;
-               }
-       }
-       this->SendError("Invalid credentials");
-       this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, invalid link credentials");
-       return false;
-}
-
-bool TreeSocket::Inbound_Server(std::deque<std::string> &params)
-{
-       if (params.size() < 5)
-       {
-               SendError("Protocol error - Missing SID");
-               return false;
-       }
-
-       irc::string servername = params[0].c_str();
-       std::string sname = params[0];
-       std::string password = params[1];
-       std::string sid = params[3];
-       std::string description = params[4];
-       int hops = atoi(params[2].c_str());
-
-       this->InboundServerName = sname;
-       this->InboundDescription = description;
-       this->InboundSID = sid;
-
-       if (!sentcapab)
-               this->SendCapabilities();
-
-       if (hops)
-       {
-               this->SendError("Server too far away for authentication");
-               this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication");
-               return false;
-       }
-
-       if (!this->Instance->IsSID(sid))
-       {
-               this->SendError("Invalid format server ID: "+sid+"!");
-               return false;
-       }
-
-       for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
-       {
-               if ((x->Name == servername) && ((ComparePass(this->MakePass(x->RecvPass,this->GetOurChallenge()),password) || x->RecvPass == password && (this->GetTheirChallenge().empty()))))
-               {
-                       /* Check for fully initialized instances of the server by id */
-                       Instance->Log(DEBUG,"Looking for dupe SID %s", sid.c_str());
-                       TreeServer* CheckDupeSID = Utils->FindServerID(sid);
-                       if (CheckDupeSID)
-                       {
-                               this->SendError("Server ID "+CheckDupeSID->GetID()+" already exists on server "+CheckDupeSID->GetName()+"!");
-                               this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server ID '"+CheckDupeSID->GetID()+
-                                               "' already exists on server "+CheckDupeSID->GetName());
-                               return false;
-                       }
-                       /* Now check for fully initialized instances of the server by name */
-                       TreeServer* CheckDupe = Utils->FindServer(sname);
-                       if (CheckDupe)
-                       {
-                               this->SendError("Server "+sname+" already exists on server "+CheckDupe->GetParent()->GetName()+"!");
-                               this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+CheckDupe->GetParent()->GetName());
-                               return false;
-                       }
-                       this->Instance->SNO->WriteToSnoMask('l',"Verified incoming server connection from \002"+sname+"\002["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] ("+description+")");
-                       if (this->Hook)
-                       {
-                               std::string name = BufferedSocketNameRequest((Module*)Utils->Creator, this->Hook).Send();
-                               this->Instance->SNO->WriteToSnoMask('l',"Connection from \2"+sname+"\2["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] using transport \2"+name+"\2");
-                       }
-
-                       // this is good. Send our details: Our server name and description and hopcount of 0,
-                       // along with the sendpass from this block.
-                       this->WriteLine(std::string("SERVER ")+this->Instance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 "+Instance->Config->GetSID()+" :"+this->Instance->Config->ServerDesc);
-                       // move to the next state, we are now waiting for THEM.
-                       this->LinkState = WAIT_AUTH_2;
-                       return true;
-               }
-       }
-       this->SendError("Invalid credentials");
-       this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, invalid link credentials");
-       return false;
-}
-
 void TreeSocket::Split(const std::string &line, std::deque<std::string> &n)
 {
        n.clear();
@@ -1042,25 +71,25 @@ bool TreeSocket::ProcessLine(std::string &line)
        if (line.empty())
                return true;
 
-       Instance->Log(DEBUG, "S[%d] I %s", this->GetFd(), line.c_str());
+       Instance->Logs->Log("m_spanningtree",DEBUG, "S[%d] I %s", this->GetFd(), line.c_str());
 
        this->Split(line.c_str(),params);
-       
+
        if (params.empty())
                return true;
-       
+
        if ((params[0][0] == ':') && (params.size() > 1))
        {
                prefix = params[0].substr(1);
                params.pop_front();
-               
+
                if (prefix.empty())
                {
                        this->SendError("BUG (?) Empty prefix recieved.");
                        return false;
                }
        }
-       
+
        command = params[0].c_str();
        params.pop_front();
 
@@ -1129,11 +158,10 @@ bool TreeSocket::ProcessLine(std::string &line)
                        }
                        else if (command == "BURST")
                        {
-                               if (params.size() && Utils->EnableTimeSync)
+                               if (params.size())
                                {
-                                       bool we_have_delta = (Instance->Time(false) != Instance->Time(true));
                                        time_t them = atoi(params[0].c_str());
-                                       time_t delta = them - Instance->Time(false);
+                                       time_t delta = them - Instance->Time();
                                        if ((delta < -600) || (delta > 600))
                                        {
                                                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));
@@ -1144,13 +172,6 @@ bool TreeSocket::ProcessLine(std::string &line)
                                        {
                                                Instance->SNO->WriteToSnoMask('l',"\2WARNING\2: Your clocks are out by %d seconds. Please consider synching your clocks.", abs(delta));
                                        }
-
-                                       if (!Utils->MasterTime && !we_have_delta)
-                                       {
-                                               this->Instance->SetTimeDelta(delta);
-                                               // Send this new timestamp to any other servers
-                                               Utils->DoOneToMany(Instance->Config->GetSID(), "TIMESET", params);
-                                       }
                                }
                                this->LinkState = CONNECTED;
                                Link* lnk = Utils->FindLink(InboundServerName);
@@ -1245,14 +266,14 @@ bool TreeSocket::ProcessLine(std::string &line)
                                if ((!route_back_again) || (route_back_again->GetSocket() != this))
                                {
                                        if (route_back_again)
-                                               Instance->Log(DEBUG,"Protocol violation: Fake direction in command '%s' from connection '%s'",line.c_str(),this->GetName().c_str());
+                                               Instance->Logs->Log("m_spanningtree",DEBUG,"Protocol violation: Fake direction in command '%s' from connection '%s'",line.c_str(),this->GetName().c_str());
                                        return true;
                                }
                                /* Fix by brain:
                                 * When there is activity on the socket, reset the ping counter so
                                 * that we're not wasting bandwidth pinging an active server.
                                 */
-                               route_back_again->SetNextPingTime(time(NULL) + Utils->PingFreq);
+                               route_back_again->SetNextPingTime(Instance->Time() + Utils->PingFreq);
                                route_back_again->SetPingFlag();
                        }
                        else
@@ -1273,6 +294,9 @@ bool TreeSocket::ProcessLine(std::string &line)
                         * First up, check for any malformed commands (e.g. MODE without a timestamp)
                         * and rewrite commands where necessary (SVSMODE -> MODE for services). -- w
                         */
+                       if (command == "SVSMODE") // This isn't in an "else if" so we still force FMODE for changes on channels.
+                               command = "MODE";
+
                        if (command == "MODE")
                        {
                                if (params.size() >= 2)
@@ -1280,29 +304,17 @@ bool TreeSocket::ProcessLine(std::string &line)
                                        Channel* channel = Instance->FindChan(params[0]);
                                        if (channel)
                                        {
-                                               User* x = Instance->FindNick(prefix);
-                                               if (x)
-                                               {
-                                                       if (warned.find(x->server) == warned.end())
-                                                       {
-                                                               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);
-                                                               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());
-                                                               warned[x->server] = x->nick;
-                                                       }
-                                               }
+                                               this->SendError("MODE may no longer be used on channels. Please use FMODE, with correct timestamp rules.");
+                                               return false;
                                        }
                                }
                        }
-                       else if (command == "SVSMODE")
-                       {
-                               command = "MODE";
-                       }
 
 
                        /*
                         * Now, check for (and parse) commands as appropriate. -- w
-                        */     
-               
+                        */
+
                        /* Find the server that this command originated from, used in the handlers below */
                        TreeServer *ServerSource = Utils->FindServer(prefix);
 
@@ -1324,6 +336,10 @@ bool TreeSocket::ProcessLine(std::string &line)
                        {
                                return this->ForceJoin(prefix,params);
                        }
+                       else if ((command == "NOTICE" || command == "PRIVMSG") && (Utils->IsServer(prefix)))
+                       {
+                               return this->ServerMessage(assign(command), prefix, params, sourceserv);
+                       }
                        else if (command == "STATS")
                        {
                                return this->Stats(prefix, params);
@@ -1345,6 +361,15 @@ bool TreeSocket::ProcessLine(std::string &line)
                        {
                                return this->Admin(prefix, params);
                        }
+                       else if (command == "MAP")
+                       {
+                               User* user = Instance->FindNick(prefix);
+                               if (user)
+                               {
+                                       std::vector<std::string> p(params.begin(), params.end());
+                                       return Utils->Creator->HandleMap(p, user);
+                               }
+                       }
                        else if (command == "SERVER")
                        {
                                return this->RemoteServer(prefix,params);
@@ -1365,18 +390,10 @@ bool TreeSocket::ProcessLine(std::string &line)
                        {
                                return this->ForceTopic(prefix,params);
                        }
-                       else if (command == "REHASH")
-                       {
-                               return this->RemoteRehash(prefix,params);
-                       }
                        else if (command == "METADATA")
                        {
                                return this->MetaData(prefix,params);
                        }
-                       else if (command == "REMSTATUS")
-                       {
-                               return this->RemoveStatus(prefix,params);
-                       }
                        else if (command == "PING")
                        {
                                return this->LocalPing(prefix,params);
@@ -1421,10 +438,6 @@ bool TreeSocket::ProcessLine(std::string &line)
                        {
                                return this->Push(prefix,params);
                        }
-                       else if (command == "TIMESET")
-                       {
-                               return this->HandleSetTime(prefix, params);
-                       }
                        else if (command == "TIME")
                        {
                                return this->Time(prefix,params);
@@ -1433,11 +446,12 @@ bool TreeSocket::ProcessLine(std::string &line)
                        {
                                if (params.size() == 3)
                                {
+                                       TreeServer* pf = Utils->FindServer(prefix);
                                        User* user = this->Instance->FindNick(params[1]);
                                        Channel* chan = this->Instance->FindChan(params[0]);
-                                       if (user && chan)
+                                       if (pf && user && chan)
                                        {
-                                               if (!chan->ServerKickUser(user, params[2].c_str(), false))
+                                               if (!chan->ServerKickUser(user, params[2].c_str(), false, pf->GetName().c_str()))
                                                        /* Yikes, the channels gone! */
                                                        delete chan;
                                        }
@@ -1461,17 +475,12 @@ bool TreeSocket::ProcessLine(std::string &line)
                                }
                                return true;
                        }
-                       else if (command == "OPERNOTICE")
-                       {
-                               if (params.size() >= 1)
-                                       Instance->SNO->WriteToSnoMask('A', "From " + prefix + ": " + params[0]);
-                               return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
-                       }
                        else if (command == "MODENOTICE")
                        {
                                if (params.size() >= 2)
                                {
-                                       Instance->Users->WriteMode(params[0].c_str(), WM_AND, "*** From %s: %s", prefix.c_str(), params[1].c_str());
+                                       if (ServerSource)
+                                               Instance->Users->WriteMode(params[0].c_str(), WM_AND, "*** From %s: %s", (ServerSource ? ServerSource->GetName().c_str() : prefix.c_str()), params[1].c_str());
                                }
                                return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
                        }
@@ -1479,19 +488,20 @@ bool TreeSocket::ProcessLine(std::string &line)
                        {
                                if (params.size() >= 2)
                                {
-                                       Instance->SNO->WriteToSnoMask(*(params[0].c_str()), "From " + prefix + ": "+ params[1]);
+                                       Instance->SNO->WriteToSnoMask(*(params[0].c_str()), "From " + (ServerSource ? ServerSource->GetName().c_str() : prefix) + ": "+ params[1]);
+                                       return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
                                }
-                               return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
+
                        }
                        else if (command == "BURST")
                        {
                                // Set prefix server as bursting
                                if (!ServerSource)
                                {
-                                       this->Instance->SNO->WriteToSnoMask('l', "WTF: Got BURST from a nonexistant server(?): %s", prefix.c_str());
+                                       this->Instance->SNO->WriteToSnoMask('l', "WTF: Got BURST from a nonexistant server(?): %s", (ServerSource ? ServerSource->GetName().c_str() : prefix.c_str()));
                                        return false;
                                }
-                               
+
                                ServerSource->bursting = true;
                                return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
                        }
@@ -1499,23 +509,35 @@ bool TreeSocket::ProcessLine(std::string &line)
                        {
                                if (!ServerSource)
                                {
-                                       this->Instance->SNO->WriteToSnoMask('l', "WTF: Got ENDBURST from a nonexistant server(?): %s", prefix.c_str());
+                                       this->Instance->SNO->WriteToSnoMask('l', "WTF: Got ENDBURST from a nonexistant server(?): %s", (ServerSource ? ServerSource->GetName().c_str() : prefix.c_str()));
                                        return false;
                                }
-                               
+
                                ServerSource->FinishBurst();
                                return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
                        }
+                       else if (command == "ENCAP")
+                       {
+                               return this->Encap(prefix, params);
+                       }
                        else if (command == "MODE")
                        {
                                // Server-prefix MODE.
-                               const char* modelist[MAXPARAMETERS];
-                               for (size_t i = 0; i < params.size(); i++)
-                                       modelist[i] = params[i].c_str();
-                                       
+                               std::vector<std::string> modelist(params.begin(), params.end());
+
+                               /* We don't support this for channel mode changes any more! */
+                               if (params.size() >= 1)
+                               {
+                                       if (Instance->FindChan(params[0]))
+                                       {
+                                               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.");
+                                               return false;
+                                       }
+                               }
+
                                // Insert into the parser
-                               this->Instance->SendMode(modelist, params.size(), this->Instance->FakeClient);
-                               
+                               this->Instance->SendMode(modelist, this->Instance->FakeClient);
+
                                // Pass out to the network
                                return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
                        }
@@ -1565,29 +587,27 @@ bool TreeSocket::ProcessLine(std::string &line)
                                                }
                                        }
                                }
-                                       
+
                                // its a user
-                               const char* strparams[127];
-                               for (unsigned int q = 0; q < params.size(); q++)
-                               {
-                                       strparams[q] = params[q].c_str();
-                               }
+                               std::vector<std::string> strparams(params.begin(), params.end());
 
-                               switch (this->Instance->CallCommandHandler(command.c_str(), strparams, params.size(), who))
+                               switch (this->Instance->CallCommandHandler(command.c_str(), strparams, who))
                                {
                                        case CMD_INVALID:
-                                               // command is irc::string, hence ugliness
+                                               /*
+                                                * XXX: command is irc::string, hence ugliness
+                                                */
                                                this->SendError("Unrecognised or malformed command '" + std::string(command.c_str()) + "' -- possibly loaded mismatched modules");
                                                return false;
                                                break;
-                                       /*
-                                        * CMD_LOCALONLY is aliased to CMD_FAILURE, so this won't go out onto the network.
-                                        */
                                        case CMD_FAILURE:
+                                               /*
+                                                * CMD_LOCALONLY is aliased to CMD_FAILURE, so this won't go out onto the network.
+                                                */
                                                return true;
                                                break;
                                        default:
-                                               /* CMD_SUCCESS and CMD_USER_DELETED fall through here */
+                                               /* CMD_SUCCESS falls through here */
                                                break;
                                }
 
@@ -1644,7 +664,7 @@ void TreeSocket::OnClose()
        if (!quitserver.empty())
        {
                Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' failed.",quitserver.c_str());
-               time_t server_uptime = Instance->Time() - this->age;    
+               time_t server_uptime = Instance->Time() - this->age;
                if (server_uptime)
                        Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
        }
@@ -1652,18 +672,19 @@ void TreeSocket::OnClose()
 
 int TreeSocket::OnIncomingConnection(int newsock, char* ip)
 {
-       /* To prevent anyone from attempting to flood opers/DDoS by connecting to the server port,
-        * or discovering if this port is the server port, we don't allow connections from any
-        * IPs for which we don't have a link block.
-        */
        bool found = false;
 
        found = (std::find(Utils->ValidIPs.begin(), Utils->ValidIPs.end(), ip) != Utils->ValidIPs.end());
        if (!found)
        {
                for (std::vector<std::string>::iterator i = Utils->ValidIPs.begin(); i != Utils->ValidIPs.end(); i++)
-                       if (irc::sockets::MatchCIDR(ip, (*i).c_str()))
+               {
+                       if (*i == "*" || irc::sockets::MatchCIDR(ip, *i))
+                       {
                                found = true;
+                               break;
+                       }
+               }
 
                if (!found)
                {