From cdef950e34ab424773a8dbbe2daf40f11aff29da Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Thu, 16 Jun 2022 17:36:11 +0800 Subject: [PATCH] fix: 服务器bug, 当未登录时,handle is nil 会导致崩溃。 --- cmd/gameserver/service/game.go | 5 +++-- cmd/test/action/TestAction.go | 18 ++++++++++++++++-- cmd/test/main.go | 2 +- cmd/test/service/TestClient.go | 6 +++--- conf/conf.yml | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/cmd/gameserver/service/game.go b/cmd/gameserver/service/game.go index f9bfc2f..4d11a12 100644 --- a/cmd/gameserver/service/game.go +++ b/cmd/gameserver/service/game.go @@ -118,10 +118,11 @@ func (s *GameServer) OnTimer(conn components.IConnection) { } func (s *GameServer) OnClose(conn components.IConnection) { - agent := s.GetConnManage().GetConn(conn.GetID()) + connID := conn.GetID() + agent := s.GetConnManage().GetConn(connID) if agent == nil { return } agent.(*Agent).OnClose() - s.GetConnManage().DelConn(conn.GetID()) + s.GetConnManage().DelConn(connID) } diff --git a/cmd/test/action/TestAction.go b/cmd/test/action/TestAction.go index 37a7921..460c728 100644 --- a/cmd/test/action/TestAction.go +++ b/cmd/test/action/TestAction.go @@ -48,14 +48,28 @@ func RoleEndBattleRsp(role *models.RoleTestModel, msg components.IMessage) { func EquipmentDelRsp(role *models.RoleTestModel, msg components.IMessage) { } -func EquipmentAddRsp(role *models.RoleTestModel, msg components.IMessage) { +func HeroUpLevelRsp(role *models.RoleTestModel, msg components.IMessage) { } -func HeroUpLevelRsp(role *models.RoleTestModel, msg components.IMessage) { +func EmailListRsp(role *models.RoleTestModel, msg components.IMessage) { +} + +func EmailDrawRsp(role *models.RoleTestModel, msg components.IMessage) { +} + +func EmailCheckRsp(role *models.RoleTestModel, msg components.IMessage) { } +func EmailDelRsp(role *models.RoleTestModel, msg components.IMessage) { +} func DisConnectNty(role *models.RoleTestModel, msg components.IMessage) { } +func RoleUpdatePropertyNty(role *models.RoleTestModel, msg components.IMessage) { +} + func RoleUpdateItemsNty(role *models.RoleTestModel, msg components.IMessage) { } + +func EquipmentAddNty(role *models.RoleTestModel, msg components.IMessage) { +} diff --git a/cmd/test/main.go b/cmd/test/main.go index 4cee58f..8d8ab13 100644 --- a/cmd/test/main.go +++ b/cmd/test/main.go @@ -26,7 +26,7 @@ func main() { time.Sleep(2 * time.Second) for { //tc.SendPB(pb.ProtoCode_HeartReq, nil) - tc.SendPB(pb.ProtoCode_HeroUpLevelRpc, pp) + tc.SendPB(pb.ProtoCode_HeroUpLevelRpc, pp, 0) time.Sleep(5 * time.Second) } diff --git a/cmd/test/service/TestClient.go b/cmd/test/service/TestClient.go index dfa18d0..f226050 100644 --- a/cmd/test/service/TestClient.go +++ b/cmd/test/service/TestClient.go @@ -55,7 +55,7 @@ func (t *TestClient) OnLoginQuery(msg components.IMessage) { Device: "test-create", } r, _ := proto.Marshal(req) - t.GetConn().SendSuccess(uint32(pb.ProtoCode_CreateRpc), r) + t.GetConn().SendSuccess(uint32(pb.ProtoCode_CreateRpc), r, 0) return } } @@ -107,7 +107,7 @@ func (t *TestClient) Login(token string) { t.Token = token head := &components.PBHead{ Length: 0, - Cmd: uint32(pb.ProtoCode_LoginRpc), + Cmd: uint32(2), ErrCode: 0, PreField: 0, } @@ -116,5 +116,5 @@ func (t *TestClient) Login(token string) { Device: "test-login", } l, _ := proto.Marshal(loginReq) - t.Send(head.Cmd, l) + t.Send(head.Cmd, l, 0) } diff --git a/conf/conf.yml b/conf/conf.yml index 057b915..f3da05d 100644 --- a/conf/conf.yml +++ b/conf/conf.yml @@ -66,7 +66,7 @@ logconf: permit: "0660" test_client: - ip: "192.168.0.100" + ip: "192.168.0.206" port: 8849 count: 1 # Conn: -- libgit2 0.21.2