segmentation fault

Started by Nihongo^, Jul 20, 2023, 08:36 AM

Previous topic - Next topic

habi

The "{" is a string, so no need to close it.

Did you changed player IP for testing i told using __getTable ? Otherwise ip will be 127.0.0.1 and response will not contain "{".

Also change
if(response.find("{")==null)
{
  print("Bad response");
  return;
}

Quote from: Nihongo^ on Jul 21, 2023, 10:45 AMAbout API Key, you know where to insert it.
xd, no where ?
Then how did you made this
Quote from: Nihongo^ on Jul 20, 2023, 08:36 AMlocal url = "https://proxycheck.io/v2/" + playerIP + "?vpn=1&asn=1&key=" + api_key;

habi

local request=format("GET /v2/%s?vpn=1&asn=1&key=%s  HTTP/1.1\r\nHost: proxycheck.io\r\nAccept: */*\r\n\r\n", ipaddr,
"YOUR_API_KEY");

Nihongo^

Quote from: habi on Jul 21, 2023, 11:06 AMlocal request=format("GET /v2/%s?vpn=1&asn=1&key=%s  HTTP/1.1\r\nHost: proxycheck.io\r\nAccept: */*\r\n\r\n", ipaddr,
"YOUR_API_KEY");

Oh actually the function works now, and it did not require any API, it said i am using proxy

Just one more question do i still need that API ? or just ignore it ?

habi

Yes, because you may reach the 'limit' of number of queries w/o key.

If it shows you are using proxy, it might be because of the line in onScriptLoad.

In onScriptLoad, i gave you comment the line CPlayer.__getTable.IP

Also remember, to check IP only if it is not 127.0.0.1

Nihongo^

Quote from: habi on Jul 21, 2023, 12:08 PMYes, because you may reach the 'limit' of number of queries w/o key.

If it shows you are using proxy, it might be because of the line in onScriptLoad.

In onScriptLoad, i gave you comment the line CPlayer.__getTable.IP

Also remember, to check IP only if it is not 127.0.0.1
Yes, i totally understand the function, i actually removed CPlayer.__getTable.IP and put the function on my VPS and tried with the real VPN, its detected the proxy so its work

about the API ok i will placee it on my function, also i would like to know is there any packages for the API ? i can see some prices/paid options




habi

Proxycheck.io
Daily Limit - 100 queries
Registered (get API key) - 1000 queries.
Go for a paid one if you like to have one!

Nihongo^

Quote from: habi on Jul 21, 2023, 01:24 PMProxycheck.io
Daily Limit - 100 queries
Registered (get API key) - 1000 queries.
Go for a paid one if you like to have one!
I am sorry for asking you too many questions
i understand it, but what is queries ? and how does it relat to script for detecting proxy

again i apologise for this act

habi

#22
No need to apologize and all.

Each time you send a request to detect an ip is proxy/vpn it is a query.

With a registered account there, you can do 1000 checks per day.

If you pay also, then according to image you posted you can check 10K ips a day. So are various plans there.

Nihongo^

Hi habi

i am sorry but there's an other problem occur here, when player is banned and get kicked checkproxy gave an error here

  line no 43   if(!player) throw print("No player with IP exists");



function recv(response)
{
 if(response.find("{")==null)
  return;
 
 local output=JSONParser.parse( response.slice( response.find("{") ) );
 if( typeof(output) == "table" )
 {
  if("status" in output )
  {
   if(output.status=="ok")
   {
    foreach(a,b in output)
    {
     if(typeof(b)=="table")
     {
      //Can be IP
      if( "proxy" in b && "type" in b )
      {
       //This is ip
       local IP=a;
       //Find the player
       local player=null;
       for(local i=0;i < GetMaxPlayers();i++)
       {
        player=FindPlayer(i);
        if( player && player.IP==IP)
        {
         //Got the player
         break;
        }
       }
    line no 43   if(!player) throw print("No player with IP exists");
       
       if( b.proxy == "yes" || b.type=="VPN")
       {
        print(player.Name+ " is using proxy/VPN");
ServerMessage("[VPN-Usage] [#FF0000]Auto-Kicked: [#FFFFFF][ "+player.Name+ " ][#FF0000] Reason: [#FFFFFF] [Proxy/VPN]");
EchoMessage("[VPN] Auto-Kicked: [ "+player.Name+ " ] Reason: [Proxy/VPN]");
EchoMessageAdmin("[VPN] Auto Kicked: [ "+player.Name+ " ] Reason: [Proxy/VPN] [" +player.IP+ "] Country [" +b.country+ "]");
player.Kick();
return 0;
        /*
         Take actions
        */
       }else if( "country" in b )
       {
        //Ordinary player
        print(player.Name+ " is connecting from "+ b.country);
       }
      }
     }
    }
   }else EchoMessageAdmin("[VPN] status is not ok");
  }else EchoMessageAdmin("[VPN] status code not in output");
 }else EchoMessageAdmin("[VPN] bad response from server");
}

habi

line no.43
then you simply replace
if(!player) throw print("No player with IP exists");by
if(!player) { print("proxycheck: player quit"); return }

Nihongo^

Thanks, but sorry to keep letting you disturb

I just signup and it should give me at least 1000 queries but it showing me its 100
i would like to know if i placed my API key to the correct line ? ( as you shows

Quotelocal request=format("GET /v2/%s?vpn=1&asn=1&key=%s  HTTP/1.1\r\nHost: proxycheck.io\r\nAccept: */*\r\n\r\n", ipaddr,"YOUR_API_KEY");

Quotefunction CheckProxy(ipaddr)
{
 Socket1<-NewSocket("recv");
 local request=format("GET /v2/%s?vpn=1&asn=1  HTTP/1.1\r\nHost: proxycheck.io\r\nAccept: */*\r\n\r\n", ipaddr, "96ho1j-a57071-8j1317-7vk380");
 getroottable().rawset(ipaddr+"connF",function(){
 Socket1.Send(request);
 });
 Socket1.SetNewConnFunc(ipaddr+"connF");
 Socket1.Connect("proxycheck.io", 80);
}





habi

In local variable request,
&key=%sYou are careless.

Nihongo^

#27
Quote from: habi on Jul 22, 2023, 05:04 PMIn local variable request,
&key=%sYou are careless.

I am sorry I did not check, it's working now but
after few hours, it start giving me this error until I restart the server



function CheckProxy(ipaddr)
{
 Socket1<-NewSocket("recv");
 local request=format("GET /v2/%s?vpn=1&asn=1&key=%s  HTTP/1.1\r\nHost: proxycheck.io\r\nAccept: */*\r\n\r\n", ipaddr,"96ho1j-a57071-8j1317-7vk380");
 getroottable().rawset(ipaddr+"connF",function(){
 Socket1.Send(request);
 });
 Socket1.SetNewConnFunc(ipaddr+"connF"); Line 8
 Socket1.Connect("proxycheck.io", 80);
}

P.S after restarting the server it works fine nad gives me details of every player's IP but gives error after few hours

habi

Found out that Socket plugin can handle only 64 connections if sockets are not closed.
We were not closing sockets.
I made a timer of 5 seconds to do the job:
function CheckProxy(ipaddr)
{
 local socket=NewSocket("recv");
 local request=format("GET /v2/%s?vpn=1&asn=1&key=%s  HTTP/1.1\r\nHost: proxycheck.io\r\nAccept: */*\r\n\r\n", ipaddr,"96ho1j-a57071-8j1317-7vk380");
 getroottable().rawset(ipaddr+"connF",function(){
 socket.Send(request);
 });
 socket.SetNewConnFunc(ipaddr+"connF");
 socket.Connect("proxycheck.io", 80);
 NewTimer("DestroySocket",5000,1,socket, ipaddr+"connF");
}
function DestroySocket(sock, fname){
if(sock)sock.Delete();
rawdelete(fname);
};

Nihongo^

#29
Thanks but
I used your function but this time if 3 or 4 players join the server at same time server get crashed