From a8fb2326432ec2863deb4f44a1ca7919a9016728 Mon Sep 17 00:00:00 2001 From: Jonas Weinz Date: Thu, 4 Apr 2019 14:58:29 +0200 Subject: [PATCH] temporary accounts --- main.js | 6 +++--- online_match_manager.js | 12 +++++++----- websocket_connection.js | 13 +++++++++++-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/main.js b/main.js index 3459d25..d66be8b 100644 --- a/main.js +++ b/main.js @@ -26,9 +26,9 @@ b_local_game = create_game_container.create_button("Local Game"); // register container: register_container = main_menu.create_infocontainer("Login to play online"); i_register_username = register_container.create_input("username"); -i_register_pw = register_container.create_input("password", true); -b_register = register_container.create_button("register/login"); -register_container.create_label("If the username does not exist yet, a new account is created automatically"); +i_register_pw = register_container.create_input("pw (optional)", true); +b_register = register_container.create_button("play online"); +register_container.create_label("To play ranked matches you have to create an account. Login without an password will only create a temporary session"); register_container.create_label("Note that inactive accounts will be deleted after 45 days") // logout TODO: rename container: diff --git a/online_match_manager.js b/online_match_manager.js index 6bdd5de..40fc389 100644 --- a/online_match_manager.js +++ b/online_match_manager.js @@ -1,6 +1,6 @@ class OnlineMatchManager { - constructor(grid, info_func, matches_container, control_container, end_button, game_server_connection, match_id, match_state, revoke_time, player_name) + constructor(grid, info_func, matches_container, control_container, end_button, game_server_connection, match_id, match_state, revoke_time, player_name, ranked) { this.grid = grid; @@ -10,6 +10,8 @@ class OnlineMatchManager this.game_server_connection = game_server_connection; + this.ranked = ranked; + this.match_state = match_state; this.revoke_time = Date.create_from_mysql(revoke_time); @@ -32,7 +34,7 @@ class OnlineMatchManager this.match_button_div = tmp[0]; this.match_button_option = tmp[2]; - if (this.game_server_connection.is_friend(this.online_opponent.get_name())) + if (this.game_server_connection.temporary_session || this.game_server_connection.is_friend(this.online_opponent.get_name())) { this.match_button_option.disabled = true; } @@ -244,7 +246,7 @@ class OnlineMatchManager } } - var control_head = ""; + var control_head = this.ranked ? "Ranked Match
" : "Unranked_Match
"; this.control_container.clear_background_color(); this.update_button_text(); @@ -325,9 +327,9 @@ class OnlineMatchManager this.control_container.blink(theme_color_highlight); } - control_head += "" + current_player_name + "'s move"; + control_head += "" + encodeHTML(current_player_name) + "'s move"; - this.control_container.update_head(encodeHTML(control_head)); + this.control_container.update_head(control_head); diff --git a/websocket_connection.js b/websocket_connection.js index 687f39d..f50d836 100644 --- a/websocket_connection.js +++ b/websocket_connection.js @@ -9,6 +9,8 @@ class WebsocketConnection this.socket = null; this.registered = false; + this.temporary_session = false; + this.info_func = info_func; this.err_func = err_func; @@ -42,6 +44,8 @@ class WebsocketConnection this.friend_name_divs = []; + + matches_container.hide(); } @@ -245,6 +249,7 @@ class WebsocketConnection var id = data.id var match_state = data.match_state; var revoke_time = data.revoke_time; + var ranked = data.ranked; if (match_state == null) { @@ -281,7 +286,7 @@ class WebsocketConnection this.l_matches_container = null; } - this.openmatches[id] = new OnlineMatchManager(this.grid, this.info_func, this.matches_container, this.control_container, this.end_button, this, id, match_state, revoke_time, this.player.get_name()); + this.openmatches[id] = new OnlineMatchManager(this.grid, this.info_func, this.matches_container, this.control_container, this.end_button, this, id, match_state, revoke_time, this.player.get_name(), ranked); if (match_state.last_move == null) { this.notify("new Game against " + encodeHTML(this.openmatches[id].online_opponent.get_name())); @@ -303,6 +308,7 @@ class WebsocketConnection { this.registered = true; this.session_id = data.id; + this.temporary_session = !data.registered; this.login_callback_func(); this.info_func(data.msg); return; @@ -408,7 +414,10 @@ class WebsocketConnection on_elo_update(data) { console.log("received elo update: " + data.elo); - this.logout_container.update_head("logged in as: " + encodeHTML(connection.player.get_name()) + "
Score: " + encodeHTML("" + data.elo) + "
Rank: " + encodeHTML(""+data.rank)); + if (data.elo != null && data.rank != null) + { + this.logout_container.update_head("logged in as: " + encodeHTML(connection.player.get_name()) + "
Score: " + encodeHTML("" + data.elo) + "
Rank: " + encodeHTML(""+data.rank)); + } this.top_names = data.top_names; this.top_elos = data.top_elos; this.logout_container.blink(theme_color_highlight);