summaryrefslogtreecommitdiff
path: root/schema.sql
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-01-01 17:36:56 +0100
committerTor Andersson <tor@ccxvii.net>2024-01-28 13:50:27 +0100
commita1c93c992e456764415b5a4c302e1137673c0a5f (patch)
treeaae79b1ce9c085e66f5ecf4022a2ea93cc07b92e /schema.sql
parent12a2a48e5e1158e1fcbed03862ab17e2869c09e4 (diff)
downloadserver-a1c93c992e456764415b5a4c302e1137673c0a5f.tar.gz
Add time control enforcement.
Diffstat (limited to 'schema.sql')
-rw-r--r--schema.sql45
1 files changed, 40 insertions, 5 deletions
diff --git a/schema.sql b/schema.sql
index 02b9dff..516fe28 100644
--- a/schema.sql
+++ b/schema.sql
@@ -482,17 +482,53 @@ create view player_view as
is_invite,
(
case status
- when 0 then owner_id = user_id
- when 1 then active in ( 'Both', role )
- else 0
+ when 0 then
+ owner_id = user_id
+ when 1 then
+ active in ( 'Both', role )
+ else
+ 0
end
- ) as is_active
+ ) as is_active,
+ (
+ case when pace = 0 then
+ 21.0 - (julianday() - julianday(mtime))
+ else
+ case when active in ( 'Both', role ) then
+ 10.0 - ((julianday() - julianday(mtime)) + time_used - time_added)
+ else
+ 10.0 - (time_used - time_added)
+ end
+ end
+ ) as time_left
from
games
join players using(game_id)
join users using(user_id)
;
+drop view if exists time_control_view;
+create view time_control_view as
+ select
+ game_id,
+ user_id,
+ role,
+ (
+ case when pace = 0 then
+ 21.0 - (julianday() - julianday(mtime))
+ else
+ 10.0 - ((julianday() - julianday(mtime)) + time_used - time_added)
+ end
+ ) as time_left,
+ is_opposed
+ from
+ games
+ join players using(game_id)
+ where
+ status = 1
+ and active in ( 'Both', role )
+ ;
+
drop view if exists your_turn_reminder;
create view your_turn_reminder as
select
@@ -584,7 +620,6 @@ begin
delete from game_notes where game_id = old.game_id;
delete from last_notified where game_id = old.game_id;
delete from unread_chats where game_id = old.game_id;
- update players set time_added = null where game_id = old.game_id;
end;
-- Triggers to clean up without relying on foreign key cascades