- added 3 new natives for banning/unbanning and interception

- moved banning commands into new plugin, basebans
- improved quality and input methods of ban commands
- corrected svn props on a few files
- added an IsLANServer() to IGameHelpers API
- completely deprecated and removed old banning forwards

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401429
This commit is contained in:
David Anderson 2007-09-14 02:11:10 +00:00
parent f968fc1293
commit 74b23aebfe
14 changed files with 854 additions and 303 deletions

View File

@ -37,6 +37,7 @@
CHalfLife2 g_HL2;
bool g_IsOriginalEngine = false;
ConVar *sv_lan = NULL;
namespace SourceHook
{
@ -369,3 +370,16 @@ void CHalfLife2::ProcessFakeCliCmdQueue()
m_CmdQueue.pop();
}
}
bool CHalfLife2::IsLANServer()
{
sv_lan = icvar->FindVar("sv_lan");
if (!sv_lan)
{
return false;
}
return (sv_lan->GetInt() != 0);
}

View File

@ -86,6 +86,7 @@ public: //IGameHelpers
bool TextMsg(int client, int dest, const char *msg);
bool HintTextMsg(int client, const char *msg);
bool ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show);
bool IsLANServer();
public:
void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
void ProcessFakeCliCmdQueue();

View File

@ -27,7 +27,8 @@ OBJECTS = AdminCache.cpp CDataPack.cpp ConCmdManager.cpp ConVarManager.cpp CoreC
frame_hooks.cpp
OBJECTS += smn_admin.cpp smn_bitbuffer.cpp smn_console.cpp smn_core.cpp \
smn_datapacks.cpp smn_entities.cpp smn_events.cpp smn_fakenatives.cpp \
smn_filesystem.cpp smn_float.cpp smn_functions.cpp smn_gameconfigs.cpp smn_halflife.cpp smn_handles.cpp smn_keyvalues.cpp \
smn_filesystem.cpp smn_float.cpp smn_functions.cpp smn_gameconfigs.cpp smn_halflife.cpp \
smn_handles.cpp smn_keyvalues.cpp smn_banning.cpp \
smn_lang.cpp smn_player.cpp smn_string.cpp smn_sorting.cpp smn_textparse.cpp smn_timers.cpp \
smn_usermsgs.cpp smn_menus.cpp smn_database.cpp smn_vector.cpp smn_adt_array.cpp
OBJECTS += systems/ExtensionSys.cpp systems/ForwardSys.cpp systems/HandleSys.cpp \

378
core/smn_banning.cpp Normal file
View File

@ -0,0 +1,378 @@
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#include "sm_globals.h"
#include "sm_stringutil.h"
#include "HalfLife2.h"
#include "PlayerManager.h"
#include "ForwardSys.h"
#include <inetchannel.h>
#include <iclient.h>
#define BANFLAG_AUTO (1<<0) /**< Auto-detects whether to ban by steamid or IP */
#define BANFLAG_IP (1<<1) /**< Always ban by IP address */
#define BANFLAG_AUTHID (1<<2) /**< Ban by SteamID */
#define BANFLAG_NOKICK (1<<3) /**< Does not kick the client */
#define BANFLAG_NOWRITE (1<<4) /**< Ban is not written to SourceDS's files if permanent */
IForward *g_pOnBanClient = NULL;
IForward *g_pOnBanIdentity = NULL;
IForward *g_pOnRemoveBan = NULL;
class BanNativeHelpers : public SMGlobalClass
{
public:
void OnSourceModAllInitialized()
{
g_pOnBanClient = g_Forwards.CreateForward(
"OnBanClient",
ET_Ignore,
7,
NULL,
Param_Cell,
Param_Cell,
Param_Cell,
Param_String,
Param_String,
Param_String,
Param_Cell);
g_pOnBanIdentity = g_Forwards.CreateForward(
"OnBanIdentity",
ET_Ignore,
6,
NULL,
Param_String,
Param_Cell,
Param_Cell,
Param_String,
Param_String,
Param_Cell);
g_pOnRemoveBan = g_Forwards.CreateForward(
"OnRemoveBan",
ET_Ignore,
4,
NULL,
Param_String,
Param_Cell,
Param_String,
Param_Cell);
}
void OnSourceModShutdown()
{
g_Forwards.ReleaseForward(g_pOnBanClient);
g_Forwards.ReleaseForward(g_pOnBanIdentity);
g_Forwards.ReleaseForward(g_pOnRemoveBan);
g_pOnBanClient = NULL;
g_pOnBanIdentity = NULL;
g_pOnRemoveBan = NULL;
}
} s_BanNativeHelpers;
static cell_t BanIdentity(IPluginContext *pContext, const cell_t *params)
{
char *r_identity, *ban_reason, *ban_cmd;
int ban_time, ban_flags, ban_source;
pContext->LocalToString(params[1], &r_identity);
pContext->LocalToString(params[4], &ban_reason);
pContext->LocalToString(params[5], &ban_cmd);
ban_time = params[2];
ban_flags = params[3];
ban_source = params[6];
/* Make sure we can ban by one of the two methods! */
bool ban_by_ip = ((ban_flags & BANFLAG_IP) == BANFLAG_IP);
if (!ban_by_ip && ((ban_flags & BANFLAG_AUTHID) != BANFLAG_AUTHID))
{
return pContext->ThrowNativeError("No valid ban flags specified");
}
/* Sanitize the input */
char identity[64];
strncopy(identity, r_identity, sizeof(identity));
UTIL_ReplaceAll(identity, sizeof(identity), ";", "");
if (ban_cmd[0] != '\0' && g_pOnBanIdentity->GetFunctionCount() > 0)
{
g_pOnBanIdentity->PushString(identity);
g_pOnBanIdentity->PushCell(ban_time);
g_pOnBanIdentity->PushCell(ban_flags);
g_pOnBanIdentity->PushString(ban_reason);
g_pOnBanIdentity->PushString(ban_cmd);
g_pOnBanIdentity->PushCell(ban_source);
g_pOnBanIdentity->Execute(NULL);
}
bool write_ban = ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE);
char command[256];
if (ban_by_ip)
{
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())
{
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;
}
return 1;
}
static cell_t RemoveBan(IPluginContext *pContext, const cell_t *params)
{
char *r_identity, *ban_cmd;
int ban_flags, ban_source;
pContext->LocalToString(params[1], &r_identity);
pContext->LocalToString(params[3], &ban_cmd);
ban_flags = params[2];
ban_source = params[4];
/* Make sure we can ban by one of the two methods! */
bool ban_by_ip = ((ban_flags & BANFLAG_IP) == BANFLAG_IP);
if (!ban_by_ip && ((ban_flags & BANFLAG_AUTHID) != BANFLAG_AUTHID))
{
return pContext->ThrowNativeError("No valid ban flags specified");
}
char identity[64];
strncopy(identity, r_identity, sizeof(identity));
UTIL_ReplaceAll(identity, sizeof(identity), ";", "");
if (ban_cmd[0] != '\0' && g_pOnRemoveBan->GetFunctionCount() > 0)
{
g_pOnRemoveBan->PushString(identity);
g_pOnRemoveBan->PushCell(ban_flags);
g_pOnRemoveBan->PushString(ban_cmd);
g_pOnRemoveBan->PushCell(ban_source);
g_pOnRemoveBan->Execute(NULL);
}
char command[256];
if (ban_by_ip)
{
UTIL_Format(
command,
sizeof(command),
"removeip %s\n",
identity);
engine->ServerCommand(command);
engine->ServerCommand("writeip\n");
}
else if (!g_HL2.IsLANServer())
{
UTIL_Format(
command,
sizeof(command),
"removeid %s\n",
identity);
engine->ServerCommand(command);
engine->ServerCommand("writeid\n");
}
else
{
return 0;
}
return 1;
}
static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
{
const char *kick_message;
char *ban_reason, *ban_cmd;
int client, ban_flags, ban_source, ban_time;
client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer || !pPlayer->IsConnected())
{
return pContext->ThrowNativeError("Client index %d is invalid", client);
}
pContext->LocalToString(params[4], &ban_reason);
pContext->LocalToString(params[5], (char **)&kick_message);
pContext->LocalToString(params[6], &ban_cmd);
ban_time = params[2];
ban_flags = params[3];
ban_source = params[7];
INetChannel *pNetChan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(params[1]));
IClient *pClient = static_cast<IClient *>(pNetChan->GetMsgHandler());
/* Check how we should ban the player */
if ((ban_flags & BANFLAG_AUTO) == BANFLAG_AUTO)
{
if (g_HL2.IsLANServer() || !pPlayer->IsAuthorized())
{
ban_flags |= BANFLAG_IP;
ban_flags &= BANFLAG_AUTHID;
}
else
{
ban_flags |= BANFLAG_AUTHID;
ban_flags &= BANFLAG_IP;
}
}
else if ((ban_flags & BANFLAG_IP) == BANFLAG_IP)
{
ban_flags |= BANFLAG_IP;
ban_flags &= BANFLAG_AUTHID;
}
else if ((ban_flags & BANFLAG_AUTHID) == BANFLAG_AUTHID)
{
if (pPlayer->IsAuthorized())
{
ban_flags |= BANFLAG_AUTHID;
ban_flags &= BANFLAG_IP;
}
else
{
return 0;
}
}
else
{
return pContext->ThrowNativeError("No valid ban method flags specified");
}
if (ban_cmd[0] != '\0' && g_pOnBanClient->GetFunctionCount() > 0)
{
g_pOnBanClient->PushCell(client);
g_pOnBanClient->PushCell(ban_time);
g_pOnBanClient->PushCell(ban_flags);
g_pOnBanClient->PushString(ban_reason);
g_pOnBanClient->PushString(kick_message);
g_pOnBanClient->PushString(ban_cmd);
g_pOnBanClient->PushCell(ban_source);
g_pOnBanClient->Execute(NULL);
}
if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
{
/* Build a kick message */
const char *kick_message = "";
pContext->LocalToString(params[5], (char **)&kick_message);
if (kick_message[0] == '\0')
{
kick_message = "Kicked";
}
/* Disconnect the client now */
pClient->Disconnect("%s", kick_message);
}
if ((ban_flags & BANFLAG_IP) == BANFLAG_IP)
{
/* 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);
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());
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");
}
}
return 1;
}
REGISTER_NATIVES(banNatives)
{
{"BanClient", BanClient},
{"BanIdentity", BanIdentity},
{"RemoveBan", RemoveBan},
{NULL, NULL}
};

View File

@ -1142,3 +1142,4 @@ REGISTER_NATIVES(playernatives)
{"NotifyPostAdminCheck", NotifyPostAdminCheck},
{NULL, NULL}
};

284
plugins/basebans.sp Normal file
View File

@ -0,0 +1,284 @@
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod Basic Commands Plugin
* Implements basic admin commands.
*
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#pragma semicolon 1
#include <sourcemod>
public Plugin:myinfo =
{
name = "Basic Ban Commands",
author = "AlliedModders LLC",
description = "Basic Banning Commands",
version = SOURCEMOD_VERSION,
url = "http://www.sourcemod.net/"
};
public OnPluginStart()
{
LoadTranslations("common.phrases");
RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> <minutes|0> [reason]");
RegAdminCmd("sm_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban <steamid>");
RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <time> <steamid> [reason]");
RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_BAN, "sm_banip <time> <ip|#userid|name> [reason]");
}
public Action:Command_BanIp(client, args)
{
if (args < 2)
{
ReplyToCommand(client, "[SM] Usage: sm_banip <time> <ip|#userid|name> [reason]");
return Plugin_Handled;
}
decl String:arg[50], String:time[20];
GetCmdArg(1, time, sizeof(time));
GetCmdArg(2, arg, sizeof(arg));
if (StrEqual(arg, "0"))
{
ReplyToCommand(client, "[SM] %t", "Cannot ban that IP");
return Plugin_Handled;
}
new clients[1];
new numClients = SearchForClients(arg, clients, 1);
new bool:has_rcon;
if (client == 0 || (client == 1 && !IsDedicatedServer()))
{
has_rcon = true;
} else {
new AdminId:id = GetUserAdmin(client);
has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON);
}
new hit_client = -1;
if (numClients == 1
&& !IsFakeClient(clients[0])
&& (has_rcon || CanUserTarget(client, clients[0])))
{
GetClientIP(clients[0], arg, sizeof(arg));
hit_client = clients[0];
}
if (hit_client == -1 && !has_rcon)
{
ReplyToCommand(client, "[SM] %t", "No Access");
return Plugin_Handled;
}
new minutes = StringToInt(time);
decl String:reason[128];
if (args >= 3)
{
GetCmdArg(3, reason, sizeof(reason));
}
LogAction(client,
hit_client,
"\"%L\" added ban (minutes \"%d\") (ip \"%s\") (reason \"%s\")",
client,
minutes,
arg,
reason);
BanIdentity(arg,
minutes,
BANFLAG_IP,
reason,
"sm_banip",
client);
ReplyToCommand(client, "[SM] %t", "Ban added");
return Plugin_Handled;
}
public Action:Command_AddBan(client, args)
{
if (args < 2)
{
ReplyToCommand(client, "[SM] Usage: sm_addban <time> <steamid> [reason]");
return Plugin_Handled;
}
decl String:arg_string[256];
new String:reason[128];
new String:time[50];
new String:authid[50];
GetCmdArgString(arg_string, sizeof(arg_string));
new len, total_len;
/* Get time */
if ((len = BreakString(arg_string, time, sizeof(time))) == -1)
{
ReplyToCommand(client, "t[SM] Usage: sm_addban <time> <steamid> [reason]");
return Plugin_Handled;
}
total_len += len;
/* Get steamid */
if ((len = BreakString(arg_string[total_len], authid, sizeof(authid))) != -1)
{
/* Get reason */
total_len += len;
BreakString(arg_string[total_len], reason, sizeof(reason));
}
/* Verify steamid */
if (strncmp(authid, "STEAM_0:", 8) != 0)
{
ReplyToCommand(client, "[SM] %t", "Invalid SteamID specified");
return Plugin_Handled;
}
new minutes = StringToInt(time);
LogAction(client,
-1,
"\"%L\" added ban (minutes \"%d\") (id \"%s\") (reason \"%s\")",
client,
minutes,
authid,
reason);
BanIdentity(authid,
minutes,
BANFLAG_AUTHID,
reason,
"sm_addban",
client);
ReplyToCommand(client, "[SM] %t", "Ban added");
return Plugin_Handled;
}
public Action:Command_Unban(client, args)
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_unban <steamid|ip>");
return Plugin_Handled;
}
decl String:arg[50];
GetCmdArgString(arg, sizeof(arg));
ReplaceString(arg, sizeof(arg), "\"", "");
new ban_flags;
if (strncmp(arg, "STEAM_0:", 8) == 0)
{
ban_flags |= BANFLAG_AUTHID;
}
else
{
ban_flags |= BANFLAG_IP;
}
LogAction(client, -1, "\"%L\" removed ban (filter \"%s\")", client, arg);
RemoveBan(arg, ban_flags, "sm_unban", client);
ReplyToCommand(client, "[SM] %t", "Removed bans matching", arg);
return Plugin_Handled;
}
public Action:Command_Ban(client, args)
{
if (args < 2)
{
ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]");
return Plugin_Handled;
}
decl String:arg[65];
GetCmdArg(1, arg, sizeof(arg));
new target = FindTarget(client, arg, true);
if (target == -1)
{
return Plugin_Handled;
}
decl String:s_time[12];
GetCmdArg(2, s_time, sizeof(s_time));
new time = StringToInt(s_time);
decl String:reason[128];
if (args >= 3)
{
GetCmdArg(3, reason, sizeof(reason));
} else {
reason[0] = '\0';
}
decl String:authid[64];
GetClientAuthString(target, authid, sizeof(authid));
GetClientName(target, arg, sizeof(arg));
if (!time)
{
if (reason[0] == '\0')
{
ShowActivity(client, "%t", "Permabanned player", arg);
} else {
ShowActivity(client, "%t", "Permabanned player reason", arg, reason);
}
} else {
if (reason[0] == '\0')
{
ShowActivity(client, "%t", "Banned player", arg, time);
} else {
ShowActivity(client, "%t", "Banned player reason", arg, time, reason);
}
}
LogAction(client, target, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, time, reason);
if (reason[0] == '\0')
{
strcopy(reason, sizeof(reason), "Banned");
}
BanClient(target, time, BANFLAG_AUTO, reason, reason, "sm_ban", client);
return Plugin_Handled;
}

View File

@ -44,10 +44,6 @@ public Plugin:myinfo =
url = "http://www.sourcemod.net/"
};
new Handle:hBanForward = INVALID_HANDLE;
new Handle:hAddBanForward = INVALID_HANDLE;
new Handle:hBanRemoved = INVALID_HANDLE;
public OnPluginStart()
{
LoadTranslations("common.phrases");
@ -58,16 +54,8 @@ public OnPluginStart()
RegAdminCmd("sm_cvar", Command_Cvar, ADMFLAG_CONVARS, "sm_cvar <cvar> [value]");
RegAdminCmd("sm_execcfg", Command_ExecCfg, ADMFLAG_CONFIG, "sm_execcfg <filename>");
RegAdminCmd("sm_who", Command_Who, ADMFLAG_GENERIC, "sm_who [#userid|name]");
RegAdminCmd("sm_ban", Command_Ban, ADMFLAG_BAN, "sm_ban <#userid|name> <minutes|0> [reason]");
RegAdminCmd("sm_unban", Command_Unban, ADMFLAG_UNBAN, "sm_unban <steamid>");
RegAdminCmd("sm_addban", Command_AddBan, ADMFLAG_RCON, "sm_addban <time> <steamid> [reason]");
RegAdminCmd("sm_banip", Command_BanIp, ADMFLAG_BAN, "sm_banip <time> <ip|#userid|name> [reason]");
RegAdminCmd("sm_reloadadmins", Command_ReloadAdmins, ADMFLAG_BAN, "sm_reloadadmins");
RegAdminCmd("sm_cancelvote", Command_CancelVote, ADMFLAG_VOTE, "sm_cancelvote");
hBanForward = CreateGlobalForward("OnClientBanned", ET_Hook, Param_Cell, Param_Cell, Param_Cell, Param_String);
hAddBanForward = CreateGlobalForward("OnBanAdded", ET_Hook, Param_Cell, Param_String, Param_Cell, Param_String);
hBanRemoved = CreateGlobalForward("OnBanRemoved", ET_Hook, Param_Cell, Param_String);
}
public Action:Command_ReloadAdmins(client, args)
@ -82,263 +70,6 @@ public Action:Command_ReloadAdmins(client, args)
return Plugin_Handled;
}
public Action:Command_BanIp(client, args)
{
if (args < 2)
{
ReplyToCommand(client, "[SM] Usage: sm_banip <time> <ip|#userid|name> [reason]");
return Plugin_Handled;
}
decl String:arg[50], String:time[20];
GetCmdArg(1, time, sizeof(time));
GetCmdArg(2, arg, sizeof(arg));
if (StrEqual(arg, "0"))
{
ReplyToCommand(client, "[SM] %t", "Cannot ban that IP");
return Plugin_Handled;
}
new clients[1];
new numClients = SearchForClients(arg, clients, 1);
new bool:has_rcon;
if (client == 0 || (client == 1 && !IsDedicatedServer()))
{
has_rcon = true;
} else {
new AdminId:id = GetUserAdmin(client);
has_rcon = (id == INVALID_ADMIN_ID) ? false : GetAdminFlag(id, Admin_RCON);
}
new hit_client = -1;
if (numClients == 1
&& !IsFakeClient(clients[0])
&& (has_rcon || CanUserTarget(client, clients[0])))
{
GetClientIP(clients[0], arg, sizeof(arg));
hit_client = clients[0];
}
if (hit_client == -1 && !has_rcon)
{
ReplyToCommand(client, "[SM] %t", "No Access");
return Plugin_Handled;
}
new minutes = StringToInt(time);
decl String:reason[128];
if (args >= 3)
{
GetCmdArg(3, reason, sizeof(reason));
}
new Action:act = Plugin_Continue;
Call_StartForward(hAddBanForward);
Call_PushCell(client);
Call_PushString(arg);
Call_PushCell(minutes);
Call_PushString(reason);
Call_Finish(act);
if (act < Plugin_Handled)
{
LogAction(client, hit_client, "\"%L\" added ban (minutes \"%d\") (ip \"%s\") (reason \"%s\")", client, minutes, arg, reason);
ReplyToCommand(client, "[SM] %t", "Ban added");
}
if (act < Plugin_Stop)
{
ServerCommand("addip %d %s", minutes, arg);
ServerCommand("writeip");
}
return Plugin_Handled;
}
public Action:Command_AddBan(client, args)
{
if (args < 2)
{
ReplyToCommand(client, "[SM] Usage: sm_addban <time> <steamid> [reason]");
return Plugin_Handled;
}
decl String:arg[50], String:time[20];
GetCmdArg(1, time, sizeof(time));
GetCmdArg(2, arg, sizeof(arg));
new minutes = StringToInt(time);
new String:reason[128];
if (args >= 3)
{
GetCmdArg(3, reason, sizeof(reason));
}
new Action:act = Plugin_Continue;
Call_StartForward(hAddBanForward);
Call_PushCell(client);
Call_PushString(arg);
Call_PushCell(minutes);
Call_PushString(reason);
Call_Finish(act);
if (act < Plugin_Handled)
{
LogAction(client, -1, "\"%L\" added ban (minutes \"%d\") (id \"%s\") (reason \"%s\")", client, minutes, arg, reason);
ReplyToCommand(client, "[SM] %t", "Ban added");
}
if (act < Plugin_Stop)
{
ServerCommand("banid %d %s", minutes, arg);
ServerCommand("writeid");
}
return Plugin_Handled;
}
public Action:Command_Unban(client, args)
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_unban <steamid>");
return Plugin_Handled;
}
decl String:arg[50], String:new_arg[50];
new start=0;
GetCmdArgString(arg, sizeof(arg));
if(arg[start] == '"')
{
start++;
}
if (strncmp(arg[start], "STEAM_0:", 8, false) == 0)
{
start += 8;
} else if (strncmp(arg[start], "0:1:", 4) == 0 || strncmp(arg[start], "0:0:", 4) == 0) {
start += 2;
}
Format(new_arg, sizeof(new_arg), "STEAM_0:%s", arg[start]);
/* Remove white spaces */
new len = TrimString(new_arg);
if(new_arg[len - 1] == '"')
{
new_arg[len - 1] = '\0';
}
new Action:act = Plugin_Continue;
Call_StartForward(hBanRemoved);
Call_PushCell(client);
Call_PushString(new_arg);
Call_Finish(act);
if (act < Plugin_Handled)
{
LogAction(client, -1, "\"%L\" removed ban (filter \"%s\")", client, new_arg);
ReplyToCommand(client, "[SM] %t", "Removed bans matching", new_arg);
}
if (act < Plugin_Stop)
{
ServerCommand("removeid %s", new_arg);
ServerCommand("writeid");
}
return Plugin_Handled;
}
public Action:Command_Ban(client, args)
{
if (args < 2)
{
ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]");
return Plugin_Handled;
}
decl String:arg[65];
GetCmdArg(1, arg, sizeof(arg));
new target = FindTarget(client, arg, true);
if (target == -1)
{
return Plugin_Handled;
}
decl String:s_time[12];
GetCmdArg(2, s_time, sizeof(s_time));
new time = StringToInt(s_time);
decl String:reason[128];
if (args >= 3)
{
GetCmdArg(3, reason, sizeof(reason));
} else {
reason[0] = '\0';
}
decl String:authid[64];
GetClientAuthString(target, authid, sizeof(authid));
GetClientName(target, arg, sizeof(arg));
/* Fire the ban forward */
new Action:act = Plugin_Continue;
Call_StartForward(hBanForward);
Call_PushCell(client);
Call_PushCell(target);
Call_PushCell(time);
Call_PushString(reason);
Call_Finish(act);
if (act < Plugin_Handled)
{
if (!time)
{
if (reason[0] == '\0')
{
ShowActivity(client, "%t", "Permabanned player", arg);
} else {
ShowActivity(client, "%t", "Permabanned player reason", arg, reason);
}
} else {
if (reason[0] == '\0')
{
ShowActivity(client, "%t", "Banned player", arg, time);
} else {
ShowActivity(client, "%t", "Banned player reason", arg, time, reason);
}
}
LogAction(client, target, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, time, reason);
}
if (act < Plugin_Stop)
{
if (reason[0] == '\0')
{
strcopy(reason, sizeof(reason), "Banned");
}
ServerCommand("banid %d %s", time, authid);
KickClient(target, "%s", reason);
if (time == 0)
{
ServerCommand("writeid");
}
}
return Plugin_Handled;
}
#define FLAG_STRINGS 14
new String:g_FlagNames[FLAG_STRINGS][20] =
{

156
plugins/include/banning.inc Normal file
View File

@ -0,0 +1,156 @@
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This file is part of the SourceMod/SourcePawn SDK.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#if defined _banning_included
#endinput
#endif
#define _banning_included
#define BANFLAG_AUTO (1<<0) /**< Auto-detects whether to ban by steamid or IP */
#define BANFLAG_IP (1<<1) /**< Always ban by IP address */
#define BANFLAG_AUTHID (1<<2) /**< Always ban by authstring (for BanIdentity) if possible */
#define BANFLAG_NOKICK (1<<3) /**< Does not kick the client */
/**
* Called for calls to BanClient() with a non-empty command.
*
* @param client Client being banned.
* @param time Time the client is being banned for (0 = permanent).
* @param flags One if AUTHID or IP will be enabled. If AUTO is also
* enabled, it means Core autodetected which to use.
* @param reason Reason passed via BanClient().
* @param kick_message Kick message passed via BanClient().
* @param command Command string to identify the ban source.
* @param source Source value passed via BanClient().
* @noreturn
*/
forward OnBanClient(client,
time,
flags,
const String:reason[],
const String:kick_message[],
const String:command[],
any:source);
/**
* Called for calls to BanIdentity() with a non-empty command.
*
* @param identity Identity string being banned (authstring or ip).
* @param time Time the client is being banned for (0 = permanent).
* @param flags Ban flags (only IP or AUTHID are valid here).
* @param reason Reason passed via BanIdentity().
* @param command Command string to identify the ban source.
* @param source Source value passed via BanIdentity().
* @noreturn
*/
forward OnBanIdentity(const String:identity[],
time,
flags,
const String:reason[],
const String:command[],
any:source);
/**
* Called for calls to RemoveBan() with a non-empty command.
*
* @param identity Identity string being banned (authstring or ip).
* @param flags Ban flags (only IP or AUTHID are valid here).
* @param command Command string to identify the ban source.
* @param source Source value passed via BanIdentity().
* @noreturn
*/
forward OnRemoveBan(const String:identity[],
flags,
const String:command[],
any:source);
/**
* Bans a client.
*
* @param client Client being banned.
* @param time Time (in minutes) to ban (0 = permanent).
* @param flags Flags for controlling the ban mechanism. If AUTHID
* is set and no AUTHID is available, the ban will fail
* unless AUTO is also flagged.
* @param reason Reason to ban the client for.
* @param kick_message Message to display to the user when kicking.
* @param command Command string to identify the source. If this is left
* empty, then the OnBanClient forward will not be called.
* @param source A source value that could be interpreted as a player
* index of any sort (not actually checked by Core).
* @return True on success, false on failure.
* @error Invalid client index or client not in game.
*/
native bool:BanClient(client,
time,
flags,
const String:reason[],
const String:kick_message[]="",
const String:command[]="",
any:source=0);
/**
* Bans an identity (either an IP address or auth string).
*
* @param identity String to ban (ip or authstring).
* @param time Time to ban for (0 = permanent).
* @param flags Flags (only IP and AUTHID are valid flags here).
* @param reason Ban reason string.
* @param command Command string to identify the source. If this is left
* empty, then the OnBanIdentity forward will not be called.
* @param source A source value that could be interpreted as a player
* index of any sort (not actually checked by Core).
* @return True on success, false on failure.
*/
native bool:BanIdentity(const String:identity[],
time,
flags,
const String:reason[],
const String:command[]="",
any:source=0);
/**
* Removes a ban that was written to the server (either in memory or on disk).
*
* @param identity String to unban (ip or authstring).
* @param flags Flags (only IP and AUTHID are valid flags here).
* @param command Command strnig to identify the source. If this is left
* empty, then OnRemoveBan will not be called.
* @param source A source value that could be interpreted as a player
* index of any sort (not actually checked by Core).
* @return True on success, false on failure.
*/
native bool:RemoveBan(const String:identity[],
flags,
const String:command[]="",
any:source=0);

View File

@ -603,3 +603,4 @@ native KickClient(client, const String:format[]="", any:...);
* mod support.
*/
native ChangeClientTeam(client, team);

View File

@ -35,37 +35,6 @@
#endif
#define _helpers_included
/**
* Provided by basecommands.sp when sm_ban is called.
*
* @param admin Admin client index (0 for server).
* @param client Client index which will be banned.
* @param time Minutes banned for (0 is permanent).
* @param reason Ban reason (may be empty if none exists).
* @return Pl_Handled to block output, Pl_Stop to block output and action.
*/
forward Action:OnClientBanned(admin, client, time, const String:reason[]);
/**
* Provided by basecommands.sp when sm_addban or sm_banip is called.
*
* @param admin Admin client index (0 for server).
* @param info User info (either steamid or ip).
* @param time Minutes banned for (0 is permanent).
* @param reason Ban reason (may be empty if none exists).
* @return Pl_Handled to block output, Pl_Stop to block output and action.
*/
forward Action:OnBanAdded(admin, const String:info[], time, const String:reason[]);
/**
* Provided by basecommands.sp when sm_unban or sm_unbanip is called.
*
* @param admin Admin client index (0 for server).
* @param info User info (either steamid or ip).
* @return Pl_Handled to block output, Pl_Stop to block output and action.
*/
forward Action:OnBanRemoved(admin, const String:info[]);
/**
* Formats a user's info as log text. This is usually not needed because
* %L can be used to auto-format client information into a string.

View File

@ -69,6 +69,7 @@ struct Plugin
#include <menus>
#include <halflife>
#include <adt>
#include <banning>
/**
* Declare this as a struct in your plugin to expose its information.

View File

@ -39,7 +39,7 @@
#include <edict.h>
#define SMINTERFACE_GAMEHELPERS_NAME "IGameHelpers"
#define SMINTERFACE_GAMEHELPERS_VERSION 1
#define SMINTERFACE_GAMEHELPERS_VERSION 2
/**
* @file IGameHelpers.h
@ -111,6 +111,13 @@ namespace SourceMod
* @return True on success, false on failure.
*/
virtual bool TextMsg(int client, int dest, const char *msg) =0;
/**
* @brief Returns whether the server ls a LAN server.
*
* @return True if LAN server, false otherwise.
*/
virtual bool IsLANServer() =0;
};
}

View File

@ -154,7 +154,7 @@ namespace builder
*/
public override Plugin [] GetPlugins()
{
Plugin [] plugins = new Plugin[14];
Plugin [] plugins = new Plugin[15];
plugins[0] = new Plugin("admin-flatfile", "admin-flatfile");
plugins[1] = new Plugin("adminhelp");
@ -170,6 +170,7 @@ namespace builder
plugins[11] = new Plugin("admin-sql-prefetch", true);
plugins[12] = new Plugin("admin-sql-threaded", true);
plugins[13] = new Plugin("sql-admin-manager", true);
plugins[14] = new Plugin("basebans");
return plugins;
}

View File

@ -231,4 +231,10 @@
{
"en" "You cannot ban that IP address."
}
"Invalid SteamID specified"
{
"en" "You have specified an invalid Steam ID (must start with 'STEAM_0:')."
}
}