Skip to content

Instantly share code, notes, and snippets.

@Bo0m
Created April 8, 2015 00:47
Show Gist options
  • Save Bo0m/066db47b35bca9bd5a7d to your computer and use it in GitHub Desktop.
Save Bo0m/066db47b35bca9bd5a7d to your computer and use it in GitHub Desktop.
Locking down a SourceMod plugin to a specific server IP.
#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.");
}
}
@Maarethyu
Copy link

Thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment