1 #include "configreader.h"
7 #include "modes/cmode_o.h"
9 ModeChannelOp::ModeChannelOp(InspIRCd* Instance) : ModeHandler(Instance, 'o', 1, 1, true, MODETYPE_CHANNEL, false, '@')
13 unsigned int ModeChannelOp::GetPrefixRank()
18 ModePair ModeChannelOp::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
20 userrec* x = ServerInstance->FindNick(parameter);
23 if (channel->GetStatusFlags(x) & UCMODE_OP)
25 return std::make_pair(true, x->nick);
29 return std::make_pair(false, parameter);
32 return std::make_pair(false, parameter);
36 void ModeChannelOp::RemoveMode(chanrec* channel)
38 CUList* list = channel->GetOppedUsers();
40 char moderemove[MAXBUF];
41 userrec* n = new userrec(ServerInstance);
42 n->SetFd(FD_MAGIC_NUMBER);
44 for (CUList::iterator i = list->begin(); i != list->end(); i++)
46 userrec* n = i->second;
47 copy.insert(std::make_pair(n,n));
49 for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
51 sprintf(moderemove,"-%c",this->GetModeChar());
52 const char* parameters[] = { channel->name, moderemove, i->second->nick };
53 ServerInstance->SendMode(parameters, 3, n);
58 void ModeChannelOp::RemoveMode(userrec* user)
62 ModeAction ModeChannelOp::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
64 int status = channel->GetStatus(source);
66 /* Call the correct method depending on wether we're adding or removing the mode */
69 parameter = this->AddOp(source, parameter.c_str(), channel, status);
73 parameter = this->DelOp(source, parameter.c_str(), channel, status);
75 /* If the method above 'ate' the parameter by reducing it to an empty string, then
76 * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
77 * the return value and is always MODEACTION_DENY if the mode is supposed to have
80 return MODEACTION_ALLOW;
83 std::string ModeChannelOp::AddOp(userrec *user,const char* dest,chanrec *chan,int status)
85 userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
92 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
94 if (MOD_RESULT == ACR_DENY)
96 if (MOD_RESULT == ACR_DEFAULT)
98 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
100 user->WriteServ("482 %s %s :You're not a channel operator",user->nick, chan->name);
106 return ServerInstance->Modes->Grant(d,chan,UCMODE_OP);
111 std::string ModeChannelOp::DelOp(userrec *user,const char *dest,chanrec *chan,int status)
113 userrec *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
120 ServerInstance->Log(DEBUG,"Call OnAccessCheck for AC_DEOP");
121 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
123 ServerInstance->Log(DEBUG,"Returns %d",MOD_RESULT);
125 if (MOD_RESULT == ACR_DENY)
127 if (MOD_RESULT == ACR_DEFAULT)
129 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)) && (IS_LOCAL(user)))
131 user->WriteServ("482 %s %s :You are not a channel operator",user->nick, chan->name);
137 return ServerInstance->Modes->Revoke(d,chan,UCMODE_OP);