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)
26 Rehash("due to SIGHUP");
34 void InspIRCd::Exit(int status)
41 this->SendError("Exiting with status " + ConvToStr(status) + " (" + std::string(ExitCodes[status]) + ")");
47 void RehashHandler::Call(const std::string &reason)
49 Server->SNO->WriteToSnoMask('A', "Rehashing config file %s %s",ServerConfig::CleanFilename(Server->ConfigFileName), reason.c_str());
50 Server->RehashUsersAndChans();
51 FOREACH_MOD_I(Server, I_OnGarbageCollect, OnGarbageCollect());
52 if (!Server->ConfigThread)
54 Server->Config->RehashUser = NULL;
55 Server->Config->RehashParameter = "";
57 Server->ConfigThread = new ConfigReaderThread(Server, false, NULL);
58 Server->Threads->Create(Server->ConfigThread);
62 void InspIRCd::RehashServer()
67 std::string InspIRCd::GetVersionString()
69 char versiondata[MAXBUF];
70 if (*Config->CustomVersion)
72 snprintf(versiondata,MAXBUF,"InspIRCd-1.2 %s :%s",Config->ServerName,Config->CustomVersion);
76 snprintf(versiondata,MAXBUF,"InspIRCd-1.2 %s :%s (%s) [FLAGS=%s,%s,%s]",Config->ServerName,SYSTEM,VERSION,REVISION,SE->GetName().c_str(),Config->sid);
81 void InspIRCd::BuildISupport()
83 // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it...
85 v << "WALLCHOPS WALLVOICES MODES=" << MAXMODES << " CHANTYPES=# PREFIX=" << this->Modes->BuildPrefixes() << " MAP MAXCHANNELS=" << Config->MaxChans << " MAXBANS=60 VBANLIST NICKLEN=" << NICKMAX-1;
86 v << " CASEMAPPING=rfc1459 STATUSMSG=@" << (this->Config->AllowHalfop ? "%" : "") << "+ CHARSET=ascii TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=" << Config->MaxTargets;
87 v << " AWAYLEN=" << MAXAWAY << " CHANMODES=" << this->Modes->ChanModes() << " FNC NETWORK=" << Config->Network << " MAXPARA=32 ELIST=MU";
88 Config->data005 = v.str();
89 FOREACH_MOD_I(this,I_On005Numeric,On005Numeric(Config->data005));
93 std::string InspIRCd::GetRevision()
98 void InspIRCd::AddServerName(const std::string &servername)
100 servernamelist::iterator itr = servernames.begin();
101 for(; itr != servernames.end(); ++itr)
102 if(**itr == servername)
105 std::string * ns = new std::string(servername);
106 servernames.push_back(ns);
109 const char* InspIRCd::FindServerNamePtr(const std::string &servername)
111 servernamelist::iterator itr = servernames.begin();
112 for(; itr != servernames.end(); ++itr)
113 if(**itr == servername)
114 return (*itr)->c_str();
116 servernames.push_back(new std::string(servername));
117 itr = --servernames.end();
118 return (*itr)->c_str();
121 bool InspIRCd::FindServerName(const std::string &servername)
123 servernamelist::iterator itr = servernames.begin();
124 for(; itr != servernames.end(); ++itr)
125 if(**itr == servername)
130 void InspIRCd::IncrementUID(int pos)
133 * Okay. The rules for generating a UID go like this...
134 * -- > ABCDEFGHIJKLMNOPQRSTUVWXYZ --> 012345679 --> WRAP
135 * That is, we start at A. When we reach Z, we go to 0. At 9, we go to
136 * A again, in an iterative fashion.. so..
137 * AAA9 -> AABA, and so on. -- w00t
141 // At pos 3, if we hit '9', we've run out of available UIDs, and need to reset to AAA..AAA.
142 if (current_uid[pos] == '9')
144 for (int i = 3; i < UUID_LENGTH; i++)
146 current_uid[i] = 'A';
147 pos = UUID_LENGTH - 1;
152 // Buf if we haven't, just keep incrementing merrily.
158 // If we hit Z, wrap around to 0.
159 if (current_uid[pos] == 'Z')
161 current_uid[pos] = '0';
163 else if (current_uid[pos] == '9')
166 * Or, if we hit 9, wrap around to pos = 'A' and (pos - 1)++,
167 * e.g. A9 -> BA -> BB ..
169 current_uid[pos] = 'A';
170 this->IncrementUID(pos - 1);
174 // Anything else, nobody gives a shit. Just increment.
181 * Retrieve the next valid UUID that is free for this server.
183 std::string InspIRCd::GetUID()
185 static int curindex = -1;
188 * If -1, we're setting up. Copy SID into the first three digits, 9's to the rest, null term at the end
189 * Why 9? Well, we increment before we find, otherwise we have an unnecessary copy, and I want UID to start at AAA..AA
190 * and not AA..AB. So by initialising to 99999, we force it to rollover to AAAAA on the first IncrementUID call.
191 * Kind of silly, but I like how it looks.
196 current_uid[0] = Config->sid[0];
197 current_uid[1] = Config->sid[1];
198 current_uid[2] = Config->sid[2];
200 for (int i = 3; i < (UUID_LENGTH - 1); i++)
201 current_uid[i] = '9';
203 curindex = UUID_LENGTH - 2; // look at the end of the string now kthx, ignore null
205 // Null terminator. Important.
206 current_uid[UUID_LENGTH - 1] = '\0';
211 // Add one to the last UID
212 this->IncrementUID(curindex);
214 if (this->FindUUID(current_uid))
217 * It's in use. We need to try the loop again.