Results 1 to 7 of 7

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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.

  2. 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
  •