2019-12-30 14:27:49 +00:00
< script >
import { onMount } from 'svelte';
import axios from 'axios'
import moment from 'moment'
2020-05-14 18:22:09 +00:00
import { onInterval } from '../util'
2019-12-30 14:27:49 +00:00
import { loggedIn } from '../UserState'
import Alert from '../components/Alert'
import AccountLink from '../components/AccountLink'
import CharacterLink from '../components/CharacterLink'
import EmpireStats from '../components/EmpireStats'
export let ready;
let stats;
let alert;
2020-05-12 21:06:22 +00:00
let players;
2020-05-13 20:57:07 +00:00
let next_update = 30;
let next_update_label = "";
let empire_stats;
2019-12-30 14:27:49 +00:00
function format_account(account) {
return `< a href = "/user/$ { account . id } " > ${ account . username } </ a > `
}
onMount(async () => {
2020-05-13 20:57:07 +00:00
await update_stats()
update_stats_label()
2020-05-14 18:22:09 +00:00
// we must use this wrapper to ensure setIntervals are cleaned
// up on view change
onInterval(update_stats_label, 1000)
2019-12-30 14:27:49 +00:00
ready = true
})
2020-05-13 20:57:07 +00:00
async function update_stats_label() {
if (next_update == 1) {
next_update = 30;
await update_stats()
empire_stats.refresh()
} else {
next_update -= 1
}
if (next_update == 1)
next_update_label = next_update + " second"
else
next_update_label = next_update + " seconds"
}
async function update_stats() {
try {
const resp = await axios.get("/api/stats")
stats = resp.data;
players = stats.players
stats.empires = stats.empires
alert.message("")
} catch (e) {
console.log(e)
alert.message("Failed to fetch stats from server")
}
}
2019-12-30 14:27:49 +00:00
< / script >
< svelte:head >
2019-12-31 14:46:34 +00:00
< title > PSForever Portal< / title >
2019-12-30 14:27:49 +00:00
< / svelte:head >
< Alert bind:this = { alert } / >
{ #if stats }
< div class = "row" >
2020-05-13 20:57:07 +00:00
< div class = "col-md-8 col-12" >
< h1 > PSForever Live Server< / h1 >
< div class = "row" >
< div class = "col" >
{ #if ! $loggedIn }
2020-05-17 15:04:19 +00:00
<!-- <a class="btn btn - primary" href="/login" role="button">Login</a>
< a class = "btn btn-primary" href = "/register" role = "button" > Create Account< / a > -->
2020-05-13 20:57:07 +00:00
{ /if }
< a class = "btn btn-secondary" href = "https://docs.google.com/document/d/1ZMx1NUylVZCXJNRyhkuVWT0eUKSVYu0JXsU-y3f93BY/edit" role = "button" > Setup Instructions< / a >
< / div >
< / div > < br / >
< p >
< strong > Server address:< / strong > < code > play.psforever.net:51000< / code >
< button type = "button" class = "btn btn-sm" class:btn-success = { stats . status == "UP" }
2020-05-12 21:06:22 +00:00
class:btn-danger={ stats . status != "UP" } >Server { stats . status } </ button >< br />
2020-05-13 20:57:07 +00:00
< strong > Last character created:</ strong > < CharacterLink character = { stats . last . character } / > (< span title = { moment ( stats . last . character . created ). format ( `MMMM Do YYYY, h:mm:ss a` )} > { moment ( stats . last . character . created ). fromNow ()} </span > )< br />
< strong > # Accounts:</ strong > { stats . accounts . toLocaleString ()} < br />
< strong > # Characters:</ strong > { stats . characters . toLocaleString ()}
< / p >
< / div >
< / div >
2020-05-12 21:06:22 +00:00
2020-05-13 20:57:07 +00:00
< div class = "row" >
< div class = "col-12" >
< h2 > Online Players ({ players . length } )</ h2 >
< p > Next update in { next_update_label } </ p >
< / div >
2020-05-14 17:51:22 +00:00
< div class = "col-md-4 col-12 mt-md-0 mt-3" >
{ #if stats . empires }
< EmpireStats bind:this = { empire_stats } bind:stats= { stats . empires } />
{ /if }
< / div >
2020-05-13 20:57:07 +00:00
< div class = "col-md-8 col-12" >
< div class = "row" >
{ #each players as char , i }
< div class = "col-md-4 col-12" >< CharacterLink character = { char } / ></ div >
{ /each }
< / div >
< / div >
2019-12-30 14:27:49 +00:00
< / div >
{ /if }