13 #include "inspircd_io.h"
19 // class type for holding an extended mode character - internal to core
21 class ExtMode : public classbase
29 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) { };
32 typedef std::vector<ExtMode> ExtModeList;
33 typedef ExtModeList::iterator ExtModeListIter;
37 // returns true if an extended mode character is in use
38 bool ModeDefined(char modechar, int type)
40 log(DEBUG,"Size of extmodes vector is %d",EMode.size());
41 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
43 log(DEBUG,"i->modechar==%c, modechar=%c, i->type=%d, type=%d",i->modechar,modechar,i->type,type);
44 if ((i->modechar == modechar) && (i->type == type))
52 bool ModeDefinedOper(char modechar, int type)
54 log(DEBUG,"Size of extmodes vector is %d",EMode.size());
55 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
57 log(DEBUG,"i->modechar==%c, modechar=%c, i->type=%d, type=%d",i->modechar,modechar,i->type,type);
58 if ((i->modechar == modechar) && (i->type == type) && (i->needsoper == true))
66 // returns number of parameters for a custom mode when it is switched on
67 int ModeDefinedOn(char modechar, int type)
69 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
71 if ((i->modechar == modechar) && (i->type == type))
73 return i->params_when_on;
79 // returns number of parameters for a custom mode when it is switched on
80 int ModeDefinedOff(char modechar, int type)
82 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
84 if ((i->modechar == modechar) && (i->type == type))
86 return i->params_when_off;
92 // returns true if an extended mode character is in use
93 bool DoAddExtendedMode(char modechar, int type, bool requires_oper, int params_on, int params_off)
95 if (ModeDefined(modechar,type)) {
98 EMode.push_back(ExtMode(modechar,type,requires_oper,params_on,params_off));
103 // version is a simple class for holding a modules version number
105 Version::Version(int major, int minor, int revision, int build) : Major(major), Minor(minor), Revision(revision), Build(build) { };
107 // admin is a simple class for holding a server's administrative info
109 Admin::Admin(std::string name, std::string email, std::string nick) : Name(name), Email(email), Nick(nick) { };
112 Module::~Module() { }
113 void Module::OnUserConnect(userrec* user) { }
114 void Module::OnUserQuit(userrec* user) { }
115 void Module::OnUserJoin(userrec* user, chanrec* channel) { }
116 void Module::OnUserPart(userrec* user, chanrec* channel) { }
117 void Module::OnPacketTransmit(char *p) { }
118 void Module::OnPacketReceive(char *p) { }
119 void Module::OnRehash() { }
120 void Module::OnServerRaw(std::string &raw, bool inbound) { }
121 int Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { return 0; }
122 bool Module::OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) { return false; }
123 Version Module::GetVersion() { return Version(1,0,0,0); }
124 void Module::OnOper(userrec* user) { };
125 void Module::OnInfo(userrec* user) { };
126 void Module::OnWhois(userrec* source, userrec* dest) { };
127 int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string text) { return 0; };
128 int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string text) { return 0; };
129 int Module::OnUserPreNick(userrec* user, std::string newnick) { return 0; };
131 // server is a wrapper class that provides methods to all of the C-style
132 // exports in the core
143 void Server::SendOpers(std::string s)
145 WriteOpers("%s",s.c_str());
148 bool Server::MatchText(std::string sliteral, std::string spattern)
150 char literal[MAXBUF],pattern[MAXBUF];
151 strncpy(literal,sliteral.c_str(),MAXBUF);
152 strncpy(pattern,spattern.c_str(),MAXBUF);
153 return match(literal,pattern);
156 void Server::SendToModeMask(std::string modes, int flags, std::string text)
158 WriteMode(modes.c_str(),flags,"%s",text.c_str());
161 chanrec* Server::JoinUserToChannel(userrec* user, std::string cname, std::string key)
163 return add_channel(user,cname.c_str(),key.c_str(),true);
166 chanrec* Server::PartUserFromChannel(userrec* user, std::string cname, std::string reason)
168 return del_channel(user,cname.c_str(),reason.c_str(),false);
171 void Server::ChangeUserNick(userrec* user, std::string nickname)
173 force_nickchange(user,nickname.c_str());
176 void Server::QuitUser(userrec* user, std::string reason)
178 send_network_quit(user->nick,reason.c_str());
179 kill_link(user,reason.c_str());
182 bool Server::IsUlined(std::string server)
184 return is_uline(server.c_str());
187 void Server::CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user)
189 call_handler(commandname.c_str(),parameters,pcnt,user);
192 void Server::Log(int level, std::string s)
194 log(level,"%s",s.c_str());
197 void Server::AddCommand(char* cmd, handlerfunc f, char flags, int minparams)
199 createcommand(cmd,f,flags,minparams);
202 void Server::SendMode(char **parameters, int pcnt, userrec *user)
204 server_mode(parameters,pcnt,user);
207 void Server::Send(int Socket, std::string s)
209 Write(Socket,"%s",s.c_str());
212 void Server::SendServ(int Socket, std::string s)
214 WriteServ(Socket,"%s",s.c_str());
217 void Server::SendFrom(int Socket, userrec* User, std::string s)
219 WriteFrom(Socket,User,"%s",s.c_str());
222 void Server::SendTo(userrec* Source, userrec* Dest, std::string s)
226 // if source is NULL, then the message originates from the local server
227 Write(Dest->fd,":%s %s",this->GetServerName().c_str(),s.c_str());
231 // otherwise it comes from the user specified
232 WriteTo(Source,Dest,"%s",s.c_str());
236 void Server::SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender)
240 WriteChannel(Channel,User,"%s",s.c_str());
244 ChanExceptSender(Channel,User,"%s",s.c_str());
248 bool Server::CommonChannels(userrec* u1, userrec* u2)
250 return (common_channels(u1,u2) != 0);
253 void Server::SendCommon(userrec* User, std::string text,bool IncludeSender)
257 WriteCommon(User,"%s",text.c_str());
261 WriteCommonExcept(User,"%s",text.c_str());
265 void Server::SendWallops(userrec* User, std::string text)
267 WriteWallOps(User,false,"%s",text.c_str());
270 void Server::ChangeHost(userrec* user, std::string host)
272 ChangeDisplayedHost(user,host.c_str());
275 void Server::ChangeGECOS(userrec* user, std::string gecos)
277 ChangeName(user,gecos.c_str());
280 bool Server::IsNick(std::string nick)
282 return (isnick(nick.c_str()) != 0);
285 userrec* Server::FindNick(std::string nick)
290 chanrec* Server::FindChannel(std::string channel)
292 return FindChan(channel.c_str());
295 std::string Server::ChanMode(userrec* User, chanrec* Chan)
297 return cmode(User,Chan);
300 std::string Server::GetServerName()
302 return getservername();
305 std::string Server::GetNetworkName()
307 return getnetworkname();
310 Admin Server::GetAdmin()
312 return Admin(getadminname(),getadminemail(),getadminnick());
317 bool Server::AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off)
319 if (type == MT_SERVER)
321 log(DEBUG,"*** API ERROR *** Modes of type MT_SERVER are reserved for future expansion");
324 if (((params_when_on>0) || (params_when_off>0)) && (type == MT_CLIENT))
326 log(DEBUG,"*** API ERROR *** Parameters on MT_CLIENT modes are not supported");
329 if ((params_when_on>1) || (params_when_off>1))
331 log(DEBUG,"*** API ERROR *** More than one parameter for an MT_CHANNEL mode is not yet supported");
334 return DoAddExtendedMode(modechar,type,requires_oper,params_when_on,params_when_off);
337 int Server::CountUsers(chanrec* c)
343 ConfigReader::ConfigReader()
345 this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
346 this->error = LoadConf(CONFIG_FILE,this->cache);
350 ConfigReader::~ConfigReader()
357 ConfigReader::ConfigReader(std::string filename)
359 this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
360 this->error = LoadConf(filename.c_str(),this->cache);
363 std::string ConfigReader::ReadValue(std::string tag, std::string name, int index)
368 strncpy(t,tag.c_str(),MAXBUF);
369 strncpy(n,name.c_str(),MAXBUF);
370 ReadConf(cache,t,n,index,val);
371 return std::string(val);
375 int ConfigReader::Enumerate(std::string tag)
377 return EnumConf(cache,tag.c_str());
380 int ConfigReader::EnumerateValues(std::string tag, int index)
382 return EnumValues(cache, tag.c_str(), index);
385 bool ConfigReader::Verify()
391 FileReader::FileReader(std::string filename)
394 readfile(c,filename.c_str());
398 FileReader::FileReader()
402 void FileReader::LoadFile(std::string filename)
405 readfile(c,filename.c_str());
410 FileReader::~FileReader()
414 bool FileReader::Exists()
426 std::string FileReader::GetLine(int x)
428 if ((x<0) || (x>fc.size()))
433 int FileReader::FileSize()
439 std::vector<Module*> modules(255);
440 std::vector<ircd_module*> factory(255);