Results 1 to 7 of 7

Thread: [CoD 1.1] How should I call curl from gsc?

  1. #1
    Deleter/Deleted
    Join Date
    Jan 2023
    Posts
    76
    Thanks
    40
    Thanked 9 Times in 9 Posts

    [CoD 1.1] How should I call curl from gsc?

    Hello

    I'm taking over PlayerConnect, to check if player uses a vpn ip before letting him in

    For that, I need to call an online api using curl, to get a response about the ip info, it looks like json

    I'm using codextended

    I'm thinking about calling the api from the .gsc, would that be the good way?

    Or should I build codextended to let it do the verification?

    Do you know how I could call curl and get a response from .gsc?

    Would you have an alternative to curl to suggest if you think there is a better option to use?

  2. #2
    Private Paho's Avatar
    Join Date
    Feb 2014
    Location
    Russia
    Posts
    101
    Thanks
    43
    Thanked 48 Times in 37 Posts
    i use too vpn api. Codextended .php + database mysql

  3. The Following User Says Thank You to Paho For This Useful Post:

    raphael (27th March 2023)

  4. #3
    Private Paho's Avatar
    Join Date
    Feb 2014
    Location
    Russia
    Posts
    101
    Thanks
    43
    Thanked 48 Times in 37 Posts
    system("php vpn.php "+self getIP()+" "+self.id);
    <?php
    $ip = $argv[1];
    $id = $argv[2];
    $ch = curl_init('http://proxycheck.io/v2/'.$ip.'?key=mykey&vpn=1&asn=1&risk=1');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $json = curl_exec($ch);
    curl_close($ch);
    $api_result = json_decode($json, true);
    $proxy=0;
    $risk=$api_result[$ip]['risk'];
    if($risk>65)
    $proxy=1;
    $mi = new mysqli("url", "login", "password", "dbname");
    $eboy=$mi->query("UPDATE `users` SET `city`='".$api_result[$ip]['city']."', `country`='".$api_result[$ip]['country']."', `isocode`='".$api_result[$ip]['isocode']."', `vpn`='".$proxy."' WHERE `realid`='".intval($id)."'");
    $mi->close();
    ?>
    Last edited by Paho; 26th March 2023 at 15:59.

  5. The Following User Says Thank You to Paho For This Useful Post:

    raphael (27th March 2023)

  6. #4
    Deleter/Deleted
    Join Date
    Jan 2023
    Posts
    76
    Thanks
    40
    Thanked 9 Times in 9 Posts
    Thank you very much

  7. #5
    Deleter/Deleted
    Join Date
    Jan 2023
    Posts
    76
    Thanks
    40
    Thanked 9 Times in 9 Posts
    I never used this system() command

    Can you get the curl/php response from it directly in gsc?

    Or you use sql for that?

  8. #6
    Private Paho's Avatar
    Join Date
    Feb 2014
    Location
    Russia
    Posts
    101
    Thanks
    43
    Thanked 48 Times in 37 Posts
    1. Run php script from gsc
    2. Write in DataBase from .php
    3. Read db-query in gsc
    My example realisation:
    C9A7ACE6-3B8F-4A9C-B221-0435AF052B96.jpeg
    system libcod:
    5ECA3DC7-D8A4-41F2-841B-2DC89904261F.jpeg
    You can try use return 1/0 or -1 in php script from gsc(libcod: system()) without db, but i cant test it now.
    Sorry for my bad english
    Last edited by Paho; 27th March 2023 at 17:47.

  9. The Following User Says Thank You to Paho For This Useful Post:

    raphael (27th March 2023)

  10. #7
    Deleter/Deleted
    Join Date
    Jan 2023
    Posts
    76
    Thanks
    40
    Thanked 9 Times in 9 Posts
    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_OutOfBandPrintNS_SERVERfrom"error\nIllegal name.");
                return;
            }

            
    //CHECK VPN
            
    cvar_tblockvpn Cvar_Get("x_blockvpn"""0);
            
    cvar_tblockvpn_url Cvar_Get("x_blockvpn_url"""0);
            
    cvar_tblockvpn_url_parameter1 Cvar_Get("x_blockvpn_url_parameter1"""0);
            
    cvar_tblockvpn_apikey Cvar_Get("x_blockvpn_apikey"""0);
            
    cvar_tblockvpn_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");

                    
    boolipIsOk true;

                    
    char ip[16];
                    
    sprintf(ip"%d.%d.%d.%d",
                        
    from.ip[0],
                        
    from.ip[1],
                        
    from.ip[2],
                        
    from.ip[3]);

                    
    charurl[
                        
    strlen(blockvpn_url->string)
                        +
    strlen(ip)
                        +
    strlen(blockvpn_url_parameter1->string)
                        +
    strlen(blockvpn_apikey->string)
                        +
    1];
                    
                    
    strcpy(urlblockvpn_url->string);
                    
    strcat(urlip);
                    
    strcat(urlblockvpn_url_parameter1->string);
                    
    strcat(urlblockvpn_apikey->string);

                    
    cprintf(PRINT_UNDERLINE PRINT_DEBUG"url = %s"url);
                    
    cprintf(PRINT_UNDERLINE PRINT_DEBUG"\n");

                    
    curl_easy_setopt(curlCURLOPT_URLurl);
                    
    curl_easy_setopt(curlCURLOPT_WRITEFUNCTIONwritefunc);
                    
    curl_easy_setopt(curlCURLOPT_WRITEDATA, &s);
                    
    res curl_easy_perform(curl);
                    
    curl_easy_cleanup(curl);

                    if (
    res == CURLE_OK)
                    {
                        
    cprintf(PRINT_UNDERLINE PRINT_DEBUG"curl CURLE_OK\n");

                        
    cJSONparsedJson cJSON_Parse(s.ptr);
                        
    free(s.ptr);

                        
    cJSONsecurityObject cJSON_GetObjectItemCaseSensitive(parsedJson"security");
                        
    cJSONvpn cJSON_GetObjectItemCaseSensitive(securityObject"vpn");
                        
    cJSONproxy cJSON_GetObjectItemCaseSensitive(securityObject"proxy");
                        
    cJSONtor cJSON_GetObjectItemCaseSensitive(securityObject"tor");
                        
    cJSONrelay 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_SERVERfrom"error\n%s"blockvpn_message->string);
                            }
                            else
                            {
                                
    NET_OutOfBandPrint(NS_SERVERfrom"error\nIP address not accepted.");
                            }
                            return;
                        }
                        else
                        {
                            
    cprintf(PRINT_UNDERLINE PRINT_DEBUG"BAD IP NOT DETECTED\n");
                        }
                    }
                    else
                    {
                        
    cprintf(PRINT_UNDERLINE PRINT_DEBUGstderr"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_SERVERfrom"error\nkthxnbai m8\n");
                            ... 

    build.sh
    PHP Code:
    ...
    $compiler $params -c sv_commands.-o obj/sv_commands.o

    $compiler $params 
    -c cJSON.-o obj/cJSON.o

    $compiler $params 
    -c sv_client.-o obj/sv_client.o
    ... 
    PHP Code:
    ...
    else
    if [ 
    $DEBUG true ]; then
    echo "LINKING CURL"
    $compiler -m32 -shared -L/lib32 -L./lib -../bin/codextended.so $obj -lz $LINK_LIBS $STEAM_LINK -ldl -lm -Wall -lcurl
    else
    $compiler -m32 -shared -L/lib32 -L./lib -../bin/codextended.so $obj -Os --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 
    Last edited by raphael; 31st March 2023 at 23:22.

  11. The Following User Says Thank You to raphael For This Useful Post:

    Ni3ls (29th March 2023)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •