summaryrefslogtreecommitdiff
path: root/schema.sql
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-07-23 21:18:08 +0200
committerTor Andersson <tor@ccxvii.net>2024-08-20 13:56:22 +0200
commit5b665a840bd3193c9be7b21fbe6f66e119e92d74 (patch)
treedb77f95672db121ee608b9ddcd57a2f7434ce5b4 /schema.sql
parentcb73d0710b0eb84d4f788ff9b1d36ed0b02bf970 (diff)
downloadserver-5b665a840bd3193c9be7b21fbe6f66e119e92d74.tar.gz
New time control.
Diffstat (limited to 'schema.sql')
-rw-r--r--schema.sql24
1 files changed, 6 insertions, 18 deletions
diff --git a/schema.sql b/schema.sql
index 1d3641c..9df5b93 100644
--- a/schema.sql
+++ b/schema.sql
@@ -452,8 +452,7 @@ create table if not exists players (
role text,
user_id integer,
is_invite integer,
- time_used real,
- time_added real,
+ clock real,
score integer,
primary key (game_id, role)
) without rowid;
@@ -505,14 +504,10 @@ create view player_view as
end
) as is_active,
(
- case when pace = 0 then
- 21.0 - (julianday() - julianday(mtime))
+ case when active in ( 'Both', role ) then
+ clock - (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
+ clock
end
) as time_left,
atime
@@ -527,15 +522,7 @@ 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
@@ -543,6 +530,7 @@ create view time_control_view as
where
status = 1
and active in ( 'Both', role )
+ and clock - (julianday() - julianday(mtime)) < 0
;
drop view if exists your_turn_reminder;
@@ -689,7 +677,7 @@ drop trigger if exists trigger_time_used_update;
create trigger trigger_time_used_update before update of active on games
begin
update players
- set time_used = time_used + (julianday() - julianday(old.mtime))
+ set clock = clock - (julianday() - julianday(old.mtime))
where
players.game_id = old.game_id and players.role in ( 'Both', old.active );
end;