00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "inspircd.h"
00015 #include "configreader.h"
00016 #include "mode.h"
00017 #include "channels.h"
00018 #include "users.h"
00019 #include "modules.h"
00020 #include "modes/cmode_o.h"
00021
00022 ModeChannelOp::ModeChannelOp(InspIRCd* Instance) : ModeHandler(Instance, 'o', 1, 1, true, MODETYPE_CHANNEL, false, '@', '@')
00023 {
00024 }
00025
00026 unsigned int ModeChannelOp::GetPrefixRank()
00027 {
00028 return OP_VALUE;
00029 }
00030
00031 ModePair ModeChannelOp::ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
00032 {
00033 User* x = ServerInstance->FindNick(parameter);
00034 if (x)
00035 {
00036 if (channel->GetStatusFlags(x) & UCMODE_OP)
00037 {
00038 return std::make_pair(true, x->nick);
00039 }
00040 else
00041 {
00042 return std::make_pair(false, parameter);
00043 }
00044 }
00045 return std::make_pair(false, parameter);
00046 }
00047
00048
00049 void ModeChannelOp::RemoveMode(Channel* channel, irc::modestacker* stack)
00050 {
00051 CUList* clist = channel->GetOppedUsers();
00052 CUList copy;
00053
00054 for (CUList::iterator i = clist->begin(); i != clist->end(); i++)
00055 {
00056 User* n = i->first;
00057 copy.insert(std::make_pair(n,n->nick));
00058 }
00059
00060 for (CUList::iterator i = copy.begin(); i != copy.end(); i++)
00061 {
00062 if (stack)
00063 stack->Push(this->GetModeChar(), i->first->nick);
00064 else
00065 {
00066 std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-o"); parameters.push_back(i->first->nick);
00067 ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
00068 }
00069 }
00070 }
00071
00072 void ModeChannelOp::RemoveMode(User*, irc::modestacker* stack)
00073 {
00074 }
00075
00076 ModeAction ModeChannelOp::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding, bool servermode)
00077 {
00078 int status = channel->GetStatus(source);
00079
00080
00081 if (adding)
00082 {
00083 parameter = this->AddOp(source, parameter.c_str(), channel, status);
00084 }
00085 else
00086 {
00087 parameter = this->DelOp(source, parameter.c_str(), channel, status);
00088 }
00089
00090
00091
00092
00093
00094 if (parameter.length())
00095 return MODEACTION_ALLOW;
00096 else
00097 return MODEACTION_DENY;
00098 }
00099
00100 std::string ModeChannelOp::AddOp(User *user,const char* dest,Channel *chan,int status)
00101 {
00102 User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
00103
00104 if (d)
00105 {
00106 if (IS_LOCAL(user))
00107 {
00108 int MOD_RESULT = 0;
00109 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
00110
00111 if (MOD_RESULT == ACR_DENY)
00112 return "";
00113 if (MOD_RESULT == ACR_DEFAULT)
00114 {
00115 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)))
00116 {
00117 user->WriteServ("482 %s %s :You're not a channel operator",user->nick.c_str(), chan->name.c_str());
00118 return "";
00119 }
00120 }
00121 }
00122
00123 return ServerInstance->Modes->Grant(d,chan,UCMODE_OP);
00124 }
00125 return "";
00126 }
00127
00128 std::string ModeChannelOp::DelOp(User *user,const char *dest,Channel *chan,int status)
00129 {
00130 User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
00131
00132 if (d)
00133 {
00134 if (IS_LOCAL(user))
00135 {
00136 int MOD_RESULT = 0;
00137 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
00138
00139 if (MOD_RESULT == ACR_DENY)
00140 return "";
00141 if (MOD_RESULT == ACR_DEFAULT)
00142 {
00143 if ((status < STATUS_OP) && (!ServerInstance->ULine(user->server)) && (IS_LOCAL(user)))
00144 {
00145 user->WriteServ("482 %s %s :You are not a channel operator",user->nick.c_str(), chan->name.c_str());
00146 return "";
00147 }
00148 }
00149 }
00150
00151 return ServerInstance->Modes->Revoke(d,chan,UCMODE_OP);
00152 }
00153 return "";
00154 }