Created
April 8, 2015 00:47
-
-
Save Bo0m/066db47b35bca9bd5a7d to your computer and use it in GitHub Desktop.
Locking down a SourceMod plugin to a specific server IP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define WHITELIST_IP "1.2.3.4" | |
new String:g_sServerIp[16]; | |
public OnPluginStart() | |
{ | |
// Pull server IP as integer from hostip, then bit shift into string format. | |
new iServerIP = GetConVarInt(FindConVar("hostip")); | |
Format(g_sServerIp, sizeof(g_sServerIp), "%i.%i.%i.%i", (iServerIP >> 24) & 0x000000FF, (iServerIP >> 16) & 0x000000FF, (iServerIP >> 8) & 0x000000FF, iServerIP & 0x000000FF); | |
// If formatted IP does not match defined IP, fail to load. | |
if (!StrEqual(g_sServerIp, WHITELIST_IP)) | |
{ | |
SetFailState("Server is not authorized to run this plugin."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this!