-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Epic Online Services (EOS) Protocol
- Loading branch information
1 parent
90fceb9
commit f02b4c2
Showing
8 changed files
with
184 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import aiohttp | ||
import base64 | ||
import json | ||
|
||
from opengsq.exceptions import ServerNotFoundException | ||
from opengsq.protocol_base import ProtocolBase | ||
|
||
|
||
class EOS(ProtocolBase): | ||
"""Epic Online Services (EOS) Protocol""" | ||
full_name = 'Epic Online Services (EOS) Protocol' | ||
|
||
_api_url = 'https://api.epicgames.dev' | ||
|
||
def __init__(self, host: str, port: int, timeout: float = 5, client_id: str = None, client_secret: str = None, deployment_id: str = None): | ||
super().__init__(host, port, timeout) | ||
|
||
if client_id is None or client_secret is None or deployment_id is None: | ||
raise ValueError( | ||
"client_id, client_secret, and deployment_id must not be None") | ||
|
||
self.client_id = client_id | ||
self.client_secret = client_secret | ||
self.deployment_id = deployment_id | ||
self.access_token = None | ||
|
||
async def _get_access_token(self) -> str: | ||
url = f'{self._api_url}/auth/v1/oauth/token' | ||
body = f"grant_type=client_credentials&deployment_id={self.deployment_id}" | ||
headers = { | ||
"Authorization": f"Basic {base64.b64encode(f'{self.client_id}:{self.client_secret}'.encode('utf-8')).decode('utf-8')}", | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
} | ||
|
||
async with aiohttp.ClientSession() as session: | ||
async with session.post(url, data=body, headers=headers) as response: | ||
response.raise_for_status() | ||
data = await response.json() | ||
|
||
return data["access_token"] | ||
|
||
async def _get_matchmaking(self, data: dict): | ||
if self.access_token is None: | ||
self.access_token = await self._get_access_token() | ||
assert self.access_token is not None, "Failed to get access token" | ||
|
||
url = f"{self._api_url}/matchmaking/v1/{self.deployment_id}/filter" | ||
headers = { | ||
"Content-Type": "application/json", | ||
"Accept": "application/json", | ||
"Authorization": f"Bearer {self.access_token}" | ||
} | ||
|
||
async with aiohttp.ClientSession() as session: | ||
async with session.post(url, data=json.dumps(data), headers=headers) as response: | ||
response.raise_for_status() | ||
data = await response.json() | ||
|
||
return data | ||
|
||
async def get_info(self) -> dict: | ||
data = await self._get_matchmaking({ | ||
"criteria": [ | ||
{ | ||
"key": "attributes.ADDRESS_s", | ||
"op": "EQUAL", | ||
"value": self._host | ||
}, | ||
{ | ||
"key": "attributes.ADDRESSBOUND_s", | ||
"op": "CONTAINS", | ||
"value": self._port | ||
}, | ||
] | ||
}) | ||
|
||
if data["count"] <= 0: | ||
raise ServerNotFoundException() | ||
|
||
return data['sessions'][0] | ||
|
||
|
||
if __name__ == '__main__': | ||
import asyncio | ||
|
||
async def main_async(): | ||
client_id = 'xyza7891muomRmynIIHaJB9COBKkwj6n' | ||
client_secret = 'PP5UGxysEieNfSrEicaD1N2Bb3TdXuD7xHYcsdUHZ7s' | ||
deployment_id = 'ad9a8feffb3b4b2ca315546f038c3ae2' | ||
|
||
eos = EOS(host='150.138.77.118', port=10019, timeout=5.0, client_id=client_id, | ||
client_secret=client_secret, deployment_id=deployment_id) | ||
data = await eos.get_info() | ||
print(json.dumps(data, 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__ = '2.1.2' | ||
__version__ = '2.2.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 @@ | ||
aiohttp==3.8.6 |
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,23 @@ | ||
import os | ||
|
||
import pytest | ||
from opengsq.protocols.eos import EOS | ||
|
||
from .result_handler import ResultHandler | ||
|
||
handler = ResultHandler(os.path.basename(__file__)[:-3]) | ||
# handler.enable_save = True | ||
|
||
# ARK: Survival Ascended | ||
client_id = 'xyza7891muomRmynIIHaJB9COBKkwj6n' | ||
client_secret = 'PP5UGxysEieNfSrEicaD1N2Bb3TdXuD7xHYcsdUHZ7s' | ||
deployment_id = 'ad9a8feffb3b4b2ca315546f038c3ae2' | ||
|
||
eos = EOS(host='150.138.77.118', port=10019, client_id=client_id, | ||
client_secret=client_secret, deployment_id=deployment_id) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_info(): | ||
result = await eos.get_info() | ||
await handler.save_result('test_get_info', 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,57 @@ | ||
{ | ||
"deployment": "ad9a8feffb3b4b2ca315546f038c3ae2", | ||
"id": "d0ce97bf965043b4a39d72c41d6aa10a", | ||
"bucket": "TestGameMode_C:<None>:TheIsland_WP", | ||
"settings": { | ||
"maxPublicPlayers": 127, | ||
"allowInvites": true, | ||
"shouldAdvertise": true, | ||
"allowReadById": true, | ||
"allowJoinViaPresence": true, | ||
"allowJoinInProgress": true, | ||
"allowConferenceRoom": false, | ||
"checkSanctions": false, | ||
"allowMigration": false, | ||
"rejoinAfterKick": "", | ||
"platforms": null | ||
}, | ||
"totalPlayers": 113, | ||
"openPublicPlayers": 14, | ||
"publicPlayers": [], | ||
"started": false, | ||
"lastUpdated": null, | ||
"attributes": { | ||
"MINORBUILDID_s": "11", | ||
"MODID_l": 0, | ||
"CUSTOMSERVERNAME_s": "服主云服务器出租QQ1165782150 低延迟-带假人++", | ||
"ADDRESSDEV_s": "150.138.77.118,127.0.0.1", | ||
"ISPRIVATE_l": 0, | ||
"SERVERPASSWORD_b": false, | ||
"MATCHTIMEOUT_d": 120.0, | ||
"ENABLEDMODSFILEIDS_s": "4850852,4854705,4846256", | ||
"DAYTIME_s": "126", | ||
"SOTFMATCHSTARTED_b": false, | ||
"STEELSHIELDENABLED_l": 0, | ||
"SERVERUSESBATTLEYE_b": false, | ||
"EOSSERVERPING_l": 252, | ||
"ALLOWDOWNLOADCHARS_l": 1, | ||
"OFFICIALSERVER_s": "0", | ||
"GAMEMODE_s": "TestGameMode_C", | ||
"ADDRESS_s": "150.138.77.118", | ||
"SEARCHKEYWORDS_s": "Custom", | ||
"__EOS_BLISTENING_b": true, | ||
"ALLOWDOWNLOADITEMS_l": 1, | ||
"LEGACY_l": 0, | ||
"ADDRESSBOUND_s": "0.0.0.0:10019", | ||
"SESSIONISPVE_l": 0, | ||
"__EOS_BUSESPRESENCE_b": true, | ||
"ENABLEDMODS_s": "931443,928793,900062", | ||
"SESSIONNAMEUPPER_s": "服主云服务器出租QQ1165782150 低延迟-带假人++ - (V26.11)", | ||
"SERVERPLATFORMTYPE_s": "All", | ||
"MAPNAME_s": "TheIsland_WP", | ||
"BUILDID_s": "26", | ||
"SESSIONNAME_s": "服主云服务器出租QQ1165782150 低延迟-带假人++ - (v26.11)" | ||
}, | ||
"owner": "Client_xyza7891muomRmynIIHaJB9COBKkwj6n", | ||
"ownerPlatformId": null | ||
} |