Finally I did it through codextended, below is how, hoping it could please someone.
Add cJSON.c and cJSON.h from https:// github.com/DaveGamble/cJSON to src folder.
sv_client.c
PHP Code:
...
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include "cJSON.h"
...
PHP Code:
...
NET_OutOfBandPrint( NS_SERVER, from, "error\nIllegal name.");
return;
}
//CHECK VPN
cvar_t* blockvpn = Cvar_Get("x_blockvpn", "", 0);
cvar_t* blockvpn_url = Cvar_Get("x_blockvpn_url", "", 0);
cvar_t* blockvpn_url_parameter1 = Cvar_Get("x_blockvpn_url_parameter1", "", 0);
cvar_t* blockvpn_apikey = Cvar_Get("x_blockvpn_apikey", "", 0);
cvar_t* blockvpn_message = Cvar_Get("x_blockvpn_message", "", 0);
if (blockvpn->integer == 1
&& blockvpn_url->string[0]
&& blockvpn_url_parameter1->string[0]
&& blockvpn_apikey->string[0])
{
cprintf(PRINT_UNDERLINE | PRINT_DEBUG, "GOING TO CHECK VPN\n");
struct string s;
init_string(&s);
CURL *curl = curl_easy_init();
CURLcode res;
if (curl)
{
cprintf(PRINT_UNDERLINE | PRINT_DEBUG, "curl PASSED\n");
bool* ipIsOk = true;
char ip[16];
sprintf(ip, "%d.%d.%d.%d",
from.ip[0],
from.ip[1],
from.ip[2],
from.ip[3]);
char* url[
strlen(blockvpn_url->string)
+strlen(ip)
+strlen(blockvpn_url_parameter1->string)
+strlen(blockvpn_apikey->string)
+1];
strcpy(url, blockvpn_url->string);
strcat(url, ip);
strcat(url, blockvpn_url_parameter1->string);
strcat(url, blockvpn_apikey->string);
cprintf(PRINT_UNDERLINE | PRINT_DEBUG, "url = %s", url);
cprintf(PRINT_UNDERLINE | PRINT_DEBUG, "\n");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res == CURLE_OK)
{
cprintf(PRINT_UNDERLINE | PRINT_DEBUG, "curl CURLE_OK\n");
cJSON* parsedJson = cJSON_Parse(s.ptr);
free(s.ptr);
cJSON* securityObject = cJSON_GetObjectItemCaseSensitive(parsedJson, "security");
cJSON* vpn = cJSON_GetObjectItemCaseSensitive(securityObject, "vpn");
cJSON* proxy = cJSON_GetObjectItemCaseSensitive(securityObject, "proxy");
cJSON* tor = cJSON_GetObjectItemCaseSensitive(securityObject, "tor");
cJSON* relay = cJSON_GetObjectItemCaseSensitive(securityObject, "relay");
if (cJSON_IsBool(vpn))
{
if (cJSON_IsTrue(vpn))
{
ipIsOk = false;
}
}
if (cJSON_IsBool(proxy))
{
if (cJSON_IsTrue(proxy))
{
ipIsOk = false;
}
}
if (cJSON_IsBool(tor))
{
if (cJSON_IsTrue(tor))
{
ipIsOk = false;
}
}
if (cJSON_IsBool(relay))
{
if (cJSON_IsTrue(relay))
{
ipIsOk = false;
}
}
if (!ipIsOk)
{
cprintf(PRINT_UNDERLINE | PRINT_DEBUG, "BAD IP DETECTED\n");
if (blockvpn_message->string[0])
{
NET_OutOfBandPrint(NS_SERVER, from, "error\n%s", blockvpn_message->string);
}
else
{
NET_OutOfBandPrint(NS_SERVER, from, "error\nIP address not accepted.");
}
return;
}
else
{
cprintf(PRINT_UNDERLINE | PRINT_DEBUG, "BAD IP NOT DETECTED\n");
}
}
else
{
cprintf(PRINT_UNDERLINE | PRINT_DEBUG, stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
}
else
{
cprintf(PRINT_UNDERLINE | PRINT_DEBUG, "curl NOT PASSED\n");
}
}
else
{
cprintf(PRINT_UNDERLINE | PRINT_DEBUG, "COULDN'T CHECK FOR VPN\n");
}
#if 0
if(strcmp(check_name, "php")) {
NET_OutOfBandPrint(NS_SERVER, from, "error\nkthxnbai m8\n");
...
build.sh
PHP Code:
...
$compiler $params -c sv_commands.c -o obj/sv_commands.o
$compiler $params -c cJSON.c -o obj/cJSON.o
$compiler $params -c sv_client.c -o obj/sv_client.o
...
PHP Code:
...
else
if [ $DEBUG = true ]; then
echo "LINKING CURL"
$compiler -m32 -shared -L/lib32 -L./lib -o ../bin/codextended.so $obj -lz $LINK_LIBS $STEAM_LINK -ldl -lm -Wall -lcurl
else
$compiler -m32 -shared -L/lib32 -L./lib -o ../bin/codextended.so $obj -Os -s -lz $LINK_LIBS $STEAM_LINK -ldl -lm -Wall
...
myserver.cfg
PHP Code:
...
set scr_teambalance "1"
//Custom cvars
set x_blockvpn "1"
set x_blockvpn_url "https://vpnapi.io/api/"
set x_blockvpn_url_parameter1 "?key="
set x_blockvpn_apikey "XXXXXXXXXXXXXXX"
set x_blockvpn_message "VPN/Proxy/Tor/Relay IP address detected."
// Deathmatch
set scr_dm_scorelimit "50"
...
I build using bash build.sh -d
_____________
I used a debian 64bit vm to build
I use a debian 64bit vps for the server
Following commands are written from memory
To build I did on the vm:
PHP Code:
apt-get remove curl libcurl4
dpkg --add-architecture i386
apt update
apt install curl:i386 libcurl4:i386 libcurl4-openssl-dev:i386
And to run on the server I did:
PHP Code:
apt-get remove curl libcurl4
dpkg --add-architecture i386
apt update
apt install curl:i386 libcurl4:i386