fix: sync current handlers, repair relic data and restore visible launcher consoles
This commit is contained in:
1 parent
163d4433e6
commit
74f3c4411b
46 files changed
+4599
-1402
No files matched your search
@@ -50,20 +50,25 @@ func apiRoot(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
cfg, err := common.LoadRuntimeConfig()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
writeJSON(w, map[string]any{
|
||||
"name": "GaC-hkrpg-go API Gateway",
|
||||
"version": "4.6.53",
|
||||
"version": cfg.ClientVersion,
|
||||
"status": 200,
|
||||
"description": "Backend connection endpoints for freesr-data, persistent, and GaC-Srtool",
|
||||
"endpoints": map[string]string{
|
||||
"status": "GET /api/status",
|
||||
"freesr": "GET, POST /api/freesr",
|
||||
"avatars": "GET, POST /api/freesr/avatars",
|
||||
"persistent": "GET, POST /api/persistent",
|
||||
"exrank_toggle": "POST /api/exrank/toggle",
|
||||
"avatar_rank": "POST /api/avatar/rank",
|
||||
"status": "GET /api/status",
|
||||
"freesr": "GET, POST /api/freesr",
|
||||
"avatars": "GET, POST /api/freesr/avatars",
|
||||
"persistent": "GET, POST /api/persistent",
|
||||
"exrank_toggle": "POST /api/exrank/toggle",
|
||||
"avatar_rank": "POST /api/avatar/rank",
|
||||
"avatar_max_all": "POST /api/avatar/max_all",
|
||||
"teleport": "POST /api/teleport",
|
||||
"teleport": "POST /api/teleport",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package sdkserver
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"gac-hkrpg-go/internal/common"
|
||||
goproto "gac-hkrpg-go/protocol/proto"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func TestConfiguredDispatchAndGateway(t *testing.T) {
|
||||
// Fixture endpoints must appear on the wire instead of any local defaults.
|
||||
cfg := common.RuntimeConfig{PublicSDKURL: "https://sdk.example.invalid/prefix", PublicGameHost: "game.example.invalid", GamePort: 32123}
|
||||
w := httptest.NewRecorder()
|
||||
queryDispatch(w, httptest.NewRequest("GET", "/query_dispatch", nil), cfg)
|
||||
raw, err := base64.StdEncoding.DecodeString(w.Body.String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var dispatch goproto.Dispatch
|
||||
if err := proto.Unmarshal(raw, &dispatch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(dispatch.RegionList) != 1 || dispatch.RegionList[0].DispatchUrl != cfg.PublicSDKURL+"/query_gateway" {
|
||||
t.Fatalf("wrong dispatch: %v", &dispatch)
|
||||
}
|
||||
state := &appState{runtime: cfg, hotfixMap: map[string]VersionConfig{"fixture": {}}}
|
||||
w = httptest.NewRecorder()
|
||||
queryGateway(state)(w, httptest.NewRequest("GET", "/query_gateway?version=fixture", nil))
|
||||
raw, err = base64.StdEncoding.DecodeString(w.Body.String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var gateway goproto.Gateserver
|
||||
if err := proto.Unmarshal(raw, &gateway); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if gateway.Ip != cfg.PublicGameHost || gateway.Port != uint32(cfg.GamePort) {
|
||||
t.Fatalf("wrong gateway: %v", &gateway)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// Package sdkserver is the Go port of the Rust sdkserver: HTTP dispatch +
|
||||
// auth + SRTools save upload, listening on :21000.
|
||||
// auth + SRTools save upload, using the shared runtime configuration.
|
||||
package sdkserver
|
||||
|
||||
import (
|
||||
@@ -11,13 +11,12 @@ import (
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"gac-hkrpg-go/internal/common"
|
||||
google "google.golang.org/protobuf/proto"
|
||||
|
||||
goproto "gac-hkrpg-go/protocol/proto"
|
||||
)
|
||||
|
||||
const Port = 21000
|
||||
|
||||
// VersionConfig is one entry of versions.json.
|
||||
type VersionConfig struct {
|
||||
AssetBundleURL string `json:"asset_bundle_url"`
|
||||
@@ -27,6 +26,7 @@ type VersionConfig struct {
|
||||
}
|
||||
|
||||
type appState struct {
|
||||
runtime common.RuntimeConfig
|
||||
mu sync.Mutex
|
||||
hotfixMap map[string]VersionConfig
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func fetchHotfix(version, dispatchSeed string) (VersionConfig, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// parseVersionString extracts region/branch, e.g. "OSBETAWin4.6.51" -> OS,BETA.
|
||||
// parseVersionString extracts region/branch, e.g. a version with the OSBETAWin prefix -> OS,BETA.
|
||||
func parseVersionString(s string) (string, string) {
|
||||
branches := []string{"PREbeta", "BETA", "PROD", "DEV", "PRE", "GM", "CECREATION"}
|
||||
if len(s) < 2 {
|
||||
@@ -154,14 +154,14 @@ func writeJSON(w http.ResponseWriter, v any) {
|
||||
_ = json.NewEncoder(w).Encode(v)
|
||||
}
|
||||
|
||||
func queryDispatch(w http.ResponseWriter, _ *http.Request) {
|
||||
func queryDispatch(w http.ResponseWriter, _ *http.Request, runtime common.RuntimeConfig) {
|
||||
rsp := &goproto.Dispatch{
|
||||
Retcode: 0,
|
||||
RegionList: []*goproto.RegionInfo{{
|
||||
Name: "GaC hkrpg GO",
|
||||
Title: "GaC hkrpg GO",
|
||||
EnvType: "9",
|
||||
DispatchUrl: fmt.Sprintf("http://127.0.0.1:%d/query_gateway", Port),
|
||||
DispatchUrl: runtime.PublicSDKURL + "/query_gateway",
|
||||
}},
|
||||
}
|
||||
bin, err := google.Marshal(rsp)
|
||||
@@ -186,8 +186,8 @@ func queryGateway(state *appState) http.HandlerFunc {
|
||||
cfg := state.getOrInsertHotfix(version, seed)
|
||||
|
||||
rsp := &goproto.Gateserver{
|
||||
Ip: "127.0.0.1",
|
||||
Port: 23301,
|
||||
Ip: state.runtime.PublicGameHost,
|
||||
Port: uint32(state.runtime.GamePort),
|
||||
AssetBundleUrl: cfg.AssetBundleURL,
|
||||
AssetBundleUrlB: cfg.AssetBundleURL,
|
||||
ExResourceUrl: cfg.ExResourceURL,
|
||||
@@ -344,11 +344,15 @@ func srToolsSave(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Listen starts the HTTP sdkserver.
|
||||
func Listen() error {
|
||||
state := &appState{hotfixMap: loadHotfix()}
|
||||
runtime, err := common.LoadRuntimeConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
state := &appState{hotfixMap: loadHotfix(), runtime: runtime}
|
||||
Log(fmt.Sprintf("loaded %d hotfix versions", len(state.hotfixMap)))
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/query_dispatch", queryDispatch)
|
||||
mux.HandleFunc("/query_dispatch", func(w http.ResponseWriter, r *http.Request) { queryDispatch(w, r, runtime) })
|
||||
mux.HandleFunc("/query_gateway", queryGateway(state))
|
||||
mux.HandleFunc("/{product_name}/mdk/shield/api/login", func(w http.ResponseWriter, r *http.Request) { loginReply(w) })
|
||||
mux.HandleFunc("/{product_name}/mdk/shield/api/verify", func(w http.ResponseWriter, r *http.Request) { loginReply(w) })
|
||||
@@ -366,9 +370,9 @@ func Listen() error {
|
||||
notFound(w, r)
|
||||
})
|
||||
|
||||
addr := fmt.Sprintf("0.0.0.0:%d", Port)
|
||||
addr := runtime.SDKAddress()
|
||||
Log("sdkserver is listening at " + addr)
|
||||
Log(fmt.Sprintf("REST API Gateway is live at http://localhost:%d/ (for GaC-Srtool)", Port))
|
||||
Log(fmt.Sprintf("REST API Gateway is live at %s/ (for GaC-Srtool)", runtime.PublicSDKURL))
|
||||
return http.ListenAndServe(addr, mux)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user