-
-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 (unsigned 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;
- int x = 0;
- 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))
- {
- log(DEBUG,"Removing %s",j->GetServerName().c_str());
- j->routes.clear();
- j->CloseConnection();
- me[i]->connectors.erase(j);
- go_again = true;
- x++;
- break;
- }
- }
- }
- }
- }
- if (!x)
- {
- log(DEBUG,"No clients to remove.");
- return;
- }
- 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;
- }
- }
- }
- has_been_netsplit = true;
- log(DEBUG,"Removed clients (DoSplit)");
-}
-
-// 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 (unsigned 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;
- }
- FOREACH_MOD OnUnloadModule(modules[j],module_names[j]);
- // 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;
- }
- }
- log(DEFAULT,"Module %s is not loaded, cannot unload it!",filename);
- snprintf(MODERR,MAXBUF,"Module not loaded");
- return false;
-}
-
-bool LoadModule(const char* filename)