aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--captain/db.f9077
-rw-r--r--captain/example/static/style.css2
-rw-r--r--captain/external.f9015
-rw-r--r--captain/levitating-captain.prj11
-rw-r--r--captain/requtils.f9040
-rw-r--r--captain/templates/index.html2
-rw-r--r--captain/web.f9034
7 files changed, 146 insertions, 35 deletions
diff --git a/captain/db.f90 b/captain/db.f90
index b9d1e61..152f61b 100644
--- a/captain/db.f90
+++ b/captain/db.f90
@@ -32,8 +32,9 @@ implicit none
integer, parameter::JOB_STATUS_WORKING = 3
integer, parameter::JOB_STATUS_PENDING = 0
- integer, parameter::PLAYER_STATUS_BUSY = JOB_STATUS_WORKING
- integer, parameter::PLAYER_STATUS_IDLE = 100
+ integer, parameter::PLAYER_STATUS_BUSY = JOB_STATUS_WORKING
+ integer, parameter::PLAYER_STATUS_IDLE = 100
+ integer, parameter::PLAYER_STATUS_OFFLINE = 101
character(1024)::database_file
type(c_ptr)::db
@@ -1248,28 +1249,27 @@ contains
integer, dimension(8), intent(out)::values
type(sqlite3_stmt)::stmt
- integer::i
! This call properly retrieves the offset from UTC if you want it...
+ values = 0
call date_and_time(values=values)
- values(1:3) = 0
- values(5:8) = 0
if(stmt%prepare(db, "SELECT year, month, day, hour, minute, second FROM checkin WHERE player=? LIMIT 1") == SQLITE_OK) then
if(stmt%bind_int(1, player) == SQLITE_OK) then
if(stmt%step() == SQLITE_ROW) then
- do i = 1, 7
- if(i < 4) then
- values(i) = stmt%column_int(i-1)
- else if(i >= 5) then
- values(i-1) = stmt%column_int(i-1)
- end if
- end do
+ values(1) = stmt%column_int(0)
+ values(2) = stmt%column_int(1)
+ values(3) = stmt%column_int(2)
+ values(5) = stmt%column_int(3)
+ values(6) = stmt%column_int(4)
+ values(7) = stmt%column_int(5)
+ else
+ values = 0
end if
end if
end if
call stmt%finalize()
-
+
end subroutine get_last_checkin_time
subroutine get_player_platform(player, platform)
@@ -1295,4 +1295,55 @@ contains
end subroutine get_player_platform
+ pure function julian_date(values) result(jd)
+ implicit none
+
+ integer, dimension(3), intent(in)::values
+ integer::jd
+
+ jd = (1461 * (values(1) + 4800 + (values(2)-14)/12))/4 + &
+ (367 * (values(2) - 2 - 12*((values(2)-14)/12)))/12 - &
+ (3*((values(1) + 4900 + (values(2)-14)/12)/100))/4 + &
+ values(3) - 32075
+
+ end function julian_date
+
+ pure function seconds_difference(first, second) result(diff)
+ implicit none
+
+ integer, dimension(8), intent(in)::first, second
+ integer(kind=8)::diff
+
+ diff = (julian_date(first(1:3)) - julian_date(second(1:3))) * 24 * 3600
+
+ diff = diff + (first(5) - second(5)) * 3600
+ diff = diff + (first(6) - second(6)) * 60
+ diff = diff + (first(7) - second(7))
+
+ end function seconds_difference
+
+ function is_player_online(player) result(ret)
+ implicit none
+
+ integer, intent(in)::player
+ logical::ret
+
+ integer, dimension(8)::now, last
+
+ call date_and_time(values=now)
+ call get_last_checkin_time(player, last)
+
+ ! All zeroes mean that it was never online
+ if(all(last == 0)) then
+
+ ret = .false.
+
+ else
+
+ ret = (seconds_difference(now, last) <= 60)
+
+ end if
+
+ end function is_player_online
+
end module captain_db
diff --git a/captain/example/static/style.css b/captain/example/static/style.css
index 6af0d2e..41d6ed0 100644
--- a/captain/example/static/style.css
+++ b/captain/example/static/style.css
@@ -52,7 +52,7 @@ body {
.content {
- margin-top: 80px;
+ padding-top: 80px;
clear:both;
margin-left: 1em;
margin-right: 1em;
diff --git a/captain/external.f90 b/captain/external.f90
index 61184f1..0cdcfdf 100644
--- a/captain/external.f90
+++ b/captain/external.f90
@@ -242,10 +242,12 @@ contains
function generate_players_gemini() result(res)
use captain_db
+ use request_utils, only: get_player_status_utf8
implicit none
character(len=:), pointer::res
character(len=PLAYER_NAME_LENGTH), dimension(:), pointer::players
+ character(4)::player_status
integer::n, i, nsize
character(len=3*PLAYER_NAME_LENGTH)::one_player
@@ -270,7 +272,9 @@ contains
res = "## Existing Players"
do i = 1, n
- one_player = "=> /players/"//trim(players(i))//".gmi "//trim(players(i))
+ player_status = get_player_status_utf8(players(i))
+
+ one_player = "=> /players/"//trim(players(i))//".gmi "//trim(player_status)//" "//trim(players(i))
if(i == 1) then
res = trim(res)//new_line(res(1:1))//new_line(res(1:1))//trim(one_player)
else
@@ -289,7 +293,7 @@ contains
function generate_one_instuction_gemini(req) result(res)
use captain_db
use server_response
- use request_utils, only: get_status_utf8
+ use request_utils, only: get_player_status_utf8
use request_utils, only: render_jobs_links
implicit none
@@ -352,12 +356,7 @@ contains
res = trim(res)//nl//nl//"### Launch Now"
do i = 1, n_players
call get_player_name(players(i), player_name)
- if(is_player_busy(players(i))) then
- player_status = get_status_utf8(PLAYER_STATUS_BUSY)
- else
- player_status = get_status_utf8(PLAYER_STATUS_IDLE)
- end if
-
+ player_status = get_player_status_utf8(players(i))
res = trim(res)//nl//"=> "//trim(req%location)//"?launch="//trim(player_name)// &
" "//trim(player_status)//" "//trim(player_name)
end do
diff --git a/captain/levitating-captain.prj b/captain/levitating-captain.prj
index 0e786f6..066c943 100644
--- a/captain/levitating-captain.prj
+++ b/captain/levitating-captain.prj
@@ -18,7 +18,7 @@
}]
},{
"Folders":[],
- "Name":"+common",
+ "Name":"-common",
"Files":[{
"filename":"../common/jessl.f90",
"enabled":"1"
@@ -39,7 +39,14 @@
"enabled":"0"
}]
},{
- "Folders":[],
+ "Folders":[{
+ "Folders":[],
+ "Name":"+static",
+ "Files":[{
+ "filename":"example/static/style.css",
+ "enabled":"1"
+ }]
+ }],
"Name":"+example",
"Files":[{
"filename":"example/levitating.conf",
diff --git a/captain/requtils.f90 b/captain/requtils.f90
index a0c42c7..41eacc6 100644
--- a/captain/requtils.f90
+++ b/captain/requtils.f90
@@ -32,6 +32,11 @@ implicit none
module procedure instruction_link_from_name
module procedure instruction_link_from_id
end interface
+
+ interface get_player_status_utf8
+ module procedure get_player_status_utf8_by_id
+ module procedure get_player_status_utf8_by_name
+ end interface
contains
@@ -143,10 +148,45 @@ contains
! Envelope 0x2709
res = char(226)//char(156)//char(137)//" "
+ case(PLAYER_STATUS_OFFLINE)
+ ! Fancy question mark 0xe29d93
+ res = char(226)//char(157)//char(147)//" "
+
end select
end function get_status_utf8
+ function get_player_status_utf8_by_id(player_id) result(res)
+ use captain_db, only: is_player_online, is_player_busy, &
+ PLAYER_STATUS_BUSY, PLAYER_STATUS_IDLE, PLAYER_STATUS_OFFLINE
+ implicit none
+
+ integer, intent(in)::player_id
+ character(4)::res
+
+ if(is_player_online(player_id)) then
+ if(is_player_busy(player_id)) then
+ res = get_status_utf8(PLAYER_STATUS_BUSY)
+ else
+ res = get_status_utf8(PLAYER_STATUS_IDLE)
+ end if
+ else
+ res = get_status_utf8(PLAYER_STATUS_OFFLINE)
+ end if
+
+ end function get_player_status_utf8_by_id
+
+ function get_player_status_utf8_by_name(player) result(res)
+ use captain_db, only: get_player_id
+ implicit none
+
+ character(*), intent(in)::player
+ character(4)::res
+
+ res = get_player_status_utf8_by_id(get_player_id(player))
+
+ end function get_player_status_utf8_by_name
+
function is_request_static(req)
use server_response
use logging
diff --git a/captain/templates/index.html b/captain/templates/index.html
index 5d90ad4..fc4de13 100644
--- a/captain/templates/index.html
+++ b/captain/templates/index.html
@@ -20,7 +20,7 @@
<li><a href="{{ base_url }}/about.html">About</a></li>
</ul>
</div>
- <h1>{{ title }} - I'm Levitating!</h1>
+ <h1 style="overflow: hidden; text-overflow: ellipsis;white-space: nowrap;">{{ title }} - I'm Levitating!</h1>
</div>
<div class="content">
diff --git a/captain/web.f90 b/captain/web.f90
index 9817775..f66250c 100644
--- a/captain/web.f90
+++ b/captain/web.f90
@@ -89,7 +89,7 @@ contains
function generate_one_instuction_html(req) result(res)
use captain_db
use server_response
- use request_utils, only: get_status_utf8, render_jobs_links, generate_simple_pager
+ use request_utils, only: get_player_status_utf8, render_jobs_links, generate_simple_pager
implicit none
type(request)::req
@@ -170,12 +170,7 @@ contains
do i = 1, n_players
call get_player_name(players(i), player_name)
- if(is_player_busy(players(i))) then
- player_status = get_status_utf8(PLAYER_STATUS_BUSY)
- else
- player_status = get_status_utf8(PLAYER_STATUS_IDLE)
- end if
-
+ player_status = get_player_status_utf8(players(i))
one_link => html_link(req%page//"?launch="//trim(player_name), &
trim(player_status)//" "//trim(player_name))
@@ -511,12 +506,14 @@ contains
function generate_players_html() result(res)
use captain_db
+ use request_utils, only: get_status_utf8
implicit none
character(len=:), pointer::res
character(len=PLAYER_NAME_LENGTH), dimension(:), pointer::players
- integer::n, i, nsize
+ integer::n, i, nsize, pid
+ character(4)::player_status
character(len=:), pointer::one_player
n = get_player_count()
@@ -539,8 +536,20 @@ contains
res = "<h2>Existing Players</h2>"//new_line(' ')//"<ul>"
do i = 1, n
+
+ pid = get_player_id(players(i))
+ if(is_player_online(pid)) then
+ if(is_player_busy(pid)) then
+ player_status = get_status_utf8(PLAYER_STATUS_BUSY)
+ else
+ player_status = get_status_utf8(PLAYER_STATUS_IDLE)
+ end if
+ else
+ player_status = get_status_utf8(PLAYER_STATUS_OFFLINE)
+ end if
+
one_player => html_link("players/"//trim(players(i))//".html", &
- trim(players(i)))
+ trim(player_status)//" "//trim(players(i)))
res = trim(res)//new_line(' ')//"<li>"//trim(one_player)//"</li>"
deallocate(one_player)
end do
@@ -580,7 +589,12 @@ contains
n = get_instructions_count(player=pid)
allocate(character(len=(2*n*PLAYER_NAME_LENGTH + 1024)) :: res)
- res = "<h2>"//trim(player_name)//"</h2>"
+ res = "<h2>"//trim(player_name)
+ if(is_player_online(pid)) then
+ res = trim(res)//" - Online</h2>"
+ else
+ res = trim(res)//" - Offline</h2>"
+ end if
! Last checkin
call get_last_checkin_time(pid, values)