1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "exitcodes.h"
19 void InspIRCd::SignalHandler(int signal)
32 void InspIRCd::Exit(int status)
39 this->SendError("Exiting with status " + ConvToStr(status) + " (" + std::string(ExitCodes[status]) + ")");
45 void InspIRCd::Rehash()
47 this->WriteOpers("*** Rehashing config file %s due to SIGHUP",ServerConfig::CleanFilename(this->ConfigFileName));
49 if (!this->OpenLog(this->Config->argv, this->Config->argc))
50 this->WriteOpers("*** ERROR: Could not open logfile %s: %s", Config->logpath.c_str(), strerror(errno));
51 this->RehashUsersAndChans();
52 FOREACH_MOD_I(this, I_OnGarbageCollect, OnGarbageCollect());
53 this->Config->Read(false,NULL);
56 FOREACH_MOD_I(this,I_OnRehash,OnRehash(NULL,""));
57 this->BuildISupport();
60 void InspIRCd::RehashServer()
62 this->WriteOpers("*** Rehashing config file");
63 this->RehashUsersAndChans();
64 this->Config->Read(false,NULL);
69 std::string InspIRCd::GetVersionString()
71 char versiondata[MAXBUF];
72 char dnsengine[] = "singlethread-object";
74 if (*Config->CustomVersion)
76 snprintf(versiondata,MAXBUF,"%s %s :%s",VERSION,Config->ServerName,Config->CustomVersion);
80 snprintf(versiondata,MAXBUF,"%s %s :%s [FLAGS=%s,%s,%s]",VERSION,Config->ServerName,SYSTEM,REVISION,SE->GetName().c_str(),dnsengine);
85 void InspIRCd::BuildISupport()
87 // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it...
89 v << "WALLCHOPS WALLVOICES MODES=" << MAXMODES << " CHANTYPES=# PREFIX=" << this->Modes->BuildPrefixes() << " MAP MAXCHANNELS=" << Config->MaxChans << " MAXBANS=60 VBANLIST NICKLEN=" << NICKMAX-1;
90 v << " CASEMAPPING=rfc1459 STATUSMSG=@%+ CHARSET=ascii TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=" << Config->MaxTargets << " AWAYLEN=";
91 v << MAXAWAY << " CHANMODES=" << this->Modes->ChanModes() << " FNC NETWORK=" << Config->Network << " MAXPARA=32 ELIST=MU";
92 Config->data005 = v.str();
93 FOREACH_MOD_I(this,I_On005Numeric,On005Numeric(Config->data005));
97 std::string InspIRCd::GetRevision()
102 void InspIRCd::AddServerName(const std::string &servername)
104 servernamelist::iterator itr = servernames.begin();
105 for(; itr != servernames.end(); ++itr)
106 if(**itr == servername)
109 string * ns = new string(servername);
110 servernames.push_back(ns);
113 const char* InspIRCd::FindServerNamePtr(const std::string &servername)
115 servernamelist::iterator itr = servernames.begin();
116 for(; itr != servernames.end(); ++itr)
117 if(**itr == servername)
118 return (*itr)->c_str();
120 servernames.push_back(new string(servername));
121 itr = --servernames.end();
122 return (*itr)->c_str();
125 bool InspIRCd::FindServerName(const std::string &servername)
127 servernamelist::iterator itr = servernames.begin();
128 for(; itr != servernames.end(); ++itr)
129 if(**itr == servername)
135 * Retrieve the next valid UUID that is free for this server.
137 std::string InspIRCd::GetUID()
142 * This will only finish once we return a UUID that is not in use.
147 * Okay. The rules for generating a UID go like this...
148 * -- > ABCDEFGHIJKLMNOPQRSTUVWXYZ --> 012345679 --> WRAP
149 * That is, we start at A. When we reach Z, we go to 0. At 9, we go to
150 * A again, in an iterative fashion.. so..
151 * AAA9 -> AABA, and so on. -- w00t
154 /* start at the end of the current UID string, work backwards. don't trample on SID! */
155 for (i = UUID_LENGTH - 2; i > 3; i--)
157 if (current_uid[i] == 'Z')
159 /* reached the end of alphabetical, go to numeric range */
160 current_uid[i] = '0';
162 else if (current_uid[i] == '9')
164 /* we reached the end of the sequence, set back to A */
165 current_uid[i] = 'A';
167 /* we also need to increment the next digit. */
172 /* most common case .. increment current UID */
176 if (current_uid[3] == 'Z')
178 /* If we get to here, we need to wrap around to AAAA. */
179 for(int j = 3; j < UUID_LENGTH - 1; j++)
180 current_uid[j] = 'A';
183 * and now we need to break the inner for () to continue the while (),
184 * which will start the checking process over again. -- w00t
190 if (this->FindUUID(current_uid))
193 * It's in use. We need to try the loop again.