From a764abe6565544bea8591b26839ad931f3f42e4d Mon Sep 17 00:00:00 2001
From: Tor Andersson <tor@ccxvii.net>
Date: Tue, 11 Feb 2025 01:01:04 +0100
Subject: Use state.active to detect finished games.

Instead of looking for (state.state === "game_over").

Add is_active_role helper function.
---
 schema.sql | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'schema.sql')

diff --git a/schema.sql b/schema.sql
index 8abfe06..5fd189e 100644
--- a/schema.sql
+++ b/schema.sql
@@ -137,7 +137,7 @@ create view user_dynamic_view as
 				status = 1
 				and user_count = player_count
 				and players.user_id = users.user_id
-				and active in ( players.role, 'Both' )
+				and active in ( 'Both', players.role )
 		) + (
 			select
 				count(*)
@@ -875,7 +875,7 @@ begin
 	update players
 		set clock = clock - (julianday() - julianday(old.mtime))
 	where
-		players.game_id = old.game_id and players.role in ( 'Both', old.active );
+		players.game_id = old.game_id and old.active in ( 'Both', players.role );
 end;
 
 -- Trigger to remove game data when filing a game as archived
-- 
cgit v1.2.3

