Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V7.0.0 Latest] Satisfactory query not working anymore #229

Open
BaxAndrei opened this issue Sep 17, 2024 · 3 comments
Open

[V7.0.0 Latest] Satisfactory query not working anymore #229

BaxAndrei opened this issue Sep 17, 2024 · 3 comments

Comments

@BaxAndrei
Copy link
Contributor

After I updated server to release 1.0, lgsl can`t query server anymore.

Server will now only use port 7777 with TCP/UDP rather than the 3 ports it uses now that are strictly UDP. (7777, 15000, 15777)

I updated my lgsl admin to use 7777 for query too but no data, server shows as offline but it is online

@BaxAndrei BaxAndrei changed the title Satisfactory query not working anymore [V7.0.0 Latest] Satisfactory query not working anymore Sep 19, 2024
@BaxAndrei
Copy link
Contributor Author

Hey! Sorry to bother you @tltneon . Any news about this? :D

@BaxAndrei
Copy link
Contributor Author

@BaxAndrei
Copy link
Contributor Author

I hope this helps you:

$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if (!$socket) {
die("Failed to create socket\n");
}

// Server address and port
$serverAddress = 'satisfactory';
$serverPort = 7777;

// Unique identifier (cookie) for the request
$cookie = microtime(true) * 1000000;

// Construct PollServerState message
$protocolMagic = 0xF6D5;
$messageType = 0; // Poll Server State
$protocolVersion = 1;
$terminatorByte = 0x1;

$message = pack('vCCP', $protocolMagic, $messageType, $protocolVersion, $cookie) . chr($terminatorByte);

// Send the message to the server
socket_sendto($socket, $message, strlen($message), 0, $serverAddress, $serverPort);

// Receive the response from the server
$response = '';
$from = '';
$port = 0;
socket_recvfrom($socket, $response, 1024, 0, $from, $port);

// Parse the response
if (strlen($response) > 0) {
$offset = 0;
$responseProtocolMagic = unpack('v', substr($response, $offset, 2))[1];
$offset += 2;
$responseType = unpack('C', substr($response, $offset, 1))[1];
$offset += 1;
$responseProtocolVersion = unpack('C', substr($response, $offset, 1))[1];
$offset += 1;
$responseCookie = unpack('P', substr($response, $offset, 8))[1];
$offset += 8;
$serverState = unpack('C', substr($response, $offset, 1))[1];
$offset += 1;
$serverNetCL = unpack('V', substr($response, $offset, 4))[1];
$offset += 4;
$serverFlags = unpack('P', substr($response, $offset, 8))[1];
$offset += 8;
$numSubStates = unpack('C', substr($response, $offset, 1))[1];
$offset += 1;

// Calculate the size of SubStates
$subStatesSize = $numSubStates * 3; // Each SubState is 3 bytes (1 byte for SubStateId and 2 bytes for SubStateVersion)
$offset += $subStatesSize;

$serverNameLength = unpack('v', substr($response, $offset, 2))[1];
$offset += 2;
$serverName = substr($response, $offset, $serverNameLength);

$serverStateDescriptions = [
	0 => 'Offline',
	1 => 'Idle',
	2 => 'Loading',
	3 => 'Playing'
];

// Output the parsed response
echo "Response Protocol Magic: $responseProtocolMagic\n";
echo "Response Type: $responseType\n";
echo "Response Protocol Version: $responseProtocolVersion\n";
echo "Response Cookie: $responseCookie\n";
echo "Server State: {$serverStateDescriptions[$serverState]}\n";
echo "Server NetCL: $serverNetCL\n";
echo "Server Flags: $serverFlags\n";
echo "Number of Sub States: $numSubStates\n";
echo "Server Name: $serverName\n";

}

// Close the socket
socket_close($socket);

I can`t find any way to get onlinePlayers or maxPlayers (most of the time is 4)

Also this might help: https://satisfactory.wiki.gg/wiki/Dedicated_servers/HTTPS_API but there is one small problem to get it working (it also sends a lot more info):

Get auth token:

curl --location 'https://SV_IP:7777/api/v1' \
--header 'Content-Type: application/json' \
--data '{
    "function": "PasswordlessLogin",
    "data": {
        "minimumPrivilegeLevel": "NotAuthenticated"
    }
}'

but if server has password you need to do this:

curl --location 'https://SV_IP:7777/api/v1' \
--header 'Content-Type: application/json' \
--data '{
    "function": "PasswordLogin",
    "data": {
        "minimumPrivilegeLevel": "Client",
        "password": "PASSWORD"
    }
}'

both requests will return:

{
    "data": {
        "authenticationToken": "++SECRET++"
    }
}

then you can query server info:

curl --location 'https://SV_IP:7777/api/v1' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ++SECRET++' \
--data '{
    "function": "QueryServerState"
}'

this will respond with:

{
    "data": {
        "serverGameState": {
            "activeSessionName": "Satisfactory Server",
            "numConnectedPlayers": 0,
            "playerLimit": 4,
            "techTier": 2,
            "activeSchematic": "/Script/Engine.BlueprintGeneratedClass'/Game/FactoryGame/Schematics/Progression/Schematic_2-2.Schematic_2-2_C'",
            "gamePhase": "/Script/FactoryGame.FGGamePhase'/Game/FactoryGame/GamePhases/GP_Project_Assembly_Phase_0.GP_Project_Assembly_Phase_0'",
            "isGameRunning": true,
            "totalGameDuration": 4676,
            "isGamePaused": true,
            "averageTickRate": 29.950733184814453,
            "autoLoadSessionName": "Satisfactory Server"
        }
    }
}

But there are 2 things:

  1. If server is password protected you need an extra field in lgsl to store the password for auth token generation
  2. Lightweight Server Query API is available at all times when the server is running, except for when it is starting up. When the server is performing a save game load or a map change, the lightweight query API will retain it’s availability, but will report Loading as the server status. In that state, HTTPS API becomes temporarily unavailable until the blocking work on the server is finished.

Hope this helps you more!

tltneon added a commit that referenced this issue Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant