ALL_WORLDS excluding 17

This commit is contained in:
41666 2025-04-08 13:07:54 -07:00
parent 4df53b3dbe
commit 99dac60e1c
13 changed files with 218 additions and 19 deletions

51
.air.toml Normal file
View file

@ -0,0 +1,51 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html", "css", "js"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
main_only = false
time = false
[misc]
clean_on_exit = false
[proxy]
app_port = 8769
enabled = true
proxy_port = 8001
[screen]
clear_on_rebuild = false
keep_scroll = true

View file

@ -32,7 +32,7 @@ func (c *CommonClient) Request(ctx context.Context, path string) (*http.Response
if res.StatusCode != http.StatusOK { if res.StatusCode != http.StatusOK {
body, err := io.ReadAll(res.Body) body, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
body = []byte(fmt.Sprintf("<< unable to read (%s) >>", err)) body = fmt.Appendf(nil, "<< unable to read (%s) >>", err)
} }
return res, fmt.Errorf("http request not 200, got: %d\nresponse body: %s", res.StatusCode, string(body)) return res, fmt.Errorf("http request not 200, got: %d\nresponse body: %s", res.StatusCode, string(body))
} }

View file

@ -31,7 +31,7 @@ func main() {
allWorldsEnv := os.Getenv("ALL_WORLDS") allWorldsEnv := os.Getenv("ALL_WORLDS")
if allWorldsEnv == "" { if allWorldsEnv == "" {
allWorldsEnv = "1,10,17,19,40,1000,2000" allWorldsEnv = "1,10,19,40,1000,2000"
} }
AllWorlds = envListToU32(allWorldsEnv) AllWorlds = envListToU32(allWorldsEnv)

55
cmd/ps2.live/index.go Normal file
View file

@ -0,0 +1,55 @@
package main
import (
"context"
"log"
"net/http"
"time"
metagameps2live "git.sapphic.engineer/ps2.live/ps2.live/clients/metagame.ps2.live"
"git.sapphic.engineer/ps2.live/ps2.live/types"
)
type indexData struct {
Worlds []indexWorld
}
type indexWorld struct {
ID uint32
Presentable presentableServer
Population *types.AggPopWorld
Metagame *types.MetagameWorld
}
func handleIndex(rw http.ResponseWriter, req *http.Request) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
metagame := metagameps2live.NewMetagameClient()
mgWorlds, err := metagame.GetAllWorlds(ctx)
if err != nil {
log.Println("metagame worlds fetch failed")
rw.WriteHeader(500)
rw.Write([]byte("internal server error"))
}
worlds := make([]indexWorld, len(mgWorlds))
for i, world := range mgWorlds {
worlds[i] = indexWorld{
ID: world.ID,
Presentable: idToPresentable(world.ID),
Metagame: world,
Population: ,
}
}
t := templates.Lookup("index")
t.Execute(rw, templateData{
Index: indexData{
Worlds: worlds,
},
Meta: templateMeta{
Title: "aaaa",
},
})
}

View file

@ -13,6 +13,7 @@ var (
type templateData struct { type templateData struct {
Meta templateMeta Meta templateMeta
Index indexData
} }
type templateMeta struct { type templateMeta struct {
@ -25,28 +26,15 @@ func main() {
addr = ":8000" addr = ":8000"
} }
// fmt.Println(templates.Templates())
mux := http.NewServeMux() mux := http.NewServeMux()
mux.HandleFunc("/worlds/{id}", handleWorld) mux.HandleFunc("/worlds/{id}", handleWorld)
mux.Handle("/", http.FileServerFS(StaticFileFS)) mux.Handle("/", http.FileServerFS(StaticFileFS))
mux.HandleFunc("/{$}", handleIndex) mux.HandleFunc("/{$}", handleIndex)
log.Println("Listening on", addr)
err := http.ListenAndServe(addr, mux) err := http.ListenAndServe(addr, mux)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
} }
func handleIndex(rw http.ResponseWriter, req *http.Request) {
t := templates.Lookup("index")
t.Execute(rw, templateData{
Meta: templateMeta{
Title: "aaaa",
},
})
}
func handleWorld(rw http.ResponseWriter, req *http.Request) {
}

View file

@ -22,7 +22,7 @@
<div>{{ .Totals.NC }}</div> <div>{{ .Totals.NC }}</div>
<div>{{ .Totals.TR }}</div> <div>{{ .Totals.TR }}</div>
</div> </div>
{{ template "bar-chart" . }} {{ template "components/bar-chart" . }}
</div> </div>
</div> </div>
</div> </div>

93
cmd/ps2.live/utils.go Normal file
View file

@ -0,0 +1,93 @@
package main
import (
"fmt"
"time"
)
var (
idToPresentableMap = map[uint32]presentableServer{
1: presentableServer{
Name: "Connery",
Region: "US-W",
Platform: "PC",
},
10: presentableServer{
Name: "Miller",
Region: "EU",
Platform: "PC",
},
17: presentableServer{
Name: "Emerald",
Region: "US-E",
Platform: "PC",
},
19: presentableServer{
Name: "Jaeger",
Region: "US-E",
Platform: "PC",
},
40: presentableServer{
Name: "SolTech",
Region: "JP",
Platform: "PC",
},
1000: presentableServer{
Name: "Genudine",
Region: "US-E",
Platform: "PS4",
},
2000: presentableServer{
Name: "Ceres",
Region: "EU",
Platform: "PS4",
},
// After 8 April
999901: presentableServer{
Name: "Osprey",
Region: "US-W", // dunno which haha
Platform: "PC",
},
999910: presentableServer{
Name: "Wainwright",
Region: "EU",
Platform: "PC",
},
999917: presentableServer{
Name: "Osprey",
Region: "US-E",
Platform: "PC",
},
}
nameChangeDate = time.Date(2025, 4, 8, 7, 0, 0, 0, time.UTC) // Midnight DBG time
nameChanged = !time.Now().Before(nameChangeDate)
)
type presentableServer struct {
Name string
Region string
Platform string
}
func idToPresentable(id uint32) (ps presentableServer) {
var ok bool
if nameChanged {
ps, ok = idToPresentableMap[id+999900]
if ok {
return ps
}
}
ps, ok = idToPresentableMap[id]
if !ok {
return presentableServer{
Name: fmt.Sprintf("??? (ID: %d)", id),
Region: "??",
Platform: "??",
}
}
return ps
}

7
cmd/ps2.live/world.go Normal file
View file

@ -0,0 +1,7 @@
package main
import "net/http"
func handleWorld(rw http.ResponseWriter, req *http.Request) {
}

2
justfile Normal file
View file

@ -0,0 +1,2 @@
dev cmd inner_port="8769":
ADDR=":{{inner_port}}" air -build.cmd="go build -o ./tmp/main ./cmd/{{cmd}}" -proxy.app_port="{{inner_port}}"

View file

@ -2,5 +2,7 @@
pkgs.mkShell { pkgs.mkShell {
buildInputs = with pkgs; [ buildInputs = with pkgs; [
go go
air
just
]; ];
} }

1
tmp/build-errors.log Normal file
View file

@ -0,0 +1 @@
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1

BIN
tmp/main Executable file

Binary file not shown.