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, 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); }
121 // server is a wrapper class that provides methods to all of the C-style
122 // exports in the core
133 void Server::SendOpers(std::string s)
135 WriteOpers("%s",s.c_str());
138 void Server::Log(int level, std::string s)
140 log(level,"%s",s.c_str());
143 void Server::AddCommand(char* cmd, handlerfunc f, char flags, int minparams)
145 createcommand(cmd,f,flags,minparams);
148 void Server::SendMode(char **parameters, int pcnt, userrec *user)
150 server_mode(parameters,pcnt,user);
153 void Server::Send(int Socket, std::string s)
155 Write(Socket,"%s",s.c_str());
158 void Server::SendServ(int Socket, std::string s)
160 WriteServ(Socket,"%s",s.c_str());
163 void Server::SendFrom(int Socket, userrec* User, std::string s)
165 WriteFrom(Socket,User,"%s",s.c_str());
168 void Server::SendTo(userrec* Source, userrec* Dest, std::string s)
170 WriteTo(Source,Dest,"%s",s.c_str());
173 void Server::SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender)
177 WriteChannel(Channel,User,"%s",s.c_str());
181 ChanExceptSender(Channel,User,"%s",s.c_str());
185 bool Server::CommonChannels(userrec* u1, userrec* u2)
187 return (common_channels(u1,u2) != 0);
190 void Server::SendCommon(userrec* User, std::string text,bool IncludeSender)
194 WriteCommon(User,"%s",text.c_str());
198 WriteCommonExcept(User,"%s",text.c_str());
202 void Server::SendWallops(userrec* User, std::string text)
204 WriteWallOps(User,"%s",text.c_str());
207 bool Server::IsNick(std::string nick)
209 return (isnick(nick.c_str()) != 0);
212 userrec* Server::FindNick(std::string nick)
217 chanrec* Server::FindChannel(std::string channel)
219 return FindChan(channel.c_str());
222 std::string Server::ChanMode(userrec* User, chanrec* Chan)
224 return cmode(User,Chan);
227 std::string Server::GetServerName()
229 return getservername();
232 std::string Server::GetNetworkName()
234 return getnetworkname();
237 Admin Server::GetAdmin()
239 return Admin(getadminname(),getadminemail(),getadminnick());
244 bool Server::AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off)
246 if (type == MT_SERVER)
248 log(DEBUG,"*** API ERROR *** Modes of type MT_SERVER are reserved for future expansion");
251 if (((params_when_on>0) || (params_when_off>0)) && (type == MT_CLIENT))
253 log(DEBUG,"*** API ERROR *** Parameters on MT_CLIENT modes are not supported");
256 if ((params_when_on>1) || (params_when_off>1))
258 log(DEBUG,"*** API ERROR *** More than one parameter for an MT_CHANNEL mode is not yet supported");
261 return DoAddExtendedMode(modechar,type,requires_oper,params_when_on,params_when_off);
265 ConfigReader::ConfigReader()
271 ConfigReader::~ConfigReader()
276 ConfigReader::ConfigReader(std::string filename) : fname(filename) { };
278 std::string ConfigReader::ReadValue(std::string tag, std::string name, int index)
281 ReadConf(fname.c_str(),tag.c_str(),name.c_str(),index,val);
286 int ConfigReader::Enumerate(std::string tag)
288 return EnumConf(fname.c_str(),tag.c_str());
292 bool ConfigReader::Verify()
298 FileReader::FileReader(std::string filename)
301 readfile(c,filename.c_str());
305 FileReader::FileReader()
309 void FileReader::LoadFile(std::string filename)
312 readfile(c,filename.c_str());
317 FileReader::~FileReader()
321 bool FileReader::Exists()
333 std::string FileReader::GetLine(int x)
335 if ((x<0) || (x>fc.size()))
340 int FileReader::FileSize()
346 std::vector<Module*> modules(255);
347 std::vector<ircd_module*> factory(255);