]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules.cpp
820488c99aff5f5c25e8d9d2b2950f7976b75f17
[user/henk/code/inspircd.git] / src / modules.cpp
1 /*
2
3
4 */
5
6
7
8 #include <typeinfo>
9 #include <iostream>
10 #include "globals.h"
11 #include "modules.h"
12 #include "ctables.h"
13 #include "inspircd_io.h"
14
15 // class type for holding an extended mode character - internal to core
16
17 class ExtMode
18 {
19 public:
20         char modechar;
21         int type;
22         bool default_on;
23         int params_when_on;
24         int params_when_off;
25         ExtMode(char mc, int ty, bool d_on, int p_on, int p_off) : modechar(mc), type(ty), default_on(d_on), params_when_on(p_on), params_when_off(p_off) { };
26 };                                     
27
28 typedef std::vector<ExtMode> ExtModeList;
29 typedef ExtModeList::iterator ExtModeListIter;
30
31 ExtModeList EMode;
32
33 // returns true if an extended mode character is in use
34 bool ModeDefined(char modechar, int type)
35 {
36         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
37         {
38                 if ((i->modechar == modechar) && (i->type == type))
39                 {
40                         return true;
41                 }
42         }
43         return false;
44 }
45
46 // returns number of parameters for a custom mode when it is switched on
47 bool ModeDefinedOn(char modechar, int type)
48 {
49         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
50         {
51                 if ((i->modechar == modechar) && (i->type == type))
52                 {
53                         return i->params_when_on;
54                 }
55         }
56         return 0;
57 }
58
59 // returns number of parameters for a custom mode when it is switched on
60 bool ModeDefinedOff(char modechar, int type)
61 {
62         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
63         {
64                 if ((i->modechar == modechar) && (i->type == type))
65                 {
66                         return i->params_when_off;
67                 }
68         }
69         return 0;
70 }
71
72 // returns true if an extended mode character is in use
73 bool AddExtendedMode(char modechar, int type, bool default_on, int params_on, int params_off)
74 {
75         EMode.push_back( ExtMode (modechar,type,default_on,params_on,params_off));
76         return true;
77 }
78
79
80 // version is a simple class for holding a modules version number
81
82 Version::Version(int major, int minor, int revision, int build) : Major(major), Minor(minor), Revision(revision), Build(build) { };
83
84 // admin is a simple class for holding a server's administrative info
85
86 Admin::Admin(std::string name, std::string email, std::string nick) : Name(name), Email(email), Nick(nick) { };
87
88 Module::Module() { }
89 Module::~Module() { }
90 void Module::OnUserConnect(userrec* user) { }
91 void Module::OnUserQuit(userrec* user) { }
92 void Module::OnUserJoin(userrec* user, chanrec* channel) { }
93 void Module::OnUserPart(userrec* user, chanrec* channel) { }
94 void Module::OnPacketTransmit(char *p) { }
95 void Module::OnPacketReceive(char *p) { }
96 void Module::OnRehash() { }
97 void Module::OnServerRaw(std::string &raw, bool inbound) { }
98 bool Module::OnExtendedMode(userrec* user, chanrec* chan, char modechar, int type, bool mode_on, string_list &params) { }
99 Version Module::GetVersion() { return Version(1,0,0,0); }
100
101 // server is a wrapper class that provides methods to all of the C-style
102 // exports in the core
103 //
104
105 Server::Server()
106 {
107 }
108
109 Server::~Server()
110 {
111 }
112
113 void Server::SendOpers(std::string s)
114 {
115         WriteOpers("%s",s.c_str());
116 }
117
118 void Server::Log(int level, std::string s)
119 {
120         log(level,"%s",s.c_str());
121 }
122
123 void Server::AddCommand(char* cmd, handlerfunc f, char flags, int minparams)
124 {
125         createcommand(cmd,f,flags,minparams);
126 }
127
128
129 void Server::Send(int Socket, std::string s)
130 {
131         Write(Socket,"%s",s.c_str());
132 }
133
134 void Server::SendServ(int Socket, std::string s)
135 {
136         WriteServ(Socket,"%s",s.c_str());
137 }
138
139 void Server::SendFrom(int Socket, userrec* User, std::string s)
140 {
141         WriteFrom(Socket,User,"%s",s.c_str());
142 }
143
144 void Server::SendTo(userrec* Source, userrec* Dest, std::string s)
145 {
146         WriteTo(Source,Dest,"%s",s.c_str());
147 }
148
149 void Server::SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender)
150 {
151         if (IncludeSender)
152         {
153                 WriteChannel(Channel,User,"%s",s.c_str());
154         }
155         else
156         {
157                 ChanExceptSender(Channel,User,"%s",s.c_str());
158         }
159 }
160
161 bool Server::CommonChannels(userrec* u1, userrec* u2)
162 {
163         return (common_channels(u1,u2) != 0);
164 }
165
166 void Server::SendCommon(userrec* User, std::string text,bool IncludeSender)
167 {
168         if (IncludeSender)
169         {
170                 WriteCommon(User,"%s",text.c_str());
171         }
172         else
173         {
174                 WriteCommonExcept(User,"%s",text.c_str());
175         }
176 }
177
178 void Server::SendWallops(userrec* User, std::string text)
179 {
180         WriteWallOps(User,"%s",text.c_str());
181 }
182
183 bool Server::IsNick(std::string nick)
184 {
185         return (isnick(nick.c_str()) != 0);
186 }
187
188 userrec* Server::FindNick(std::string nick)
189 {
190         return Find(nick);
191 }
192
193 chanrec* Server::FindChannel(std::string channel)
194 {
195         return FindChan(channel.c_str());
196 }
197
198 std::string Server::ChanMode(userrec* User, chanrec* Chan)
199 {
200         return cmode(User,Chan);
201 }
202
203 std::string Server::GetServerName()
204 {
205         return getservername();
206 }
207
208 std::string Server::GetNetworkName()
209 {
210         return getnetworkname();
211 }
212
213 Admin Server::GetAdmin()
214 {
215         return Admin(getadminname(),getadminemail(),getadminnick());
216 }
217
218
219
220 bool Server::AddExtendedMode(char modechar, int type, bool default_on, int params_when_on, int params_when_off)
221 {
222 }
223
224
225 ConfigReader::ConfigReader()
226 {
227         fname = CONFIG_FILE;
228 }
229
230
231 ConfigReader::~ConfigReader()
232 {
233 }
234
235
236 ConfigReader::ConfigReader(std::string filename) : fname(filename) { };
237
238 std::string ConfigReader::ReadValue(std::string tag, std::string name, int index)
239 {
240         char val[MAXBUF];
241         ReadConf(fname.c_str(),tag.c_str(),name.c_str(),index,val);
242         return val;
243 }
244
245
246 int ConfigReader::Enumerate(std::string tag)
247 {
248         return EnumConf(fname.c_str(),tag.c_str());
249 }
250
251
252 bool ConfigReader::Verify()
253 {
254         return true;
255 }
256
257
258 FileReader::FileReader(std::string filename)
259 {
260         file_cache c;
261         readfile(c,filename.c_str());
262         this->fc = c;
263 }
264
265 FileReader::FileReader()
266 {
267 }
268
269 void FileReader::LoadFile(std::string filename)
270 {
271         file_cache c;
272         readfile(c,filename.c_str());
273         this->fc = c;
274 }
275
276
277 FileReader::~FileReader()
278 {
279 }
280
281 bool FileReader::Exists()
282 {
283         if (fc.size() == 0)
284         {
285                 return(false);
286         }
287         else
288         {
289                 return(true);
290         }
291 }
292
293 std::string FileReader::GetLine(int x)
294 {
295         if ((x<0) || (x>fc.size()))
296                 return "";
297         return fc[x];
298 }
299
300 int FileReader::FileSize()
301 {
302         return fc.size();
303 }
304
305
306 std::vector<Module*> modules(255);
307 std::vector<ircd_module*> factory(255);
308
309 int MODCOUNT  = -1;
310
311