]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modes/cmode_h.cpp
Set EOL to WINDOWS-style always for Visual Studio files.
[user/henk/code/inspircd.git] / src / modes / cmode_h.cpp
1 /*       +------------------------------------+\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 &parameter)\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 &parameter, 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