aboutsummaryrefslogtreecommitdiff
path: root/captain/db.f90
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2021-03-29 20:36:27 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2021-03-29 20:36:27 -0400
commit342df3430218d5fd3be8ceca606330964b6f098b (patch)
treec5262d2aa98ef715dfd307880c18f74dfdd9493c /captain/db.f90
parentbe976a38f1d95258f19d94f4cf5dc4c677041ed9 (diff)
downloadlevitating-342df3430218d5fd3be8ceca606330964b6f098b.tar.gz
levitating-342df3430218d5fd3be8ceca606330964b6f098b.zip
Added further player functions to db. Added contents for listing players via gemini.
Diffstat (limited to 'captain/db.f90')
-rw-r--r--captain/db.f9050
1 files changed, 46 insertions, 4 deletions
diff --git a/captain/db.f90 b/captain/db.f90
index 5fbd0b4..e191af7 100644
--- a/captain/db.f90
+++ b/captain/db.f90
@@ -1,7 +1,9 @@
module captain_db
use sqlite
implicit none
-
+
+ integer, parameter::PLAYER_NAME_LENGTH = 128
+
character(1024)::database_file
type(c_ptr)::db
@@ -33,11 +35,20 @@ contains
subroutine add_player_db(name, token)
implicit none
- character(*), intent(in)::name, token
+ character(*), intent(in)::name
+ character(*), intent(in), optional::token
type(sqlite3_stmt)::stmt
+
+ character(64)::my_token
+
+ if(present(token)) then
+ my_token = token
+ else
+ my_token = "None"
+ end if
if(stmt%prepare(db, "INSERT INTO players(name, token) VALUES(?, ?)") == SQLITE_OK) then
- if(stmt%bind_text(1, name) == SQLITE_OK .and. stmt%bind_text(2, token) == SQLITE_OK) then
+ if(stmt%bind_text(1, name) == SQLITE_OK .and. stmt%bind_text(2, my_token) == SQLITE_OK) then
call stmt%step_now()
end if
end if
@@ -45,6 +56,37 @@ contains
end subroutine add_player_db
+ subroutine update_player_token_db(name, token)
+ implicit none
+
+ character(*), intent(in)::name
+ character(*), intent(in)::token
+ type(sqlite3_stmt)::stmt
+
+ if(stmt%prepare(db, "UPDATE players SET token=? WHERE name=?") == SQLITE_OK) then
+ if(stmt%bind_text(2, name) == SQLITE_OK .and. stmt%bind_text(1, token) == SQLITE_OK) then
+ call stmt%step_now()
+ end if
+ end if
+ call stmt%finalize()
+
+ end subroutine update_player_token_db
+
+ subroutine remove_player_db(name)
+ implicit none
+
+ character(*), intent(in)::name
+ type(sqlite3_stmt)::stmt
+
+ if(stmt%prepare(db, "DELETE FROM players WHERE name=?") == SQLITE_OK) then
+ if(stmt%bind_text(1, name) == SQLITE_OK) then
+ call stmt%step_now()
+ end if
+ end if
+ call stmt%finalize()
+
+ end subroutine remove_player_db
+
function get_player_count()
implicit none
@@ -65,7 +107,7 @@ contains
implicit none
type(sqlite3_stmt)::stmt
- character(len=256), dimension(:), pointer::res
+ character(len=PLAYER_NAME_LENGTH), dimension(:), pointer::res
integer::i,n
n = get_player_count()