Add ranged combat area effects and admin-authored mobs
This commit is contained in:
@@ -101,6 +101,11 @@ func (h *HTTP) portalRoutes(mux *http.ServeMux) {
|
||||
return
|
||||
}
|
||||
switch req.Op {
|
||||
case "spawn-mobs":
|
||||
if _, _, _, err := game.ParseMobSpawn(req.Value); err != nil {
|
||||
fail(w, 400, err.Error())
|
||||
return
|
||||
}
|
||||
case "grant-item", "remove-item":
|
||||
if _, _, err := game.ParseItemChange(req.Value); err != nil {
|
||||
fail(w, 400, err.Error())
|
||||
|
||||
@@ -119,6 +119,41 @@ func TestControlAuthorizationAndExecution(t *testing.T) {
|
||||
if len(commands) != 1 || commands[0].Status != "completed" {
|
||||
t.Fatal("command not audited")
|
||||
}
|
||||
spawn := `{"id":"` + game.ID() + `","worldId":"control-test","op":"spawn-mobs","target":"ash_guard","value":"2,30,30","reason":"Combat playtest"}`
|
||||
before := len(w.Mobs)
|
||||
for i := 0; i < 2; i++ {
|
||||
if request("POST", "/api/control/commands", spawn, token, server.URL) != 202 {
|
||||
t.Fatal("spawn command/retry not accepted")
|
||||
}
|
||||
if err = svc.controls(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(w.Mobs) != before+2 {
|
||||
t.Fatal("spawn retry duplicated mobs")
|
||||
}
|
||||
}
|
||||
if err = lease.Release(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
nextLease, snapshot, err := db.Acquire(ctx, w)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nextLease.Release(ctx)
|
||||
var restarted game.World
|
||||
if err = json.Unmarshal(snapshot, &restarted); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = restarted.Restore(time.Now()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = NewService(&restarted, nextLease).controls(ctx); err != nil || len(restarted.Mobs) != before+2 {
|
||||
t.Fatal("spawn execution was not durable/retry safe", err)
|
||||
}
|
||||
commands, err = db.Commands(ctx, w.ID, false)
|
||||
if err != nil || len(commands) != 2 || commands[0].Status != "completed" || commands[1].Status != "completed" {
|
||||
t.Fatal("spawn audit not committed with world", err)
|
||||
}
|
||||
bad := `{"id":"` + game.ID() + `","worldId":"control-test","op":"end-world","reason":"maintenance window"}`
|
||||
if request("POST", "/api/control/commands", bad, token, server.URL) != 400 {
|
||||
t.Fatal("destructive action without confirmation")
|
||||
|
||||
Reference in New Issue
Block a user