private void SendToOtherClients(PlayNetworkMessage networkMessage) { string message = JsonUtility.ToJson(networkMessage); for (int i = 0; i < m_ConnectedPlayerIndice.Count; i++) { int playerIndex = m_ConnectedPlayerIndice[i]; //don't send message back to the sender if (playerIndex != networkMessage.m_Command.m_PlayerIndex) { TcpServerSingleton.Instance.TcpQueue.SendMessage(message, i); } } }
public override void SendCommand(LudoCommand command, int turn) { PlayNetworkMessage networkMessage = new PlayNetworkMessage() { m_SessionId = m_SessionId, m_PlayerIndex = command.m_PlayerIndex, m_MessageType = CommandUtility.PlayId, m_Command = command, m_Turn = turn, }; SendToOtherClients(networkMessage); CheckBotTurns(turn); }
public override void SendCommand(LudoCommand command, int turn) { PlayNetworkMessage networkMessage = new PlayNetworkMessage() { m_SessionId = m_SessionId, m_PlayerIndex = m_Game.CommandExecuter.PlayerIndex, m_MessageType = CommandUtility.PlayId, m_Command = command, m_Turn = turn }; string message = JsonUtility.ToJson(networkMessage); TcpClientSingleton.Instance.TcpClient.SendMessage(message); }
protected void ReceiveNetworkMessage(string message) { PlayNetworkMessage networkMessage = JsonUtility.FromJson <PlayNetworkMessage>(message); if (networkMessage.m_MessageType == CommandUtility.PlayId) { if (!m_Game.IsPlaying) { HandleNetworkMessage(networkMessage); } else { m_ReceivedPlayMessages.Enqueue(networkMessage); if (m_WaitingForPlay == null) { m_WaitingForPlay = StartCoroutine(WaitForPlayingToHandleCommand()); } } } else { //handle other messages e.g. chats } }
protected override void HandleNetworkMessage(PlayNetworkMessage networkMessage) { base.HandleNetworkMessage(networkMessage); SendToOtherClients(networkMessage); CheckBotTurns(networkMessage.m_Turn); }
protected virtual void HandleNetworkMessage(PlayNetworkMessage networkMessage) { m_Game.Turn = networkMessage.m_Turn; m_Game.CommandExecuter.RunCommand(networkMessage.m_Command); }