public:
std::string matchtext;
- Shun(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char *shunmask) : XLine(Instance, s_time, d, src, re, "S")
+ Shun(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char *shunmask) : XLine(Instance, s_time, d, src, re, "SHUN")
{
this->matchtext = shunmask;
}
return false;
}
- // XXX unused, why do we *have* to implement this
bool Matches(const std::string &s)
{
+ if (matchtext == s)
+ return true;
return false;
}
void Apply(User *u)
{
- // Application is done by the module.
+ if (!u->GetExt("shunned"))
+ u->Extend("shunned");
}
}
};
+/** An XLineFactory specialized to generate shun pointers
+ */
+class ShunFactory : public XLineFactory
+{
+ public:
+ ShunFactory(InspIRCd* Instance) : XLineFactory(Instance, "SHUN") { }
+
+ /** Generate a shun
+ */
+ XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
+ {
+ return new Shun(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
+ }
+};
+
//typedef std::vector<Shun> shunlist;
class cmd_shun : public Command
if(pcnt == 1)
{
- if (ServerInstance->XLines->DelLine(parameters[0], "S", user))
+ if (ServerInstance->XLines->DelLine(parameters[0], "SHUN", user))
{
ServerInstance->SNO->WriteToSnoMask('x',"%s Removed shun on %s.",user->nick,parameters[0]);
}
class ModuleShun : public Module
{
cmd_shun* mycommand;
+ ShunFactory *f;
public:
ModuleShun(InspIRCd* Me) : Module(Me)
{
+ f = new ShunFactory(ServerInstance);
+ ServerInstance->XLines->RegisterFactory(f);
+
mycommand = new cmd_shun(ServerInstance);
ServerInstance->AddCommand(mycommand);
+
+ Implementation eventlist[] = { I_OnStats, I_OnPreCommand, I_OnUserConnect };
+ ServerInstance->Modules->Attach(eventlist, this, 3);
}
- void Implements(char* List)
+ virtual ~ModuleShun()
{
- List[I_OnPreCommand] = List[I_OnStats] = 1;
+ ServerInstance->XLines->UnregisterFactory(f);
}
-
+
virtual int OnStats(char symbol, User* user, string_list& out)
{
// XXX write me
return 0;
}
+ virtual void OnUserConnect(User* user)
+ {
+ if (!IS_LOCAL(user))
+ return;
+
+ // Apply lines on user connect
+ XLine *rl = ServerInstance->XLines->MatchesLine("SHUN", user);
+
+ if (rl)
+ {
+ // Bang. :P
+ rl->Apply(user);
+ }
+ }
+
virtual int OnPreCommand(const std::string &command, const char* const*parameters, int pcnt, User* user, bool validated, const std::string &original_line)
{
if((command != "PONG") && (command != "PING"))
{
- // Don't let them issue cmd if they are shunned..
- XLine *rl = ServerInstance->XLines->MatchesLine("S", user);
-
- if (rl)
- {
+ if (user->GetExt("shunned"))
return 1;
- }
}
-
- return 0;
- }
- virtual ~ModuleShun()
- {
+ return 0;
}
virtual Version GetVersion()