-/* +------------------------------------+\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 "configreader.h"\r#include "mode.h"\r#include "channels.h"\r#include "users.h"\r#include "modules.h"\r#include "modes/cmode_h.h"\r\rModeChannelHalfOp::ModeChannelHalfOp(InspIRCd* Instance) : ModeHandler(Instance, 'h', 1, 1, true, MODETYPE_CHANNEL, false, '%')\r{\r}\r\runsigned int ModeChannelHalfOp::GetPrefixRank()\r{\r return HALFOP_VALUE;\r}\r\rModePair ModeChannelHalfOp::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)\r{\r userrec* x = ServerInstance->FindNick(parameter);\r if (x)\r {\r if (channel->GetStatusFlags(x) & UCMODE_HOP)\r {\r return std::make_pair(true, x->nick);\r }\r else\r {\r return std::make_pair(false, parameter);\r }\r }\r return std::make_pair(false, parameter);\r}\r\rvoid ModeChannelHalfOp::RemoveMode(chanrec* channel)\r{\r CUList* list = channel->GetHalfoppedUsers();\r CUList copy;\r char moderemove[MAXBUF];\r userrec* n = new userrec(ServerInstance);\r n->SetFd(FD_MAGIC_NUMBER);\r\r for (CUList::iterator i = list->begin(); i != list->end(); i++)\r {\r userrec* n = i->first;\r copy.insert(std::make_pair(n,n->nick));\r }\r for (CUList::iterator i = copy.begin(); i != copy.end(); i++)\r {\r sprintf(moderemove,"-%c",this->GetModeChar());\r const char* parameters[] = { channel->name, moderemove, i->first->nick };\r ServerInstance->SendMode(parameters, 3, n);\r }\r delete n;\r}\r\rvoid ModeChannelHalfOp::RemoveMode(userrec* user)\r{\r}\r\rModeAction ModeChannelHalfOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)\r{\r /* If halfops are not enabled in the conf, we don't execute\r * anything in this class at all.\r */\r if (!ServerInstance->Config->AllowHalfop)\r {\r parameter = "";\r return MODEACTION_DENY;\r }\r\r int status = channel->GetStatus(source);\r\r /* Call the correct method depending on wether we're adding or removing the mode */\r if (adding)\r {\r parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);\r }\r else\r {\r parameter = this->DelHalfOp(source, parameter.c_str(), 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 if (parameter.length())\r return MODEACTION_ALLOW;\r else\r return MODEACTION_DENY;\r}\r\rstd::string ModeChannelHalfOp::AddHalfOp(userrec *user,const char* dest,chanrec *chan,int status)\r{\r userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);\r\r if (d)\r {\r if (IS_LOCAL(user))\r {\r int MOD_RESULT = 0;\r FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));\r\r if (MOD_RESULT == ACR_DENY)\r return "";\r if (MOD_RESULT == ACR_DEFAULT)\r {\r if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))\r {\r user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);\r return "";\r }\r }\r }\r\r return ServerInstance->Modes->Grant(d,chan,UCMODE_HOP);\r }\r return "";\r}\r\rstd::string ModeChannelHalfOp::DelHalfOp(userrec *user,const char *dest,chanrec *chan,int status)\r{\r userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);\r\r if (d)\r {\r if (IS_LOCAL(user))\r {\r int MOD_RESULT = 0;\r FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));\r\r if (MOD_RESULT == ACR_DENY)\r return "";\r if (MOD_RESULT == ACR_DEFAULT)\r {\r if ((user != d) && ((status < STATUS_OP) && (!ServerInstance->ULine(user->server))))\r {\r user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);\r return "";\r }\r }\r }\r\r return ServerInstance->Modes->Revoke(d,chan,UCMODE_HOP);\r }\r return "";\r}\r\r
\ No newline at end of file
+/* +------------------------------------+
+ * | Inspire Internet Relay Chat Daemon |
+ * +------------------------------------+
+ *
+ * InspIRCd: (C) 2002-2008 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
+ * This program is free but copyrighted software; see
+ * the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
+#include "inspircd.h"
+#include "configreader.h"
+#include "mode.h"
+#include "channels.h"
+#include "users.h"
+#include "modules.h"
+#include "modes/cmode_h.h"
+
+ModeChannelHalfOp::ModeChannelHalfOp(InspIRCd* Instance) : ModeHandler(Instance, 'h', 1, 1, true, MODETYPE_CHANNEL, false, '%', '@')
+{
+}
+
+unsigned int ModeChannelHalfOp::GetPrefixRank()
+{
+ return HALFOP_VALUE;
+}
+
+ModePair ModeChannelHalfOp::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
+{
+ User* x = ServerInstance->FindNick(parameter);
+ if (x)
+ {
+ if (channel->GetStatusFlags(x) & UCMODE_HOP)
+ {
+ return std::make_pair(true, x->nick);
+ }
+ else
+ {
+ return std::make_pair(false, parameter);
+ }
+ }
+ return std::make_pair(false, parameter);
+}
+
+void ModeChannelHalfOp::RemoveMode(Channel* channel, irc::modestacker* stack)
+{
+ CUList* clist = channel->GetHalfoppedUsers();
+ CUList copy;
+
+ for (CUList::iterator i = clist->begin(); i != clist->end(); i++)
+ {
+ User* n = i->first;
+ copy.insert(std::make_pair(n,n->nick));
+ }
+
+ for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
+ {
+ if (stack)
+ {
+ stack->Push(this->GetModeChar(), i->first->nick);
+ }
+ else
+ {
+ std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-h"); parameters.push_back(i->first->nick);
+ ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
+ }
+ }
+
+}
+
+void ModeChannelHalfOp::RemoveMode(User*, irc::modestacker* stack)
+{
+}
+
+ModeAction ModeChannelHalfOp::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding, bool servermode)
+{
+ /* If halfops are not enabled in the conf, we don't execute
+ * anything in this class at all.
+ */
+ if (!ServerInstance->Config->AllowHalfop)
+ {
+ parameter = "";
+ return MODEACTION_DENY;
+ }
+
+ int status = channel->GetStatus(source);
+
+ /* Call the correct method depending on wether we're adding or removing the mode */
+ if (adding)
+ {
+ parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
+ }
+ else
+ {
+ parameter = this->DelHalfOp(source, parameter.c_str(), 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.
+ */
+ if (parameter.length())
+ return MODEACTION_ALLOW;
+ else
+ return MODEACTION_DENY;
+}
+
+std::string ModeChannelHalfOp::AddHalfOp(User *user,const char* dest,Channel *chan,int status)
+{
+ User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
+
+ if (d)
+ {
+ if (IS_LOCAL(user))
+ {
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
+
+ if (MOD_RESULT == ACR_DENY)
+ return "";
+ if (MOD_RESULT == ACR_DEFAULT)
+ {
+ if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
+ {
+ user->WriteServ("482 %s %s :You're not a channel operator",user->nick.c_str(), chan->name.c_str());
+ return "";
+ }
+ }
+ }
+
+ return ServerInstance->Modes->Grant(d,chan,UCMODE_HOP);
+ }
+ return "";
+}
+
+std::string ModeChannelHalfOp::DelHalfOp(User *user,const char *dest,Channel *chan,int status)
+{
+ User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
+
+ if (d)
+ {
+ if (IS_LOCAL(user))
+ {
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
+
+ if (MOD_RESULT == ACR_DENY)
+ return "";
+ if (MOD_RESULT == ACR_DEFAULT)
+ {
+ if ((user != d) && ((status < STATUS_OP) && (!ServerInstance->ULine(user->server))))
+ {
+ user->WriteServ("482 %s %s :You are not a channel operator",user->nick.c_str(), chan->name.c_str());
+ return "";
+ }
+ }
+ }
+
+ return ServerInstance->Modes->Revoke(d,chan,UCMODE_HOP);
+ }
+ return "";
+}
+