/// <summary> /// 进入游戏 /// </summary> private void OnEnterGame(PacketBase packet) { gs2ss.EnterGame msg = packet as gs2ss.EnterGame; ClientUID client_uid = msg.client_uid; InterServerID server_uid = msg.server_uid; UnitManager.Instance.AddSession(client_uid); if (!UnitManager.Instance.HasUnit(msg.char_idx)) { DBID db_id = new DBID(); db_id.game_id = ServerConfig.GetDBByAccountIdx(msg.account_idx, eDBType.Game); PlayerInfoForSS ss_data = CommonObjectPools.Spawn <PlayerInfoForSS>(); SQLCharHandle.QueryCharacterInfo(msg.char_idx, db_id, ss_data, is_load => { if (is_load && UnitManager.Instance.HadSession(client_uid)) {//读取玩数据,有可能已经退出 //创建玩家 Player player = new Player(); player.client_uid = client_uid; player.LoadData(ss_data); UnitManager.Instance.AddUnit(player); //告诉gs成功进入游戏 ss2gs.EnterGame rep_gs_msg = PacketPools.Get(ss2gs.msg.ENTER_GAME) as ss2gs.EnterGame; rep_gs_msg.server_uid = server_uid; rep_gs_msg.client_uid = client_uid; rep_gs_msg.char_idx = ss_data.char_idx; ServerNetManager.Instance.Send(server_uid.gs_uid, rep_gs_msg); //告诉ws ss2ws.LoginClient rep_ws_msg = PacketPools.Get(ss2ws.msg.LOGIN_CLIENT) as ss2ws.LoginClient; rep_ws_msg.server_uid = server_uid; rep_ws_msg.client_uid = client_uid; rep_ws_msg.data.Copy(ss_data); ServerNetManager.Instance.Send2WS(rep_ws_msg); //告诉gl ss2gl.LoginClient rep_gl_msg = PacketPools.Get(ss2gl.msg.LOGIN_CLIENT) as ss2gl.LoginClient; rep_gl_msg.server_uid = server_uid; rep_gl_msg.data.Copy(ss_data); ServerNetManager.Instance.Send2GL(rep_gl_msg); //告诉客户端角色基础信息 ss2c.CharacterInfo rep_msg = PacketPools.Get(ss2c.msg.CHARACTER_INFO) as ss2c.CharacterInfo; rep_msg.data.Copy(ss_data); ServerNetManager.Instance.SendProxy(client_uid, rep_msg, false); //初始化内部逻辑 player.OnFirstEnter(); } CommonObjectPools.Despawn(ss_data); }); } }
/// <summary> /// 进入游戏 /// </summary> private void OnEnterGame(PacketBase packet) { ss2gs.EnterGame msg = packet as ss2gs.EnterGame; //确定session是否还存在 ClientSession session = ClientSessionManager.Instance.GetSession(msg.client_uid.conn_idx); if (session != null) { session.session_status = eSessionStatus.IN_GAMING; gs2c.EnterGame rep_msg = PacketPools.Get(gs2c.msg.ENTER_GAME) as gs2c.EnterGame; rep_msg.char_idx = msg.char_idx; session.Send(rep_msg); } }