mirror of
https://github.com/onyx-and-iris/q3rcon-cli.git
synced 2026-04-13 04:23:38 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a7cc3eacb | |||
| fce5858a93 | |||
| a9aff25c4e | |||
| 7af5caad89 | |||
| ac5b117e2c | |||
| 4f5272ac32 | |||
| 04c4e40063 | |||
| 2233f5eda1 |
@@ -20,7 +20,7 @@ classifiers = [
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"Programming Language :: Python :: Implementation :: PyPy",
|
||||
]
|
||||
dependencies = ["aio-q3-rcon>=1.0.0", "clypi>=1.8.2"]
|
||||
dependencies = ["aio-q3-rcon>=1.0.1", "clypi>=1.8.2"]
|
||||
|
||||
[project.scripts]
|
||||
q3rcon-cli = "q3rcon_cli.cli:main"
|
||||
@@ -34,7 +34,7 @@ Source = "https://github.com/onyx-and-iris/q3rcon-cli"
|
||||
path = "src/q3rcon_cli/__about__.py"
|
||||
|
||||
[tool.hatch.envs.default]
|
||||
dependencies = ["aio-q3-rcon @ {root:parent:uri}/aio-q3-rcon"]
|
||||
workspace.members = [{ path = "../aio-q3-rcon" }]
|
||||
|
||||
[tool.hatch.envs.types]
|
||||
extra-dependencies = ["mypy>=1.0.0"]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2026-present onyx-and-iris <code@onyxandiris.online>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
__version__ = '0.2.1'
|
||||
__version__ = '0.2.4'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from aioq3rcon import Client
|
||||
from clypi import Command, Positional, Spinner, arg
|
||||
from clypi import Command, Positional, Spinner, arg, cprint
|
||||
from typing_extensions import override
|
||||
|
||||
from q3rcon_cli import console
|
||||
@@ -23,21 +23,17 @@ class Gametype(Command):
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
if not Gametype.new_gametype:
|
||||
if not self.new_gametype:
|
||||
async with Client(self.host, self.port, self.password) as client:
|
||||
if response := await client.send_command('g_gametype'):
|
||||
console.out.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...'):
|
||||
async with Spinner('Forcing gametype change', suffix='...'):
|
||||
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.out.print_cvar(response)
|
||||
cprint(f'Gametype changed successfully to {self.new_gametype}.', fg='green')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from aioq3rcon import Client
|
||||
from clypi import Command, Positional, arg
|
||||
from clypi import Command, Positional, arg, cprint
|
||||
from typing_extensions import override
|
||||
|
||||
from q3rcon_cli import console
|
||||
@@ -26,5 +26,5 @@ class Hostname(Command):
|
||||
|
||||
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.out.print_cvar(response)
|
||||
|
||||
cprint(f'Hostname changed to: {self.new_hostname}', fg='green')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from aioq3rcon import Client
|
||||
from clypi import Command, Positional, Spinner, arg
|
||||
from clypi import Command, Positional, Spinner, arg, cprint
|
||||
from typing_extensions import override
|
||||
|
||||
from q3rcon_cli import console
|
||||
@@ -24,10 +24,10 @@ class Map(Command):
|
||||
console.out.print_cvar(response)
|
||||
return
|
||||
|
||||
async with Spinner('Changing map...'):
|
||||
async with Spinner('Changing map', suffix='...'):
|
||||
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.out.print_cvar(response)
|
||||
|
||||
cprint(f'Map changed to {self.new_map.removeprefix("mp_")}', fg='green')
|
||||
|
||||
@@ -14,7 +14,7 @@ class Maprestart(Command):
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
async with Spinner('Restarting map...'):
|
||||
async with Spinner('Restarting map', suffix='...'):
|
||||
async with Client(
|
||||
self.host, self.port, self.password, fragment_read_timeout=1
|
||||
) as client:
|
||||
|
||||
@@ -14,7 +14,7 @@ class Maprotate(Command):
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
async with Spinner('Rotating map...'):
|
||||
async with Spinner('Rotating map', suffix='...'):
|
||||
async with Client(
|
||||
self.host, self.port, self.password, fragment_read_timeout=1
|
||||
) as client:
|
||||
|
||||
@@ -14,7 +14,7 @@ class Status(Command):
|
||||
|
||||
@override
|
||||
async def run(self):
|
||||
async with Spinner('Fetching status...'):
|
||||
async with Spinner('Fetching status', suffix='...'):
|
||||
async with Client(
|
||||
self.host, self.port, self.password, fragment_read_timeout=0.5
|
||||
) as client:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import re
|
||||
|
||||
import clypi
|
||||
from clypi import cprint
|
||||
from clypi import Boxes, cprint
|
||||
|
||||
|
||||
class Console:
|
||||
@@ -33,6 +33,8 @@ class OutConsole(Console):
|
||||
r'(?P<rate>[0-9]+)$',
|
||||
re.IGNORECASE | re.VERBOSE,
|
||||
)
|
||||
STATUS_MAP_REGEX = re.compile(r'^map: (?P<mapname>mp_[a-z_]+)$')
|
||||
|
||||
CVAR_REGEX = re.compile(
|
||||
r'^["](?P<name>[a-z_]+)["]\sis[:]\s'
|
||||
r'["](?P<value>.*?)["]\s'
|
||||
@@ -69,40 +71,68 @@ class OutConsole(Console):
|
||||
_guids.append(m.group('guid'))
|
||||
_names.append(self._remove_colour_codes(m.group('name')))
|
||||
_ips.append(m.group('ip'))
|
||||
elif m := OutConsole.STATUS_MAP_REGEX.match(line):
|
||||
cprint(f'\nCurrent map: {m.group("mapname")}', fg=self.style)
|
||||
|
||||
if not _slots:
|
||||
cprint('\nNo players connected.\n', fg=self.style)
|
||||
cprint('No players connected.', fg='red')
|
||||
return
|
||||
|
||||
slots = clypi.boxed(_slots, title='Slot', width=15)
|
||||
scores = clypi.boxed(_scores, title='Score', width=15)
|
||||
pings = clypi.boxed(_pings, title='Ping', width=15)
|
||||
guids = clypi.boxed(_guids, title='GUID', width=40)
|
||||
names = clypi.boxed(_names, title='Name', width=30)
|
||||
ips = clypi.boxed(_ips, title='IP', width=30)
|
||||
print(f'\n{clypi.stack(slots, scores, pings, guids, names, ips, padding=0)}')
|
||||
slots = clypi.boxed(
|
||||
_slots, title='Slot', width=10, align='center', style=Boxes.ROUNDED
|
||||
)
|
||||
scores = clypi.boxed(
|
||||
_scores, title='Score', width=10, align='center', style=Boxes.ROUNDED
|
||||
)
|
||||
pings = clypi.boxed(
|
||||
_pings, title='Ping', width=10, align='center', style=Boxes.ROUNDED
|
||||
)
|
||||
guids = clypi.boxed(
|
||||
_guids,
|
||||
title='GUID',
|
||||
width=len(max(_guids, key=len)) + 4,
|
||||
style=Boxes.ROUNDED,
|
||||
)
|
||||
names = clypi.boxed(
|
||||
_names,
|
||||
title='Name',
|
||||
width=len(max(_names, key=len)) + 4,
|
||||
style=Boxes.ROUNDED,
|
||||
)
|
||||
ips = clypi.boxed(
|
||||
_ips, title='IP', width=len(max(_ips, key=len)) + 4, style=Boxes.ROUNDED
|
||||
)
|
||||
print(f'{clypi.stack(slots, scores, pings, guids, names, ips, padding=0)}')
|
||||
|
||||
def print_cvar(self, response: str):
|
||||
response = self._remove_colour_codes(response).removeprefix('print\n')
|
||||
|
||||
if m := self.CVAR_REGEX.match(response):
|
||||
name = clypi.boxed(
|
||||
[m.group('name')], title='Name', width=max(len(m.group('name')) + 4, 30)
|
||||
[m.group('name')],
|
||||
title='Name',
|
||||
width=max(len(m.group('name')) + 4, 15),
|
||||
style=Boxes.ROUNDED,
|
||||
)
|
||||
value = clypi.boxed(
|
||||
[m.group('value')],
|
||||
title='Value',
|
||||
width=max(len(m.group('value')) + 4, 30),
|
||||
width=max(len(m.group('value')) + 4, 15),
|
||||
style=Boxes.ROUNDED,
|
||||
)
|
||||
default = clypi.boxed(
|
||||
[m.group('default')],
|
||||
title='Default',
|
||||
width=max(len(m.group('default')) + 4, 30),
|
||||
width=max(len(m.group('default')) + 4, 15),
|
||||
style=Boxes.ROUNDED,
|
||||
)
|
||||
info = clypi.boxed(
|
||||
[m.group('info')], title='Info', width=max(len(m.group('info')) + 4, 30)
|
||||
[m.group('info')],
|
||||
title='Info',
|
||||
width=max(len(m.group('info')) + 4, 15),
|
||||
style=Boxes.ROUNDED,
|
||||
)
|
||||
print(f'\n{clypi.stack(name, value, default, info, padding=0)}')
|
||||
print(f'{clypi.stack(name, value, default, info, padding=0)}')
|
||||
|
||||
|
||||
out = OutConsole()
|
||||
|
||||
Reference in New Issue
Block a user