-/* +------------------------------------+\r * | Inspire Internet Relay Chat Daemon |\r * +------------------------------------+\r *\r * InspIRCd: (C) 2002-2007 InspIRCd Development Team\r * See: http://www.inspircd.org/wiki/index.php/Credits\r *\r * This program is free but copyrighted software; see\r * the file COPYING for details.\r *\r * ---------------------------------------------------\r */\r\r#include "inspircd.h"\r#include <string>\r#include <vector>\r#include "inspircd_config.h"\r#include "configreader.h"\r#include "hash_map.h"\r#include "mode.h"\r#include "channels.h"\r#include "users.h"\r#include "modules.h"\r#include "inspstring.h"\r#include "hashcomp.h"\r#include "modes/cmode_b.h"\r\rModeChannelBan::ModeChannelBan(InspIRCd* Instance) : ModeHandler(Instance, 'b', 1, 1, true, MODETYPE_CHANNEL, false)\r{\r}\r\rModeAction ModeChannelBan::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)\r{\r int status = channel->GetStatus(source);\r /* Call the correct method depending on wether we're adding or removing the mode */\r if (adding)\r {\r parameter = this->AddBan(source, parameter, channel, status);\r }\r else\r {\r parameter = this->DelBan(source, parameter, channel, status);\r }\r /* If the method above 'ate' the parameter by reducing it to an empty string, then\r * it won't matter wether we return ALLOW or DENY here, as an empty string overrides\r * the return value and is always MODEACTION_DENY if the mode is supposed to have\r * a parameter.\r */\r return MODEACTION_ALLOW;\r}\r\rvoid ModeChannelBan::RemoveMode(chanrec* channel)\r{\r BanList copy;\r char moderemove[MAXBUF];\r userrec* n = new userrec(ServerInstance);\r n->SetFd(FD_MAGIC_NUMBER);\r\r for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)\r {\r copy.push_back(*i);\r }\r for (BanList::iterator i = copy.begin(); i != copy.end(); i++)\r {\r sprintf(moderemove,"-%c",this->GetModeChar());\r const char* parameters[] = { channel->name, moderemove, i->data };\r ServerInstance->SendMode(parameters, 3, n);\r }\r\r delete n;\r}\r\rvoid ModeChannelBan::RemoveMode(userrec* user)\r{\r}\r\rvoid ModeChannelBan::DisplayList(userrec* user, chanrec* channel)\r{\r /* Display the channel banlist */\r for (BanList::reverse_iterator i = channel->bans.rbegin(); i != channel->bans.rend(); ++i)\r {\r user->WriteServ("367 %s %s %s %s %d",user->nick, channel->name, i->data, i->set_by, i->set_time);\r }\r user->WriteServ("368 %s %s :End of channel ban list",user->nick, channel->name);\r return;\r}\r\rstd::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *chan,int status)\r{\r if ((!user) || (!chan))\r {\r ServerInstance->Log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");\r dest = "";\r return dest;\r }\r\r /* Attempt to tidy the mask */\r ModeParser::CleanMask(dest);\r /* If the mask was invalid, we exit */\r if (dest == "")\r return dest;\r\r long maxbans = chan->GetMaxBans();\r if ((unsigned)chan->bans.size() > (unsigned)maxbans)\r {\r user->WriteServ("478 %s %s :Channel ban list for %s is full (maximum entries for this channel is %d)",user->nick, chan->name,chan->name,maxbans);\r dest = "";\r return dest;\r }\r\r int MOD_RESULT = 0;\r FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));\r if (MOD_RESULT)\r {\r dest = "";\r return dest;\r }\r\r for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)\r {\r if (!strcasecmp(i->data,dest.c_str()))\r {\r /* dont allow a user to set the same ban twice */\r dest = "";\r return dest;\r }\r }\r\r b.set_time = ServerInstance->Time();\r strlcpy(b.data,dest.c_str(),MAXBUF);\r if (*user->nick)\r {\r strlcpy(b.set_by,user->nick,NICKMAX-1);\r }\r else\r {\r strlcpy(b.set_by,ServerInstance->Config->ServerName,NICKMAX-1);\r }\r chan->bans.push_back(b);\r return dest;\r}\r\rModePair ModeChannelBan::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)\r{\r for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)\r {\r if (!strcasecmp(i->data,parameter.c_str()))\r {\r return std::make_pair(true, i->data);\r }\r }\r return std::make_pair(false, parameter);\r}\r\rstd::string& ModeChannelBan::DelBan(userrec *user,std::string& dest,chanrec *chan,int status)\r{\r if ((!user) || (!chan))\r {\r ServerInstance->Log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");\r dest = "";\r return dest;\r }\r\r /* 'Clean' the mask, e.g. nick -> nick!*@* */\r ModeParser::CleanMask(dest);\r\r for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)\r {\r if (!strcasecmp(i->data,dest.c_str()))\r {\r int MOD_RESULT = 0;\r FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));\r if (MOD_RESULT)\r {\r dest = "";\r return dest;\r }\r chan->bans.erase(i);\r return dest;\r }\r }\r dest = "";\r return dest;\r}\r\r
\ No newline at end of file
+/* +------------------------------------+
+ * | Inspire Internet Relay Chat Daemon |
+ * +------------------------------------+
+ *
+ * InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
+ *
+ * This program is free but copyrighted software; see
+ * the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
+#include "inspircd.h"
+#include <string>
+#include <vector>
+#include "inspircd_config.h"
+#include "configreader.h"
+#include "hash_map.h"
+#include "mode.h"
+#include "channels.h"
+#include "users.h"
+#include "modules.h"
+#include "inspstring.h"
+#include "hashcomp.h"
+#include "modes/cmode_b.h"
+
+ModeChannelBan::ModeChannelBan(InspIRCd* Instance) : ModeHandler(Instance, NULL, 'b', 1, 1, true, MODETYPE_CHANNEL, false)
+{
+}
+
+ModeAction ModeChannelBan::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding)
+{
+ int status = channel->GetStatus(source);
+ /* Call the correct method depending on wether we're adding or removing the mode */
+ if (adding)
+ {
+ parameter = this->AddBan(source, parameter, channel, status);
+ }
+ else
+ {
+ parameter = this->DelBan(source, parameter, channel, status);
+ }
+ /* If the method above 'ate' the parameter by reducing it to an empty string, then
+ * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
+ * the return value and is always MODEACTION_DENY if the mode is supposed to have
+ * a parameter.
+ */
+ return MODEACTION_ALLOW;
+}
+
+void ModeChannelBan::RemoveMode(Channel* channel, irc::modestacker* stack)
+{
+ BanList copy;
+
+ for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
+ {
+ copy.push_back(*i);
+ }
+
+ for (BanList::iterator i = copy.begin(); i != copy.end(); i++)
+ {
+ if (stack)
+ {
+ stack->Push(this->GetModeChar(), i->data);
+ }
+ else
+ {
+ std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-b"); parameters.push_back(i->data);
+ ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
+ }
+ }
+}
+
+void ModeChannelBan::RemoveMode(User*, irc::modestacker* stack)
+{
+}
+
+void ModeChannelBan::DisplayList(User* user, Channel* channel)
+{
+ /* Display the channel banlist */
+ for (BanList::reverse_iterator i = channel->bans.rbegin(); i != channel->bans.rend(); ++i)
+ {
+ user->WriteServ("367 %s %s %s %s %lu",user->nick.c_str(), channel->name.c_str(), i->data.c_str(), i->set_by.c_str(), (unsigned long)i->set_time);
+ }
+ user->WriteServ("368 %s %s :End of channel ban list",user->nick.c_str(), channel->name.c_str());
+ return;
+}
+
+void ModeChannelBan::DisplayEmptyList(User* user, Channel* channel)
+{
+ user->WriteServ("368 %s %s :End of channel ban list",user->nick.c_str(), channel->name.c_str());
+}
+
+std::string& ModeChannelBan::AddBan(User *user, std::string &dest, Channel *chan, int)
+{
+ if ((!user) || (!chan))
+ {
+ ServerInstance->Logs->Log("MODE",DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
+ dest = "";
+ return dest;
+ }
+
+ /* Attempt to tidy the mask */
+ ModeParser::CleanMask(dest);
+ /* If the mask was invalid, we exit */
+ if (dest == "")
+ return dest;
+
+ long maxbans = chan->GetMaxBans();
+ if (!IS_LOCAL(user) && ((unsigned)chan->bans.size() > (unsigned)maxbans))
+ {
+ user->WriteServ("478 %s %s :Channel ban list for %s is full (maximum entries for this channel is %ld)",user->nick.c_str(), chan->name.c_str(), chan->name.c_str(), maxbans);
+ dest = "";
+ return dest;
+ }
+
+ ModResult MOD_RESULT;
+ FIRST_MOD_RESULT(ServerInstance, OnAddBan, MOD_RESULT, (user,chan,dest));
+ if (MOD_RESULT == MOD_RES_DENY)
+ {
+ dest = "";
+ return dest;
+ }
+
+ for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
+ {
+ if (i->data == dest)
+ {
+ /* dont allow a user to set the same ban twice */
+ dest = "";
+ return dest;
+ }
+ }
+
+ b.set_time = ServerInstance->Time();
+ b.data.assign(dest, 0, MAXBUF);
+ b.set_by.assign(user->nick, 0, 64);
+ chan->bans.push_back(b);
+ return dest;
+}
+
+ModePair ModeChannelBan::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
+{
+ for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++)
+ {
+ if (!strcasecmp(i->data.c_str(), parameter.c_str()))
+ {
+ return std::make_pair(true, i->data);
+ }
+ }
+ return std::make_pair(false, parameter);
+}
+
+std::string& ModeChannelBan::DelBan(User *user, std::string& dest, Channel *chan, int)
+{
+ if ((!user) || (!chan))
+ {
+ ServerInstance->Logs->Log("MODE",DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
+ dest = "";
+ return dest;
+ }
+
+ /* 'Clean' the mask, e.g. nick -> nick!*@* */
+ ModeParser::CleanMask(dest);
+
+ for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
+ {
+ if (!strcasecmp(i->data.c_str(), dest.c_str()))
+ {
+ ModResult MOD_RESULT;
+ FIRST_MOD_RESULT(ServerInstance, OnDelBan, MOD_RESULT, (user, chan, dest));
+ if (MOD_RESULT == MOD_RES_DENY)
+ {
+ dest = "";
+ return dest;
+ }
+ chan->bans.erase(i);
+ return dest;
+ }
+ }
+ dest = "";
+ return dest;
+}
+