Skip to content

Commit

Permalink
feat: Add multi-platform support for Gametools
Browse files Browse the repository at this point in the history
  • Loading branch information
cetteup committed Apr 27, 2024
1 parent 5bf4d14 commit d1fca3e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
12 changes: 11 additions & 1 deletion GameserverLister/commands/gametools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from GameserverLister.commands.options import common, http
from GameserverLister.common.logger import logger
from GameserverLister.common.types import GametoolsGame
from GameserverLister.common.types import GametoolsGame, GametoolsPlatform
from GameserverLister.listers import GametoolsServerLister


Expand All @@ -17,6 +17,14 @@
required=True,
help='Game to list servers for'
)
@click.option(
'-pf',
'--platform',
type=click.Choice(GametoolsPlatform),
required=True,
help='Platform to list servers for',
default=GametoolsPlatform.PC
)
@click.option(
'--include-official',
default=False,
Expand All @@ -34,6 +42,7 @@
@common.debug
def run(
game: GametoolsGame,
platform: GametoolsPlatform,
page_limit: int,
sleep: float,
max_attempts: int,
Expand All @@ -51,6 +60,7 @@ def run(

lister = GametoolsServerLister(
game,
platform,
page_limit,
expired_ttl,
recover,
Expand Down
2 changes: 2 additions & 0 deletions GameserverLister/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ class BattlelogPlatform(Platform):

class GametoolsPlatform(Platform):
PC = 'pc'
PS4 = 'ps4'
XboxOne = 'xboxone'


@dataclass
Expand Down
5 changes: 3 additions & 2 deletions GameserverLister/listers/gametools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class GametoolsServerLister(HttpServerLister):
def __init__(
self,
game: GametoolsGame,
platform: GametoolsPlatform,
page_limit: int,
expired_ttl: float,
recover: bool,
Expand All @@ -31,7 +32,7 @@ def __init__(
):
super().__init__(
game,
GametoolsPlatform.PC,
platform,
GametoolsServer,
page_limit,
100,
Expand All @@ -48,7 +49,7 @@ def __init__(
self.include_official = include_official

def get_server_list_url(self, per_page: int) -> str:
return f'{GAMETOOLS_BASE_URI}/{self.game}/servers/?name=&limit={per_page}' \
return f'{GAMETOOLS_BASE_URI}/{self.game}/servers/?platform={self.platform}&name=&limit={per_page}' \
f'&nocache={datetime.now().timestamp()}'

def add_page_found_servers(self, found_servers: List[GametoolsServer], page_response_data: dict) -> List[GametoolsServer]:
Expand Down

0 comments on commit d1fca3e

Please sign in to comment.