Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

modules.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 
00004 */
00005 
00006 
00007 
00008 #include <typeinfo>
00009 #include <iostream>
00010 #include "globals.h"
00011 #include "modules.h"
00012 #include "ctables.h"
00013 #include "inspircd_io.h"
00014 #include "wildcard.h"
00015 #include "mode.h"
00016 #include "message.h"
00017 #include "commands.h"
00018 
00019 // class type for holding an extended mode character - internal to core
00020 
00021 class ExtMode : public classbase
00022 {
00023 public:
00024         char modechar;
00025         int type;
00026         int params_when_on;
00027         int params_when_off;
00028         bool needsoper;
00029         bool list;
00030         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) { };
00031 };                                     
00032 
00033 typedef std::vector<ExtMode> ExtModeList;
00034 typedef ExtModeList::iterator ExtModeListIter;
00035 
00036 ExtModeList EMode;
00037 
00038 // returns true if an extended mode character is in use
00039 bool ModeDefined(char modechar, int type)
00040 {
00041         log(DEBUG,"Size of extmodes vector is %d",EMode.size());
00042         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
00043         {
00044                 log(DEBUG,"i->modechar==%c, modechar=%c, i->type=%d, type=%d",i->modechar,modechar,i->type,type);
00045                 if ((i->modechar == modechar) && (i->type == type))
00046                 {
00047                         return true;
00048                 }
00049         }
00050         return false;
00051 }
00052 
00053 bool ModeIsListMode(char modechar, int type)
00054 {
00055         log(DEBUG,"Size of extmodes vector is %d",EMode.size());
00056         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
00057         {
00058                 log(DEBUG,"i->modechar==%c, modechar=%c, i->type=%d, type=%d",i->modechar,modechar,i->type,type);
00059                 if ((i->modechar == modechar) && (i->type == type) && (i->list == true))
00060                 {
00061                         return true;
00062                 }
00063         }
00064         return false;
00065 }
00066 
00067 bool ModeDefinedOper(char modechar, int type)
00068 {
00069         log(DEBUG,"Size of extmodes vector is %d",EMode.size());
00070         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
00071         {
00072                 log(DEBUG,"i->modechar==%c, modechar=%c, i->type=%d, type=%d",i->modechar,modechar,i->type,type);
00073                 if ((i->modechar == modechar) && (i->type == type) && (i->needsoper == true))
00074                 {
00075                         return true;
00076                 }
00077         }
00078         return false;
00079 }
00080 
00081 // returns number of parameters for a custom mode when it is switched on
00082 int ModeDefinedOn(char modechar, int type)
00083 {
00084         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
00085         {
00086                 if ((i->modechar == modechar) && (i->type == type))
00087                 {
00088                         return i->params_when_on;
00089                 }
00090         }
00091         return 0;
00092 }
00093 
00094 // returns number of parameters for a custom mode when it is switched on
00095 int ModeDefinedOff(char modechar, int type)
00096 {
00097         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
00098         {
00099                 if ((i->modechar == modechar) && (i->type == type))
00100                 {
00101                         return i->params_when_off;
00102                 }
00103         }
00104         return 0;
00105 }
00106 
00107 // returns true if an extended mode character is in use
00108 bool DoAddExtendedMode(char modechar, int type, bool requires_oper, int params_on, int params_off)
00109 {
00110         if (ModeDefined(modechar,type)) {
00111                 return false;
00112         }
00113         EMode.push_back(ExtMode(modechar,type,requires_oper,params_on,params_off));
00114         return true;
00115 }
00116 
00117 // turns a mode into a listmode
00118 void ModeMakeList(char modechar)
00119 {
00120         for (ExtModeListIter i = EMode.begin(); i < EMode.end(); i++)
00121         {
00122                 if ((i->modechar == modechar) && (i->type == MT_CHANNEL))
00123                 {
00124                         i->list = true;
00125                         return;
00126                 }
00127         }
00128         return;
00129 }
00130 
00131 // version is a simple class for holding a modules version number
00132 
00133 Version::Version(int major, int minor, int revision, int build) : Major(major), Minor(minor), Revision(revision), Build(build) { };
00134 
00135 // admin is a simple class for holding a server's administrative info
00136 
00137 Admin::Admin(std::string name, std::string email, std::string nick) : Name(name), Email(email), Nick(nick) { };
00138 
00139 Module::Module() { }
00140 Module::~Module() { }
00141 void Module::OnUserConnect(userrec* user) { }
00142 void Module::OnUserQuit(userrec* user) { }
00143 void Module::OnUserJoin(userrec* user, chanrec* channel) { }
00144 void Module::OnUserPart(userrec* user, chanrec* channel) { }
00145 void Module::OnPacketTransmit(char *p) { }
00146 void Module::OnPacketReceive(char *p) { }
00147 void Module::OnRehash() { }
00148 void Module::OnServerRaw(std::string &raw, bool inbound, userrec* user) { }
00149 int Module::OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) { return 0; }
00150 int Module::OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params) { return false; }
00151 Version Module::GetVersion() { return Version(1,0,0,0); }
00152 void Module::OnOper(userrec* user) { };
00153 void Module::OnInfo(userrec* user) { };
00154 void Module::OnWhois(userrec* source, userrec* dest) { };
00155 int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::string text) { return 0; };
00156 int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string text) { return 0; };
00157 int Module::OnUserPreNick(userrec* user, std::string newnick) { return 0; };
00158 int Module::OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type) { return ACR_DEFAULT; };
00159 
00160 // server is a wrapper class that provides methods to all of the C-style
00161 // exports in the core
00162 //
00163 
00164 Server::Server()
00165 {
00166 }
00167 
00168 Server::~Server()
00169 {
00170 }
00171 
00172 void Server::SendOpers(std::string s)
00173 {
00174         WriteOpers("%s",s.c_str());
00175 }
00176 
00177 bool Server::MatchText(std::string sliteral, std::string spattern)
00178 {
00179         char literal[MAXBUF],pattern[MAXBUF];
00180         strncpy(literal,sliteral.c_str(),MAXBUF);
00181         strncpy(pattern,spattern.c_str(),MAXBUF);
00182         return match(literal,pattern);
00183 }
00184 
00185 void Server::SendToModeMask(std::string modes, int flags, std::string text)
00186 {
00187         WriteMode(modes.c_str(),flags,"%s",text.c_str());
00188 }
00189 
00190 chanrec* Server::JoinUserToChannel(userrec* user, std::string cname, std::string key)
00191 {
00192         return add_channel(user,cname.c_str(),key.c_str(),true);
00193 }
00194 
00195 chanrec* Server::PartUserFromChannel(userrec* user, std::string cname, std::string reason)
00196 {
00197         return del_channel(user,cname.c_str(),reason.c_str(),false);
00198 }
00199 
00200 void Server::ChangeUserNick(userrec* user, std::string nickname)
00201 {
00202         force_nickchange(user,nickname.c_str());
00203 }
00204 
00205 void Server::QuitUser(userrec* user, std::string reason)
00206 {
00207         send_network_quit(user->nick,reason.c_str());
00208         kill_link(user,reason.c_str());
00209 }
00210 
00211 bool Server::IsUlined(std::string server)
00212 {
00213         return is_uline(server.c_str());
00214 }
00215 
00216 void Server::CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user)
00217 {
00218         call_handler(commandname.c_str(),parameters,pcnt,user);
00219 }
00220 
00221 void Server::Log(int level, std::string s)
00222 {
00223         log(level,"%s",s.c_str());
00224 }
00225 
00226 void Server::AddCommand(char* cmd, handlerfunc f, char flags, int minparams)
00227 {
00228         createcommand(cmd,f,flags,minparams);
00229 }
00230 
00231 void Server::SendMode(char **parameters, int pcnt, userrec *user)
00232 {
00233         server_mode(parameters,pcnt,user);
00234 }
00235 
00236 void Server::Send(int Socket, std::string s)
00237 {
00238         Write(Socket,"%s",s.c_str());
00239 }
00240 
00241 void Server::SendServ(int Socket, std::string s)
00242 {
00243         WriteServ(Socket,"%s",s.c_str());
00244 }
00245 
00246 void Server::SendFrom(int Socket, userrec* User, std::string s)
00247 {
00248         WriteFrom(Socket,User,"%s",s.c_str());
00249 }
00250 
00251 void Server::SendTo(userrec* Source, userrec* Dest, std::string s)
00252 {
00253         if (!Source)
00254         {
00255                 // if source is NULL, then the message originates from the local server
00256                 Write(Dest->fd,":%s %s",this->GetServerName().c_str(),s.c_str());
00257         }
00258         else
00259         {
00260                 // otherwise it comes from the user specified
00261                 WriteTo(Source,Dest,"%s",s.c_str());
00262         }
00263 }
00264 
00265 void Server::SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender)
00266 {
00267         if (IncludeSender)
00268         {
00269                 WriteChannel(Channel,User,"%s",s.c_str());
00270         }
00271         else
00272         {
00273                 ChanExceptSender(Channel,User,"%s",s.c_str());
00274         }
00275 }
00276 
00277 bool Server::CommonChannels(userrec* u1, userrec* u2)
00278 {
00279         return (common_channels(u1,u2) != 0);
00280 }
00281 
00282 void Server::SendCommon(userrec* User, std::string text,bool IncludeSender)
00283 {
00284         if (IncludeSender)
00285         {
00286                 WriteCommon(User,"%s",text.c_str());
00287         }
00288         else
00289         {
00290                 WriteCommonExcept(User,"%s",text.c_str());
00291         }
00292 }
00293 
00294 void Server::SendWallops(userrec* User, std::string text)
00295 {
00296         WriteWallOps(User,false,"%s",text.c_str());
00297 }
00298 
00299 void Server::ChangeHost(userrec* user, std::string host)
00300 {
00301         ChangeDisplayedHost(user,host.c_str());
00302 }
00303 
00304 void Server::ChangeGECOS(userrec* user, std::string gecos)
00305 {
00306         ChangeName(user,gecos.c_str());
00307 }
00308 
00309 bool Server::IsNick(std::string nick)
00310 {
00311         return (isnick(nick.c_str()) != 0);
00312 }
00313 
00314 userrec* Server::FindNick(std::string nick)
00315 {
00316         return Find(nick);
00317 }
00318 
00319 chanrec* Server::FindChannel(std::string channel)
00320 {
00321         return FindChan(channel.c_str());
00322 }
00323 
00324 std::string Server::ChanMode(userrec* User, chanrec* Chan)
00325 {
00326         return cmode(User,Chan);
00327 }
00328 
00329 bool Server::IsOnChannel(userrec* User, chanrec* Chan)
00330 {
00331         return has_channel(User,Chan);
00332 }
00333 
00334 std::string Server::GetServerName()
00335 {
00336         return getservername();
00337 }
00338 
00339 std::string Server::GetNetworkName()
00340 {
00341         return getnetworkname();
00342 }
00343 
00344 Admin Server::GetAdmin()
00345 {
00346         return Admin(getadminname(),getadminemail(),getadminnick());
00347 }
00348 
00349 
00350 
00351 bool Server::AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off)
00352 {
00353         if (type == MT_SERVER)
00354         {
00355                 log(DEBUG,"*** API ERROR *** Modes of type MT_SERVER are reserved for future expansion");
00356                 return false;
00357         }
00358         if (((params_when_on>0) || (params_when_off>0)) && (type == MT_CLIENT))
00359         {
00360                 log(DEBUG,"*** API ERROR *** Parameters on MT_CLIENT modes are not supported");
00361                 return false;
00362         }
00363         if ((params_when_on>1) || (params_when_off>1))
00364         {
00365                 log(DEBUG,"*** API ERROR *** More than one parameter for an MT_CHANNEL mode is not yet supported");
00366                 return false;
00367         }
00368         return DoAddExtendedMode(modechar,type,requires_oper,params_when_on,params_when_off);
00369 }
00370 
00371 bool Server::AddExtendedListMode(char modechar)
00372 {
00373         bool res = DoAddExtendedMode(modechar,MT_CHANNEL,false,1,1);
00374         if (res)
00375                 ModeMakeList(modechar);
00376         return res;
00377 }
00378 
00379 int Server::CountUsers(chanrec* c)
00380 {
00381         return usercount(c);
00382 }
00383 
00384 
00385 ConfigReader::ConfigReader()
00386 {
00387         this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
00388         this->error = LoadConf(CONFIG_FILE,this->cache);
00389 }
00390 
00391 
00392 ConfigReader::~ConfigReader()
00393 {
00394         if (this->cache)
00395                 delete this->cache;
00396 }
00397 
00398 
00399 ConfigReader::ConfigReader(std::string filename)
00400 {
00401         this->cache = new std::stringstream(std::stringstream::in | std::stringstream::out);
00402         this->error = LoadConf(filename.c_str(),this->cache);
00403 };
00404 
00405 std::string ConfigReader::ReadValue(std::string tag, std::string name, int index)
00406 {
00407         char val[MAXBUF];
00408         char t[MAXBUF];
00409         char n[MAXBUF];
00410         strncpy(t,tag.c_str(),MAXBUF);
00411         strncpy(n,name.c_str(),MAXBUF);
00412         ReadConf(cache,t,n,index,val);
00413         return std::string(val);
00414 }
00415 
00416 
00417 int ConfigReader::Enumerate(std::string tag)
00418 {
00419         return EnumConf(cache,tag.c_str());
00420 }
00421 
00422 int ConfigReader::EnumerateValues(std::string tag, int index)
00423 {
00424         return EnumValues(cache, tag.c_str(), index);
00425 }
00426 
00427 bool ConfigReader::Verify()
00428 {
00429         return this->error;
00430 }
00431 
00432 
00433 FileReader::FileReader(std::string filename)
00434 {
00435         file_cache c;
00436         readfile(c,filename.c_str());
00437         this->fc = c;
00438 }
00439 
00440 FileReader::FileReader()
00441 {
00442 }
00443 
00444 void FileReader::LoadFile(std::string filename)
00445 {
00446         file_cache c;
00447         readfile(c,filename.c_str());
00448         this->fc = c;
00449 }
00450 
00451 
00452 FileReader::~FileReader()
00453 {
00454 }
00455 
00456 bool FileReader::Exists()
00457 {
00458         if (fc.size() == 0)
00459         {
00460                 return(false);
00461         }
00462         else
00463         {
00464                 return(true);
00465         }
00466 }
00467 
00468 std::string FileReader::GetLine(int x)
00469 {
00470         if ((x<0) || (x>fc.size()))
00471                 return "";
00472         return fc[x];
00473 }
00474 
00475 int FileReader::FileSize()
00476 {
00477         return fc.size();
00478 }
00479 
00480 
00481 std::vector<Module*> modules(255);
00482 std::vector<ircd_module*> factory(255);
00483 
00484 int MODCOUNT  = -1;
00485 
00486 

Generated on Sat May 1 13:39:00 2004 for InspIRCd by doxygen1.3-rc3