segmentation fault

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

Previous topic - Next topic

Nihongo^

After spending hours to making VPN detection now, I am facing this segmentation fault in the Linux after this message server get closed
This error only occurs on this line onPlayer join
  request.sendGet();
and here the full function
function onPlayerJoin( player )
{
   local playerIP = "195.146.4.43";
    // Replace "YOUR_API_KEY" with your actual proxycheck.io API key
    local api_key = "798233-593822-1490lk-681482";

    local url = "https://proxycheck.io/v2/" + playerIP + "?vpn=1&asn=1&key=" + api_key;

    // Make the HTTP request to proxycheck.io
    local request = ::SqHTTP.GetRequest();
    request.setURL(url);
    request.setTag("proxy_check_request");
    request.sendGet();

}



habi

I think the error happens in function HTTP_OnResponse. Post that function's code please.

Nihongo^

#2
Quote from: habi on Jul 20, 2023, 10:07 AMI think the error happens in function HTTP_OnResponse. Post that function's code please.
Well just for checking I removed that function, but still, the same thing happens anyways here is the code.

function HTTP_OnResponse(tag, url, statusCode, response) {

if (tag == "proxy_check_request") {
// Check if the request was successful
if (statusCode == 200) {
local findProxy = response.find("proxy\": \"yes");
if (findProxy != null) {
// Player is using a proxy
print("Using a proxy.");

for (local i=0; i<=GetMaxPlayers(); i++)
{
local player = FindPlayer(i);
if (!player) continue; //checking for null
print("Player IP matches: " + player.Name);
}
} 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);
}
}
else {
print("Player name not found in the response.");
}
}

P.S Code work perfectly only in Windows. Here's the pic, (player name is Everest), but give an error in Linux.


habi

Working fine for me on WSL Ubuntu
I use httprequests04rel64[dot]so from here (0.2.1)
scripts/httptest.nut
request <- ::SqHTTP.GetRequest();
request.setURL("https://proxycheck.io/v2/79.137.85.208?vpn=1&asn=1")
request.setTag("James_Bond");
function HTTP_OnResponse(tag, url, statusCode, response)
{
   // Check if the request was successful
   if (statusCode == 200)
   {
local findProxy = response.find("proxy\": \"yes");

if (findProxy != null)
{
print("-------PROXY DETECTED-------");
print("Name: "+tag);
print("----------------------------");
//To get the player instance
local player = FindPlayer(tag);
if( player && player.Name == tag )
{
MessagePlayer("You are about to be k**ck*d", player);
}else
{
//player /q before the response arrived!
}
} else
{
print(tag+ " is not using a proxy.");
}

}else {
    // Handle HTTP request error
    print("Proxy check request failed with status code " + statusCode);
   } 

}
request.sendGet();

The screenshot is not of Windows but of Linux(Ubuntu.)
There is a tag function for http request. You simply set it as player's name. Then using the tag, find the player.

Nihongo^

I am bit confused the function not work without request.sendGet(); as it lead to HTTP_OnResponse
also may i ask why'd you put request.sendGet(); at the end of the function HTTP_OnResponse

print("Proxy check request failed with status code " + statusCode);
   }

}
request.sendGet();

Nihongo^

I believe this is due to the plugins/out dated plugins

habi

#6
Quote from: Nihongo^ on Jul 20, 2023, 12:08 PMI am bit confused the function not work without request.sendGet(); as it lead to HTTP_OnResponse
also may i ask why'd you put request.sendGet(); at the end of the function HTTP_OnResponse

print("Proxy check request failed with status code " + statusCode);
   }

}
request.sendGet();
Hi Nihongo^, i have not put request. sendGet at the end of the function, but 'outside' the function.
You may as well put the function first and request<-::SqHTTP.GetRequest(), etc below it. This is because when we  'dofile', statement gets executed in order.
Not that 'HTTP_OnResponse' is compiled only when it is put first, actual 'calling' do not happens.
It must be put before sendGet, because sendGet needs it.

So what happens when you put the file as it is, and 'dofile' it in onScriptLoad ?

Either you use previous version of plugin, or server or it may have something to do with vps.

Nihongo^

So what happens when you put the file as it is, and 'dofile' it in onScriptLoad ?
Same error occur, it also give this error when i put httprequest04rel64 plugins before the discord or any other plugins in the server.cfg sounds weird right ? server closed it self saying "segmentation error" whenever i launch it

Either you use previous version of plugin, or server or it may have something to do with vps.
I tried with the other vps and give same error, i request you to please give the latest plugins for Linux

PS: Pretty cool, it says 'Hero Member' - my 'posts' 501
Congratulation for this achievement, you don't need any post count to be called hero, you actually a real hero xd



habi

#8
QuoteCongratulation for this achievement, you don't need any post count to be called hero, you actually a real hero xd
lol xd

Putting httprequest04rel64 first not causing problem to me.


i use plugin link https://github.com/Luckshya/httpreq-squirrel/releases/download/0.2.1/httprequest04rel64.so

I remember segmentation fault occuring to me when 'one of the plugin in server.cfg' was corrupt. I put my plugin last, then second last,  etc until i find which plugin was interfering. What are the plugins you use? Do you use earlier versions of my plugins such as filterscripts, npchide, plugincommand? (one of them was faulty)


Nihongo^

#9
Quote from: habi on Jul 20, 2023, 07:28 PMPutting httprequest04rel64 first not causing problem to me.
i use plugin link https://github.com/Luckshya/httpreq-squirrel/releases/download/0.2.1/httprequest04rel64.so
I used the same plugins for linux and place them at the top of all plugins now its giving me this error


You can see following plugins i am using ( i put httprequest04rel64 at the top )

 httprequest04rel64 xmlconf04rel64 announce04rel64 squirrel04rel64 sqlite04rel64 geoip04rel64 sockets04rel64 mysql04rel64 ini04rel64 discord04rel64



QuoteWhat are the plugins you use? Do you use earlier versions of my plugins such as filterscripts, npchide, plugincommand? (one of them was faulty)

I am sorry habi i have no idea what kind of plugins i am using as i only download it from here years ago these filterscripts, npchide, plugincommand are new for me never heard about it

I think its only plugins issue do you think there's faulty plugins other the httprequest04rel64  ?

habi

#10
Forget httprequests04,

Here is scripts/proxycheck.nut using  socket04
function 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);
getroottable().rawset(ipaddr+"connF",function(){
Socket1.Send(request);
});
Socket1.SetNewConnFunc(ipaddr+"connF");
Socket1.Connect("proxycheck.io", 80);
}
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;
}
}
if(!player)throw("No player with IP exists");

if( b.proxy == "yes" || b.type=="VPN")
{
print(player.Name+ " is using proxy/VPN");
/*
Take actions
*/
}else if( "country" in b )
{
//Ordinary player
print(player.Name+ " is connecting from "+ b.country);
}
}
}
}
}else throw("status is not ok");
}else throw("status code not in output");
}else throw("bad response from server");
}
function onPlayerJoin( player )
{
    CheckProxy(player.IP);
}
How to test?
For testing add the following line to onScriptLoad. After testing remove the code!
function onScriptLoad()
{
    dofile("scripts/proxycheck.nut");   
    //For test purpose
    //CPlayer.__getTable.IP=function(){return "79.137.85.208"}
}
What does this testing do? This will make player.IP return the given ip everytime, all players.

Nihongo^

#11
Thank you habi, i'll check it, kinda new things for me i have few question

1)do i need to put any link inside it ?
local request = format("GET /v2/%s?vpn=1&asn=1 HTTP/1.1\r\nHost: proxycheck.io\r\nAccept: */*\r\n\r\n", ipaddr);

2)For JSONParser
is it necessary to add plugins?
json04rel64.so

3)These words "throw" seem to look like you're giving an example should I change it ?
Quoteif (!player) throw ("No player with IP exists");

Quoteelse {
                throw ("status is not ok");
            }
        } else {
            throw ("status code not in output");
        }
    } else {
        throw ("bad response from server");

4)and in last do i need to put my API on it ?

    // Connect to the proxycheck.io API
 Socket1.Connect("proxycheck.io", 80);[/td]

habi

#12
Quote from: Nihongo^ on Jul 21, 2023, 10:10 AMdo i need to put any link inside it ?

local request = format("GET /v2/%s?vpn=1&asn=1 HTTP/1.1\r\nHost: proxycheck.io\r\nAccept: */*\r\n\r\n", ipaddr);
No. The %s get replaced by player IP.

Quote from: Nihongo^ on Jul 21, 2023, 10:10 AMis it necessary to add plugins?

json04rel64.so
No, but need to dofile 'JsonParser.class.nut'

About API Key, you know where to insert it.

throw is a dangerous statement. If you use it somewhere in your code, the function will be returned at once and error message printed on console. "Error -...". If you dont like it, you can use print("error msg");
return;
.

Let's wind it up.

Nihongo^

Habi i am sorry but nothing appeared in the console neither there's any bug 

But i see one thing the function recv(response) not closed properly. I am using Notepad++ and it shows me that the last close-bracket started 

with response.find("{") ) );

if i put another close bracket it refer to if(response.find("{")==null)

i hope you understand what i am saying

Nihongo^

Quote from: Nihongo^ on Jul 21, 2023, 10:41 AMHabi i am sorry but nothing appeared in the console neither there's any bug 

But i see one thing the function recv(response) not closed properly. I am using Notepad++ and it shows me that the last close-bracket started 

with response.find("{") ) );

if i put another close bracket it refer to if(response.find("{")==null)

i hope you understand what i am saying


About API Key, you know where to insert it.
xd, no where ?