]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules.cpp
Added OnUserDisconnect method to modules.* to fix fd leak in m_ident.cpp
[user/henk/code/inspircd.git] / src / modules.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 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 #include "inspircd.h"
18 #include "inspircd_io.h"
19 #include "inspircd_util.h"
20 #include "inspircd_config.h"
21 #include <unistd.h>
22 #include <fcntl.h>
23 #include <sys/errno.h>
24 #include <sys/ioctl.h>
25 #include <sys/utsname.h>
26 #include <cstdio>
27 #include <time.h>
28 #include <string>
29 #ifdef GCC3
30 #include <ext/hash_map>
31 #else
32 #include <hash_map>
33 #endif
34 #include <map>
35 #include <sstream>
36 #include <vector>
37 #include <errno.h>
38 #include <deque>
39 #include <errno.h>
40 #include <unistd.h>
41 #include <sched.h>
42 #include "connection.h"
43 #include "users.h"
44 #include "servers.h"
45 #include "ctables.h"
46 #include "globals.h"
47 #include "modules.h"
48 #include "dynamic.h"
49 #include "wildcard.h"
50 #include "message.h"
51 #include "mode.h"
52 #include "xline.h"
53 #include "commands.h"
54 #include "inspstring.h"
55
56 #ifdef GCC3
57 #define nspace __gnu_cxx
58 #else
59 #define nspace std
60 #endif
61
62 using namespace std;
63
64 extern int MODCOUNT;
65 extern std::vector<Module*> modules;
66 extern std::vector<ircd_module*> factory;
67
68 extern time_t TIME;
69
70 extern int LogLevel;
71 extern char ServerName[MAXBUF];
72 extern char Network[MAXBUF];
73 extern char ServerDesc[MAXBUF];
74 extern char AdminName[MAXBUF];
75 extern char AdminEmail[MAXBUF];
76 extern char AdminNick[MAXBUF];
77 extern char diepass[MAXBUF];
78 extern char restartpass[MAXBUF];
79 extern char motd[MAXBUF];
80 extern char rules[MAXBUF];
81 extern char list[MAXBUF];
82 extern char PrefixQuit[MAXBUF];
83 extern char DieValue[MAXBUF];
84
85 extern int debugging;
86 extern int WHOWAS_STALE;
87 extern int WHOWAS_MAX;
88 extern int DieDelay;
89 extern time_t startup_time;
90 extern int NetBufferSize;
91 extern int MaxWhoResults;
92 extern time_t nb_start;
93
94 extern std::vector<int> fd_reap;
95 extern std::vector<std::string> module_names;
96
97 extern int boundPortCount;
98 extern int portCount;
99 extern int UDPportCount;
100 extern int ports[MAXSOCKS];
101 extern int defaultRoute;
102
103 extern std::vector<long> auth_cookies;
104 extern std::stringstream config_f;
105
106 extern serverrec* me[32];
107
108 extern FILE *log_file;
109
110
111 namespace nspace
112 {
113 #ifdef GCC34
114         template<> struct hash<in_addr>
115 #else
116         template<> struct nspace::hash<in_addr>
117 #endif
118         {
119                 size_t operator()(const struct in_addr &a) const
120                 {
121                         size_t q;
122                         memcpy(&q,&a,sizeof(size_t));
123                         return q;
124                 }
125         };
126 #ifdef GCC34
127         template<> struct hash<string>
128 #else
129         template<> struct nspace::hash<string>
130 #endif
131         {
132                 size_t operator()(const string &s) const
133                 {
134                         char a[MAXBUF];
135                         static struct hash<const char *> strhash;
136                         strlcpy(a,s.c_str(),MAXBUF);
137                         strlower(a);
138                         return strhash(a);
139                 }
140         };
141 }
142
143 struct StrHashComp
144 {
145
146         bool operator()(const string& s1, const string& s2) const
147         {
148                 char a[MAXBUF],b[MAXBUF];
149                 strlcpy(a,s1.c_str(),MAXBUF);
150                 strlcpy(b,s2.c_str(),MAXBUF);
151                 strlower(a);
152                 strlower(b);
153                 return (strcasecmp(a,b) == 0);
154         }
155
156 };
157
158 struct InAddr_HashComp
159 {
160
161         bool operator()(const in_addr &s1, const in_addr &s2) const
162         {
163                 size_t q;
164                 size_t p;
165                 
166                 memcpy(&q,&s1,sizeof(size_t));
167                 memcpy(&p,&s2,sizeof(size_t));
168                 
169                 return (q == p);
170         }
171
172 };
173
174
175 typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, StrHashComp> user_hash;
176 typedef nspace::hash_map<std::string, chanrec*, nspace::hash<string>, StrHashComp> chan_hash;
177 typedef nspace::hash_map<in_addr,string*, nspace::hash<in_addr>, InAddr_HashComp> address_cache;
178 typedef std::deque<command_t> command_table;
179
180
181 extern user_hash clientlist;
182 extern chan_hash chanlist;
183 extern user_hash whowas;
184 extern command_table cmdlist;
185 extern file_cache MOTD;
186 extern file_cache RULES;
187 extern address_cache IP;
188
189
190 // class type for holding an extended mode character - internal to core
191
192 class ExtMode : public classbase
193 {
194 public:
195         char modechar;
196         int type;
197         int params_when_on;
198         int params_when_off;
199         bool needsoper;
200         bool list;
201         ExtMode(char mc, int ty, bool oper, int p_on, int p_off) : modechar(mc), type(ty), needsoper(oper), params_when_on(p_on), params_when_off(p_off) { };
202 };                                     
203
204 typedef std::vector<ExtMode> ExtModeList;
205 typedef ExtModeList::iterator ExtModeListIter;
206
207
208 ExtModeList EMode;
209
210 // returns true if an extended mode character is in use
211 bool ModeDefined(char modechar, int type)
212 {
213         log(DEBUG,"Size of extmodes vector is %d",EMode.size());
214         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
215         {
216                 if ((i->modechar == modechar) && (i->type == type))
217                 {
218                         return true;
219                 }
220         }
221         return false;
222 }
223
224 bool ModeIsListMode(char modechar, int type)
225 {
226         log(DEBUG,"Size of extmodes vector is %d",EMode.size());
227         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
228         {
229                 if ((i->modechar == modechar) && (i->type == type) && (i->list == true))
230                 {
231                         return true;
232                 }
233         }
234         return false;
235 }
236
237 bool ModeDefinedOper(char modechar, int type)
238 {
239         log(DEBUG,"Size of extmodes vector is %d",EMode.size());
240         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
241         {
242                 if ((i->modechar == modechar) && (i->type == type) && (i->needsoper == true))
243                 {
244                         return true;
245                 }
246         }
247         return false;
248 }
249
250 // returns number of parameters for a custom mode when it is switched on
251 int ModeDefinedOn(char modechar, int type)
252 {
253         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
254         {
255                 if ((i->modechar == modechar) && (i->type == type))
256                 {
257                         return i->params_when_on;
258                 }
259         }
260         return 0;
261 }
262
263 // returns number of parameters for a custom mode when it is switched on
264 int ModeDefinedOff(char modechar, int type)
265 {
266         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
267         {
268                 if ((i->modechar == modechar) && (i->type == type))
269                 {
270                         return i->params_when_off;
271                 }
272         }
273         return 0;
274 }
275
276 // returns true if an extended mode character is in use
277 bool DoAddExtendedMode(char modechar, int type, bool requires_oper, int params_on, int params_off)
278 {
279         if (ModeDefined(modechar,type)) {
280                 return false;
281         }
282         EMode.push_back(ExtMode(modechar,type,requires_oper,params_on,params_off));
283         return true;
284 }
285
286 // turns a mode into a listmode
287 void ModeMakeList(char modechar)
288 {
289         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
290         {
291                 if ((i->modechar == modechar) && (i->type == MT_CHANNEL))
292                 {
293                         i->list = true;
294                         return;
295                 }
296         }
297         return;
298 }
299
300 // version is a simple class for holding a modules version number
301
302 Version::Version(int major, int minor, int revision, int build, int flags) : Major(major), Minor(minor), Revision(revision), Build(build), Flags(flags) { };
303
304 // admin is a simple class for holding a server's administrative info
305
306 Admin::Admin(std::string name, std::string email, std::string nick) : Name(name), Email(email), Nick(nick) { };
307
308 Module::Module() { }
309 Module::~Module() { }
310 void Module::OnUserConnect(userrec* user) { }
311 void Module::OnUserQuit(userrec* user) { }
312 void Module::OnUserDisconnect(userrec* user) { }
313 void Module::OnUserJoin(userrec* user, chanrec* channel) { }
314 void Module::OnUserPart(userrec* user, chanrec* channel) { }
315 void Module::OnPacketTransmit(std::string &data, std::string serv) { }
316 void Module::OnPacketReceive(std::string &data, std::string serv) { }
317 void Module::OnRehash() { }
318 void Module::OnServerRaw(std::string &raw, bool inbound, userrec* user) { }
319 int Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { return 0; }
320 int Module::OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params) { return false; }
321 Version Module::GetVersion() { return Version(1,0,0,0,VF_VENDOR); }
322 void Module::OnOper(userrec* user) { };
323 void Module::OnInfo(userrec* user) { };
324 void Module::OnWhois(userrec* source, userrec* dest) { };
325 int Module::OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel) { return 0; };
326 int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) { return 0; };
327 int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text) { return 0; };
328 int Module::OnUserPreNick(userrec* user, std::string newnick) { return 0; };
329 void Module::OnUserPostNick(userrec* user, std::string oldnick) { };
330 int Module::OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type) { return ACR_DEFAULT; };
331 string_list Module::OnUserSync(userrec* user) { string_list empty; return empty; }
332 string_list Module::OnChannelSync(chanrec* chan) { string_list empty; return empty; }
333 void Module::On005Numeric(std::string &output) { };
334 int Module::OnKill(userrec* source, userrec* dest, std::string reason) { return 0; };
335 void Module::OnLoadModule(Module* mod,std::string name) { };
336 void Module::OnBackgroundTimer(time_t curtime) { };
337 void Module::OnSendList(userrec* user, chanrec* channel, char mode) { };
338 int Module::OnPreCommand(std::string command, char **parameters, int pcnt, userrec *user) { return 0; };
339 bool Module::OnCheckReady(userrec* user) { return true; };
340 void Module::OnUserRegister(userrec* user) { };
341 int Module::OnUserPreKick(userrec* source, userrec* user, chanrec* chan, std::string reason) { return 0; };
342 void Module::OnUserKick(userrec* source, userrec* user, chanrec* chan, std::string reason) { };
343 int Module::OnRawMode(userrec* user, chanrec* chan, char mode, std::string param, bool adding, int pcnt) { return 0; };
344 int Module::OnCheckInvite(userrec* user, chanrec* chan) { return 0; };
345 int Module::OnCheckKey(userrec* user, chanrec* chan, std::string keygiven) { return 0; };
346 int Module::OnCheckLimit(userrec* user, chanrec* chan) { return 0; };
347 int Module::OnCheckBan(userrec* user, chanrec* chan) { return 0; };
348 void Module::OnStats(char symbol) { };
349 int Module::OnChangeLocalUserHost(userrec* user, std::string newhost) { return 0; };
350 int Module::OnChangeLocalUserGECOS(userrec* user, std::string newhost) { return 0; };
351 int Module::OnLocalTopicChange(userrec* user, chanrec* chan, std::string topic) { return 0; };
352 int Module::OnMeshToken(char token,string_list params,serverrec* source,serverrec* reply, std::string tcp_host,std::string ipaddr,int port) { return 0; };
353
354 // server is a wrapper class that provides methods to all of the C-style
355 // exports in the core
356 //
357
358 Server::Server()
359 {
360 }
361
362 Server::~Server()
363 {
364 }
365
366 void Server::SendOpers(std::string s)
367 {
368         WriteOpers("%s",s.c_str());
369 }
370
371 bool Server::MatchText(std::string sliteral, std::string spattern)
372 {
373         char literal[MAXBUF],pattern[MAXBUF];
374         strlcpy(literal,sliteral.c_str(),MAXBUF);
375         strlcpy(pattern,spattern.c_str(),MAXBUF);
376         return match(literal,pattern);
377 }
378
379 void Server::SendToModeMask(std::string modes, int flags, std::string text)
380 {
381         WriteMode(modes.c_str(),flags,"%s",text.c_str());
382 }
383
384 chanrec* Server::JoinUserToChannel(userrec* user, std::string cname, std::string key)
385 {
386         return add_channel(user,cname.c_str(),key.c_str(),true);
387 }
388
389 chanrec* Server::PartUserFromChannel(userrec* user, std::string cname, std::string reason)
390 {
391         return del_channel(user,cname.c_str(),reason.c_str(),false);
392 }
393
394 chanuserlist Server::GetUsers(chanrec* chan)
395 {
396         chanuserlist userl;
397         userl.clear();
398         for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
399         {
400                 if (i->second)
401                 {
402                         if (has_channel(i->second,chan))
403                         {
404                                 if (isnick(i->second->nick))
405                                 {
406                                         userl.push_back(i->second);
407                                 }
408                         }
409                 }
410         }
411         return userl;
412 }
413 void Server::ChangeUserNick(userrec* user, std::string nickname)
414 {
415         force_nickchange(user,nickname.c_str());
416 }
417
418 void Server::QuitUser(userrec* user, std::string reason)
419 {
420         send_network_quit(user->nick,reason.c_str());
421         kill_link(user,reason.c_str());
422 }
423
424 bool Server::IsUlined(std::string server)
425 {
426         return is_uline(server.c_str());
427 }
428
429 void Server::CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user)
430 {
431         call_handler(commandname.c_str(),parameters,pcnt,user);
432 }
433
434 void Server::Log(int level, std::string s)
435 {
436         log(level,"%s",s.c_str());
437 }
438
439 void Server::AddCommand(char* cmd, handlerfunc f, char flags, int minparams, char* source)
440 {
441         createcommand(cmd,f,flags,minparams,source);
442 }
443
444 void Server::SendMode(char **parameters, int pcnt, userrec *user)
445 {
446         server_mode(parameters,pcnt,user);
447 }
448
449 void Server::Send(int Socket, std::string s)
450 {
451         Write(Socket,"%s",s.c_str());
452 }
453
454 void Server::SendServ(int Socket, std::string s)
455 {
456         WriteServ(Socket,"%s",s.c_str());
457 }
458
459 void Server::SendFrom(int Socket, userrec* User, std::string s)
460 {
461         WriteFrom(Socket,User,"%s",s.c_str());
462 }
463
464 void Server::SendTo(userrec* Source, userrec* Dest, std::string s)
465 {
466         if (!Source)
467         {
468                 // if source is NULL, then the message originates from the local server
469                 Write(Dest->fd,":%s %s",this->GetServerName().c_str(),s.c_str());
470         }
471         else
472         {
473                 // otherwise it comes from the user specified
474                 WriteTo(Source,Dest,"%s",s.c_str());
475         }
476 }
477
478 void Server::SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender)
479 {
480         if (IncludeSender)
481         {
482                 WriteChannel(Channel,User,"%s",s.c_str());
483         }
484         else
485         {
486                 ChanExceptSender(Channel,User,"%s",s.c_str());
487         }
488 }
489
490 bool Server::CommonChannels(userrec* u1, userrec* u2)
491 {
492         return (common_channels(u1,u2) != 0);
493 }
494
495 void Server::SendCommon(userrec* User, std::string text,bool IncludeSender)
496 {
497         if (IncludeSender)
498         {
499                 WriteCommon(User,"%s",text.c_str());
500         }
501         else
502         {
503                 WriteCommonExcept(User,"%s",text.c_str());
504         }
505 }
506
507 void Server::SendWallops(userrec* User, std::string text)
508 {
509         WriteWallOps(User,false,"%s",text.c_str());
510 }
511
512 void Server::ChangeHost(userrec* user, std::string host)
513 {
514         ChangeDisplayedHost(user,host.c_str());
515 }
516
517 void Server::ChangeGECOS(userrec* user, std::string gecos)
518 {
519         ChangeName(user,gecos.c_str());
520 }
521
522 bool Server::IsNick(std::string nick)
523 {
524         return (isnick(nick.c_str()) != 0);
525 }
526
527 userrec* Server::FindNick(std::string nick)
528 {
529         return Find(nick);
530 }
531
532 chanrec* Server::FindChannel(std::string channel)
533 {
534         return FindChan(channel.c_str());
535 }
536
537 std::string Server::ChanMode(userrec* User, chanrec* Chan)
538 {
539         return cmode(User,Chan);
540 }
541
542 bool Server::IsOnChannel(userrec* User, chanrec* Chan)
543 {
544         return has_channel(User,Chan);
545 }
546
547 std::string Server::GetServerName()
548 {
549         return getservername();
550 }
551
552 std::string Server::GetNetworkName()
553 {
554         return getnetworkname();
555 }
556
557 Admin Server::GetAdmin()
558 {
559         return Admin(getadminname(),getadminemail(),getadminnick());
560 }
561
562
563
564 bool Server::AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off)
565 {
566         if (type == MT_SERVER)
567         {
568                 log(DEBUG,"*** API ERROR *** Modes of type MT_SERVER are reserved for future expansion");
569                 return false;
570         }
571         if (((params_when_on>0) || (params_when_off>0)) && (type == MT_CLIENT))
572         {
573                 log(DEBUG,"*** API ERROR *** Parameters on MT_CLIENT modes are not supported");
574                 return false;
575         }
576         if ((params_when_on>1) || (params_when_off>1))
577         {
578                 log(DEBUG,"*** API ERROR *** More than one parameter for an MT_CHANNEL mode is not yet supported");
579                 return false;
580         }
581         return DoAddExtendedMode(modechar,type,requires_oper,params_when_on,params_when_off);
582 }
583
584 bool Server::AddExtendedListMode(char modechar)
585 {
586         bool res = DoAddExtendedMode(modechar,MT_CHANNEL,false,1,1);
587         if (res)
588                 ModeMakeList(modechar);
589         return res;
590 }
591
592 int Server::CountUsers(chanrec* c)
593 {
594         return usercount(c);
595 }
596
597
598 bool Server::UserToPseudo(userrec* user,std::string message)
599 {
600         unsigned int old_fd = user->fd;
601         user->fd = FD_MAGIC_NUMBER;
602         Write(old_fd,"ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,message.c_str());
603         close(old_fd);
604         shutdown (old_fd,2);
605 }
606
607 bool Server::PseudoToUser(userrec* alive,userrec* zombie,std::string message)
608 {
609         zombie->fd = alive->fd;
610         alive->fd = FD_MAGIC_NUMBER;
611         Write(zombie->fd,":%s!%s@%s NICK %s",alive->nick,alive->ident,alive->host,zombie->nick);
612         kill_link(alive,message.c_str());
613         for (int i = 0; i != MAXCHANS; i++)
614         {
615                 if (zombie->chans[i].channel != NULL)
616                 {
617                         if (zombie->chans[i].channel->name)
618                         {
619                                 chanrec* Ptr = zombie->chans[i].channel;
620                                 WriteFrom(zombie->fd,zombie,"JOIN %s",Ptr->name);
621                                 if (Ptr->topicset)
622                                 {
623                                         WriteServ(zombie->fd,"332 %s %s :%s", zombie->nick, Ptr->name, Ptr->topic);
624                                         WriteServ(zombie->fd,"333 %s %s %s %d", zombie->nick, Ptr->name, Ptr->setby, Ptr->topicset);
625                                 }
626                                 userlist(zombie,Ptr);
627                                 WriteServ(zombie->fd,"366 %s %s :End of /NAMES list.", zombie->nick, Ptr->name);
628                                 //WriteServ(zombie->fd,"324 %s %s +%s",zombie->nick, Ptr->name,chanmodes(Ptr));
629                                 //WriteServ(zombie->fd,"329 %s %s %d", zombie->nick, Ptr->name, Ptr->created);
630
631                         }
632                 }
633         }
634
635 }
636
637 void Server::AddGLine(long duration, std::string source, std::string reason, std::string hostmask)
638 {
639         add_gline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
640 }
641
642 void Server::AddQLine(long duration, std::string source, std::string reason, std::string nickname)
643 {
644         add_qline(duration, source.c_str(), reason.c_str(), nickname.c_str());
645 }
646
647 void Server::AddZLine(long duration, std::string source, std::string reason, std::string ipaddr)
648 {
649         add_zline(duration, source.c_str(), reason.c_str(), ipaddr.c_str());
650 }
651
652 void Server::AddKLine(long duration, std::string source, std::string reason, std::string hostmask)
653 {
654         add_kline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
655 }
656
657 void Server::AddELine(long duration, std::string source, std::string reason, std::string hostmask)
658 {
659         add_eline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
660 }
661
662 bool Server::DelGLine(std::string hostmask)
663 {
664         del_gline(hostmask.c_str());
665 }
666
667 bool Server::DelQLine(std::string nickname)
668 {
669         del_qline(nickname.c_str());
670 }
671
672 bool Server::DelZLine(std::string ipaddr)
673 {
674         del_zline(ipaddr.c_str());
675 }
676
677 bool Server::DelKLine(std::string hostmask)
678 {
679         del_kline(hostmask.c_str());
680 }
681
682 bool Server::DelELine(std::string hostmask)
683 {
684         del_eline(hostmask.c_str());
685 }
686
687 long Server::CalcDuration(std::string delta)
688 {
689         return duration(delta.c_str());
690 }
691
692 bool Server::IsValidMask(std::string mask)
693 {
694         const char* dest = mask.c_str();
695         if (strchr(dest,'!')==0)
696                 return false;
697         if (strchr(dest,'@')==0)
698                 return false;
699         for (int i = 0; i < strlen(dest); i++)
700                 if (dest[i] < 32)
701                         return false;
702         for (int i = 0; i < strlen(dest); i++)
703                 if (dest[i] > 126)
704                         return false;
705         int c = 0;
706         for (int i = 0; i < strlen(dest); i++)
707                 if (dest[i] == '!')
708                         c++;
709         if (c>1)
710                 return false;
711         c = 0;
712         for (int i = 0; i < strlen(dest); i++)
713                 if (dest[i] == '@')
714                         c++;
715         if (c>1)
716                 return false;
717
718         return true;
719 }
720
721 void Server::MeshSendAll(std::string text)
722 {
723         NetSendToAll((char*)text.c_str());
724 }
725
726 void Server::MeshSendCommon(userrec* user, std::string text)
727 {
728         if (user)
729                 NetSendToCommon(user,(char*)text.c_str());
730 }
731
732 void Server::MeshSendAllAlive(std::string text)
733 {
734         NetSendToAllAlive((char*)text.c_str());
735 }
736
737 void Server::MeshSendUnicast(std::string destination, std::string text)
738 {
739         NetSendToOne((char*)destination.c_str(),(char*)text.c_str());
740 }
741
742 void Server::MeshSendAllExcept(std::string target, std::string text)
743 {
744         NetSendToAllExcept(target.c_str(),(char*)text.c_str());
745 }
746
747 bool Server::MeshCheckChan(chanrec *c,std::string servername)
748 {
749         if (c)
750         {
751                 return ChanAnyOnThisServer(c,(char*)servername.c_str());
752         }
753         else return false;
754 }
755
756 bool Server::MeshCheckCommon(userrec* u,std::string servername)
757 {
758         if (u)
759         {
760                 return CommonOnThisServer(u,(char*)servername.c_str());
761         }
762         else return false;
763 }
764
765 ConfigReader::ConfigReader()
766 {
767         this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
768         this->errorlog = new std::stringstream(std::stringstream::in | std::stringstream::out);
769         this->readerror = LoadConf(CONFIG_FILE,this->cache,this->errorlog);
770         if (!this->readerror)
771                 this->error = CONF_FILE_NOT_FOUND;
772 }
773
774
775 ConfigReader::~ConfigReader()
776 {
777         if (this->cache)
778                 delete this->cache;
779         if (this->errorlog)
780                 delete this->errorlog;
781 }
782
783
784 ConfigReader::ConfigReader(std::string filename)
785 {
786         this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
787         this->errorlog = new std::stringstream(std::stringstream::in | std::stringstream::out);
788         this->readerror = LoadConf(filename.c_str(),this->cache,this->errorlog);
789         if (!this->readerror)
790                 this->error = CONF_FILE_NOT_FOUND;
791 };
792
793 std::string ConfigReader::ReadValue(std::string tag, std::string name, int index)
794 {
795         char val[MAXBUF];
796         char t[MAXBUF];
797         char n[MAXBUF];
798         strlcpy(t,tag.c_str(),MAXBUF);
799         strlcpy(n,name.c_str(),MAXBUF);
800         int res = ReadConf(cache,t,n,index,val);
801         if (!res)
802         {
803                 this->error = CONF_VALUE_NOT_FOUND;
804                 return "";
805         }
806         return std::string(val);
807 }
808
809 bool ConfigReader::ReadFlag(std::string tag, std::string name, int index)
810 {
811         char val[MAXBUF];
812         char t[MAXBUF];
813         char n[MAXBUF];
814         strlcpy(t,tag.c_str(),MAXBUF);
815         strlcpy(n,name.c_str(),MAXBUF);
816         int res = ReadConf(cache,t,n,index,val);
817         if (!res)
818         {
819                 this->error = CONF_VALUE_NOT_FOUND;
820                 return false;
821         }
822         std::string s = val;
823         return ((s == "yes") || (s == "YES") || (s == "true") || (s == "TRUE") || (s == "1"));
824 }
825
826 long ConfigReader::ReadInteger(std::string tag, std::string name, int index, bool needs_unsigned)
827 {
828         char val[MAXBUF];
829         char t[MAXBUF];
830         char n[MAXBUF];
831         strlcpy(t,tag.c_str(),MAXBUF);
832         strlcpy(n,name.c_str(),MAXBUF);
833         int res = ReadConf(cache,t,n,index,val);
834         if (!res)
835         {
836                 this->error = CONF_VALUE_NOT_FOUND;
837                 return 0;
838         }
839         for (int i = 0; i < strlen(val); i++)
840         {
841                 if (!isdigit(val[i]))
842                 {
843                         this->error = CONF_NOT_A_NUMBER;
844                         return 0;
845                 }
846         }
847         if ((needs_unsigned) && (atoi(val)<0))
848         {
849                 this->error = CONF_NOT_UNSIGNED;
850                 return 0;
851         }
852         return atoi(val);
853 }
854
855 long ConfigReader::GetError()
856 {
857         long olderr = this->error;
858         this->error = 0;
859         return olderr;
860 }
861
862 void ConfigReader::DumpErrors(bool bail, userrec* user)
863 {
864         if (bail)
865         {
866                 printf("There were errors in your configuration:\n%s",errorlog->str().c_str());
867                 exit(0);
868         }
869         else
870         {
871                 char dataline[1024];
872                 if (user)
873                 {
874                         WriteServ(user->fd,"NOTICE %s :There were errors in the configuration file:",user->nick);
875                         while (!errorlog->eof())
876                         {
877                                 errorlog->getline(dataline,1024);
878                                 WriteServ(user->fd,"NOTICE %s :%s",user->nick,dataline);
879                         }
880                 }
881                 else
882                 {
883                         WriteOpers("There were errors in the configuration file:",user->nick);
884                         while (!errorlog->eof())
885                         {
886                                 errorlog->getline(dataline,1024);
887                                 WriteOpers(dataline);
888                         }
889                 }
890                 return;
891         }
892 }
893
894
895 int ConfigReader::Enumerate(std::string tag)
896 {
897         return EnumConf(cache,tag.c_str());
898 }
899
900 int ConfigReader::EnumerateValues(std::string tag, int index)
901 {
902         return EnumValues(cache, tag.c_str(), index);
903 }
904
905 bool ConfigReader::Verify()
906 {
907         return this->readerror;
908 }
909
910
911 FileReader::FileReader(std::string filename)
912 {
913         file_cache c;
914         readfile(c,filename.c_str());
915         this->fc = c;
916 }
917
918 FileReader::FileReader()
919 {
920 }
921
922 void FileReader::LoadFile(std::string filename)
923 {
924         file_cache c;
925         readfile(c,filename.c_str());
926         this->fc = c;
927 }
928
929
930 FileReader::~FileReader()
931 {
932 }
933
934 bool FileReader::Exists()
935 {
936         if (fc.size() == 0)
937         {
938                 return(false);
939         }
940         else
941         {
942                 return(true);
943         }
944 }
945
946 std::string FileReader::GetLine(int x)
947 {
948         if ((x<0) || (x>fc.size()))
949                 return "";
950         return fc[x];
951 }
952
953 int FileReader::FileSize()
954 {
955         return fc.size();
956 }
957
958
959 std::vector<Module*> modules(255);
960 std::vector<ircd_module*> factory(255);
961
962 int MODCOUNT  = -1;
963
964