Skip to content

Commit

Permalink
Support FiveM Protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Jan 14, 2024
1 parent a0ac831 commit 519ca88
Show file tree
Hide file tree
Showing 8 changed files with 834 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ from opengsq.protocols.ase import ASE
from opengsq.protocols.battlefield import Battlefield
from opengsq.protocols.doom3 import Doom3
from opengsq.protocols.eos import EOS
from opengsq.protocols.fivem import FiveM
from opengsq.protocols.gamespy1 import GameSpy1
from opengsq.protocols.gamespy2 import GameSpy2
from opengsq.protocols.gamespy3 import GameSpy3
Expand Down
1 change: 1 addition & 0 deletions opengsq/protocols/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from opengsq.protocols.battlefield import Battlefield
from opengsq.protocols.doom3 import Doom3
from opengsq.protocols.eos import EOS
from opengsq.protocols.fivem import FiveM
from opengsq.protocols.gamespy1 import GameSpy1
from opengsq.protocols.gamespy2 import GameSpy2
from opengsq.protocols.gamespy3 import GameSpy3
Expand Down
41 changes: 41 additions & 0 deletions opengsq/protocols/fivem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import aiohttp
import time

from opengsq.protocol_base import ProtocolBase


class FiveM(ProtocolBase):
"""FiveM Protocol (https://docs.fivem.net/docs/server-manual/proxy-setup/)"""
full_name = 'FiveM Protocol'

async def _get(self, filename: str) -> dict:
url = f'http://{self._host}:{self._port}/{filename}.json?v={int(time.time())}'

async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
return await response.json(content_type=None)

async def get_info(self) -> dict:
return await self._get('info')

async def get_players(self) -> dict:
return await self._get('players')

async def get_dynamic(self) -> dict:
return await self._get('dynamic')


if __name__ == '__main__':
import asyncio
import json

async def main_async():
fivem = FiveM(host='45.81.17.148', port=30120, timeout=5.0)
info = await fivem.get_info()
print(json.dumps(info, indent=None) + '\n')
players = await fivem.get_players()
print(json.dumps(players, indent=None) + '\n')
dynamic = await fivem.get_dynamic()
print(json.dumps(dynamic, indent=None) + '\n')

asyncio.run(main_async())
2 changes: 1 addition & 1 deletion opengsq/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.2.4'
__version__ = '2.3.0'
30 changes: 30 additions & 0 deletions tests/protocols/test_fivem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os

import pytest
from opengsq.protocols.fivem import FiveM

from .result_handler import ResultHandler

handler = ResultHandler(os.path.basename(__file__)[:-3])
# handler.enable_save = True

# FiveM
fivem = FiveM(host='185.254.99.12', port=30120)


@pytest.mark.asyncio
async def test_get_info():
result = await fivem.get_info()
await handler.save_result('test_get_info', result)


@pytest.mark.asyncio
async def test_get_players():
result = await fivem.get_players()
await handler.save_result('test_get_players', result)


@pytest.mark.asyncio
async def test_get_dynamic():
result = await fivem.get_dynamic()
await handler.save_result('test_get_dynamic', result)
8 changes: 8 additions & 0 deletions tests/results/test_fivem/test_get_dynamic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"clients": 10,
"gametype": "Freeroam",
"hostname": "LostCityRP",
"iv": "652028923",
"mapname": "fivem-map-skater",
"sv_maxclients": "128"
}
616 changes: 616 additions & 0 deletions tests/results/test_fivem/test_get_info.json

Large diffs are not rendered by default.

136 changes: 136 additions & 0 deletions tests/results/test_fivem/test_get_players.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
[
{
"endpoint": "127.0.0.1",
"id": 1,
"identifiers": [
"license:55c9f75b3bc30f28764a37e8fd2e66f899216b0b",
"xbl:2535413625126501",
"live:1055518845242972",
"discord:620289937518100500",
"fivem:2461670",
"license2:2b6ba9fc91c63b282c2ba98037140af6a39da9ed"
],
"name": "Maedschen Tanja",
"ping": 26
},
{
"endpoint": "127.0.0.1",
"id": 9,
"identifiers": [
"license:accc150eec2b02b5da82c71409107d75e487e621",
"discord:808663781508907049",
"fivem:5033440",
"license2:5207c0e399f39ff3d3e1fd2ea806aed9c10d6e66"
],
"name": "basti",
"ping": 21
},
{
"endpoint": "127.0.0.1",
"id": 10,
"identifiers": [
"license:933cbb980b3591f6a9e8d4be278115b7fcc7f9af",
"xbl:2535456982092545",
"live:844425431815955",
"discord:591997076947075080",
"fivem:11555238",
"license2:933cbb980b3591f6a9e8d4be278115b7fcc7f9af"
],
"name": "MikeS",
"ping": 21
},
{
"endpoint": "127.0.0.1",
"id": 8,
"identifiers": [
"license:a545cb5f2ae9630fe3e3dd9b12463c5afe4e321e",
"xbl:2535449833818629",
"live:844425300837503",
"discord:1042388257507385404",
"fivem:11701281",
"license2:9ac5144665ed7c613757d4e4e006372f83dc0e10"
],
"name": "Luna Metro",
"ping": 24
},
{
"endpoint": "127.0.0.1",
"id": 5,
"identifiers": [
"license:89a0479c4c3a0683d57141004d5b0bb129eede19",
"xbl:2535418682421843",
"live:914798413546912",
"discord:1168652036506648576",
"license2:1743900011038c6bbe1618467acaff2bd8b22033"
],
"name": "rossowsean",
"ping": 38
},
{
"endpoint": "127.0.0.1",
"id": 7,
"identifiers": [
"license:a36a1d2e9122d9185205cd776028ea5c6e48f297",
"discord:731443398178766859",
"fivem:10674213",
"license2:0d22eb958c275eea74a0f746e1262567e2ba47bb"
],
"name": "nini ",
"ping": 20
},
{
"endpoint": "127.0.0.1",
"id": 11,
"identifiers": [
"license:36c0aa8aaeef3283bbfe3f2f9d1e87ce7e578931",
"xbl:2535412205332266",
"live:1688849970711335",
"discord:769657569622360065",
"fivem:4145740",
"license2:36c0aa8aaeef3283bbfe3f2f9d1e87ce7e578931"
],
"name": "Jake.Richard",
"ping": 21
},
{
"endpoint": "127.0.0.1",
"id": 12,
"identifiers": [
"license:e111a35bc943f883f44466de10cae49bbfdfa583",
"xbl:2535435837379177",
"live:914798993902704",
"discord:511599913193177094",
"fivem:8918852",
"license2:7ea1060a1a868b54e29527bc8a06b3382d5e50c9"
],
"name": "colin",
"ping": 48
},
{
"endpoint": "127.0.0.1",
"id": 13,
"identifiers": [
"license:0dac7e3e0d8e8bcd13fd8bae87818aa9c02d79a2",
"xbl:2535411447092852",
"live:914801821086552",
"discord:535479677439967239",
"fivem:3761874",
"license2:0dac7e3e0d8e8bcd13fd8bae87818aa9c02d79a2"
],
"name": "Jan",
"ping": 31
},
{
"endpoint": "127.0.0.1",
"id": 14,
"identifiers": [
"license:4cae242fae2f4e019c74eb8512a357040402b8d3",
"xbl:2535432367179001",
"live:1055519252860983",
"discord:716394258155700335",
"license2:60a02a04a3e05621a481d08835b4f76fafab8ded"
],
"name": "gamer_kev1",
"ping": 20
}
]

0 comments on commit 519ca88

Please sign in to comment.