1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "exitcodes.h"
17 #include "inspircd_version.h"
19 void InspIRCd::SignalHandler(int signal)
23 Rehash("Caught SIGHUP");
25 else if (signal == SIGTERM)
31 void InspIRCd::Exit(int status)
36 SetServiceStopped(status);
40 this->SendError("Exiting with status " + ConvToStr(status) + " (" + std::string(ExitCodes[status]) + ")");
43 ServerInstance = NULL;
48 void RehashHandler::Call(const std::string &reason)
50 ServerInstance->SNO->WriteToSnoMask('a', "Rehashing config file %s %s",ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()), reason.c_str());
51 ServerInstance->RehashUsersAndChans();
52 FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
53 if (!ServerInstance->ConfigThread)
55 ServerInstance->ConfigThread = new ConfigReaderThread("");
56 ServerInstance->Threads->Start(ServerInstance->ConfigThread);
60 std::string InspIRCd::GetVersionString(bool operstring)
62 char versiondata[MAXBUF];
64 snprintf(versiondata,MAXBUF,"%s %s :%s [%s,%s,%s]",VERSION,Config->ServerName.c_str(),SYSTEM,REVISION,SE->GetName().c_str(),Config->sid.c_str());
66 snprintf(versiondata,MAXBUF,"InspIRCd-2.0 %s :%s",Config->ServerName.c_str(),Config->CustomVersion.c_str());
70 void InspIRCd::BuildISupport()
72 // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it...
74 v << "WALLCHOPS WALLVOICES MODES=" << Config->Limits.MaxModes - 1 << " CHANTYPES=# PREFIX=" << this->Modes->BuildPrefixes() << " MAP MAXCHANNELS=" << Config->MaxChans << " MAXBANS=60 VBANLIST NICKLEN=" << Config->Limits.NickMax - 1;
75 v << " CASEMAPPING=rfc1459 STATUSMSG=" << Modes->BuildPrefixes(false) << " CHARSET=ascii TOPICLEN=" << Config->Limits.MaxTopic - 1 << " KICKLEN=" << Config->Limits.MaxKick - 1 << " MAXTARGETS=" << Config->MaxTargets - 1;
76 v << " AWAYLEN=" << Config->Limits.MaxAway - 1 << " CHANMODES=" << this->Modes->GiveModeList(MASK_CHANNEL) << " FNC NETWORK=" << Config->Network << " MAXPARA=32 ELIST=MU";
77 Config->data005 = v.str();
78 FOREACH_MOD(I_On005Numeric,On005Numeric(Config->data005));
82 void InspIRCd::IncrementUID(int pos)
85 * Okay. The rules for generating a UID go like this...
86 * -- > ABCDEFGHIJKLMNOPQRSTUVWXYZ --> 012345679 --> WRAP
87 * That is, we start at A. When we reach Z, we go to 0. At 9, we go to
88 * A again, in an iterative fashion.. so..
89 * AAA9 -> AABA, and so on. -- w00t
93 // At pos 3, if we hit '9', we've run out of available UIDs, and need to reset to AAA..AAA.
94 if (current_uid[pos] == '9')
96 for (int i = 3; i < (UUID_LENGTH - 1); i++)
99 pos = UUID_LENGTH - 1;
104 // Buf if we haven't, just keep incrementing merrily.
110 // If we hit Z, wrap around to 0.
111 if (current_uid[pos] == 'Z')
113 current_uid[pos] = '0';
115 else if (current_uid[pos] == '9')
118 * Or, if we hit 9, wrap around to pos = 'A' and (pos - 1)++,
119 * e.g. A9 -> BA -> BB ..
121 current_uid[pos] = 'A';
122 this->IncrementUID(pos - 1);
126 // Anything else, nobody gives a shit. Just increment.
133 * Retrieve the next valid UUID that is free for this server.
135 std::string InspIRCd::GetUID()
137 static int curindex = -1;
140 * If -1, we're setting up. Copy SID into the first three digits, 9's to the rest, null term at the end
141 * Why 9? Well, we increment before we find, otherwise we have an unnecessary copy, and I want UID to start at AAA..AA
142 * and not AA..AB. So by initialising to 99999, we force it to rollover to AAAAA on the first IncrementUID call.
143 * Kind of silly, but I like how it looks.
148 current_uid[0] = Config->sid[0];
149 current_uid[1] = Config->sid[1];
150 current_uid[2] = Config->sid[2];
152 for (int i = 3; i < (UUID_LENGTH - 1); i++)
153 current_uid[i] = '9';
155 curindex = UUID_LENGTH - 2; // look at the end of the string now kthx, ignore null
157 // Null terminator. Important.
158 current_uid[UUID_LENGTH - 1] = '\0';
163 // Add one to the last UID
164 this->IncrementUID(curindex);
166 if (this->FindUUID(current_uid))
169 * It's in use. We need to try the loop again.