1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 * ---------------------------------------------------
14 /* $Core: libIRCDserver */
17 #include "exitcodes.h"
21 void InspIRCd::SignalHandler(int signal)
34 void InspIRCd::Exit(int status)
41 this->SendError("Exiting with status " + ConvToStr(status) + " (" + std::string(ExitCodes[status]) + ")");
47 void InspIRCd::Rehash()
49 this->SNO->WriteToSnoMask('A', "Rehashing config file %s due to SIGHUP",ServerConfig::CleanFilename(this->ConfigFileName));
50 this->RehashUsersAndChans();
51 FOREACH_MOD_I(this, I_OnGarbageCollect, OnGarbageCollect());
52 if (!this->ConfigThread)
54 Config->RehashUser = NULL;
55 Config->RehashParameter = "";
57 ConfigThread = new ConfigReaderThread(this, false, NULL);
58 Threads->Create(ConfigThread);
62 void InspIRCd::RehashServer()
64 this->SNO->WriteToSnoMask('A', "Rehashing config file");
65 this->RehashUsersAndChans();
66 if (!this->ConfigThread)
68 Config->RehashUser = NULL;
69 Config->RehashParameter = "";
71 ConfigThread = new ConfigReaderThread(this, false, NULL);
72 Threads->Create(ConfigThread);
76 std::string InspIRCd::GetVersionString()
78 char versiondata[MAXBUF];
79 if (*Config->CustomVersion)
81 snprintf(versiondata,MAXBUF,"InspIRCd-1.2 %s :%s",Config->ServerName,Config->CustomVersion);
85 snprintf(versiondata,MAXBUF,"InspIRCd-1.2 %s :%s (%s) [FLAGS=%s,%s,%s]",Config->ServerName,SYSTEM,VERSION,REVISION,SE->GetName().c_str(),Config->sid);
90 void InspIRCd::BuildISupport()
92 // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it...
94 v << "WALLCHOPS WALLVOICES MODES=" << MAXMODES << " CHANTYPES=# PREFIX=" << this->Modes->BuildPrefixes() << " MAP MAXCHANNELS=" << Config->MaxChans << " MAXBANS=60 VBANLIST NICKLEN=" << NICKMAX-1;
95 v << " CASEMAPPING=rfc1459 STATUSMSG=@" << (this->Config->AllowHalfop ? "%" : "") << "+ CHARSET=ascii TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=" << Config->MaxTargets;
96 v << " AWAYLEN=" << MAXAWAY << " CHANMODES=" << this->Modes->ChanModes() << " FNC NETWORK=" << Config->Network << " MAXPARA=32 ELIST=MU";
97 Config->data005 = v.str();
98 FOREACH_MOD_I(this,I_On005Numeric,On005Numeric(Config->data005));
102 std::string InspIRCd::GetRevision()
107 void InspIRCd::AddServerName(const std::string &servername)
109 servernamelist::iterator itr = servernames.begin();
110 for(; itr != servernames.end(); ++itr)
111 if(**itr == servername)
114 std::string * ns = new std::string(servername);
115 servernames.push_back(ns);
118 const char* InspIRCd::FindServerNamePtr(const std::string &servername)
120 servernamelist::iterator itr = servernames.begin();
121 for(; itr != servernames.end(); ++itr)
122 if(**itr == servername)
123 return (*itr)->c_str();
125 servernames.push_back(new std::string(servername));
126 itr = --servernames.end();
127 return (*itr)->c_str();
130 bool InspIRCd::FindServerName(const std::string &servername)
132 servernamelist::iterator itr = servernames.begin();
133 for(; itr != servernames.end(); ++itr)
134 if(**itr == servername)
139 void InspIRCd::IncrementUID(int pos)
142 * Okay. The rules for generating a UID go like this...
143 * -- > ABCDEFGHIJKLMNOPQRSTUVWXYZ --> 012345679 --> WRAP
144 * That is, we start at A. When we reach Z, we go to 0. At 9, we go to
145 * A again, in an iterative fashion.. so..
146 * AAA9 -> AABA, and so on. -- w00t
150 // At pos 3, if we hit '9', we've run out of available UIDs, and need to reset to AAA..AAA.
151 if (current_uid[pos] == '9')
153 for (int i = 3; i < UUID_LENGTH; i++)
155 current_uid[i] = 'A';
156 pos = UUID_LENGTH - 1;
161 // Buf if we haven't, just keep incrementing merrily.
167 // If we hit Z, wrap around to 0.
168 if (current_uid[pos] == 'Z')
170 current_uid[pos] = '0';
172 else if (current_uid[pos] == '9')
175 * Or, if we hit 9, wrap around to pos = 'A' and (pos - 1)++,
176 * e.g. A9 -> BA -> BB ..
178 current_uid[pos] = 'A';
179 this->IncrementUID(pos - 1);
183 // Anything else, nobody gives a shit. Just increment.
190 * Retrieve the next valid UUID that is free for this server.
192 std::string InspIRCd::GetUID()
194 static int curindex = -1;
197 * If -1, we're setting up. Copy SID into the first three digits, 9's to the rest, null term at the end
198 * Why 9? Well, we increment before we find, otherwise we have an unnecessary copy, and I want UID to start at AAA..AA
199 * and not AA..AB. So by initialising to 99999, we force it to rollover to AAAAA on the first IncrementUID call.
200 * Kind of silly, but I like how it looks.
205 current_uid[0] = Config->sid[0];
206 current_uid[1] = Config->sid[1];
207 current_uid[2] = Config->sid[2];
209 for (int i = 3; i < (UUID_LENGTH - 1); i++)
210 current_uid[i] = '9';
212 curindex = UUID_LENGTH - 2; // look at the end of the string now kthx, ignore null
214 // Null terminator. Important.
215 current_uid[UUID_LENGTH - 1] = '\0';
220 // Add one to the last UID
221 this->IncrementUID(curindex);
223 if (this->FindUUID(current_uid))
226 * It's in use. We need to try the loop again.