13 #include "inspircd_io.h"
16 // class type for holding an extended mode character - internal to core
26 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) { };
29 typedef std::vector<ExtMode> ExtModeList;
30 typedef ExtModeList::iterator ExtModeListIter;
34 // returns true if an extended mode character is in use
35 bool ModeDefined(char modechar, int type)
37 log(DEBUG,"Size of extmodes vector is %d",EMode.size());
38 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
40 log(DEBUG,"i->modechar==%c, modechar=%c, i->type=%d, type=%d",i->modechar,modechar,i->type,type);
41 if ((i->modechar == modechar) && (i->type == type))
49 bool ModeDefinedOper(char modechar, int type)
51 log(DEBUG,"Size of extmodes vector is %d",EMode.size());
52 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
54 log(DEBUG,"i->modechar==%c, modechar=%c, i->type=%d, type=%d",i->modechar,modechar,i->type,type);
55 if ((i->modechar == modechar) && (i->type == type) && (i->needsoper == true))
63 // returns number of parameters for a custom mode when it is switched on
64 int ModeDefinedOn(char modechar, int type)
66 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
68 if ((i->modechar == modechar) && (i->type == type))
70 return i->params_when_on;
76 // returns number of parameters for a custom mode when it is switched on
77 int ModeDefinedOff(char modechar, int type)
79 for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
81 if ((i->modechar == modechar) && (i->type == type))
83 return i->params_when_off;
89 // returns true if an extended mode character is in use
90 bool DoAddExtendedMode(char modechar, int type, bool requires_oper, int params_on, int params_off)
92 if (ModeDefined(modechar,type)) {
95 EMode.push_back(ExtMode(modechar,type,requires_oper,params_on,params_off));
100 // version is a simple class for holding a modules version number
102 Version::Version(int major, int minor, int revision, int build) : Major(major), Minor(minor), Revision(revision), Build(build) { };
104 // admin is a simple class for holding a server's administrative info
106 Admin::Admin(std::string name, std::string email, std::string nick) : Name(name), Email(email), Nick(nick) { };
109 Module::~Module() { }
110 void Module::OnUserConnect(userrec* user) { }
111 void Module::OnUserQuit(userrec* user) { }
112 void Module::OnUserJoin(userrec* user, chanrec* channel) { }
113 void Module::OnUserPart(userrec* user, chanrec* channel) { }
114 void Module::OnPacketTransmit(char *p) { }
115 void Module::OnPacketReceive(char *p) { }
116 void Module::OnRehash() { }
117 void Module::OnServerRaw(std::string &raw, bool inbound) { }
118 int Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { return 0; }
119 bool Module::OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) { }
120 Version Module::GetVersion() { return Version(1,0,0,0); }
121 void Module::OnOper(userrec* user) { };
122 void Module::OnInfo(userrec* user) { };
123 void Module::OnWhois(userrec* source, userrec* dest) { };
124 int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string text) { return 0; };
125 int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string text) { return 0; };
127 // server is a wrapper class that provides methods to all of the C-style
128 // exports in the core
139 void Server::SendOpers(std::string s)
141 WriteOpers("%s",s.c_str());
144 bool Server::MatchText(std::string sliteral, std::string spattern)
146 char literal[MAXBUF],pattern[MAXBUF];
147 strncpy(literal,sliteral.c_str(),MAXBUF);
148 strncpy(pattern,spattern.c_str(),MAXBUF);
149 return match(literal,pattern);
152 void Server::SendToModeMask(std::string modes, int flags, std::string text)
154 WriteMode(modes.c_str(),flags,"%s",text.c_str());
157 chanrec* Server::JoinUserToChannel(userrec* user, std::string cname, std::string key)
159 return add_channel(user,cname.c_str(),key.c_str());
162 chanrec* Server::PartUserFromChannel(userrec* user, std::string cname, std::string reason)
164 return del_channel(user,cname.c_str(),reason.c_str());
167 void Server::ChangeUserNick(userrec* user, std::string nickname)
169 force_nickchange(user,nickname.c_str());
172 void Server::QuitUser(userrec* user, std::string reason)
174 kill_link(user,reason.c_str());
178 void Server::Log(int level, std::string s)
180 log(level,"%s",s.c_str());
183 void Server::AddCommand(char* cmd, handlerfunc f, char flags, int minparams)
185 createcommand(cmd,f,flags,minparams);
188 void Server::SendMode(char **parameters, int pcnt, userrec *user)
190 server_mode(parameters,pcnt,user);
193 void Server::Send(int Socket, std::string s)
195 Write(Socket,"%s",s.c_str());
198 void Server::SendServ(int Socket, std::string s)
200 WriteServ(Socket,"%s",s.c_str());
203 void Server::SendFrom(int Socket, userrec* User, std::string s)
205 WriteFrom(Socket,User,"%s",s.c_str());
208 void Server::SendTo(userrec* Source, userrec* Dest, std::string s)
212 // if source is NULL, then the message originates from the local server
213 Write(Dest->fd,":%s %s",this->GetServerName().c_str(),s.c_str());
217 // otherwise it comes from the user specified
218 WriteTo(Source,Dest,"%s",s.c_str());
222 void Server::SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender)
226 WriteChannel(Channel,User,"%s",s.c_str());
230 ChanExceptSender(Channel,User,"%s",s.c_str());
234 bool Server::CommonChannels(userrec* u1, userrec* u2)
236 return (common_channels(u1,u2) != 0);
239 void Server::SendCommon(userrec* User, std::string text,bool IncludeSender)
243 WriteCommon(User,"%s",text.c_str());
247 WriteCommonExcept(User,"%s",text.c_str());
251 void Server::SendWallops(userrec* User, std::string text)
253 WriteWallOps(User,"%s",text.c_str());
256 bool Server::IsNick(std::string nick)
258 return (isnick(nick.c_str()) != 0);
261 userrec* Server::FindNick(std::string nick)
266 chanrec* Server::FindChannel(std::string channel)
268 return FindChan(channel.c_str());
271 std::string Server::ChanMode(userrec* User, chanrec* Chan)
273 return cmode(User,Chan);
276 std::string Server::GetServerName()
278 return getservername();
281 std::string Server::GetNetworkName()
283 return getnetworkname();
286 Admin Server::GetAdmin()
288 return Admin(getadminname(),getadminemail(),getadminnick());
293 bool Server::AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off)
295 if (type == MT_SERVER)
297 log(DEBUG,"*** API ERROR *** Modes of type MT_SERVER are reserved for future expansion");
300 if (((params_when_on>0) || (params_when_off>0)) && (type == MT_CLIENT))
302 log(DEBUG,"*** API ERROR *** Parameters on MT_CLIENT modes are not supported");
305 if ((params_when_on>1) || (params_when_off>1))
307 log(DEBUG,"*** API ERROR *** More than one parameter for an MT_CHANNEL mode is not yet supported");
310 return DoAddExtendedMode(modechar,type,requires_oper,params_when_on,params_when_off);
314 ConfigReader::ConfigReader()
316 this->cache = new std::stringstream(stringstream::in | stringstream::out);
317 LoadConf(CONFIG_FILE,this->cache);
321 ConfigReader::~ConfigReader()
328 ConfigReader::ConfigReader(std::string filename)
330 this->cache = new std::stringstream(stringstream::in | stringstream::out);
331 LoadConf(filename.c_str(),this->cache);
334 std::string ConfigReader::ReadValue(std::string tag, std::string name, int index)
337 ReadConf(cache,tag.c_str(),name.c_str(),index,val);
342 int ConfigReader::Enumerate(std::string tag)
344 return EnumConf(cache,tag.c_str());
348 bool ConfigReader::Verify()
354 FileReader::FileReader(std::string filename)
357 readfile(c,filename.c_str());
361 FileReader::FileReader()
365 void FileReader::LoadFile(std::string filename)
368 readfile(c,filename.c_str());
373 FileReader::~FileReader()
377 bool FileReader::Exists()
389 std::string FileReader::GetLine(int x)
391 if ((x<0) || (x>fc.size()))
396 int FileReader::FileSize()
402 std::vector<Module*> modules(255);
403 std::vector<ircd_module*> factory(255);