fix: improve endgame clock and gameplay stability
This commit is contained in:
1 parent
ce6aabfc55
commit
658298ee86
46 files changed
+1915
-99
No files matched your search
@@ -0,0 +1,46 @@
|
||||
package sdkserver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gac-hkrpg-go/internal/common"
|
||||
)
|
||||
|
||||
func TestFakeTimeWindowCommand(t *testing.T) {
|
||||
chdirRepoRootSDK(t)
|
||||
t.Setenv("GAC_CONFIG", "server.json")
|
||||
t.Setenv("GAC_GAME_CLOCK_STATE_FILE", filepath.Join(t.TempDir(), "clock.json"))
|
||||
call := func(command string) map[string]any {
|
||||
t.Helper()
|
||||
w := httptest.NewRecorder()
|
||||
apiFakeTimeCommand(w, command)
|
||||
var response map[string]any
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return response
|
||||
}
|
||||
if result := call("/faketime window 1000 2000"); result["success"] != true || result["unix_seconds"] != float64(1500) {
|
||||
t.Fatalf("window command: %v", result)
|
||||
}
|
||||
before, err := common.ReadGameClock()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result := call("/faketime window 2000 1000"); result["success"] != false {
|
||||
t.Fatalf("invalid window accepted: %v", result)
|
||||
}
|
||||
after, err := common.ReadGameClock()
|
||||
if err != nil || before != after {
|
||||
t.Fatalf("invalid window changed clock: %+v %v", after, err)
|
||||
}
|
||||
if result := call("/faketime off"); result["success"] != true {
|
||||
t.Fatalf("reset: %v", result)
|
||||
}
|
||||
if state, err := common.ReadGameClock(); err != nil || state.WindowEndMS != 0 {
|
||||
t.Fatalf("reset did not remove window: %+v %v", state, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user