-
Bug
-
Resolution: Awaiting Response
-
None
-
1.21.50
-
None
-
Linux
-
Unconfirmed
Not sure if this is an issue related to just the newest version, or if it effects older versions as well. I just encountered this issue when creating a new addon.
Basically I created an addon that uses the server.net module for the scripting API, which sends a HTTP post request to a web server I have running locally when a player leaves or joins the server. I have tested the addon on the Windows version on BDS (Test Server) and it worked perfectly. Comes time to add it to the live server I have running on Linux, and I have issues.
The server console tells me that the addon has loaded sucessfully, and most functions of the addon work perfectly fine. The issues start when this line of code is run.
const response = await http.request(req);
Which is the line that sends the HTTP post request to the web server. Here is the whole function
async function logPlayerJoinOrLeave(player, totalOnline, connectOrDisconect) {
try {
let responseBody = "API calls quota exceeded! maximum admitted 1 per 3s.";
// Ensure that 'players' and 'key' are not undefined or empty
if (!players || !players.length)
const key = "XXXX"; // Make sure to replace with a valid key if needed
if (!key)
var URL = 'http://xxx.xxx.x.xxx:xxxx/LogPlayerActivity?player=' + player + '&totalOnline=' + totalOnline + '&connectOrDisconect=' + connectOrDisconect + '&key=' + key;
URL = URL.replace(/\s+/g, '%20');
const req = new HttpRequest(URL);
req.method = HttpRequestMethod.Post;
req.headers = [
new HttpHeader('accept', 'text/plain'),
];
// Await the request and log the response or error
***//const response = await http.request(req);***
responseBody = response.body
if(responseBody == "API calls quota exceeded! maximum admitted 1 per 3s."){
server.system.runTimeout(() =>
, 3000);
}
} catch (error)
}
This is the event listener that triggers the above function
world.afterEvents.playerJoin.subscribe(e =>
{ var player = e.playerName var totalOnline = world.getAllPlayers().length + 1; var connectOrDisconect = true logPlayerJoinOrLeave(player, totalOnline, connectOrDisconect) })
When I uncomment the offending line, when a player joins the server their game hangs on "locating server". The console says the player has connected and spawned in, and if they click "cancel" or close the game the console shows them disconecting. If I try to stop the server using the "stop" command after a player attempted to connect, the server also hangs and I have to force close it. And no, the HTTP post request never goes through.
Not sure if this is a known bug or if there is a work around, but for now I am not logging player connects or disconnects. I am assuming this is some form of bug since the above code works flawlessly on the Windows version on BDS.