projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Some debug, plan several short + long term TODOs
[vchess.git]
/
sockets.js
diff --git
a/sockets.js
b/sockets.js
index
2d9117d
..
e411050
100644
(file)
--- a/
sockets.js
+++ b/
sockets.js
@@
-1,6
+1,6
@@
const url = require('url');
const sqlite3 = require('sqlite3');
const url = require('url');
const sqlite3 = require('sqlite3');
-const db = new sqlite3.Database(
'db/vchess.sqlite'
);
+const db = new sqlite3.Database(
__dirname + "/db/vchess.sqlite"
);
// Node version in Ubuntu 16.04 does not know about URL class
function getJsonFromUrl(url) {
// Node version in Ubuntu 16.04 does not know about URL class
function getJsonFromUrl(url) {
@@
-100,20
+100,21
@@
module.exports = function(wss) {
// Start a new game
const oppId = games[page]["id"];
const fen = games[page]["fen"];
// Start a new game
const oppId = games[page]["id"];
const fen = games[page]["fen"];
+ const gameId = games[page]["gameid"];
delete games[page];
delete games[page];
- const mycolor =
Math.random() < 0.5 ? 'w' : 'b'
;
+ const mycolor =
(Math.random() < 0.5 ? 'w' : 'b')
;
socket.send(JSON.stringify(
socket.send(JSON.stringify(
- {code:"newgame",fen:fen,oppid:oppId,color:mycolor}));
+ {code:"newgame",fen:fen,oppid:oppId,color:mycolor
,gameid:gameId
}));
if (!!clients[page][oppId])
{
clients[page][oppId].send(
JSON.stringify(
if (!!clients[page][oppId])
{
clients[page][oppId].send(
JSON.stringify(
- {code:"newgame",fen:fen,oppid:sid,color:mycolor=="w"?"b":"w"}),
+ {code:"newgame",fen:fen,oppid:sid,color:mycolor=="w"?"b":"w"
,gameid:gameId
}),
noop);
}
}
else
noop);
}
}
else
- games[page] = {id:sid, fen:obj.fen}; //wait for opponent
+ games[page] = {id:sid, fen:obj.fen
, gameid:obj.gameid
}; //wait for opponent
break;
case "cancelnewgame": //if a user cancel his seek
delete games[page];
break;
case "cancelnewgame": //if a user cancel his seek
delete games[page];