VPN/Proxy Blocker

Unpaid Requests, Public Plugins
Post Reply
Pdv72
Member
Member
United States of America
Posts: 6
Joined: 4 Months Ago
Has thanked: 0
Been thanked: 0
Contact:

VPN/Proxy Blocker

#1

Post by Pdv72 » 3 Weeks Ago

Hi,
There is a plugin it's job to block any detected client who's using Proxy/VPN.
But the problem is that this plugin appears as "Running" But it does not doing it's job. like checking client and punishing fake client and the legit client don't gets punished.
Plugin Code:
  1. #include <amxmodx>
  2. #tryinclude <grip>
  3. #include <nvault>
  4.  
  5. #pragma semicolon 1
  6.  
  7. #if !defined _grip_included
  8.     #assert "gRIP module is required! https://dev-cs.ru/resources/650/"
  9. #endif
  10.  
  11. new g_szDataDir[PLATFORM_MAX_PATH];
  12. new g_hVault = INVALID_HANDLE;
  13.  
  14. public plugin_init() {
  15.     register_plugin("Proxy Check", "2.1", "juice, voed");
  16.    
  17.     if ((g_hVault = nvault_open("proxycheck")) == INVALID_HANDLE) {
  18.         set_fail_state("nvault Error: Vault wasn't opened!");
  19.         return;
  20.     }
  21.    
  22.     get_localinfo("amxx_datadir", g_szDataDir, charsmax(g_szDataDir));
  23.     add(g_szDataDir, charsmax(g_szDataDir), "/proxycheck");
  24.    
  25.     if (!dir_exists(g_szDataDir)) {
  26.         mkdir(g_szDataDir);
  27.     }
  28. }
  29.  
  30. public client_putinserver(id) {
  31.     if (is_user_bot(id) || is_user_hltv(id)) {
  32.         return;
  33.     }
  34.    
  35.     new netAddress[MAX_IP_LENGTH];
  36.     get_user_ip(id, netAddress, charsmax(netAddress), 1);
  37.  
  38.     if (netAddress[0] == 'l') {
  39.         return;
  40.     } else {
  41.         new buf[sizeof netAddress];
  42.  
  43.         copy(buf, charsmax(buf), netAddress);
  44.         replace_all(buf, charsmax(buf), ".", " ");
  45.        
  46.         new octets[4][4];
  47.         parse(buf, octets[0], charsmax(octets[]),
  48.             octets[1], charsmax(octets[]),
  49.             octets[2], charsmax(octets[]),
  50.             octets[3], charsmax(octets[]));
  51.                
  52.         new address = (str_to_num(octets[0]) << 24) |
  53.             (str_to_num(octets[1]) << 16) |
  54.             (str_to_num(octets[2]) << 8) |
  55.             (str_to_num(octets[3]));
  56.        
  57.         // Ignore private IPv4 address spaces
  58.         if ((address & 0xFF000000) == 0x0A000000 ||    //10.0.0.0/8
  59.         (address & 0xFFF00000) == 0xAC100000 ||       //172.16.0.0/12
  60.         (address & 0xFFFF0000) == 0xC0A80000 ||       //192.168.0.0/16
  61.         (address & 0xFF000000) == 0x7F000000)         //127.0.0.0/8
  62.         {
  63.             return;
  64.         }
  65.     }
  66.  
  67.     new data = nvault_get(g_hVault, netAddress);
  68.  
  69.     if (data) {
  70.         if (data == 1) {
  71.             punish_player(id);
  72.         }
  73.  
  74.         return;
  75.     }
  76.  
  77.     new szFile[PLATFORM_MAX_PATH];
  78.     formatex(szFile, charsmax(szFile), "%s/check_%s.txt", g_szDataDir, netAddress);
  79.  
  80.     if (!file_exists(szFile)) {
  81.         new szRequest[68];
  82.  
  83.         formatex(szRequest, charsmax(szRequest), "https://ip.teoh.io/api/vpn/%s", netAddress);
  84.         grip_request(szRequest, Empty_GripBody, GripRequestTypeGet, "HandleRequest");
  85.     }
  86. }
  87.  
  88. public HandleRequest() {
  89.     new GripResponseState:responseState = grip_get_response_state();
  90.  
  91.     if (responseState == GripResponseStateError) {
  92.         return;
  93.     }
  94.  
  95.     new GripHTTPStatus:status = grip_get_response_status_code();
  96.  
  97.     if (status != GripHTTPStatusOk) {
  98.         return;
  99.     }
  100.  
  101.     new response[512];
  102.     grip_get_response_body_string(response, charsmax(response));
  103.  
  104.     new GripJSONValue:data = grip_json_parse_response_body(response, charsmax(response));
  105.  
  106.     if (data == Invalid_GripJSONValue) {
  107.         return;
  108.     }
  109.  
  110.     new netAddress[MAX_IP_LENGTH];
  111.    
  112.     grip_json_get_string(grip_json_object_get_value(data, "ip"), netAddress, MAX_IP_LENGTH);
  113.     grip_json_get_string(grip_json_object_get_value(data, "vpn_or_proxy"), response, charsmax(response));
  114.  
  115.     if (equal(response, "yes")) {
  116.         nvault_set(g_hVault, netAddress, "1");
  117.         punish_player(find_player("d", netAddress));
  118.     } else {
  119.         nvault_set(g_hVault, netAddress, "2");
  120.     }
  121.        
  122.     grip_destroy_json_value(data);
  123. }
  124.  
  125. punish_player(id) {
  126.     if(!is_user_connected(id)) {
  127.         return;
  128.     }
  129.    
  130.     server_cmd("kick #%d ^"Proxy/VPN not Allowed!^"", get_user_userid(id));
  131. }
So please can you help me to fix this plugin code so to make it works as it should be?
Thanks in advance. :)

[ Post made via Android ]

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests