From: Christian Heller Date: Tue, 27 Oct 2020 02:52:43 +0000 (+0100) Subject: Fix QUERY/msg bug. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%7B%7Bdb.prefix%7D%7D/template?a=commitdiff_plain;h=2e712c7bd1617337bafff6afdf8c3ba058d4a709;p=plomrogue2-experiments Fix QUERY/msg bug. --- diff --git a/new2/rogue_chat_nocanvas_monochrome.html b/new2/rogue_chat_nocanvas_monochrome.html index 82df80c..3f907c0 100644 --- a/new2/rogue_chat_nocanvas_monochrome.html +++ b/new2/rogue_chat_nocanvas_monochrome.html @@ -59,6 +59,7 @@ let terminal = { let parser = { tokenize: function(str) { + let token_ends = []; let tokens = []; let token = '' let quoted = false; @@ -72,7 +73,7 @@ let parser = { } else if (c == '\\') { escaped = true; } else if (c == '"') { - quoted = false + quoted = false } else { token += c; } @@ -80,6 +81,7 @@ let parser = { quoted = true } else if (c === ' ') { if (token.length > 0) { + token_ends.push(i); tokens.push(token); token = ''; } @@ -90,7 +92,11 @@ let parser = { if (token.length > 0) { tokens.push(token); } - return tokens; + let token_starts = []; + for (let i = 0; i < token_ends.length; i++) { + token_starts.push(token_ends[i] - tokens[i].length); + }; + return [tokens, token_starts]; }, parse_yx(position_string) { let coordinate_strings = position_string.split(',') @@ -254,7 +260,7 @@ tui.full_refresh(); let websocket = new WebSocket(websocket_location); websocket.onmessage = function (event) { - let tokens = parser.tokenize(event.data); + let tokens = parser.tokenize(event.data)[0]; if (tokens[0] === 'TURN') { game.things = {} game.turn = parseInt(tokens[1]); @@ -330,7 +336,7 @@ document.addEventListener('keydown', (event) => { tui.draw_input_line(); tui.refresh(); } else if (event.key == 'Enter') { - let tokens = parser.tokenize(chat.input_line); + let [tokens, token_starts] = parser.tokenize(chat.input_line); if (tokens.length > 0 && tokens[0].length > 0) { if (tokens[0][0] == '/') { if (tokens[0] == '/play') { @@ -346,8 +352,8 @@ document.addEventListener('keydown', (event) => { } } else if (tokens[0] == '/msg') { if (tokens.length > 2) { - // FIXME only sends first word - websocket.send('QUERY ' + quote(tokens[1]) + ' ' + quote(tokens[2])); + let msg = chat.input_line.slice(token_starts[2]); + websocket.send('QUERY ' + quote(tokens[1]) + ' ' + quote(msg)); } else { tui.log_msg('? need message target and message'); }