Skip to content

Instantly share code, notes, and snippets.

@shavitush
Created October 18, 2016 15:53
Show Gist options
  • Save shavitush/2e1b9ef7ad544642971477dab0ced372 to your computer and use it in GitHub Desktop.
Save shavitush/2e1b9ef7ad544642971477dab0ced372 to your computer and use it in GitHub Desktop.
AMXX City Bans
// some macros so it's easier for me to use AMXX
#define null INVALID_HANDLE
#define view_as<%1>(%2) %1:(%2)
#define char new
#define int new
#define File new
#define void
#include <amxmodx>
#include <amxmisc>
#include <geoip>
#pragma semicolon 1
#pragma ctrlchar '\'
// i wish i could remove this ugly 'new'
new Array:gA_BannedCities = view_as<Array>(null);
int gI_ArraySize = 0;
public void plugin_init()
{
register_plugin("City Bans", "1.0", "https://github.com/shavitush");
gA_BannedCities = ArrayCreate(128);
char sConfigFile[PLATFORM_MAX_PATH];
get_configsdir(sConfigFile, PLATFORM_MAX_PATH);
format(sConfigFile, PLATFORM_MAX_PATH, "%s/citybans.txt", sConfigFile);
if(!file_exists(sConfigFile))
{
set_fail_state("Make sure \"%s\" exists and is accessable!", sConfigFile);
}
char sLine[128];
File fFile = fopen(sConfigFile, "r");
if(fFile == null)
{
set_fail_state("Could not open \"%s\".", sConfigFile);
}
for(gI_ArraySize = 0; !feof(fFile); gI_ArraySize++)
{
fgets(fFile, sLine, PLATFORM_MAX_PATH);
trim(sLine);
ArrayPushString(gA_BannedCities, sLine);
}
fclose(fFile);
}
public void client_putinserver(client)
{
char sIP[64]; // 64 purely because of ipv6
get_user_ip(client, sIP, 64, 1);
char sCity[128];
geoip_city(sIP, sCity, 128);
for(int i = 0; i < gI_ArraySize; i++)
{
char sTempCity[128];
ArrayGetString(gA_BannedCities, i, sTempCity, 128);
if(equali(sTempCity, sCity))
{
// is there seriously no way to kick properly in AMXX WTF?!
server_cmd("kick #%d Your city (%s) is banned from this server.", get_user_userid(client), sCity);
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment