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