From 1158d4534befb29f7049981381d1acdbe933a00e Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 25 Apr 2015 19:23:46 +0200 Subject: Better nickname management --- chatserver.html | 6 ++---- chatserver.js | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/chatserver.html b/chatserver.html index 02c0b1a..2b46d5c 100644 --- a/chatserver.html +++ b/chatserver.html @@ -108,10 +108,8 @@ ws.addEventListener("message",function(msg){ else if(cmd[0]=="#yournick")nick=cmd[1]; else if(cmd[0]=="#lobbylist")updateLobbyList(cmd.slice(1)); else if(cmd[0]=="#nicklist")updateNickList(cmd.slice(1)); - else if(cmd[0]=="#nick"){ - addMessageLine("--","<"+cmd[1]+"> is now known as <"+cmd[2]+">"); - if(cmd[1]==nick)nick=cmd[2]; - } else if(cmd[0]=="#join")addMessageLine("--","<"+cmd[1]+"> joined the lobby"); + else if(cmd[0]=="#nick")addMessageLine("--","<"+cmd[1]+"> is now known as <"+cmd[2]+">"); + else if(cmd[0]=="#join")addMessageLine("--","<"+cmd[1]+"> joined the lobby"); else if(cmd[0]=="#part")addMessageLine("--","<"+cmd[1]+"> left the lobby"); else if(cmd[0]=="#lobby")highlightLobby(cmd[1]); else if(cmd[0]=="#historystart")clearMessageHistory(); diff --git a/chatserver.js b/chatserver.js index 51ab363..ec0e839 100755 --- a/chatserver.js +++ b/chatserver.js @@ -84,9 +84,10 @@ new WebSocketServer({port:WSPORT}).on("connection",function(ws){ while(fnick(choice+i)!=-1)i++; choice+=i; } - lobbysend(lobbies[flob(uobj.lob)],"#nick "+uobj.nick+" "+choice); + lobbysend(lobbies[flob(uobj.lob)],"#nick "+uobj.nick+" "+choice,[uobj.id]); } uobj.nick=choice; + ws.send("#yournick "+uobj.nick); do_persist_lobbies(); } else if(msg.match(/^#lobbylist/)){ ws.send("#lobbylist "+lobbies.map(function(lob){return lob.id+":"+lob.name;}).join(" ")); -- cgit v1.2.3-70-g09d2