m_nicklock.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "inspircd.h"
00015
00016
00017
00020 class CommandNicklock : public Command
00021 {
00022 char* dummy;
00023 public:
00024 CommandNicklock (InspIRCd* Instance) : Command(Instance,"NICKLOCK", "o", 2)
00025 {
00026 this->source = "m_nicklock.so";
00027 syntax = "<oldnick> <newnick>";
00028 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
00029 }
00030
00031 CmdResult Handle(const std::vector<std::string>& parameters, User *user)
00032 {
00033 User* target = ServerInstance->FindNick(parameters[0]);
00034 irc::string server;
00035 irc::string me;
00036
00037
00038 if (!target)
00039 {
00040 return CMD_FAILURE;
00041 }
00042
00043
00044 if (target->GetExt("nick_locked", dummy))
00045 {
00046 user->WriteNumeric(946, "%s %s :This user's nickname is already locked.",user->nick.c_str(),target->nick.c_str());
00047 return CMD_FAILURE;
00048 }
00049
00050
00051 if (IS_LOCAL(user) && !ServerInstance->IsNick(parameters[1].c_str(), ServerInstance->Config->Limits.NickMax))
00052 {
00053 return CMD_FAILURE;
00054 }
00055
00056
00057 ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" used NICKLOCK to change and hold "+parameters[0]+" to "+parameters[1]);
00058
00059 if (!target->ForceNickChange(parameters[1].c_str()))
00060 {
00061
00062 if (!target->ForceNickChange(target->uuid.c_str()))
00063 {
00064
00065 ServerInstance->Users->QuitUser(target, "Nickname collision");
00066 }
00067 }
00068
00069
00070 target->Extend("nick_locked", "ON");
00071
00072
00073 return CMD_SUCCESS;
00074 }
00075 };
00076
00079 class CommandNickunlock : public Command
00080 {
00081 public:
00082 CommandNickunlock (InspIRCd* Instance) : Command(Instance,"NICKUNLOCK", "o", 1)
00083 {
00084 this->source = "m_nicklock.so";
00085 syntax = "<locked-nick>";
00086 }
00087
00088 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
00089 {
00090 User* target = ServerInstance->FindNick(parameters[0]);
00091 if (target)
00092 {
00093 target->Shrink("nick_locked");
00094 user->WriteNumeric(945, "%s %s :Nickname now unlocked.",user->nick.c_str(),target->nick.c_str());
00095 ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" used NICKUNLOCK on "+parameters[0]);
00096 return CMD_SUCCESS;
00097 }
00098
00099 return CMD_FAILURE;
00100 }
00101 };
00102
00103
00104 class ModuleNickLock : public Module
00105 {
00106 CommandNicklock* cmd1;
00107 CommandNickunlock* cmd2;
00108 char* n;
00109 public:
00110 ModuleNickLock(InspIRCd* Me)
00111 : Module(Me)
00112 {
00113
00114 cmd1 = new CommandNicklock(ServerInstance);
00115 cmd2 = new CommandNickunlock(ServerInstance);
00116 ServerInstance->AddCommand(cmd1);
00117 ServerInstance->AddCommand(cmd2);
00118 Implementation eventlist[] = { I_OnUserPreNick, I_OnUserQuit, I_OnCleanup };
00119 ServerInstance->Modules->Attach(eventlist, this, 3);
00120 }
00121
00122 virtual ~ModuleNickLock()
00123 {
00124 }
00125
00126 virtual Version GetVersion()
00127 {
00128 return Version("$Id: m_nicklock.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_COMMON | VF_VENDOR, API_VERSION);
00129 }
00130
00131
00132 virtual int OnUserPreNick(User* user, const std::string &newnick)
00133 {
00134 if (isdigit(newnick[0]))
00135 return 0;
00136
00137 if (user->GetExt("nick_locked", n))
00138 {
00139 user->WriteNumeric(447, "%s :You cannot change your nickname (your nick is locked)",user->nick.c_str());
00140 return 1;
00141 }
00142 return 0;
00143 }
00144
00145 virtual void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
00146 {
00147 user->Shrink("nick_locked");
00148 }
00149
00150 virtual void OnCleanup(int target_type, void* item)
00151 {
00152 if(target_type == TYPE_USER)
00153 {
00154 User* user = (User*)item;
00155 user->Shrink("nick_locked");
00156 }
00157 }
00158 };
00159
00160 MODULE_INIT(ModuleNickLock)