00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "inspircd.h"
00015
00016
00017
00020 class ServProtectMode : public ModeHandler
00021 {
00022 public:
00023 ServProtectMode(InspIRCd* Instance) : ModeHandler(Instance, 'k', 0, 0, false, MODETYPE_USER, true) { }
00024
00025 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
00026 {
00027
00028
00029
00030
00031
00032
00033
00034
00035 return MODEACTION_DENY;
00036 }
00037
00038 bool NeedsOper() { return true; }
00039 };
00040
00041 class ModuleServProtectMode : public Module
00042 {
00043
00044 ServProtectMode* bm;
00045 public:
00046 ModuleServProtectMode(InspIRCd* Me)
00047 : Module(Me)
00048 {
00049
00050 bm = new ServProtectMode(ServerInstance);
00051 if (!ServerInstance->Modes->AddMode(bm))
00052 throw ModuleException("Could not add new modes!");
00053 Implementation eventlist[] = { I_OnWhois, I_OnKill, I_OnWhoisLine, I_OnRawMode, I_OnUserPreKick };
00054 ServerInstance->Modules->Attach(eventlist, this, 5);
00055 }
00056
00057
00058 virtual ~ModuleServProtectMode()
00059 {
00060 ServerInstance->Modes->DelMode(bm);
00061 delete bm;
00062 }
00063
00064 virtual Version GetVersion()
00065 {
00066 return Version("$Id: m_servprotect.cpp 10622 2008-10-04 21:27:52Z brain $",VF_COMMON,API_VERSION);
00067 }
00068
00069 virtual void OnWhois(User* src, User* dst)
00070 {
00071 if (dst->IsModeSet('k'))
00072 {
00073 ServerInstance->SendWhoisLine(src, dst, 310, std::string(src->nick)+" "+std::string(dst->nick)+" :is an "+ServerInstance->Config->Network+" Service");
00074 }
00075 }
00076
00077 virtual int OnRawMode(User* user, Channel* chan, const char mode, const std::string ¶m, bool adding, int pcnt, bool servermode)
00078 {
00079
00080
00081
00082 if (!servermode && !adding && chan && IS_LOCAL(user) && !param.empty() && !ServerInstance->ULine(user->server))
00083 {
00084
00085
00086 User *u = ServerInstance->FindNick(param);
00087 if (u)
00088 {
00089
00090
00091
00092
00093 if (u->IsModeSet('k') && ServerInstance->Modes->ModeString(u, chan, false).find(mode) != std::string::npos)
00094 {
00095
00096 user->WriteNumeric(482, "%s %s :You are not permitted to remove privileges from %s services", user->nick.c_str(), chan->name.c_str(), ServerInstance->Config->Network);
00097 return ACR_DENY;
00098 }
00099 }
00100 }
00101
00102 return 0;
00103 }
00104
00105 virtual int OnKill(User* src, User* dst, const std::string &reason)
00106 {
00107 if (src == NULL)
00108 return 0;
00109
00110 if (dst->IsModeSet('k'))
00111 {
00112 src->WriteNumeric(485, "%s :You are not permitted to kill %s services!", src->nick.c_str(), ServerInstance->Config->Network);
00113 ServerInstance->SNO->WriteToSnoMask('A', std::string(src->nick)+" tried to kill service "+dst->nick+" ("+reason+")");
00114 return 1;
00115 }
00116 return 0;
00117 }
00118
00119 virtual int OnUserPreKick(User *src, User *dst, Channel *c, const std::string &reason)
00120 {
00121 if (dst->IsModeSet('k'))
00122 {
00123 src->WriteNumeric(484, "%s %s :You are not permitted to kick services", src->nick.c_str(), c->name.c_str());
00124 return 1;
00125 }
00126
00127 return 0;
00128 }
00129
00130 virtual int OnWhoisLine(User* src, User* dst, int &numeric, std::string &text)
00131 {
00132 return ((src != dst) && (numeric == 319) && dst->IsModeSet('k'));
00133 }
00134 };
00135
00136
00137 MODULE_INIT(ModuleServProtectMode)