home · contact · privacy
Add basic admin commands.
[plomrogue2] / rogue_chat_nocanvas_monochrome.html
index b8d7b986d11c1350bf203f5a8f380bc4b1298816..9feb615049d9fe682b0b54f74aef0f02fe52dc4a 100644 (file)
@@ -30,6 +30,8 @@ terminal columns: <input id="n_cols" type="number" step=4 min=80 value=80 />
 <button id="switch_to_annotate">annotate tile</button>
 <button id="switch_to_portal">edit portal link</button>
 <button id="toggle_map_mode">toggle terrain/annotations/control view</button>
+<button id="switch_to_admin">become admin</button>
+<button id="switch_to_control_pw">change tile control password</button>
 </div>
 <h3>edit keybindings</h3> (see <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values">here</a> for non-obvious available values):<br />
 <ul>
@@ -53,6 +55,8 @@ terminal columns: <input id="n_cols" type="number" step=4 min=80 value=80 />
 <li>switch to study mode: <input id="key_switch_to_study" type="text" value="?" />
 <li>edit tile (from play mode): <input id="key_switch_to_edit" type="text" value="m" />
 <li>enter tile password (from play mode): <input id="key_switch_to_password" type="text" value="P" />
+<li>enter admin password (from play mode): <input id="key_switch_to_admin" type="text" value="A" />
+<li>change tile control password (from play mode): <input id="key_switch_to_control_pw" type="text" value="C" />
 <li>annotate tile (from play mode): <input id="key_switch_to_annotate" type="text" value="M" />
 <li>annotate portal (from play mode): <input id="key_switch_to_portal" type="text" value="T" />
 <li>toggle terrain/annotations/control view (from study mode): <input id="key_toggle_map_mode" type="text" value="M" />
@@ -325,24 +329,53 @@ let unparser = {
 }
 
 class Mode {
-    constructor(name, help_intro, has_input_prompt=false, shows_info=false, is_intro=false) {
+    constructor(name, help_intro, has_input_prompt=false, shows_info=false,
+                is_intro=false, is_single_char_entry=false) {
         this.name = name;
         this.has_input_prompt = has_input_prompt;
         this.shows_info= shows_info;
         this.is_intro = is_intro;
         this.help_intro = help_intro;
+        this.is_single_char_entry = is_single_char_entry;
     }
 }
-let mode_waiting_for_server = new Mode('waiting_for_server', 'Waiting for a server response.', false, false, true);
-let mode_login = new Mode('login', 'Pick your player name.', true, false, true);
-let mode_post_login_wait = new Mode('waiting for game world', 'Waiting for a server response.', false, false, true);
-let mode_chat = new 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:', true, false);
-  let mode_annotate = new 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.', true, true);
-let mode_play = new Mode('play', 'This mode allows you to interact with the map.', false, false);
-let mode_study = new 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.', false, true);
-let mode_edit = new 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.', false, false);
-let mode_portal = new 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.', true, true);
-let mode_password = new 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.', true, false, false);
+  let mode_waiting_for_server = new Mode('waiting_for_server',
+                                         'Waiting for a server response.',
+                                         false, false, true);
+  let mode_login = new Mode('login',
+                            'Pick your player name.',
+                            true, false, true);
+  let mode_post_login_wait = new Mode('waiting for game world',
+                                      'Waiting for a server response.')
+  let mode_chat = new 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:',
+                           true);
+  let mode_annotate = new 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.',
+                               true, true);
+  let mode_play = new Mode('play',
+                           'This mode allows you to interact with the map.')
+  let mode_study = new 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.',
+                            false, true);
+  let mode_edit = new 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.',
+                           false, false, false, true);
+  let mode_control_pw_type = new 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!',
+                                      false, false, false, true);
+  let mode_portal = new 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.',
+                             true, true);
+  let mode_password = new 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.',
+                               true);
+  let mode_admin = new Mode('admin',
+                            'This mode allows you to become admin if you know an admin password.',
+                            true);
+  let mode_control_pw_pw = new 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.',
+                                    true);
 
 let tui = {
   mode: mode_waiting_for_server,
@@ -387,7 +420,7 @@ let tui = {
   },
   switch_mode: function(mode) {
     this.inputEl.focus();
-    this.show_help = false;
+    //this.show_help = false;
     this.map_mode = 'terrain';
     if (mode.shows_info && game.player_id in game.things) {
       explorer.position = game.things[game.player_id].position;
@@ -408,6 +441,8 @@ let tui = {
     document.getElementById("switch_to_portal").disabled = true;
     document.getElementById("switch_to_annotate").disabled = true;
     document.getElementById("switch_to_password").disabled = true;
+    document.getElementById("switch_to_admin").disabled = true;
+    document.getElementById("switch_to_control_pw").disabled = true;
     document.getElementById("move_left").disabled = true;
     document.getElementById("move_upleft").disabled = true;
     document.getElementById("move_up").disabled = true;
@@ -461,10 +496,16 @@ let tui = {
         document.getElementById("switch_to_edit").disabled = false;
         document.getElementById("switch_to_portal").disabled = false;
         document.getElementById("switch_to_password").disabled = false;
+        document.getElementById("switch_to_admin").disabled = false;
+        document.getElementById("switch_to_control_pw").disabled = false;
     } else if (mode == mode_study) {
         document.getElementById("toggle_map_mode").disabled = false;
-    } else if (mode == mode_edit) {
+    } else if (mode.is_single_char_entry) {
         this.show_help = true;
+    } else if (mode == mode_admin) {
+        this.log_msg('@ enter admin password:')
+    } else if (mode == mode_control_pw_pw) {
+        this.log_msg('@ enter tile control password for "' + this.tile_control_char + '":');
     }
     this.full_refresh();
   },
@@ -659,6 +700,8 @@ let tui = {
           content += '[' + this.keys.switch_to_portal + '] – portal edit mode\n';
           content += '[' + this.keys.switch_to_annotate + '] – annotation mode\n';
           content += '[' + this.keys.switch_to_password + '] – password input mode\n';
+          content += '[' + this.keys.switch_to_admin + '] – become admin\n';
+          content += '[' + this.keys.switch_to_control_pw + '] – change tile control password\n';
       } else if (this.mode == mode_study) {
           content += "Available actions:\n";
           content += '[' + movement_keys_desc + '] – move question mark\n';
@@ -878,6 +921,9 @@ tui.inputEl.addEventListener('input', (event) => {
     } else if (tui.mode == mode_edit && tui.inputEl.value.length > 0) {
         server.send(["TASK:WRITE", tui.inputEl.value[0], tui.password]);
         tui.switch_mode(mode_play);
+    } else if (tui.mode == mode_control_pw_type && tui.inputEl.value.length > 0) {
+        tui.tile_control_char = tui.inputEl.value[0];
+        tui.switch_mode(mode_control_pw_pw);
     }
     tui.full_refresh();
 }, false);
@@ -890,12 +936,21 @@ tui.inputEl.addEventListener('keydown', (event) => {
         tui.show_help = true;
         tui.empty_input();
         tui.restore_input_values();
-    } else if (!tui.mode.has_input_prompt && event.key == tui.keys.help) {
+    } else if (!tui.mode.has_input_prompt && event.key == tui.keys.help
+               && !tui.mode.is_single_char_entry) {
         tui.show_help = true;
     } else if (tui.mode == mode_login && event.key == 'Enter') {
         tui.login_name = tui.inputEl.value;
         server.send(['LOGIN', tui.inputEl.value]);
         tui.empty_input();
+    } else if (tui.mode == mode_control_pw_pw && event.key == 'Enter') {
+        if (tui.inputEl.value.length == 0) {
+            tui.log_msg('@ aborted');
+        } else {
+            server.send(['SET_MAP_CONTROL_PASSWORD',
+                        tui.tile_control_char, tui.inputEl.value]);
+        }
+        tui.switch_mode(mode_play);
     } else if (tui.mode == mode_portal && event.key == 'Enter') {
         explorer.set_portal(tui.inputEl.value);
         tui.switch_mode(mode_play);
@@ -908,6 +963,9 @@ tui.inputEl.addEventListener('keydown', (event) => {
         }
         tui.password = tui.inputEl.value
         tui.switch_mode(mode_play);
+    } else if (tui.mode == mode_admin && event.key == 'Enter') {
+        server.send(['BECOME_ADMIN', tui.inputEl.value]);
+        tui.switch_mode(mode_play);
     } else if (tui.mode == mode_chat && event.key == 'Enter') {
         let tokens = parser.tokenize(tui.inputEl.value);
         if (tokens.length > 0 && tokens[0].length > 0) {
@@ -942,6 +1000,12 @@ tui.inputEl.addEventListener('keydown', (event) => {
               tui.switch_mode(mode_edit);
           } else if (event.key === tui.keys.switch_to_study) {
               tui.switch_mode(mode_study);
+          } else if (event.key === tui.keys.switch_to_admin) {
+              event.preventDefault();
+              tui.switch_mode(mode_admin);
+          } else if (event.key === tui.keys.switch_to_control_pw) {
+              event.preventDefault();
+              tui.switch_mode(mode_control_pw_type);
           } else if (event.key === tui.keys.switch_to_password) {
               event.preventDefault();
               tui.switch_mode(mode_password);
@@ -1053,6 +1117,14 @@ document.getElementById("switch_to_portal").onclick = function() {
     tui.switch_mode(mode_portal);
     tui.full_refresh();
 };
+document.getElementById("switch_to_admin").onclick = function() {
+    tui.switch_mode(mode_admin);
+    tui.full_refresh();
+};
+document.getElementById("switch_to_control_pw").onclick = function() {
+    tui.switch_mode(mode_control_pw_type);
+    tui.full_refresh();
+};
 document.getElementById("toggle_map_mode").onclick = function() {
     if (tui.map_mode == 'terrain') {
         tui.map_mode = 'annotations';