/// <summary> /// 用于本地兼容,比如打PVE的时候,也可以用帧同步兼容 /// </summary> /// <param name="vkey"></param> /// <param name="arg"></param> bool SendFSPLocal(int vkey, int arg) { Debuger.Log(LOG_TAG, "SendFSPLocal() vkey={0}, arg={1}", vkey, arg); // 新的帧 int nextFrameId = m_CurrentFrameIndex + 1; if (m_NextLocalFrame == null || m_NextLocalFrame.frameId != nextFrameId) { m_NextLocalFrame = new FSPFrame(); m_NextLocalFrame.frameId = nextFrameId; m_FrameBuffer[m_NextLocalFrame.frameId] = m_NextLocalFrame; } // 添加输入 FSPVKey cmd = new FSPVKey(); cmd.playerId = _mainPlayerId; cmd.vkey = vkey; cmd.args.Add(arg); m_NextLocalFrame.vkeys.Add(cmd); return(true); }
void Handle_PlayerExit(FSPVKey cmd) { if (m_GameStateListener != null) { m_GameStateListener.OnPlayerExit(cmd); } }
void Handle_GameEnd(FSPVKey cmd) { m_GameState = FSPGameState.GameEnd; if (m_GameStateListener != null) { m_GameStateListener.OnGameEnd(cmd); } }
// 服务端下推 protected void AddCmdToCurrentFrame(FSPVKeyBase vkey, int arg = 0) { FSPVKey cmd = new FSPVKey(); cmd.vkey = (int)vkey; cmd.args.Add(arg); AddCmdToCurrentFrame(0, cmd); }
void Handle_RoundEnd(FSPVKey cmd) { m_GameState = FSPGameState.RoundEnd; if (m_GameStateListener != null) { m_GameStateListener.OnRoundEnd(cmd); } }
void Handle_ControlStart(FSPVKey cmd) { m_GameState = FSPGameState.ControlStart; if (m_GameStateListener != null) { m_GameStateListener.OnControlStart(cmd); } }
void Handle_GameBegin(FSPVKey cmd) { m_GameState = FSPGameState.GameBegin; if (m_GameStateListener != null) { m_GameStateListener.OnGameBegin(cmd); } }
/// <summary> /// 处理来自客户端的 Cmd /// 对其中的关键VKey进行处理 /// 并且收集业务VKey /// </summary> /// <param name="player"></param> /// <param name="cmd"></param> protected virtual void HandleClientCmd(FSPPlayer player, FSPVKey cmd) { uint playerId = player.Id; if (!player.HasAuth) { if (cmd.vkey == FSPVKeyBase.AUTH) { player.SetAuth(cmd.args[0]); } return; } switch (cmd.vkey) { case FSPVKeyBase.GAME_BEGIN: { SetFlag(playerId, ref m_GameBeginFlag, "m_GameBeginFlag"); break; } case FSPVKeyBase.ROUND_BEGIN: { SetFlag(playerId, ref m_RoundBeginFlag, "m_RoundBeginFlag"); break; } case FSPVKeyBase.CONTROL_START: { SetFlag(playerId, ref m_ControlStartFlag, "m_ControlStartFlag"); break; } case FSPVKeyBase.ROUND_END: { SetFlag(playerId, ref m_RoundEndFlag, "m_RoundEndFlag"); break; } case FSPVKeyBase.GAME_END: { SetFlag(playerId, ref m_GameEndFlag, "m_GameEndFlag"); break; } case FSPVKeyBase.GAME_EXIT: { HandleGameExit(playerId, cmd); break; } default: { AddCmdToCurrentFrame(playerId, cmd); break; } } }
protected void AddCmdToCurrentFrame(int vkey, int arg = 0) { FSPVKey cmd = new FSPVKey(); cmd.vkey = vkey; cmd.args = new int[] { arg }; cmd.playerId = 0; AddCmdToCurrentFrame(0, cmd); }
private void OnPlayerReceive(FSPPlayer player, FSPVKey cmd) { if (UseDelayGC) { m_ListObjectsForDelayGC.Add(cmd); } HandleClientCmd(player, cmd); }
public void OnPlayerExit(FSPVKey cmd) { Debuger.Log(LOG_TAG, "OnGameExit: {0}", cmd.args[0]); if (cmd.playerId == m_playerId) { delayToStop = 1; } }
/// <summary> /// 处理来自客户端的 Cmd /// 对其中的关键VKey进行处理 /// 并且收集业务VKey /// </summary> /// <param name="player"></param> /// <param name="cmd"></param> protected virtual void HandleClientCmd(FSPPlayer player, FSPVKey cmd) { // Debuger.Log(LOG_TAG, "HandleClientCmd() cmd: {0}", cmd.ToString()); uint playerId = player.Id; if (!player.HasAuth) { Debuger.Log(LOG_TAG, "HandleClientCmd() hasAuth = false! Wait for AUTH! the vkey is {0}", cmd.vkey); if (cmd.vkey == (int)FSPVKeyBase.AUTH) { player.HasAuth = true; // player.HasAuth = cmd.args[0] > 0; Debuger.Log(LOG_TAG, "HandleClientCmd() AUTH, playerId={0}", playerId); } return; } switch (cmd.vkey) { case (int)FSPVKeyBase.GAME_BEGIN: Debuger.Log(LOG_TAG, "HandleClientCmd() GAME_BEGIN, playerId = {0}, cmd = {1}", playerId, cmd); SetFlag(playerId, ref m_GameBeginFlag, "m_GameBeginFlag"); break; case (int)FSPVKeyBase.ROUND_BEGIN: Debuger.Log(LOG_TAG, "HandleClientCmd() ROUND_BEGIN, playerId = {0}, cmd = {1}", playerId, cmd); SetFlag(playerId, ref m_RoundBeginFlag, "m_RoundBeginFlag"); break; case (int)FSPVKeyBase.CONTROL_START: Debuger.Log(LOG_TAG, "HandleClientCmd() CONTROL_START, playerId = {0}, cmd = {1}", playerId, cmd); SetFlag(playerId, ref m_ControlStartFlag, "m_ControlStartFlag"); break; case (int)FSPVKeyBase.ROUND_END: Debuger.Log(LOG_TAG, "HandleClientCmd() ROUND_END, playerId = {0}, cmd = {1}", playerId, cmd); SetFlag(playerId, ref m_RoundEndFlag, "m_RoundEndFlag"); break; case (int)FSPVKeyBase.GAME_END: Debuger.Log(LOG_TAG, "HandleClientCmd() GAME_END, playerId = {0}, cmd = {1}", playerId, cmd); SetFlag(playerId, ref m_GameEndFlag, "m_GameEndFlag"); break; case (int)FSPVKeyBase.PLAYER_EXIT: Debuger.Log(LOG_TAG, "HandleClientCmd() PLAYER_EXIT, playerId = {0}, cmd = {1}", playerId, cmd); HandlePlayerExit(playerId, cmd); break; default: Debuger.Log(LOG_TAG, "HandleClientCmd() other, playerId = {0}, cmd = {1}", playerId, cmd); AddCmdToCurrentFrame(playerId, cmd); break; } }
private void OnEnterFrame(int frameId, FSPFrame frame) { if (frame != null && frame.vkeys != null) { for (int i = 0; i < frame.vkeys.Count; i++) { FSPVKey cmd = frame.vkeys[i]; m_lastVKey = cmd.ToString(); this.Log("OnEnterFrame() frameId:{0}, cmd:{1}", frameId, cmd.ToString()); } } }
void Handle_RoundBegin(FSPVKey cmd) { m_GameState = FSPGameState.RoundBegin; // 这里需要重置一些数据 ResetRound(); if (m_GameStateListener != null) { m_GameStateListener.OnRoundBegin(cmd); } }
//------------------------------------------------------------ #region Receive 先用公用消息 // private void OnReceive(byte[] buffer, int size, IPEndPoint remotePoint) // { // FSPDataS2C data = PBSerializer.NDeserialize<FSPDataS2C>(buffer); // // if (m_RecvListener != null) // { // for (int i = 0; i < data.frames.Count; i++) // { // m_RecvListener(data.frames[i]); // } // // } // } #endregion //------------------------------------------------------------ #region Send public bool SendFSP(int vkey, int arg, int clientFrameId) { if (m_IsRunning) { FSPVKey cmd = m_TempSendData.Vkeys[0]; cmd.Vkey = vkey; cmd.Args.Add(arg); cmd.PlayerIdOrClientFrameId = (uint)clientFrameId; ETModel.SessionComponent.Instance.Session.Send(m_TempSendData); return(true); } return(false); }
public bool SendFSP(int vkey, int arg, int clientFrameId) { if (m_IsRunning) { FSPVKey cmd = m_TempSendData.vkeys[0]; cmd.vkey = vkey; cmd.args.Add(arg); cmd.clientFrameId = (uint)clientFrameId; int len = PBSerializer.Serialize(m_TempSendData, m_TempSendBuf); return(m_Socket.SendTo(m_TempSendBuf, len, m_HostEndPoint)); } return(false); }
private void HandleGameExit(uint playerId, FSPVKey cmd) { AddCmdToCurrentFrame(playerId, cmd); FSPPlayer player = GetPlayer(playerId); if (player != null) { player.WaitForExit = true; if (onGameExit != null) { onGameExit(playerId); } } }
private void OnEnterFrame(int frameId, FSPFrame frame) { GameManager.Instance.EnterFrame(frameId); if (frame != null && frame.vkeys != null) { for (int i = 0; i < frame.vkeys.Count; i++) { FSPVKey cmd = frame.vkeys[i]; GameManager.Instance.InputVKey(cmd.vkey, ((float)cmd.args[0]) / 10000.0f, cmd.playerId); } } CheckTimeEnd(); }
/// <summary> /// 用于本地兼容,比如打PVE的时候,也可以用帧同步兼容 /// </summary> /// <param name="vkey"></param> /// <param name="arg"></param> private void SendFSPLocal(int vkey, int arg = 0) { int nextFrameId = m_CurrentFrameIndex + 1; if (m_NextLocalFrame == null || m_NextLocalFrame.FrameId != nextFrameId) { m_NextLocalFrame = new FSPFrame(); m_NextLocalFrame.FrameId = nextFrameId; m_FrameBuffer.Add(m_NextLocalFrame.FrameId, m_NextLocalFrame); } FSPVKey cmd = new FSPVKey(); cmd.Vkey = vkey; cmd.Args.Add(arg); cmd.PlayerIdOrClientFrameId = m_MinePlayerId; m_NextLocalFrame.Vkeys.Add(cmd); }
/// <summary> /// 执行每一帧 /// </summary> /// <param name="frameId"></param> /// <param name="frame"></param> private void ExecuteFrame(int frameId, FSPFrame frame) { //优先处理流程VKey if (frame != null && frame.Vkeys != null) { for (int i = 0; i < frame.Vkeys.Count; i++) { FSPVKey cmd = frame.Vkeys[i]; if (cmd.Vkey == FSPVKeyBase.GAME_BEGIN) { Handle_GameBegin(cmd.Args[0]); } else if (cmd.Vkey == FSPVKeyBase.ROUND_BEGIN) { Handle_RoundBegin(cmd.Args[0]); } else if (cmd.Vkey == FSPVKeyBase.CONTROL_START) { Handle_ControlStart(cmd.Args[0]); } else if (cmd.Vkey == FSPVKeyBase.ROUND_END) { Handle_RoundEnd(cmd.Args[0]); } else if (cmd.Vkey == FSPVKeyBase.GAME_END) { Handle_GameEnd(cmd.Args[0]); } else if (cmd.Vkey == FSPVKeyBase.GAME_EXIT) { Handle_GameExit(cmd.PlayerIdOrClientFrameId); } } } //再将其它VKey抛给外界处理 if (m_FrameListener != null) { m_FrameListener(frameId, frame); } }
/// <summary> /// execute a frame /// </summary> /// <param name="frameId"></param> /// <param name="frame"></param> private void ExecuteFrame(int frameId, FSPFrame frame) { //handle game state Vkey first if (frame != null && frame.vkeys != null) { for (int i = 0; i < frame.vkeys.Count; i++) { FSPVKey cmd = frame.vkeys[i]; if (cmd.vkey == FSPVKeyBase.GAME_BEGIN) { Handle_GameBegin(cmd.args[0]); } else if (cmd.vkey == FSPVKeyBase.ROUND_BEGIN) { Handle_RoundBegin(cmd.args[0]); } else if (cmd.vkey == FSPVKeyBase.CONTROL_START) { Handle_ControlStart(cmd.args[0]); } else if (cmd.vkey == FSPVKeyBase.ROUND_END) { Handle_RoundEnd(cmd.args[0]); } else if (cmd.vkey == FSPVKeyBase.GAME_END) { Handle_GameEnd(cmd.args[0]); } else if (cmd.vkey == FSPVKeyBase.GAME_EXIT) { Handle_GameExit(cmd.playerId); } } } //other Virtual key can be handled by game manager if (mFrameListener != null) { mFrameListener(frameId, frame); } }
/// <summary> /// to be compatible with local, like PVE mode can also use Frame Synchronization Protocol /// </summary> /// <param name="vkey"></param> /// <param name="arg"></param> private void SendFSPLocal(int vkey, int arg = 0) { MyLogger.Log(LOG_TAG, "SendFSPLocal() vkey={0}, arg={1}", vkey.ToString(), arg); int nextFrameId = mCurrentFrameIndex + 1; if (mNextLocalFrame == null || mNextLocalFrame.frameId != nextFrameId) { mNextLocalFrame = new FSPFrame(); mNextLocalFrame.frameId = nextFrameId; mNextLocalFrame.vkeys = new List <FSPVKey>(); mFrameBuffer.Add(mNextLocalFrame.frameId, mNextLocalFrame); } FSPVKey cmd = new FSPVKey(); cmd.vkey = vkey; cmd.args = new int[] { arg }; cmd.playerId = mMinePlayerId; mNextLocalFrame.vkeys.Add(cmd); }
//--------------------------------------------------------- /// <summary> /// 处理来自客户端的 Cmd /// 对其中的关键VKey进行处理 /// 并且收集业务VKey /// </summary> /// <param name="player"></param> /// <param name="cmd"></param> protected virtual void HandleClientCmd(FSPPlayer player, FSPVKey cmd) { uint playerId = player.Id; //处理鉴权 if (!player.HasAuth) { Debuger.Log(LOG_TAG, "HandleClientCmd() hasAuth = false! Wait AUTH!"); if (cmd.vkey == FSPVKeyBase.AUTH) { Debuger.Log(LOG_TAG, "HandleClientCmd() AUTH, playerId={0}", playerId); player.SetAuth(cmd.args[0]); } return; } switch (cmd.vkey) { case FSPVKeyBase.GAME_BEGIN: { Debuger.Log(LOG_TAG, "HandleClientCmd() GAME_BEGIN, playerId = {0}, cmd = {1}", playerId, cmd); SetFlag(playerId, ref m_GameBeginFlag, "m_GameBeginFlag"); break; } case FSPVKeyBase.ROUND_BEGIN: { Debuger.Log(LOG_TAG, "HandleClientCmd() ROUND_BEGIN, playerId = {0}, cmd = {1}", playerId, cmd); SetFlag(playerId, ref m_RoundBeginFlag, "m_RoundBeginFlag"); break; } case FSPVKeyBase.CONTROL_START: { Debuger.Log(LOG_TAG, "HandleClientCmd() CONTROL_START, playerId = {0}, cmd = {1}", playerId, cmd); SetFlag(playerId, ref m_ControlStartFlag, "m_ControlStartFlag"); break; } case FSPVKeyBase.ROUND_END: { Debuger.Log(LOG_TAG, "HandleClientCmd() ROUND_END, playerId = {0}, cmd = {1}", playerId, cmd); SetFlag(playerId, ref m_RoundEndFlag, "m_RoundEndFlag"); break; } case FSPVKeyBase.GAME_END: { Debuger.Log(LOG_TAG, "HandleClientCmd() GAME_END, playerId = {0}, cmd = {1}", playerId, cmd); SetFlag(playerId, ref m_GameEndFlag, "m_GameEndFlag"); break; } case FSPVKeyBase.GAME_EXIT: { Debuger.Log(LOG_TAG, "HandleClientCmd() GAME_EXIT, playerId = {0}, cmd = {1}", playerId, cmd); HandleGameExit(playerId, cmd); break; } default: { Debuger.Log(LOG_TAG, "HandleClientCmd() playerId = {0}, cmd = {1}", playerId, cmd); AddCmdToCurrentFrame(playerId, cmd); break; } } }
// 收到客户端的数据 protected void AddCmdToCurrentFrame(uint playerId, FSPVKey cmd) { cmd.playerId = playerId; m_LockedFrame.vkeys.Add(cmd); }
void OnPlayerReceive(FSPPlayer player, FSPVKey cmd) { HandleClientCmd(player, cmd); }
public void OnGameBegin(FSPVKey cmd) { Debuger.Log(LOG_TAG, "OnGameBegin: {0}", cmd.args[0]); }
public void OnControlStart(FSPVKey cmd) { Debuger.Log(LOG_TAG, "OnControlStart: {0}", cmd.args[0]); }
public void OnRoundEnd(FSPVKey cmd) { Debuger.Log(LOG_TAG, "OnRoundEnd: {0}", cmd.args[0]); }
public void OnGameEnd(FSPVKey cmd) { Debuger.Log(LOG_TAG, "OnGameEnd: {0}", (GameProtocol.FSPGameEndReason)cmd.args[0]); delayToStop = 60; //2s }