aboutsummaryrefslogtreecommitdiff
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
parentbe976a38f1d95258f19d94f4cf5dc4c677041ed9 (diff)
downloadlevitating-342df3430218d5fd3be8ceca606330964b6f098b.tar.gz
levitating-342df3430218d5fd3be8ceca606330964b6f098b.zip
Added further player functions to db. Added contents for listing players via gemini.
-rw-r--r--captain/db.f9050
-rw-r--r--captain/external.f9060
2 files changed, 103 insertions, 7 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()
diff --git a/captain/external.f90 b/captain/external.f90
index aa65e71..3ec018f 100644
--- a/captain/external.f90
+++ b/captain/external.f90
@@ -4,18 +4,58 @@ implicit none
contains
+ function generate_players_gemini() result(res)
+ use captain_db
+ implicit none
+
+ character(len=:), pointer::res
+ character(len=PLAYER_NAME_LENGTH), dimension(:), pointer::players
+ integer::n, i, nsize
+
+ character(len=3*PLAYER_NAME_LENGTH)::one_player
+
+ n = get_player_count()
+ if(n == 0) then
+
+ allocate(character(len=1024) :: res)
+
+ res = "None Yet"
+
+ else
+
+ res = "## Existing Players"
+ players => get_player_names()
+
+ nsize = 1024
+ do i = 1, size(players)
+ nsize = nsize + 16 + 2*len_trim(players(i))
+ end do
+
+ allocate(character(len=nsize) :: res)
+ do i = 1, n
+ one_player = "=> /players/"//trim(players(i))//".gmi "//trim(players(i))
+ res = trim(res)//new_line(res(1:1))//trim(one_player)
+ end do
+
+ deallocate(players)
+ end if
+
+ res = trim(res)//new_line(res(1:1))//"## Management"// &
+ new_line(res(1:1))//"=> /players/add.gmi Add Player"
+
+ end function generate_players_gemini
+
function external_request_gemini(request) result(disk_filename)
use page_template
- use config, only: template_filepath
+ use config, only: template_filepath, project
use logging, only: write_log
implicit none
character(*), intent(in)::request
character(len=:), pointer::disk_filename
- integer::renderunit
character(1024)::template_file
type(template)::page
- character(16)::log_tmp
+ character(len=:), pointer::contents
! Open the base template
call template_filepath("index.gmi", template_file)
@@ -37,6 +77,18 @@ contains
else if(trim(request) == "/players.gmi") then
call page%assign('title', 'Players')
+ contents => generate_players_gemini()
+ call page%assign('contents', contents)
+
+ else if(request(1:9) == '/players/') then
+
+ if(trim(request) == "/players/add.gmi") then
+
+ ! Need input!
+
+ else
+
+ end if
else if(trim(request) == "/about.gmi") then
@@ -48,6 +100,8 @@ contains
end if
+ call page%assign('project', project)
+
call page%render()
disk_filename => page%output_filename