aboutsummaryrefslogtreecommitdiff
path: root/internal/game/hardening_disconnect_combat_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/game/hardening_disconnect_combat_test.go')
-rw-r--r--internal/game/hardening_disconnect_combat_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/game/hardening_disconnect_combat_test.go b/internal/game/hardening_disconnect_combat_test.go
new file mode 100644
index 0000000..7bd6708
--- /dev/null
+++ b/internal/game/hardening_disconnect_combat_test.go
@@ -0,0 +1,31 @@
+package game
+
+import "testing"
+
+// TestDisconnectHardRemoveEndsCombat pins the P0 fix: a session hard-removed
+// while a fight is live must have that fight ended. Otherwise the combat tick
+// subscribers (keyed by character name) keep attacking and saving a detached
+// Player, which duplicates items/credits on death and can permanently lock a
+// finishing_blow mob.
+func TestDisconnectHardRemoveEndsCombat(t *testing.T) {
+ h := newHarness(t)
+ h.seedAccount("alice")
+ h.seedCharacter("alice", "alice")
+ sess, _ := h.connect("alice")
+ p := sess.Player
+
+ h.g.RunOnOwner(func() {
+ sess.StartDisconnect(1)
+ h.g.Combat.Enter(p.Name, "skeleton")
+ for i := 0; i < disconnectCombatGraceTicks+5 && len(h.g.Hub.AllSessions()) > 0; i++ {
+ h.g.DisconnectTick()
+ }
+ })
+
+ if len(h.g.Hub.AllSessions()) != 0 {
+ t.Fatal("session was not hard-removed")
+ }
+ if h.g.Combat.Get(p.Name) != nil {
+ t.Fatal("combat survived the hard remove; a ghost fight would keep saving the detached character")
+ }
+}