mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-10 19:19:02 -04:00
Added interface 'ChannelBanList' that these two modules implement. Send a request class ListModeRequest to the module to check if a user is matched on a channel:
const char* ismatched = ListModeRequest(this, targetmodule, someuser, somechan).Send(); ismatched will be NULL if theyre not matched by the modules list, or will contain the mask if they are matched. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6325 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
parent
16e251d74a
commit
8c14f0f530
@ -62,6 +62,21 @@ public:
|
||||
typedef std::vector<ListItem> modelist;
|
||||
typedef std::vector<ListLimit> limitlist;
|
||||
|
||||
class ListModeRequest : public Request
|
||||
{
|
||||
public:
|
||||
userrec* user;
|
||||
chanrec* chan;
|
||||
|
||||
ListModeRequest(Module* sender, Module* target, userrec* u, chanrec* c) : Request(sender, target, "LM_CHECKLIST"), user(u), chan(c)
|
||||
{
|
||||
}
|
||||
|
||||
~ListModeRequest()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/** The base class for listmodes defined by u_listmode.h
|
||||
*/
|
||||
class ListModeBase : public ModeHandler
|
||||
|
@ -54,12 +54,13 @@ public:
|
||||
be = new BanException(ServerInstance);
|
||||
if (!ServerInstance->AddMode(be, 'e'))
|
||||
throw ModuleException("Could not add new modes!");
|
||||
ServerInstance->PublishInterface("ChannelBanList", this);
|
||||
}
|
||||
|
||||
virtual void Implements(char* List)
|
||||
{
|
||||
be->DoImplements(List);
|
||||
List[I_On005Numeric] = List[I_OnCheckBan] = 1;
|
||||
List[I_OnRequest] = List[I_On005Numeric] = List[I_OnCheckBan] = 1;
|
||||
}
|
||||
|
||||
virtual void On005Numeric(std::string &output)
|
||||
@ -112,7 +113,33 @@ public:
|
||||
{
|
||||
be->DoRehash();
|
||||
}
|
||||
|
||||
|
||||
virtual char* OnRequest(Request* request)
|
||||
{
|
||||
ListModeRequest* LM = (ListModeRequest*)request;
|
||||
if (strcmp("LM_CHECKLIST", request->GetId()) == 0)
|
||||
{
|
||||
modelist* list;
|
||||
LM->chan->GetExt(be->GetInfoKey(), list);
|
||||
if (list)
|
||||
{
|
||||
char mask[MAXBUF];
|
||||
snprintf(mask, MAXBUF, "%s!%s@%s", LM->user->nick, LM->user->ident, LM->user->GetIPString());
|
||||
for (modelist::iterator it = list->begin(); it != list->end(); it++)
|
||||
{
|
||||
if (ServerInstance->MatchText(LM->user->GetFullRealHost(), it->mask) || ServerInstance->MatchText(LM->user->GetFullHost(), it->mask) ||
|
||||
(match(mask, it->mask.c_str(), true)))
|
||||
{
|
||||
// They match an entry
|
||||
return (char*)it->mask.c_str();
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual Version GetVersion()
|
||||
{
|
||||
return Version(1, 1, 0, 3, VF_COMMON | VF_VENDOR, API_VERSION);
|
||||
@ -121,7 +148,8 @@ public:
|
||||
virtual ~ModuleBanException()
|
||||
{
|
||||
ServerInstance->Modes->DelMode(be);
|
||||
DELETE(be);
|
||||
DELETE(be);
|
||||
ServerInstance->UnpublishInterface("ChannelBanList", this);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
* See: http://www.inspircd.org/wiki/index.php/Credits
|
||||
*
|
||||
* This program is free but copyrighted software; see
|
||||
* the file COPYING for details.
|
||||
* the file COPYING for details.
|
||||
*
|
||||
* ---------------------------------------------------
|
||||
*/
|
||||
@ -51,12 +51,13 @@ public:
|
||||
ie = new InviteException(ServerInstance);
|
||||
if (!ServerInstance->AddMode(ie, 'I'))
|
||||
throw ModuleException("Could not add new modes!");
|
||||
ServerInstance->PublishInterface("ChannelBanList", this);
|
||||
}
|
||||
|
||||
|
||||
virtual void Implements(char* List)
|
||||
{
|
||||
ie->DoImplements(List);
|
||||
List[I_On005Numeric] = List[I_OnCheckInvite] = 1;
|
||||
List[I_OnRequest] = List[I_On005Numeric] = List[I_OnCheckInvite] = 1;
|
||||
}
|
||||
|
||||
virtual void On005Numeric(std::string &output)
|
||||
@ -89,6 +90,32 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual char* OnRequest(Request* request)
|
||||
{
|
||||
ListModeRequest* LM = (ListModeRequest*)request;
|
||||
if (strcmp("LM_CHECKLIST", request->GetId()) == 0)
|
||||
{
|
||||
modelist* list;
|
||||
LM->chan->GetExt(ie->GetInfoKey(), list);
|
||||
if (list)
|
||||
{
|
||||
char mask[MAXBUF];
|
||||
snprintf(mask, MAXBUF, "%s!%s@%s", LM->user->nick, LM->user->ident, LM->user->GetIPString());
|
||||
for (modelist::iterator it = list->begin(); it != list->end(); it++)
|
||||
{
|
||||
if (ServerInstance->MatchText(LM->user->GetFullRealHost(), it->mask) || ServerInstance->MatchText(LM->user->GetFullHost(), it->mask) ||
|
||||
(match(mask, it->mask.c_str(), true)))
|
||||
{
|
||||
// They match an entry
|
||||
return (char*)it->mask.c_str();
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual void OnCleanup(int target_type, void* item)
|
||||
{
|
||||
ie->DoCleanup(target_type, item);
|
||||
@ -118,6 +145,7 @@ public:
|
||||
{
|
||||
ServerInstance->Modes->DelMode(ie);
|
||||
DELETE(ie);
|
||||
ServerInstance->UnpublishInterface("ChannelBanList", this);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user