Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Nihongo^ on Jul 19, 2023, 12:02 PM

Title: not using a proxy
Post by: Nihongo^ on Jul 19, 2023, 12:02 PM
In the refer of t his https://forum.vc-mp.org/index.php?topic=9275.0

I want to say thanks to @habi and @vitovc for the help.

I tried to utilize the function and made a code it detecting its as a proxy, but in print, it said
not using a proxy

While I've provided a proxy IP and it detected


(https://i.postimg.cc/bJ6cQ16N/Untitled.png)

Function

function HTTP_OnResponse(tag, url, statusCode, response)
{
    print("Data received for request with tag " + tag);
    print("Response: " + response);
   
    if (tag == "proxy_check_request")
    {
        // Check if the request was successful
        if (statusCode == 200)
        {
            local findProxy = response.find("proxy");
            if (findProxy == "yes")
            {
//Player is using a proxy
                    print("Using a proxy.");
                }
                else
                {
                    // Player is not using a proxy
                    print("Not using a proxy.");
                }
            }
        else
        {
            // Handle HTTP request error
            print("Proxy check request failed with status code " + statusCode);
        }
    }
}


Title: Re: not using a proxy
Post by: habi on Jul 19, 2023, 12:41 PM
QuoteI want to say thanks to @habi and @vitovc for the help
you are welcome.

local findProxy = response.find("proxy");
            if (findProxy == "yes")
This won't work. Change to:
local findProxy = response.find("proxy\": \"yes");
            if (findProxy!= null)
Title: Re: not using a proxy
Post by: Nihongo^ on Jul 19, 2023, 12:46 PM
Thank you so much habi its works, just because of you I made VPN detector
Title: Re: not using a proxy
Post by: Nihongo^ on Jul 19, 2023, 01:03 PM
btw one question how do i include player name ?
+player.Name+ using VPN  ?


p.s The player variable is not directly accessible inside the HTTP_OnResponse function since it's a separate callback function. We need to find a way to pass the player data from onPlayerJoin to HTTP_OnResponse
Title: Re: not using a proxy
Post by: habi on Jul 19, 2023, 02:46 PM
There is another way.
if(response.find(player.IP)!=null)Put above code in a loop over all players.
Only one will match it.
Title: Re: not using a proxy
Post by: Nihongo^ on Jul 19, 2023, 03:01 PM
Quote from: habi on Jul 19, 2023, 02:46 PMThere is another way.
if(response.find(player.IP)!=null)Put above code in a loop over all players.
Only one will match it.
I am sorry habi, but how does player.IP helped me to get the player.Name ?
Title: Re: not using a proxy
Post by: Nihongo^ on Jul 19, 2023, 03:51 PM
Quote from: vitovc on Jul 19, 2023, 03:05 PM1) why not work with json normally with this https://github.com/electricimp/JSONParser

Never used that JSONParser, any tip please
Title: Re: not using a proxy
Post by: habi on Jul 19, 2023, 04:29 PM
Get the below file from github given by vito.
then
dofile("scripts/JsonParser.class.nut") Now at proper place do this
local tbl=JSONParser.parse( request.slice( request.find( "{" ) ) );
If you print contents of tbl, you get
[SCRIPT]  status
[SCRIPT]  79.137.85.208
So the ip is indexed at position 1.

How to loop through players?
Then make a for loop from 0 to Max Players.
player =  FindPlayer( i );
if( !player ) continue; //checking for null;

Now, compare IPs
if( player.IP == tbl[1] )
Title: Re: not using a proxy
Post by: Nihongo^ on Jul 19, 2023, 05:28 PM
Quote from: habi on Jul 19, 2023, 04:29 PMGet the below file from github given by vito.

can it be done like this ?

local JSONData = JSONParser.parse(response.slice(response.find("{")));
        if (JSONData != null && JSONData("player")) {
            local playerName = JSONData["player"];
            print("Player Name: " + playerName);


            for (local i = 0; i < MaxPlayers; ++i) {
                local player = FindPlayer(i);
                if (!player) continue; //checking for null

                if (player.IP == tbl[1]) {
                   
                    print("Player IP matches: " + player.Name);
                }

    }
line 442 -->         if (JSONData != null && JSONData("player"))

(https://i.postimg.cc/447hDbrz/Untitled.png)
Title: Re: not using a proxy
Post by: habi on Jul 20, 2023, 04:06 AM
if (JSONData != null ) {
           //local playerName = JSONData["player"];
           //print("Player Name: " + playerName);
Title: Re: not using a proxy
Post by: Nihongo^ on Jul 20, 2023, 07:14 AM
Thank you so much habi, i finally made it
thanks to vito also for such efforts