-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8b3f2a
commit e101b57
Showing
7 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import struct | ||
|
||
from opengsq.binary_reader import BinaryReader | ||
from opengsq.exceptions import InvalidPacketException | ||
from opengsq.protocol_base import ProtocolBase | ||
from opengsq.socket_async import SocketAsync | ||
|
||
|
||
class Satisfactory(ProtocolBase): | ||
"""Satisfactory Protocol""" | ||
full_name = 'Satisfactory Protocol' | ||
|
||
async def get_status(self) -> dict: | ||
""" | ||
Retrieves information about the server including state, version, and beacon port | ||
Server state: 1 - Idle (no game loaded), 2 - currently loading or creating a game, 3 - currently in game | ||
""" | ||
# Credit: https://github.com/dopeghoti/SF-Tools/blob/main/Protocol.md | ||
|
||
# Send message id, protocol version | ||
request = struct.pack('2b', 0, 0) + 'opengsq'.encode() | ||
response = await SocketAsync.send_and_receive(self._address, self._query_port, self._timeout, request) | ||
br = BinaryReader(response) | ||
header = br.read_byte() | ||
|
||
if header != 1: | ||
raise InvalidPacketException('Packet header mismatch. Received: {}. Expected: {}.'.format(chr(header), chr(1))) | ||
|
||
br.read_byte() # Protocol version | ||
br.read_bytes(8) # Request data | ||
|
||
result = {} | ||
result['State'] = br.read_byte() | ||
result['Version'] = br.read_long() | ||
result['BeaconPort'] = br.read_short() | ||
|
||
return result | ||
|
||
|
||
if __name__ == '__main__': | ||
import asyncio | ||
import json | ||
|
||
async def main_async(): | ||
satisfactory = Satisfactory(address='delta3.ptse.host', query_port=15777, timeout=5.0) | ||
status = await satisfactory.get_status() | ||
print(json.dumps(status, indent=None) + '\n') | ||
|
||
asyncio.run(main_async()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '1.4.5' | ||
__version__ = '1.5.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from opengsq.protocols.satisfactory import Satisfactory | ||
|
||
from .result_handler import ResultHandler | ||
|
||
handler = ResultHandler(os.path.basename(__file__)[:-3]) | ||
handler.enable_save = True | ||
|
||
# Satisfactory | ||
test = Satisfactory(address='delta3.ptse.host', query_port=15777) | ||
|
||
@pytest.mark.asyncio | ||
async def test_get_status(): | ||
result = await test.get_status() | ||
await handler.save_result('test_get_status', result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"State": 3, | ||
"Version": 211839, | ||
"BeaconPort": 15000 | ||
} |