aboutsummaryrefslogtreecommitdiff
path: root/captain
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2021-11-24 18:12:57 -0500
committerJeffrey Armstrong <jeff@approximatrix.com>2021-11-24 18:12:57 -0500
commitc79a25cdbb359a6757cf7c2bca64fb52642073e2 (patch)
tree32de91faf6ea8ed6098edb8bd667f8820f60b58a /captain
parenta3fe1adbf76e16e218864a8cfecdea7e6bc5dccd (diff)
downloadlevitating-c79a25cdbb359a6757cf7c2bca64fb52642073e2.tar.gz
levitating-c79a25cdbb359a6757cf7c2bca64fb52642073e2.zip
Started addition of scheduling jobs
Diffstat (limited to 'captain')
-rw-r--r--captain/db.f9049
-rw-r--r--captain/sql/create.sql3
2 files changed, 52 insertions, 0 deletions
diff --git a/captain/db.f90 b/captain/db.f90
index 152f61b..b7712fa 100644
--- a/captain/db.f90
+++ b/captain/db.f90
@@ -36,6 +36,8 @@ implicit none
integer, parameter::PLAYER_STATUS_IDLE = 100
integer, parameter::PLAYER_STATUS_OFFLINE = 101
+ integer, parameter::SCHEDULE_DAILY = 0
+
character(1024)::database_file
type(c_ptr)::db
@@ -1345,5 +1347,52 @@ contains
end if
end function is_player_online
+
+ subroutine add_scheduled_job(player, instruction, day, hour)
+ implicit none
+
+ integer, intent(in)::player, instruction, day, hour
+ type(sqlite3_stmt)::stmt
+
+ if(stmt%prepare(db, "INSERT INTO schedule(instruction, player, day, hour) VALUES(?, ?, ?, ?") == SQLITE_OK) then
+ if(stmt%bind_int(1, instruction) == SQLITE_OK .and. &
+ stmt%bind_int(2, player) == SQLITE_OK .and. &
+ stmt%bind_int(3, day) == SQLITE_OK .and. &
+ stmt%bind_int(4, hour) == SQLITE_OK) &
+ then
+ call stmt%step_now()
+ end if
+ end if
+ call stmt%finalize()
+ end subroutine add_scheduled_job
+
+ subroutine delete_scheduled_job(player, instruction, day, hour)
+ implicit none
+
+ integer, intent(in)::player, instruction, day, hour
+ type(sqlite3_stmt)::stmt
+
+ if(stmt%prepare(db, "DELETE FROM schedule WHERE instruction=? AND player=? AND day=? AND hour=?") == SQLITE_OK) then
+ if(stmt%bind_int(1, instruction) == SQLITE_OK .and. &
+ stmt%bind_int(2, player) == SQLITE_OK .and. &
+ stmt%bind_int(3, day) == SQLITE_OK .and. &
+ stmt%bind_int(4, hour) == SQLITE_OK) &
+ then
+ call stmt%step_now()
+ end if
+ end if
+ call stmt%finalize()
+
+ end subroutine delete_scheduled_job
+
+ subroutine queue_scheduled_jobs(player)
+ implicit none
+
+ integer, intent(in)::player
+
+ ! Needs implementation
+
+ end subroutine queue_scheduled_jobs
+
end module captain_db
diff --git a/captain/sql/create.sql b/captain/sql/create.sql
index e4a944c..8e93e23 100644
--- a/captain/sql/create.sql
+++ b/captain/sql/create.sql
@@ -14,3 +14,6 @@ CREATE TABLE groups(id INTEGER PRIMARY KEY, name TEXT UNIQUE NOT NULL);
CREATE TABLE group_instructions(group_id INTEGER, instruction INTEGER, player INTEGER, FOREIGN KEY(group_id) REFERENCES groups(id) ON DELETE CASCADE, FOREIGN KEY(instruction) REFERENCES instructions(id) ON DELETE CASCADE, FOREIGN KEY(player) REFERENCES players(id) ON DELETE CASCADE);
CREATE TABLE checkin(player INTEGER PRIMARY KEY, year INTEGER, month INTEGER, day INTEGER, hour INTEGER, minute INTEGER, second INTEGER, os TEXT DEFAULT NULL, FOREIGN KEY(player) REFERENCES players(id) ON DELETE CASCADE);
+
+CREATE TABLE schedule(instruction INTEGER NOT NULL, player INTEGER NOT NULL, day INTEGER DEFAULT 0, hour INTEGER DEFAULT 0, FOREIGN KEY(instruction) REFERENCES instructions(id) ON DELETE CASCADE, FOREIGN KEY(player) REFERENCES players(id) ON DELETE CASCADE );
+