home · contact · privacy
Add basic admin commands.
[plomrogue2] / rogue_chat_curses.py
index 99a7e88bc94b0f0bccf81c0bd3228335226765fe..3e078816a922c7ec4b52c17d899bb6c88a233364 100755 (executable)
@@ -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/')