]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/inspircd.h
f901200cdd6840cac871889639f832c6bb5c0feb
[user/henk/code/inspircd.git] / include / inspircd.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #ifndef __INSPIRCD_H__
18 #define __INSPIRCD_H__
19
20 #include <time.h>
21 #include <string>
22 #include <sstream>
23 #include "inspircd_config.h"
24 #include "users.h"
25 #include "channels.h"
26 #include "socket.h"
27 #include "mode.h"
28 #include "helperfuncs.h"
29 #include "socketengine.h"
30 #include "command_parse.h"
31
32 /* Some misc defines */
33 #define ERROR -1
34 #define MAXCOMMAND 32
35
36 /* Crucial defines */
37 #define ETIREDGERBILS EAGAIN
38
39 /* This define is used in place of strcmp when we 
40  * want to check if a char* string contains only one
41  * letter. Pretty fast, its just two compares and an
42  * addition.
43  */
44 #define IS_SINGLE(x,y) ( (*x == y) && (*(x+1) == 0) )
45
46 #define DELETE(x) { InspIRCd::Log(DEBUG,"%s:%d: delete()",__FILE__,__LINE__); if (x) { delete x; x = NULL; } else InspIRCd::Log(DEBUG,"Attempt to delete NULL pointer!"); }
47
48 template<typename T> inline std::string ConvToStr(const T &in)
49 {
50         std::stringstream tmp;
51         if (!(tmp << in)) return std::string();
52         return tmp.str();
53 }
54
55 class serverstats : public classbase
56 {
57   public:
58         unsigned long statsAccept;
59         unsigned long statsRefused;
60         unsigned long statsUnknown;
61         unsigned long statsCollisions;
62         unsigned long statsDns;
63         unsigned long statsDnsGood;
64         unsigned long statsDnsBad;
65         unsigned long statsConnects;
66         double statsSent;
67         double statsRecv;
68         unsigned long BoundPortCount;
69
70         serverstats()
71         {
72                 statsAccept = statsRefused = statsUnknown = 0;
73                 statsCollisions = statsDns = statsDnsGood = 0;
74                 statsDnsBad = statsConnects = 0;
75                 statsSent = statsRecv = 0.0;
76                 BoundPortCount = 0;
77         }
78 };
79
80
81 class InspIRCd : public classbase
82 {
83  private:
84         char MODERR[MAXBUF];
85         bool expire_run;
86         servernamelist servernames;
87  
88         void EraseFactory(int j);
89         void EraseModule(int j);
90         void BuildISupport();
91         void MoveTo(std::string modulename,int slot);
92         void Start();
93         void SetSignals(bool SEGVHandler);
94         bool DaemonSeed();
95         void MakeLowerMap();
96         void MoveToLast(std::string modulename);
97         void MoveToFirst(std::string modulename);
98         void MoveAfter(std::string modulename, std::string after);
99         void MoveBefore(std::string modulename, std::string before);
100
101         void ProcessUser(userrec* cu);
102         void DoSocketTimeouts(time_t TIME);
103         void DoBackgroundUserStuff(time_t TIME);
104
105  public:
106         time_t startup_time;
107         ModeParser* ModeGrok;
108         CommandParser* Parser;
109         SocketEngine* SE;
110         serverstats* stats;
111         ServerConfig* Config;
112         std::vector<InspSocket*> module_sockets;
113         InspSocket* socket_ref[MAX_DESCRIPTORS];        /* XXX: This should probably be made private, with inline accessors */
114         userrec* fd_ref_table[MAX_DESCRIPTORS];         /* XXX: Ditto */
115         user_hash clientlist;
116         chan_hash chanlist;
117         std::vector<userrec*> local_users;
118         DNS* Res;
119
120         void AddServerName(const std::string &servername);
121         const char* FindServerNamePtr(const std::string &servername);
122         bool FindServerName(const std::string &servername);
123
124         bool UserToPseudo(userrec* user, const std::string &message);
125         bool PseudoToUser(userrec* alive, userrec* zombie, const std::string &message);
126
127         void ServerNoticeAll(char* text, ...);
128         void ServerPrivmsgAll(char* text, ...);
129         void WriteMode(const char* modes, int flags, const char* text, ...);
130
131         int usercnt();
132         int registered_usercount();
133         int usercount_invisible();
134         int usercount_opers();
135         int usercount_unknown();
136         long chancount();
137         long local_count();
138
139         void SendError(const char *s);
140
141         std::string GetRevision();
142         std::string GetVersionString();
143         void WritePID(const std::string &filename);
144         char* ModuleError();
145         bool LoadModule(const char* filename);
146         bool UnloadModule(const char* filename);
147         InspIRCd(int argc, char** argv);
148         void DoOneIteration(bool process_module_sockets);
149         static void Log(int level, const char* text, ...);
150         static void Log(int level, const std::string &text);
151         int Run();
152 };
153
154 /* Miscellaneous stuff here, moved from inspircd_io.h */
155 void Exit(int status);
156
157 #endif