Skip to content
Permalink
Browse files

password field for tourneys

  • Loading branch information...
Manuel-777 committed May 1, 2019
1 parent 34e0919 commit e9b2242b8ae333b67c7374e134217668452044e8
Showing with 73 additions and 14 deletions.
  1. +1 −1 window_background/background.js
  2. +5 −3 window_background/http-api.js
  3. +13 −0 window_main/index.css
  4. +54 −10 window_main/tournaments.js
@@ -599,7 +599,7 @@ ipc.on("tou_get", function(event, arg) {
});

ipc.on("tou_join", function(event, arg) {
httpApi.httpTournamentJoin(arg.id, arg.deck);
httpApi.httpTournamentJoin(arg.id, arg.deck, sha1(arg.pass));
});

ipc.on("tou_drop", function(event, arg) {
@@ -11,7 +11,8 @@ global
store,
makeId,
debugLog,
syncUserData
syncUserData,
sha1
*/
const async = require("async");
const qs = require("qs");
@@ -604,15 +605,16 @@ function httpTournamentGet(tid) {
});
}

function httpTournamentJoin(tid, _deck) {
function httpTournamentJoin(tid, _deck, pass) {
let _id = makeId(6);
let deck = JSON.stringify(decks[_deck]);
httpAsync.unshift({
reqId: _id,
method: "tou_join",
method_path: "/api/tournament_join.php",
id: tid,
deck: deck
deck: deck,
pass: pass
});
}

@@ -2584,6 +2584,19 @@ a:hover {
overflow: auto;
}

.tourney_pwd_container {
display: flex;
align-items: center;
max-width: 300px;
margin: auto;
}

.input_lock {
width: 24px;
height: 24px;
margin-right: 8px;
}

.tou_create_but {
cursor: pointer;
margin: auto 0;
@@ -86,32 +86,35 @@ function tournamentOpen(t) {
flr = createDivision(["tou_top_status", "state_clock"]);
flr.style.alignSelf = "center";


let state = "";
if (stateClockInterval !== null) clearInterval(stateClockInterval);
if (tou.state == -1) {
state = "";
stateClockInterval = window.setInterval(() => {
let tst = timestamp();
$$(".state_clock")[0].innerHTML = "Registration begin in " + toHHMMSS(tst - tou.starts);
$$(".state_clock")[0].innerHTML =
"Registration begin in " + toHHMMSS(tst - tou.starts);
}, 1000);
}
if (tou.state == 0) {
state = "";
stateClockInterval = window.setInterval(() => {
let tst = timestamp();
if (joined) {
$$(".state_clock")[0].innerHTML = "Starts in " + toHHMMSS(roundsStart - tst);
$$(".state_clock")[0].innerHTML =
"Starts in " + toHHMMSS(roundsStart - tst);
} else {
$$(".state_clock")[0].innerHTML = toHHMMSS(roundsStart - tst) + " left to register."
$$(".state_clock")[0].innerHTML =
toHHMMSS(roundsStart - tst) + " left to register.";
}
}, 1000);
}
if (tou.state == 1) {
state = "";
stateClockInterval = window.setInterval(() => {
let tst = timestamp();
$$(".state_clock")[0].innerHTML = `Round ${tou.currentRound + 1} ends in ${toHHMMSS(roundEnd - tst)}`;
$$(".state_clock")[0].innerHTML = `Round ${tou.currentRound +
1} ends in ${toHHMMSS(roundEnd - tst)}`;
}, 1000);
}
if (tou.state == 3) {
@@ -185,7 +188,35 @@ function showTournamentRegister(mainDiv, tou) {
mainDiv.appendChild(deckSelect);

if (tou.state == 0) {
buttonJoin = createDivision(["button_simple_disabled", "but_join"], "Join");
if (tou.password) {
let cont = createDivision([
"input_login_container",
"tourney_pwd_container"
]);

let lockIcon = createDivision(["status_locked", "input_lock"]);

let pwdInput = document.createElement("input");
pwdInput.id = "tourney_pass";
pwdInput.autocomplete = "off";
pwdInput.type = "password";

let lockedMsg = createDivision(
["tou_desc"],
"This tournament is password protected."
);
lockedMsg.style.margin = "32px 0 0px 0px";
mainDiv.appendChild(lockedMsg);

cont.appendChild(lockIcon);
cont.appendChild(pwdInput);
mainDiv.appendChild(cont);
}

buttonJoin = createDivision(
["button_simple_disabled", "but_join"],
"Join"
);
mainDiv.appendChild(buttonJoin);
}

@@ -194,7 +225,10 @@ function showTournamentRegister(mainDiv, tou) {
}

let list = createDivision(["tou_list_players"]);
let pJoined = createDivision(["tou_list_player_name", "tou_list_player_name_title"], "Players joined:");
let pJoined = createDivision(
["tou_list_player_name", "tou_list_player_name_title"],
"Players joined:"
);
list.appendChild(pJoined);

tou.players.forEach(p => {
@@ -206,8 +240,13 @@ function showTournamentRegister(mainDiv, tou) {

if (buttonJoin) {
buttonJoin.addEventListener("click", () => {
if (this.classList.contains("button_simple")) {
ipc_send("tou_join", { id: tou._id, deck: tournamentDeck });
if (buttonJoin.classList.contains("button_simple")) {
if (tou.password) {
let pwd = document.getElementById("tourney_pass").value;
tournamentJoin(tou._id, tournamentDeck, pwd);
} else {
tournamentJoin(tou._id, tournamentDeck, "");
}
}
});
}
@@ -219,6 +258,10 @@ function showTournamentRegister(mainDiv, tou) {
}
}

function tournamentJoin(_id, _deck, _pass) {
ipc_send("tou_join", { id: _id, deck: _deck, pass: _pass });
}

function showTournamentStarted(mainDiv, tou) {
let joined = false;
if (tou.players.indexOf(playerData.name) !== -1) {
@@ -611,12 +654,13 @@ function generateChecks(state, seat) {

function selectTourneyDeck(index) {
let _deck = decks[index];
tournamentDeck = _deck.id;
_deck.mainDeck.sort(compare_cards);
_deck.sideboard.sort(compare_cards);
// drawDeck requires a jquery div... mmm
drawDeck($(".join_decklist"), _deck, true);

$$(".but_join").classList.add("button_simple");
$$(".but_join")[0].classList.add("button_simple");
}

function drawSideboardDeck() {

0 comments on commit e9b2242

Please sign in to comment.
You can’t perform that action at this time.