{
"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",
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.'))
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')
self.portals = {}
self.player_chars = string.digits + string.ascii_letters
self.player_char_i = -1
+ self.admin_passwords = []
self.terrains = {
'.': 'floor',
'X': 'wall',
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_))
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
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)
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)
'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',
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):
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)
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
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')
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/')
<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>
<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" />
}
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,
},
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;
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;
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();
},
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';
} 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);
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);
}
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) {
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);
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';