projects
/
vchess.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
1f49533
)
Work on correspondance challenges system
author
Benjamin Auder
<benjamin.auder@somewhere>
Tue, 12 Mar 2019 16:12:55 +0000
(17:12 +0100)
committer
Benjamin Auder
<benjamin.auder@somewhere>
Tue, 12 Mar 2019 16:12:55 +0000
(17:12 +0100)
client/src/main.js
patch
|
blob
|
blame
|
history
client/src/views/Hall.vue
patch
|
blob
|
blame
|
history
server/models/Challenge.js
patch
|
blob
|
blame
|
history
server/models/User.js
patch
|
blob
|
blame
|
history
server/routes/challenges.js
patch
|
blob
|
blame
|
history
diff --git
a/client/src/main.js
b/client/src/main.js
index
22fe0cd
..
6547865
100644
(file)
--- a/
client/src/main.js
+++ b/
client/src/main.js
@@
-37,13
+37,6
@@
new Vue({
},
}).$mount("#app");
},
}).$mount("#app");
-// TODO: get rules, dynamic import
-// Load a rules page (AJAX)
-// router.get("/rules/:vname([a-zA-Z0-9]+)", access.ajax, (req,res) => {
-// const lang = selectLanguage(req, res);
-// res.render("rules/" + req.params["vname"] + "/" + lang);
-// });
-//
// board2, 3, 4 automatiquement, mais rules separement (les 3 pour une)
// game : aussi systématique
// problems: on-demand
// board2, 3, 4 automatiquement, mais rules separement (les 3 pour une)
// game : aussi systématique
// problems: on-demand
diff --git
a/client/src/views/Hall.vue
b/client/src/views/Hall.vue
index
c91fb1e
..
1d842d5
100644
(file)
--- a/
client/src/views/Hall.vue
+++ b/
client/src/views/Hall.vue
@@
-125,6
+125,10
@@
export default {
created: function() {
// Always add myself to players' list
this.players.push(this.st.user);
created: function() {
// Always add myself to players' list
this.players.push(this.st.user);
+
+ console.log("created");
+ajax("/testtest", "DELETE");
+
// Ask server for current corr games (all but mines)
// ajax(
// "",
// Ask server for current corr games (all but mines)
// ajax(
// "",
@@
-208,7
+212,7
@@
export default {
{target: sid}
)));
};
{target: sid}
)));
};
-
else
if (!!to[0])
+ if (!!to[0])
{
to.forEach(pname => {
// Challenge with targeted players
{
to.forEach(pname => {
// Challenge with targeted players
@@
-483,30
+487,34
@@
export default {
// * - prepare and start new game (if challenge is full after acceptation)
// * --> include challenge ID (so that opponents can delete the challenge too)
clickChallenge: function(c) {
// * - prepare and start new game (if challenge is full after acceptation)
// * --> include challenge ID (so that opponents can delete the challenge too)
clickChallenge: function(c) {
-
switch (c.type
)
+
if (!!c.accepted
)
{
{
- case "live":
- if (!!c.accepted)
- {
- this.st.conn.send(JSON.stringify({code: "withdrawchallenge",
- cid: c.id, target: c.from.sid}));
-
- break;
- case "corr":
+ this.st.conn.send(JSON.stringify({code: "withdrawchallenge",
+ cid: c.id, target: c.from.sid}));
+ if (c.type == "corr")
+ {
ajax(
"/challenges",
"PUT",
{action:"withdraw", id: this.challenges[cIdx].id}
);
ajax(
"/challenges",
"PUT",
{action:"withdraw", id: this.challenges[cIdx].id}
);
- break;
- }
- c.accepted = false;
- {
+ }
+ c.accepted = false;
}
}
- else if (c.from.sid == this.st.user.sid) //it's my challenge: cancel it
+ else if (c.from.sid == this.st.user.sid
+ || (this.st.user.id > 0 && c.from.id == this.st.user.id))
{
{
+ // It's my challenge: cancel it
this.sendSomethingTo(c.to, "deletechallenge", {cid:c.id});
ArrayFun.remove(this.challenges, ch => ch.id == c.id);
this.sendSomethingTo(c.to, "deletechallenge", {cid:c.id});
ArrayFun.remove(this.challenges, ch => ch.id == c.id);
+ if (c.type == "corr")
+ {
+ ajax(
+ "/challenges",
+ "DELETE",
+ {id: this.challenges[cIdx].id}
+ );
+ }
}
else //accept (or refuse) a challenge
{
}
else //accept (or refuse) a challenge
{
@@
-516,16
+524,35
@@
export default {
// TODO: if special FEN, show diagram after loading variant
c.accepted = confirm("Accept challenge?");
}
// TODO: if special FEN, show diagram after loading variant
c.accepted = confirm("Accept challenge?");
}
+ const action = (c.accepted ? "accept" : "refuse");
this.st.conn.send(JSON.stringify({
this.st.conn.send(JSON.stringify({
- code:
(c.accepted ? "accept" : "refuse")
+ "challenge",
+ code:
action
+ "challenge",
cid: c.id, target: c.from.sid}));
cid: c.id, target: c.from.sid}));
+ if (c.type == "corr")
+ {
+ ajax(
+ "/challenges",
+ "PUT",
+ {action: action, id: this.challenges[cIdx].id}
+ );
+ }
if (!c.accepted)
if (!c.accepted)
+ {
ArrayFun.remove(this.challenges, ch => ch.id == c.id);
ArrayFun.remove(this.challenges, ch => ch.id == c.id);
+ if (c.type == "corr")
+ {
+ ajax(
+ "/challenges",
+ "DELETE",
+ {id: this.challenges[cIdx].id}
+ );
+ }
+ }
}
},
// c.type == corr alors use id...sinon sid (figés)
// NOTE: only for live games ?
}
},
// c.type == corr alors use id...sinon sid (figés)
// NOTE: only for live games ?
- launchGame: function(c) {
+ launchGame:
async
function(c) {
// Just assign colors and pass the message
const vname = this.getVname(c.vid);
const vModule = await import("@/variants/" + vname + ".js");
// Just assign colors and pass the message
const vname = this.getVname(c.vid);
const vModule = await import("@/variants/" + vname + ".js");
@@
-537,7
+564,7
@@
export default {
fen: c.fen || V.GenRandInitFen(),
// Shuffle players order (white then black then other colors).
// Players' names may be required if game start when a player is offline
fen: c.fen || V.GenRandInitFen(),
// Shuffle players order (white then black then other colors).
// Players' names may be required if game start when a player is offline
- players: shuffle(players).map(p => {
name:p.name, sid:p.sid}
,
+ players: shuffle(players).map(p => {
return {name:p.name, sid:p.sid} })
,
vid: c.vid,
timeControl: c.timeControl,
};
vid: c.vid,
timeControl: c.timeControl,
};
diff --git
a/server/models/Challenge.js
b/server/models/Challenge.js
index
e977267
..
8adf3ca
100644
(file)
--- a/
server/models/Challenge.js
+++ b/
server/models/Challenge.js
@@
-126,6
+126,15
@@
const ChallengeModel =
});
},
});
},
+ testfunc: function()
+ {
+ db.serialize(function() {
+ db.run("DELETE * FROM TableTest", (err,ret) => {
+ console.log(ret);
+ });
+ });
+ },
+
remove: function(id, uid)
{
db.serialize(function() {
remove: function(id, uid)
{
db.serialize(function() {
@@
-133,10
+142,15
@@
const ChallengeModel =
"DELETE FROM Challenges " +
"WHERE id = " + id + " AND uid = " + uid;
db.run(query, (err,ret) => {
"DELETE FROM Challenges " +
"WHERE id = " + id + " AND uid = " + uid;
db.run(query, (err,ret) => {
- if (!!err && query = //TODO
- "DELETE FROM WillPlay " +
- "WHERE cid = " + id;
- db.run(query);
+ if (!err && ret >= 1)
+ {
+ // Also remove matching WillPlay entries if a challenge was deleted
+ query =
+ "DELETE FROM WillPlay " +
+ "WHERE cid = " + id;
+ db.run(query);
+ }
+ });
});
},
}
});
},
}
diff --git
a/server/models/User.js
b/server/models/User.js
index
9401133
..
9e1aded
100644
(file)
--- a/
server/models/User.js
+++ b/
server/models/User.js
@@
-66,9
+66,9
@@
const UserModel =
getByName: function(names, cb) {
db.serialize(function() {
const query =
getByName: function(names, cb) {
db.serialize(function() {
const query =
- "SELECT id
+ "SELECT id
" +
"FROM Users " +
"FROM Users " +
- "WHERE name IN ('" + names.join("','") + "')";
;
+ "WHERE name IN ('" + names.join("','") + "')";
db.all(query, cb);
});
},
db.all(query, cb);
});
},
diff --git
a/server/routes/challenges.js
b/server/routes/challenges.js
index
b1e0694
..
99f055f
100644
(file)
--- a/
server/routes/challenges.js
+++ b/
server/routes/challenges.js
@@
-5,6
+5,11
@@
const access = require("../utils/access");
const ChallengeModel = require("../models/Challenge");
const UserModel = require("../models/User"); //for name check
const ChallengeModel = require("../models/Challenge");
const UserModel = require("../models/User"); //for name check
+router.delete("/testtest", access.ajax, (req,res) => {
+ console.log("passag");
+ ChallengeModel.testfunc();
+});
+
router.post("/challenges", access.logged, access.ajax, (req,res) => {
const error = ChallengeModel.checkChallenge(req.body.chall);
if (!!error)
router.post("/challenges", access.logged, access.ajax, (req,res) => {
const error = ChallengeModel.checkChallenge(req.body.chall);
if (!!error)