diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-04-27 16:19:45 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-04-27 16:19:45 +0000 |
commit | 06b12b71ae73cdfceba122e6400dd97830c8cea9 (patch) | |
tree | 5de5a5b5d1cc758581b8bf25b5e27157507f5272 /src/modules/m_timedbans.cpp | |
parent | 450c234e966cd915f7f4b5c74bb2e89b53e1e839 (diff) |
Fixed WriteChannelWithServ
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1217 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/m_timedbans.cpp')
-rw-r--r-- | src/modules/m_timedbans.cpp | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp index 7a3c714ed..5649a9e37 100644 --- a/src/modules/m_timedbans.cpp +++ b/src/modules/m_timedbans.cpp @@ -34,7 +34,7 @@ class TimedBan public: std::string channel; std::string mask; - std::string expire; + time_t expire; }; typedef std::vector<TimedBan> timedbans; @@ -48,11 +48,24 @@ void handle_tban(char **parameters, int pcnt, userrec *user) std::string cm = Srv->ChanMode(user,channel); if ((cm == "%") || (cm == "@")) { + for (timedbans::iterator i = TimedBanList.begin(); i < TimedBanList.end(); i++) + { + if ((!strcasecmp(i->mask.c_str(),parameters[2])) && (!strcasecmp(i->channel.c_str(),parameters[0]))) + { + Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :The ban "+std::string(parameters[2])+" is already on the banlist of "+std::string(parameters[0])); + return; + } + } TimedBan T; std::string channelname = parameters[0]; - unsigned long expire = Srv->Duration(parameters[1]) + time(NULL); + unsigned long expire = Srv->CalcDuration(parameters[1]) + time(NULL); + if (Srv->CalcDuration(parameters[1]) < 1) + { + Srv->SendServ(user->fd,"NOTICE "+std::string(user->nick)+" :Invalid ban time"); + return; + } char duration[MAXBUF]; - snprintf(duration,MAXBUF,"%lu",Srv->Duration(parameters[1])); + snprintf(duration,MAXBUF,"%lu",Srv->CalcDuration(parameters[1])); std::string mask = parameters[2]; char *setban[3]; setban[0] = parameters[0]; @@ -65,9 +78,11 @@ void handle_tban(char **parameters, int pcnt, userrec *user) T.mask = mask; T.expire = expire; TimedBanList.push_back(T); - Srv->SendChannelServerNotice(Srv->GetServerName(),channel,std::string(user->nick)+" added a timed ban on "+mask+" lasting for "+std::string(duration)+" seconds."); + Srv->SendChannelServerNotice(Srv->GetServerName(),channel,"NOTICE "+std::string(channel->name)+" :"+std::string(user->nick)+" added a timed ban on "+mask+" lasting for "+std::string(duration)+" seconds."); + return; } else WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, channel->name); + return; } WriteServ(user->fd,"401 %s %s :No such channel",user->nick, parameters[0]); } @@ -94,18 +109,26 @@ class ModuleTimedBans : public Module again = false; for (timedbans::iterator i = TimedBanList.begin(); i < TimedBanList.end(); i++) { - if (i->expire >= curtime) + if (curtime > i->expire) { chanrec* cr = Srv->FindChannel(i->channel); again = true; if (cr) { char *setban[3]; - setban[0] = i->channel.c_str(); + setban[0] = (char*)i->channel.c_str(); setban[1] = "-b"; - setban[2] = i->mask.c_str(); - Srv->SendMode(setban,3,NULL); - Srv->SendChannelServerNotice(Srv->GetServerName(),channel,"Timed ban on "+i->mask+" expired."); + setban[2] = (char*)i->mask.c_str(); + // kludge alert! + // ::SendMode expects a userrec* to send the numeric replies + // 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; + temp->fd = FD_MAGIC_NUMBER; + Srv->SendMode(setban,3,temp); + delete temp; + Srv->SendChannelServerNotice(Srv->GetServerName(),cr,"NOTICE "+std::string(cr->name)+" :Timed ban on "+i->mask+" expired."); } TimedBanList.erase(i); break; |