From 7384fca4837c8b7dad7ec0093b0df4801b4ef4eb Mon Sep 17 00:00:00 2001 From: huangxiaolei <1782360262@qq.com> Date: Mon, 5 Dec 2022 23:05:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gs/game/command_controller.go | 14 +-- gs/game/command_gm.go | 18 ++-- gs/game/command_manager.go | 17 ++- gs/game/game_manager.go | 56 +++++----- gs/game/local_event_manager.go | 8 +- gs/game/route_manager.go | 139 +++++++++++++------------ gs/game/tick_manager.go | 54 +++++----- gs/game/user_chat.go | 2 +- gs/game/user_login.go | 148 +++++++++++++++------------ gs/game/user_multiplayer.go | 55 +++------- gs/game/user_scene.go | 5 +- gs/game/user_social.go | 2 +- protocol/cmd/cmd_id_proto_obj_map.go | 3 + 13 files changed, 251 insertions(+), 270 deletions(-) diff --git a/gs/game/command_controller.go b/gs/game/command_controller.go index 174507e8..f38c3936 100644 --- a/gs/game/command_controller.go +++ b/gs/game/command_controller.go @@ -32,8 +32,6 @@ func (c *CommandManager) OpCommand(cmd *CommandMessage) { // TeleportCommand 传送玩家命令 // tp [-u ] [-s ] -x -y -z func (c *CommandManager) TeleportCommand(cmd *CommandMessage) { - game := c.gameManager - // 执行者如果不是玩家则必须输入目标UID player, ok := cmd.Executor.(*model.Player) if !ok && cmd.Args["u"] == "" { @@ -61,7 +59,7 @@ func (c *CommandManager) TeleportCommand(cmd *CommandMessage) { var uid uint64 if uid, err = strconv.ParseUint(v, 10, 32); err != nil { // 判断目标用户是否在线 - if user := game.userManager.GetOnlineUser(uint32(uid)); user != nil { + if user := USER_MANAGER.GetOnlineUser(uint32(uid)); user != nil { target = user // 防止覆盖用户指定过的sceneId if target.SceneId != sceneId { @@ -135,8 +133,6 @@ func (c *CommandManager) TeleportCommand(cmd *CommandMessage) { // GiveCommand 给予物品命令 // give [-u ] [-c ] -i func (c *CommandManager) GiveCommand(cmd *CommandMessage) { - game := c.gameManager - // 执行者如果不是玩家则必须输入目标UID player, ok := cmd.Executor.(*model.Player) if !ok && cmd.Args["u"] == "" { @@ -168,7 +164,7 @@ func (c *CommandManager) GiveCommand(cmd *CommandMessage) { var uid uint64 if uid, err = strconv.ParseUint(v, 10, 32); err != nil { // 判断目标用户是否在线 - if user := game.userManager.GetOnlineUser(uint32(uid)); user != nil { + if user := USER_MANAGER.GetOnlineUser(uint32(uid)); user != nil { target = user } else { c.SendMessage(player, "目标玩家不在线,UID: %v。", v) @@ -208,7 +204,7 @@ func (c *CommandManager) GiveCommand(cmd *CommandMessage) { switch mode { case "once": // 判断是否为物品 - _, ok := game.GetAllItemDataConfig()[int32(itemId)] + _, ok := GAME_MANAGER.GetAllItemDataConfig()[int32(itemId)] if ok { // 给予玩家物品 c.GMAddUserItem(target.PlayerID, itemId, count) @@ -216,7 +212,7 @@ func (c *CommandManager) GiveCommand(cmd *CommandMessage) { return } // 判断是否为武器 - _, ok = game.GetAllWeaponDataConfig()[int32(itemId)] + _, ok = GAME_MANAGER.GetAllWeaponDataConfig()[int32(itemId)] if ok { // 给予玩家武器 c.GMAddUserWeapon(target.PlayerID, itemId, count) @@ -225,7 +221,7 @@ func (c *CommandManager) GiveCommand(cmd *CommandMessage) { } // 判断是否为角色 - _, ok = game.GetAllAvatarDataConfig()[int32(itemId)] + _, ok = GAME_MANAGER.GetAllAvatarDataConfig()[int32(itemId)] if ok { // 给予玩家武器 c.GMAddUserAvatar(target.PlayerID, itemId) diff --git a/gs/game/command_gm.go b/gs/game/command_gm.go index 5945e769..0d7cd673 100644 --- a/gs/game/command_gm.go +++ b/gs/game/command_gm.go @@ -7,12 +7,12 @@ import ( // GMTeleportPlayer 传送玩家 func (c *CommandManager) GMTeleportPlayer(userId, sceneId uint32, posX, posY, posZ float64) { - player := c.gameManager.userManager.GetOnlineUser(userId) + player := USER_MANAGER.GetOnlineUser(userId) if player == nil { logger.LOG.Error("player is nil, uid: %v", userId) return } - c.gameManager.TeleportPlayer(player, sceneId, &model.Vector{ + GAME_MANAGER.TeleportPlayer(player, sceneId, &model.Vector{ X: posX, Y: posY, Z: posZ, @@ -21,7 +21,7 @@ func (c *CommandManager) GMTeleportPlayer(userId, sceneId uint32, posX, posY, po // GMAddUserItem 给予玩家物品 func (c *CommandManager) GMAddUserItem(userId, itemId, itemCount uint32) { - c.gameManager.AddUserItem(userId, []*UserItem{ + GAME_MANAGER.AddUserItem(userId, []*UserItem{ { ItemId: itemId, ChangeCount: itemCount, @@ -34,40 +34,40 @@ func (c *CommandManager) GMAddUserWeapon(userId, itemId, itemCount uint32) { // 武器数量 for i := uint32(0); i < itemCount; i++ { // 给予武器 - c.gameManager.AddUserWeapon(userId, itemId) + GAME_MANAGER.AddUserWeapon(userId, itemId) } } // GMAddUserAvatar 给予玩家角色 func (c *CommandManager) GMAddUserAvatar(userId, avatarId uint32) { - player := c.gameManager.userManager.GetOnlineUser(userId) + player := USER_MANAGER.GetOnlineUser(userId) if player == nil { logger.LOG.Error("player is nil, uid: %v", userId) return } // 添加角色 - c.gameManager.AddUserAvatar(userId, avatarId) + GAME_MANAGER.AddUserAvatar(userId, avatarId) // TODO 设置角色 等以后做到角色升级之类的再说 //avatar := player.AvatarMap[avatarId] } // GMAddUserAllItem 给予玩家所有物品 func (c *CommandManager) GMAddUserAllItem(userId, itemCount uint32) { - for itemId := range c.gameManager.GetAllItemDataConfig() { + for itemId := range GAME_MANAGER.GetAllItemDataConfig() { c.GMAddUserItem(userId, uint32(itemId), itemCount) } } // GMAddUserAllWeapon 给予玩家所有武器 func (c *CommandManager) GMAddUserAllWeapon(userId, itemCount uint32) { - for itemId := range c.gameManager.GetAllWeaponDataConfig() { + for itemId := range GAME_MANAGER.GetAllWeaponDataConfig() { c.GMAddUserWeapon(userId, uint32(itemId), itemCount) } } // GMAddUserAllAvatar 给予玩家所有角色 func (c *CommandManager) GMAddUserAllAvatar(userId uint32) { - for avatarId := range c.gameManager.GetAllAvatarDataConfig() { + for avatarId := range GAME_MANAGER.GetAllAvatarDataConfig() { c.GMAddUserAvatar(userId, uint32(avatarId)) } } diff --git a/gs/game/command_manager.go b/gs/game/command_manager.go index d49e0da3..16f4b39d 100644 --- a/gs/game/command_manager.go +++ b/gs/game/command_manager.go @@ -9,6 +9,8 @@ import ( "hk4e/protocol/proto" ) +// 命令管理器 + // CommandPerm 命令权限等级 // 0 为普通玩家 数越大权限越大 type CommandPerm uint8 @@ -38,27 +40,24 @@ type CommandManager struct { commandFuncRouter map[string]CommandFunc // 记录命令处理函数 commandPermMap map[string]CommandPerm // 记录命令对应的权限 commandTextInput chan *CommandMessage // 传输要处理的命令文本 - - gameManager *GameManager } // NewCommandManager 新建命令管理器 -func NewCommandManager(g *GameManager) *CommandManager { +func NewCommandManager() *CommandManager { r := new(CommandManager) // 创建一个公共的开放世界的AI - g.OnRegOk(false, &proto.SetPlayerBornDataReq{AvatarId: 10000007, NickName: "System"}, 1, 0) - r.system = g.userManager.GetOnlineUser(1) + GAME_MANAGER.OnRegOk(false, &proto.SetPlayerBornDataReq{AvatarId: 10000007, NickName: "System"}, 1, 0) + r.system = USER_MANAGER.GetOnlineUser(1) // 开放大世界 r.system.SceneLoadState = model.SceneEnterDone r.system.DbState = model.DbNormal - g.worldManager.InitBigWorld(r.system) + WORLD_MANAGER.InitBigWorld(r.system) // 初始化 r.commandTextInput = make(chan *CommandMessage, 1000) r.InitRouter() // 初始化路由 - r.gameManager = g return r } @@ -221,14 +220,12 @@ func (c *CommandManager) ExecCommand(cmd *CommandMessage) { // SendMessage 发送消息 func (c *CommandManager) SendMessage(executor any, msg string, param ...any) { - game := c.gameManager - // 根据相应的类型发送消息 switch executor.(type) { case *model.Player: // 玩家类型 player := executor.(*model.Player) - game.SendPrivateChat(c.system, player, fmt.Sprintf(msg, param...)) + GAME_MANAGER.SendPrivateChat(c.system, player, fmt.Sprintf(msg, param...)) case string: // GM接口等 //str := executor.(string) diff --git a/gs/game/game_manager.go b/gs/game/game_manager.go index 5fdea66a..d56609e0 100644 --- a/gs/game/game_manager.go +++ b/gs/game/game_manager.go @@ -11,25 +11,23 @@ import ( "hk4e/protocol/proto" ) -var GAME *GameManager = nil +var GAME_MANAGER *GameManager = nil +var LOCAL_EVENT_MANAGER *LocalEventManager = nil +var ROUTE_MANAGER *RouteManager = nil +var USER_MANAGER *UserManager = nil +var WORLD_MANAGER *WorldManager = nil +var TICK_MANAGER *TickManager = nil +var COMMAND_MANAGER *CommandManager = nil type GameManager struct { dao *dao.Dao netMsgInput chan *cmd.NetMsg netMsgOutput chan *cmd.NetMsg snowflake *alg.SnowflakeWorker - // 本地事件队列管理器 - localEventManager *LocalEventManager - // 接口路由管理器 - routeManager *RouteManager // 用户管理器 userManager *UserManager // 世界管理器 worldManager *WorldManager - // 游戏服务器定时帧管理器 - tickManager *TickManager - // 命令管理器 - commandManager *CommandManager } func NewGameManager(dao *dao.Dao, netMsgInput chan *cmd.NetMsg, netMsgOutput chan *cmd.NetMsg) (r *GameManager) { @@ -38,34 +36,36 @@ func NewGameManager(dao *dao.Dao, netMsgInput chan *cmd.NetMsg, netMsgOutput cha r.netMsgInput = netMsgInput r.netMsgOutput = netMsgOutput r.snowflake = alg.NewSnowflakeWorker(1) - r.localEventManager = NewLocalEventManager(r) - r.routeManager = NewRouteManager(r) - r.userManager = NewUserManager(dao, r.localEventManager.localEventChan) + GAME_MANAGER = r + LOCAL_EVENT_MANAGER = NewLocalEventManager() + ROUTE_MANAGER = NewRouteManager() + r.userManager = NewUserManager(dao, LOCAL_EVENT_MANAGER.localEventChan) + USER_MANAGER = r.userManager r.worldManager = NewWorldManager(r.snowflake) - r.tickManager = NewTickManager(r) - r.commandManager = NewCommandManager(r) - GAME = r + WORLD_MANAGER = r.worldManager + TICK_MANAGER = NewTickManager() + COMMAND_MANAGER = NewCommandManager() return r } func (g *GameManager) Start() { - g.routeManager.InitRoute() - g.userManager.StartAutoSaveUser() + ROUTE_MANAGER.InitRoute() + USER_MANAGER.StartAutoSaveUser() go func() { for { select { case netMsg := <-g.netMsgOutput: // 接收客户端消息 - g.routeManager.RouteHandle(netMsg) - case <-g.tickManager.ticker.C: + ROUTE_MANAGER.RouteHandle(netMsg) + case <-TICK_MANAGER.ticker.C: // 游戏服务器定时帧 - g.tickManager.OnGameServerTick() - case localEvent := <-g.localEventManager.localEventChan: + TICK_MANAGER.OnGameServerTick() + case localEvent := <-LOCAL_EVENT_MANAGER.localEventChan: // 处理本地事件 - g.localEventManager.LocalEventHandle(localEvent) - case command := <-g.commandManager.commandTextInput: + LOCAL_EVENT_MANAGER.LocalEventHandle(localEvent) + case command := <-COMMAND_MANAGER.commandTextInput: // 处理传入的命令 (普通玩家 GM命令) - g.commandManager.HandleCommand(command) + COMMAND_MANAGER.HandleCommand(command) } } }() @@ -73,14 +73,14 @@ func (g *GameManager) Start() { func (g *GameManager) Stop() { // 保存玩家数据 - g.userManager.SaveUser() + USER_MANAGER.SaveUser() //g.worldManager.worldStatic.SaveTerrain() } -// 发送消息给客户端 +// SendMsg 发送消息给客户端 func (g *GameManager) SendMsg(cmdId uint16, userId uint32, clientSeq uint32, payloadMsg pb.Message) { - if userId < 100000000 { + if userId < 100000000 || payloadMsg == nil { return } netMsg := new(cmd.NetMsg) @@ -106,7 +106,7 @@ func (g *GameManager) DisconnectPlayer(userId uint32) { g.SendMsg(cmd.ServerDisconnectClientNotify, userId, 0, new(proto.ServerDisconnectClientNotify)) } -// 踢出玩家 +// KickPlayer 踢出玩家 func (g *GameManager) KickPlayer(userId uint32) { info := new(gm.KickPlayerInfo) info.UserId = userId diff --git a/gs/game/local_event_manager.go b/gs/game/local_event_manager.go index e2a89f40..c6695335 100644 --- a/gs/game/local_event_manager.go +++ b/gs/game/local_event_manager.go @@ -14,13 +14,11 @@ type LocalEvent struct { type LocalEventManager struct { localEventChan chan *LocalEvent - gameManager *GameManager } -func NewLocalEventManager(gameManager *GameManager) (r *LocalEventManager) { +func NewLocalEventManager() (r *LocalEventManager) { r = new(LocalEventManager) r.localEventChan = make(chan *LocalEvent, 1000) - r.gameManager = gameManager return r } @@ -28,9 +26,9 @@ func (l *LocalEventManager) LocalEventHandle(localEvent *LocalEvent) { switch localEvent.EventId { case LoadLoginUserFromDbFinish: playerLoginInfo := localEvent.Msg.(*PlayerLoginInfo) - l.gameManager.OnLoginOk(playerLoginInfo.UserId, playerLoginInfo.Player, playerLoginInfo.ClientSeq) + GAME_MANAGER.OnLoginOk(playerLoginInfo.UserId, playerLoginInfo.Player, playerLoginInfo.ClientSeq) case CheckUserExistOnRegFromDbFinish: playerRegInfo := localEvent.Msg.(*PlayerRegInfo) - l.gameManager.OnRegOk(playerRegInfo.Exist, playerRegInfo.Req, playerRegInfo.UserId, playerRegInfo.ClientSeq) + GAME_MANAGER.OnRegOk(playerRegInfo.Exist, playerRegInfo.Req, playerRegInfo.UserId, playerRegInfo.ClientSeq) } } diff --git a/gs/game/route_manager.go b/gs/game/route_manager.go index cb2df806..7594c78f 100644 --- a/gs/game/route_manager.go +++ b/gs/game/route_manager.go @@ -13,14 +13,12 @@ import ( type HandlerFunc func(player *model.Player, payloadMsg pb.Message) type RouteManager struct { - gameManager *GameManager // k:cmdId v:HandlerFunc handlerFuncRouteMap map[uint16]HandlerFunc } -func NewRouteManager(gameManager *GameManager) (r *RouteManager) { +func NewRouteManager() (r *RouteManager) { r = new(RouteManager) - r.gameManager = gameManager r.handlerFuncRouteMap = make(map[uint16]HandlerFunc) return r } @@ -35,11 +33,11 @@ func (r *RouteManager) doRoute(cmdId uint16, userId uint32, clientSeq uint32, pa logger.LOG.Error("no route for msg, cmdId: %v", cmdId) return } - player := r.gameManager.userManager.GetOnlineUser(userId) + player := USER_MANAGER.GetOnlineUser(userId) if player == nil { logger.LOG.Error("player is nil, uid: %v", userId) // 临时为了调试便捷搞的重连 生产环境请务必去除 不然新用户会一直重连不能进入 - //r.gameManager.ReconnectPlayer(userId) + //GAME_MANAGER.ReconnectPlayer(userId) return } player.ClientSeq = clientSeq @@ -47,66 +45,67 @@ func (r *RouteManager) doRoute(cmdId uint16, userId uint32, clientSeq uint32, pa } func (r *RouteManager) InitRoute() { - r.registerRouter(cmd.UnionCmdNotify, r.gameManager.UnionCmdNotify) - r.registerRouter(cmd.MassiveEntityElementOpBatchNotify, r.gameManager.MassiveEntityElementOpBatchNotify) - r.registerRouter(cmd.ToTheMoonEnterSceneReq, r.gameManager.ToTheMoonEnterSceneReq) - r.registerRouter(cmd.PlayerSetPauseReq, r.gameManager.PlayerSetPauseReq) - r.registerRouter(cmd.EnterSceneReadyReq, r.gameManager.EnterSceneReadyReq) - r.registerRouter(cmd.PathfindingEnterSceneReq, r.gameManager.PathfindingEnterSceneReq) - r.registerRouter(cmd.GetScenePointReq, r.gameManager.GetScenePointReq) - r.registerRouter(cmd.GetSceneAreaReq, r.gameManager.GetSceneAreaReq) - r.registerRouter(cmd.SceneInitFinishReq, r.gameManager.SceneInitFinishReq) - r.registerRouter(cmd.EnterSceneDoneReq, r.gameManager.EnterSceneDoneReq) - r.registerRouter(cmd.EnterWorldAreaReq, r.gameManager.EnterWorldAreaReq) - r.registerRouter(cmd.PostEnterSceneReq, r.gameManager.PostEnterSceneReq) - r.registerRouter(cmd.TowerAllDataReq, r.gameManager.TowerAllDataReq) - r.registerRouter(cmd.SceneTransToPointReq, r.gameManager.SceneTransToPointReq) - r.registerRouter(cmd.MarkMapReq, r.gameManager.MarkMapReq) - r.registerRouter(cmd.ChangeAvatarReq, r.gameManager.ChangeAvatarReq) - r.registerRouter(cmd.SetUpAvatarTeamReq, r.gameManager.SetUpAvatarTeamReq) - r.registerRouter(cmd.ChooseCurAvatarTeamReq, r.gameManager.ChooseCurAvatarTeamReq) - r.registerRouter(cmd.GetGachaInfoReq, r.gameManager.GetGachaInfoReq) - r.registerRouter(cmd.DoGachaReq, r.gameManager.DoGachaReq) - r.registerRouter(cmd.QueryPathReq, r.gameManager.QueryPathReq) - r.registerRouter(cmd.CombatInvocationsNotify, r.gameManager.CombatInvocationsNotify) - r.registerRouter(cmd.AbilityInvocationsNotify, r.gameManager.AbilityInvocationsNotify) - r.registerRouter(cmd.ClientAbilityInitFinishNotify, r.gameManager.ClientAbilityInitFinishNotify) - r.registerRouter(cmd.EvtDoSkillSuccNotify, r.gameManager.EvtDoSkillSuccNotify) - r.registerRouter(cmd.ClientAbilityChangeNotify, r.gameManager.ClientAbilityChangeNotify) - r.registerRouter(cmd.EntityAiSyncNotify, r.gameManager.EntityAiSyncNotify) - r.registerRouter(cmd.WearEquipReq, r.gameManager.WearEquipReq) - r.registerRouter(cmd.ChangeGameTimeReq, r.gameManager.ChangeGameTimeReq) - r.registerRouter(cmd.GetPlayerSocialDetailReq, r.gameManager.GetPlayerSocialDetailReq) - r.registerRouter(cmd.SetPlayerBirthdayReq, r.gameManager.SetPlayerBirthdayReq) - r.registerRouter(cmd.SetNameCardReq, r.gameManager.SetNameCardReq) - r.registerRouter(cmd.SetPlayerSignatureReq, r.gameManager.SetPlayerSignatureReq) - r.registerRouter(cmd.SetPlayerNameReq, r.gameManager.SetPlayerNameReq) - r.registerRouter(cmd.SetPlayerHeadImageReq, r.gameManager.SetPlayerHeadImageReq) - r.registerRouter(cmd.GetAllUnlockNameCardReq, r.gameManager.GetAllUnlockNameCardReq) - r.registerRouter(cmd.GetPlayerFriendListReq, r.gameManager.GetPlayerFriendListReq) - r.registerRouter(cmd.GetPlayerAskFriendListReq, r.gameManager.GetPlayerAskFriendListReq) - r.registerRouter(cmd.AskAddFriendReq, r.gameManager.AskAddFriendReq) - r.registerRouter(cmd.DealAddFriendReq, r.gameManager.DealAddFriendReq) - r.registerRouter(cmd.GetOnlinePlayerListReq, r.gameManager.GetOnlinePlayerListReq) - r.registerRouter(cmd.PlayerApplyEnterMpReq, r.gameManager.PlayerApplyEnterMpReq) - r.registerRouter(cmd.PlayerApplyEnterMpResultReq, r.gameManager.PlayerApplyEnterMpResultReq) - r.registerRouter(cmd.PlayerGetForceQuitBanInfoReq, r.gameManager.PlayerGetForceQuitBanInfoReq) - r.registerRouter(cmd.GetShopmallDataReq, r.gameManager.GetShopmallDataReq) - r.registerRouter(cmd.GetShopReq, r.gameManager.GetShopReq) - r.registerRouter(cmd.BuyGoodsReq, r.gameManager.BuyGoodsReq) - r.registerRouter(cmd.McoinExchangeHcoinReq, r.gameManager.McoinExchangeHcoinReq) - r.registerRouter(cmd.AvatarChangeCostumeReq, r.gameManager.AvatarChangeCostumeReq) - r.registerRouter(cmd.AvatarWearFlycloakReq, r.gameManager.AvatarWearFlycloakReq) - r.registerRouter(cmd.PullRecentChatReq, r.gameManager.PullRecentChatReq) - r.registerRouter(cmd.PullPrivateChatReq, r.gameManager.PullPrivateChatReq) - r.registerRouter(cmd.PrivateChatReq, r.gameManager.PrivateChatReq) - r.registerRouter(cmd.ReadPrivateChatReq, r.gameManager.ReadPrivateChatReq) - r.registerRouter(cmd.PlayerChatReq, r.gameManager.PlayerChatReq) - r.registerRouter(cmd.BackMyWorldReq, r.gameManager.BackMyWorldReq) - r.registerRouter(cmd.ChangeWorldToSingleModeReq, r.gameManager.ChangeWorldToSingleModeReq) - r.registerRouter(cmd.SceneKickPlayerReq, r.gameManager.SceneKickPlayerReq) - r.registerRouter(cmd.ChangeMpTeamAvatarReq, r.gameManager.ChangeMpTeamAvatarReq) - r.registerRouter(cmd.SceneAvatarStaminaStepReq, r.gameManager.SceneAvatarStaminaStepReq) + r.registerRouter(cmd.UnionCmdNotify, GAME_MANAGER.UnionCmdNotify) + r.registerRouter(cmd.MassiveEntityElementOpBatchNotify, GAME_MANAGER.MassiveEntityElementOpBatchNotify) + r.registerRouter(cmd.ToTheMoonEnterSceneReq, GAME_MANAGER.ToTheMoonEnterSceneReq) + r.registerRouter(cmd.PlayerSetPauseReq, GAME_MANAGER.PlayerSetPauseReq) + r.registerRouter(cmd.EnterSceneReadyReq, GAME_MANAGER.EnterSceneReadyReq) + r.registerRouter(cmd.PathfindingEnterSceneReq, GAME_MANAGER.PathfindingEnterSceneReq) + r.registerRouter(cmd.GetScenePointReq, GAME_MANAGER.GetScenePointReq) + r.registerRouter(cmd.GetSceneAreaReq, GAME_MANAGER.GetSceneAreaReq) + r.registerRouter(cmd.SceneInitFinishReq, GAME_MANAGER.SceneInitFinishReq) + r.registerRouter(cmd.EnterSceneDoneReq, GAME_MANAGER.EnterSceneDoneReq) + r.registerRouter(cmd.EnterWorldAreaReq, GAME_MANAGER.EnterWorldAreaReq) + r.registerRouter(cmd.PostEnterSceneReq, GAME_MANAGER.PostEnterSceneReq) + r.registerRouter(cmd.TowerAllDataReq, GAME_MANAGER.TowerAllDataReq) + r.registerRouter(cmd.SceneTransToPointReq, GAME_MANAGER.SceneTransToPointReq) + r.registerRouter(cmd.MarkMapReq, GAME_MANAGER.MarkMapReq) + r.registerRouter(cmd.ChangeAvatarReq, GAME_MANAGER.ChangeAvatarReq) + r.registerRouter(cmd.SetUpAvatarTeamReq, GAME_MANAGER.SetUpAvatarTeamReq) + r.registerRouter(cmd.ChooseCurAvatarTeamReq, GAME_MANAGER.ChooseCurAvatarTeamReq) + r.registerRouter(cmd.GetGachaInfoReq, GAME_MANAGER.GetGachaInfoReq) + r.registerRouter(cmd.DoGachaReq, GAME_MANAGER.DoGachaReq) + r.registerRouter(cmd.QueryPathReq, GAME_MANAGER.QueryPathReq) + r.registerRouter(cmd.CombatInvocationsNotify, GAME_MANAGER.CombatInvocationsNotify) + r.registerRouter(cmd.AbilityInvocationsNotify, GAME_MANAGER.AbilityInvocationsNotify) + r.registerRouter(cmd.ClientAbilityInitFinishNotify, GAME_MANAGER.ClientAbilityInitFinishNotify) + r.registerRouter(cmd.EvtDoSkillSuccNotify, GAME_MANAGER.EvtDoSkillSuccNotify) + r.registerRouter(cmd.ClientAbilityChangeNotify, GAME_MANAGER.ClientAbilityChangeNotify) + r.registerRouter(cmd.EntityAiSyncNotify, GAME_MANAGER.EntityAiSyncNotify) + r.registerRouter(cmd.WearEquipReq, GAME_MANAGER.WearEquipReq) + r.registerRouter(cmd.ChangeGameTimeReq, GAME_MANAGER.ChangeGameTimeReq) + r.registerRouter(cmd.GetPlayerSocialDetailReq, GAME_MANAGER.GetPlayerSocialDetailReq) + r.registerRouter(cmd.SetPlayerBirthdayReq, GAME_MANAGER.SetPlayerBirthdayReq) + r.registerRouter(cmd.SetNameCardReq, GAME_MANAGER.SetNameCardReq) + r.registerRouter(cmd.SetPlayerSignatureReq, GAME_MANAGER.SetPlayerSignatureReq) + r.registerRouter(cmd.SetPlayerNameReq, GAME_MANAGER.SetPlayerNameReq) + r.registerRouter(cmd.SetPlayerHeadImageReq, GAME_MANAGER.SetPlayerHeadImageReq) + r.registerRouter(cmd.GetAllUnlockNameCardReq, GAME_MANAGER.GetAllUnlockNameCardReq) + r.registerRouter(cmd.GetPlayerFriendListReq, GAME_MANAGER.GetPlayerFriendListReq) + r.registerRouter(cmd.GetPlayerAskFriendListReq, GAME_MANAGER.GetPlayerAskFriendListReq) + r.registerRouter(cmd.AskAddFriendReq, GAME_MANAGER.AskAddFriendReq) + r.registerRouter(cmd.DealAddFriendReq, GAME_MANAGER.DealAddFriendReq) + r.registerRouter(cmd.GetOnlinePlayerListReq, GAME_MANAGER.GetOnlinePlayerListReq) + r.registerRouter(cmd.PlayerApplyEnterMpReq, GAME_MANAGER.PlayerApplyEnterMpReq) + r.registerRouter(cmd.PlayerApplyEnterMpResultReq, GAME_MANAGER.PlayerApplyEnterMpResultReq) + r.registerRouter(cmd.PlayerGetForceQuitBanInfoReq, GAME_MANAGER.PlayerGetForceQuitBanInfoReq) + r.registerRouter(cmd.GetShopmallDataReq, GAME_MANAGER.GetShopmallDataReq) + r.registerRouter(cmd.GetShopReq, GAME_MANAGER.GetShopReq) + r.registerRouter(cmd.BuyGoodsReq, GAME_MANAGER.BuyGoodsReq) + r.registerRouter(cmd.McoinExchangeHcoinReq, GAME_MANAGER.McoinExchangeHcoinReq) + r.registerRouter(cmd.AvatarChangeCostumeReq, GAME_MANAGER.AvatarChangeCostumeReq) + r.registerRouter(cmd.AvatarWearFlycloakReq, GAME_MANAGER.AvatarWearFlycloakReq) + r.registerRouter(cmd.PullRecentChatReq, GAME_MANAGER.PullRecentChatReq) + r.registerRouter(cmd.PullPrivateChatReq, GAME_MANAGER.PullPrivateChatReq) + r.registerRouter(cmd.PrivateChatReq, GAME_MANAGER.PrivateChatReq) + r.registerRouter(cmd.ReadPrivateChatReq, GAME_MANAGER.ReadPrivateChatReq) + r.registerRouter(cmd.PlayerChatReq, GAME_MANAGER.PlayerChatReq) + r.registerRouter(cmd.BackMyWorldReq, GAME_MANAGER.BackMyWorldReq) + r.registerRouter(cmd.ChangeWorldToSingleModeReq, GAME_MANAGER.ChangeWorldToSingleModeReq) + r.registerRouter(cmd.SceneKickPlayerReq, GAME_MANAGER.SceneKickPlayerReq) + r.registerRouter(cmd.ChangeMpTeamAvatarReq, GAME_MANAGER.ChangeMpTeamAvatarReq) + r.registerRouter(cmd.SceneAvatarStaminaStepReq, GAME_MANAGER.SceneAvatarStaminaStepReq) + r.registerRouter(cmd.JoinPlayerSceneReq, GAME_MANAGER.JoinPlayerSceneReq) } func (r *RouteManager) RouteHandle(netMsg *cmd.NetMsg) { @@ -114,14 +113,14 @@ func (r *RouteManager) RouteHandle(netMsg *cmd.NetMsg) { case cmd.NormalMsg: r.doRoute(netMsg.CmdId, netMsg.UserId, netMsg.ClientSeq, netMsg.PayloadMessage) case cmd.UserRegNotify: - r.gameManager.OnReg(netMsg.UserId, netMsg.ClientSeq, netMsg.PayloadMessage) + GAME_MANAGER.OnReg(netMsg.UserId, netMsg.ClientSeq, netMsg.PayloadMessage) case cmd.UserLoginNotify: - r.gameManager.OnLogin(netMsg.UserId, netMsg.ClientSeq) + GAME_MANAGER.OnLogin(netMsg.UserId, netMsg.ClientSeq) case cmd.UserOfflineNotify: - r.gameManager.OnUserOffline(netMsg.UserId) + GAME_MANAGER.OnUserOffline(netMsg.UserId) case cmd.ClientRttNotify: - r.gameManager.ClientRttNotify(netMsg.UserId, netMsg.ClientRtt) + GAME_MANAGER.ClientRttNotify(netMsg.UserId, netMsg.ClientRtt) case cmd.ClientTimeNotify: - r.gameManager.ClientTimeNotify(netMsg.UserId, netMsg.ClientTime) + GAME_MANAGER.ClientTimeNotify(netMsg.UserId, netMsg.ClientTime) } } diff --git a/gs/game/tick_manager.go b/gs/game/tick_manager.go index dc6d027f..76db3204 100644 --- a/gs/game/tick_manager.go +++ b/gs/game/tick_manager.go @@ -14,16 +14,14 @@ import ( // 游戏服务器定时帧管理器 type TickManager struct { - ticker *time.Ticker - tickCount uint64 - gameManager *GameManager + ticker *time.Ticker + tickCount uint64 } -func NewTickManager(gameManager *GameManager) (r *TickManager) { +func NewTickManager() (r *TickManager) { r = new(TickManager) r.ticker = time.NewTicker(time.Millisecond * 100) logger.LOG.Info("game server tick start at: %v", time.Now().UnixMilli()) - r.gameManager = gameManager return r } @@ -73,21 +71,21 @@ func (t *TickManager) onTickHour(now int64) { } func (t *TickManager) onTick10Minute(now int64) { - for _, world := range t.gameManager.worldManager.worldMap { + for _, world := range WORLD_MANAGER.worldMap { for _, player := range world.playerMap { // 蓝球粉球 - t.gameManager.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 223, ChangeCount: 1}}, true, 0) - t.gameManager.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 224, ChangeCount: 1}}, true, 0) + GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 223, ChangeCount: 1}}, true, 0) + GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 224, ChangeCount: 1}}, true, 0) } } } func (t *TickManager) onTickMinute(now int64) { //t.gameManager.ServerAnnounceNotify(100, "test123") - for _, world := range t.gameManager.worldManager.worldMap { + for _, world := range WORLD_MANAGER.worldMap { for _, player := range world.playerMap { // 随机物品 - allItemDataConfig := t.gameManager.GetAllItemDataConfig() + allItemDataConfig := GAME_MANAGER.GetAllItemDataConfig() count := random.GetRandomInt32(0, 4) i := int32(0) for itemId := range allItemDataConfig { @@ -101,29 +99,29 @@ func (t *TickManager) onTickMinute(now int64) { continue } num := random.GetRandomInt32(1, 9) - t.gameManager.AddUserItem(player.PlayerID, []*UserItem{{ItemId: uint32(itemId), ChangeCount: uint32(num)}}, true, 0) + GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: uint32(itemId), ChangeCount: uint32(num)}}, true, 0) i++ if i > count { break } } - t.gameManager.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 102, ChangeCount: 30}}, true, 0) - t.gameManager.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 201, ChangeCount: 10}}, true, 0) - t.gameManager.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 202, ChangeCount: 100}}, true, 0) - t.gameManager.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 203, ChangeCount: 10}}, true, 0) + GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 102, ChangeCount: 30}}, true, 0) + GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 201, ChangeCount: 10}}, true, 0) + GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 202, ChangeCount: 100}}, true, 0) + GAME_MANAGER.AddUserItem(player.PlayerID, []*UserItem{{ItemId: 203, ChangeCount: 10}}, true, 0) } } } func (t *TickManager) onTick10Second(now int64) { - for _, world := range t.gameManager.worldManager.worldMap { + for _, world := range WORLD_MANAGER.worldMap { for _, scene := range world.sceneMap { for _, player := range scene.playerMap { // PacketSceneTimeNotify sceneTimeNotify := new(proto.SceneTimeNotify) sceneTimeNotify.SceneId = player.SceneId sceneTimeNotify.SceneTime = uint64(scene.GetSceneTime()) - GAME.SendMsg(cmd.SceneTimeNotify, player.PlayerID, player.ClientSeq, sceneTimeNotify) + GAME_MANAGER.SendMsg(cmd.SceneTimeNotify, player.PlayerID, player.ClientSeq, sceneTimeNotify) } } if !world.IsBigWorld() && (world.multiplayer || !world.owner.Pause) { @@ -137,8 +135,8 @@ func (t *TickManager) onTick10Second(now int64) { } if monsterEntityCount < 30 { monsterEntityId := t.createMonster(scene) - bigWorldOwner := t.gameManager.userManager.GetOnlineUser(1) - t.gameManager.AddSceneEntityNotify(bigWorldOwner, proto.VisionType_VISION_TYPE_BORN, []uint32{monsterEntityId}, true) + bigWorldOwner := USER_MANAGER.GetOnlineUser(1) + GAME_MANAGER.AddSceneEntityNotify(bigWorldOwner, proto.VisionType_VISION_TYPE_BORN, []uint32{monsterEntityId}, true) } } for _, player := range world.playerMap { @@ -152,7 +150,7 @@ func (t *TickManager) onTick10Second(now int64) { avatar := player.AvatarMap[avatarId] avatar.FightPropMap[uint32(constant.FightPropertyConst.FIGHT_PROP_CUR_ATTACK)] = 1000000 avatar.FightPropMap[uint32(constant.FightPropertyConst.FIGHT_PROP_CRITICAL)] = 1.0 - t.gameManager.UpdateUserAvatarFightProp(player.PlayerID, avatarId) + GAME_MANAGER.UpdateUserAvatarFightProp(player.PlayerID, avatarId) } } } @@ -160,10 +158,10 @@ func (t *TickManager) onTick10Second(now int64) { } func (t *TickManager) onTick5Second(now int64) { - for _, world := range t.gameManager.worldManager.worldMap { + for _, world := range WORLD_MANAGER.worldMap { if world.IsBigWorld() { for applyUid := range world.owner.CoopApplyMap { - t.gameManager.UserDealEnterWorld(world.owner, applyUid, true) + GAME_MANAGER.UserDealEnterWorld(world.owner, applyUid, true) } } for _, player := range world.playerMap { @@ -190,7 +188,7 @@ func (t *TickManager) onTick5Second(now int64) { } worldPlayerLocationNotify.PlayerWorldLocList = append(worldPlayerLocationNotify.PlayerWorldLocList, playerWorldLocationInfo) } - t.gameManager.SendMsg(cmd.WorldPlayerLocationNotify, player.PlayerID, 0, worldPlayerLocationNotify) + GAME_MANAGER.SendMsg(cmd.WorldPlayerLocationNotify, player.PlayerID, 0, worldPlayerLocationNotify) // PacketScenePlayerLocationNotify scene := world.GetSceneById(player.SceneId) @@ -212,14 +210,14 @@ func (t *TickManager) onTick5Second(now int64) { } scenePlayerLocationNotify.PlayerLocList = append(scenePlayerLocationNotify.PlayerLocList, playerLocationInfo) } - t.gameManager.SendMsg(cmd.ScenePlayerLocationNotify, player.PlayerID, 0, scenePlayerLocationNotify) + GAME_MANAGER.SendMsg(cmd.ScenePlayerLocationNotify, player.PlayerID, 0, scenePlayerLocationNotify) } } } } func (t *TickManager) onTickSecond(now int64) { - for _, world := range t.gameManager.worldManager.worldMap { + for _, world := range WORLD_MANAGER.worldMap { for _, player := range world.playerMap { // 世界里所有玩家的网络延迟广播 // PacketWorldPlayerRTTNotify @@ -229,16 +227,16 @@ func (t *TickManager) onTickSecond(now int64) { playerRTTInfo := &proto.PlayerRTTInfo{Uid: worldPlayer.PlayerID, Rtt: worldPlayer.ClientRTT} worldPlayerRTTNotify.PlayerRttList = append(worldPlayerRTTNotify.PlayerRttList, playerRTTInfo) } - t.gameManager.SendMsg(cmd.WorldPlayerRTTNotify, player.PlayerID, 0, worldPlayerRTTNotify) + GAME_MANAGER.SendMsg(cmd.WorldPlayerRTTNotify, player.PlayerID, 0, worldPlayerRTTNotify) } } } func (t *TickManager) onTick200MilliSecond(now int64) { // 耐力消耗 - for _, world := range t.gameManager.worldManager.worldMap { + for _, world := range WORLD_MANAGER.worldMap { for _, player := range world.playerMap { - t.gameManager.StaminaHandler(player) + GAME_MANAGER.StaminaHandler(player) } } } diff --git a/gs/game/user_chat.go b/gs/game/user_chat.go index 808ff226..c8f0c6fe 100644 --- a/gs/game/user_chat.go +++ b/gs/game/user_chat.go @@ -155,7 +155,7 @@ func (g *GameManager) PrivateChatReq(player *model.Player, payloadMsg pb.Message g.SendPrivateChat(player, targetPlayer, text) // 输入命令 会检测是否为命令的 - g.commandManager.InputCommand(player, text) + COMMAND_MANAGER.InputCommand(player, text) case *proto.PrivateChatReq_Icon: icon := content.(*proto.PrivateChatReq_Icon).Icon diff --git a/gs/game/user_login.go b/gs/game/user_login.go index 78fa43db..b11978e1 100644 --- a/gs/game/user_login.go +++ b/gs/game/user_login.go @@ -1,6 +1,7 @@ package game import ( + pb "google.golang.org/protobuf/proto" "time" gdc "hk4e/gs/config" @@ -10,8 +11,6 @@ import ( "hk4e/pkg/reflection" "hk4e/protocol/cmd" "hk4e/protocol/proto" - - pb "google.golang.org/protobuf/proto" ) func (g *GameManager) OnLogin(userId uint32, clientSeq uint32) { @@ -53,6 +52,73 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u // } //} + g.LoginNotify(userId, player, clientSeq) + + player.SceneLoadState = model.SceneNone + g.SendMsg(cmd.PlayerEnterSceneNotify, userId, clientSeq, g.PacketPlayerEnterSceneNotifyLogin(player, proto.EnterType_ENTER_TYPE_SELF)) +} + +func (g *GameManager) OnReg(userId uint32, clientSeq uint32, payloadMsg pb.Message) { + logger.LOG.Debug("user reg, uid: %v", userId) + req := payloadMsg.(*proto.SetPlayerBornDataReq) + logger.LOG.Debug("avatar id: %v, nickname: %v", req.AvatarId, req.NickName) + + exist, asyncWait := g.userManager.CheckUserExistOnReg(userId, req, clientSeq) + if !asyncWait { + g.OnRegOk(exist, req, userId, clientSeq) + } +} + +func (g *GameManager) OnRegOk(exist bool, req *proto.SetPlayerBornDataReq, userId uint32, clientSeq uint32) { + if exist { + logger.LOG.Error("recv reg req, but user is already exist, userId: %v", userId) + return + } + + nickName := req.NickName + mainCharAvatarId := req.GetAvatarId() + if mainCharAvatarId != 10000005 && mainCharAvatarId != 10000007 { + logger.LOG.Error("invalid main char avatar id: %v", mainCharAvatarId) + return + } + + player := g.CreatePlayer(userId, nickName, mainCharAvatarId) + if player == nil { + logger.LOG.Error("player is nil, uid: %v", userId) + return + } + g.userManager.AddUser(player) + + g.SendMsg(cmd.SetPlayerBornDataRsp, userId, clientSeq, new(proto.SetPlayerBornDataRsp)) + g.OnLogin(userId, clientSeq) +} + +func (g *GameManager) OnUserOffline(userId uint32) { + logger.LOG.Info("user offline, uid: %v", userId) + player := g.userManager.GetOnlineUser(userId) + if player == nil { + logger.LOG.Error("player is nil, userId: %v", userId) + return + } + world := g.worldManager.GetWorldByID(player.WorldId) + if world != nil { + g.UserWorldRemovePlayer(world, player) + } + player.OfflineTime = uint32(time.Now().Unix()) + player.Online = false + player.TotalOnlineTime += uint32(time.Now().UnixMilli()) - player.OnlineTime + g.userManager.OfflineUser(player) +} + +func (g *GameManager) LoginNotify(userId uint32, player *model.Player, clientSeq uint32) { + g.SendMsg(cmd.PlayerDataNotify, userId, clientSeq, g.PacketPlayerDataNotify(player)) + g.SendMsg(cmd.StoreWeightLimitNotify, userId, clientSeq, g.PacketStoreWeightLimitNotify()) + g.SendMsg(cmd.PlayerStoreNotify, userId, clientSeq, g.PacketPlayerStoreNotify(player)) + g.SendMsg(cmd.AvatarDataNotify, userId, clientSeq, g.PacketAvatarDataNotify(player)) + g.SendMsg(cmd.OpenStateUpdateNotify, userId, clientSeq, g.PacketOpenStateUpdateNotify()) +} + +func (g *GameManager) PacketPlayerDataNotify(player *model.Player) *proto.PlayerDataNotify { // PacketPlayerDataNotify playerDataNotify := new(proto.PlayerDataNotify) playerDataNotify.NickName = player.NickName @@ -67,8 +133,10 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u propValue.Val = int64(v) playerDataNotify.PropMap[uint32(k)] = propValue } - g.SendMsg(cmd.PlayerDataNotify, userId, clientSeq, playerDataNotify) + return playerDataNotify +} +func (g *GameManager) PacketStoreWeightLimitNotify() *proto.StoreWeightLimitNotify { // PacketStoreWeightLimitNotify storeWeightLimitNotify := new(proto.StoreWeightLimitNotify) storeWeightLimitNotify.StoreType = proto.StoreType_STORE_TYPE_PACK @@ -78,8 +146,10 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u storeWeightLimitNotify.ReliquaryCountLimit = 1500 storeWeightLimitNotify.MaterialCountLimit = 2000 storeWeightLimitNotify.FurnitureCountLimit = 2000 - g.SendMsg(cmd.StoreWeightLimitNotify, userId, clientSeq, storeWeightLimitNotify) + return storeWeightLimitNotify +} +func (g *GameManager) PacketPlayerStoreNotify(player *model.Player) *proto.PlayerStoreNotify { // PacketPlayerStoreNotify playerStoreNotify := new(proto.PlayerStoreNotify) playerStoreNotify.StoreType = proto.StoreType_STORE_TYPE_PACK @@ -94,7 +164,7 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u itemData, ok := itemDataMapConfig[int32(weapon.ItemId)] if !ok { logger.LOG.Error("config is nil, itemId: %v", weapon.ItemId) - return + return nil } if itemData.ItemEnumType != constant.ItemTypeConst.ITEM_WEAPON { continue @@ -167,8 +237,10 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u } playerStoreNotify.ItemList = append(playerStoreNotify.ItemList, pbItem) } - g.SendMsg(cmd.PlayerStoreNotify, userId, clientSeq, playerStoreNotify) + return playerStoreNotify +} +func (g *GameManager) PacketAvatarDataNotify(player *model.Player) *proto.AvatarDataNotify { // PacketAvatarDataNotify avatarDataNotify := new(proto.AvatarDataNotify) chooseAvatarId := player.MainCharAvatarId @@ -195,14 +267,10 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u TeamName: team.Name, } } - g.SendMsg(cmd.AvatarDataNotify, userId, clientSeq, avatarDataNotify) - - player.SceneLoadState = model.SceneNone - - // PacketPlayerEnterSceneNotify - playerEnterSceneNotify := g.PacketPlayerEnterSceneNotify(player) - g.SendMsg(cmd.PlayerEnterSceneNotify, userId, clientSeq, playerEnterSceneNotify) + return avatarDataNotify +} +func (g *GameManager) PacketOpenStateUpdateNotify() *proto.OpenStateUpdateNotify { // PacketOpenStateUpdateNotify openStateUpdateNotify := new(proto.OpenStateUpdateNotify) openStateConstMap := reflection.ConvStructToMap(constant.OpenStateConst) @@ -210,59 +278,7 @@ func (g *GameManager) OnLoginOk(userId uint32, player *model.Player, clientSeq u for _, v := range openStateConstMap { openStateUpdateNotify.OpenStateMap[uint32(v.(uint16))] = 1 } - g.SendMsg(cmd.OpenStateUpdateNotify, userId, clientSeq, openStateUpdateNotify) -} - -func (g *GameManager) OnReg(userId uint32, clientSeq uint32, payloadMsg pb.Message) { - logger.LOG.Debug("user reg, uid: %v", userId) - req := payloadMsg.(*proto.SetPlayerBornDataReq) - logger.LOG.Debug("avatar id: %v, nickname: %v", req.AvatarId, req.NickName) - - exist, asyncWait := g.userManager.CheckUserExistOnReg(userId, req, clientSeq) - if !asyncWait { - g.OnRegOk(exist, req, userId, clientSeq) - } -} - -func (g *GameManager) OnRegOk(exist bool, req *proto.SetPlayerBornDataReq, userId uint32, clientSeq uint32) { - if exist { - logger.LOG.Error("recv reg req, but user is already exist, userId: %v", userId) - return - } - - nickName := req.NickName - mainCharAvatarId := req.GetAvatarId() - if mainCharAvatarId != 10000005 && mainCharAvatarId != 10000007 { - logger.LOG.Error("invalid main char avatar id: %v", mainCharAvatarId) - return - } - - player := g.CreatePlayer(userId, nickName, mainCharAvatarId) - if player == nil { - logger.LOG.Error("player is nil, uid: %v", userId) - return - } - g.userManager.AddUser(player) - - g.SendMsg(cmd.SetPlayerBornDataRsp, userId, clientSeq, new(proto.SetPlayerBornDataRsp)) - g.OnLogin(userId, clientSeq) -} - -func (g *GameManager) OnUserOffline(userId uint32) { - logger.LOG.Info("user offline, uid: %v", userId) - player := g.userManager.GetOnlineUser(userId) - if player == nil { - logger.LOG.Error("player is nil, userId: %v", userId) - return - } - world := g.worldManager.GetWorldByID(player.WorldId) - if world != nil { - g.UserWorldRemovePlayer(world, player) - } - player.OfflineTime = uint32(time.Now().Unix()) - player.Online = false - player.TotalOnlineTime += uint32(time.Now().UnixMilli()) - player.OnlineTime - g.userManager.OfflineUser(player) + return openStateUpdateNotify } func (g *GameManager) CreatePlayer(userId uint32, nickName string, mainCharAvatarId uint32) *model.Player { diff --git a/gs/game/user_multiplayer.go b/gs/game/user_multiplayer.go index 36596109..c79b7813 100644 --- a/gs/game/user_multiplayer.go +++ b/gs/game/user_multiplayer.go @@ -202,7 +202,7 @@ func (g *GameManager) UserDealEnterWorld(hostPlayer *model.Player, otherUid uint hostPlayerEnterSceneNotify := g.PacketPlayerEnterSceneNotifyMp( hostPlayer, hostPlayer, - proto.EnterType_ENTER_TYPE_SELF, + proto.EnterType_ENTER_TYPE_GOTO, uint32(constant.EnterReasonConst.HostFromSingleToMp), hostPlayer.SceneId, hostPlayer.Pos, @@ -213,13 +213,6 @@ func (g *GameManager) UserDealEnterWorld(hostPlayer *model.Player, otherUid uint otherWorld := g.worldManager.GetWorldByID(otherPlayer.WorldId) g.UserWorldRemovePlayer(otherWorld, otherPlayer) - otherPlayerOldSceneId := otherPlayer.SceneId - otherPlayerOldPos := &model.Vector{ - X: otherPlayer.Pos.X, - Y: otherPlayer.Pos.Y, - Z: otherPlayer.Pos.Z, - } - otherPlayer.Pos = &model.Vector{ X: hostPlayer.Pos.X, Y: hostPlayer.Pos.Y + 1, @@ -233,18 +226,19 @@ func (g *GameManager) UserDealEnterWorld(hostPlayer *model.Player, otherUid uint otherPlayer.SceneId = hostPlayer.SceneId g.UserWorldAddPlayer(hostWorld, otherPlayer) - otherPlayer.SceneLoadState = model.SceneNone +} - // PacketPlayerEnterSceneNotify - playerEnterSceneNotify := g.PacketPlayerEnterSceneNotifyMp( - otherPlayer, - hostPlayer, - proto.EnterType_ENTER_TYPE_OTHER, - uint32(constant.EnterReasonConst.TeamJoin), - otherPlayerOldSceneId, - otherPlayerOldPos, - ) - g.SendMsg(cmd.PlayerEnterSceneNotify, otherPlayer.PlayerID, otherPlayer.ClientSeq, playerEnterSceneNotify) +func (g *GameManager) JoinPlayerSceneReq(player *model.Player, payloadMsg pb.Message) { + joinPlayerSceneRsp := new(proto.JoinPlayerSceneRsp) + joinPlayerSceneRsp.Retcode = int32(proto.Retcode_RETCODE_RET_JOIN_OTHER_WAIT) + g.SendMsg(cmd.JoinPlayerSceneRsp, player.PlayerID, player.ClientSeq, joinPlayerSceneRsp) + + g.SendMsg(cmd.LeaveWorldNotify, player.PlayerID, 0, new(proto.LeaveWorldNotify)) + + g.LoginNotify(player.PlayerID, player, 0) + + player.SceneLoadState = model.SceneNone + g.SendMsg(cmd.PlayerEnterSceneNotify, player.PlayerID, 0, g.PacketPlayerEnterSceneNotifyLogin(player, proto.EnterType_ENTER_TYPE_OTHER)) } func (g *GameManager) UserLeaveWorld(player *model.Player) bool { @@ -258,27 +252,8 @@ func (g *GameManager) UserLeaveWorld(player *model.Player) bool { } } g.UserWorldRemovePlayer(oldWorld, player) - //{ - // newWorld := g.worldManager.CreateWorld(player, false) - // g.UserWorldAddPlayer(newWorld, player) - // player.SceneLoadState = model.SceneNone - // - // // PacketPlayerEnterSceneNotify - // enterReasonConst := constant.GetEnterReasonConst() - // playerEnterSceneNotify := g.PacketPlayerEnterSceneNotifyMp( - // player, - // player, - // proto.EnterType_ENTER_TYPE_SELF, - // uint32(enterReasonConst.TeamBack), - // player.SceneId, - // player.Pos, - // ) - // g.SendMsg(cmd.PlayerEnterSceneNotify, player.PlayerID, player.ClientSeq, playerEnterSceneNotify) - //} - { - // PacketClientReconnectNotify - g.SendMsg(cmd.ClientReconnectNotify, player.PlayerID, 0, new(proto.ClientReconnectNotify)) - } + // PacketClientReconnectNotify + g.SendMsg(cmd.ClientReconnectNotify, player.PlayerID, 0, new(proto.ClientReconnectNotify)) return true } diff --git a/gs/game/user_scene.go b/gs/game/user_scene.go index dc65c73c..04b9e088 100644 --- a/gs/game/user_scene.go +++ b/gs/game/user_scene.go @@ -282,7 +282,7 @@ func (g *GameManager) ChangeGameTimeReq(player *model.Player, payloadMsg pb.Mess g.SendMsg(cmd.ChangeGameTimeRsp, player.PlayerID, player.ClientSeq, changeGameTimeRsp) } -func (g *GameManager) PacketPlayerEnterSceneNotify(player *model.Player) *proto.PlayerEnterSceneNotify { +func (g *GameManager) PacketPlayerEnterSceneNotifyLogin(player *model.Player, enterType proto.EnterType) *proto.PlayerEnterSceneNotify { world := g.worldManager.GetWorldByID(player.WorldId) scene := world.GetSceneById(player.SceneId) player.EnterSceneToken = uint32(random.GetRandomInt32(5000, 50000)) @@ -290,12 +290,11 @@ func (g *GameManager) PacketPlayerEnterSceneNotify(player *model.Player) *proto. playerEnterSceneNotify.SceneId = player.SceneId playerEnterSceneNotify.Pos = &proto.Vector{X: float32(player.Pos.X), Y: float32(player.Pos.Y), Z: float32(player.Pos.Z)} playerEnterSceneNotify.SceneBeginTime = uint64(scene.GetSceneCreateTime()) - playerEnterSceneNotify.Type = proto.EnterType_ENTER_TYPE_SELF + playerEnterSceneNotify.Type = enterType playerEnterSceneNotify.TargetUid = player.PlayerID playerEnterSceneNotify.EnterSceneToken = player.EnterSceneToken playerEnterSceneNotify.WorldLevel = player.PropertiesMap[constant.PlayerPropertyConst.PROP_PLAYER_WORLD_LEVEL] playerEnterSceneNotify.EnterReason = uint32(constant.EnterReasonConst.Login) - // 刚登录进入场景的时候才为true playerEnterSceneNotify.IsFirstLoginEnterScene = true playerEnterSceneNotify.WorldType = 1 playerEnterSceneNotify.SceneTransaction = strconv.Itoa(int(player.SceneId)) + "-" + diff --git a/gs/game/user_social.go b/gs/game/user_social.go index 76c99008..c46e0bf2 100644 --- a/gs/game/user_social.go +++ b/gs/game/user_social.go @@ -148,7 +148,7 @@ func (g *GameManager) GetPlayerFriendListReq(player *model.Player, payloadMsg pb // 获取包含系统的临时好友列表 // 用于实现好友列表内的系统且不更改原先的内容 - tempFriendList := g.commandManager.GetFriendList(player.FriendList) + tempFriendList := COMMAND_MANAGER.GetFriendList(player.FriendList) for uid := range tempFriendList { // TODO 同步阻塞待优化 diff --git a/protocol/cmd/cmd_id_proto_obj_map.go b/protocol/cmd/cmd_id_proto_obj_map.go index 3c0ee681..817bb758 100644 --- a/protocol/cmd/cmd_id_proto_obj_map.go +++ b/protocol/cmd/cmd_id_proto_obj_map.go @@ -94,6 +94,7 @@ func (c *CmdProtoMap) registerAllMessage() { c.registerMessage(ToTheMoonEnterSceneReq, &proto.ToTheMoonEnterSceneReq{}) // 进入场景请求 c.registerMessage(ToTheMoonEnterSceneRsp, &proto.ToTheMoonEnterSceneRsp{}) // 进入场景响应 c.registerMessage(SetEntityClientDataNotify, &proto.SetEntityClientDataNotify{}) // 通知 + c.registerMessage(LeaveWorldNotify, &proto.LeaveWorldNotify{}) // 删除客户端世界通知 // 战斗与技能 c.registerMessage(AvatarFightPropNotify, &proto.AvatarFightPropNotify{}) // 角色战斗属性通知 @@ -137,6 +138,8 @@ func (c *CmdProtoMap) registerAllMessage() { c.registerMessage(SceneKickPlayerRsp, &proto.SceneKickPlayerRsp{}) // 剔除玩家响应 c.registerMessage(SceneKickPlayerNotify, &proto.SceneKickPlayerNotify{}) // 剔除玩家通知 c.registerMessage(PlayerQuitFromMpNotify, &proto.PlayerQuitFromMpNotify{}) // 退出多人游戏通知 + c.registerMessage(JoinPlayerSceneReq, &proto.JoinPlayerSceneReq{}) // 进入他人世界请求 + c.registerMessage(JoinPlayerSceneRsp, &proto.JoinPlayerSceneRsp{}) // 进入他人世界响应 // 社交 c.registerMessage(SetPlayerBirthdayReq, &proto.SetPlayerBirthdayReq{}) // 设置生日请求