diff options
author | Simponic <loganhunt@simponic.xyz> | 2022-12-31 02:29:38 -0700 |
---|---|---|
committer | Simponic <loganhunt@simponic.xyz> | 2022-12-31 02:31:58 -0700 |
commit | 58d0b1a89c461467c9ea6229f9a6b3d5ed573da5 (patch) | |
tree | f0e91ce7bccb93e755357395f1ed7a7a18d6257b /lib/chessh/schema | |
parent | 3308036c0859dcca2d80d80396a19a3cca269e78 (diff) | |
download | chessh-58d0b1a89c461467c9ea6229f9a6b3d5ed573da5.tar.gz chessh-58d0b1a89c461467c9ea6229f9a6b3d5ed573da5.zip |
A simple stalling TUI! Also, ensure sessions are counted correctly. Next up, some way of pub-sub across multiple nodes
Diffstat (limited to 'lib/chessh/schema')
-rw-r--r-- | lib/chessh/schema/player_session.ex | 25 |
1 files changed, 15 insertions, 10 deletions
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 |