public void HandleMessage(ProtoBase proto) { switch (proto.MessageID) { case MessageId.SC_StartLevel: { if (m_curSubGameType != ESubGame.Battle) { ProtoSCStartLevel startLevel = proto as ProtoSCStartLevel; m_globalData.CurrLevel = startLevel.LevelId; SwitchToSubgame(ESubGame.Battle); } break; } case MessageId.SC_LeaveGame: { ExitRoom(); break; } default: break; } // update subgame if (m_curSubGame != null) { m_curSubGame.HandleMessage(proto); } }
public void Send(ProtoBase proto) { if (m_isConnected == false) { return; } StreamBuffer sb = proto.GetStream(); m_peer.Send(sb); }
public static ProtoBase ConstructThriftProto(StreamBuffer sb) { MessageId messageId = (MessageId)sb.m_protocolHeader.ProtocolID; if (s_protoConstructorDic.ContainsKey(messageId)) { TMemoryBuffer membuf = new TMemoryBuffer(sb.ByteBuffer); TCompactProtocol inProto = new TCompactProtocol(membuf); ProtoBase proto = s_protoConstructorDic[messageId].Invoke(inProto); return(proto); } return(null); }
public override void HandleMessage(ProtoBase proto) { base.HandleMessage(proto); switch (proto.MessageID) { case MessageId.SC_JoinGame: { ProtoSCJoinGame joinGame = proto as ProtoSCJoinGame; if (joinGame.Result == JoinGameResult.JGR_Success) { OnJoinRoom(true, ""); } else if (joinGame.Result == JoinGameResult.JGR_UserFull) { OnJoinRoom(false, "房间已满,无法进入"); } else if (joinGame.Result == JoinGameResult.JGR_BattleFull) { OnJoinRoom(false, "服务器爆满,无法创建房间"); } else if (joinGame.Result == JoinGameResult.JGR_AlreadyInBattle) { OnJoinRoom(false, "已经在房间中"); } break; } case MessageId.SC_EnterGame: { ProtoSCEnterGame enterBattle = proto as ProtoSCEnterGame; if (enterBattle.IsSuccess) { GameCore.Instance.MySide = enterBattle.Side; } break; } case MessageId.SC_MatchSuccess: { GameCore.Instance.SwitchToSubgame(ESubGame.SelectLevel); break; } } }
public override void HandleMessage(ProtoBase proto) { base.HandleMessage(proto); switch (proto.MessageID) { case MessageId.SC_EnterGame: { ProtoSCEnterGame enterBattle = proto as ProtoSCEnterGame; if (enterBattle.IsSuccess) { GameCore.Instance.MySide = enterBattle.Side; } break; } case MessageId.SC_MatchSuccess: { GameCore.Instance.SwitchToSubgame(ESubGame.SelectLevel); break; } } }
public void OnPktReceive(StreamBuffer streamBuffer) { ProtoBase proto = ProtoFactory.ConstructThriftProto(streamBuffer); if (proto != null) { if (proto.MessageID == MessageId.SC_ClockSync) { ServerTimeHelper.Instance.HandleSyncClockMessage(proto as ProtoSCClockSync); return; } if (!proto.IsRoomMessage()) { Debug.Log("OnPktReceive: " + proto.ToString()); // 不包含ID字段,是与服务器通讯的消息,直接处理 if (m_handler != null) { m_handler.HandleMessage(proto); } return; } } }
public virtual void HandleMessage(ProtoBase proto) { }
public override void HandleMessage(ProtoBase proto) { switch (proto.MessageID) { case MessageId.SC_StartLevel: { ProtoSCStartLevel startLevel = proto as ProtoSCStartLevel; GameCore.Instance.m_globalData.CurrLevel = startLevel.LevelId; Reset(); SyncClock(); break; } case MessageId.SC_LeaveLevel: { GameCore.Instance.SwitchToSubgame(ESubGame.SelectLevel); break; } case MessageId.SC_StartBattle: { ProtoSCStartBattle startBattle = proto as ProtoSCStartBattle; m_state = EBattleState.Ready; m_startFightTime = startBattle.StartTime + m_startFightDelay; m_viewSceneTarget = startBattle.Translation; Vector2 startPos = new Vector2(-6, m_viewSceneTarget.y); m_battleField.BattleFieldObj.transform.position = startPos; m_viewSceneSpeed = (m_viewSceneTarget.x + 6) / m_viewSceneTime; for (int i = 0; i < startBattle.BallQueueA.Count; ++i) { m_battleField.m_ballReserve[0].Enqueue((ELevelBallType)startBattle.BallQueueA[i]); } m_battleField.CheckBallDisplay(0); for (int i = 0; i < startBattle.BallQueueB.Count; ++i) { m_battleField.m_ballReserve[1].Enqueue((ELevelBallType)startBattle.BallQueueB[i]); } m_battleField.CheckBallDisplay(1); if (GameCore.Instance.m_globalData.CurrLevel % 2 == 1) { AudioMgr.PlayAudio(2, Guid.Empty); } else { AudioMgr.PlayAudio(3, Guid.Empty); } break; } case MessageId.SC_EndBattle: { ProtoSCEndBattle endBattle = proto as ProtoSCEndBattle; StartTimer(() => { OnEndBattle(endBattle.IsWin); }, 2f); break; } case MessageId.SC_BattleCommand: { ProtoSCBattleCommand battleCommand = proto as ProtoSCBattleCommand; HandleBattleCommand(battleCommand.Command); break; } } }