]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/server.cpp
7f05aee7bdca6402b09e048afa8b31ce1b4360f3
[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 "inspircd.h"
16
17
18 void InspIRCd::SignalHandler(int signal)
19 {
20         switch (signal)
21         {
22                 case SIGHUP:
23                         Rehash();
24                         break;
25         }
26 }
27
28 void InspIRCd::Rehash()
29 {
30         this->WriteOpers("*** Rehashing config file %s due to SIGHUP",ServerConfig::CleanFilename(this->ConfigFileName));
31         this->CloseLog();
32         this->OpenLog(this->Config->argv, this->Config->argc);
33         this->RehashUsersAndChans();
34         FOREACH_MOD_I(this, I_OnGarbageCollect, OnGarbageCollect());
35         this->Config->Read(false,NULL);
36         this->ResetMaxBans();
37         this->Res->Rehash();
38         FOREACH_MOD_I(this,I_OnRehash,OnRehash(NULL,""));
39         this->BuildISupport();
40 }
41
42 void InspIRCd::RehashServer()
43 {
44         this->WriteOpers("*** Rehashing config file");
45         this->RehashUsersAndChans();
46         this->Config->Read(false,NULL);
47         this->ResetMaxBans();
48         this->Res->Rehash();
49 }
50
51 std::string InspIRCd::GetVersionString()
52 {
53         char versiondata[MAXBUF];
54         char dnsengine[] = "singlethread-object";
55
56         if (*Config->CustomVersion)
57         {
58                 snprintf(versiondata,MAXBUF,"%s %s :%s",VERSION,Config->ServerName,Config->CustomVersion);
59         }
60         else
61         {
62                 snprintf(versiondata,MAXBUF,"%s %s :%s [FLAGS=%s,%s,%s]",VERSION,Config->ServerName,SYSTEM,REVISION,SE->GetName().c_str(),dnsengine);
63         }
64         return versiondata;
65 }
66
67 void InspIRCd::BuildISupport()
68 {
69         // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it...
70         std::stringstream v;
71         v << "WALLCHOPS WALLVOICES MODES=" << MAXMODES-1 << " CHANTYPES=# PREFIX=" << this->Modes->BuildPrefixes() << " MAP MAXCHANNELS=" << Config->MaxChans << " MAXBANS=60 VBANLIST NICKLEN=" << NICKMAX-1;
72         v << " CASEMAPPING=rfc1459 STATUSMSG=@%+ CHARSET=ascii TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=" << Config->MaxTargets << " AWAYLEN=";
73         v << MAXAWAY << " CHANMODES=" << this->Modes->ChanModes() << " FNC NETWORK=" << Config->Network << " MAXPARA=32 ELIST=MU";
74         Config->data005 = v.str();
75         FOREACH_MOD_I(this,I_On005Numeric,On005Numeric(Config->data005));
76         Config->Update005();
77 }
78
79 std::string InspIRCd::GetRevision()
80 {
81         return REVISION;
82 }
83
84 void InspIRCd::AddServerName(const std::string &servername)
85 {
86         servernamelist::iterator itr = servernames.begin();
87         for(; itr != servernames.end(); ++itr)
88                 if(**itr == servername)
89                         return;
90
91         string * ns = new string(servername);
92         servernames.push_back(ns);
93 }
94
95 const char* InspIRCd::FindServerNamePtr(const std::string &servername)
96 {
97         servernamelist::iterator itr = servernames.begin();
98         for(; itr != servernames.end(); ++itr)
99                 if(**itr == servername)
100                         return (*itr)->c_str();
101
102         servernames.push_back(new string(servername));
103         itr = --servernames.end();
104         return (*itr)->c_str();
105 }
106
107 bool InspIRCd::FindServerName(const std::string &servername)
108 {
109         servernamelist::iterator itr = servernames.begin();
110         for(; itr != servernames.end(); ++itr)
111                 if(**itr == servername)
112                         return true;
113         return false;
114 }
115