From 58d0b1a89c461467c9ea6229f9a6b3d5ed573da5 Mon Sep 17 00:00:00 2001 From: Simponic Date: Sat, 31 Dec 2022 02:29:38 -0700 Subject: A simple stalling TUI! Also, ensure sessions are counted correctly. Next up, some way of pub-sub across multiple nodes --- lib/chessh/schema/player_session.ex | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'lib/chessh/schema') diff --git a/lib/chessh/schema/player_session.ex b/lib/chessh/schema/player_session.ex index ce3fc1f..57803cb 100644 --- a/lib/chessh/schema/player_session.ex +++ b/lib/chessh/schema/player_session.ex @@ -55,17 +55,22 @@ defmodule Chessh.PlayerSession do auth_fn.(player) && PlayerSession.concurrent_sessions(player) < max_sessions - Repo.insert(%PlayerSession{ - login: DateTime.utc_now(), - node_id: System.fetch_env!("NODE_ID"), - player: player, - # TODO: This PID may be wrong - need to determine if this PID is shared with disconnectfun - process: Utils.pid_to_str(self()) - }) + if authed do + Logger.debug( + "Creating session for player #{username} on node #{System.fetch_env!("NODE_ID")} with process #{inspect(self())}" + ) - player - |> Player.authentications_changeset(%{authentications: player.authentications + 1}) - |> Repo.update() + Repo.insert(%PlayerSession{ + login: DateTime.utc_now(), + node_id: System.fetch_env!("NODE_ID"), + player: player, + process: Utils.pid_to_str(self()) + }) + + player + |> Player.authentications_changeset(%{authentications: player.authentications + 1}) + |> Repo.update() + end send(self(), {:authed, authed}) end -- cgit v1.2.3-70-g09d2