Add form to join game

O01eg
Oct 17, 2022, 11:34 AM
TEB4R7OU65GZAGPNINWHOR4Q23OJYVUQK5RT75SV26W7JJEVT5DQC

Dependencies

  • [2] BVCWJKEX Get auth info for slow game page
  • [3] LOFH5LIA Make bold player name
  • [4] XKG2L3QB Show label if player could join the game
  • [5] A2LJT7TT Show duration in turns
  • [6] GUAEZDLE Add turns info to slow game's page
  • [7] AEWYJHUD Start to show player list
  • [8] 6NYILMKI Add page for slow game
  • [9] 6BDGQ4VM Show player names for registered players
  • [10] C6F7SJZI Add players count to slow game's page
  • [*] EVP2FSBH Split index page
  • [*] FUCFD4UV Add log in and log out support
  • [*] 3HT5CE6S Manage TTL duration in config
  • [*] 4MZ4VIR7 Initial commit

Change contents

  • replacement in src/templates/slow-game.html at line 68
    [5.195][4.0:33]()
    {{#if can_join}}
    <p>Can join</p>
    [5.195]
    [4.33]
    {{#if join_data}}
    <form id="join-game" action="join-game.do" method="post">
    <fieldset>
    <input name="csrf" type="hidden" value="{{ join_data.csrf }}">
    <input name="submit" type="submit" value="Join Game">
    </fieldset>
    </form>
  • edit in src/pages/slow_game.rs at line 2
    [2.49]
    [5.662]
    use uuid::Uuid;
  • edit in src/pages/slow_game.rs at line 16
    [5.802]
    [5.802]
    struct JoinData {
    csrf: Uuid,
    }
    #[derive(serde_derive::Serialize)]
  • replacement in src/pages/slow_game.rs at line 32
    [5.246][4.42:108]()
    player_list: Option<&'a Vec<PlayerInfo>>,
    can_join: bool,
    [5.246]
    [5.0]
    player_list: Option<Vec<PlayerInfo>>,
    join_data: Option<JoinData>,
  • replacement in src/pages/slow_game.rs at line 121
    [5.236][3.181:234]()
    let player_list = if let Some(ref user) = user {
    [5.236]
    [3.234]
    let status = row.get::<_, Option<&str>>(0);
    let (player_list, join_data) = if let Some(ref user) = user {
  • replacement in src/pages/slow_game.rs at line 148
    [5.1039][4.109:143]()
    Some((users, has_itself))
    [5.1039]
    [5.1059]
    let join_data = if !has_itself && status.is_none() {
    let csrf = Uuid::new_v4();
    let mut cache = data.cache_join_game.lock().await;
    cache.insert(
    csrf,
    (gameuid.clone(), user.to_string()),
    std::time::Duration::from_secs(data.cache_duration_sec),
    );
    Some(JoinData { csrf })
    } else {
    None
    };
    (Some(users), join_data)
  • replacement in src/pages/slow_game.rs at line 164
    [5.1072][5.1072:1085]()
    None
    [5.1072]
    [5.1085]
    (None, None)
  • edit in src/pages/slow_game.rs at line 167
    [4.145][4.145:193](),[4.193][5.1122:1123](),[5.1092][5.1122:1123](),[5.1122][5.1122:1123]()
    let status = row.get::<_, Option<&str>>(0);
  • replacement in src/pages/slow_game.rs at line 181
    [5.886][4.215:398]()
    player_list: player_list.as_ref().map(|x| &x.0),
    can_join: player_list
    .as_ref()
    .map_or(false, |x| !x.1 && status.is_none()),
    [5.886]
    [5.2642]
    player_list,
    join_data,
  • edit in src/pages/mod.rs at line 47
    [13.1548]
    [14.140]
    pub cache_join_game: Mutex<TtlCache<Uuid, (String, String)>>,
  • edit in src/main.rs at line 218
    [13.7053]
    [14.203]
    cache_join_game: tokio::sync::Mutex::new(ttl_cache::TtlCache::new(cache_capacity)),