diff options
author | tomsmeding <hallo@tomsmeding.nl> | 2015-04-25 19:23:46 +0200 |
---|---|---|
committer | tomsmeding <hallo@tomsmeding.nl> | 2015-04-25 19:23:46 +0200 |
commit | 1158d4534befb29f7049981381d1acdbe933a00e (patch) | |
tree | 7947e80d0ef3f6323276a8cdd6e0f6c553ed8827 | |
parent | 705363b98b841f0f2e0f0bf5f1b270bdfcea6915 (diff) |
Better nickname management
-rw-r--r-- | chatserver.html | 6 | ||||
-rwxr-xr-x | 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(" ")); |