]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/server.cpp
0f931da075ec85aae28d5ff043450a5a79bc37e8
[user/henk/code/inspircd.git] / src / server.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include <signal.h>
15 #include "exitcodes.h"
16 #include "inspircd.h"
17
18
19 void InspIRCd::SignalHandler(int signal)
20 {
21         switch (signal)
22         {
23                 case SIGHUP:
24                         Rehash();
25                         break;
26                 case SIGTERM:
27                         Exit(signal);
28                         break;
29         }
30 }
31
32 void InspIRCd::Exit(int status)
33 {
34 #ifdef WINDOWS
35         CloseIPC();
36 #endif
37         if (this)
38         {
39                 this->SendError("Exiting with status " + ConvToStr(status) + " (" + std::string(ExitCodes[status]) + ")");
40                 this->Cleanup();
41     }
42     exit (status);
43 }
44
45 void InspIRCd::Rehash()
46 {
47         this->WriteOpers("*** Rehashing config file %s due to SIGHUP",ServerConfig::CleanFilename(this->ConfigFileName));
48         this->CloseLog();
49         this->OpenLog(this->Config->argv, this->Config->argc);
50         this->RehashUsersAndChans();
51         FOREACH_MOD_I(this, I_OnGarbageCollect, OnGarbageCollect());
52         this->Config->Read(false,NULL);
53         this->ResetMaxBans();
54         this->Res->Rehash();
55         FOREACH_MOD_I(this,I_OnRehash,OnRehash(NULL,""));
56         this->BuildISupport();
57 }
58
59 void InspIRCd::RehashServer()
60 {
61         this->WriteOpers("*** Rehashing config file");
62         this->RehashUsersAndChans();
63         this->Config->Read(false,NULL);
64         this->ResetMaxBans();
65         this->Res->Rehash();
66 }
67
68 std::string InspIRCd::GetVersionString()
69 {
70         char versiondata[MAXBUF];
71         char dnsengine[] = "singlethread-object";
72
73         if (*Config->CustomVersion)
74         {
75                 snprintf(versiondata,MAXBUF,"%s %s :%s",VERSION,Config->ServerName,Config->CustomVersion);
76         }
77         else
78         {
79                 snprintf(versiondata,MAXBUF,"%s %s :%s [FLAGS=%s,%s,%s]",VERSION,Config->ServerName,SYSTEM,REVISION,SE->GetName().c_str(),dnsengine);
80         }
81         return versiondata;
82 }
83
84 void InspIRCd::BuildISupport()
85 {
86         // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it...
87         std::stringstream v;
88         v << "WALLCHOPS WALLVOICES MODES=" << MAXMODES-1 << " CHANTYPES=# PREFIX=" << this->Modes->BuildPrefixes() << " MAP MAXCHANNELS=" << Config->MaxChans << " MAXBANS=60 VBANLIST NICKLEN=" << NICKMAX-1;
89         v << " CASEMAPPING=rfc1459 STATUSMSG=@%+ CHARSET=ascii TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=" << Config->MaxTargets << " AWAYLEN=";
90         v << MAXAWAY << " CHANMODES=" << this->Modes->ChanModes() << " FNC NETWORK=" << Config->Network << " MAXPARA=32 ELIST=MU";
91         Config->data005 = v.str();
92         FOREACH_MOD_I(this,I_On005Numeric,On005Numeric(Config->data005));
93         Config->Update005();
94 }
95
96 std::string InspIRCd::GetRevision()
97 {
98         return REVISION;
99 }
100
101 void InspIRCd::AddServerName(const std::string &servername)
102 {
103         servernamelist::iterator itr = servernames.begin();
104         for(; itr != servernames.end(); ++itr)
105                 if(**itr == servername)
106                         return;
107
108         string * ns = new string(servername);
109         servernames.push_back(ns);
110 }
111
112 const char* InspIRCd::FindServerNamePtr(const std::string &servername)
113 {
114         servernamelist::iterator itr = servernames.begin();
115         for(; itr != servernames.end(); ++itr)
116                 if(**itr == servername)
117                         return (*itr)->c_str();
118
119         servernames.push_back(new string(servername));
120         itr = --servernames.end();
121         return (*itr)->c_str();
122 }
123
124 bool InspIRCd::FindServerName(const std::string &servername)
125 {
126         servernamelist::iterator itr = servernames.begin();
127         for(; itr != servernames.end(); ++itr)
128                 if(**itr == servername)
129                         return true;
130         return false;
131 }
132