summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rwxr-xr-xindex.js25
1 files changed, 15 insertions, 10 deletions
diff --git a/index.js b/index.js
index f4f55b2..33b1ffe 100755
--- a/index.js
+++ b/index.js
@@ -22,7 +22,7 @@ app.get("/",function(req,res){
res.sendFile(__dirname+"/index.html");
});
-["index.html","common.js"].forEach(function(fname){
+["index.html","common.js","dong.ogg","dong.mp3"].forEach(function(fname){
app.get("/"+fname,function(req,res){
res.sendFile(__dirname+"/"+fname);
});
@@ -99,12 +99,14 @@ io.on("connection",function(conn){
if(idx==-1)return; //WAT
obj.pending.forEach(function(pendid){
io.to(pendid).emit("roomdestroy",pendid);
- rooms[pendid].ids.forEach(function(id){
- var o=connlist[findid(id)];
- o.conn.leave(pendid);
- o.rooms.splice(o.rooms.indexOf(pendid),1);
- });
- delete rooms[pendid];
+ if(rooms[pendid]){
+ rooms[pendid].ids.forEach(function(id){
+ var o=connlist[findid(id)];
+ o.conn.leave(pendid);
+ o.rooms.splice(o.rooms.indexOf(pendid),1);
+ });
+ delete rooms[pendid];
+ }
});
obj.rooms.forEach(function(roomid){
io.to(roomid).emit("roomdestroy",roomid);
@@ -157,9 +159,10 @@ io.on("connection",function(conn){
connlist[idx].pending.push(roomid);
});
});
- conn.on("inviteaccept",function(roomid){
+ conn.on("inviteaccept",function(roomid,wellactuallydecline){
var idx=obj.pending.indexOf(roomid);
if(idx!=-1)obj.pending.splice(idx,1);
+ if(wellactuallydecline)return;
if(idx==-1||rooms[roomid]==undefined){
conn.emit("message","Cannot accept non-existent invitation");
return;
@@ -200,7 +203,8 @@ io.on("connection",function(conn){
});
conn.on("roomchat",function(roomid,message){
if(!guardroomid(roomid))return;
- io.to(roomid).emit("roomchat",roomid,[obj.id,obj.name],message);
+ conn.broadcast.to(roomid).emit("roomchat",roomid,[obj.id,obj.name],message,false); //send to everyone in room EXCEPT this client
+ conn.emit("roomchat",roomid,[obj.id,obj.name],message,true);
});
conn.on("roomcreategame",function(roomid){
if(!guardroomid(roomid))return;
@@ -250,7 +254,8 @@ io.on("connection",function(conn){
conn.emit("message","Invalid move!");
return;
}
- io.to(roomid).emit("roomgameplace",roomid,pos,playeridx);
+ conn.broadcast.to(roomid).emit("roomgameplace",roomid,pos,playeridx,false);
+ conn.emit("roomgameplace",roomid,pos,playeridx,true);
var win=rooms[roomid].game.checkwin();
if(win!=-1){
io.to(roomid).emit("roomgamewin",roomid,playeridx);