13 #include "inspircd_io.h"
15 // class type for holding an extended mode character - internal to core
25 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) { };
28 typedef std::vector<ExtMode> ExtModeList;
29 typedef ExtModeList::iterator ExtModeListIter;
33 // returns true if an extended mode character is in use
34 bool ModeDefined(char modechar, int type)
36 log(DEBUG,"Size of extmodes vector is %d",EMode.size());
37 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
39 log(DEBUG,"i->modechar==%c, modechar=%c, i->type=%d, type=%d",i->modechar,modechar,i->type,type);
40 if ((i->modechar == modechar) && (i->type == type))
48 bool ModeDefinedOper(char modechar, int type)
50 log(DEBUG,"Size of extmodes vector is %d",EMode.size());
51 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
53 log(DEBUG,"i->modechar==%c, modechar=%c, i->type=%d, type=%d",i->modechar,modechar,i->type,type);
54 if ((i->modechar == modechar) && (i->type == type) && (i->needsoper == true))
62 // returns number of parameters for a custom mode when it is switched on
63 int ModeDefinedOn(char modechar, int type)
65 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
67 if ((i->modechar == modechar) && (i->type == type))
69 return i->params_when_on;
75 // returns number of parameters for a custom mode when it is switched on
76 int ModeDefinedOff(char modechar, int type)
78 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
80 if ((i->modechar == modechar) && (i->type == type))
82 return i->params_when_off;
88 // returns true if an extended mode character is in use
89 bool DoAddExtendedMode(char modechar, int type, bool requires_oper, int params_on, int params_off)
91 if (ModeDefined(modechar,type)) {
94 EMode.push_back(ExtMode(modechar,type,requires_oper,params_on,params_off));
99 // version is a simple class for holding a modules version number
101 Version::Version(int major, int minor, int revision, int build) : Major(major), Minor(minor), Revision(revision), Build(build) { };
103 // admin is a simple class for holding a server's administrative info
105 Admin::Admin(std::string name, std::string email, std::string nick) : Name(name), Email(email), Nick(nick) { };
108 Module::~Module() { }
109 void Module::OnUserConnect(userrec* user) { }
110 void Module::OnUserQuit(userrec* user) { }
111 void Module::OnUserJoin(userrec* user, chanrec* channel) { }
112 void Module::OnUserPart(userrec* user, chanrec* channel) { }
113 void Module::OnPacketTransmit(char *p) { }
114 void Module::OnPacketReceive(char *p) { }
115 void Module::OnRehash() { }
116 void Module::OnServerRaw(std::string &raw, bool inbound) { }
117 int Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { return 0; }
118 bool Module::OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) { }
119 Version Module::GetVersion() { return Version(1,0,0,0); }
120 void Module::OnOper(userrec* user) { };
121 void Module::OnInfo(userrec* user) { };
122 void Module::OnWhois(userrec* source, userrec* dest) { };
123 int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string text) { return 0; };
124 int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string text) { return 0; };
126 // server is a wrapper class that provides methods to all of the C-style
127 // exports in the core
138 void Server::SendOpers(std::string s)
140 WriteOpers("%s",s.c_str());
143 void Server::SendToModeMask(std::string modes, int flags, std::string text)
145 WriteMode(modes.c_str(),flags,"%s",text.c_str());
148 chanrec* Server::JoinUserToChannel(userrec* user, std::string cname, std::string key)
150 return add_channel(user,cname.c_str(),key.c_str());
153 chanrec* Server::PartUserFromChannel(userrec* user, std::string cname, std::string reason)
155 return del_channel(user,cname.c_str(),reason.c_str());
158 void Server::ChangeUserNick(userrec* user, std::string nickname)
160 force_nickchange(user,nickname.c_str());
163 void Server::QuitUser(userrec* user, std::string reason)
165 kill_link(user,reason.c_str());
169 void Server::Log(int level, std::string s)
171 log(level,"%s",s.c_str());
174 void Server::AddCommand(char* cmd, handlerfunc f, char flags, int minparams)
176 createcommand(cmd,f,flags,minparams);
179 void Server::SendMode(char **parameters, int pcnt, userrec *user)
181 server_mode(parameters,pcnt,user);
184 void Server::Send(int Socket, std::string s)
186 Write(Socket,"%s",s.c_str());
189 void Server::SendServ(int Socket, std::string s)
191 WriteServ(Socket,"%s",s.c_str());
194 void Server::SendFrom(int Socket, userrec* User, std::string s)
196 WriteFrom(Socket,User,"%s",s.c_str());
199 void Server::SendTo(userrec* Source, userrec* Dest, std::string s)
201 WriteTo(Source,Dest,"%s",s.c_str());
204 void Server::SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender)
208 WriteChannel(Channel,User,"%s",s.c_str());
212 ChanExceptSender(Channel,User,"%s",s.c_str());
216 bool Server::CommonChannels(userrec* u1, userrec* u2)
218 return (common_channels(u1,u2) != 0);
221 void Server::SendCommon(userrec* User, std::string text,bool IncludeSender)
225 WriteCommon(User,"%s",text.c_str());
229 WriteCommonExcept(User,"%s",text.c_str());
233 void Server::SendWallops(userrec* User, std::string text)
235 WriteWallOps(User,"%s",text.c_str());
238 bool Server::IsNick(std::string nick)
240 return (isnick(nick.c_str()) != 0);
243 userrec* Server::FindNick(std::string nick)
248 chanrec* Server::FindChannel(std::string channel)
250 return FindChan(channel.c_str());
253 std::string Server::ChanMode(userrec* User, chanrec* Chan)
255 return cmode(User,Chan);
258 std::string Server::GetServerName()
260 return getservername();
263 std::string Server::GetNetworkName()
265 return getnetworkname();
268 Admin Server::GetAdmin()
270 return Admin(getadminname(),getadminemail(),getadminnick());
275 bool Server::AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off)
277 if (type == MT_SERVER)
279 log(DEBUG,"*** API ERROR *** Modes of type MT_SERVER are reserved for future expansion");
282 if (((params_when_on>0) || (params_when_off>0)) && (type == MT_CLIENT))
284 log(DEBUG,"*** API ERROR *** Parameters on MT_CLIENT modes are not supported");
287 if ((params_when_on>1) || (params_when_off>1))
289 log(DEBUG,"*** API ERROR *** More than one parameter for an MT_CHANNEL mode is not yet supported");
292 return DoAddExtendedMode(modechar,type,requires_oper,params_when_on,params_when_off);
296 ConfigReader::ConfigReader()
302 ConfigReader::~ConfigReader()
307 ConfigReader::ConfigReader(std::string filename) : fname(filename) { };
309 std::string ConfigReader::ReadValue(std::string tag, std::string name, int index)
312 ReadConf(fname.c_str(),tag.c_str(),name.c_str(),index,val);
317 int ConfigReader::Enumerate(std::string tag)
319 return EnumConf(fname.c_str(),tag.c_str());
323 bool ConfigReader::Verify()
329 FileReader::FileReader(std::string filename)
332 readfile(c,filename.c_str());
336 FileReader::FileReader()
340 void FileReader::LoadFile(std::string filename)
343 readfile(c,filename.c_str());
348 FileReader::~FileReader()
352 bool FileReader::Exists()
364 std::string FileReader::GetLine(int x)
366 if ((x<0) || (x>fc.size()))
371 int FileReader::FileSize()
377 std::vector<Module*> modules(255);
378 std::vector<ircd_module*> factory(255);