Ejemplo n.º 1
0
 /// <summary>
 /// Send a chat message to all players that have the given relationship with the sending
 /// player.
 /// </summary>
 /// <param name="message">The message to send.</param>
 /// <param name="receivers">The players that should receive the message.</param>
 public void SendMessage(string message, List <Player> receivers)
 {
     _context.SendMessage(NetworkMessageRecipient.All, new ChatNetworkMessage()
     {
         Content   = message,
         Sender    = _context.LocalPlayer,
         Receivers = Maybe.Just(receivers)
     });
 }
Ejemplo n.º 2
0
        public void ChangeMap(string serializedMap)
        {
            _serializedMap = serializedMap;
            _mapHash       = _mapManager.GetHash(_serializedMap);

            _context.SendMessage(NetworkMessageRecipient.Clients, new LobbyMapVerifyNetworkMessage()
            {
                MapHash = _mapHash
            });
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Send the given set of game commands to the server. It will be processed at a later point
 /// by every client.
 /// </summary>
 /// <param name="commands">The commands to send.</param>
 public void SendCommand(List <IGameCommand> commands)
 {
     _context.SendMessage(NetworkMessageRecipient.Server, new SubmitCommandsNetworkMessage()
     {
         Commands = commands
     });
 }
Ejemplo n.º 4
0
        public void OnConnected(Player connectedPlayer)
        {
            // this has to go before we notify everyone else of the connected player, otherwise we
            // will transmit to the connected player that they themselves got connected twice
            foreach (var player in _players)
            {
                _context.SendMessage(connectedPlayer, new PlayerJoinedNetworkMessage()
                {
                    Player = player
                });
            }

            _context.SendMessage(NetworkMessageRecipient.All, new PlayerJoinedNetworkMessage()
            {
                Player = connectedPlayer
            });
        }
Ejemplo n.º 5
0
        public void HandleNetworkMessage(Player sender, INetworkMessage message)
        {
            if (message is LobbyMapDownloadNetworkMessage)
            {
                var m = (LobbyMapDownloadNetworkMessage)message;
                _mapManager.Save(m.Map);
            }

            if (message is LobbyMapVerifyNetworkMessage)
            {
                var m = (LobbyMapVerifyNetworkMessage)message;
                _mapManager.HasMap(m.MapHash).ContinueWith(result => {
                    bool hasMap = result.Result;
                    if (hasMap == false)
                    {
                        _context.SendMessage(NetworkMessageRecipient.Server,
                                             new LobbyMapDownloadRequestedNetworkMessage());
                    }
                });
            }
        }
Ejemplo n.º 6
0
 private void ButtonSendAll_Click(object sender, EventArgs e)
 {
     _context.SendMessage(NetworkMessageRecipient.All, new DummyMessage());
 }