basic flag support
This commit is contained in:
parent
8c56389991
commit
19e94f036e
11 changed files with 134 additions and 151 deletions
55
cmd/main.go
55
cmd/main.go
|
@ -3,26 +3,16 @@ package main
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
|
||||||
"io/ioutil"
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"git.snrd.de/Spaenny/steamServer"
|
"git.snrd.de/Spaenny/steamServer"
|
||||||
"git.snrd.de/Spaenny/steamServer/postgres"
|
"git.snrd.de/Spaenny/steamServer/postgres"
|
||||||
"git.snrd.de/Spaenny/steamServer/web"
|
"git.snrd.de/Spaenny/steamServer/web"
|
||||||
|
"github.com/rumblefrog/go-a2s"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
|
||||||
AppID int `json:"AppID"`
|
|
||||||
Name string `json:"Name"`
|
|
||||||
Map string `json:"Map"`
|
|
||||||
Players int `json:"Players"`
|
|
||||||
MaxPlayers int `json:"MaxPlayers"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
dsn := "postgres://postgres:secret@postgres:5432/postgres?sslmode=disable"
|
dsn := "postgres://postgres:secret@localhost:5432/postgres?sslmode=disable"
|
||||||
|
|
||||||
store, err := postgres.NewStore(dsn)
|
store, err := postgres.NewStore(dsn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -47,35 +37,32 @@ func main() {
|
||||||
http.ListenAndServe(":3000", h)
|
http.ListenAndServe(":3000", h)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateServers(serverString string, store steamServer.Store) {
|
func updateServers(host string, store steamServer.Store) {
|
||||||
url := "http://steam-server-api:8080/server/" + serverString
|
client, err := a2s.NewClient(host)
|
||||||
|
|
||||||
reqClient := http.Client {
|
|
||||||
Timeout: time.Second * 10,
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal("Creation of client failed: %w", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := reqClient.Do(req)
|
defer client.Close()
|
||||||
|
|
||||||
|
info, err := client.QueryInfo()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Printf("Querying failed: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.Body != nil {
|
log.Printf("%s - %s\n", host, info.Name)
|
||||||
defer res.Body.Close()
|
|
||||||
|
server := steamServer.Server {
|
||||||
|
AppID: info.ID,
|
||||||
|
Name: info.Name,
|
||||||
|
Map: info.Map,
|
||||||
|
Players: info.Players,
|
||||||
|
MaxPlayers: info.MaxPlayers,
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(res.Body)
|
store.UpdateServerByQuery(&server, host)
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
server := steamServer.Server{}
|
|
||||||
json.Unmarshal([]byte(body), &server)
|
|
||||||
store.UpdateServerByQuery(&server, serverString)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -3,10 +3,10 @@ module git.snrd.de/Spaenny/steamServer
|
||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.snrd.de/Spaenny/steamserver v0.0.0-20210920125724-7e62f366e7e0
|
|
||||||
github.com/go-chi/chi v1.5.4
|
github.com/go-chi/chi v1.5.4
|
||||||
github.com/google/uuid v1.3.0
|
github.com/google/uuid v1.3.0
|
||||||
github.com/jmoiron/sqlx v1.3.4
|
github.com/jmoiron/sqlx v1.3.4
|
||||||
github.com/lib/pq v1.10.3
|
github.com/lib/pq v1.10.3
|
||||||
github.com/robfig/cron/v3 v3.0.1
|
github.com/robfig/cron/v3 v3.0.1
|
||||||
|
github.com/rumblefrog/go-a2s v1.0.1
|
||||||
)
|
)
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -1,5 +1,3 @@
|
||||||
git.snrd.de/Spaenny/steamserver v0.0.0-20210920125724-7e62f366e7e0 h1:b43+U83rjT0A+1k6MP5Muu/crGVzciaszaPGIFBXNow=
|
|
||||||
git.snrd.de/Spaenny/steamserver v0.0.0-20210920125724-7e62f366e7e0/go.mod h1:rl0ho92HJaP8HYnk2Fwqq4fWnFrVaolgiadz5iPqRWk=
|
|
||||||
github.com/go-chi/chi v1.5.4 h1:QHdzF2szwjqVV4wmByUnTcsbIg7UGaQ0tPF2t5GcAIs=
|
github.com/go-chi/chi v1.5.4 h1:QHdzF2szwjqVV4wmByUnTcsbIg7UGaQ0tPF2t5GcAIs=
|
||||||
github.com/go-chi/chi v1.5.4/go.mod h1:uaf8YgoFazUOkPBG7fxPftUylNumIev9awIWOENIuEg=
|
github.com/go-chi/chi v1.5.4/go.mod h1:uaf8YgoFazUOkPBG7fxPftUylNumIev9awIWOENIuEg=
|
||||||
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
|
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
|
||||||
|
@ -15,3 +13,5 @@ github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRU
|
||||||
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||||
|
github.com/rumblefrog/go-a2s v1.0.1 h1:0M4QUDB1Tz00tCz36r/AWB4YFO2ajksvPnd7Abzz9SE=
|
||||||
|
github.com/rumblefrog/go-a2s v1.0.1/go.mod h1:JwbTgMTRGZcWzr3T2MUfDusrJU5Bdg8biEeZzPtN0So=
|
||||||
|
|
|
@ -8,10 +8,16 @@ CREATE TABLE gamemodes (
|
||||||
name TEXT NOT NULL
|
name TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE flags (
|
||||||
|
server_ip TEXT PRIMARY KEY,
|
||||||
|
flag VARCHAR(2) NULL DEFAULT NULL,
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE servers (
|
CREATE TABLE servers (
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
region_id UUID NOT NULL REFERENCES regions(id) ON DELETE CASCADE,
|
region_id UUID NOT NULL REFERENCES regions(id) ON DELETE CASCADE,
|
||||||
gamemode_id UUID NOT NULL REFERENCES gamemodes(id) ON DELETE CASCADE,
|
gamemode_id UUID NOT NULL REFERENCES gamemodes(id) ON DELETE CASCADE,
|
||||||
|
server_id UUID NOT NULL REFERENCES flags(server_ip) ON DELETE CASCADE,
|
||||||
app_id INT NOT NULL,
|
app_id INT NOT NULL,
|
||||||
server_ip TEXT NOT NULL,
|
server_ip TEXT NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
|
|
29
postgres/flag_store.go
Normal file
29
postgres/flag_store.go
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package postgres
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.snrd.de/Spaenny/steamServer"
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FlagStore struct {
|
||||||
|
*sqlx.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FlagStore) Flag(server_ip string) (steamServer.Flag, error) {
|
||||||
|
var f steamServer.Flag
|
||||||
|
if err := s.Get(&f, `SELECT * FROM flags WHERE name = $1`, server_ip); err != nil {
|
||||||
|
return steamServer.Flag{}, fmt.Errorf("error getting flag id: %w", err)
|
||||||
|
}
|
||||||
|
return f, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FlagStore) Flags() ([]steamServer.Flag, error) {
|
||||||
|
var ff []steamServer.Flag
|
||||||
|
var query = `SELECT * FROM flags`
|
||||||
|
if err := s.Select(&ff, query); err != nil {
|
||||||
|
return []steamServer.Flag{}, fmt.Errorf("error gettings flag: %w", err)
|
||||||
|
}
|
||||||
|
return ff, nil
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ func (s *ServerStore) Server(id uuid.UUID) (steamServer.Server, error) {
|
||||||
|
|
||||||
func (s *ServerStore) Servers() ([]steamServer.Server, error) {
|
func (s *ServerStore) Servers() ([]steamServer.Server, error) {
|
||||||
var ss []steamServer.Server
|
var ss []steamServer.Server
|
||||||
var query = `SELECT * FROM servers`
|
var query = `SELECT * FROM servers ORDER BY name ASC`
|
||||||
if err := s.Select(&ss, query); err != nil {
|
if err := s.Select(&ss, query); err != nil {
|
||||||
return []steamServer.Server{}, fmt.Errorf("error gettings servers: %w", err)
|
return []steamServer.Server{}, fmt.Errorf("error gettings servers: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -32,18 +32,18 @@ func (s *ServerStore) Servers() ([]steamServer.Server, error) {
|
||||||
func (s *ServerStore) ServersByRegion(regionID uuid.UUID) ([]steamServer.Server, error) {
|
func (s *ServerStore) ServersByRegion(regionID uuid.UUID) ([]steamServer.Server, error) {
|
||||||
var ss []steamServer.Server
|
var ss []steamServer.Server
|
||||||
var query = `
|
var query = `
|
||||||
SELECT * FROM servers WHERE region_id = $1`
|
SELECT * FROM servers WHERE region_id = $1 ORDER BY name ASC`
|
||||||
if err := s.Select(&ss, query, regionID); err != nil {
|
if err := s.Select(&ss, query, regionID); err != nil {
|
||||||
return []steamServer.Server{}, fmt.Errorf("error gettings region servers: %w", err)
|
return []steamServer.Server{}, fmt.Errorf("error getting region servers: %w", err)
|
||||||
}
|
}
|
||||||
return ss, nil
|
return ss, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerStore) ServersByRegionAndGamemode(regionID uuid.UUID, gamemodeID uuid.UUID) ([]steamServer.Server, error) {
|
func (s *ServerStore) ServersByRegionAndGamemode(regionID uuid.UUID, gamemodeID uuid.UUID) ([]steamServer.Server, error) {
|
||||||
var ss []steamServer.Server
|
var ss []steamServer.Server
|
||||||
var query = `SELECT * FROM servers WHERE gamemode_id = $1 AND region_id = $2`
|
var query = `SELECT * FROM servers WHERE gamemode_id = $1 AND region_id = $2 ORDER BY name ASC`
|
||||||
if err := s.Select(&ss, query, regionID, gamemodeID); err != nil {
|
if err := s.Select(&ss, query, regionID, gamemodeID); err != nil {
|
||||||
return []steamServer.Server{}, fmt.Errorf("error gettings region servers: %w", err)
|
return []steamServer.Server{}, fmt.Errorf("error getting region and gamemode servers: %w", err)
|
||||||
}
|
}
|
||||||
return ss, nil
|
return ss, nil
|
||||||
}
|
}
|
||||||
|
@ -51,10 +51,10 @@ func (s *ServerStore) ServersByRegionAndGamemode(regionID uuid.UUID, gamemodeID
|
||||||
func (s *ServerStore) ServersByGamemode(gamemodeID uuid.UUID) ([]steamServer.Server, error) {
|
func (s *ServerStore) ServersByGamemode(gamemodeID uuid.UUID) ([]steamServer.Server, error) {
|
||||||
var ss []steamServer.Server
|
var ss []steamServer.Server
|
||||||
|
|
||||||
var query = `SELECT * FROM servers WHERE gamemode_id = $1`
|
var query = `SELECT * FROM servers WHERE gamemode_id = $1 ORDER BY name ASC`
|
||||||
|
|
||||||
if err := s.Select(&ss, query, gamemodeID); err != nil {
|
if err := s.Select(&ss, query, gamemodeID); err != nil {
|
||||||
return []steamServer.Server{}, fmt.Errorf("error gettings gamemode servers: %w", err)
|
return []steamServer.Server{}, fmt.Errorf("error getting gamemode servers: %w", err)
|
||||||
}
|
}
|
||||||
return ss, nil
|
return ss, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ func NewStore(dataSourceName string) (*Store, error) {
|
||||||
ServerStore: &ServerStore{DB: db},
|
ServerStore: &ServerStore{DB: db},
|
||||||
RegionStore: &RegionStore{DB: db},
|
RegionStore: &RegionStore{DB: db},
|
||||||
GamemodeStore: &GamemodeStore{DB: db},
|
GamemodeStore: &GamemodeStore{DB: db},
|
||||||
|
FlagStore: &FlagStore{DB: db},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,5 +31,6 @@ type Store struct {
|
||||||
*ServerStore
|
*ServerStore
|
||||||
*RegionStore
|
*RegionStore
|
||||||
*GamemodeStore
|
*GamemodeStore
|
||||||
|
*FlagStore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,12 @@ type Server struct {
|
||||||
ID uuid.UUID `db:"id"`
|
ID uuid.UUID `db:"id"`
|
||||||
RegionID uuid.UUID `db:"region_id"`
|
RegionID uuid.UUID `db:"region_id"`
|
||||||
GamemodeID uuid.UUID `db:"gamemode_id"`
|
GamemodeID uuid.UUID `db:"gamemode_id"`
|
||||||
AppID int `db:"app_id"`
|
AppID uint16 `db:"app_id"`
|
||||||
ServerIP string `db:"server_ip"`
|
ServerIP string `db:"server_ip"`
|
||||||
Name string `db:"name"`
|
Name string `db:"name"`
|
||||||
Map string `db:"map"`
|
Map string `db:"map"`
|
||||||
Players int `db:"players"`
|
Players uint8 `db:"players"`
|
||||||
MaxPlayers int `db:"max_players"`
|
MaxPlayers uint8 `db:"max_players"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Region struct {
|
type Region struct {
|
||||||
|
@ -26,6 +26,11 @@ type Gamemode struct {
|
||||||
Name string `db:"name"`
|
Name string `db:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Flag struct {
|
||||||
|
ServerIP string `db:"server_ip"`
|
||||||
|
Flag string `db:"flag"`
|
||||||
|
}
|
||||||
|
|
||||||
type ServerStore interface {
|
type ServerStore interface {
|
||||||
Server(id uuid.UUID) (Server, error)
|
Server(id uuid.UUID) (Server, error)
|
||||||
Servers() ([]Server, error)
|
Servers() ([]Server, error)
|
||||||
|
@ -40,14 +45,20 @@ type RegionStore interface {
|
||||||
Region(name string) (Region, error)
|
Region(name string) (Region, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type GamemodeStore interface {
|
type GamemodeStore interface {
|
||||||
Gamemode(name string) (Gamemode, error)
|
Gamemode(name string) (Gamemode, error)
|
||||||
Gamemodes() ([]Gamemode, error)
|
Gamemodes() ([]Gamemode, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FlagStore interface {
|
||||||
|
Flag(server_ip string) (Flag, error)
|
||||||
|
Flags() ([]Flag, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
type Store interface {
|
type Store interface {
|
||||||
ServerStore
|
ServerStore
|
||||||
RegionStore
|
RegionStore
|
||||||
GamemodeStore
|
GamemodeStore
|
||||||
|
FlagStore
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,17 @@
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link href="https://unpkg.com/tailwindcss@1.0.4/dist/tailwind.min.css" rel="stylesheet">
|
<link href="https://unpkg.com/tailwindcss@1.0.4/dist/tailwind.min.css" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
tr#content {
|
||||||
|
line-height: 0;
|
||||||
|
}
|
||||||
|
td#flag {
|
||||||
|
padding-right: 0;
|
||||||
|
}
|
||||||
|
td#name {
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body class="flex items-center justify-center" style="background: #edf2f7;">
|
<body class="flex items-center justify-center" style="background: #edf2f7;">
|
||||||
<section class="container mx-auto px-8 my-1 flex flex-wrap -m-4">
|
<section class="container mx-auto px-8 my-1 flex flex-wrap -m-4">
|
||||||
|
@ -44,10 +55,11 @@
|
||||||
|
|
||||||
{{ $gamemodes := .Gamemodes}}
|
{{ $gamemodes := .Gamemodes}}
|
||||||
{{ $servers := .Servers}}
|
{{ $servers := .Servers}}
|
||||||
|
{{ $flags := .Flags}}
|
||||||
<div class="container mx-auto px-4 sm:px-8">
|
<div class="container mx-auto px-4 sm:px-8">
|
||||||
<div class="py-8">
|
<div class="py-8">
|
||||||
<div>
|
<div>
|
||||||
<h2 class="text-2xl font-semibold leading-tight">All Regions - Serverlist</h2>
|
<h2 class="text-2xl font-semibold leading-tight">{{.Region}}</h2>
|
||||||
</div>
|
</div>
|
||||||
{{range $gamemode := $gamemodes}}
|
{{range $gamemode := $gamemodes}}
|
||||||
<div class="-mx-4 sm:-mx-8 px-4 sm:px-8 py-4 overflow-x-auto">
|
<div class="-mx-4 sm:-mx-8 px-4 sm:px-8 py-4 overflow-x-auto">
|
||||||
|
@ -55,6 +67,9 @@
|
||||||
<table class="min-w-full leading-normal">
|
<table class="min-w-full leading-normal">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||||
|
|
||||||
|
</th>
|
||||||
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||||
{{$gamemode.Name}}
|
{{$gamemode.Name}}
|
||||||
</th>
|
</th>
|
||||||
|
@ -70,8 +85,15 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{{range $server := $servers}}
|
{{range $server := $servers}}
|
||||||
{{if eq $gamemode.ID $server.GamemodeID}}
|
{{if eq $gamemode.ID $server.GamemodeID}}
|
||||||
<tr>
|
<tr id="content">
|
||||||
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
|
<td class="px-5 border-b border-gray-200 bg-white" id="flag">
|
||||||
|
{{range $flag := $flags}}
|
||||||
|
{{if eq $server.ServerIP $flag.ServerIP}}
|
||||||
|
<img src="https://flagcdn.com/16x12/{{$flag.Flag}}.png">
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
</td>
|
||||||
|
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm" id="name">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<div class="ml-3">
|
<div class="ml-3">
|
||||||
<a href="steam://connect/{{$server.ServerIP}}" class="text-gray-900 whitespace-no-wrap">{{$server.Name}}</a>
|
<a href="steam://connect/{{$server.ServerIP}}" class="text-gray-900 whitespace-no-wrap">{{$server.Name}}</a>
|
||||||
|
|
|
@ -1,98 +0,0 @@
|
||||||
<html lang="en"><head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<link href="https://unpkg.com/tailwindcss@1.0.4/dist/tailwind.min.css" rel="stylesheet">
|
|
||||||
</head>
|
|
||||||
<body class="flex items-center justify-center" style="background: #edf2f7;">
|
|
||||||
<section class="container mx-auto px-8 my-1 flex flex-wrap -m-4">
|
|
||||||
<div class="p-2 md:w-40">
|
|
||||||
<a href="/" class="flex items-center p-4 bg-blue-200 rounded-lg shadow-xs cursor-pointer hover:bg-blue-500 hover:text-gray-100">
|
|
||||||
<div>
|
|
||||||
<p class=" text-xs font-medium ">All Regions</p>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="p-2 md:w-40">
|
|
||||||
<a href="/america" class="flex items-center p-4 bg-blue-200 rounded-lg shadow-xs cursor-pointer hover:bg-blue-500 hover:text-gray-100">
|
|
||||||
<div>
|
|
||||||
<p class=" text-xs font-medium ">North America</p>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="p-2 md:w-40">
|
|
||||||
<a href="/europe" class="flex items-center p-4 bg-blue-200 rounded-lg shadow-xs cursor-pointer hover:bg-blue-500 hover:text-gray-100">
|
|
||||||
<div>
|
|
||||||
<p class=" text-xs font-medium ">Europe</p>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="p-2 md:w-40">
|
|
||||||
<a href="#" class="flex items-center p-4 bg-blue-200 rounded-lg shadow-xs cursor-pointer hover:bg-blue-500 hover:text-gray-100">
|
|
||||||
<div>
|
|
||||||
<p class=" text-xs font-medium ">Australia</p>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="p-2 md:w-40">
|
|
||||||
<a href="#" class="flex items-center p-4 bg-blue-200 rounded-lg shadow-xs cursor-pointer hover:bg-blue-500 hover:text-gray-100">
|
|
||||||
<div>
|
|
||||||
<p class=" text-xs font-medium ">Asia</p>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{{ $gamemodes := .Gamemodes}}
|
|
||||||
{{ $servers := .Servers}}
|
|
||||||
<div class="container mx-auto px-4 sm:px-8">
|
|
||||||
<div class="py-8">
|
|
||||||
<div>
|
|
||||||
<h2 class="text-2xl font-semibold leading-tight">{{.Region}}</h2>
|
|
||||||
</div>
|
|
||||||
{{range $gamemode := $gamemodes}}
|
|
||||||
<div class="-mx-4 sm:-mx-8 px-4 sm:px-8 py-4 overflow-x-auto">
|
|
||||||
<div class="inline-block min-w-full shadow rounded-lg overflow-hidden">
|
|
||||||
<table class="min-w-full leading-normal">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
|
||||||
{{$gamemode.Name}}
|
|
||||||
</th>
|
|
||||||
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
|
||||||
Map
|
|
||||||
</th>
|
|
||||||
<th class="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
|
||||||
Players
|
|
||||||
</th>
|
|
||||||
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{{range $server := $servers}}
|
|
||||||
{{if eq $gamemode.ID $server.GamemodeID}}
|
|
||||||
<tr>
|
|
||||||
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
|
|
||||||
<div class="flex items-center">
|
|
||||||
<div class="ml-3">
|
|
||||||
<a href="steam://connect/{{$server.ServerIP}}" class="text-gray-900 whitespace-no-wrap">{{$server.Name}}</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
|
|
||||||
<p class="text-gray-900 whitespace-no-wrap">{{$server.Map}}</p>
|
|
||||||
</td>
|
|
||||||
<td class="px-5 py-5 border-b border-gray-200 bg-white text-sm">
|
|
||||||
<p class="text-gray-900 whitespace-no-wrap">{{$server.Players}}/{{$server.MaxPlayers}}</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -32,8 +32,10 @@ type Handler struct {
|
||||||
|
|
||||||
func (h *Handler) Home() http.HandlerFunc {
|
func (h *Handler) Home() http.HandlerFunc {
|
||||||
type data struct {
|
type data struct {
|
||||||
|
Region string
|
||||||
Servers []steamServer.Server
|
Servers []steamServer.Server
|
||||||
Gamemodes []steamServer.Gamemode
|
Gamemodes []steamServer.Gamemode
|
||||||
|
Flags []steamServer.Flag
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl := template.Must(template.ParseFiles("templates/home.html"))
|
tmpl := template.Must(template.ParseFiles("templates/home.html"))
|
||||||
|
@ -49,9 +51,17 @@ func (h *Handler) Home() http.HandlerFunc {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ff, err := h.store.Flags()
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
tmpl.Execute(w, data {
|
tmpl.Execute(w, data {
|
||||||
|
Region: "All Regions - Serverlist",
|
||||||
Servers: ss,
|
Servers: ss,
|
||||||
Gamemodes: gg,
|
Gamemodes: gg,
|
||||||
|
Flags: ff,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,9 +71,10 @@ func (h *Handler) Europe() http.HandlerFunc {
|
||||||
Region string
|
Region string
|
||||||
Servers []steamServer.Server
|
Servers []steamServer.Server
|
||||||
Gamemodes []steamServer.Gamemode
|
Gamemodes []steamServer.Gamemode
|
||||||
|
Flags []steamServer.Flag
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl := template.Must(template.ParseFiles("templates/region.html"))
|
tmpl := template.Must(template.ParseFiles("templates/home.html"))
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
reg, err := h.store.Region("Europe")
|
reg, err := h.store.Region("Europe")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -81,11 +92,17 @@ func (h *Handler) Europe() http.HandlerFunc {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ff, err := h.store.Flags()
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
tmpl.Execute(w, data {
|
tmpl.Execute(w, data {
|
||||||
Region: "Europe",
|
Region: "Europe",
|
||||||
Servers: ss,
|
Servers: ss,
|
||||||
Gamemodes: gg,
|
Gamemodes: gg,
|
||||||
|
Flags: ff,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,9 +114,10 @@ func (h *Handler) America() http.HandlerFunc {
|
||||||
Region string
|
Region string
|
||||||
Servers []steamServer.Server
|
Servers []steamServer.Server
|
||||||
Gamemodes []steamServer.Gamemode
|
Gamemodes []steamServer.Gamemode
|
||||||
|
Flags []steamServer.Flag
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl := template.Must(template.ParseFiles("templates/region.html"))
|
tmpl := template.Must(template.ParseFiles("templates/home.html"))
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
reg, err := h.store.Region("North America")
|
reg, err := h.store.Region("North America")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -118,10 +136,16 @@ func (h *Handler) America() http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ff, err := h.store.Flags()
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
tmpl.Execute(w, data {
|
tmpl.Execute(w, data {
|
||||||
Region: "North America",
|
Region: "North America",
|
||||||
Servers: ss,
|
Servers: ss,
|
||||||
Gamemodes: gg,
|
Gamemodes: gg,
|
||||||
|
Flags: ff,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue