Some (experimental) fixes
[vchess.git] / client / src / views / Hall.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#modalAccept.modal(type="checkbox")
12 div#acceptDiv(role="dialog")
13 .card
14 p.text-center
15 span.variantName
16 | {{ curChallToAccept.vname }}
17 | {{ curChallToAccept.options.abridged || '' }}
18 span {{ curChallToAccept.cadence }}
19 span {{ st.tr["with"] + " " + curChallToAccept.from.name }}
20 p.text-center(v-if="!!curChallToAccept.color")
21 | {{ st.tr["Your color:"] + " " + invColor(curChallToAccept.color) }}
22 .diagram(
23 v-if="!!curChallToAccept.fen"
24 v-html="tchallDiag"
25 )
26 .button-group#buttonsTchall(:style="tchallButtonsMargin()")
27 button.acceptBtn(@click="decisionChallenge(true)")
28 span {{ st.tr["Accept challenge?"] }}
29 button.refuseBtn(@click="decisionChallenge(false)")
30 span {{ st.tr["Refuse"] }}
31 input#modalNewgame.modal(
32 type="checkbox"
33 @change="cadenceFocusIfOpened($event)"
34 )
35 div#newgameDiv(
36 role="dialog"
37 data-checkbox="modalNewgame"
38 )
39 .card
40 label#closeNewgame.modal-close(for="modalNewgame")
41 div(@keyup.enter="issueNewChallenge()")
42 fieldset
43 label(for="selectVariant") {{ st.tr["Variant"] }} *
44 select#selectVariant(
45 @change="loadNewchallVariant(trySetNewchallDiag)"
46 v-model="newchallenge.vid"
47 )
48 option(
49 v-for="v in st.variants"
50 :value="v.id"
51 :selected="newchallenge.vid==v.id"
52 )
53 | {{ v.display }}
54 // Variant-specific options (often at least randomness)
55 fieldset(v-if="!!newchallenge.V && newchallenge.V.Options")
56 div(v-for="select of newchallenge.V.Options.select || []")
57 label(:for="select.variable + '_opt'") {{ st.tr[select.label] }} *
58 select(:id="select.variable + '_opt'")
59 option(
60 v-for="o of select.options"
61 :value="o.value"
62 :selected="o.value == select.defaut"
63 )
64 | {{ st.tr[o.label] }}
65 div(v-for="check of newchallenge.V.Options.check || []")
66 label(:for="check.variable + '_opt'") {{ st.tr[check.label] }} *
67 input(
68 :id="check.variable + '_opt'"
69 type="checkbox"
70 :checked="check.defaut")
71 fieldset
72 label(for="cadence") {{ st.tr["Cadence"] }} *
73 div#predefinedCadences
74 button(type="button") 15+5
75 button(type="button") 45+30
76 button(type="button") 3d
77 button(type="button") 7d
78 input#cadence(
79 type="text"
80 v-model="newchallenge.cadence"
81 placeholder="5+0, 1h+30s, 5d ..."
82 )
83 fieldset
84 label(for="memorizeChall") {{ st.tr["Memorize"] }}
85 input#memorizeChall(
86 type="checkbox"
87 v-model="newchallenge.memorize"
88 )
89 fieldset(v-if="st.user.id > 0")
90 label(for="selectPlayers") {{ st.tr["Play with"] }}
91 select#selectPlayersInList(
92 v-model="newchallenge.to"
93 @change="changeChallTarget()"
94 )
95 option(value="")
96 option(
97 v-for="p in Object.values(people)"
98 v-if="!!p.name"
99 :value="p.name"
100 )
101 | {{ p.name }}
102 input#selectPlayers(
103 type="text"
104 v-model="newchallenge.to"
105 )
106 fieldset(v-show="st.user.id > 0 && newchallenge.to.length > 0")
107 label(for="selectColor") {{ st.tr["Color"] }}
108 select#selectColor(v-model="newchallenge.color")
109 option(value='')
110 option(value='w') {{ st.tr["White"] }}
111 option(value='b') {{ st.tr["Black"] }}
112 br
113 input#inputFen(
114 placeholder="FEN"
115 @input="trySetNewchallDiag()"
116 type="text"
117 v-model="newchallenge.fen"
118 )
119 .diagram(v-html="newchallenge.diag")
120 button(@click="issueNewChallenge()") {{ st.tr["Send challenge"] }}
121 input#modalPeople.modal(
122 type="checkbox"
123 @click="toggleSocialColor()"
124 )
125 div#peopleWrap(
126 role="dialog"
127 data-checkbox="modalPeople"
128 )
129 .card
130 label.modal-close(for="modalPeople")
131 #people
132 #players
133 p(
134 v-for="sid in Object.keys(people)"
135 v-if="!!people[sid].name"
136 )
137 UserBio.user-bio(:uid="people[sid].id" :uname="people[sid].name")
138 button.player-action(
139 v-if="isGamer(sid)"
140 @click="watchGame(sid)"
141 )
142 | {{ st.tr["Observe"] }}
143 button.player-action(
144 v-else-if="st.user.sid != sid"
145 :class="{focused: isFocusedOnHall(sid)}"
146 @click="challenge(sid)"
147 )
148 | {{ st.tr["Challenge"] }}
149 p.anonymous @nonymous ({{ anonymousCount() }})
150 #chat
151 Chat(
152 ref="chatcomp"
153 @mychat="processChat"
154 :pastChats="[]"
155 )
156 .clearer
157 .row
158 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
159 .button-group
160 button#peopleBtn(onClick="window.doClick('modalPeople')")
161 | {{ st.tr["Who's there?"] }}
162 button(@click="showNewchallengeForm()")
163 | {{ st.tr["New game"] }}
164 .row(v-if="presetChalls.length > 0")
165 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
166 h4.text-center {{ st.tr["Preset challenges"] }}
167 table
168 thead
169 tr
170 th {{ st.tr["Variant"] }}
171 th {{ st.tr["Cadence"] }}
172 th {{ st.tr["Options"] }}
173 th
174 tbody
175 tr(
176 v-for="pc in presetChalls"
177 @click="newChallFromPreset(pc)"
178 )
179 td {{ pc.vname }}
180 td {{ pc.cadence }}
181 td(:class="getRandomnessClass(pc)") {{ pc.options.abridged || '' }}
182 td.remove-preset(@click="removePresetChall($event, pc)")
183 img(src="/images/icons/delete.svg")
184 .row
185 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
186 div#div2
187 .button-group
188 button.tabbtn#btnClive(@click="setDisplay('c','live',$event)")
189 | {{ st.tr["Live challenges"] }}
190 button.tabbtn#btnCcorr(@click="setDisplay('c','corr',$event)")
191 | {{ st.tr["Correspondence challenges"] }}
192 ChallengeList(
193 v-show="cdisplay=='live'"
194 :challenges="filterChallenges('live')"
195 @click-challenge="clickChallenge"
196 )
197 ChallengeList(
198 v-show="cdisplay=='corr'"
199 :challenges="filterChallenges('corr')"
200 @click-challenge="clickChallenge"
201 )
202 div#div3
203 .button-group
204 button.tabbtn#btnGlive(@click="setDisplay('g','live',$event)")
205 | {{ st.tr["Live games"] }}
206 button.tabbtn#btnGcorr(@click="setDisplay('g','corr',$event)")
207 | {{ st.tr["Correspondence games"] }}
208 GameList(
209 v-show="gdisplay=='live'"
210 :games="filterGames('live')"
211 :show-both="true"
212 @show-game="showGame"
213 )
214 div(v-show="gdisplay=='corr'")
215 GameList(
216 :games="filterGames('corr')"
217 :show-both="true"
218 @show-game="showGame"
219 )
220 button#loadMoreBtn(
221 v-if="hasMore"
222 @click="loadMoreCorr()"
223 )
224 | {{ st.tr["Load more"] }}
225 </template>
226
227 <script>
228 import { store } from "@/store";
229 import { checkChallenge } from "@/data/challengeCheck";
230 import { notify } from "@/utils/notifications";
231 import { ArrayFun } from "@/utils/array";
232 import { ajax } from "@/utils/ajax";
233 import params from "@/parameters";
234 import { getRandString, shuffle, randInt } from "@/utils/alea";
235 import { getDiagram } from "@/utils/printDiagram";
236 import Chat from "@/components/Chat.vue";
237 import UserBio from "@/components/UserBio.vue";
238 import GameList from "@/components/GameList.vue";
239 import ChallengeList from "@/components/ChallengeList.vue";
240 import { GameStorage } from "@/utils/gameStorage";
241 import { processModalClick } from "@/utils/modalClick";
242 export default {
243 name: "my-hall",
244 components: {
245 Chat,
246 UserBio,
247 GameList,
248 ChallengeList
249 },
250 data: function() {
251 return {
252 st: store.state,
253 cdisplay: "live", //or corr
254 gdisplay: "live",
255 // timestamp of last showed (oldest) corr game:
256 cursor: Number.MAX_SAFE_INTEGER,
257 // hasMore == TRUE: a priori there could be more games to load
258 hasMore: true,
259 games: [],
260 challenges: [],
261 people: {},
262 infoMessage: "",
263 newchallenge: {
264 fen: "",
265 vid: parseInt(localStorage.getItem("vid"), 10) || 0,
266 to: "", //name of challenged player (if any)
267 color: '',
268 cadence: localStorage.getItem("cadence") || "",
269 options: {},
270 // VariantRules object, stored to not interfere with
271 // diagrams of targeted challenges:
272 V: null,
273 vname: "",
274 diag: "", //visualizing FEN
275 memorize: false //put settings in localStorage
276 },
277 focus: true,
278 tchallDiag: "",
279 curChallToAccept: { from: {}, options: {} },
280 presetChalls: JSON.parse(localStorage.getItem("presetChalls") || "[]"),
281 conn: null,
282 connexionString: "",
283 socketCloseListener: 0,
284 // Related to (killing of) self multi-connects:
285 newConnect: {}
286 };
287 },
288 watch: {
289 // st.variants changes only once, at loading from [] to [...]
290 "st.variants": function() {
291 // Set potential challenges and games variant names:
292 this.challenges.concat(this.games).forEach(o => {
293 if (!o.vname) this.setVname(o);
294 });
295 if (!this.newchallenge.V && this.newchallenge.vid > 0)
296 this.loadNewchallVariant();
297 },
298 $route: function(to, from) {
299 if (to.path != "/") this.cleanBeforeDestroy();
300 }
301 },
302 created: function() {
303 document.addEventListener('visibilitychange', this.visibilityChange);
304 window.addEventListener('focus', this.onFocus);
305 window.addEventListener('blur', this.onBlur);
306 window.addEventListener("beforeunload", this.cleanBeforeDestroy);
307 if (this.st.variants.length > 0 && this.newchallenge.vid > 0)
308 this.loadNewchallVariant();
309 const my = this.st.user;
310 const tmpId = getRandString();
311 this.$set(
312 this.people,
313 my.sid,
314 {
315 id: my.id,
316 name: my.name,
317 tmpIds: {
318 tmpId: { page: "/", focus: true }
319 }
320 }
321 );
322 const connectAndPoll = () => {
323 this.send("connect");
324 this.send("pollclientsandgamers");
325 if (!!this.$route.query["challenge"]) {
326 // Automatic challenge sending, for tournaments
327 this.loadNewchallVariant(
328 () => {
329 Object.assign(
330 this.newchallenge,
331 {
332 fen: "",
333 vid:
334 this.st.variants
335 .find(v => v.name == this.$route.query["variant"])
336 .id,
337 to: this.$route.query["challenge"],
338 color: this.$route.query["color"] || '',
339 cadence: this.$route.query["cadence"],
340 options: {},
341 memorize: false
342 }
343 );
344 window.doClick("modalNewgame");
345 },
346 this.$route.query["variant"]
347 );
348 }
349 };
350 // Initialize connection
351 this.connexionString =
352 params.socketUrl +
353 "/?sid=" + this.st.user.sid +
354 "&id=" + this.st.user.id +
355 "&tmpId=" + tmpId +
356 "&page=" +
357 // Hall: path is "/" (TODO: could be hard-coded as well)
358 encodeURIComponent(this.$route.path);
359 this.conn = new WebSocket(this.connexionString);
360 this.conn.onopen = connectAndPoll;
361 this.conn.addEventListener("message", this.socketMessageListener);
362 this.socketCloseListener = setInterval(
363 () => {
364 if (this.conn.readyState == 3) {
365 this.conn.removeEventListener("message", this.socketMessageListener);
366 this.conn = new WebSocket(this.connexionString);
367 this.conn.addEventListener("message", this.socketMessageListener);
368 }
369 },
370 1000
371 );
372 },
373 mounted: function() {
374 document.getElementById("peopleWrap")
375 .addEventListener("click", (e) => {
376 processModalClick(e, () => {
377 this.toggleSocialColor("close")
378 });
379 });
380 ["infoDiv", "newgameDiv"].forEach(eltName => {
381 document.getElementById(eltName)
382 .addEventListener("click", processModalClick);
383 });
384 document.querySelectorAll("#predefinedCadences > button").forEach(b => {
385 b.addEventListener("click", () => {
386 this.newchallenge.cadence = b.innerHTML;
387 });
388 });
389 const dispCorr = this.$route.query["disp"];
390 const showCtype =
391 dispCorr || localStorage.getItem("type-challenges") || "live";
392 const showGtype =
393 dispCorr || localStorage.getItem("type-games") || "live";
394 this.setDisplay('c', showCtype);
395 this.setDisplay('g', showGtype);
396 // Ask server for current corr games (all but mines)
397 this.loadMoreCorr();
398 // Also ask for corr challenges (open + sent by/to me)
399 // List them all, because they are not supposed to be that many (TODO?)
400 ajax(
401 "/challenges",
402 "GET",
403 {
404 data: { uid: this.st.user.id },
405 success: (response) => {
406 if (
407 response.challenges.length > 0 &&
408 this.challenges.length == 0 &&
409 this.cdisplay == "live"
410 ) {
411 document
412 .getElementById("btnCcorr")
413 .classList.add("somethingnew");
414 }
415 // Gather all senders names, and then retrieve full identity:
416 // (TODO [perf]: some might be online...)
417 let names = {};
418 response.challenges.forEach(c => {
419 if (c.uid != this.st.user.id) names[c.uid] = "";
420 else if (!!c.target && c.target != this.st.user.id)
421 names[c.target] = "";
422 });
423 const addChallenges = () => {
424 names[this.st.user.id] = this.st.user.name; //in case of
425 this.challenges = this.challenges.concat(
426 response.challenges.map(c => {
427 const from = { name: names[c.uid], id: c.uid }; //or just name
428 const type = this.classifyObject(c);
429 this.setVname(c);
430 return Object.assign(
431 {},
432 c,
433 {
434 type: type,
435 from: from,
436 to: c.target ? names[c.target] : "",
437 options: JSON.parse(c.options)
438 }
439 );
440 })
441 );
442 };
443 if (Object.keys(names).length > 0) {
444 ajax(
445 "/users",
446 "GET",
447 {
448 data: { ids: Object.keys(names).join(",") },
449 success: (response2) => {
450 response2.users.forEach(u => {
451 names[u.id] = u.name;
452 });
453 addChallenges();
454 }
455 }
456 );
457 }
458 else addChallenges();
459 }
460 }
461 );
462 },
463 beforeDestroy: function() {
464 this.cleanBeforeDestroy();
465 },
466 methods: {
467 cleanBeforeDestroy: function() {
468 clearInterval(this.socketCloseListener);
469 document.removeEventListener('visibilitychange', this.visibilityChange);
470 window.removeEventListener('focus', this.onFocus);
471 window.removeEventListener('blur', this.onBlur);
472 window.removeEventListener("beforeunload", this.cleanBeforeDestroy);
473 this.conn.removeEventListener("message", this.socketMessageListener);
474 this.send("disconnect");
475 this.conn = null;
476 },
477 getRandomnessClass: function(pc) {
478 const opts = pc.options;
479 if (opts.randomness === undefined && opts.random === undefined)
480 return {};
481 if (opts.randomness !== undefined)
482 return { ["random-" + opts.randomness]: true };
483 return { ["random-" + (opts.random ? 2 : 0)]: true };
484 },
485 anonymousCount: function() {
486 let count = 0;
487 Object.values(this.people).forEach(p => {
488 // Do not cound people who did not send their identity yet:
489 count += (!p.name && p.id === 0) ? 1 : 0;
490 });
491 return count;
492 },
493 visibilityChange: function() {
494 // TODO: Use document.hidden? https://webplatform.news/issues/2019-03-27
495 this.focus = (document.visibilityState == "visible");
496 this.send(this.focus ? "getfocus" : "losefocus");
497 },
498 onFocus: function() {
499 this.focus = true;
500 this.send("getfocus");
501 },
502 onBlur: function() {
503 this.focus = false;
504 this.send("losefocus");
505 },
506 invColor: function(c) {
507 if (c == 'w') return this.st.tr["Black"];
508 return this.tr.tr["White"];
509 },
510 partialResetNewchallenge: function() {
511 // Reset potential target and custom FEN:
512 this.newchallenge.to = "";
513 this.newchallenge.color = '';
514 this.newchallenge.fen = "";
515 this.newchallenge.diag = "";
516 this.newchallenge.memorize = false;
517 },
518 showNewchallengeForm: function() {
519 this.partialResetNewchallenge();
520 window.doClick("modalNewgame");
521 },
522 sameOptions: function(opt1, opt2) {
523 const keys1 = Object.keys(opt1),
524 keys2 = Object.keys(opt2);
525 if (keys1.length != keys2.length) return false;
526 for (const key1 of keys1) {
527 if (!keys2.includes(key1)) return false;
528 if (opt1[key1] != opt2[key1]) return false;
529 }
530 return true;
531 },
532 addPresetChall: function(chall) {
533 // Add only if not already existing:
534 if (this.presetChalls.some(c =>
535 c.vid == chall.vid &&
536 c.cadence == chall.cadence &&
537 this.sameOptions(c.options, chall.options)
538 )) {
539 return;
540 }
541 const L = this.presetChalls.length;
542 this.presetChalls.push({
543 index: L,
544 vid: chall.vid,
545 vname: chall.vname, //redundant, but easier
546 cadence: chall.cadence,
547 options: chall.options
548 });
549 localStorage.setItem("presetChalls", JSON.stringify(this.presetChalls));
550 },
551 removePresetChall: function(e, pchall) {
552 e.stopPropagation();
553 const pchallIdx =
554 this.presetChalls.findIndex(pc => pc.index == pchall.index);
555 this.presetChalls.splice(pchallIdx, 1);
556 localStorage.setItem("presetChalls", JSON.stringify(this.presetChalls));
557 },
558 tchallButtonsMargin: function() {
559 if (!!this.curChallToAccept.fen) return { "margin-top": "10px" };
560 return {};
561 },
562 changeChallTarget: function() {
563 if (!this.newchallenge.to) {
564 // Reset potential FEN + diagram
565 this.newchallenge.fen = "";
566 this.newchallenge.color = '';
567 this.newchallenge.diag = "";
568 }
569 },
570 cadenceFocusIfOpened: function() {
571 if (event.target.checked)
572 document.getElementById("cadence").focus();
573 },
574 send: function(code, obj) {
575 if (!!this.conn && this.conn.readyState == 1) {
576 this.conn.send(JSON.stringify(Object.assign({ code: code }, obj)));
577 }
578 },
579 setVname: function(obj) {
580 const variant = this.st.variants.find(v => v.id == obj.vid);
581 // this.st.variants might be uninitialized (variant == null)
582 if (!!variant) {
583 obj.vname = variant.name;
584 obj.vdisp = variant.display;
585 }
586 // NOTE: Next line is used in loadNewchallVariant
587 return (!variant ? "" : variant.name);
588 },
589 filterChallenges: function(type) {
590 return this.challenges.filter(c => c.type == type);
591 },
592 filterGames: function(type) {
593 return this.games.filter(g => g.type == type);
594 },
595 // o: challenge or game
596 classifyObject: function(o) {
597 // No imported games here
598 return (o.cadence.indexOf("d") >= 0 ? "corr" : "live");
599 },
600 setDisplay: function(letter, type, e) {
601 this[letter + "display"] = type;
602 localStorage.setItem(
603 "type-" + (letter == "c" ? "challenges" : "games"),
604 type
605 );
606 let elt = e
607 ? e.target
608 : document.getElementById("btn" + letter.toUpperCase() + type);
609 elt.classList.add("active");
610 elt.classList.remove("somethingnew"); //in case of
611 if (!!elt.previousElementSibling)
612 elt.previousElementSibling.classList.remove("active");
613 else elt.nextElementSibling.classList.remove("active");
614 },
615 isGamer: function(sid) {
616 return Object.values(this.people[sid].tmpIds)
617 .some(v => v.focus && v.page.indexOf("/game/") >= 0);
618 },
619 isFocusedOnHall: function(sid) {
620 return (
621 // This is meant to challenge people, thus the next 2 conditions:
622 this.st.user.id > 0 &&
623 sid != this.st.user.sid &&
624 Object.values(this.people[sid].tmpIds)
625 .some(v => v.focus && v.page == "/")
626 );
627 },
628 challenge: function(sid) {
629 this.partialResetNewchallenge();
630 // Available, in Hall
631 this.newchallenge.to = this.people[sid].name;
632 // TODO: also store target sid to not re-search for it
633 document.getElementById("modalPeople").checked = false;
634 window.doClick("modalNewgame");
635 },
636 watchGame: function(sid) {
637 // In some game, maybe playing maybe not: show a random one
638 let gids = [];
639 Object.values(this.people[sid].tmpIds).forEach(v => {
640 if (v.focus) {
641 const matchGid = v.page.match(/[a-zA-Z0-9]+$/);
642 if (!!matchGid) gids.push(matchGid[0]);
643 }
644 });
645 const gid = gids[Math.floor(Math.random() * gids.length)];
646 window.open("/#/game/" + gid, "_blank");
647 },
648 showGame: function(g) {
649 // NOTE: we are an observer, since only games I don't play are shown here
650 // ==> Moves sent by connected remote player(s) if live game
651 window.open("/#/game/" + g.id, "_blank");
652 },
653 toggleSocialColor: function(action) {
654 if (!action && document.getElementById("modalPeople").checked)
655 document.getElementById("inputChat").focus();
656 else
657 document.getElementById("peopleBtn").classList.remove("somethingnew");
658 },
659 processChat: function(chat) {
660 this.send("newchat", { data: chat });
661 },
662 getOppsid: function(c) {
663 let oppsid = c.from.sid; //may not be defined if corr + offline opp
664 if (!oppsid) {
665 oppsid = Object.keys(this.people).find(
666 sid => this.people[sid].id == c.from.id
667 );
668 }
669 return oppsid;
670 },
671 // Messaging center:
672 socketMessageListener: function(msg) {
673 if (!this.conn) return;
674 const data = JSON.parse(msg.data);
675 switch (data.code) {
676 case "pollclientsandgamers": {
677 // TODO: shuffling and random filtering on server,
678 // if the room is really crowded.
679 Object.keys(data.sockIds).forEach(sid => {
680 if (sid != this.st.user.sid) {
681 // Pick a target tmpId (+page) at random:
682 const pt = Object.values(data.sockIds[sid]);
683 const randPage = pt[randInt(pt.length)].page;
684 this.send(
685 "askidentity",
686 {
687 target: sid,
688 page: randPage
689 }
690 );
691 }
692 if (!this.people[sid])
693 // Do not set name or id: identity unknown yet
694 this.people[sid] = { tmpIds: data.sockIds[sid] };
695 else
696 Object.assign(this.people[sid].tmpIds, data.sockIds[sid]);
697 if (Object.values(data.sockIds[sid]).some(v => v.page == "/"))
698 // Peer is in Hall
699 this.send("askchallenges", { target: sid });
700 Object.values(data.sockIds[sid]).forEach(v => {
701 if (
702 v.page.indexOf("/game/") >= 0 &&
703 !v.page.match(/\/[0-9]+$/)
704 ) {
705 // Peer is in Game: ask only if live game
706 this.send("askgame", { target: sid, page: v.page });
707 }
708 });
709 });
710 break;
711 }
712 case "connect":
713 case "gconnect": {
714 const page = data.page || "/";
715 if (data.code == "connect") {
716 // Ask challenges only on first connexion:
717 if (!this.people[data.from[0]])
718 this.send("askchallenges", { target: data.from[0] });
719 }
720 // Ask game only if live:
721 else if (!page.match(/\/[0-9]+$/))
722 this.send("askgame", { target: data.from[0], page: page });
723 if (!this.people[data.from[0]]) {
724 this.$set(
725 this.people,
726 data.from[0],
727 {
728 tmpIds: {
729 [data.from[1]]: { page: page, focus: true }
730 }
731 }
732 );
733 // For self multi-connects tests:
734 this.newConnect[data.from[0]] = true;
735 this.send("askidentity", { target: data.from[0], page: page });
736 }
737 else {
738 this.people[data.from[0]].tmpIds[data.from[1]] =
739 { page: page, focus: true };
740 this.$forceUpdate(); //TODO: shouldn't be required
741 }
742 break;
743 }
744 case "disconnect":
745 case "gdisconnect": {
746 // If the user reloads the page twice very quickly
747 // (experienced with Firefox), the first reload won't have time to
748 // connect but will trigger a "close" event anyway.
749 // ==> Next check is required.
750 if (!this.people[data.from[0]]) return;
751 delete this.people[data.from[0]].tmpIds[data.from[1]];
752 if (Object.keys(this.people[data.from[0]].tmpIds).length == 0)
753 this.$delete(this.people, data.from[0]);
754 else this.$forceUpdate(); //TODO: shouldn't be required
755 if (data.code == "disconnect") {
756 // Remove the live challenges sent by this player, if
757 // he isn't connected on another tab:
758 if (
759 !this.people[data.from[0]] ||
760 Object.values(this.people[data.from[0]].tmpIds)
761 .every(v => v.page != "/")
762 ) {
763 ArrayFun.remove(
764 this.challenges,
765 c => c.type == "live" && c.from.sid == data.from[0],
766 "all"
767 );
768 }
769 }
770 else {
771 // Remove the matching live game if now unreachable
772 const gid = data.page.match(/[a-zA-Z0-9]+$/)[0];
773 // Corr games are always reachable:
774 if (!gid.match(/^[0-9]+$/)) {
775 // Live games are reachable if someone is on the game page
776 if (Object.values(this.people).every(p =>
777 Object.values(p.tmpIds).every(v => v.page != data.page))
778 ) {
779 ArrayFun.remove(this.games, g => g.id == gid);
780 }
781 }
782 }
783 break;
784 }
785 case "getfocus": {
786 let player = this.people[data.from[0]];
787 // If user reload a page, focus may arrive earlier than connect
788 if (!!player) {
789 player.tmpIds[data.from[1]].focus = true;
790 this.$forceUpdate(); //TODO: shouldn't be required
791 }
792 break;
793 }
794 case "losefocus": {
795 let player = this.people[data.from[0]];
796 if (!!player) {
797 player.tmpIds[data.from[1]].focus = false;
798 this.$forceUpdate(); //TODO: shouldn't be required
799 }
800 break;
801 }
802 case "askidentity": {
803 // Request for identification
804 const me = {
805 // Decompose to avoid revealing email
806 name: this.st.user.name,
807 sid: this.st.user.sid,
808 id: this.st.user.id
809 };
810 this.send("identity", { data: me, target: data.from });
811 break;
812 }
813 case "identity": {
814 const user = data.data;
815 let player = this.people[user.sid];
816 // player.tmpIds is already set
817 player.id = user.id;
818 player.name = user.name;
819 // TODO: this.$set(people, ...) fails. So forceUpdate.
820 // But this shouldn't be like that!
821 this.$forceUpdate();
822 // If I multi-connect, kill current connexion if no mark (I'm older)
823 if (this.newConnect[user.sid]) {
824 delete this.newConnect[user.sid];
825 if (
826 user.id > 0 &&
827 user.id == this.st.user.id &&
828 user.sid != this.st.user.sid
829 ) {
830 // I logged in elsewhere:
831 this.cleanBeforeDestroy();
832 alert(this.st.tr["New connexion detected: tab now offline"]);
833 }
834 }
835 break;
836 }
837 case "askchallenges": {
838 // Send my current live challenges (if any)
839 const myChallenges = this.challenges
840 .filter(c =>
841 c.from.sid == this.st.user.sid && c.type == "live"
842 )
843 .map(c => {
844 // NOTE: in principle, should only send targeted challenge to the
845 // target. But we may not know yet the identity of the target
846 // (just name), so can't decide if data.from is the target.
847 return {
848 id: c.id,
849 from: this.st.user.sid,
850 to: c.to,
851 options: JSON.stringify(c.options),
852 fen: c.fen,
853 vid: c.vid,
854 cadence: c.cadence,
855 added: c.added
856 };
857 });
858 if (myChallenges.length > 0)
859 this.send("challenges", { data: myChallenges, target: data.from });
860 break;
861 }
862 case "challenges": //after "askchallenges"
863 data.data.forEach(this.addChallenge);
864 break;
865 case "newchallenge":
866 this.addChallenge(data.data);
867 break;
868 case "refusechallenge": {
869 const cid = data.data;
870 ArrayFun.remove(this.challenges, c => c.id == cid);
871 alert(this.st.tr["Challenge declined"]);
872 break;
873 }
874 case "deletechallenge_s": {
875 // NOTE: the challenge(s) may be already removed
876 const cref = data.data;
877 if (!!cref.cid)
878 ArrayFun.remove(this.challenges, c => c.id == cref.cid);
879 else if (!!cref.sids) {
880 cref.sids.forEach(s => {
881 ArrayFun.remove(
882 this.challenges,
883 c => c.type == "live" && c.from.sid == s,
884 "all"
885 );
886 });
887 }
888 break;
889 }
890 case "game": // Individual request
891 case "newgame": {
892 const game = data.data;
893 // Ignore games where I play (will go in MyGames page),
894 // and also games that I already received.
895 if (
896 this.games.findIndex(g => g.id == game.id) == -1 &&
897 game.players.every(p => {
898 return (
899 p.sid != this.st.user.sid &&
900 (p.id == 0 || p.id != this.st.user.id)
901 );
902 })
903 ) {
904 let newGame = game;
905 newGame.type = this.classifyObject(game);
906 this.setVname(game);
907 if (!game.score)
908 // New game from Hall
909 newGame.score = "*";
910 // TODO: remove patch on next line (options || "{}")
911 newGame.options = JSON.parse(newGame.options || "{}");
912 this.games.push(newGame);
913 if (
914 newGame.score == '*' &&
915 (newGame.type == "live" && this.gdisplay == "corr") ||
916 (newGame.type == "corr" && this.gdisplay == "live")
917 ) {
918 document
919 .getElementById("btnG" + newGame.type)
920 .classList.add("somethingnew");
921 }
922 }
923 break;
924 }
925 case "result": {
926 let g = this.games.find(g => g.id == data.gid);
927 if (!!g) g.score = data.score;
928 break;
929 }
930 case "startgame": {
931 // New game just started, I'm involved
932 let gameInfo = data.data;
933 if (this.classifyObject(gameInfo) == "live") {
934 // TODO: remove patch on next line (+ const gameInfo)
935 if (!gameInfo.options) gameInfo.options = "{}";
936 this.startNewGame(gameInfo);
937 }
938 else {
939 this.infoMessage =
940 this.st.tr["New correspondence game:"] + " " +
941 "<a href='#/game/" + gameInfo.id + "'>" +
942 "#/game/" + gameInfo.id + "</a>";
943 document.getElementById("modalInfo").checked = true;
944 }
945 break;
946 }
947 case "newchat":
948 this.$refs["chatcomp"].newChat(data.data);
949 if (!document.getElementById("modalPeople").checked)
950 document.getElementById("peopleBtn").classList.add("somethingnew");
951 break;
952 }
953 },
954 loadMoreCorr: function() {
955 ajax(
956 "/observedgames",
957 "GET",
958 {
959 data: {
960 uid: this.st.user.id,
961 cursor: this.cursor
962 },
963 success: (res) => {
964 const L = res.games.length;
965 if (L > 0) {
966 if (
967 this.cursor == Number.MAX_SAFE_INTEGER &&
968 this.games.length == 0 &&
969 this.gdisplay == "live" &&
970 res.games.some(g => g.score == '*')
971 ) {
972 // First loading: show indicators
973 document
974 .getElementById("btnGcorr")
975 .classList.add("somethingnew");
976 }
977 this.cursor = res.games[L - 1].created;
978 let moreGames = res.games.map(g => {
979 this.setVname(g);
980 g.type = "corr";
981 g.options = JSON.parse(g.options);
982 return g;
983 });
984 this.games = this.games.concat(moreGames);
985 }
986 else this.hasMore = false;
987 }
988 }
989 );
990 },
991 // Challenge lifecycle:
992 addChallenge: function(chall) {
993 // NOTE about next condition: see "askchallenges" case.
994 if (
995 !chall.to ||
996 (this.people[chall.from].id > 0 &&
997 (chall.from == this.st.user.sid || chall.to == this.st.user.name))
998 ) {
999 let newChall = Object.assign({}, chall);
1000 newChall.type = this.classifyObject(chall);
1001 // TODO: remove patch on next line (options || "{}")
1002 newChall.options = JSON.parse(chall.options || "{}");
1003 newChall.added = Date.now();
1004 let fromValues = Object.assign({}, this.people[chall.from]);
1005 delete fromValues["pages"]; //irrelevant in this context
1006 newChall.from = Object.assign({ sid: chall.from }, fromValues);
1007 this.setVname(newChall);
1008 this.challenges.push(newChall);
1009 if (
1010 (newChall.type == "live" && this.cdisplay == "corr") ||
1011 (newChall.type == "corr" && this.cdisplay == "live")
1012 ) {
1013 document
1014 .getElementById("btnC" + newChall.type)
1015 .classList.add("somethingnew");
1016 }
1017 if (!!chall.to && chall.to == this.st.user.name) {
1018 notify(
1019 "New challenge",
1020 // fromValues.name should exist since the player is online, but
1021 // let's consider there is some chance that the challenge arrives
1022 // right after we connected and before receiving the poll result:
1023 { body: "from " + (fromValues.name || "@nonymous") }
1024 );
1025 }
1026 }
1027 },
1028 loadNewchallVariant: async function(cb, vname) {
1029 vname = vname || this.setVname(this.newchallenge);
1030 await import("@/variants/" + vname + ".js")
1031 .then((vModule) => {
1032 window.V = vModule[vname + "Rules"];
1033 this.newchallenge.V = window.V;
1034 if (!!cb) cb();
1035 });
1036 },
1037 trySetNewchallDiag: function() {
1038 if (!this.newchallenge.fen) {
1039 this.newchallenge.diag = "";
1040 return;
1041 }
1042 // If vid > 0 then the variant is loaded (function above):
1043 window.V = this.newchallenge.V;
1044 if (
1045 this.newchallenge.vid > 0 &&
1046 !!this.newchallenge.fen &&
1047 V.IsGoodFen(this.newchallenge.fen)
1048 ) {
1049 const parsedFen = V.ParseFen(this.newchallenge.fen);
1050 this.newchallenge.diag = getDiagram({
1051 position: parsedFen.position
1052 //,orientation: parsedFen.turn
1053 });
1054 }
1055 else this.newchallenge.diag = "";
1056 },
1057 newChallFromPreset(pchall) {
1058 this.partialResetNewchallenge();
1059 this.newchallenge.vid = pchall.vid;
1060 this.newchallenge.cadence = pchall.cadence;
1061 this.newchallenge.options = pchall.options;
1062 this.loadNewchallVariant(this.issueNewChallenge);
1063 },
1064 issueNewChallenge: async function() {
1065 if (!!(this.newchallenge.cadence.match(/^[0-9]+$/)))
1066 this.newchallenge.cadence += "+0"; //assume minutes, no increment
1067 const ctype = this.classifyObject(this.newchallenge);
1068 // TODO: cadence still unchecked so ctype could be wrong...
1069 let error = "";
1070 if (!this.newchallenge.vid)
1071 error = this.st.tr["Please select a variant"];
1072 else if (ctype == "corr" && this.st.user.id <= 0)
1073 error = this.st.tr["Please log in to play correspondence games"];
1074 else if (!this.newchallenge.to && !!this.newchallenge.color)
1075 error = this.st.tr["Color option only for targeted challenge"];
1076 else if (!!this.newchallenge.to) {
1077 if (this.newchallenge.to == this.st.user.name)
1078 error = this.st.tr["Self-challenge is forbidden"];
1079 else if (
1080 ctype == "live" &&
1081 Object.values(this.people).every(p => p.name != this.newchallenge.to)
1082 ) {
1083 error = this.newchallenge.to + " " + this.st.tr["is not online"];
1084 }
1085 if (
1086 !!this.newchallenge.color &&
1087 !['w', 'b'].includes(this.newchallenge.color)
1088 ) {
1089 error = this.st.tr["Wrong color"];
1090 }
1091 }
1092 if (error) {
1093 alert(error);
1094 return;
1095 }
1096 window.V = this.newchallenge.V;
1097 let chall = Object.assign({ options: {} }, this.newchallenge);
1098 // Get/set options variables (if any) / TODO: v-model?!
1099 for (const check of this.newchallenge.V.Options.check || []) {
1100 const elt = document.getElementById(check.variable + "_opt");
1101 chall.options[check.variable] = elt.checked;
1102 }
1103 for (const select of this.newchallenge.V.Options.select || []) {
1104 const elt = document.getElementById(select.variable + "_opt");
1105 const tryIntVal = parseInt(elt.value, 10);
1106 chall.options[select.variable] =
1107 (isNaN(tryIntVal) ? elt.value : tryIntVal);
1108 }
1109 error = checkChallenge(chall);
1110 if (error) {
1111 alert(this.st.tr[error]);
1112 return;
1113 }
1114 chall.options.abridged = V.AbbreviateOptions(chall.options);
1115 // Add only if not already issued (not counting FEN):
1116 // NOTE: "from" information is not required here
1117 if (this.challenges.some(c =>
1118 (
1119 c.from.sid == this.st.user.sid ||
1120 (c.from.id > 0 && c.from.id == this.st.user.id)
1121 )
1122 &&
1123 (
1124 (!c.to && !chall.to) ||
1125 c.to == chall.to
1126 )
1127 &&
1128 c.vid == chall.vid &&
1129 c.cadence == chall.cadence &&
1130 this.sameOptions(c.options, chall.options)
1131 )) {
1132 alert(this.st.tr["Challenge already exists"]);
1133 return;
1134 }
1135 if (this.newchallenge.memorize) this.addPresetChall(this.newchallenge);
1136 delete chall["V"];
1137 delete chall["diag"];
1138 const finishAddChallenge = cid => {
1139 chall.id = cid || "c" + getRandString();
1140 const MAX_ALLOWED_CHALLS = 3;
1141 // Remove oldest challenge if 3 found: only 3 at a time of a given type
1142 let countMyChalls = 0;
1143 let challToDelIdx = 0;
1144 let oldestAdded = Number.MAX_SAFE_INTEGER;
1145 for (let i=0; i<this.challenges.length; i++) {
1146 const c = this.challenges[i];
1147 if (
1148 c.type == ctype &&
1149 (
1150 c.from.sid == this.st.user.sid ||
1151 (c.from.id > 0 && c.from.id == this.st.user.id)
1152 )
1153 ) {
1154 countMyChalls++;
1155 if (c.added < oldestAdded) {
1156 challToDelIdx = i;
1157 oldestAdded = c.added;
1158 }
1159 }
1160 }
1161 if (countMyChalls >= MAX_ALLOWED_CHALLS) {
1162 this.send(
1163 "deletechallenge_s",
1164 { data: { cid: this.challenges[challToDelIdx].id } }
1165 );
1166 if (ctype == "corr") {
1167 ajax(
1168 "/challenges",
1169 "DELETE",
1170 { data: { id: this.challenges[challToDelIdx].id } }
1171 );
1172 }
1173 this.challenges.splice(challToDelIdx, 1);
1174 }
1175 this.send("newchallenge", {
1176 data: Object.assign(
1177 // Temporarily add sender infos to display challenge on Discord.
1178 { from: this.st.user.sid, sender: this.st.user.name },
1179 chall,
1180 { options: JSON.stringify(chall.options) }
1181 )
1182 });
1183 // Add new challenge:
1184 chall.from = {
1185 sid: this.st.user.sid,
1186 id: this.st.user.id,
1187 name: this.st.user.name
1188 };
1189 chall.added = Date.now();
1190 // NOTE: vname and type are redundant (deduced from cadence + vid)
1191 chall.type = ctype;
1192 chall.vname = this.newchallenge.vname;
1193 this.challenges.push(chall);
1194 // Remember cadence + vid for quicker further challenges:
1195 localStorage.setItem("cadence", chall.cadence);
1196 localStorage.setItem("vid", chall.vid);
1197 document.getElementById("modalNewgame").checked = false;
1198 // Show the challenge if not on current display
1199 if (
1200 (ctype == "live" && this.cdisplay == "corr") ||
1201 (ctype == "corr" && this.cdisplay == "live")
1202 ) {
1203 this.setDisplay('c', ctype);
1204 }
1205 };
1206 if (ctype == "live") {
1207 // Live challenges have a random ID
1208 finishAddChallenge(null);
1209 }
1210 else {
1211 // Correspondence game: send challenge to server
1212 ajax(
1213 "/challenges",
1214 "POST",
1215 {
1216 data: {
1217 chall: Object.assign({},
1218 chall, { options: JSON.stringify(chall.options) }
1219 )
1220 },
1221 success: (response) => {
1222 finishAddChallenge(response.id);
1223 }
1224 }
1225 );
1226 }
1227 },
1228 // Callback function after a diagram was showed to accept
1229 // or refuse targetted challenge:
1230 decisionChallenge: function(accepted) {
1231 this.curChallToAccept.accepted = accepted;
1232 this.finishProcessingChallenge(this.curChallToAccept);
1233 document.getElementById("modalAccept").checked = false;
1234 },
1235 finishProcessingChallenge: function(c) {
1236 if (c.accepted) {
1237 c.seat = {
1238 sid: this.st.user.sid,
1239 id: this.st.user.id,
1240 name: this.st.user.name
1241 };
1242 this.launchGame(c);
1243 if (c.type == "live") {
1244 // Remove all live challenges of both players
1245 this.send(
1246 "deletechallenge_s",
1247 { data: { sids: [c.from.sid, c.seat.sid] } }
1248 );
1249 }
1250 else
1251 // Corr challenge: just remove the challenge
1252 this.send("deletechallenge_s", { data: { cid: c.id } });
1253 }
1254 else {
1255 const oppsid = this.getOppsid(c);
1256 if (!!oppsid)
1257 this.send("refusechallenge", { data: c.id, target: oppsid });
1258 if (c.type == "corr") {
1259 ajax(
1260 "/challenges",
1261 "DELETE",
1262 { data: { id: c.id } }
1263 );
1264 }
1265 this.send("deletechallenge_s", { data: { cid: c.id } });
1266 }
1267 },
1268 // TODO: if several players click same challenge at the same time: problem
1269 clickChallenge: async function(c) {
1270 const myChallenge =
1271 c.from.sid == this.st.user.sid || //live
1272 (this.st.user.id > 0 && c.from.id == this.st.user.id); //corr
1273 if (!myChallenge) {
1274 if (c.type == "corr" && this.st.user.id <= 0) {
1275 alert(this.st.tr["Please log in to accept corr challenges"]);
1276 return;
1277 }
1278 else {
1279 c.accepted = true;
1280 await import("@/variants/" + c.vname + ".js")
1281 .then((vModule) => {
1282 window.V = vModule[c.vname + "Rules"];
1283 if (!!c.to) {
1284 // c.to == this.st.user.name (connected)
1285 if (!!c.fen) {
1286 const parsedFen = V.ParseFen(c.fen);
1287 this.tchallDiag = getDiagram({
1288 position: parsedFen.position,
1289 orientation: parsedFen.turn
1290 });
1291 }
1292 this.curChallToAccept = c;
1293 document.getElementById("modalAccept").checked = true;
1294 }
1295 else this.finishProcessingChallenge(c);
1296 });
1297 }
1298 }
1299 else {
1300 // My challenge
1301 if (c.type == "corr") {
1302 ajax(
1303 "/challenges",
1304 "DELETE",
1305 { data: { id: c.id } }
1306 );
1307 }
1308 this.send("deletechallenge_s", { data: { cid: c.id } });
1309 }
1310 // In all cases, the challenge is consumed:
1311 ArrayFun.remove(this.challenges, ch => ch.id == c.id);
1312 },
1313 // NOTE: when launching game, the challenge is already being deleted
1314 launchGame: function(c) {
1315 // White player index 0, black player index 1:
1316 let players =
1317 !!c.color
1318 ? (c.color == "w" ? [c.from, c.seat] : [c.seat, c.from])
1319 : shuffle([c.from, c.seat]);
1320 players.forEach(p => {
1321 if (!!p["tmpIds"]) delete p["tmpIds"];
1322 });
1323 // These game informations will be shared
1324 let gameInfo = {
1325 id: getRandString(),
1326 fen: c.fen || V.GenRandInitFen(c.options),
1327 options: JSON.stringify(c.options), //for rematch
1328 players: players,
1329 vid: c.vid,
1330 cadence: c.cadence
1331 };
1332 const notifyNewgame = () => {
1333 const oppsid = this.getOppsid(c);
1334 if (!!oppsid)
1335 // Opponent is online
1336 this.send("startgame", { data: gameInfo, target: oppsid });
1337 // If new corr game, notify Hall (except opponent and me)
1338 if (c.type == "corr") {
1339 this.send(
1340 "newgame",
1341 {
1342 data: gameInfo,
1343 excluded: [this.st.user.sid, oppsid]
1344 }
1345 );
1346 }
1347 // Notify MyGames page:
1348 this.send(
1349 "notifynewgame",
1350 {
1351 data: gameInfo,
1352 targets: gameInfo.players
1353 }
1354 );
1355 // NOTE: no need to send the game to the room, since I'll connect
1356 // on game just after, the main Hall will be notified.
1357 };
1358 if (c.type == "live") {
1359 // TODO: ask my IP + opp IP, to add to game infos? (potential bans)
1360 notifyNewgame();
1361 this.startNewGame(gameInfo);
1362 // Increment game stats counter in DB
1363 ajax(
1364 "/gamestat",
1365 "POST",
1366 { data: { vid: gameInfo.vid } }
1367 );
1368 }
1369 else {
1370 // corr: game only on server
1371 ajax(
1372 "/games",
1373 "POST",
1374 {
1375 // cid is useful to delete the challenge:
1376 data: {
1377 gameInfo: gameInfo,
1378 cid: c.id
1379 },
1380 success: (response) => {
1381 gameInfo.id = response.id;
1382 notifyNewgame();
1383 this.$router.push("/game/" + response.id);
1384 }
1385 }
1386 );
1387 }
1388 },
1389 // NOTE: for live games only (corr games start on the server)
1390 startNewGame: function(gameInfo) {
1391 this.setVname(gameInfo);
1392 const game = Object.assign(
1393 {},
1394 gameInfo,
1395 {
1396 // (other) Game infos: constant
1397 fenStart: gameInfo.fen,
1398 created: Date.now(),
1399 // Game state (including FEN): will be updated
1400 moves: [],
1401 clocks: [-1, -1], //-1 = unstarted
1402 chats: [],
1403 score: "*"
1404 }
1405 );
1406 setTimeout(
1407 () => {
1408 const myIdx = (game.players[0].sid == this.st.user.sid ? 0 : 1);
1409 GameStorage.add(game, (err) => {
1410 // If an error occurred, game is not added: the focused tab
1411 // already added the game.
1412 if (!this.focus) {
1413 if (this.st.settings.sound)
1414 // This will be played several times if several hidden tabs
1415 // on Hall... TODO: fix that (how ?!)
1416 new Audio("/sounds/newgame.flac").play().catch(() => {});
1417 notify(
1418 "New live game",
1419 { body: "vs " + (game.players[1-myIdx].name || "@nonymous") }
1420 );
1421 }
1422 this.$router.push("/game/" + gameInfo.id);
1423 });
1424 },
1425 this.focus ? 0 : 500 + 1000 * Math.random()
1426 );
1427 }
1428 }
1429 };
1430 </script>
1431
1432 <style lang="sass" scoped>
1433 .active
1434 color: #388e3c
1435
1436 #infoDiv > .card
1437 padding: 15px 0
1438 max-width: 430px
1439
1440 #newgameDiv > .card, #acceptDiv > .card
1441 max-width: 767px
1442 max-height: 100%
1443
1444 div#peopleWrap > .card
1445 max-height: 100%
1446
1447 @media screen and (min-width: 1281px)
1448 div#peopleWrap > .card
1449 max-width: 66.67%
1450
1451 @media screen and (max-width: 1280px)
1452 div#peopleWrap > .card
1453 max-width: 83.33%
1454
1455 @media screen and (max-width: 767px)
1456 div#peopleWrap > .card
1457 max-width: 100%
1458
1459 #players
1460 width: 50%
1461 position: relative
1462 float: left
1463
1464 #chat
1465 width: 50%
1466 float: left
1467 position: relative
1468
1469 @media screen and (max-width: 767px)
1470 #players, #chats
1471 width: 100%
1472
1473 #chat > .card
1474 max-width: 100%
1475 margin: 0;
1476 border: none;
1477
1478 #players > p
1479 margin-left: 5px
1480
1481 .anonymous
1482 font-style: italic
1483
1484 button.player-action
1485 margin-left: 32px
1486 &.focused
1487 background-color: #E6D271
1488
1489 .somethingnew
1490 background-color: #90C4EC !important
1491
1492 .tabbtn
1493 background-color: #f9faee
1494
1495 button.acceptBtn
1496 background-color: lightgreen
1497 button.refuseBtn
1498 background-color: red
1499
1500 #buttonsTchall
1501 // margin-top set dynamically (depends if diagram showed or not)
1502 & > button > span
1503 width: 100%
1504 text-align: center
1505
1506 .variantName
1507 font-weight: bold
1508
1509 .diagram
1510 margin: 0 auto
1511 max-width: 400px
1512 // width: 100% required for Firefox
1513 width: 100%
1514
1515 #inputFen
1516 width: 100%
1517
1518 #div2, #div3
1519 margin-top: 15px
1520 @media screen and (max-width: 767px)
1521 #div2, #div3
1522 margin-top: 0
1523
1524 .user-bio
1525 display: inline
1526
1527 tr > td
1528 &.random-0
1529 background-color: #FEAF9E
1530 &.random-1
1531 background-color: #9EB2FE
1532 &.random-2
1533 background-color: #A5FE9E
1534
1535 @media screen and (max-width: 767px)
1536 h4
1537 margin: 5px 0
1538
1539 button#loadMoreBtn
1540 display: block
1541 margin: 0 auto
1542
1543 td.remove-preset
1544 background-color: lightgrey
1545 text-align: center
1546 & > img
1547 height: 1em
1548 </style>