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 * ---------------------------------------------------
14 /* $Core: libIRCDserver */
17 #include "exitcodes.h"
21 void InspIRCd::SignalHandler(int signal)
34 void InspIRCd::Exit(int status)
36 printf("exit with status %d\n", status);
42 this->SendError("Exiting with status " + ConvToStr(status) + " (" + std::string(ExitCodes[status]) + ")");
45 printf("Exit done.\n");
49 void InspIRCd::Rehash()
51 this->WriteOpers("*** Rehashing config file %s due to SIGHUP",ServerConfig::CleanFilename(this->ConfigFileName));
53 if (!this->OpenLog(this->Config->argv, this->Config->argc))
54 this->WriteOpers("*** ERROR: Could not open logfile %s: %s", Config->logpath.c_str(), strerror(errno));
55 this->RehashUsersAndChans();
56 FOREACH_MOD_I(this, I_OnGarbageCollect, OnGarbageCollect());
57 this->Config->Read(false,NULL);
60 FOREACH_MOD_I(this,I_OnRehash,OnRehash(NULL,""));
61 this->BuildISupport();
64 void InspIRCd::RehashServer()
66 this->WriteOpers("*** Rehashing config file");
67 this->RehashUsersAndChans();
68 this->Config->Read(false,NULL);
73 std::string InspIRCd::GetVersionString()
75 char versiondata[MAXBUF];
76 if (*Config->CustomVersion)
78 snprintf(versiondata,MAXBUF,"%s %s :%s",VERSION,Config->ServerName,Config->CustomVersion);
82 snprintf(versiondata,MAXBUF,"%s %s :%s [FLAGS=%s,%s,%d]",VERSION,Config->ServerName,SYSTEM,REVISION,SE->GetName().c_str(),Config->sid);
87 void InspIRCd::BuildISupport()
89 // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it...
91 v << "WALLCHOPS WALLVOICES MODES=" << MAXMODES << " CHANTYPES=# PREFIX=" << this->Modes->BuildPrefixes() << " MAP MAXCHANNELS=" << Config->MaxChans << " MAXBANS=60 VBANLIST NICKLEN=" << NICKMAX-1;
92 v << " CASEMAPPING=rfc1459 STATUSMSG=@" << (this->Config->AllowHalfop ? "%" : "") << "+ CHARSET=ascii TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=" << Config->MaxTargets;
93 v << " AWAYLEN=" << MAXAWAY << " CHANMODES=" << this->Modes->ChanModes() << " FNC NETWORK=" << Config->Network << " MAXPARA=32 ELIST=MU";
94 Config->data005 = v.str();
95 FOREACH_MOD_I(this,I_On005Numeric,On005Numeric(Config->data005));
99 std::string InspIRCd::GetRevision()
104 void InspIRCd::AddServerName(const std::string &servername)
106 servernamelist::iterator itr = servernames.begin();
107 for(; itr != servernames.end(); ++itr)
108 if(**itr == servername)
111 string * ns = new string(servername);
112 servernames.push_back(ns);
115 const char* InspIRCd::FindServerNamePtr(const std::string &servername)
117 servernamelist::iterator itr = servernames.begin();
118 for(; itr != servernames.end(); ++itr)
119 if(**itr == servername)
120 return (*itr)->c_str();
122 servernames.push_back(new string(servername));
123 itr = --servernames.end();
124 return (*itr)->c_str();
127 bool InspIRCd::FindServerName(const std::string &servername)
129 servernamelist::iterator itr = servernames.begin();
130 for(; itr != servernames.end(); ++itr)
131 if(**itr == servername)
137 * Retrieve the next valid UUID that is free for this server.
139 std::string InspIRCd::GetUID()
144 * This will only finish once we return a UUID that is not in use.
149 * Okay. The rules for generating a UID go like this...
150 * -- > ABCDEFGHIJKLMNOPQRSTUVWXYZ --> 012345679 --> WRAP
151 * That is, we start at A. When we reach Z, we go to 0. At 9, we go to
152 * A again, in an iterative fashion.. so..
153 * AAA9 -> AABA, and so on. -- w00t
156 /* start at the end of the current UID string, work backwards. don't trample on SID! */
157 for (i = UUID_LENGTH - 2; i > 3; i--)
159 if (current_uid[i] == 'Z')
161 /* reached the end of alphabetical, go to numeric range */
162 current_uid[i] = '0';
164 else if (current_uid[i] == '9')
166 /* we reached the end of the sequence, set back to A */
167 current_uid[i] = 'A';
169 /* we also need to increment the next digit. */
174 /* most common case .. increment current UID */
178 if (current_uid[3] == 'Z')
181 * Ugh. We have run out of room.. roll back around to the
182 * start of the UUID namespace. -- w00t
184 this->InitialiseUID();
187 * and now we need to break the inner for () to continue the while (),
188 * which will start the checking process over again. -- w00t
194 if (this->FindUUID(current_uid))
197 * It's in use. We need to try the loop again.