finalized api by adding limited interception

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401432
This commit is contained in:
David Anderson 2007-09-14 03:01:14 +00:00
parent c230444274
commit bb0678c1ac

View File

@ -54,7 +54,7 @@ public:
{ {
g_pOnBanClient = g_Forwards.CreateForward( g_pOnBanClient = g_Forwards.CreateForward(
"OnBanClient", "OnBanClient",
ET_Ignore, ET_Event,
7, 7,
NULL, NULL,
Param_Cell, Param_Cell,
@ -66,7 +66,7 @@ public:
Param_Cell); Param_Cell);
g_pOnBanIdentity = g_Forwards.CreateForward( g_pOnBanIdentity = g_Forwards.CreateForward(
"OnBanIdentity", "OnBanIdentity",
ET_Ignore, ET_Event,
6, 6,
NULL, NULL,
Param_String, Param_String,
@ -77,7 +77,7 @@ public:
Param_Cell); Param_Cell);
g_pOnRemoveBan = g_Forwards.CreateForward( g_pOnRemoveBan = g_Forwards.CreateForward(
"OnRemoveBan", "OnRemoveBan",
ET_Ignore, ET_Event,
4, 4,
NULL, NULL,
Param_String, Param_String,
@ -122,6 +122,7 @@ static cell_t BanIdentity(IPluginContext *pContext, const cell_t *params)
strncopy(identity, r_identity, sizeof(identity)); strncopy(identity, r_identity, sizeof(identity));
UTIL_ReplaceAll(identity, sizeof(identity), ";", ""); UTIL_ReplaceAll(identity, sizeof(identity), ";", "");
cell_t handled = 0;
if (ban_cmd[0] != '\0' && g_pOnBanIdentity->GetFunctionCount() > 0) if (ban_cmd[0] != '\0' && g_pOnBanIdentity->GetFunctionCount() > 0)
{ {
g_pOnBanIdentity->PushString(identity); g_pOnBanIdentity->PushString(identity);
@ -130,9 +131,11 @@ static cell_t BanIdentity(IPluginContext *pContext, const cell_t *params)
g_pOnBanIdentity->PushString(ban_reason); g_pOnBanIdentity->PushString(ban_reason);
g_pOnBanIdentity->PushString(ban_cmd); g_pOnBanIdentity->PushString(ban_cmd);
g_pOnBanIdentity->PushCell(ban_source); g_pOnBanIdentity->PushCell(ban_source);
g_pOnBanIdentity->Execute(NULL); g_pOnBanIdentity->Execute(&handled);
} }
if (!handled)
{
bool write_ban = ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE); bool write_ban = ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE);
char command[256]; char command[256];
@ -170,6 +173,7 @@ static cell_t BanIdentity(IPluginContext *pContext, const cell_t *params)
{ {
return 0; return 0;
} }
}
return 1; return 1;
} }
@ -195,17 +199,20 @@ static cell_t RemoveBan(IPluginContext *pContext, const cell_t *params)
strncopy(identity, r_identity, sizeof(identity)); strncopy(identity, r_identity, sizeof(identity));
UTIL_ReplaceAll(identity, sizeof(identity), ";", ""); UTIL_ReplaceAll(identity, sizeof(identity), ";", "");
cell_t handled = 0;
if (ban_cmd[0] != '\0' && g_pOnRemoveBan->GetFunctionCount() > 0) if (ban_cmd[0] != '\0' && g_pOnRemoveBan->GetFunctionCount() > 0)
{ {
g_pOnRemoveBan->PushString(identity); g_pOnRemoveBan->PushString(identity);
g_pOnRemoveBan->PushCell(ban_flags); g_pOnRemoveBan->PushCell(ban_flags);
g_pOnRemoveBan->PushString(ban_cmd); g_pOnRemoveBan->PushString(ban_cmd);
g_pOnRemoveBan->PushCell(ban_source); g_pOnRemoveBan->PushCell(ban_source);
g_pOnRemoveBan->Execute(NULL); g_pOnRemoveBan->Execute(&handled);
} }
char command[256]; char command[256];
if (ban_by_ip) if (ban_by_ip)
{
if (!handled)
{ {
UTIL_Format( UTIL_Format(
command, command,
@ -215,7 +222,10 @@ static cell_t RemoveBan(IPluginContext *pContext, const cell_t *params)
engine->ServerCommand(command); engine->ServerCommand(command);
engine->ServerCommand("writeip\n"); engine->ServerCommand("writeip\n");
} }
}
else if (!g_HL2.IsLANServer()) else if (!g_HL2.IsLANServer())
{
if (!handled)
{ {
UTIL_Format( UTIL_Format(
command, command,
@ -225,6 +235,7 @@ static cell_t RemoveBan(IPluginContext *pContext, const cell_t *params)
engine->ServerCommand(command); engine->ServerCommand(command);
engine->ServerCommand("writeid\n"); engine->ServerCommand("writeid\n");
} }
}
else else
{ {
return 0; return 0;
@ -293,6 +304,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
return pContext->ThrowNativeError("No valid ban method flags specified"); return pContext->ThrowNativeError("No valid ban method flags specified");
} }
cell_t handled = 0;
if (ban_cmd[0] != '\0' && g_pOnBanClient->GetFunctionCount() > 0) if (ban_cmd[0] != '\0' && g_pOnBanClient->GetFunctionCount() > 0)
{ {
g_pOnBanClient->PushCell(client); g_pOnBanClient->PushCell(client);
@ -302,7 +314,7 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
g_pOnBanClient->PushString(kick_message); g_pOnBanClient->PushString(kick_message);
g_pOnBanClient->PushString(ban_cmd); g_pOnBanClient->PushString(ban_cmd);
g_pOnBanClient->PushCell(ban_source); g_pOnBanClient->PushCell(ban_source);
g_pOnBanClient->Execute(NULL); g_pOnBanClient->Execute(&handled);
} }
/* Sanitize the kick message */ /* Sanitize the kick message */
@ -311,6 +323,8 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
kick_message = "Kicked"; kick_message = "Kicked";
} }
if (!handled)
{
if ((ban_flags & BANFLAG_IP) == BANFLAG_IP) if ((ban_flags & BANFLAG_IP) == BANFLAG_IP)
{ {
/* Get the IP address and strip the port */ /* Get the IP address and strip the port */
@ -367,6 +381,11 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
engine->ServerCommand("writeid\n"); engine->ServerCommand("writeid\n");
} }
} }
}
else if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
{
pClient->Disconnect("%s", kick_message);
}
return 1; return 1;