5 @click="resetChatColor()"
9 data-checkbox="modalChat"
12 label.modal-close(for="modalChat")
14 span {{ Object.keys(people).length + " " + st.tr["participant(s):"] }}
16 v-for="p in Object.values(people)"
20 span.anonymous(v-if="Object.values(people).some(p => !p.name && p.id === 0)")
23 :players="game.players"
24 :pastChats="game.chats"
27 @chatcleared="clearChat"
30 #aboveBoard.col-sm-12.col-md-9.col-md-offset-3.col-lg-10.col-lg-offset-2
31 span.variant-cadence {{ game.cadence }}
32 span.variant-name {{ game.vname }}
33 button#chatBtn(onClick="window.doClick('modalChat')") Chat
34 #actions(v-if="game.score=='*'")
37 :class="{['draw-' + drawOffer]: true}"
44 | {{ st.tr["Abort"] }}
49 | {{ st.tr["Resign"] }}
52 span.name(:class="{connected: isConnected(0)}")
53 | {{ game.players[0].name || "@nonymous" }}
55 v-if="game.score=='*'"
56 :class="{yourturn: !!vr && vr.turn == 'w'}"
58 span.time-left {{ virtualClocks[0][0] }}
59 span.time-separator(v-if="!!virtualClocks[0][1]") :
60 span.time-right(v-if="!!virtualClocks[0][1]") {{ virtualClocks[0][1] }}
62 span.name(:class="{connected: isConnected(1)}")
63 | {{ game.players[1].name || "@nonymous" }}
65 v-if="game.score=='*'"
66 :class="{yourturn: !!vr && vr.turn == 'b'}"
68 span.time-left {{ virtualClocks[1][0] }}
69 span.time-separator(v-if="!!virtualClocks[1][1]") :
70 span.time-right(v-if="!!virtualClocks[1][1]") {{ virtualClocks[1][1] }}
74 @newmove="processMove"
80 import BaseGame from "@/components/BaseGame.vue";
81 import Chat from "@/components/Chat.vue";
82 import { store } from "@/store";
83 import { GameStorage } from "@/utils/gameStorage";
84 import { ppt } from "@/utils/datetime";
85 import { ajax } from "@/utils/ajax";
86 import { extractTime } from "@/utils/timeControl";
87 import { getRandString } from "@/utils/alea";
88 import { processModalClick } from "@/utils/modalClick";
89 import { getFullNotation } from "@/utils/notation";
90 import { playMove, getFilteredMove } from "@/utils/playUndo";
91 import { getScoreMessage } from "@/utils/scoring";
92 import { ArrayFun } from "@/utils/array";
93 import params from "@/parameters";
100 // gameRef: to find the game in (potentially remote) storage
105 // rid = remote (socket) ID
110 // Passed to BaseGame
111 players: [{ name: "" }, { name: "" }],
115 virtualClocks: [[0,0], [0,0]], //initialized with true game.clocks
116 vr: null, //"variant rules" object initialized from FEN
118 people: {}, //players + observers
119 onMygames: [], //opponents (or me) on "MyGames" page
120 lastate: undefined, //used if opponent send lastate before game is ready
121 repeat: {}, //detect position repetition
124 roomInitialized: false,
125 // If newmove has wrong index: ask fullgame again:
127 gameIsLoading: false,
128 // If asklastate got no reply, ask again:
130 gotMoveIdx: -1, //last move index received
131 // If newmove got no pingback, send again:
132 opponentGotMove: false,
134 // Related to (killing of) self multi-connects:
140 $route: function(to) {
141 this.gameRef.id = to.params["id"];
142 this.gameRef.rid = to.query["rid"];
146 // NOTE: some redundant code with Hall.vue (mostly related to people array)
147 created: function() {
148 // Always add myself to players' list
149 const my = this.st.user;
150 this.$set(this.people, my.sid, { id: my.id, name: my.name });
151 this.gameRef.id = this.$route.params["id"];
152 this.gameRef.rid = this.$route.query["rid"]; //may be undefined
153 // Initialize connection
154 this.connexionString =
161 encodeURIComponent(this.$route.path);
162 this.conn = new WebSocket(this.connexionString);
163 this.conn.onmessage = this.socketMessageListener;
164 this.conn.onclose = this.socketCloseListener;
165 // Socket init required before loading remote game:
166 const socketInit = callback => {
167 if (!!this.conn && this.conn.readyState == 1)
171 // Socket not ready yet (initial loading)
172 // NOTE: it's important to call callback without arguments,
173 // otherwise first arg is Websocket object and loadGame fails.
174 this.conn.onopen = () => callback();
176 if (!this.gameRef.rid)
177 // Game stored locally or on server
178 this.loadGame(null, () => socketInit(this.roomInit));
180 // Game stored remotely: need socket to retrieve it
181 // NOTE: the callback "roomInit" will be lost, so we don't provide it.
182 // --> It will be given when receiving "fullgame" socket event.
183 socketInit(this.loadGame);
185 mounted: function() {
187 .getElementById("chatWrap")
188 .addEventListener("click", processModalClick);
190 beforeDestroy: function() {
191 this.send("disconnect");
194 roomInit: function() {
195 if (!this.roomInitialized) {
196 // Notify the room only now that I connected, because
197 // messages might be lost otherwise (if game loading is slow)
198 this.send("connect");
199 this.send("pollclients");
200 // We may ask fullgame several times if some moves are lost,
201 // but room should be init only once:
202 this.roomInitialized = true;
205 send: function(code, obj) {
207 this.conn.send(JSON.stringify(Object.assign({ code: code }, obj)));
209 isConnected: function(index) {
210 const player = this.game.players[index];
212 if (this.st.user.sid == player.sid || this.st.user.id == player.uid)
214 // Try to find a match in people:
218 Object.keys(this.people).some(sid => sid == player.sid)
223 Object.values(this.people).some(p => p.id == player.uid)
227 resetChatColor: function() {
228 // TODO: this is called twice, once on opening an once on closing
229 document.getElementById("chatBtn").classList.remove("somethingnew");
231 processChat: function(chat) {
232 this.send("newchat", { data: chat });
233 // NOTE: anonymous chats in corr games are not stored on server (TODO?)
234 if (this.game.type == "corr" && this.st.user.id > 0)
235 GameStorage.update(this.gameRef.id, { chat: chat });
237 clearChat: function() {
238 // Nothing more to do if game is live (chats not recorded)
239 if (this.game.type == "corr") {
240 if (!!this.game.mycolor)
241 ajax("/chats", "DELETE", {gid: this.game.id});
242 this.$set(this.game, "chats", []);
245 // Notify turn after a new move (to opponent and me on MyGames page)
246 notifyTurn: function(sid) {
247 const player = this.people[sid];
248 const colorIdx = this.game.players.findIndex(
249 p => p.sid == sid || p.uid == player.id);
250 const color = ["w","b"][colorIdx];
251 const movesCount = this.game.moves.length;
253 (color == "w" && movesCount % 2 == 0) ||
254 (color == "b" && movesCount % 2 == 1);
255 this.send("turnchange", { target: sid, yourTurn: yourTurn });
257 askGameAgain: function() {
258 this.gameIsLoading = true;
259 const doAskGame = () => {
260 if (!this.gameRef.rid)
261 // This is my game: just reload.
264 // Just ask fullgame again (once!), this is much simpler.
265 // If this fails, the user could just reload page :/
267 (function askIfPeerConnected() {
268 if (!!self.people[self.gameRef.rid])
269 self.send("askfullgame", { target: self.gameRef.rid });
270 else setTimeout(askIfPeerConnected, 1000);
274 // Delay of at least 2s between two game requests
275 const now = Date.now();
276 const delay = Math.max(2000 - (now - this.askGameTime), 0);
277 this.askGameTime = now;
278 setTimeout(doAskGame, delay);
280 socketMessageListener: function(msg) {
281 if (!this.conn) return;
282 const data = JSON.parse(msg.data);
285 data.sockIds.forEach(sid => {
286 if (sid != this.st.user.sid)
287 this.send("askidentity", { target: sid });
291 if (!this.people[data.from]) {
292 this.newConnect[data.from] = true; //for self multi-connects tests
293 this.send("askidentity", { target: data.from });
297 this.$delete(this.people, data.from);
300 // TODO: from MyGames page : send mconnect message with the list of gid (live and corr)
301 // Either me (another tab) or opponent
302 const sid = data.from;
303 if (!this.onMygames.some(s => s == sid))
305 this.onMygames.push(sid);
306 this.notifyTurn(sid); //TODO: this may require server ID (so, notify after receiving identity)
309 if (!this.people[sid])
310 this.send("askidentity", { target: sid });
313 ArrayFun.remove(this.onMygames, sid => sid == data.from);
316 // I logged in elsewhere:
318 alert(this.st.tr["New connexion detected: tab now offline"]);
320 case "askidentity": {
321 // Request for identification
323 // Decompose to avoid revealing email
324 name: this.st.user.name,
325 sid: this.st.user.sid,
328 this.send("identity", { data: me, target: data.from });
332 const user = data.data;
333 this.$set(this.people, user.sid, { name: user.name, id: user.id });
334 // If I multi-connect, kill current connexion if no mark (I'm older)
335 if (this.newConnect[user.sid]) {
338 user.id == this.st.user.id &&
339 user.sid != this.st.user.sid &&
340 !this.killed[this.st.user.sid]
342 this.send("killme", { sid: this.st.user.sid });
343 this.killed[this.st.user.sid] = true;
345 delete this.newConnect[user.sid];
347 if (!this.killed[this.st.user.sid]) {
348 // Ask potentially missed last state, if opponent and I play
350 !!this.game.mycolor &&
351 this.game.type == "live" &&
352 this.game.score == "*" &&
353 this.game.players.some(p => p.sid == user.sid)
356 (function askLastate() {
357 self.send("asklastate", { target: user.sid });
360 // Ask until we got a reply (or opponent disconnect):
361 if (!self.gotLastate && !!self.people[user.sid])
372 // Send current (live) game if not asked by any of the players
374 this.game.type == "live" &&
375 this.game.players.every(p => p.sid != data.from[0])
380 players: this.game.players,
382 cadence: this.game.cadence,
383 score: this.game.score,
384 rid: this.st.user.sid //useful in Hall if I'm an observer
386 this.send("game", { data: myGame, target: data.from });
390 const gameToSend = Object.keys(this.game)
393 "id","fen","players","vid","cadence","fenStart","vname",
394 "moves","clocks","initime","score","drawOffer"
398 obj[k] = this.game[k];
403 this.send("fullgame", { data: gameToSend, target: data.from });
406 // Callback "roomInit" to poll clients only after game is loaded
407 this.loadGame(data.data, this.roomInit);
410 // Sending informative last state if I played a move or score != "*"
412 (this.game.moves.length > 0 && this.vr.turn != this.game.mycolor) ||
413 this.game.score != "*" ||
414 this.drawOffer == "sent"
416 // Send our "last state" informations to opponent
417 const L = this.game.moves.length;
418 const myIdx = ["w", "b"].indexOf(this.game.mycolor);
420 lastMove: L > 0 ? this.game.moves[L - 1] : undefined,
421 addTime: L > 0 ? this.game.addTimes[L - 1] : undefined,
422 // Since we played a move (or abort or resign),
423 // only drawOffer=="sent" is possible
424 drawSent: this.drawOffer == "sent",
425 score: this.game.score,
427 initime: this.game.initime[1 - myIdx] //relevant only if I played
429 this.send("lastate", { data: myLastate, target: data.from });
431 this.send("lastate", { data: {nothing: true}, target: data.from });
435 // Got opponent infos about last move
436 this.gotLastate = true;
437 if (!data.data.nothing) {
438 this.lastate = data.data;
439 if (this.game.rendered)
440 // Game is rendered (Board component)
441 this.processLastate();
442 // Else: will be processed when game is ready
447 const movePlus = data.data;
448 const movesCount = this.game.moves.length;
449 if (movePlus.index > movesCount) {
450 // This can only happen if I'm an observer and missed a move.
451 if (this.gotMoveIdx < movePlus.index)
452 this.gotMoveIdx = movePlus.index;
453 if (!this.gameIsLoading) this.askGameAgain();
457 movePlus.index < movesCount ||
458 this.gotMoveIdx >= movePlus.index
460 // Opponent re-send but we already have the move:
461 // (maybe he didn't receive our pingback...)
462 this.send("gotmove", {data: movePlus.index, target: data.from});
464 this.gotMoveIdx = movePlus.index;
465 const receiveMyMove = (movePlus.color == this.game.mycolor);
466 if (!receiveMyMove && !!this.game.mycolor)
467 // Notify opponent that I got the move:
468 this.send("gotmove", {data: movePlus.index, target: data.from});
469 if (movePlus.cancelDrawOffer) {
470 // Opponent refuses draw
472 // NOTE for corr games: drawOffer reset by player in turn
474 this.game.type == "live" &&
475 !!this.game.mycolor &&
478 GameStorage.update(this.gameRef.id, { drawOffer: "" });
481 this.$refs["basegame"].play(movePlus.move, "received", null, true);
485 addTime: movePlus.addTime,
486 receiveMyMove: receiveMyMove
494 this.opponentGotMove = true;
498 const score = data.side == "b" ? "1-0" : "0-1";
499 const side = data.side == "w" ? "White" : "Black";
500 this.gameOver(score, side + " surrender");
503 this.gameOver("?", "Stop");
506 this.gameOver("1/2", data.data);
509 // NOTE: observers don't know who offered draw
510 this.drawOffer = "received";
513 this.newChat = data.data;
514 if (!document.getElementById("modalChat").checked)
515 document.getElementById("chatBtn").classList.add("somethingnew");
519 socketCloseListener: function() {
520 this.conn = new WebSocket(this.connexionString);
521 this.conn.addEventListener("message", this.socketMessageListener);
522 this.conn.addEventListener("close", this.socketCloseListener);
524 // lastate was received, but maybe game wasn't ready yet:
525 processLastate: function() {
526 const data = this.lastate;
527 this.lastate = undefined; //security...
528 const L = this.game.moves.length;
529 if (data.movesCount > L) {
530 // Just got last move from him
531 this.$refs["basegame"].play(
535 {addTime: data.addTime, initime: data.initime}
538 if (data.drawSent) this.drawOffer = "received";
539 if (data.score != "*") {
541 if (this.game.score == "*") this.gameOver(data.score);
544 clickDraw: function() {
545 if (!this.game.mycolor) return; //I'm just spectator
546 if (["received", "threerep"].includes(this.drawOffer)) {
547 if (!confirm(this.st.tr["Accept draw?"])) return;
549 this.drawOffer == "received"
551 : "Three repetitions";
552 this.send("draw", { data: message });
553 this.gameOver("1/2", message);
554 } else if (this.drawOffer == "") {
555 // No effect if drawOffer == "sent"
556 if (this.game.mycolor != this.vr.turn) {
557 alert(this.st.tr["Draw offer only in your turn"]);
560 if (!confirm(this.st.tr["Offer draw?"])) return;
561 this.drawOffer = "sent";
562 this.send("drawoffer");
563 GameStorage.update(this.gameRef.id, { drawOffer: this.game.mycolor });
566 abortGame: function() {
567 if (!this.game.mycolor || !confirm(this.st.tr["Terminate game?"])) return;
568 this.gameOver("?", "Stop");
572 if (!this.game.mycolor || !confirm(this.st.tr["Resign the game?"]))
574 this.send("resign", { data: this.game.mycolor });
575 const score = this.game.mycolor == "w" ? "0-1" : "1-0";
576 const side = this.game.mycolor == "w" ? "White" : "Black";
577 this.gameOver(score, side + " surrender");
579 // 3 cases for loading a game:
580 // - from indexedDB (running or completed live game I play)
581 // - from server (one correspondance game I play[ed] or not)
582 // - from remote peer (one live game I don't play, finished or not)
583 loadGame: function(game, callback) {
584 const afterRetrieval = async game => {
585 const vModule = await import("@/variants/" + game.vname + ".js");
586 window.V = vModule.VariantRules;
587 this.vr = new V(game.fen);
588 const gtype = game.cadence.indexOf("d") >= 0 ? "corr" : "live";
589 const tc = extractTime(game.cadence);
590 const myIdx = game.players.findIndex(p => {
591 return p.sid == this.st.user.sid || p.uid == this.st.user.id;
593 const mycolor = [undefined, "w", "b"][myIdx + 1]; //undefined for observers
594 if (!game.chats) game.chats = []; //live games don't have chat history
595 if (gtype == "corr") {
596 if (game.players[0].color == "b") {
597 // Adopt the same convention for live and corr games: [0] = white
598 [game.players[0], game.players[1]] = [
603 // NOTE: clocks in seconds, initime in milliseconds
604 game.moves.sort((m1, m2) => m1.idx - m2.idx); //in case of
605 const L = game.moves.length;
606 if (game.score == "*") {
607 // Set clocks + initime
608 game.clocks = [tc.mainTime, tc.mainTime];
609 game.initime = [0, 0];
611 const gameLastupdate = game.moves[L-1].played;
612 game.initime[L % 2] = gameLastupdate;
615 tc.mainTime - (Date.now() - gameLastupdate) / 1000;
619 // Sort chat messages from newest to oldest
620 game.chats.sort((c1, c2) => {
621 return c2.added - c1.added;
623 if (myIdx >= 0 && game.score == "*" && game.chats.length > 0) {
624 // Did a chat message arrive after my last move?
626 if (L == 1 && myIdx == 0)
627 dtLastMove = game.moves[0].played;
630 // It's now white turn
631 dtLastMove = game.moves[L-1-(1-myIdx)].played;
634 dtLastMove = game.moves[L-1-myIdx].played;
637 if (dtLastMove < game.chats[0].added)
638 document.getElementById("chatBtn").classList.add("somethingnew");
640 // Now that we used idx and played, re-format moves as for live games
641 game.moves = game.moves.map(m => m.squares);
643 if (gtype == "live" && game.clocks[0] < 0) {
645 game.clocks = [tc.mainTime, tc.mainTime];
646 if (game.score == "*") {
647 game.initime[0] = Date.now();
649 // I play in this live game; corr games don't have clocks+initime
650 GameStorage.update(game.id, {
652 initime: game.initime
657 if (!!game.drawOffer) {
658 if (game.drawOffer == "t")
660 this.drawOffer = "threerep";
662 // Draw offered by any of the players:
663 if (myIdx < 0) this.drawOffer = "received";
665 // I play in this game:
667 (game.drawOffer == "w" && myIdx == 0) ||
668 (game.drawOffer == "b" && myIdx == 1)
670 this.drawOffer = "sent";
671 else this.drawOffer = "received";
675 this.repeat = {}; //reset: scan past moves' FEN:
677 let vr_tmp = new V(game.fenStart);
679 game.moves.forEach(m => {
681 const fenIdx = vr_tmp.getFen().replace(/ /g, "_");
682 this.repeat[fenIdx] = this.repeat[fenIdx]
683 ? this.repeat[fenIdx] + 1
686 if (this.repeat[repIdx] >= 3) this.drawOffer = "threerep";
687 this.game = Object.assign(
688 // NOTE: assign mycolor here, since BaseGame could also be VS computer
691 increment: tc.increment,
693 // opponent sid not strictly required (or available), but easier
694 // at least oppsid or oppid is available anyway:
695 oppsid: myIdx < 0 ? undefined : game.players[1 - myIdx].sid,
696 oppid: myIdx < 0 ? undefined : game.players[1 - myIdx].uid,
697 addTimes: [], //used for live games
701 if (this.gameIsLoading)
702 // Re-load game because we missed some moves:
703 // artificially reset BaseGame (required if moves arrived in wrong order)
704 this.$refs["basegame"].re_setVariables();
706 this.$nextTick(() => {
707 this.game.rendered = true;
708 // Did lastate arrive before game was rendered?
709 if (this.lastate) this.processLastate();
711 if (this.gameIsLoading) {
712 this.gameIsLoading = false;
713 if (this.gotMoveIdx >= game.moves.length)
714 // Some moves arrived meanwhile...
717 if (!!callback) callback();
720 afterRetrieval(game);
723 if (this.gameRef.rid) {
724 // Remote live game: forgetting about callback func... (TODO: design)
725 this.send("askfullgame", { target: this.gameRef.rid });
727 // Local or corr game
728 // NOTE: afterRetrieval() is never called if game not found
729 GameStorage.get(this.gameRef.id, afterRetrieval);
732 re_setClocks: function() {
733 if (this.game.moves.length < 2 || this.game.score != "*") {
734 // 1st move not completed yet, or game over: freeze time
735 this.virtualClocks = this.game.clocks.map(s => ppt(s).split(':'));
738 const currentTurn = this.vr.turn;
739 const currentMovesCount = this.game.moves.length;
740 const colorIdx = ["w", "b"].indexOf(currentTurn);
742 this.game.clocks[colorIdx] -
743 (Date.now() - this.game.initime[colorIdx]) / 1000;
744 this.virtualClocks = [0, 1].map(i => {
746 i == colorIdx ? (Date.now() - this.game.initime[colorIdx]) / 1000 : 0;
747 return ppt(this.game.clocks[i] - removeTime).split(':');
749 let clockUpdate = setInterval(() => {
752 this.game.moves.length > currentMovesCount ||
753 this.game.score != "*"
755 clearInterval(clockUpdate);
758 currentTurn == "w" ? "0-1" : "1-0",
765 ppt(Math.max(0, --countdown)).split(':')
769 // Update variables and storage after a move:
770 processMove: function(move, data) {
771 if (!data) data = {};
772 const moveCol = this.vr.turn;
773 const doProcessMove = () => {
774 const colorIdx = ["w", "b"].indexOf(moveCol);
775 const nextIdx = 1 - colorIdx;
776 const origMovescount = this.game.moves.length;
778 this.game.type == "live"
779 ? (data.addTime || 0)
781 if (moveCol == this.game.mycolor && !data.receiveMyMove) {
782 if (this.drawOffer == "received")
785 if (this.game.type == "live" && origMovescount >= 2) {
786 const elapsed = Date.now() - this.game.initime[colorIdx];
787 // elapsed time is measured in milliseconds
788 addTime = this.game.increment - elapsed / 1000;
791 // Update current game object:
792 playMove(move, this.vr);
793 // TODO: notifyTurn: "changeturn" message
794 this.game.moves.push(move);
795 // (add)Time indication: useful in case of lastate infos requested
796 if (this.game.type == "live")
797 this.game.addTimes.push(addTime);
798 this.game.fen = this.vr.getFen();
799 if (this.game.type == "live") this.game.clocks[colorIdx] += addTime;
800 // In corr games, just reset clock to mainTime:
801 else this.game.clocks[colorIdx] = extractTime(this.game.cadence).mainTime;
802 // data.initime is set only when I receive a "lastate" move from opponent
803 this.game.initime[nextIdx] = data.initime || Date.now();
805 // If repetition detected, consider that a draw offer was received:
806 const fenObj = this.vr.getFenForRepeat();
807 this.repeat[fenObj] = this.repeat[fenObj] ? this.repeat[fenObj] + 1 : 1;
808 if (this.repeat[fenObj] >= 3) this.drawOffer = "threerep";
809 else if (this.drawOffer == "threerep") this.drawOffer = "";
810 // Since corr games are stored at only one location, update should be
811 // done only by one player for each move:
812 if (!!this.game.mycolor && !data.receiveMyMove) {
813 // NOTE: 'var' to see that variable outside this block
814 var filtered_move = getFilteredMove(move);
817 !!this.game.mycolor &&
818 !data.receiveMyMove &&
819 (this.game.type == "live" || moveCol == this.game.mycolor)
822 switch (this.drawOffer) {
827 drawCode = this.game.mycolor;
830 drawCode = V.GetOppCol(this.game.mycolor);
833 if (this.game.type == "corr") {
834 GameStorage.update(this.gameRef.id, {
837 squares: filtered_move,
841 // Code "n" for "None" to force reset (otherwise it's ignored)
842 drawOffer: drawCode || "n"
846 const updateStorage = () => {
847 GameStorage.update(this.gameRef.id, {
850 moveIdx: origMovescount,
851 clocks: this.game.clocks,
852 initime: this.game.initime,
856 // The active tab can update storage immediately
857 if (!document.hidden) updateStorage();
858 // Small random delay otherwise
859 else setTimeout(updateStorage, 500 + 1000 * Math.random());
862 // Send move ("newmove" event) to people in the room (if our turn)
863 if (moveCol == this.game.mycolor && !data.receiveMyMove) {
866 index: origMovescount,
867 // color is required to check if this is my move (if several tabs opened)
869 addTime: addTime, //undefined for corr games
870 cancelDrawOffer: this.drawOffer == ""
872 this.opponentGotMove = false;
873 this.send("newmove", {data: sendMove});
874 // If the opponent doesn't reply gotmove soon enough, re-send move:
875 let retrySendmove = setInterval(
877 if (this.opponentGotMove) {
878 clearInterval(retrySendmove);
881 let oppsid = this.game.players[nextIdx].sid;
883 oppsid = Object.keys(this.people).find(
884 sid => this.people[sid].id == this.game.players[nextIdx].uid
887 if (!oppsid || !this.people[oppsid])
888 // Opponent is disconnected: he'll ask last state
889 clearInterval(retrySendmove);
890 else this.send("newmove", {data: sendMove, target: oppsid});
897 this.game.type == "corr" &&
898 moveCol == this.game.mycolor &&
902 // TODO: remplacer cette confirm box par qqch de plus discret
903 // (et de même pour challenge accepté / refusé)
906 this.st.tr["Move played:"] +
908 getFullNotation(move) +
910 this.st.tr["Are you sure?"]
913 this.$refs["basegame"].cancelLastMove();
917 // Let small time to finish drawing current move attempt:
920 else doProcessMove();
922 gameOver: function(score, scoreMsg) {
923 this.game.score = score;
924 this.$set(this.game, "scoreMsg", scoreMsg || getScoreMessage(score));
925 const myIdx = this.game.players.findIndex(p => {
926 return p.sid == this.st.user.sid || p.uid == this.st.user.id;
929 // OK, I play in this game
930 GameStorage.update(this.gameRef.id, {
934 // Notify the score to main Hall. TODO: only one player (currently double send)
935 this.send("result", { gid: this.game.id, score: score });
942 <style lang="sass" scoped>
944 background-color: lightgreen
956 @media screen and (min-width: 768px)
959 @media screen and (max-width: 767px)
964 display: inline-block
967 display: inline-block
970 @media screen and (max-width: 767px)
973 @media screen and (min-width: 768px)
990 display: inline-block
1003 animation: blink-animation 2s steps(3, start) infinite
1004 @keyframes blink-animation
1009 display: inline-block
1020 .draw-sent, .draw-sent:hover
1021 background-color: lightyellow
1023 .draw-received, .draw-received:hover
1024 background-color: lightgreen
1026 .draw-threerep, .draw-threerep:hover
1027 background-color: #e4d1fc
1030 background-color: #c5fefe