X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_timedbans.cpp;h=3d38affabcc5f707cd01cc1ba09c89fce5b44834;hb=66098d307c036997e51eaea21724615e27fdc3e9;hp=fad2409dcbd7a3d2b5ce8a678b1479134547470b;hpb=09afa5085614e0224a296abd082fce205003c3fe;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp index fad2409dc..3d38affab 100644 --- a/src/modules/m_timedbans.cpp +++ b/src/modules/m_timedbans.cpp @@ -25,10 +25,12 @@ using namespace std; #include "modules.h" #include "helperfuncs.h" #include "hashcomp.h" +#include "configreader.h" #include "inspircd.h" -static Server *Srv; - + +extern InspIRCd* ServerInstance; + class TimedBan : public classbase { public: @@ -43,7 +45,7 @@ timedbans TimedBanList; class cmd_tban : public command_t { public: - cmd_tban () : command_t("TBAN", 0, 3) + cmd_tban (InspIRCd* Instance) : command_t(Instance,"TBAN", 0, 3) { this->source = "m_timedbans.so"; syntax = " "; @@ -51,13 +53,13 @@ class cmd_tban : public command_t void Handle (const char** parameters, int pcnt, userrec *user) { - chanrec* channel = Srv->FindChannel(parameters[0]); + chanrec* channel = ServerInstance->FindChan(parameters[0]); if (channel) { - std::string cm = Srv->ChanMode(user,channel); - if ((cm == "%") || (cm == "@")) + int cm = channel->GetStatus(user); + if ((cm == STATUS_HOP) || (cm == STATUS_OP)) { - if (!Srv->IsValidMask(parameters[2])) + if (!ServerInstance->IsValidMask(parameters[2])) { user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid ban mask"); return; @@ -72,14 +74,14 @@ class cmd_tban : public command_t } TimedBan T; std::string channelname = parameters[0]; - unsigned long expire = Srv->CalcDuration(parameters[1]) + time(NULL); - if (Srv->CalcDuration(parameters[1]) < 1) + unsigned long expire = ServerInstance->CalcDuration(parameters[1]) + time(NULL); + if (ServerInstance->CalcDuration(parameters[1]) < 1) { user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid ban time"); return; } char duration[MAXBUF]; - snprintf(duration,MAXBUF,"%lu",Srv->CalcDuration(parameters[1])); + snprintf(duration,MAXBUF,"%lu",ServerInstance->CalcDuration(parameters[1])); std::string mask = parameters[2]; const char *setban[32]; setban[0] = parameters[0]; @@ -87,7 +89,7 @@ class cmd_tban : public command_t setban[2] = parameters[2]; // use CallCommandHandler to make it so that the user sets the mode // themselves - Srv->CallCommandHandler("MODE",setban,3,user); + ServerInstance->CallCommandHandler("MODE",setban,3,user); /* Check if the ban was actually added (e.g. banlist was NOT full) */ bool was_added = false; for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++) @@ -99,7 +101,7 @@ class cmd_tban : public command_t T.mask = mask; T.expire = expire; TimedBanList.push_back(T); - channel->WriteChannelWithServ(Srv->GetServerName().c_str(), "NOTICE %s :%s added a timed ban on %s lasting for %s seconds.", channel->name, user->nick, mask.c_str(), duration); + channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s added a timed ban on %s lasting for %s seconds.", channel->name, user->nick, mask.c_str(), duration); } return; } @@ -114,12 +116,12 @@ class ModuleTimedBans : public Module { cmd_tban* mycommand; public: - ModuleTimedBans(Server* Me) + ModuleTimedBans(InspIRCd* Me) : Module::Module(Me) { - Srv = Me; - mycommand = new cmd_tban(); - Srv->AddCommand(mycommand); + + mycommand = new cmd_tban(ServerInstance); + ServerInstance->AddCommand(mycommand); TimedBanList.clear(); } @@ -158,11 +160,11 @@ class ModuleTimedBans : public Module { if (curtime > i->expire) { - chanrec* cr = Srv->FindChannel(i->channel); + chanrec* cr = ServerInstance->FindChan(i->channel); again = true; if (cr) { - cr->WriteChannelWithServ(Srv->GetServerName().c_str(), "NOTICE %s :Timed ban on %s expired.", cr->name, i->mask.c_str()); + cr->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :Timed ban on %s expired.", cr->name, i->mask.c_str()); const char *setban[3]; setban[0] = i->channel.c_str(); setban[1] = "-b"; @@ -172,10 +174,10 @@ class ModuleTimedBans : public Module // back to, so we create it a fake user that isnt in the user // hash and set its descriptor to FD_MAGIC_NUMBER so the data // falls into the abyss :p - userrec* temp = new userrec; + userrec* temp = new userrec(ServerInstance); temp->fd = FD_MAGIC_NUMBER; temp->server = ""; - Srv->SendMode(setban,3,temp); + ServerInstance->SendMode(setban,3,temp); /* FIX: Send mode remotely*/ std::deque n; n.push_back(i->channel); @@ -215,7 +217,7 @@ class ModuleTimedBansFactory : public ModuleFactory { } - virtual Module * CreateModule(Server* Me) + virtual Module * CreateModule(InspIRCd* Me) { return new ModuleTimedBans(Me); }