- snprintf(data,MAXBUF,"%s %s",CreateSum().c_str(),l[j].c_str());
- serv->SendPacket(data,tcp_host);
- }
- }
- char* chl = chlist(u->second,u->second);
- if (strcmp(chl,""))
- {
- snprintf(data,MAXBUF,"%s J %s %s",CreateSum().c_str(),u->second->nick,chl);
- serv->SendPacket(data,tcp_host);
- }
- }
- // send channel modes, topics etc...
- for (chan_hash::iterator c = chanlist.begin(); c != chanlist.end(); c++)
- {
- snprintf(data,MAXBUF,"M %s +%s",c->second->name,chanmodes(c->second));
- serv->SendPacket(data,tcp_host);
- for (int i = 0; i <= MODCOUNT; i++)
- {
- string_list l = modules[i]->OnChannelSync(c->second);
- for (int j = 0; j < l.size(); j++)
- {
- snprintf(data,MAXBUF,"%s %s",CreateSum().c_str(),l[j].c_str());
- serv->SendPacket(data,tcp_host);
- }
- }
- if (c->second->topic[0])
- {
- snprintf(data,MAXBUF,"%s T %lu %s %s :%s",CreateSum().c_str(),(unsigned long)c->second->topicset,c->second->setby,c->second->name,c->second->topic);
- serv->SendPacket(data,tcp_host);
- }
- // send current banlist
-
- for (BanList::iterator b = c->second->bans.begin(); b != c->second->bans.end(); b++)
- {
- snprintf(data,MAXBUF,"%s M %s +b %s",CreateSum().c_str(),c->second->name,b->data);
- serv->SendPacket(data,tcp_host);
- }
- }
- // sync global zlines, glines, etc
- sync_xlines(serv,tcp_host);
-
- snprintf(data,MAXBUF,"%s F %lu",CreateSum().c_str(),(unsigned long)TIME);
- serv->SendPacket(data,tcp_host);
- log(DEBUG,"Sent sync");
- // ircd sends its serverlist after the end of sync here
-}
-
-
-void NetSendMyRoutingTable()
-{
- // send out a line saying what is reachable to us.
- // E.g. if A is linked to B C and D, send out:
- // $ A B C D
- // if its only linked to B and D send out:
- // $ A B D
- // if it has no links, dont even send out the line at all.
- char buffer[MAXBUF];
- snprintf(buffer,MAXBUF,"$ %s",ServerName);
- bool sendit = false;
- for (int i = 0; i < 32; i++)
- {
- if (me[i] != NULL)
- {
- for (int j = 0; j < me[i]->connectors.size(); j++)
- {
- if ((me[i]->connectors[j].GetState() != STATE_DISCONNECTED) || (is_uline(me[i]->connectors[j].GetServerName().c_str())))
- {
- strlcat(buffer," ",MAXBUF);
- strlcat(buffer,me[i]->connectors[j].GetServerName().c_str(),MAXBUF);
- sendit = true;
- }
- }
- }
- }
- if (sendit)
- NetSendToAll(buffer);
-}
-
-
-void DoSplit(const char* params)
-{
- bool go_again = true;
- while (go_again)
- {
- go_again = false;
- for (int i = 0; i < 32; i++)
- {
- if (me[i] != NULL)
- {
- for (vector<ircd_connector>::iterator j = me[i]->connectors.begin(); j != me[i]->connectors.end(); j++)
- {
- if (!strcasecmp(j->GetServerName().c_str(),params))
- {
- j->routes.clear();
- j->CloseConnection();
- me[i]->connectors.erase(j);
- go_again = true;
- break;
- }
- }
- }
- }
- }
- log(DEBUG,"Removed server. Will remove clients...");
- // iterate through the userlist and remove all users on this server.
- // because we're dealing with a mesh, we dont have to deal with anything
- // "down-route" from this server (nice huh)
- go_again = true;
- char reason[MAXBUF];
- snprintf(reason,MAXBUF,"%s %s",ServerName,params);
- while (go_again)
- {
- go_again = false;
- for (user_hash::const_iterator u = clientlist.begin(); u != clientlist.end(); u++)
- {
- if (!strcasecmp(u->second->server,params))
- {
- kill_link(u->second,reason);
- go_again = true;
- break;
- }
- }
- }
-}
-
-// removes a server. Will NOT remove its users!
-
-void RemoveServer(const char* name)
-{
- bool go_again = true;
- while (go_again)
- {
- go_again = false;
- for (int i = 0; i < 32; i++)
- {
- if (me[i] != NULL)
- {
- for (vector<ircd_connector>::iterator j = me[i]->connectors.begin(); j != me[i]->connectors.end(); j++)
- {
- if (!strcasecmp(j->GetServerName().c_str(),name))
- {
- j->routes.clear();
- j->CloseConnection();
- me[i]->connectors.erase(j);
- go_again = true;
- break;
- }
- }
- }
- }
- }
-}
-
-
-char MODERR[MAXBUF];
-
-char* ModuleError()
-{
- return MODERR;
-}
-
-void erase_factory(int j)
-{
- int v = 0;
- for (std::vector<ircd_module*>::iterator t = factory.begin(); t != factory.end(); t++)
- {
- if (v == j)
- {
- factory.erase(t);
- factory.push_back(NULL);
- return;
- }
- v++;
- }
-}
-
-void erase_module(int j)
-{
- int v1 = 0;
- for (std::vector<Module*>::iterator m = modules.begin(); m!= modules.end(); m++)
- {
- if (v1 == j)
- {
- delete *m;
- modules.erase(m);
- modules.push_back(NULL);
- break;
- }
- v1++;
- }
- int v2 = 0;
- for (std::vector<std::string>::iterator v = module_names.begin(); v != module_names.end(); v++)
- {
- if (v2 == j)
- {
- module_names.erase(v);
- break;
- }
- v2++;
- }
-
-}
-
-bool UnloadModule(const char* filename)
-{
- std::string filename_str = filename;
- for (int j = 0; j != module_names.size(); j++)
- {
- if (module_names[j] == filename_str)
- {
- if (modules[j]->GetVersion().Flags & VF_STATIC)
- {
- log(DEFAULT,"Failed to unload STATIC module %s",filename);
- snprintf(MODERR,MAXBUF,"Module not unloadable (marked static)");
- return false;
- }
- // found the module
- log(DEBUG,"Deleting module...");
- erase_module(j);
- log(DEBUG,"Erasing module entry...");
- erase_factory(j);
- log(DEBUG,"Removing dependent commands...");
- removecommands(filename);
- log(DEFAULT,"Module %s unloaded",filename);
- MODCOUNT--;
- return true;