mirror of
https://github.com/onyx-and-iris/q3rcon-cli.git
synced 2026-04-17 22:43:39 +00:00
first commit
This commit is contained in:
19
src/q3rcon_cli/commands/__init__.py
Normal file
19
src/q3rcon_cli/commands/__init__.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from .fastrestart import Fastrestart
|
||||
from .gametype import Gametype
|
||||
from .hostname import Hostname
|
||||
from .map import Map
|
||||
from .mapname import Mapname
|
||||
from .maprotate import Maprotate
|
||||
from .plugins import Plugins
|
||||
from .status import Status
|
||||
|
||||
__all__ = [
|
||||
'Status',
|
||||
'Mapname',
|
||||
'Maprotate',
|
||||
'Fastrestart',
|
||||
'Gametype',
|
||||
'Hostname',
|
||||
'Map',
|
||||
'Plugins',
|
||||
]
|
||||
19
src/q3rcon_cli/commands/fastrestart.py
Normal file
19
src/q3rcon_cli/commands/fastrestart.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from aioq3rcon import Client
|
||||
from clypi import Command, arg
|
||||
from typing_extensions import override
|
||||
|
||||
from q3rcon_cli.console import Console
|
||||
|
||||
|
||||
class Fastrestart(Command):
|
||||
"""Executes a fast restart of the server."""
|
||||
|
||||
host: str = arg(inherited=True)
|
||||
port: int = arg(inherited=True)
|
||||
password: str = arg(inherited=True)
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
async with Client(self.host, self.port, self.password) as client:
|
||||
if response := await client.send_command('fast_restart'):
|
||||
Console.print_response(response)
|
||||
43
src/q3rcon_cli/commands/gametype.py
Normal file
43
src/q3rcon_cli/commands/gametype.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from aioq3rcon import Client
|
||||
from clypi import Command, Positional, Spinner, arg
|
||||
from typing_extensions import override
|
||||
|
||||
from q3rcon_cli.console import Console
|
||||
|
||||
|
||||
class Gametype(Command):
|
||||
"""Get or set the current gametype of the server."""
|
||||
|
||||
new_gametype: Positional[str] = arg(
|
||||
help='The new gametype to change to (optional). If not provided, the current gametype will be printed.',
|
||||
default='',
|
||||
)
|
||||
host: str = arg(inherited=True)
|
||||
port: int = arg(inherited=True)
|
||||
password: str = arg(inherited=True)
|
||||
force: bool = arg(
|
||||
False,
|
||||
short='f',
|
||||
help='Whether to force the gametype change even if players are currently in the server.',
|
||||
)
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
if not Gametype.new_gametype:
|
||||
async with Client(self.host, self.port, self.password) as client:
|
||||
if response := await client.send_command('g_gametype'):
|
||||
Console.print_cvar(response)
|
||||
return
|
||||
|
||||
async with Client(self.host, self.port, self.password) as client:
|
||||
DEFAULT_FRAGMENT_READ_TIMEOUT = client.fragment_read_timeout
|
||||
|
||||
await client.send_command(f'g_gametype {self.new_gametype}')
|
||||
if self.force:
|
||||
async with Spinner('Forcing gametype change...'):
|
||||
client.fragment_read_timeout = 1
|
||||
await client.send_command('map_restart')
|
||||
|
||||
client.fragment_read_timeout = DEFAULT_FRAGMENT_READ_TIMEOUT
|
||||
if response := await client.send_command('g_gametype'):
|
||||
Console.print_cvar(response)
|
||||
30
src/q3rcon_cli/commands/hostname.py
Normal file
30
src/q3rcon_cli/commands/hostname.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from aioq3rcon import Client
|
||||
from clypi import Command, Positional, arg
|
||||
from typing_extensions import override
|
||||
|
||||
from q3rcon_cli.console import Console
|
||||
|
||||
|
||||
class Hostname(Command):
|
||||
"""Get or set the current hostname of the server."""
|
||||
|
||||
new_hostname: Positional[str] = arg(
|
||||
help='The new hostname to change to (optional). If not provided, the current hostname will be printed.',
|
||||
default='',
|
||||
)
|
||||
host: str = arg(inherited=True)
|
||||
port: int = arg(inherited=True)
|
||||
password: str = arg(inherited=True)
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
if not self.new_hostname:
|
||||
async with Client(self.host, self.port, self.password) as client:
|
||||
if response := await client.send_command('sv_hostname'):
|
||||
Console.print_cvar(response)
|
||||
return
|
||||
|
||||
async with Client(self.host, self.port, self.password) as client:
|
||||
await client.send_command(f'sv_hostname {self.new_hostname}')
|
||||
if response := await client.send_command('sv_hostname'):
|
||||
Console.print_cvar(response)
|
||||
33
src/q3rcon_cli/commands/map.py
Normal file
33
src/q3rcon_cli/commands/map.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from aioq3rcon import Client
|
||||
from clypi import Command, Positional, Spinner, arg
|
||||
from typing_extensions import override
|
||||
|
||||
from q3rcon_cli.console import Console
|
||||
|
||||
|
||||
class Map(Command):
|
||||
"""Get the current map or change to a new one."""
|
||||
|
||||
new_map: Positional[str] = arg(
|
||||
help='The new map to change to (optional). If not provided, the current map will be printed.',
|
||||
default='',
|
||||
)
|
||||
host: str = arg(inherited=True)
|
||||
port: int = arg(inherited=True)
|
||||
password: str = arg(inherited=True)
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
if not self.new_map:
|
||||
async with Client(self.host, self.port, self.password) as client:
|
||||
if response := await client.send_command('mapname'):
|
||||
Console.print_cvar(response)
|
||||
return
|
||||
|
||||
async with Spinner('Changing map...'):
|
||||
async with Client(
|
||||
self.host, self.port, self.password, fragment_read_timeout=1
|
||||
) as client:
|
||||
await client.send_command(f'map mp_{self.new_map.removeprefix("mp_")}')
|
||||
if response := await client.send_command('mapname'):
|
||||
Console.print_cvar(response)
|
||||
19
src/q3rcon_cli/commands/mapname.py
Normal file
19
src/q3rcon_cli/commands/mapname.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from aioq3rcon import Client
|
||||
from clypi import Command, arg
|
||||
from typing_extensions import override
|
||||
|
||||
from q3rcon_cli.console import Console
|
||||
|
||||
|
||||
class Mapname(Command):
|
||||
"""Prints the current map name of the server."""
|
||||
|
||||
host: str = arg(inherited=True)
|
||||
port: int = arg(inherited=True)
|
||||
password: str = arg(inherited=True)
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
async with Client(self.host, self.port, self.password) as client:
|
||||
if response := await client.send_command('mapname'):
|
||||
Console.print_cvar(response)
|
||||
22
src/q3rcon_cli/commands/maprotate.py
Normal file
22
src/q3rcon_cli/commands/maprotate.py
Normal file
@@ -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 Maprotate(Command):
|
||||
"""Rotates the map to the next one in the map rotation list."""
|
||||
|
||||
host: str = arg(inherited=True)
|
||||
port: int = arg(inherited=True)
|
||||
password: str = arg(inherited=True)
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
async with Spinner('Rotating map...'):
|
||||
async with Client(
|
||||
self.host, self.port, self.password, fragment_read_timeout=1
|
||||
) as client:
|
||||
if response := await client.send_command('map_rotate'):
|
||||
Console.print_response(response)
|
||||
19
src/q3rcon_cli/commands/plugins.py
Normal file
19
src/q3rcon_cli/commands/plugins.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from aioq3rcon import Client
|
||||
from clypi import Command, arg
|
||||
from typing_extensions import override
|
||||
|
||||
from q3rcon_cli.console import Console
|
||||
|
||||
|
||||
class Plugins(Command):
|
||||
"""Prints the currently loaded plugins of the server."""
|
||||
|
||||
host: str = arg(inherited=True)
|
||||
port: int = arg(inherited=True)
|
||||
password: str = arg(inherited=True)
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
async with Client(self.host, self.port, self.password) as client:
|
||||
if response := await client.send_command('plugins'):
|
||||
Console.print_response(response)
|
||||
22
src/q3rcon_cli/commands/status.py
Normal file
22
src/q3rcon_cli/commands/status.py
Normal file
@@ -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 Status(Command):
|
||||
"""Prints the status of the server."""
|
||||
|
||||
host: str = arg(inherited=True)
|
||||
port: int = arg(inherited=True)
|
||||
password: str = arg(inherited=True)
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
async with Spinner('Fetching status...'):
|
||||
async with Client(
|
||||
self.host, self.port, self.password, fragment_read_timeout=0.5
|
||||
) as client:
|
||||
if response := await client.send_command('status'):
|
||||
Console.print_status(response)
|
||||
Reference in New Issue
Block a user