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