Attempt to get rid of the weird trans-pages errors (especially in Game)
[vchess.git] / client / src / views / Game.vue
1 <template lang="pug">
2 main
3 input#modalInfo.modal(type="checkbox")
4 div#infoDiv(
5 role="dialog"
6 data-checkbox="modalInfo"
7 )
8 .card.text-center
9 label.modal-close(for="modalInfo")
10 a(
11 :href="'#/game/' + rematchId"
12 onClick="document.getElementById('modalInfo').checked=false"
13 )
14 | {{ st.tr["Rematch in progress"] }}
15 input#modalChat.modal(
16 type="checkbox"
17 @click="toggleChat()"
18 )
19 div#chatWrap(
20 role="dialog"
21 data-checkbox="modalChat"
22 )
23 .card
24 label.modal-close(for="modalChat")
25 #participants
26 span {{ st.tr["Participant(s):"] }}
27 span(
28 v-for="p in Object.values(people)"
29 v-if="p.focus && !!p.name"
30 )
31 | {{ p.name }}
32 span.anonymous(
33 v-if="Object.values(people).some(p => p.focus && !p.name)"
34 )
35 | + @nonymous
36 Chat(
37 ref="chatcomp"
38 :players="game.players"
39 :pastChats="game.chats"
40 @mychat="processChat"
41 @chatcleared="clearChat"
42 )
43 input#modalConfirm.modal(type="checkbox")
44 div#confirmDiv(role="dialog")
45 .card
46 .diagram(
47 v-if="!!vr && ['all','byrow'].includes(vr.showMoves)"
48 v-html="curDiag"
49 )
50 p.text-center(v-else)
51 span {{ st.tr["Move played:"] + " " }}
52 span.bold {{ moveNotation }}
53 br
54 span {{ st.tr["Are you sure?"] }}
55 .button-group#buttonsConfirm
56 // onClick for acceptBtn: set dynamically
57 button.acceptBtn
58 span {{ st.tr["Validate"] }}
59 button.refuseBtn(@click="cancelMove()")
60 span {{ st.tr["Cancel"] }}
61 .row
62 #aboveBoard.col-sm-12.col-md-9.col-md-offset-3.col-lg-10.col-lg-offset-2
63 span.variant-cadence {{ game.cadence }}
64 span.variant-name {{ game.vname }}
65 span#nextGame(
66 v-if="nextIds.length > 0"
67 @click="showNextGame()"
68 )
69 | {{ st.tr["Next_g"] }}
70 button#chatBtn.tooltip(
71 onClick="window.doClick('modalChat')"
72 aria-label="Chat"
73 )
74 img(src="/images/icons/chat.svg")
75 #actions(v-if="game.score=='*'")
76 button.tooltip(
77 @click="clickDraw()"
78 :class="{['draw-' + drawOffer]: true}"
79 :aria-label="st.tr['Draw']"
80 )
81 img(src="/images/icons/draw.svg")
82 button.tooltip(
83 v-if="!!game.mycolor"
84 @click="abortGame()"
85 :aria-label="st.tr['Abort']"
86 )
87 img(src="/images/icons/abort.svg")
88 button.tooltip(
89 v-if="!!game.mycolor"
90 @click="resign()"
91 :aria-label="st.tr['Resign']"
92 )
93 img(src="/images/icons/resign.svg")
94 button.tooltip(
95 v-else
96 @click="clickRematch()"
97 :class="{['rematch-' + rematchOffer]: true}"
98 :aria-label="st.tr['Rematch']"
99 )
100 img(src="/images/icons/rematch.svg")
101 #playersInfo
102 p
103 span.name(:class="{connected: isConnected(0)}")
104 | {{ game.players[0].name || "@nonymous" }}
105 span.time(
106 v-if="game.score=='*'"
107 :class="{yourturn: !!vr && vr.turn == 'w'}"
108 )
109 span.time-left {{ virtualClocks[0][0] }}
110 span.time-separator(v-if="!!virtualClocks[0][1]") :
111 span.time-right(v-if="!!virtualClocks[0][1]")
112 | {{ virtualClocks[0][1] }}
113 span.split-names -
114 span.name(:class="{connected: isConnected(1)}")
115 | {{ game.players[1].name || "@nonymous" }}
116 span.time(
117 v-if="game.score=='*'"
118 :class="{yourturn: !!vr && vr.turn == 'b'}"
119 )
120 span.time-left {{ virtualClocks[1][0] }}
121 span.time-separator(v-if="!!virtualClocks[1][1]") :
122 span.time-right(v-if="!!virtualClocks[1][1]")
123 | {{ virtualClocks[1][1] }}
124 BaseGame(
125 ref="basegame"
126 :game="game"
127 @newmove="processMove"
128 )
129 </template>
130
131 <script>
132 import BaseGame from "@/components/BaseGame.vue";
133 import Chat from "@/components/Chat.vue";
134 import { store } from "@/store";
135 import { GameStorage } from "@/utils/gameStorage";
136 import { ppt } from "@/utils/datetime";
137 import { ajax } from "@/utils/ajax";
138 import { extractTime } from "@/utils/timeControl";
139 import { getRandString } from "@/utils/alea";
140 import { getScoreMessage } from "@/utils/scoring";
141 import { getFullNotation } from "@/utils/notation";
142 import { getDiagram } from "@/utils/printDiagram";
143 import { processModalClick } from "@/utils/modalClick";
144 import { playMove, getFilteredMove } from "@/utils/playUndo";
145 import { ArrayFun } from "@/utils/array";
146 import params from "@/parameters";
147 export default {
148 name: "my-game",
149 components: {
150 BaseGame,
151 Chat
152 },
153 data: function() {
154 return {
155 st: store.state,
156 // gameRef can point to a corr game, local game or remote live game
157 gameRef: "",
158 nextIds: [],
159 game: {}, //passed to BaseGame
160 // virtualClocks will be initialized from true game.clocks
161 virtualClocks: [],
162 vr: null, //"variant rules" object initialized from FEN
163 drawOffer: "",
164 rematchId: "",
165 rematchOffer: "",
166 lastateAsked: false,
167 people: {}, //players + observers
168 lastate: undefined, //used if opponent send lastate before game is ready
169 repeat: {}, //detect position repetition
170 curDiag: "", //for corr moves confirmation
171 conn: null,
172 roomInitialized: false,
173 // If newmove has wrong index: ask fullgame again:
174 askGameTime: 0,
175 gameIsLoading: false,
176 // If asklastate got no reply, ask again:
177 gotLastate: false,
178 gotMoveIdx: -1, //last move index received
179 // If newmove got no pingback, send again:
180 opponentGotMove: false,
181 connexionString: "",
182 // Incomplete info games: show move played
183 moveNotation: "",
184 // Intervals from setInterval():
185 askLastate: null,
186 retrySendmove: null,
187 clockUpdate: null,
188 // Related to (killing of) self multi-connects:
189 newConnect: {},
190 killed: {}
191 };
192 },
193 watch: {
194 $route: function(to, from) {
195 if (to.path.length < 6 || to.path.substr(6) != "/game/")
196 // Page change
197 this.cleanBeforeDestroy();
198 else if (from.params["id"] != to.params["id"]) {
199 // Change everything:
200 this.cleanBeforeDestroy();
201 let boardDiv = document.querySelector(".game");
202 if (!!boardDiv)
203 // In case of incomplete information variant:
204 boardDiv.style.visibility = "hidden";
205 this.atCreation();
206 } else
207 // Same game ID
208 this.nextIds = JSON.parse(this.$route.query["next"] || "[]");
209 }
210 },
211 // NOTE: some redundant code with Hall.vue (mostly related to people array)
212 created: function() {
213 this.atCreation();
214 },
215 mounted: function() {
216 ["chatWrap", "infoDiv"].forEach(eltName => {
217 document.getElementById(eltName)
218 .addEventListener("click", processModalClick);
219 });
220 if ("ontouchstart" in window) {
221 // Disable tooltips on smartphones:
222 document.querySelectorAll("#aboveBoard .tooltip").forEach(elt => {
223 elt.classList.remove("tooltip");
224 });
225 }
226 },
227 beforeDestroy: function() {
228 this.cleanBeforeDestroy();
229 },
230 methods: {
231 cleanBeforeDestroy: function() {
232 document.removeEventListener('visibilitychange', this.visibilityChange);
233 if (!!this.askLastate)
234 clearInterval(this.askLastate);
235 if (!!this.retrySendmove)
236 clearInterval(this.retrySendmove);
237 if (!!this.clockUpdate)
238 clearInterval(this.clockUpdate);
239 this.send("disconnect");
240 },
241 visibilityChange: function() {
242 // TODO: Use document.hidden? https://webplatform.news/issues/2019-03-27
243 this.send(
244 document.visibilityState == "visible"
245 ? "getfocus"
246 : "losefocus"
247 );
248 },
249 atCreation: function() {
250 document.addEventListener('visibilitychange', this.visibilityChange);
251 // 0] (Re)Set variables
252 this.gameRef = this.$route.params["id"];
253 // next = next corr games IDs to navigate faster (if applicable)
254 this.nextIds = JSON.parse(this.$route.query["next"] || "[]");
255 // Always add myself to players' list
256 const my = this.st.user;
257 this.$set(
258 this.people,
259 my.sid,
260 {
261 id: my.id,
262 name: my.name,
263 focus: true
264 }
265 );
266 this.game = {
267 players: [{ name: "" }, { name: "" }],
268 chats: [],
269 rendered: false
270 };
271 let chatComp = this.$refs["chatcomp"];
272 if (!!chatComp) chatComp.chats = [];
273 this.virtualClocks = [[0,0], [0,0]];
274 this.vr = null;
275 this.drawOffer = "";
276 this.lastateAsked = false;
277 this.rematchOffer = "";
278 this.lastate = undefined;
279 this.roomInitialized = false;
280 this.askGameTime = 0;
281 this.gameIsLoading = false;
282 this.gotLastate = false;
283 this.gotMoveIdx = -1;
284 this.opponentGotMove = false;
285 this.askLastate = null;
286 this.retrySendmove = null;
287 this.clockUpdate = null;
288 this.newConnect = {};
289 this.killed = {};
290 // 1] Initialize connection
291 this.connexionString =
292 params.socketUrl +
293 "/?sid=" +
294 this.st.user.sid +
295 "&id=" +
296 this.st.user.id +
297 "&tmpId=" +
298 getRandString() +
299 "&page=" +
300 // Discard potential "/?next=[...]" for page indication:
301 encodeURIComponent(this.$route.path.match(/\/game\/[a-zA-Z0-9]+/)[0]);
302 this.conn = new WebSocket(this.connexionString);
303 this.conn.addEventListener("message", this.socketMessageListener);
304 this.conn.addEventListener("close", this.socketCloseListener);
305 // Socket init required before loading remote game:
306 const socketInit = callback => {
307 if (this.conn.readyState == 1)
308 // 1 == OPEN state
309 callback();
310 else
311 // Socket not ready yet (initial loading)
312 // NOTE: first arg is Websocket object, unused here:
313 this.conn.onopen = () => callback();
314 };
315 this.fetchGame((game) => {
316 if (!!game)
317 this.loadVariantThenGame(game, () => socketInit(this.roomInit));
318 else
319 // Live game stored remotely: need socket to retrieve it
320 // NOTE: the callback "roomInit" will be lost, so we don't provide it.
321 // --> It will be given when receiving "fullgame" socket event.
322 socketInit(() => { this.send("askfullgame"); });
323 });
324 },
325 roomInit: function() {
326 if (!this.roomInitialized) {
327 // Notify the room only now that I connected, because
328 // messages might be lost otherwise (if game loading is slow)
329 this.send("connect");
330 this.send("pollclients");
331 // We may ask fullgame several times if some moves are lost,
332 // but room should be init only once:
333 this.roomInitialized = true;
334 }
335 },
336 send: function(code, obj) {
337 if (!!this.conn)
338 this.conn.send(JSON.stringify(Object.assign({ code: code }, obj)));
339 },
340 isConnected: function(index) {
341 const player = this.game.players[index];
342 // Is it me ? In this case no need to bother with focus
343 if (this.st.user.sid == player.sid || this.st.user.id == player.id)
344 // Still have to check for name (because of potential multi-accounts
345 // on same browser, although this should be rare...)
346 return (!this.st.user.name || this.st.user.name == player.name);
347 // Try to find a match in people:
348 return (
349 (
350 !!player.sid &&
351 Object.keys(this.people).some(sid =>
352 sid == player.sid && this.people[sid].focus)
353 )
354 ||
355 (
356 !!player.id &&
357 Object.values(this.people).some(p =>
358 p.id == player.id && p.focus)
359 )
360 );
361 },
362 getOppsid: function() {
363 let oppsid = this.game.oppsid;
364 if (!oppsid) {
365 oppsid = Object.keys(this.people).find(
366 sid => this.people[sid].id == this.game.oppid
367 );
368 }
369 // oppsid is useful only if opponent is online:
370 if (!!oppsid && !!this.people[oppsid]) return oppsid;
371 return null;
372 },
373 toggleChat: function() {
374 if (document.getElementById("modalChat").checked)
375 // Entering chat
376 document.getElementById("inputChat").focus();
377 // TODO: next line is only required when exiting chat,
378 // but the event for now isn't well detected.
379 document.getElementById("chatBtn").classList.remove("somethingnew");
380 },
381 processChat: function(chat) {
382 this.send("newchat", { data: chat });
383 // NOTE: anonymous chats in corr games are not stored on server (TODO?)
384 if (this.game.type == "corr" && this.st.user.id > 0)
385 this.updateCorrGame({ chat: chat });
386 },
387 clearChat: function() {
388 // Nothing more to do if game is live (chats not recorded)
389 if (this.game.type == "corr") {
390 if (!!this.game.mycolor) {
391 ajax(
392 "/chats",
393 "DELETE",
394 { data: { gid: this.game.id } }
395 );
396 }
397 this.$set(this.game, "chats", []);
398 }
399 },
400 getGameType: function(game) {
401 return game.cadence.indexOf("d") >= 0 ? "corr" : "live";
402 },
403 // Notify something after a new move (to opponent and me on MyGames page)
404 notifyMyGames: function(thing, data) {
405 this.send(
406 "notify" + thing,
407 {
408 data: data,
409 targets: this.game.players.map(p => {
410 return { sid: p.sid, id: p.id };
411 })
412 }
413 );
414 },
415 showNextGame: function() {
416 // Did I play in current game? If not, add it to nextIds list
417 if (this.game.score == "*" && this.vr.turn == this.game.mycolor)
418 this.nextIds.unshift(this.game.id);
419 const nextGid = this.nextIds.pop();
420 this.$router.push(
421 "/game/" + nextGid + "/?next=" + JSON.stringify(this.nextIds));
422 },
423 askGameAgain: function() {
424 this.gameIsLoading = true;
425 const currentUrl = document.location.href;
426 const doAskGame = () => {
427 if (document.location.href != currentUrl) return; //page change
428 this.fetchGame((game) => {
429 if (!!game)
430 // This is my game: just reload.
431 this.loadGame(game);
432 else
433 // Just ask fullgame again (once!), this is much simpler.
434 // If this fails, the user could just reload page :/
435 this.send("askfullgame");
436 });
437 };
438 // Delay of at least 2s between two game requests
439 const now = Date.now();
440 const delay = Math.max(2000 - (now - this.askGameTime), 0);
441 this.askGameTime = now;
442 setTimeout(doAskGame, delay);
443 },
444 socketMessageListener: function(msg) {
445 if (!this.conn) return;
446 const data = JSON.parse(msg.data);
447 switch (data.code) {
448 case "pollclients":
449 // TODO: shuffling and random filtering on server, if
450 // the room is really crowded.
451 data.sockIds.forEach(sid => {
452 if (sid != this.st.user.sid) {
453 this.people[sid] = { focus: true };
454 this.send("askidentity", { target: sid });
455 }
456 });
457 break;
458 case "connect":
459 if (!this.people[data.from]) {
460 this.people[data.from] = { focus: true };
461 this.newConnect[data.from] = true; //for self multi-connects tests
462 this.send("askidentity", { target: data.from });
463 }
464 break;
465 case "disconnect":
466 this.$delete(this.people, data.from);
467 break;
468 case "getfocus": {
469 let player = this.people[data.from];
470 if (!!player) {
471 player.focus = true;
472 this.$forceUpdate(); //TODO: shouldn't be required
473 }
474 break;
475 }
476 case "losefocus": {
477 let player = this.people[data.from];
478 if (!!player) {
479 player.focus = false;
480 this.$forceUpdate(); //TODO: shouldn't be required
481 }
482 break;
483 }
484 case "killed":
485 // I logged in elsewhere:
486 this.conn.removeEventListener("message", this.socketMessageListener);
487 this.conn.removeEventListener("close", this.socketCloseListener);
488 this.conn = null;
489 alert(this.st.tr["New connexion detected: tab now offline"]);
490 break;
491 case "askidentity": {
492 // Request for identification
493 const me = {
494 // Decompose to avoid revealing email
495 name: this.st.user.name,
496 sid: this.st.user.sid,
497 id: this.st.user.id
498 };
499 this.send("identity", { data: me, target: data.from });
500 break;
501 }
502 case "identity": {
503 const user = data.data;
504 let player = this.people[user.sid];
505 // player.focus is already set
506 player.name = user.name;
507 player.id = user.id;
508 this.$forceUpdate(); //TODO: shouldn't be required
509 // If I multi-connect, kill current connexion if no mark (I'm older)
510 if (this.newConnect[user.sid]) {
511 if (
512 user.id > 0 &&
513 user.id == this.st.user.id &&
514 user.sid != this.st.user.sid &&
515 !this.killed[this.st.user.sid]
516 ) {
517 this.send("killme", { sid: this.st.user.sid });
518 this.killed[this.st.user.sid] = true;
519 }
520 delete this.newConnect[user.sid];
521 }
522 if (!this.killed[this.st.user.sid]) {
523 // Ask potentially missed last state, if opponent and I play
524 if (
525 !!this.game.mycolor &&
526 this.game.type == "live" &&
527 this.game.score == "*" &&
528 this.game.players.some(p => p.sid == user.sid)
529 ) {
530 this.send("asklastate", { target: user.sid });
531 let counter = 1;
532 this.askLastate = setInterval(
533 () => {
534 // Ask at most 3 times:
535 // if no reply after that there should be a network issue.
536 if (
537 counter < 3 &&
538 !this.gotLastate &&
539 !!this.people[user.sid]
540 ) {
541 this.send("asklastate", { target: user.sid });
542 counter++;
543 } else {
544 clearInterval(this.askLastate);
545 }
546 },
547 1500
548 );
549 }
550 }
551 break;
552 }
553 case "askgame":
554 // Send current (live) game if not asked by any of the players
555 if (
556 this.game.type == "live" &&
557 this.game.players.every(p => p.sid != data.from[0])
558 ) {
559 const myGame = {
560 id: this.game.id,
561 fen: this.game.fen,
562 players: this.game.players,
563 vid: this.game.vid,
564 cadence: this.game.cadence,
565 score: this.game.score
566 };
567 this.send("game", { data: myGame, target: data.from });
568 }
569 break;
570 case "askfullgame":
571 const gameToSend = Object.keys(this.game)
572 .filter(k =>
573 [
574 "id","fen","players","vid","cadence","fenStart","vname",
575 "moves","clocks","score","drawOffer","rematchOffer"
576 ].includes(k))
577 .reduce(
578 (obj, k) => {
579 obj[k] = this.game[k];
580 return obj;
581 },
582 {}
583 );
584 this.send("fullgame", { data: gameToSend, target: data.from });
585 break;
586 case "fullgame":
587 // Callback "roomInit" to poll clients only after game is loaded
588 this.loadVariantThenGame(data.data, this.roomInit);
589 break;
590 case "asklastate":
591 // Sending informative last state if I played a move or score != "*"
592 // If the game or moves aren't loaded yet, delay the sending:
593 if (!this.game || !this.game.moves) this.lastateAsked = true;
594 else this.sendLastate(data.from);
595 break;
596 case "lastate": {
597 // Got opponent infos about last move
598 this.gotLastate = true;
599 this.lastate = data.data;
600 if (this.game.rendered)
601 // Game is rendered (Board component)
602 this.processLastate();
603 // Else: will be processed when game is ready
604 break;
605 }
606 case "newmove": {
607 const movePlus = data.data;
608 const movesCount = this.game.moves.length;
609 if (movePlus.index > movesCount) {
610 // This can only happen if I'm an observer and missed a move.
611 if (this.gotMoveIdx < movePlus.index)
612 this.gotMoveIdx = movePlus.index;
613 if (!this.gameIsLoading) this.askGameAgain();
614 }
615 else {
616 if (
617 movePlus.index < movesCount ||
618 this.gotMoveIdx >= movePlus.index
619 ) {
620 // Opponent re-send but we already have the move:
621 // (maybe he didn't receive our pingback...)
622 this.send("gotmove", {data: movePlus.index, target: data.from});
623 } else {
624 this.gotMoveIdx = movePlus.index;
625 const receiveMyMove = (movePlus.color == this.game.mycolor);
626 if (!receiveMyMove && !!this.game.mycolor)
627 // Notify opponent that I got the move:
628 this.send("gotmove", {data: movePlus.index, target: data.from});
629 if (movePlus.cancelDrawOffer) {
630 // Opponent refuses draw
631 this.drawOffer = "";
632 // NOTE for corr games: drawOffer reset by player in turn
633 if (
634 this.game.type == "live" &&
635 !!this.game.mycolor &&
636 !receiveMyMove
637 ) {
638 GameStorage.update(this.gameRef, { drawOffer: "" });
639 }
640 }
641 this.$refs["basegame"].play(movePlus.move, "received", null, true);
642 const moveColIdx = ["w", "b"].indexOf(movePlus.color);
643 this.game.clocks[moveColIdx] = movePlus.clock;
644 this.processMove(
645 movePlus.move,
646 { receiveMyMove: receiveMyMove }
647 );
648 }
649 }
650 break;
651 }
652 case "gotmove": {
653 this.opponentGotMove = true;
654 // Now his clock starts running on my side:
655 const oppIdx = ['w','b'].indexOf(this.vr.turn);
656 this.re_setClocks();
657 break;
658 }
659 case "resign":
660 const score = (data.data == "b" ? "1-0" : "0-1");
661 const side = (data.data == "w" ? "White" : "Black");
662 this.gameOver(score, side + " surrender");
663 break;
664 case "abort":
665 this.gameOver("?", "Stop");
666 break;
667 case "draw":
668 this.gameOver("1/2", data.data);
669 break;
670 case "drawoffer":
671 // NOTE: observers don't know who offered draw
672 this.drawOffer = "received";
673 if (this.game.type == "live") {
674 GameStorage.update(
675 this.gameRef,
676 { drawOffer: V.GetOppCol(this.game.mycolor) }
677 );
678 }
679 break;
680 case "rematchoffer":
681 // NOTE: observers don't know who offered rematch
682 this.rematchOffer = data.data ? "received" : "";
683 if (this.game.type == "live") {
684 GameStorage.update(
685 this.gameRef,
686 { rematchOffer: V.GetOppCol(this.game.mycolor) }
687 );
688 }
689 break;
690 case "newgame": {
691 // A game started, redirect if I'm playing in
692 const gameInfo = data.data;
693 const gameType = this.getGameType(gameInfo);
694 if (
695 gameType == "live" &&
696 gameInfo.players.some(p => p.sid == this.st.user.sid)
697 ) {
698 this.addAndGotoLiveGame(gameInfo);
699 } else if (
700 gameType == "corr" &&
701 gameInfo.players.some(p => p.id == this.st.user.id)
702 ) {
703 this.$router.push("/game/" + gameInfo.id);
704 } else {
705 this.rematchId = gameInfo.id;
706 document.getElementById("modalInfo").checked = true;
707 }
708 break;
709 }
710 case "newchat":
711 this.$refs["chatcomp"].newChat(data.data);
712 if (!document.getElementById("modalChat").checked)
713 document.getElementById("chatBtn").classList.add("somethingnew");
714 break;
715 }
716 },
717 socketCloseListener: function() {
718 this.conn = new WebSocket(this.connexionString);
719 this.conn.addEventListener("message", this.socketMessageListener);
720 this.conn.addEventListener("close", this.socketCloseListener);
721 },
722 updateCorrGame: function(obj, callback) {
723 ajax(
724 "/games",
725 "PUT",
726 {
727 data: {
728 gid: this.gameRef,
729 newObj: obj
730 },
731 success: () => {
732 if (!!callback) callback();
733 }
734 }
735 );
736 },
737 sendLastate: function(target) {
738 // Send our "last state" informations to opponent
739 const L = this.game.moves.length;
740 const myIdx = ["w", "b"].indexOf(this.game.mycolor);
741 const myLastate = {
742 lastMove:
743 (L > 0 && this.vr.turn != this.game.mycolor)
744 ? this.game.moves[L - 1]
745 : undefined,
746 clock: this.game.clocks[myIdx],
747 // Since we played a move (or abort or resign),
748 // only drawOffer=="sent" is possible
749 drawSent: this.drawOffer == "sent",
750 rematchSent: this.rematchOffer == "sent",
751 score: this.game.score != "*" ? this.game.score : undefined,
752 scoreMsg: this.game.score != "*" ? this.game.scoreMsg : undefined,
753 movesCount: L
754 };
755 this.send("lastate", { data: myLastate, target: target });
756 },
757 // lastate was received, but maybe game wasn't ready yet:
758 processLastate: function() {
759 const data = this.lastate;
760 this.lastate = undefined; //security...
761 const L = this.game.moves.length;
762 const oppIdx = 1 - ["w", "b"].indexOf(this.game.mycolor);
763 this.game.clocks[oppIdx] = data.clock;
764 if (data.movesCount > L) {
765 // Just got last move from him
766 this.$refs["basegame"].play(data.lastMove, "received", null, true);
767 this.processMove(data.lastMove);
768 } else {
769 clearInterval(this.clockUpdate);
770 this.re_setClocks();
771 }
772 if (data.drawSent) this.drawOffer = "received";
773 if (data.rematchSent) this.rematchOffer = "received";
774 if (!!data.score) {
775 this.drawOffer = "";
776 if (this.game.score == "*")
777 this.gameOver(data.score, data.scoreMsg);
778 }
779 },
780 clickDraw: function() {
781 if (!this.game.mycolor) return; //I'm just spectator
782 if (["received", "threerep"].includes(this.drawOffer)) {
783 if (!confirm(this.st.tr["Accept draw?"])) return;
784 const message =
785 this.drawOffer == "received"
786 ? "Mutual agreement"
787 : "Three repetitions";
788 this.send("draw", { data: message });
789 this.gameOver("1/2", message);
790 } else if (this.drawOffer == "") {
791 // No effect if drawOffer == "sent"
792 if (this.game.mycolor != this.vr.turn) {
793 alert(this.st.tr["Draw offer only in your turn"]);
794 return;
795 }
796 if (!confirm(this.st.tr["Offer draw?"])) return;
797 this.drawOffer = "sent";
798 this.send("drawoffer");
799 if (this.game.type == "live") {
800 GameStorage.update(
801 this.gameRef,
802 { drawOffer: this.game.mycolor }
803 );
804 } else this.updateCorrGame({ drawOffer: this.game.mycolor });
805 }
806 },
807 addAndGotoLiveGame: function(gameInfo, callback) {
808 const game = Object.assign(
809 {},
810 gameInfo,
811 {
812 // (other) Game infos: constant
813 fenStart: gameInfo.fen,
814 vname: this.game.vname,
815 created: Date.now(),
816 // Game state (including FEN): will be updated
817 moves: [],
818 clocks: [-1, -1], //-1 = unstarted
819 score: "*"
820 }
821 );
822 GameStorage.add(game, (err) => {
823 // No error expected.
824 if (!err) {
825 if (this.st.settings.sound)
826 new Audio("/sounds/newgame.flac").play().catch(() => {});
827 if (!!callback) callback();
828 this.$router.push("/game/" + gameInfo.id);
829 }
830 });
831 },
832 clickRematch: function() {
833 if (!this.game.mycolor) return; //I'm just spectator
834 if (this.rematchOffer == "received") {
835 // Start a new game!
836 let gameInfo = {
837 id: getRandString(), //ignored if corr
838 fen: V.GenRandInitFen(this.game.randomness),
839 players: this.game.players.reverse(),
840 vid: this.game.vid,
841 cadence: this.game.cadence
842 };
843 const notifyNewGame = () => {
844 const oppsid = this.getOppsid(); //may be null
845 this.send("rnewgame", { data: gameInfo, oppsid: oppsid });
846 // To main Hall if corr game:
847 if (this.game.type == "corr")
848 this.send("newgame", { data: gameInfo });
849 // Also to MyGames page:
850 this.notifyMyGames("newgame", gameInfo);
851 };
852 if (this.game.type == "live")
853 this.addAndGotoLiveGame(gameInfo, notifyNewGame);
854 else {
855 // corr game
856 ajax(
857 "/games",
858 "POST",
859 {
860 // cid is useful to delete the challenge:
861 data: { gameInfo: gameInfo },
862 success: (response) => {
863 gameInfo.id = response.gameId;
864 notifyNewGame();
865 this.$router.push("/game/" + response.gameId);
866 }
867 }
868 );
869 }
870 } else if (this.rematchOffer == "") {
871 this.rematchOffer = "sent";
872 this.send("rematchoffer", { data: true });
873 if (this.game.type == "live") {
874 GameStorage.update(
875 this.gameRef,
876 { rematchOffer: this.game.mycolor }
877 );
878 } else this.updateCorrGame({ rematchOffer: this.game.mycolor });
879 } else if (this.rematchOffer == "sent") {
880 // Toggle rematch offer (on --> off)
881 this.rematchOffer = "";
882 this.send("rematchoffer", { data: false });
883 if (this.game.type == "live") {
884 GameStorage.update(
885 this.gameRef,
886 { rematchOffer: '' }
887 );
888 } else this.updateCorrGame({ rematchOffer: 'n' });
889 }
890 },
891 abortGame: function() {
892 if (!this.game.mycolor || !confirm(this.st.tr["Terminate game?"])) return;
893 this.gameOver("?", "Stop");
894 this.send("abort");
895 },
896 resign: function() {
897 if (!this.game.mycolor || !confirm(this.st.tr["Resign the game?"]))
898 return;
899 this.send("resign", { data: this.game.mycolor });
900 const score = (this.game.mycolor == "w" ? "0-1" : "1-0");
901 const side = (this.game.mycolor == "w" ? "White" : "Black");
902 this.gameOver(score, side + " surrender");
903 },
904 loadGame: function(game, callback) {
905 this.vr = new V(game.fen);
906 const gtype = this.getGameType(game);
907 const tc = extractTime(game.cadence);
908 const myIdx = game.players.findIndex(p => {
909 return p.sid == this.st.user.sid || p.id == this.st.user.id;
910 });
911 const mycolor = [undefined, "w", "b"][myIdx + 1]; //undefined for observers
912 if (!game.chats) game.chats = []; //live games don't have chat history
913 if (gtype == "corr") {
914 // NOTE: clocks in seconds
915 game.moves.sort((m1, m2) => m1.idx - m2.idx); //in case of
916 game.clocks = [tc.mainTime, tc.mainTime];
917 const L = game.moves.length;
918 if (game.score == "*") {
919 // Adjust clocks
920 if (L >= 2) {
921 game.clocks[L % 2] -=
922 (Date.now() - game.moves[L-1].played) / 1000;
923 }
924 }
925 // Sort chat messages from newest to oldest
926 game.chats.sort((c1, c2) => {
927 return c2.added - c1.added;
928 });
929 if (myIdx >= 0 && game.score == "*" && game.chats.length > 0) {
930 // Did a chat message arrive after my last move?
931 let dtLastMove = 0;
932 if (L == 1 && myIdx == 0)
933 dtLastMove = game.moves[0].played;
934 else if (L >= 2) {
935 if (L % 2 == 0) {
936 // It's now white turn
937 dtLastMove = game.moves[L-1-(1-myIdx)].played;
938 } else {
939 // Black turn:
940 dtLastMove = game.moves[L-1-myIdx].played;
941 }
942 }
943 if (dtLastMove < game.chats[0].added)
944 document.getElementById("chatBtn").classList.add("somethingnew");
945 }
946 // Now that we used idx and played, re-format moves as for live games
947 game.moves = game.moves.map(m => m.squares);
948 }
949 if (gtype == "live") {
950 if (game.clocks[0] < 0) {
951 // Game is unstarted. clock is ignored until move 2
952 game.clocks = [tc.mainTime, tc.mainTime];
953 if (myIdx >= 0) {
954 // I play in this live game
955 GameStorage.update(game.id, {
956 clocks: game.clocks
957 });
958 }
959 } else {
960 if (!!game.initime)
961 // It's my turn: clocks not updated yet
962 game.clocks[myIdx] -= (Date.now() - game.initime) / 1000;
963 }
964 }
965 // TODO: merge next 2 "if" conditions
966 if (!!game.drawOffer) {
967 if (game.drawOffer == "t")
968 // Three repetitions
969 this.drawOffer = "threerep";
970 else {
971 // Draw offered by any of the players:
972 if (myIdx < 0) this.drawOffer = "received";
973 else {
974 // I play in this game:
975 if (
976 (game.drawOffer == "w" && myIdx == 0) ||
977 (game.drawOffer == "b" && myIdx == 1)
978 )
979 this.drawOffer = "sent";
980 else this.drawOffer = "received";
981 }
982 }
983 }
984 if (!!game.rematchOffer) {
985 if (myIdx < 0) this.rematchOffer = "received";
986 else {
987 // I play in this game:
988 if (
989 (game.rematchOffer == "w" && myIdx == 0) ||
990 (game.rematchOffer == "b" && myIdx == 1)
991 )
992 this.rematchOffer = "sent";
993 else this.rematchOffer = "received";
994 }
995 }
996 this.repeat = {}; //reset: scan past moves' FEN:
997 let repIdx = 0;
998 let vr_tmp = new V(game.fenStart);
999 let curTurn = "n";
1000 game.moves.forEach(m => {
1001 playMove(m, vr_tmp);
1002 const fenIdx = vr_tmp.getFen().replace(/ /g, "_");
1003 this.repeat[fenIdx] = this.repeat[fenIdx]
1004 ? this.repeat[fenIdx] + 1
1005 : 1;
1006 });
1007 if (this.repeat[repIdx] >= 3) this.drawOffer = "threerep";
1008 this.game = Object.assign(
1009 // NOTE: assign mycolor here, since BaseGame could also be VS computer
1010 {
1011 type: gtype,
1012 increment: tc.increment,
1013 mycolor: mycolor,
1014 // opponent sid not strictly required (or available), but easier
1015 // at least oppsid or oppid is available anyway:
1016 oppsid: myIdx < 0 ? undefined : game.players[1 - myIdx].sid,
1017 oppid: myIdx < 0 ? undefined : game.players[1 - myIdx].id
1018 },
1019 game
1020 );
1021 this.$refs["basegame"].re_setVariables(this.game);
1022 if (!this.gameIsLoading) {
1023 // Initial loading:
1024 this.gotMoveIdx = game.moves.length - 1;
1025 // If we arrive here after 'nextGame' action, the board might be hidden
1026 let boardDiv = document.querySelector(".game");
1027 if (!!boardDiv && boardDiv.style.visibility == "hidden")
1028 boardDiv.style.visibility = "visible";
1029 }
1030 this.re_setClocks();
1031 this.$nextTick(() => {
1032 this.game.rendered = true;
1033 // Did lastate arrive before game was rendered?
1034 if (this.lastate) this.processLastate();
1035 });
1036 if (this.lastateAsked) {
1037 this.lastateAsked = false;
1038 this.sendLastate(game.oppsid);
1039 }
1040 if (this.gameIsLoading) {
1041 this.gameIsLoading = false;
1042 if (this.gotMoveIdx >= game.moves.length)
1043 // Some moves arrived meanwhile...
1044 this.askGameAgain();
1045 }
1046 if (!!callback) callback();
1047 },
1048 loadVariantThenGame: async function(game, callback) {
1049 await import("@/variants/" + game.vname + ".js")
1050 .then((vModule) => {
1051 window.V = vModule[game.vname + "Rules"];
1052 this.loadGame(game, callback);
1053 });
1054 },
1055 // 3 cases for loading a game:
1056 // - from indexedDB (running or completed live game I play)
1057 // - from server (one correspondance game I play[ed] or not)
1058 // - from remote peer (one live game I don't play, finished or not)
1059 fetchGame: function(callback) {
1060 if (Number.isInteger(this.gameRef) || !isNaN(parseInt(this.gameRef))) {
1061 // corr games identifiers are integers
1062 ajax(
1063 "/games",
1064 "GET",
1065 {
1066 data: { gid: this.gameRef },
1067 success: (res) => {
1068 res.game.moves.forEach(m => {
1069 m.squares = JSON.parse(m.squares);
1070 });
1071 callback(res.game);
1072 }
1073 }
1074 );
1075 } else
1076 // Local game (or live remote)
1077 GameStorage.get(this.gameRef, callback);
1078 },
1079 re_setClocks: function() {
1080 this.virtualClocks = this.game.clocks.map(s => ppt(s).split(':'));
1081 if (this.game.moves.length < 2 || this.game.score != "*") {
1082 // 1st move not completed yet, or game over: freeze time
1083 return;
1084 }
1085 const currentTurn = this.vr.turn;
1086 const currentMovesCount = this.game.moves.length;
1087 const colorIdx = ["w", "b"].indexOf(currentTurn);
1088 this.clockUpdate = setInterval(
1089 () => {
1090 if (
1091 this.game.clocks[colorIdx] < 0 ||
1092 this.game.moves.length > currentMovesCount ||
1093 this.game.score != "*"
1094 ) {
1095 clearInterval(this.clockUpdate);
1096 if (this.game.clocks[colorIdx] < 0)
1097 this.gameOver(
1098 currentTurn == "w" ? "0-1" : "1-0",
1099 "Time"
1100 );
1101 } else {
1102 this.$set(
1103 this.virtualClocks,
1104 colorIdx,
1105 ppt(Math.max(0, --this.game.clocks[colorIdx])).split(':')
1106 );
1107 }
1108 },
1109 1000
1110 );
1111 },
1112 // Update variables and storage after a move:
1113 processMove: function(move, data) {
1114 if (!data) data = {};
1115 const moveCol = this.vr.turn;
1116 const colorIdx = ["w", "b"].indexOf(moveCol);
1117 const nextIdx = 1 - colorIdx;
1118 const doProcessMove = () => {
1119 const origMovescount = this.game.moves.length;
1120 // The move is (about to be) played: stop clock
1121 clearInterval(this.clockUpdate);
1122 if (moveCol == this.game.mycolor && !data.receiveMyMove) {
1123 if (this.drawOffer == "received")
1124 // I refuse draw
1125 this.drawOffer = "";
1126 if (this.game.type == "live" && origMovescount >= 2) {
1127 this.game.clocks[colorIdx] += this.game.increment;
1128 // For a correct display in casqe of disconnected opponent:
1129 this.$set(
1130 this.virtualClocks,
1131 colorIdx,
1132 ppt(this.game.clocks[colorIdx]).split(':')
1133 );
1134 GameStorage.update(this.gameRef, {
1135 // It's not my turn anymore:
1136 initime: null
1137 });
1138 }
1139 }
1140 // Update current game object:
1141 playMove(move, this.vr);
1142 if (!data.score)
1143 // Received move, score is computed in BaseGame, but maybe not yet.
1144 // ==> Compute it here, although this is redundant (TODO)
1145 data.score = this.vr.getCurrentScore();
1146 if (data.score != "*") this.gameOver(data.score);
1147 this.game.moves.push(move);
1148 this.game.fen = this.vr.getFen();
1149 if (this.game.type == "corr") {
1150 // In corr games, just reset clock to mainTime:
1151 this.game.clocks[colorIdx] = extractTime(this.game.cadence).mainTime;
1152 }
1153 // If repetition detected, consider that a draw offer was received:
1154 const fenObj = this.vr.getFenForRepeat();
1155 this.repeat[fenObj] =
1156 !!this.repeat[fenObj]
1157 ? this.repeat[fenObj] + 1
1158 : 1;
1159 if (this.repeat[fenObj] >= 3) this.drawOffer = "threerep";
1160 else if (this.drawOffer == "threerep") this.drawOffer = "";
1161 if (!!this.game.mycolor && !data.receiveMyMove) {
1162 // NOTE: 'var' to see that variable outside this block
1163 var filtered_move = getFilteredMove(move);
1164 }
1165 if (moveCol == this.game.mycolor && !data.receiveMyMove) {
1166 // Notify turn on MyGames page:
1167 this.notifyMyGames(
1168 "turn",
1169 {
1170 gid: this.gameRef,
1171 turn: this.vr.turn
1172 }
1173 );
1174 }
1175 // Since corr games are stored at only one location, update should be
1176 // done only by one player for each move:
1177 if (
1178 this.game.type == "live" &&
1179 !!this.game.mycolor &&
1180 moveCol != this.game.mycolor &&
1181 this.game.moves.length >= 2
1182 ) {
1183 // Receive a move: update initime
1184 this.game.initime = Date.now();
1185 GameStorage.update(this.gameRef, {
1186 // It's my turn now!
1187 initime: this.game.initime
1188 });
1189 }
1190 if (
1191 !!this.game.mycolor &&
1192 !data.receiveMyMove &&
1193 (this.game.type == "live" || moveCol == this.game.mycolor)
1194 ) {
1195 let drawCode = "";
1196 switch (this.drawOffer) {
1197 case "threerep":
1198 drawCode = "t";
1199 break;
1200 case "sent":
1201 drawCode = this.game.mycolor;
1202 break;
1203 case "received":
1204 drawCode = V.GetOppCol(this.game.mycolor);
1205 break;
1206 }
1207 if (this.game.type == "corr") {
1208 // corr: only move, fen and score
1209 this.updateCorrGame({
1210 fen: this.game.fen,
1211 move: {
1212 squares: filtered_move,
1213 idx: origMovescount
1214 },
1215 // Code "n" for "None" to force reset (otherwise it's ignored)
1216 drawOffer: drawCode || "n"
1217 });
1218 }
1219 else {
1220 const updateStorage = () => {
1221 GameStorage.update(this.gameRef, {
1222 fen: this.game.fen,
1223 move: filtered_move,
1224 moveIdx: origMovescount,
1225 clocks: this.game.clocks,
1226 drawOffer: drawCode
1227 });
1228 };
1229 // The active tab can update storage immediately
1230 if (!document.hidden) updateStorage();
1231 // Small random delay otherwise
1232 else setTimeout(updateStorage, 500 + 1000 * Math.random());
1233 }
1234 }
1235 // Send move ("newmove" event) to people in the room (if our turn)
1236 if (moveCol == this.game.mycolor && !data.receiveMyMove) {
1237 let sendMove = {
1238 move: filtered_move,
1239 index: origMovescount,
1240 // color is required to check if this is my move (if several tabs opened)
1241 color: moveCol,
1242 cancelDrawOffer: this.drawOffer == ""
1243 };
1244 if (this.game.type == "live")
1245 sendMove["clock"] = this.game.clocks[colorIdx];
1246 // (Live) Clocks will re-start when the opponent pingback arrive
1247 this.opponentGotMove = false;
1248 this.send("newmove", {data: sendMove});
1249 // If the opponent doesn't reply gotmove soon enough, re-send move:
1250 // Do this at most 2 times, because mpore would mean network issues,
1251 // opponent would then be expected to disconnect/reconnect.
1252 let counter = 1;
1253 const currentUrl = document.location.href;
1254 this.retrySendmove = setInterval(
1255 () => {
1256 if (
1257 counter >= 3 ||
1258 this.opponentGotMove ||
1259 document.location.href != currentUrl //page change
1260 ) {
1261 clearInterval(this.retrySendmove);
1262 return;
1263 }
1264 const oppsid = this.getOppsid();
1265 if (!oppsid)
1266 // Opponent is disconnected: he'll ask last state
1267 clearInterval(this.retrySendmove);
1268 else {
1269 this.send("newmove", { data: sendMove, target: oppsid });
1270 counter++;
1271 }
1272 },
1273 1500
1274 );
1275 }
1276 else
1277 // Not my move or I'm an observer: just start other player's clock
1278 this.re_setClocks();
1279 };
1280 if (
1281 this.game.type == "corr" &&
1282 moveCol == this.game.mycolor &&
1283 !data.receiveMyMove
1284 ) {
1285 let boardDiv = document.querySelector(".game");
1286 const afterSetScore = () => {
1287 doProcessMove();
1288 if (this.st.settings.gotonext && this.nextIds.length > 0)
1289 this.showNextGame();
1290 else {
1291 // The board might have been hidden:
1292 if (boardDiv.style.visibility == "hidden")
1293 boardDiv.style.visibility = "visible";
1294 if (data.score == "*") this.re_setClocks();
1295 }
1296 };
1297 let el = document.querySelector("#buttonsConfirm > .acceptBtn");
1298 // We may play several moves in a row: in case of, remove listener:
1299 let elClone = el.cloneNode(true);
1300 el.parentNode.replaceChild(elClone, el);
1301 elClone.addEventListener(
1302 "click",
1303 () => {
1304 document.getElementById("modalConfirm").checked = false;
1305 if (!!data.score && data.score != "*")
1306 // Set score first
1307 this.gameOver(data.score, null, afterSetScore);
1308 else afterSetScore();
1309 }
1310 );
1311 // PlayOnBoard is enough, and more appropriate for Synchrone Chess
1312 V.PlayOnBoard(this.vr.board, move);
1313 const position = this.vr.getBaseFen();
1314 V.UndoOnBoard(this.vr.board, move);
1315 if (["all","byrow"].includes(V.ShowMoves)) {
1316 this.curDiag = getDiagram({
1317 position: position,
1318 orientation: V.CanFlip ? this.game.mycolor : "w"
1319 });
1320 document.querySelector("#confirmDiv > .card").style.width =
1321 boardDiv.offsetWidth + "px";
1322 } else {
1323 // Incomplete information: just ask confirmation
1324 // Hide the board, because otherwise it could reveal infos
1325 boardDiv.style.visibility = "hidden";
1326 this.moveNotation = getFullNotation(move);
1327 }
1328 document.getElementById("modalConfirm").checked = true;
1329 }
1330 else {
1331 // Normal situation
1332 if (!!data.score && data.score != "*")
1333 this.gameOver(data.score, null, doProcessMove);
1334 else doProcessMove();
1335 }
1336 },
1337 cancelMove: function() {
1338 let boardDiv = document.querySelector(".game");
1339 if (boardDiv.style.visibility == "hidden")
1340 boardDiv.style.visibility = "visible";
1341 document.getElementById("modalConfirm").checked = false;
1342 this.$refs["basegame"].cancelLastMove();
1343 },
1344 // In corr games, callback to change page only after score is set:
1345 gameOver: function(score, scoreMsg, callback) {
1346 this.game.score = score;
1347 if (!scoreMsg) scoreMsg = getScoreMessage(score);
1348 this.game.scoreMsg = scoreMsg;
1349 this.$set(this.game, "scoreMsg", scoreMsg);
1350 const myIdx = this.game.players.findIndex(p => {
1351 return p.sid == this.st.user.sid || p.id == this.st.user.id;
1352 });
1353 if (myIdx >= 0) {
1354 // OK, I play in this game
1355 const scoreObj = {
1356 score: score,
1357 scoreMsg: scoreMsg
1358 };
1359 if (this.game.type == "live") {
1360 GameStorage.update(this.gameRef, scoreObj);
1361 if (!!callback) callback();
1362 }
1363 else this.updateCorrGame(scoreObj, callback);
1364 // Notify the score to main Hall. TODO: only one player (currently double send)
1365 this.send("result", { gid: this.game.id, score: score });
1366 // Also to MyGames page (TODO: doubled as well...)
1367 this.notifyMyGames(
1368 "score",
1369 {
1370 gid: this.gameRef,
1371 score: score
1372 }
1373 );
1374 }
1375 else if (!!callback) callback();
1376 }
1377 }
1378 };
1379 </script>
1380
1381 <style lang="sass" scoped>
1382 #infoDiv > .card
1383 padding: 15px 0
1384 max-width: 430px
1385
1386 .connected
1387 background-color: lightgreen
1388
1389 #participants
1390 margin-left: 5px
1391
1392 .anonymous
1393 color: grey
1394 font-style: italic
1395
1396 #playersInfo > p
1397 margin: 0
1398
1399 @media screen and (min-width: 768px)
1400 #actions
1401 width: 300px
1402 @media screen and (max-width: 767px)
1403 .game
1404 width: 100%
1405
1406 #actions
1407 display: inline-block
1408 margin: 0
1409
1410 button
1411 display: inline-block
1412 margin: 0
1413 display: inline-flex
1414 img
1415 height: 22px
1416 display: flex
1417 @media screen and (max-width: 767px)
1418 height: 18px
1419
1420 @media screen and (max-width: 767px)
1421 #aboveBoard
1422 text-align: center
1423 @media screen and (min-width: 768px)
1424 #aboveBoard
1425 margin-left: 30%
1426
1427 .variant-cadence
1428 padding-right: 10px
1429
1430 .variant-name
1431 font-weight: bold
1432 padding-right: 10px
1433
1434 span#nextGame
1435 background-color: #edda99
1436 cursor: pointer
1437 display: inline-block
1438 margin-right: 10px
1439
1440 span.name
1441 font-size: 1.5rem
1442 padding: 0 3px
1443
1444 span.time
1445 font-size: 2rem
1446 display: inline-block
1447 .time-left
1448 margin-left: 10px
1449 .time-right
1450 margin-left: 5px
1451 .time-separator
1452 margin-left: 5px
1453 position: relative
1454 top: -1px
1455
1456 span.yourturn
1457 color: #831B1B
1458 .time-separator
1459 animation: blink-animation 2s steps(3, start) infinite
1460 @keyframes blink-animation
1461 to
1462 visibility: hidden
1463
1464 .split-names
1465 display: inline-block
1466 margin: 0 15px
1467
1468 #chatWrap > .card
1469 padding-top: 20px
1470 max-width: 767px
1471 border: none
1472
1473 #confirmDiv > .card
1474 max-width: 767px
1475 max-height: 100%
1476
1477 .draw-sent, .draw-sent:hover
1478 background-color: lightyellow
1479
1480 .draw-received, .draw-received:hover
1481 background-color: lightgreen
1482
1483 .draw-threerep, .draw-threerep:hover
1484 background-color: #e4d1fc
1485
1486 .rematch-sent, .rematch-sent:hover
1487 background-color: lightyellow
1488
1489 .rematch-received, .rematch-received:hover
1490 background-color: lightgreen
1491
1492 .somethingnew
1493 background-color: #c5fefe
1494
1495 .diagram
1496 margin: 0 auto
1497 width: 100%
1498
1499 #buttonsConfirm
1500 margin: 0
1501 & > button > span
1502 width: 100%
1503 text-align: center
1504
1505 button.acceptBtn
1506 background-color: lightgreen
1507 button.refuseBtn
1508 background-color: red
1509 </style>