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
@@ -2,13 +2,13 @@ package gameserver
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"gac-hkrpg-go/internal/common"
|
||||
kcplib "gac-hkrpg-go/pkg/kcp"
|
||||
goproto "gac-hkrpg-go/protocol/proto"
|
||||
)
|
||||
@@ -36,21 +36,25 @@ func TestGatewayHandshakeAndLogin(t *testing.T) {
|
||||
}
|
||||
t.Logf("handshake ok: conv=%d token=%d", conv, token)
|
||||
|
||||
// 2. configure the SERVER-side session held by the gateway
|
||||
player, _ := common.LoadFreesrData()
|
||||
if player == nil {
|
||||
player = &common.FreesrData{}
|
||||
}
|
||||
// 2. Verify the gateway loaded the player data itself.
|
||||
serverSession := gw.GetSession(conv)
|
||||
if serverSession == nil {
|
||||
t.Fatal("gateway did not register the session")
|
||||
}
|
||||
serverSession.SetJSON(player)
|
||||
if serverSession.JSON() == nil {
|
||||
t.Fatal("gateway session has no player data")
|
||||
}
|
||||
|
||||
// 3. send PlayerGetTokenCsReq (cmd 5)
|
||||
reqID := uint16(goproto.CmdIDByName["PlayerGetTokenCsReq"])
|
||||
rspID := uint16(goproto.CmdIDByName["PlayerGetTokenScRsp"])
|
||||
if err := client.sendCmd(reqID, nil); err != nil {
|
||||
// Synthetic fields exercise non-empty requests without storing account data.
|
||||
tokenRequest := &goproto.PlayerGetTokenCsReq{AccountUid: "52022", Token: strings.Repeat("x", 32), Uid: playerUID, Platform: 3}
|
||||
tokenBody, err := proto.Marshal(tokenRequest)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := client.sendCmd(reqID, tokenBody); err != nil {
|
||||
t.Fatalf("send cmd: %v", err)
|
||||
}
|
||||
|
||||
@@ -71,6 +75,69 @@ func TestGatewayHandshakeAndLogin(t *testing.T) {
|
||||
}
|
||||
t.Logf("login token ok: retcode=%d uid=%d msg=%q", rsp.Retcode, rsp.Uid, rsp.Msg)
|
||||
|
||||
// 4. Login must also round-trip through the same UDP/KCP session.
|
||||
loginReq := &goproto.PlayerLoginCsReq{LoginRandom: 123456, Signature: strings.Repeat("x", 768)}
|
||||
loginBody, err := proto.Marshal(loginReq)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := client.sendCmd(uint16(goproto.CmdIDByName["PlayerLoginCsReq"]), loginBody); err != nil {
|
||||
t.Fatalf("send player login: %v", err)
|
||||
}
|
||||
cmdID, body, err = client.recvCmd(3 * time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("no player login response: %v", err)
|
||||
}
|
||||
if want := uint16(goproto.CmdIDByName["PlayerLoginScRsp"]); cmdID != want {
|
||||
t.Fatalf("login response command: got %d want %d", cmdID, want)
|
||||
}
|
||||
loginRsp := &goproto.PlayerLoginScRsp{}
|
||||
if err := proto.Unmarshal(body, loginRsp); err != nil {
|
||||
t.Fatalf("decode login response: %v", err)
|
||||
}
|
||||
if loginRsp.Retcode != 0 || loginRsp.LoginRandom != loginReq.LoginRandom || loginRsp.BasicInfo == nil {
|
||||
t.Fatalf("invalid player login response: %v", loginRsp)
|
||||
}
|
||||
|
||||
// The Android client asks for level rewards before login finish.
|
||||
if err := client.sendCmd(uint16(goproto.CmdIDByName["GetLevelRewardTakenListCsReq"]), nil); err != nil {
|
||||
t.Fatalf("send level rewards request: %v", err)
|
||||
}
|
||||
cmdID, body, err = client.recvCmd(3 * time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("no level rewards response: %v", err)
|
||||
}
|
||||
if want := uint16(goproto.CmdIDByName["GetLevelRewardTakenListScRsp"]); cmdID != want {
|
||||
t.Fatalf("level rewards response command: got %d want %d", cmdID, want)
|
||||
}
|
||||
levelRsp := &goproto.GetLevelRewardTakenListScRsp{}
|
||||
if err := proto.Unmarshal(body, levelRsp); err != nil || levelRsp.Retcode != 0 {
|
||||
t.Fatalf("invalid level rewards response: %v / %v", levelRsp, err)
|
||||
}
|
||||
|
||||
if err := client.sendCmd(uint16(goproto.CmdIDByName["PlayerLoginFinishCsReq"]), nil); err != nil {
|
||||
t.Fatalf("send login finish: %v", err)
|
||||
}
|
||||
seenFinish := false
|
||||
for i := 0; i < 3 && !seenFinish; i++ {
|
||||
cmdID, body, err = client.recvCmd(3 * time.Second)
|
||||
if err != nil {
|
||||
t.Fatalf("no login finish response: %v", err)
|
||||
}
|
||||
if cmdID == uint16(goproto.CmdIDByName["PlayerLoginFinishScRsp"]) {
|
||||
finishRsp := &goproto.PlayerLoginFinishScRsp{}
|
||||
if err := proto.Unmarshal(body, finishRsp); err != nil || finishRsp.Retcode != 0 {
|
||||
t.Fatalf("invalid login finish response: %v / %v", finishRsp, err)
|
||||
}
|
||||
seenFinish = true
|
||||
} else if cmdID != uint16(goproto.CmdIDByName["ContentPackageSyncDataScNotify"]) {
|
||||
t.Fatalf("unexpected login finish packet: %d", cmdID)
|
||||
}
|
||||
}
|
||||
if !seenFinish {
|
||||
t.Fatal("login finish response missing")
|
||||
}
|
||||
|
||||
// 4. exercise the SceneCastSkill fix: attack with no real monsters ->
|
||||
// must NOT enter battle (no battle_info in the response)
|
||||
skillReqID := uint16(goproto.CmdIDByName["SceneCastSkillCsReq"])
|
||||
|
||||
Reference in new issue
Block a user