From: Christian Heller Date: Thu, 19 Nov 2020 21:05:50 +0000 (+0100) Subject: Add basic admin commands. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/static/%7B%7Btodo.date%7D%7D?a=commitdiff_plain;h=750eb29e8a84e9846bb6b568745b8de453788f58;p=plomrogue2 Add basic admin commands. --- diff --git a/config.json b/config.json index 1824802..1185268 100644 --- a/config.json +++ b/config.json @@ -1,10 +1,13 @@ { "switch_to_chat": "t", "switch_to_play": "p", + "switch_to_password": "P", "switch_to_annotate": "M", "switch_to_portal": "T", "switch_to_study": "?", "switch_to_edit": "m", + "switch_to_admin": "A", + "switch_to_control_pw": "C", "flatten": "F", "take_thing": "z", "drop_thing": "u", diff --git a/plomrogue/commands.py b/plomrogue/commands.py index 603e0d3..c079599 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -75,7 +75,10 @@ def cmd_LOGIN(game, nick, connection_id): YX(game.map_geometry.size.y // 2, game.map_geometry.size.x // 2)) game.things += [t] # TODO refactor into Thing.__init__? t.player_char = game.get_next_player_char() - game.sessions[connection_id] = {'thing_id': t.id_} + game.sessions[connection_id] = { + 'thing_id': t.id_, + 'status': 'player' + } game.io.send('LOGIN_OK', connection_id) t.name = nick game.io.send('CHAT ' + quote(t.name + ' entered the map.')) @@ -83,6 +86,41 @@ def cmd_LOGIN(game, nick, connection_id): game.changed = True cmd_LOGIN.argtypes = 'string' +def cmd_BECOME_ADMIN(game, password, connection_id): + player = game.thing_types['Player'](game) + if not player: + raise GameError('need to be logged in for this') + if password in game.admin_passwords: + game.sessions[connection_id]['status'] = 'admin' + else: + raise GameError('wrong password') +cmd_BECOME_ADMIN.argtypes = 'string' + +def cmd_ADMIN_PASSWORD(game, password): + game.admin_passwords += [password] +cmd_ADMIN_PASSWORD.argtypes = 'string' + +def cmd_SET_TILE_CONTROL(game, yx, control_char, connection_id): + player = game.get_player(connection_id) + if not player: + raise GameError('need to be logged in for this') + if not game.sessions[connection_id]['status'] == 'admin': + raise GameError('need to be admin for this') + big_yx, little_yx = player.fov_stencil.source_yxyx(yx) + map_control = game.get_map(big_yx, 'control') + map_control[little_yx] = control_char +cmd_SET_TILE_CONTROL.argtypes = 'yx:nonneg char' + +def cmd_SET_MAP_CONTROL_PASSWORD(game, tile_class, password, connection_id): + player = game.get_player(connection_id) + if not player: + raise GameError('need to be logged in for this') + if not game.sessions[connection_id]['status'] == 'admin': + raise GameError('need to be admin for this') + game.map_control_passwords[tile_class] = password + game.changed = True +cmd_SET_MAP_CONTROL_PASSWORD.argtypes = 'char string' + def cmd_NICK(game, nick, connection_id): for t in [t for t in game.things if t.type_ == 'Player' and t.name == nick]: raise GameError('name already in use') diff --git a/plomrogue/game.py b/plomrogue/game.py index 23a0d7b..8b3edb1 100755 --- a/plomrogue/game.py +++ b/plomrogue/game.py @@ -64,6 +64,7 @@ class Game(GameBase): self.portals = {} self.player_chars = string.digits + string.ascii_letters self.player_char_i = -1 + self.admin_passwords = [] self.terrains = { '.': 'floor', 'X': 'wall', @@ -265,6 +266,8 @@ class Game(GameBase): for tile_class in self.map_control_passwords: write(f, 'MAP_CONTROL_PW %s %s' % (tile_class, self.map_control_passwords[tile_class])) + for pw in self.admin_passwords: + write(f, 'ADMIN_PASSWORD %s' % pw) for t in [t for t in self.things if not t.type_ == 'Player']: write(f, 'THING %s %s %s %s' % (t.position[0], t.position[1], t.type_, t.id_)) diff --git a/rogue_chat.py b/rogue_chat.py index 8aaf1a6..18fc91b 100755 --- a/rogue_chat.py +++ b/rogue_chat.py @@ -7,7 +7,9 @@ from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THIN cmd_ANNOTATE, cmd_PORTAL, cmd_GET_GAMESTATE, cmd_TASKS, cmd_MAP_CONTROL_LINE, cmd_MAP_CONTROL_PW, cmd_GOD_ANNOTATE, cmd_GOD_PORTAL, cmd_THING_TYPES, - cmd_THING_NAME, cmd_TERRAINS) + cmd_THING_NAME, cmd_TERRAINS, cmd_ADMIN_PASSWORD, + cmd_BECOME_ADMIN, cmd_SET_TILE_CONTROL, + cmd_SET_MAP_CONTROL_PASSWORD) from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP, Task_DROP, Task_FLATTEN_SURROUNDINGS) from plomrogue.things import Thing_Player, Thing_Item, Thing_Furniture @@ -38,6 +40,10 @@ game.register_command(cmd_THING_TYPES) game.register_command(cmd_TERRAINS) game.register_command(cmd_THING) game.register_command(cmd_THING_NAME) +game.register_command(cmd_ADMIN_PASSWORD) +game.register_command(cmd_SET_TILE_CONTROL) +game.register_command(cmd_SET_MAP_CONTROL_PASSWORD) +game.register_command(cmd_BECOME_ADMIN) game.register_task(Task_WAIT) game.register_task(Task_MOVE) game.register_task(Task_WRITE) diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index 99a7e88..3e07881 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -234,27 +234,54 @@ class TUI: class Mode: def __init__(self, name, help_intro, has_input_prompt=False, - shows_info=False, is_intro = False): + shows_info=False, is_intro = False, + is_single_char_entry=False): self.name = name self.has_input_prompt = has_input_prompt self.shows_info = shows_info self.is_intro = is_intro self.help_intro = help_intro + self.is_single_char_entry = is_single_char_entry def __init__(self, host): import os import json self.host = host - self.mode_play = self.Mode('play', 'This mode allows you to interact with the map.') + self.mode_play = self.Mode('play', + 'This mode allows you to interact with the map.') self.mode_study = self.Mode('study', 'This mode allows you to study the map and its tiles in detail. Move the question mark over a tile, and the right half of the screen will show detailed information on it.', shows_info=True) - self.mode_edit = self.Mode('edit', 'This mode allows you to change the map tile you currently stand on (if your map editing password authorizes you so). Just enter any printable ASCII character to imprint it on the ground below you.') - self.mode_annotate = self.Mode('annotate', 'This mode allows you to add/edit a comment on the tile you are currently standing on (provided your map editing password authorizes you so). Hit Return to leave.', has_input_prompt=True, shows_info=True) - self.mode_portal = self.Mode('portal', 'This mode allows you to imprint/edit/remove a teleportation target on the ground you are currently standing on (provided your map editing password authorizes you so). Enter or edit a URL to imprint a teleportation target; enter emptiness to remove a pre-existing teleportation target. Hit Return to leave.', has_input_prompt=True, shows_info=True) - self.mode_chat = self.Mode('chat', 'This mode allows you to engage in chit-chat with other users. Any line you enter into the input prompt that does not start with a "/" will be sent out to nearby players – but barriers and distance will reduce what they can read, so stand close to them to ensure they get your message. Lines that start with a "/" are used for commands like:', has_input_prompt=True) - self.mode_waiting_for_server = self.Mode('waiting_for_server', 'Waiting for a server response.', is_intro=True) - self.mode_login = self.Mode('login', 'Pick your player name.', has_input_prompt=True, is_intro=True) - self.mode_post_login_wait = self.Mode('post_login_wait', 'Waiting for a server response.', is_intro=True) - self.mode_password = self.Mode('password', 'This mode allows you to change the password that you send to authorize yourself for editing password-protected map tiles. Hit return to confirm and leave.', has_input_prompt=True) + self.mode_edit = self.Mode('edit', + 'This mode allows you to change the map tile you currently stand on (if your map editing password authorizes you so). Just enter any printable ASCII character to imprint it on the ground below you.', + is_single_char_entry=True) + self.mode_control_pw_type = self.Mode('control_pw_type', + 'This mode is the first of two steps to change the password for a tile control character. First enter the tile control character for which you want to change the password!', + is_single_char_entry=True) + self.mode_control_pw_pw = self.Mode('control_pw_pw', + 'This mode is the second of two steps to change the password for a tile control character. Enter the new password for the tile control character you chose.', + has_input_prompt=True) + self.mode_annotate = self.Mode('annotate', + 'This mode allows you to add/edit a comment on the tile you are currently standing on (provided your map editing password authorizes you so). Hit Return to leave.', + has_input_prompt=True, shows_info=True) + self.mode_portal = self.Mode('portal', + 'This mode allows you to imprint/edit/remove a teleportation target on the ground you are currently standing on (provided your map editing password authorizes you so). Enter or edit a URL to imprint a teleportation target; enter emptiness to remove a pre-existing teleportation target. Hit Return to leave.', + has_input_prompt=True, shows_info=True) + self.mode_chat = self.Mode('chat', + 'This mode allows you to engage in chit-chat with other users. Any line you enter into the input prompt that does not start with a "/" will be sent out to nearby players – but barriers and distance will reduce what they can read, so stand close to them to ensure they get your message. Lines that start with a "/" are used for commands like:', has_input_prompt=True) + self.mode_waiting_for_server = self.Mode('waiting_for_server', + 'Waiting for a server response.', + is_intro=True) + self.mode_login = self.Mode('login', + 'Pick your player name.', + has_input_prompt=True, is_intro=True) + self.mode_post_login_wait = self.Mode('post_login_wait', + 'Waiting for a server response.', + is_intro=True) + self.mode_password = self.Mode('password', + 'This mode allows you to change the password that you send to authorize yourself for editing password-protected map tiles. Hit return to confirm and leave.', + has_input_prompt=True) + self.mode_admin = self.Mode('admin', + 'This mode allows you to become admin if you know an admin password.', + has_input_prompt=True) self.game = Game() self.game.tui = self self.parser = Parser(self.game) @@ -273,10 +300,13 @@ class TUI: 'switch_to_portal': 'T', 'switch_to_study': '?', 'switch_to_edit': 'm', + 'switch_to_admin': 'A', + 'switch_to_control_pw': 'C', 'flatten': 'F', 'take_thing': 'z', 'drop_thing': 'u', 'teleport': 'p', + 'help': 'h', 'toggle_map_mode': 'M', 'hex_move_upleft': 'w', 'hex_move_upright': 'e', @@ -375,15 +405,19 @@ class TUI: player = self.game.get_thing(self.game.player_id) self.explorer = YX(player.position.y, player.position.x) self.query_info() + if self.mode.is_single_char_entry: + self.show_help = True if self.mode.name == 'waiting_for_server': self.log_msg('@ waiting for server …') - if self.mode.name == 'edit': - self.show_help = True elif self.mode.name == 'login': if self.login_name: self.send('LOGIN ' + quote(self.login_name)) else: self.log_msg('@ enter username') + elif self.mode.name == 'admin': + self.log_msg('@ enter admin password:') + elif self.mode.name == 'control_pw_pw': + self.log_msg('@ enter tile control password for "%s":' % self.tile_control_char) self.restore_input_values() def loop(self, stdscr): @@ -588,6 +622,9 @@ class TUI: content += '[%s] – portal edit mode\n' % self.keys['switch_to_portal'] content += '[%s] – annotation mode\n' % self.keys['switch_to_annotate'] content += '[%s] – password input mode\n' % self.keys['switch_to_password'] + content += '[%s] – become admin\n' % self.keys['switch_to_admin'] + content += '[%s] – change tile control password' % self.keys['switch_to_control_pw'] + elif self.mode == self.mode_study: content += 'Available actions:\n' content += '[%s] – move question mark\n' % ','.join(self.movement_keys) @@ -680,18 +717,29 @@ class TUI: max_length = self.window_width * self.size.y - len(input_prompt) - 1 if len(self.input_) > max_length: self.input_ = self.input_[:max_length] - elif key == self.keys['help'] and self.mode != self.mode_edit: + elif key == self.keys['help'] and not self.mode.is_single_char_entry: self.show_help = True elif self.mode == self.mode_login and key == '\n': self.login_name = self.input_ self.send('LOGIN ' + quote(self.input_)) self.input_ = "" + elif self.mode == self.mode_control_pw_pw and key == '\n': + if self.input_ == '': + self.log_msg('@ aborted') + else: + self.send('SET_MAP_CONTROL_PASSWORD ' + quote(self.tile_control_char) + ' ' + quote(self.input_)) + self.input_ = "" + self.switch_mode('play') elif self.mode == self.mode_password and key == '\n': if self.input_ == '': self.input_ = ' ' self.password = self.input_ self.input_ = "" self.switch_mode('play') + elif self.mode == self.mode_admin and key == '\n': + self.send('BECOME_ADMIN ' + quote(self.input_)) + self.input_ = "" + self.switch_mode('play') elif self.mode == self.mode_chat and key == '\n': if self.input_ == '': continue @@ -750,6 +798,10 @@ class TUI: self.switch_mode('portal') elif key == self.keys['switch_to_password']: self.switch_mode('password') + elif key == self.keys['switch_to_admin']: + self.switch_mode('admin') + elif key == self.keys['switch_to_control_pw']: + self.switch_mode('control_pw_type') if key == self.keys['switch_to_edit'] and\ 'WRITE' in self.game.tasks: self.switch_mode('edit') @@ -773,6 +825,9 @@ class TUI: elif self.mode == self.mode_edit: self.send('TASK:WRITE %s %s' % (key, quote(self.password))) self.switch_mode('play') + elif self.mode == self.mode_control_pw_type: + self.tile_control_char = key + self.switch_mode('control_pw_pw') #TUI('localhost:5000') TUI('wss://plomlompom.com/rogue_chat/') diff --git a/rogue_chat_nocanvas_monochrome.html b/rogue_chat_nocanvas_monochrome.html index b8d7b98..9feb615 100644 --- a/rogue_chat_nocanvas_monochrome.html +++ b/rogue_chat_nocanvas_monochrome.html @@ -30,6 +30,8 @@ terminal columns: + +

edit keybindings

(see here for non-obvious available values):