private void OnUserInfoSyn(PacketBase msg) { if (msg.code == 0) { UserInfoSyn response = NetSerilizer.DeSerialize <UserInfoSyn>(msg.data); this.playerId = response.userId; this.nickname = response.nickName; this.coins = response.coin; this.cards = response.fanka; this.face = response.headImg; //this.sex = response.sex;//性别 值为1时是男性,值为2时是女性,值为0时是未知 this.sex = IconManager.GetSexByFace(response.sex, response.headImg); this.continueWinCount = response.continueWinCount; this.totalGameCount = response.totalGameCount; this.winRate = (float)response.winRate; this.ip = response.ip; this.maxFanType = response.maxFanType; this.handcard = response.handcard; this.downcard = response.downcard; this.createMultiRoom = response.createMultiRoom; Debug.LogFormat("OnUserInfoSyn playerId:{0};nickname:{1};face:{2};", playerId, nickname, face); EventDispatcher.DispatchEvent(MessageCommand.Update_UserInfo); } }
void OnLogin(PacketBase msg) { //Game.LoadingPage.Hide(); if (msg.code == 0) { GDM.Save(SAVE_DATA_TYPE.GameData); LoginResponse response = NetSerilizer.DeSerialize <LoginResponse>(msg.data); Game.Instance.playerId = response.userId; Game.Instance.token = response.token; Game.InitHallSocket(response.hallServerAddr); Game.InitMsgSocket(response.msgServerAddr); Game.InitGameSocket(response.gameServerAddr); //EventDispatcher.DispatchEvent(MessageCommand.LoginSucess); //Game.StateMachine.SetNext(Game.StateMachine.MenuState); Game.Reset(); Game.SocketHall.DoRoomConfigRequest(); //Game.SocketHall.DoRankRequest(); Game.UIMgr.PushScene(UIPage.MainPage); } else { Game.DialogMgr.PushDialog(UIDialog.SingleBtnDialog, msg.msg); } }
private void OnHangupSyn(PacketBase msg) { HangupSyn response = NetSerilizer.DeSerialize <HangupSyn>(msg.data); Game.MJMgr.HangUp = response.status == 1;// 1 托管 2 正常 EventDispatcher.DispatchEvent(MessageCommand.MJ_UpdatePlayPage); }
public static object DeSerialize(PacketBase msg) { if (null != msg && null != msg.data) { string className = msg.packetType.ToString(); Type type = Type.GetType("packet.game." + className); if (null == type) { type = Type.GetType("packet.mj." + className); if (null == type) { type = Type.GetType("packet.task." + className); if (null == type) { type = Type.GetType("packet.user." + className); } } } if (null == type) { Debug.LogFormat("DeSerialize GetType Err! packetType:{0}", msg.packetType.ToString()); return(null); } object obj = NetSerilizer.DeSerialize(msg.data, type); if (null == obj) { Debug.LogFormat("DeSerialize Err! packetType:{0}", msg.packetType.ToString()); return(null); } return(obj); } return(null); }
// 读取数据 private void ReadData() { byte[] data = NetEncode.Decode(ref receiveCache); //说明获取到一条完整数据 if (data != null) { PacketBase msg = NetSerilizer.DeSerialize <PacketBase>(data); #if UNITY_EDITOR || UNITY_STANDALONE_WIN string dataStr = Utils.ToStr(Utils.DeSerialize(msg)); Debug.LogFormat("<<=:{0}; code:{1}; msg:{2};data:[{3}]", msg.packetType, msg.code, msg.msg, dataStr); //Debug.LogFormat("<<=:{0}; code:{1}; msg:{2};data:[{3}]", msg.packetType, msg.code, msg.msg, dataStr); #endif //if(msg.code != 0 && string.IsNullOrEmpty(msg.msg) == false) //{ // Game.DialogMgr.ShowDialog1Btn(msg.msg); //} if (receiveCallBack != null) { receiveCallBack(msg); } //尾递归,继续读取数据 ReadData(); } else { isReceiving = false; } }
void OnPLAYER_SIT_SYN(PacketBase msg) { if (msg.code == 0) { PlayerSitSyn response = NetSerilizer.DeSerialize <PlayerSitSyn>(msg.data); Debug.LogFormat("===OnPLAYER_SIT_SYN:" + Utils.ToStr(response)); Player player = new Player(); player.position = response.position; player.playerId = response.playerId; player.sex = IconManager.GetSexByFace(response.sex, response.headImg); player.nickName = response.nickName; player.headImg = response.headImg; player.coin = response.coin; player.score = response.score; player.offline = (response.online == 0); player.isReady[0] = (response.state == 1); player.leave = (response.away == 1); player.ip = response.ip; Game.MJMgr.MjData[player.position].player = player; if (player.playerId == Game.Instance.playerId) { Game.MJMgr.IntPosition(player.position); Game.MJTable.SetDirection(player.position); } int index = Game.MJMgr.GetIndexByPosition(response.position); Game.MJMgr.players[index].postion = response.position; EventDispatcher.DispatchEvent(MessageCommand.MJ_UpdatePlayPage); } }
void OnPlayerExitSyn(PacketBase msg) { if (msg.code == 0) { PlayerExitSyn response = NetSerilizer.DeSerialize <PlayerExitSyn>(msg.data); if (Game.IsSelf(response.playerId)) { Game.Instance.state = GameState.Hall; Game.UIMgr.PushScene(UIPage.MainPage); return; } else { Player player = Game.MJMgr.GetPlayerById(response.playerId); if (null != player) { Game.MJMgr.MjData[player.position].player = null; EventDispatcher.DispatchEvent(MessageCommand.MJ_UpdatePlayPage); } else { Debug.LogWarningFormat("Game.MJMgr.GetPlayerById == null! playerId={0}", response.playerId); } } } }
private void OnActAndNoticeMsgSyn(PacketBase msg) { if (msg.code == 0) { ActAndNoticeMsgSyn response = NetSerilizer.DeSerialize <ActAndNoticeMsgSyn>(msg.data); Game.Instance.SetActAndNoticeMsg(response); } }
private void OnNewMailMsgSyn(PacketBase msg) { if (msg.code == 0) { NewMailMsgSyn response = NetSerilizer.DeSerialize <NewMailMsgSyn>(msg.data); Game.Instance.SetNewMailMsg(response); } }
private void OnMarqueeMsgSyn(PacketBase msg) { if (msg.code == 0) { MarqueeMsgSyn response = NetSerilizer.DeSerialize <MarqueeMsgSyn>(msg.data); Game.Instance.SetMarqueeMsg(response); } }
private void OnLogoutSyn(PacketBase msg) { LogoutSyn response = NetSerilizer.DeSerialize <LogoutSyn>(msg.data); Game.DialogMgr.PushDialogImmediately(UIDialog.SingleBtnDialog, response.reason, new System.Action(() => { Game.Logout(); })); }
private void OnLogoutSyn(PacketBase msg) { LogoutSyn response = NetSerilizer.DeSerialize <LogoutSyn>(msg.data); Action callback = () => { Game.Logout(); }; Game.DialogMgr.PushDialog(UIDialog.SingleBtnDialog, response.reason, "提示", callback); }
public static void OnServerChangeSyn(PacketBase msg) { ServerChangeSyn response = NetSerilizer.DeSerialize <ServerChangeSyn>(msg.data); Game.InitHallSocket(response.hallServerAddr); Game.InitMsgSocket(response.msgServerAddr); Game.InitGameSocket(response.gameServerAddr); Debug.LogFormat("hallServerAddr:{0}; msgServerAddr:{1}; gameServerAddr:{2}", response.hallServerAddr, response.msgServerAddr, response.gameServerAddr); }
private void OnDissmissVoteSyn(PacketBase msg) { if (msg.code == 0) { DissmissVoteSyn response = NetSerilizer.DeSerialize <DissmissVoteSyn>(msg.data); MjData player = Game.MJMgr.MjData[response.position]; Action <bool> callback = (ok) => { DoDissmissVoteSyn(ok); }; Game.DialogMgr.PushDialog(UIDialog.DoubleBtnDialog, player.player.nickName + "申请解散房间", "提示", callback); } }
void OnVipRoomListSyn(PacketBase msg) { if (0 == msg.code) { result = NetSerilizer.DeSerialize <VipRoomListSyn>(msg.data); SetupUI(); } else { Game.DialogMgr.PushDialog(UIDialog.SingleBtnDialog, msg.msg); } }
public void DoLoadVipRoom(Action <VipRoomListSyn> callback) { PacketBase msg = new PacketBase() { packetType = PacketType.VipRoomListReuqest }; SocketNetTools.SendMsg(msg, PacketType.VipRoomListSyn, (data) => { VipRoomListSyn result = NetSerilizer.DeSerialize <VipRoomListSyn>(data.data); callback(result); }); }
public void DoPlayerGamingSynInquire(Action <bool> callback) { PacketBase msg = new PacketBase() { packetType = PacketType.PlayerGamingSynInquire }; SocketNetTools.SendMsg(msg, PacketType.PlayerGamingSynInquire, (data) => { PlayerGamingSynInquire result = NetSerilizer.DeSerialize <PlayerGamingSynInquire>(data.data); callback(result.isGaming); }); }
public void DoRoomConfigRequest() { PacketBase msg = new PacketBase() { packetType = PacketType.RoomConfigRequest }; SocketNetTools.SendMsg(msg, PacketType.RoomConfigResponse, (data) => { RoomConfigResponse response = NetSerilizer.DeSerialize <RoomConfigResponse>(data.data); Game.Instance.RoomConfig = response; }); }
public void DoMallProductRequest(Action callback) { PacketBase msg = new PacketBase() { packetType = PacketType.MallProductRequest }; SocketNetTools.SendMsg(msg, PacketType.MallProductResponse, (data) => { MallProductResponse response = NetSerilizer.DeSerialize <MallProductResponse>(data.data); Game.Instance.MallProduct = response; callback(); }); }
void OnGAMING_SYN(PacketBase msg) { if (msg.code == 0) { PlayerGamingSyn response = NetSerilizer.DeSerialize <PlayerGamingSyn>(msg.data); Game.Instance.state = GameState.Waitting; Debug.Log("===OnGAMING_SYN [" + GetWanfa(response.wanfa) + "]"); Game.MJMgr.targetFlag.gameObject.SetActive(false); RoomMgr.Reset(); RoomMgr.playerGamingSyn = response; Game.MJTable.roomNum.text = ""; Game.MJTable.baseScore.text = ""; if (!RoomMgr.IsSingeRoom()) { if (!RoomMgr.IsVipRoom()) { RoomConfigModel config = Game.Instance.GetRoomInfo(response.matchId); if (null != config) { Game.MJTable.baseScore.text = string.Format("底分:{0}", config.baseScore); Game.Instance.baseScore = config.baseScore; } } else { Game.MJTable.roomNum.text = string.Format("房间号:{0}", response.deskId); } } int col = RoomMgr.IsVip2Room() ? 10 : 6; Game.MJMgr.players[0].dropCardLayout.col = col; Game.MJMgr.players[1].dropCardLayout.col = col; Game.MJMgr.players[2].dropCardLayout.col = col; Game.MJMgr.players[3].dropCardLayout.col = col; if (Game.UIMgr.IsSceneActive(UIPage.PlayPage)) { EventDispatcher.DispatchEvent(MessageCommand.MJ_UpdatePlayPage); } else { Game.UIMgr.PushScene(UIPage.PlayPage); } } }
public void DoRankRequest() { PacketBase msg = new PacketBase() { packetType = PacketType.RankRequest }; SocketNetTools.SendMsg(msg, PacketType.RankSyn, (data) => { RankSyn response = NetSerilizer.DeSerialize <RankSyn>(data.data); Game.Instance.RankSyn = response; EventDispatcher.DispatchEvent(MessageCommand.Update_Rank); }); }
void OnREADY_SYN(PacketBase msg) { if (msg.code == 0) { ReadySyn response = NetSerilizer.DeSerialize <ReadySyn>(msg.data); Player player = Game.MJMgr.GetPlayerById(response.playerId); if (null != player) { player.isReady = (response.state == 1); EventDispatcher.DispatchEvent(MessageCommand.MJ_UpdatePlayPage); } } else if (msg.code == (int)ErrCode.NotEnoughCoins) { // TODO 金币不足 无法准备 } }
public void DoGenOrderRequest(int platformId, string productId, Action <GenOrderResponse> callback) { PacketBase msg = new PacketBase() { packetType = PacketType.GenOrderRequest }; GenOrderRequest request = new GenOrderRequest() { platformId = platformId, productId = productId }; msg.data = NetSerilizer.Serialize(request); SocketNetTools.SendMsg(msg, PacketType.GenOrderResponse, (data) => { GenOrderResponse response = NetSerilizer.DeSerialize <GenOrderResponse>(data.data); callback(response); }); }
void OnPlayerReconnectSyn(PacketBase msg) { if (msg.code == 0) { PlayerReconnectSyn response = NetSerilizer.DeSerialize <PlayerReconnectSyn>(msg.data); Player player = Game.MJMgr.GetPlayerById(response.playerId); if (null != player) { Game.MJMgr.MjData[player.position].player.offline = false; EventDispatcher.DispatchEvent(MessageCommand.MJ_UpdatePlayPage); } else { Debug.LogWarningFormat("Game.MJMgr.GetPlayerById == null! playerId={0}", response.playerId); } } }
void OnPLAYER_COMEBACK(PacketBase msg) { if (msg.code == 0) { //TODO wxd away的时候,game.Instance会reset。为什么comeback的时候不用还原。 PlayerComebackSyn response = NetSerilizer.DeSerialize <PlayerComebackSyn>(msg.data); Player player = Game.MJMgr.GetPlayerById(response.playerId); if (null != player) { Game.MJMgr.MjData[player.position].player.leave = false; Game.MJMgr.MjData[player.position].player.offline = false; EventDispatcher.DispatchEvent(MessageCommand.MJ_UpdatePlayPage); } else { Debug.LogWarningFormat("Game.MJMgr.GetPlayerById == null! playerId={0}", response.playerId); } } }
public void DoRoomResult(long roomId, Action <RoomResultResponse> callback) { PacketBase msg = new PacketBase() { packetType = PacketType.RoomResultRequest }; RoomResultRequest request = new RoomResultRequest() { roomId = roomId }; msg.data = NetSerilizer.Serialize(request); SocketNetTools.SendMsg(msg, PacketType.RoomResultResponse, (data) => { RoomResultResponse response = NetSerilizer.DeSerialize <RoomResultResponse>(data.data); callback(response); }); }
public void DoCreateVipRoom(int vipRoomType, int quanNum, int wangfa, Action <VipRoomListSyn> callback) { PacketBase msg = new PacketBase() { packetType = PacketType.CreateVipRoomRequest }; CreateVipRoomRequest request = new CreateVipRoomRequest(); request.vipRoomType = vipRoomType; request.quanNum = quanNum; //request.vipRoomType = 0; request.wangfa = wangfa; msg.data = NetSerilizer.Serialize(request); SocketNetTools.SendMsg(msg, PacketType.VipRoomListSyn, (data) => { VipRoomListSyn result = NetSerilizer.DeSerialize <VipRoomListSyn>(data.data); callback(result); }); }
void _OnGameOperation(GameOperation response) { switch (response.operType) { case GameOperType.GameOperStartSyn: OnGameOperStartSyn(NetSerilizer.DeSerialize <GameOperStartSyn>(response.content)); break; case GameOperType.GameOperHandCardSyn: //OnGameOperHandCardSyn(NetSerilizer.DeSerialize<GameOperHandCardSyn>(response.content)); break; case GameOperType.GameOperPublicInfoSyn: OnGameOperPublicInfoSyn(NetSerilizer.DeSerialize <GameOperPublicInfoSyn>(response.content)); break; case GameOperType.GameOperPlayerHuSyn: OnGameOperPlayerHuSyn(NetSerilizer.DeSerialize <GameOperPlayerHuSyn>(response.content)); break; case GameOperType.GameOperPlayerActionNotify: OnGameOperPlayerActionNotify(NetSerilizer.DeSerialize <GameOperPlayerActionNotify>(response.content)); break; case GameOperType.GameOperActorSyn: OnGameOperActorSyn(NetSerilizer.DeSerialize <GameOperActorSyn>(response.content)); break; case GameOperType.GameOperPlayerActionSyn: OnGameOperPlayerActionSyn(NetSerilizer.DeSerialize <GameOperPlayerActionSyn>(response.content)); break; case GameOperType.GameOperBaoChangeSyn: OnGameOperBaoChangeSyn(NetSerilizer.DeSerialize <GameOperBaoChangeSyn>(response.content)); break; case GameOperType.GameOperFinalSettleSyn: OnGameOperFinalSettleSyn(NetSerilizer.DeSerialize <GameOperFinalSettleSyn>(response.content)); break; } }
private void OnGameChatMsgSyn(PacketBase msg) { if (msg.code == 0) { GameChatMsgSyn response = NetSerilizer.DeSerialize <GameChatMsgSyn>(msg.data); Debug.LogFormat("===OnGameChatMsgSyn:" + Utils.ToStr(response)); //类型 1 文字 2图片 3语音 if (response.contentType == 1) { string str = System.Text.Encoding.Default.GetString(response.data); if (null != str && str.StartsWith("[") && str.EndsWith("]")) { string sId = str.Substring(1, str.Length - 2); int id = 0; int.TryParse(sId, out id); if (id < 100) { // 表情 EventDispatcher.DispatchEvent(MessageCommand.Chat, response.position, 0, id); } else { // 短语 EventDispatcher.DispatchEvent(MessageCommand.Chat, response.position, 1, id); } print(id); } else { // 文字 print(str); EventDispatcher.DispatchEvent(MessageCommand.Chat, response.position, 2, str); } } else { // 语音 EventDispatcher.DispatchEvent(MessageCommand.Chat, response.position, 3, response.data); } } }
/// <summary> /// 读取数据 /// </summary> private void ReadData() { byte[] data = NetEncode.Decode(ref receiveCache); //如果数据读取成功 if (null != data) { NetModel item = NetSerilizer.DeSerialize(data); Debug.Log(item.ID + "," + item.Commit + "," + item.Message); if (null != receiveCallback) { receiveCallback(item); } //尾递归,继续处理数据 ReadData(); } else { isReceiving = false; } }