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();
}
(https://i.postimg.cc/cCyJN4rp/segmention-falut.png)
I think the error happens in function HTTP_OnResponse. Post that function's code please.
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.
(https://i.postimg.cc/zXvxBw2J/Untitled.png)
Working fine for me on WSL Ubuntu
I use httprequests04rel64[dot]so from here (https://github.com/Luckshya/httpreq-squirrel/releases) (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();
(https://i.imgur.com/PHCRMca.png)
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.
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();
I believe this is due to the plugins/out dated plugins
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.
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
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.
(https://i.imgur.com/aCoVPTm.png)
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)
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
(https://i.postimg.cc/NF0s7Jr9/Screenshot-2023-07-21-091752.png)
You can see following plugins i am using ( i put httprequest04rel64 at the top )
httprequest04rel64 xmlconf04rel64 announce04rel64 squirrel04rel64 sqlite04rel64 geoip04rel64 sockets04rel64 mysql04rel64 ini04rel64 discord04rel64
(https://i.postimg.cc/nhf8nSc4/Screenshot-2023-07-21-092027.png)
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 ?
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.
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]
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.
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
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 ?
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;
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");
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 ?
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
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
(https://i.postimg.cc/yNwPPhJm/Untitled.png)
Proxycheck.io
Daily Limit - 100 queries
Registered (get API key) - 1000 queries.
Go for a paid one if you like to have one!
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
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.
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");
(https://i.postimg.cc/9MFvQKZn/Screenshot-2023-07-22-100605.png)
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");
}
line no.43
then you simply replace
if(!player) throw print("No player with IP exists");
by
if(!player) { print("proxycheck: player quit"); return }
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);
}
(https://i.postimg.cc/xdrvD5B5/Untitled.png)
(https://i.postimg.cc/KcL4CFx6/Untitled.png)
In local variable request,
&key=%s
You are careless.
Quote from: habi on Jul 22, 2023, 05:04 PMIn local variable request,
&key=%s
You 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
(https://i.postimg.cc/dV2cdPNY/Untitled.png)
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
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);
};
Thanks but
I used your function but this time if 3 or 4 players join the server at same time server get crashed
(https://i.postimg.cc/y8r8c2Tf/Untitled.png)
Just to confirm, are the IP of the players same?
Quote from: habi on Jul 23, 2023, 03:09 PMJust to confirm, are the IP of the players same?
Everest is me
but, before 3 players join the server at the same time, and all these players belonged to other locations and then server crashed
i assume that error so i thought i should check it
i joined the server 3 times and then it crashed
It probably was because of variable 'socket' going out of scope.
Check this:
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);
});
getroottable().rawset(socket,null);
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(sock);
}
rawdelete(fname);
};
Quote from: Nihongo^ on Jul 23, 2023, 03:35 PMQuote from: habi on Jul 23, 2023, 03:09 PMJust to confirm, are the IP of the players same?
Everest is me
but, before 3 players join the server at the same time, and all these players belonged to other locations and then server crashed
i assume that error so i thought i should check it
i joined the server 3 times and then it crashed
hy
@habi i am here with my same problem
I thought this matter is solved but its still there. My server crashed when 3/4 players joining the server
(https://i.ibb.co/cNDRXdb/Untitled.png)
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,"3t32l6-477co2-3d0653-2601s0");
getroottable().rawset(ipaddr+"connF",function(){
socket.Send(request);
});
getroottable().rawset(socket,null);
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(sock);
}
rawdelete(fname);
};
function DestroySocket(sock, fname){
if(sock)sock.Delete();
rawdelete(fname);
};
There is not enough information to find out what has happened? First HttpRequest Module used, then i told to use socket module.
It is your server, so find out what is happening - which line it crashes or when exactly it happens. Try to reproduce it and come with more information. Then i will help you.
Quote from: habi on Jul 20, 2023, 11:39 AMWorking fine for me on WSL Ubuntu
I use httprequests04rel64[dot]so from here (https://github.com/Luckshya/httpreq-squirrel/releases) (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();
(https://i.imgur.com/PHCRMca.png)
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.
I recently discovered that the issue causing a "segmentation fault" is related to the Discord plugins and the httprequest04rel64 plugins. When I remove the Discord plugins from my server, the httprequest works perfectly and displays the desired result. However, if I prioritize loading the Discord plugins first, it leads to a segmentation fault during the server loading process. My suspicion is that OpenSSL operates exclusively for either Discord or httprequest at a given time.
Maybe the discord module is faulty. I don't think OpenSSL has anything to do with it.
I see from your console, you are using a modified version of discord plugin, is the source code of it available?
Quote from: habi on Aug 13, 2023, 02:41 PMis the source code of it available?
Thank you for the reply,
afaik it one of my friends who gave me this plugin because the current one is not working/not updated
i think it was
@KAKAN P.S maybe it can help i am not sure he shared this link with me i didn't get what is it
https://github.com/kakan-gamerelated/sleepydiscord-squirrel
I went through the code, there was no mistake like i thought.
Since you said everything is working good on windows, then this might be a bug with vcmp modules sharing same function names. Both httprequests04 and discord04 use sqrat namespaces and it might be a problem with that. I don't know, i have reported this instance [url here.
When i come back, we will write a new code using sockets again which will not crash. You also have to make sure all your functions are good and no duplicate events exist.
...
I was yesterday making a curl module, but not completed. But i believe in socket plugin, so today made this:
function CheckProxy(ipaddr)
{
local socket=NewSocket("recv");
//Your request
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");
//Making individual slot name formatted so that they are different for any two different players.
local funcname = format("%s_%s_func", ipaddr, GetTickCount() );
local sockname = format("%s_%s_sock", ipaddr, GetTickCount() );
local requestname = format("%s_%s_rqst", ipaddr, GetTickCount() );
//NewConnFunc
local func= function(){
if(rawin(sockname) && rawin(requestname))
{
local _socket = rawget(sockname);
local _request = rawget(requestname);
_socket.Send(_request);
}
}
//LostConnFunc and its name
local lostfunc= function(){
if(rawin(sockname))
rawdelete(sockname);
if(rawin(requestname))
rawdelete(requestname);
}
local lostname= format("%s_%s_lost", ipaddr, GetTickCount() );
//Set these pairs in roottable
rawset(funcname, func);
rawset(sockname, socket);
rawset(requestname, request);
rawset(lostname, lostfunc);
socket.SetNewConnFunc(funcname);
socket.SetLostConnFunc(lostname);
socket.Connect("proxycheck.io", 80);
NewTimer("DestroySocket",10000,1,funcname, sockname, requestname, lostname);//After 10 seconds
}
function DestroySocket(fname, sname, reqname, lname)
{
if(rawin(sname))
{
rawget(sname).Delete(); //Delete socket
rawdelete(sname); //Delete slot
}
if(rawin(fname))
rawdelete(fname);
if(rawin(reqname))
rawdelete(reqname);
if(rawin(lname))
rawdelete(lname);
}
//Need not delete timer in lost connection function, because timer has 'if' inside it.
* recv is same and i hope you have not bugs inside it.
*Unload httprequests04 from your system ( assuming it is clashing with discord04)
*code is not tested
I was yesterday making a curl module
Best of luck with your endeavors! also tell us what's the benefits of it ?
I've noticed your diligent work for this community, actively breathing life into it. I genuinely appreciate your dedicated efforts.
In regards to the code, I will review it shortly.
Hy habi sorry it has some bugs at line 8
(https://i.postimg.cc/fLkXDgt5/Screenshot-2023-08-15-203545.png)
and here's the line 8
local funcname = format("%s_%s_func", ipaddr, GetTickCount() );
Replace %s by %d second time:
local funcname = format("%s_%d_func", ipaddr, GetTickCount() );
local sockname = format("%s_%d_sock", ipaddr, GetTickCount() );
local requestname = format("%s_%d_rqst", ipaddr, GetTickCount() );
Quote from: habi on Aug 15, 2023, 05:27 PMReplace %s by %d second time:
local funcname = format("%s_%d_func", ipaddr, GetTickCount() );
local sockname = format("%s_%d_sock", ipaddr, GetTickCount() );
local requestname = format("%s_%d_rqst", ipaddr, GetTickCount() );
Thank you, it works. For testing purposes, I repeated the same action that previously led to crashes (joining every time). As a result, it's now causing bugs at line 291 in the JSONParser.nut and then server off (segmentation fault)
(https://i.postimg.cc/gj3wk4bb/1.png)
Line 291
throw "JSON Syntax Error near `" + near + "`";
Full code
/**
* JSON Parser
*
* @author Mikhail Yurasov <[email protected]>
* @package JSONParser
* @version 1.0.1
*/
/**
* JSON Parser
* @package JSONParser
*/
class JSONParser {
// should be the same for all components within JSONParser package
static version = "1.0.1";
/**
* Parse JSON string into data structure
*
* @param {string} str
* @param {function({string} value[, "number"|"string"])|null} converter
* @return {*}
*/
function parse(str, converter = null) {
local state;
local stack = []
local container;
local key;
local value;
// actions for string tokens
local string = {
go = function () {
state = "ok";
},
firstokey = function () {
key = value;
state = "colon";
},
okey = function () {
key = value;
state = "colon";
},
ovalue = function () {
value = this._convert(value, "string", converter);
state = "ocomma";
}.bindenv(this),
firstavalue = function () {
value = this._convert(value, "string", converter);
state = "acomma";
}.bindenv(this),
avalue = function () {
value = this._convert(value, "string", converter);
state = "acomma";
}.bindenv(this)
};
// the actions for number tokens
local number = {
go = function () {
state = "ok";
},
ovalue = function () {
value = this._convert(value, "number", converter);
state = "ocomma";
}.bindenv(this),
firstavalue = function () {
value = this._convert(value, "number", converter);
state = "acomma";
}.bindenv(this),
avalue = function () {
value = this._convert(value, "number", converter);
state = "acomma";
}.bindenv(this)
};
// action table
// describes where the state machine will go from each given state
local action = {
"{": {
go = function () {
stack.push({state = "ok"});
container = {};
state = "firstokey";
},
ovalue = function () {
stack.push({container = container, state = "ocomma", key = key});
container = {};
state = "firstokey";
},
firstavalue = function () {
stack.push({container = container, state = "acomma"});
container = {};
state = "firstokey";
},
avalue = function () {
stack.push({container = container, state = "acomma"});
container = {};
state = "firstokey";
}
},
"}" : {
firstokey = function () {
local pop = stack.pop();
value = container;
container = ("container" in pop) ? pop.container : null;
key = ("key" in pop) ? pop.key : null;
state = pop.state;
},
ocomma = function () {
local pop = stack.pop();
container[key] <- value;
value = container;
container = ("container" in pop) ? pop.container : null;
key = ("key" in pop) ? pop.key : null;
state = pop.state;
}
},
"[" : {
go = function () {
stack.push({state = "ok"});
container = [];
state = "firstavalue";
},
ovalue = function () {
stack.push({container = container, state = "ocomma", key = key});
container = [];
state = "firstavalue";
},
firstavalue = function () {
stack.push({container = container, state = "acomma"});
container = [];
state = "firstavalue";
},
avalue = function () {
stack.push({container = container, state = "acomma"});
container = [];
state = "firstavalue";
}
},
"]" : {
firstavalue = function () {
local pop = stack.pop();
value = container;
container = ("container" in pop) ? pop.container : null;
key = ("key" in pop) ? pop.key : null;
state = pop.state;
},
acomma = function () {
local pop = stack.pop();
container.push(value);
value = container;
container = ("container" in pop) ? pop.container : null;
key = ("key" in pop) ? pop.key : null;
state = pop.state;
}
},
":" : {
colon = function () {
// Check if the key already exists
// NOTE previous code used 'if (key in container)...'
// but this finds table ('container') member methods too
local err = false;
foreach (akey, avalue in container) {
if (akey == key) err = true;
break
}
if (err) throw "Duplicate key \"" + key + "\"";
state = "ovalue";
}
},
"," : {
ocomma = function () {
container[key] <- value;
state = "okey";
},
acomma = function () {
container.push(value);
state = "avalue";
}
},
"true" : {
go = function () {
value = true;
state = "ok";
},
ovalue = function () {
value = true;
state = "ocomma";
},
firstavalue = function () {
value = true;
state = "acomma";
},
avalue = function () {
value = true;
state = "acomma";
}
},
"false" : {
go = function () {
value = false;
state = "ok";
},
ovalue = function () {
value = false;
state = "ocomma";
},
firstavalue = function () {
value = false;
state = "acomma";
},
avalue = function () {
value = false;
state = "acomma";
}
},
"null" : {
go = function () {
value = null;
state = "ok";
},
ovalue = function () {
value = null;
state = "ocomma";
},
firstavalue = function () {
value = null;
state = "acomma";
},
avalue = function () {
value = null;
state = "acomma";
}
}
};
//
state = "go";
stack = [];
// current tokenizeing position
local start = 0;
try {
local
result,
token,
tokenizer = _JSONTokenizer();
while (token = tokenizer.nextToken(str, start)) {
if ("ptfn" == token.type) {
// punctuation/true/false/null
action[token.value][state]();
} else if ("number" == token.type) {
// number
value = token.value;
number[state]();
} else if ("string" == token.type) {
// string
value = tokenizer.unescape(token.value);
string[state]();
}
start += token.length;
}
} catch (e) {
state = e;
}
// check is the final state is not ok
// or if there is somethign left in the str
if (state != "ok" || regexp("[^\\s]").capture(str, start)) {
local min = @(a, b) a < b ? a : b;
local near = str.slice(start, min(str.len(), start + 10));
throw "JSON Syntax Error near `" + near + "`"; <---- 291
}
return value;
}
i have no idea why this is caused. To investigate, we need the reply string from proxycheck.io which when passed to JsonParser is throwing the error.
Did you bypassed their daily limit or something so something different is send back as reply?
The inference is the string may not be in the format preferred by JsonParser.
Try to print the string like this
foreach(s in str)stdout.writen(s, 'c');
in line 190.
Quote from: habi on Aug 18, 2023, 07:36 AMi have no idea why this is caused. To investigate, we need the reply string from proxycheck.io which when passed to JsonParser is throwing the error.
Did you bypassed their daily limit or something so something different is send back as reply?
The inference is the string may not be in the format preferred by JsonParser.
Try to print the string like this
foreach(s in str)stdout.writen(s, 'c');
in line 190.
Well maybe this error was unexpected, i mean now it doesn't show any bug and server showed "segmentation fault" and turned off
its only happen when 5 6 people joined the server at a time
I understand it is occuring when 3-4 players join the server. So it must have something to do with onPlayerJoin function also. Post your onPlayerJoin function.
I understand it is occuring when 3-4 players join the server
Yes only when they keep join in a row
here's my function
function onPlayerJoin( player )
{
status[ player.ID ] = Playerstats();
chat[player.ID] = ChatClass()
CheckProxy(player.IP);
CheckTempBan(player);
CheckBan(player.ID);
local nickcheck = IsNum(player.Name)
if (nickcheck) {
ServerMessage("[#FF0000]** Auto Kick[#FFFFFF] [ " +player.Name+" ][#FF0000] Reason: [#FFFFFF][Invalid nick numbers not allowed Connect with proper nick ]");
EchoMessage("** Auto Kick [ " +player.Name+" ] Reason: [ Invalid nick numbers not allowed Connect with proper nick ]");
KickPlayer( player );
}
player.Angle = -12.90654;
AddAlias( player );
local country = geoip_country_name_by_addr(player.IP);
if (country != null) // the plugin returned a meaningful result
ServerMessage("[#FFFFFF][ " +player.Name+" ] is connecting from [ " + country + " ] ["+ geoip_country_code_by_addr(player.IP) + "]");
EchoMessage("* [ " + player.Name + " ] is connecting from [ " + country + " ]. [" + geoip_country_code_by_addr(player.IP) + "]");
PlayerInfo(player);
GetSpawnWepData(player);
status[ player.ID ].Timeplayed = time();
local q = QuerySQL(db, "SELECT Name,Warn FROM Warn WHERE Name='"+player.Name+"'");
if (GetSQLColumnData(q,0) == null)
{
QuerySQL(db, "INSERT INTO Warn (Name, Warn) VALUES ('"+player.Name+"', '0')");}
if (GetSQLColumnData(q,0) == player.Name)
{
QuerySQL(db, "UPDATE Warn SET Warn='0' WHERE Name='" + player.Name + "'");}
FreeSQLQuery( q );
}
Here are a few suggestions:
1. Add a return statement after KickPlayer(player);
KickPlayer( player );
return;
Because after kicking player, do not use player.ID, player.Name, etc etc
Add a print statement 'before and after' in onPlayerJoin.
function onPlayerJoin(player)
{
print("onPlayerJoin for player"+player.Name+" called");
...
//here all codes
...
print("onPlayerJoin completed");
}
Now please join 4-5 players and show us the result of console.(you can copy paste them in '['code']'