finalized api by adding limited interception
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401432
This commit is contained in:
parent
c230444274
commit
bb0678c1ac
@ -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,45 +131,48 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool write_ban = ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE);
|
if (!handled)
|
||||||
|
|
||||||
char command[256];
|
|
||||||
if (ban_by_ip)
|
|
||||||
{
|
{
|
||||||
UTIL_Format(
|
bool write_ban = ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE);
|
||||||
command,
|
|
||||||
sizeof(command),
|
|
||||||
"addip %d %s\n",
|
|
||||||
ban_time,
|
|
||||||
identity);
|
|
||||||
engine->ServerCommand(command);
|
|
||||||
|
|
||||||
if (write_ban && ban_time == 0)
|
char command[256];
|
||||||
|
if (ban_by_ip)
|
||||||
{
|
{
|
||||||
engine->ServerCommand("writeip\n");
|
UTIL_Format(
|
||||||
|
command,
|
||||||
|
sizeof(command),
|
||||||
|
"addip %d %s\n",
|
||||||
|
ban_time,
|
||||||
|
identity);
|
||||||
|
engine->ServerCommand(command);
|
||||||
|
|
||||||
|
if (write_ban && ban_time == 0)
|
||||||
|
{
|
||||||
|
engine->ServerCommand("writeip\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (!g_HL2.IsLANServer())
|
||||||
else if (!g_HL2.IsLANServer())
|
|
||||||
{
|
|
||||||
UTIL_Format(
|
|
||||||
command,
|
|
||||||
sizeof(command),
|
|
||||||
"banid %d %s\n",
|
|
||||||
ban_time,
|
|
||||||
identity);
|
|
||||||
engine->ServerCommand(command);
|
|
||||||
|
|
||||||
if (write_ban && ban_time == 0)
|
|
||||||
{
|
{
|
||||||
engine->ServerCommand("writeid\n");
|
UTIL_Format(
|
||||||
|
command,
|
||||||
|
sizeof(command),
|
||||||
|
"banid %d %s\n",
|
||||||
|
ban_time,
|
||||||
|
identity);
|
||||||
|
engine->ServerCommand(command);
|
||||||
|
|
||||||
|
if (write_ban && ban_time == 0)
|
||||||
|
{
|
||||||
|
engine->ServerCommand("writeid\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -195,35 +199,42 @@ 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)
|
||||||
{
|
{
|
||||||
UTIL_Format(
|
if (!handled)
|
||||||
command,
|
{
|
||||||
sizeof(command),
|
UTIL_Format(
|
||||||
"removeip %s\n",
|
command,
|
||||||
identity);
|
sizeof(command),
|
||||||
engine->ServerCommand(command);
|
"removeip %s\n",
|
||||||
engine->ServerCommand("writeip\n");
|
identity);
|
||||||
|
engine->ServerCommand(command);
|
||||||
|
engine->ServerCommand("writeip\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (!g_HL2.IsLANServer())
|
else if (!g_HL2.IsLANServer())
|
||||||
{
|
{
|
||||||
UTIL_Format(
|
if (!handled)
|
||||||
command,
|
{
|
||||||
sizeof(command),
|
UTIL_Format(
|
||||||
"removeid %s\n",
|
command,
|
||||||
identity);
|
sizeof(command),
|
||||||
engine->ServerCommand(command);
|
"removeid %s\n",
|
||||||
engine->ServerCommand("writeid\n");
|
identity);
|
||||||
|
engine->ServerCommand(command);
|
||||||
|
engine->ServerCommand("writeid\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -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,61 +323,68 @@ static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
|
|||||||
kick_message = "Kicked";
|
kick_message = "Kicked";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ban_flags & BANFLAG_IP) == BANFLAG_IP)
|
if (!handled)
|
||||||
{
|
{
|
||||||
/* Get the IP address and strip the port */
|
if ((ban_flags & BANFLAG_IP) == BANFLAG_IP)
|
||||||
char ip[24], *ptr;
|
|
||||||
strncopy(ip, pPlayer->GetIPAddress(), sizeof(ip));
|
|
||||||
if ((ptr = strchr(ip, ':')) != NULL)
|
|
||||||
{
|
{
|
||||||
*ptr = '\0';
|
/* Get the IP address and strip the port */
|
||||||
|
char ip[24], *ptr;
|
||||||
|
strncopy(ip, pPlayer->GetIPAddress(), sizeof(ip));
|
||||||
|
if ((ptr = strchr(ip, ':')) != NULL)
|
||||||
|
{
|
||||||
|
*ptr = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tell the server to ban the ip */
|
||||||
|
char command[256];
|
||||||
|
UTIL_Format(
|
||||||
|
command,
|
||||||
|
sizeof(command),
|
||||||
|
"addip %d %s\n",
|
||||||
|
ban_time,
|
||||||
|
ip);
|
||||||
|
|
||||||
|
/* Kick, then ban */
|
||||||
|
if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
|
||||||
|
{
|
||||||
|
pClient->Disconnect("%s", kick_message);
|
||||||
|
}
|
||||||
|
engine->ServerCommand(command);
|
||||||
|
|
||||||
|
/* Physically write the ban */
|
||||||
|
if ((ban_time == 0) && ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE))
|
||||||
|
{
|
||||||
|
engine->ServerCommand("writeip\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ((ban_flags & BANFLAG_AUTHID) == BANFLAG_AUTHID)
|
||||||
|
{
|
||||||
|
/* Tell the server to ban the auth string */
|
||||||
|
char command[256];
|
||||||
|
UTIL_Format(
|
||||||
|
command,
|
||||||
|
sizeof(command),
|
||||||
|
"banid %d %s\n",
|
||||||
|
ban_time,
|
||||||
|
pPlayer->GetAuthString());
|
||||||
|
|
||||||
|
/* Kick, then ban */
|
||||||
|
if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
|
||||||
|
{
|
||||||
|
pClient->Disconnect("%s", kick_message);
|
||||||
|
}
|
||||||
|
engine->ServerCommand(command);
|
||||||
|
|
||||||
|
/* Physically write the ban if it's permanent */
|
||||||
|
if ((ban_time == 0) && ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE))
|
||||||
|
{
|
||||||
|
engine->ServerCommand("writeid\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Tell the server to ban the ip */
|
else if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
|
||||||
char command[256];
|
|
||||||
UTIL_Format(
|
|
||||||
command,
|
|
||||||
sizeof(command),
|
|
||||||
"addip %d %s\n",
|
|
||||||
ban_time,
|
|
||||||
ip);
|
|
||||||
|
|
||||||
/* Kick, then ban */
|
|
||||||
if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
|
|
||||||
{
|
|
||||||
pClient->Disconnect("%s", kick_message);
|
|
||||||
}
|
|
||||||
engine->ServerCommand(command);
|
|
||||||
|
|
||||||
/* Physically write the ban */
|
|
||||||
if ((ban_time == 0) && ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE))
|
|
||||||
{
|
|
||||||
engine->ServerCommand("writeip\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ((ban_flags & BANFLAG_AUTHID) == BANFLAG_AUTHID)
|
|
||||||
{
|
{
|
||||||
/* Tell the server to ban the auth string */
|
pClient->Disconnect("%s", kick_message);
|
||||||
char command[256];
|
|
||||||
UTIL_Format(
|
|
||||||
command,
|
|
||||||
sizeof(command),
|
|
||||||
"banid %d %s\n",
|
|
||||||
ban_time,
|
|
||||||
pPlayer->GetAuthString());
|
|
||||||
|
|
||||||
/* Kick, then ban */
|
|
||||||
if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
|
|
||||||
{
|
|
||||||
pClient->Disconnect("%s", kick_message);
|
|
||||||
}
|
|
||||||
engine->ServerCommand(command);
|
|
||||||
|
|
||||||
/* Physically write the ban if it's permanent */
|
|
||||||
if ((ban_time == 0) && ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE))
|
|
||||||
{
|
|
||||||
engine->ServerCommand("writeid\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user