- /*
- SourceMod Anti-Cheat
- Copyright (C) 2011-2016 SMAC Development Team
- Copyright (C) 2007-2011 CodingDirect LLC
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- 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/>.
- */
- #pragma semicolon 1
- #pragma newdecls required
- /* SM Includes */
- #include <sourcemod>
- #include <sdktools>
- #include <smac>
- #include <colors>
- /* Plugin Info */
- public Plugin myinfo =
- {
- name = "SourceMod Anti-Cheat",
- author = SMAC_AUTHOR,
- description = "Open source anti-cheat plugin for SourceMod",
- version = SMAC_VERSION,
- url = SMAC_URL
- };
- /* Globals */
- #define SOURCEBANS_AVAILABLE() (GetFeatureStatus(FeatureType_Native, "SBBanPlayer") == FeatureStatus_Available) // Depreciated in SB++, leaving in for legacy/compatibility!
- #define SBPP_AVAILABLE() (GetFeatureStatus(FeatureType_Native, "SBPP_BanPlayer") == FeatureStatus_Available)
- #define SOURCEIRC_AVAILABLE() (GetFeatureStatus(FeatureType_Native, "IRC_MsgFlaggedChannels") == FeatureStatus_Available)
- #define IRCRELAY_AVAILABLE() (GetFeatureStatus(FeatureType_Native, "IRC_Broadcast") == FeatureStatus_Available)
- enum IrcChannel
- {
- IrcChannel_Public = 1,
- IrcChannel_Private = 2,
- IrcChannel_Both = 3
- }
- native void SBBanPlayer(int client,int target,int time, char[] reason); // Depreciated in SB++, leaving in for legacy/compatibility!
- native void SBPP_BanPlayer(int client,int target,int time, char[] reason);
- GameType g_Game = Game_Unknown;
- ConVar g_hCvarVersion = null;
- ConVar g_hCvarWelcomeMsg = null;
- ConVar g_hCvarBanDuration = null;
- ConVar g_hCvarLogVerbose = null;
- ConVar g_hCvarIrcMode = null;
- char g_sLogPath[PLATFORM_MAX_PATH];
- /* Plugin Functions */
- public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
- {
- // Detect game.
- char sGame[64];
- EngineVersion iEngine = GetEngineVersion();
- /*
- Notes: Removed GMOD support as SourceMod doesn't support Gmod anymore.
- Todo: Figure out which EngineVersion INSMod, FoF, HL2CTF, HIDDEN and ZPS use
- from https://sm.alliedmods.net/new-api/halflife/EngineVersion
- Those could be switched over too. Also, is cstrike_beta even still a thing?
- */
- if (iEngine == Engine_TF2)
- {
- g_Game = Game_TF2;
- }
- else if (iEngine == Engine_CSS)
- {
- g_Game = Game_CSS;
- }
- else if (iEngine == Engine_CSGO)
- {
- g_Game = Game_CSGO;
- }
- else if (iEngine == Engine_DODS)
- {
- g_Game = Game_DODS;
- }
- else if (iEngine == Engine_Left4Dead)
- {
- g_Game = Game_L4D;
- }
- else if (iEngine == Engine_Left4Dead2)
- {
- g_Game = Game_L4D2;
- }
- else if (iEngine == Engine_HL2DM)
- {
- g_Game = Game_HL2DM;
- }
- else if (iEngine == Engine_NuclearDawn)
- {
- g_Game = Game_ND;
- }
- else if (iEngine == Engine_Insurgency)
- {
- g_Game = Game_INS;
- }
- else if (iEngine == Engine_BlackMesa)
- {
- g_Game = Game_BM;
- }
- else if (iEngine == Engine_SDK2013)
- {
- if (StrEqual(sGame, "fof"))
- {
- g_Game = Game_FOF;
- }
- else if (StrEqual(sGame, "zps"))
- {
- g_Game = Game_ZPS;
- }
- else if (StrEqual(sGame, "zps"))
- {
- g_Game = Game_ZMR;
- }
- else
- {
- g_Game = Game_Unknown;
- }
- }
- else if (iEngine == Engine_SourceSDK2006)
- {
- if (StrEqual(sGame, "hl2ctf"))
- {
- g_Game = Game_HL2CTF;
- }
- else if (StrEqual(sGame, "hidden"))
- {
- g_Game = Game_HIDDEN;
- }
- else
- {
- g_Game = Game_Unknown;
- }
- }
- else if (iEngine == Engine_Unknown)
- {
- g_Game = Game_Unknown;
- }
- else
- {
- g_Game = Game_Unknown;
- }
- // Path used for logging.
- // Optional dependencies.
- API_Init();
- return APLRes_Success;
- }
- {
- // Convars.
- g_hCvarVersion = CreateConVar("smac_version", SMAC_VERSION, "SourceMod Anti-Cheat", FCVAR_NOTIFY|FCVAR_DONTRECORD);
- OnVersionChanged(g_hCvarVersion, "", "");
- g_hCvarVersion.AddChangeHook(OnVersionChanged);
- g_hCvarWelcomeMsg = CreateConVar("smac_welcomemsg", "0", "Display a message saying that your server is protected.", 0, true, 0.0, true, 1.0);
- g_hCvarBanDuration = CreateConVar("smac_ban_duration", "0", "The duration in minutes used for automatic bans. (0 = Permanent)", 0, true, 0.0);
- g_hCvarLogVerbose = CreateConVar("smac_log_verbose", "0", "Include extra information about a client being logged.", 0, true, 0.0, true, 1.0);
- g_hCvarIrcMode = CreateConVar("smac_irc_mode", "1", "Which messages should be sent to IRC plugins. (1 = Admin notices, 2 = Mimic log)", 0, true, 1.0, true, 2.0);
- // Commands.
- }
- {
- // Don't clutter the config if they aren't using IRC anyway.
- if (!SOURCEIRC_AVAILABLE() && !IRCRELAY_AVAILABLE())
- {
- g_hCvarVersion.Flags |= FCVAR_DONTRECORD;
- }
- // Wait for other modules to create their convars.
- }
- public void OnVersionChanged(ConVar convar, char[] oldValue, char[] newValue)
- {
- if (!StrEqual(newValue, SMAC_VERSION))
- {
- convar.SetString(SMAC_VERSION, false, false);
- }
- }
- {
- if (g_hCvarWelcomeMsg.BoolValue)
- {
- }
- }
- public Action Timer_WelcomeMsg(Handle timer, any serial)
- {
- {
- CPrintToChat(client, "%t%t", "SMAC_Tag", "SMAC_WelcomeMsg");
- }
- return Plugin_Stop;
- }
- public Action Command_Status(int client, int args)
- {
- char sAuthID[MAX_AUTHID_LENGTH];
- for (int i = 1; i <= MaxClients; i++)
- {
- {
- continue;
- }
- if (!GetClientAuthId(i, AuthId_Steam2, sAuthID, sizeof(sAuthID), true))
- {
- if (GetClientAuthId(i, AuthId_Steam2, sAuthID, sizeof(sAuthID), false))
- {
- }
- else
- {
- }
- }
- }
- return Plugin_Handled;
- }
- {
- char sBuffer[256];
- if (SOURCEIRC_AVAILABLE())
- {
- IRC_MsgFlaggedChannels("ticket", sBuffer);
- }
- if (IRCRELAY_AVAILABLE())
- {
- IRC_Broadcast(IrcChannel_Private, sBuffer);
- }
- }
- /* API - Natives & Forwards */
- Handle g_OnCheatDetected = INVALID_HANDLE;
- void API_Init()
- {
- g_OnCheatDetected = CreateGlobalForward("SMAC_OnCheatDetected", ET_Event, Param_Cell, Param_String, Param_Cell, Param_Cell);
- }
- // native GameType:SMAC_GetGameType();
- public any Native_GetGameType(Handle plugin, int numParams)
- {
- return view_as<GameType>(g_Game);
- }
- // native SMAC_Log(const String:format[], any:...);
- public any Native_Log(Handle plugin, int numParams)
- {
- char sFilename[64], sBuffer[256];
- GetPluginBasename(plugin, sFilename, sizeof(sFilename));
- // Relay log to IRC.
- {
- SMAC_RelayToIRC("[%s] %s", sFilename, sBuffer);
- }
- }
- // native SMAC_LogAction(client, const String:format[], any:...);
- public any Native_LogAction(Handle plugin, int numParams)
- {
- {
- }
- char sAuthID[MAX_AUTHID_LENGTH];
- if (!GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), true))
- {
- if (GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID), false))
- {
- }
- else
- {
- }
- }
- char sIP[17];
- {
- }
- char sVersion[16], sFilename[64], sBuffer[512];
- GetPluginBasename(plugin, sFilename, sizeof(sFilename));
- // Verbose client logging.
- {
- char sMap[MAX_MAPNAME_LENGTH], sWeapon[32];
- float vOrigin[3], vAngles[3];
- int iTeam, iLatency;
- LogToFileEx(g_sLogPath,
- "[%s | %s] %N (ID: %s | IP: %s) %s\n\tMap: %s | Origin: %.0f %.0f %.0f | Angles: %.0f %.0f %.0f | Weapon: %s | Team: %i | Latency: %ims",
- sFilename,
- sVersion,
- client,
- sAuthID,
- sIP,
- sBuffer,
- sMap,
- vOrigin[0], vOrigin[1], vOrigin[2],
- vAngles[0], vAngles[1], vAngles[2],
- sWeapon,
- iTeam,
- iLatency);
- }
- else
- {
- LogToFileEx(g_sLogPath, "[%s | %s] %N (ID: %s | IP: %s) %s", sFilename, sVersion, client, sAuthID, sIP, sBuffer);
- }
- // Relay minimal log to IRC.
- {
- SMAC_RelayToIRC("[%s | %s] %N (ID: %s | IP: %s) %s", sFilename, sVersion, client, sAuthID, sIP, sBuffer);
- }
- }
- // native SMAC_Ban(client, const String:reason[], any:...);
- public any Native_Ban(Handle plugin, int numParams)
- {
- char sVersion[16], sReason[256];
- int duration = g_hCvarBanDuration.IntValue;
- if (SBPP_AVAILABLE())
- {
- SBPP_BanPlayer(0, client, duration, sReason);
- }
- else if (SOURCEBANS_AVAILABLE())
- {
- SBBanPlayer(0, client, duration, sReason);
- }
- else
- {
- char sKickMsg[256];
- }
- {
- }
- }
- // native SMAC_PrintAdminNotice(const String:format[], any:...);
- public any Native_PrintAdminNotice(Handle plugin, int numParams)
- {
- char sBuffer[192];
- for (int i = 1; i <= MaxClients; i++)
- {
- {
- CPrintToChat(i, "%t%s", "SMAC_Tag", sBuffer);
- }
- }
- // Relay admin notice to IRC.
- if (g_hCvarIrcMode.IntValue == 1)
- {
- CRemoveTags(sBuffer, sizeof(sBuffer));
- SMAC_RelayToIRC(sBuffer);
- }
- }
- // native Handle:SMAC_CreateConVar(const String:name[], const String:defaultValue[], const String:description[]="", flags=0, bool:hasMin=false, Float:min=0.0, bool:hasMax=false, Float:max=0.0);
- public any Native_CreateConVar(Handle plugin, int numParams)
- {
- char name[64], defaultValue[16], description[192];
- char sFilename[64];
- GetPluginBasename(plugin, sFilename, sizeof(sFilename));
- }
- // native Action:SMAC_CheatDetected(client, DetectionType:type = Detection_Unknown, Handle:info = INVALID_HANDLE);
- public int Native_CheatDetected(Handle plugin, int numParams)
- {
- {
- }
- // Block duplicate detections.
- {
- return view_as<int>(Plugin_Handled);
- }
- char sFilename[64];
- GetPluginBasename(plugin, sFilename, sizeof(sFilename));
- DetectionType type = Detection_Unknown;
- Handle info = INVALID_HANDLE;
- if (numParams == 3)
- {
- // caller is using newer cheat detected native
- }
- // forward Action:SMAC_OnCheatDetected(client, const String:module[], DetectionType:type, Handle:info);
- Action result = Plugin_Continue;
- return view_as<int>(result);
- }
Recent Pastes