From 12273c396bb406d4a85083c34bf54dd6d628308d Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sun, 5 Jul 2020 21:45:52 +0200 Subject: [PATCH] add /countdown and !options --- MultiServer.py | 50 ++++++++++++++++++++++++++------------------------ Utils.py | 2 +- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/MultiServer.py b/MultiServer.py index 6ec20a94..cef132e0 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -620,9 +620,33 @@ class CommandProcessor(metaclass=CommandMeta): self.output(str(exception)) +class CommonCommandProcessor(CommandProcessor): + ctx: Context + + simple_options = {"hint_cost": int, + "location_check_points": int, + "password": str, + "forfeit_mode": str, + "item_cheat": bool, + "auto_save_interval": int} + + def _cmd_countdown(self, seconds: str = "10") -> bool: + """Start a countdown in seconds""" + try: + timer = int(seconds, 10) + except ValueError: + timer = 10 + asyncio.create_task(countdown(self.ctx, timer)) + return True + + def _cmd_options(self): + """List all current options. Warning: lists password.""" + self.output("Current options:") + for option in self.simple_options: + self.output(f"Option {option} is set to {getattr(self.ctx, option)}") + class ClientMessageProcessor(CommandProcessor): marker = "!" - ctx: Context def __init__(self, ctx: Context, client: Client): self.ctx = ctx @@ -695,14 +719,6 @@ class ClientMessageProcessor(CommandProcessor): "Your client is too old to send game beaten information. Please update, load you savegame and reconnect.") return False - def _cmd_countdown(self, seconds: str = "10") -> bool: - """Start a countdown in seconds""" - try: - timer = int(seconds, 10) - except ValueError: - timer = 10 - asyncio.create_task(countdown(self.ctx, timer)) - return True def _cmd_missing(self) -> bool: """List all missing location checks from the server's perspective""" @@ -959,15 +975,7 @@ async def process_client_cmd(ctx: Context, client: Client, cmd, args): client.messageprocessor(args) -class ServerCommandProcessor(CommandProcessor): - ctx: Context - simple_options = {"hint_cost": int, - "location_check_points": int, - "password": str, - "forfeit_mode": str, - "item_cheat": bool, - "auto_save_interval": int} - +class ServerCommandProcessor(CommonCommandProcessor): def __init__(self, ctx: Context): self.ctx = ctx super(ServerCommandProcessor, self).__init__() @@ -1115,12 +1123,6 @@ class ServerCommandProcessor(CommandProcessor): f"{', '.join(known)}") return False - def _cmd_options(self): - """List all current options. Warning: lists password.""" - self.output("Current options:") - for option in self.simple_options: - self.output(f"Option {option} is set to {getattr(self.ctx, option)}") - async def console(ctx: Context): session = prompt_toolkit.PromptSession() while ctx.running: diff --git a/Utils.py b/Utils.py index efaa3140..6b9c9074 100644 --- a/Utils.py +++ b/Utils.py @@ -6,7 +6,7 @@ def tuplize_version(version: str) -> typing.Tuple[int, ...]: return tuple(int(piece, 10) for piece in version.split(".")) -__version__ = "2.3.3" +__version__ = "2.3.4" _version_tuple = tuplize_version(__version__) import os