From 36e54e89b703439d4e457125e357327a147e0120 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sat, 21 Mar 2026 10:19:01 +0000 Subject: [PATCH] add maprestart command --- README.md | 7 ++++--- src/q3rcon_cli/cli.py | 13 +++++++++++-- src/q3rcon_cli/commands/__init__.py | 2 ++ src/q3rcon_cli/commands/maprestart.py | 22 ++++++++++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 src/q3rcon_cli/commands/maprestart.py diff --git a/README.md b/README.md index fd0a986..235e302 100644 --- a/README.md +++ b/README.md @@ -60,14 +60,15 @@ export Q3RCON_CLI_PASSWORD="" Usage: q3rcon-cli [OPTIONS] COMMAND ┏━ Subcommands ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ -┃ status Prints the status of the server ┃ -┃ mapname Prints the current map name of the server ┃ -┃ maprotate Rotates the map to the next one in the map rotation list ┃ ┃ fastrestart Executes a fast restart of the server ┃ ┃ gametype Get or set the current gametype of the server ┃ ┃ hostname Get or set the current hostname of the server ┃ ┃ map Get the current map or change to a new one ┃ +┃ mapname Prints the current map name of the server ┃ +┃ maprestart Restarts the current map ┃ +┃ maprotate Rotates the map to the next one in the map rotation list ┃ ┃ plugins Prints the currently loaded plugins of the server ┃ +┃ status Prints the status of the server ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ┏━ Options ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ diff --git a/src/q3rcon_cli/cli.py b/src/q3rcon_cli/cli.py index b9f3f16..aa64894 100644 --- a/src/q3rcon_cli/cli.py +++ b/src/q3rcon_cli/cli.py @@ -9,6 +9,7 @@ from .commands import ( Hostname, Map, Mapname, + Maprestart, Maprotate, Plugins, Status, @@ -16,7 +17,15 @@ from .commands import ( from .console import Console Subcommands = ( - Status | Mapname | Maprotate | Fastrestart | Gametype | Hostname | Map | Plugins + Fastrestart + | Gametype + | Hostname + | Map + | Mapname + | Maprestart + | Maprotate + | Plugins + | Status ) @@ -54,7 +63,7 @@ class Q3rconCli(Command): if self.interactive: await self.run_interactive() else: - await Status.run(self) + await Status(self.host, self.port, self.password).run() async def run_interactive(self): print( diff --git a/src/q3rcon_cli/commands/__init__.py b/src/q3rcon_cli/commands/__init__.py index 21a1e75..7f02e38 100644 --- a/src/q3rcon_cli/commands/__init__.py +++ b/src/q3rcon_cli/commands/__init__.py @@ -3,6 +3,7 @@ from .gametype import Gametype from .hostname import Hostname from .map import Map from .mapname import Mapname +from .maprestart import Maprestart from .maprotate import Maprotate from .plugins import Plugins from .status import Status @@ -16,4 +17,5 @@ __all__ = [ 'Hostname', 'Map', 'Plugins', + 'Maprestart', ] diff --git a/src/q3rcon_cli/commands/maprestart.py b/src/q3rcon_cli/commands/maprestart.py new file mode 100644 index 0000000..67f16a3 --- /dev/null +++ b/src/q3rcon_cli/commands/maprestart.py @@ -0,0 +1,22 @@ +from aioq3rcon import Client +from clypi import Command, Spinner, arg +from typing_extensions import override + +from q3rcon_cli.console import Console + + +class Maprestart(Command): + """Restarts the current map.""" + + host: str = arg(inherited=True) + port: int = arg(inherited=True) + password: str = arg(inherited=True) + + @override + async def run(self): + async with Spinner('Restarting map...'): + async with Client( + self.host, self.port, self.password, fragment_read_timeout=1 + ) as client: + if response := await client.send_command('map_restart'): + Console.print_response(response)