diff options
author | tomsmeding <hallo@tomsmeding.nl> | 2015-04-25 20:14:54 +0200 |
---|---|---|
committer | tomsmeding <hallo@tomsmeding.nl> | 2015-04-25 20:14:54 +0200 |
commit | 390c96c86855d086fee45e924f3dd514fae9363c (patch) | |
tree | fd58580a3d7871c1f2ae50f9a25ee728f3e842ab | |
parent | 1158d4534befb29f7049981381d1acdbe933a00e (diff) |
Add Naampje
-rwxr-xr-x | chatserver.js | 15 | ||||
-rw-r--r-- | package.json | 1 |
2 files changed, 11 insertions, 5 deletions
diff --git a/chatserver.js b/chatserver.js index ec0e839..11443d8 100755 --- a/chatserver.js +++ b/chatserver.js @@ -4,10 +4,14 @@ var fs=require("fs"), util=require("util"), WebSocketServer=require("ws").Server, CircularBuffer=require("circular-buffer"), - Persist=require("node-persist"); + Persist=require("node-persist"), + Naampje=require("naampje").name; var HTTPPORT=81,WSPORT=8000; +var nickdeleteregex=/[\x00-\x20\x7F\x80-\xFF]/g; + + ////////// WEBSOCKETS ////////// function uniqid(){ @@ -49,9 +53,10 @@ if(!lobbies){ new WebSocketServer({port:WSPORT}).on("connection",function(ws){ var uobj; (function(){ - var nick="_user"+uniqid(); - while(fnick(nick)!=-1)nick="_user"+uniqid(); - uobj=new UserObject(nick,ws); + //var nick="_user"+uniqid(); + var nick=Naampje(),suffix=""; + if(fnick(nick)!=-1)for(suffix=1;fnick(nick+suffix)!=-1;suffix++); + uobj=new UserObject((nick+suffix).replace(nickdeleteregex,""),ws); })(); users.push(uobj); ws.send("#yournick "+uobj.nick); @@ -72,7 +77,7 @@ new WebSocketServer({port:WSPORT}).on("connection",function(ws){ if(uobj.lob==null)ws.send("#mylobby"); else ws.send("#mylobby "+uobj.lob); } else if(msg.match(/^#nick /)){ - var choice=msg.slice(6).replace(/[\x00-\x20\x7F\x80-\xFF]/g,""); //all shitty characters including space (' ') + var choice=msg.slice(6).replace(nickdeleteregex,""); //all shitty characters including space (' ') var i; if(choice.length==0||choice.length>8){ ws.send("#error Invalid nick"); diff --git a/package.json b/package.json index d359a03..1fd53cb 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "chatserver.js", "dependencies": { "circular-buffer": "0.0.6", + "naampje": "^1.0.1", "node-persist": "0.0.3", "ws": "^0.6.5" }, |