Пример #1
0
        /// <summary>
        /// Try to join the lobby at the given IP end point as the given player.
        /// </summary>
        /// <param name="host">The IP address that the lobby server is running at.</param>
        /// <param name="mapManager">The map manager that will be used to check to see if we have a
        /// map and to save a downloaded map.</param>
        /// <param name="player">This player that will be used to uniquely identify
        /// ourselves.</param>
        /// <param name="password">The password that the lobby host has set.</param>
        public static Task<Maybe<LobbyMember>> JoinLobby(string host, Player player, IMapManager mapManager, string password) {
            /*
            return Task.Factory.StartNew(() => {
                try {
                    Maybe<NetworkContext> context = NetworkContext.CreateClient(address, player, password);
                    if (context.Exists) {
                        LobbyMember lobbyMember = new LobbyMember(context.Value, mapManager);
                        return Maybe.Just(lobbyMember);
                    }
                }
                catch (Exception) {
                }

                return Maybe<LobbyMember>.Empty;
            });
            */

            Maybe<LobbyMember> result = Maybe<LobbyMember>.Empty;
            Maybe<NetworkContext> context = NetworkContext.CreateClient(host, player, password);
            if (context.Exists) {
                LobbyMember lobbyMember = new LobbyMember(context.Value, mapManager);
                result = Maybe.Just(lobbyMember);
            }

            return Task.Factory.StartNew(() => result);
        }
Пример #2
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
            });
        }
Пример #3
0
        public void HandleNetworkMessage(Player sender, INetworkMessage message) {
            ChatNetworkMessage m = (ChatNetworkMessage)message;

            var receivedMessage = new ReceivedChatMessage() {
                RecieveTime = DateTime.Now,
                Sender = m.Sender,
                Content = m.Content
            };
            AllMessages.Add(receivedMessage);

            if (ShouldDisplay(m.Receivers)) {
                DisplayableMessages.Add(receivedMessage);
            }
        }
Пример #4
0
        public ChatMessageHandler(NetworkContext context) {
            _localPlayer = context.LocalPlayer;

            AllMessages = new List<ReceivedChatMessage>();
            DisplayableMessages = new List<ReceivedChatMessage>();
        }
Пример #5
0
        public void HandleNetworkMessage(Player sender, INetworkMessage message) {
            Log<PlayerManager>.Info("PlayerManager got message " + message);

            if (message is PlayerJoinedNetworkMessage) {
                Player player = ((PlayerJoinedNetworkMessage)message).Player;
                _players.Add(player);
            }

            else if (message is PlayerLeftNetworkMessage) {
                Player player = ((PlayerLeftNetworkMessage)message).Player;
                _players.Remove(player);
            }
        }
Пример #6
0
 public void OnDisconnected(Player player) {
     _context.SendMessage(NetworkMessageRecipient.All, new PlayerLeftNetworkMessage() {
         Player = player
     });
 }
 public void OnDisconnected(Player player) {
     _notReady.Remove(player);
     _ready.Remove(player);
 }
Пример #8
0
 /// <summary>
 /// Kick the given lobby member from the lobby.
 /// </summary>
 /// <param name="member">The member to kick.</param>
 public void Kick(Player member) {
     _context.Kick(member);
 }
Пример #9
0
        public void HandleNetworkMessage(Player sender, INetworkMessage message) {
            if (message is SubmitCommandsNetworkMessage) {
                SubmitCommandsNetworkMessage m = (SubmitCommandsNetworkMessage)message;

                int offset = Math.Min(_lastSentTurn, m.SubmittedOn + _turnDelay);
                _commands.Add(offset, m.Commands);
            }

            else if (message is AdjustTurnDelayNetworkMessage) {
                AdjustTurnDelayNetworkMessage m = (AdjustTurnDelayNetworkMessage)message;
                TurnDelay = m.NewDelay;
            }
        }
Пример #10
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());
                    }
                });
            }
        }
Пример #11
0
 public void OnDisconnected(Player player) {
 }
Пример #12
0
 public void OnConnected(Player player) {
     _context.SendMessage(player, new LobbyMapVerifyNetworkMessage() {
         MapHash = _mapHash
     });
 }
Пример #13
0
 /// <summary>
 /// Is the given player the host of the lobby?
 /// </summary>
 public bool IsHost(Player player) {
     return _context.IsPlayerServer(player);
 }
        public void HandleNetworkMessage(Player sender, INetworkMessage message) {
            if (message is LobbyNotReadyNetworkMessage) {
                _ready.Remove(sender);
                _notReady.Add(sender);
            }

            else if (message is LobbyReadyNetworkMessage) {
                _notReady.Remove(sender);
                _ready.Add(sender);
            }
        }
Пример #15
0
 public void HandleNetworkMessage(Player sender, INetworkMessage message) {
     if (message is LobbyMapDownloadRequestedNetworkMessage) {
         _context.SendMessage(sender, new LobbyMapDownloadNetworkMessage() {
             Map = _serializedMap
         });
     }
 }
Пример #16
0
        public void HandleNetworkMessage(Player sender, INetworkMessage message) {
            if (message is EndTurnNetworkMessage) {
                _updates.Enqueue(((EndTurnNetworkMessage)message).Commands);
            }

            if (message is AdjustTurnDelayNetworkMessage) {
                TurnDelay = ((AdjustTurnDelayNetworkMessage)message).NewDelay;
            }
        }
Пример #17
0
 public void HandleNetworkMessage(Player sender, INetworkMessage message) {
     Contract.Requires(message is LobbyLaunchedNetworkMessage);
     IsLaunched = true;
 }
Пример #18
0
        /// <summary>
        /// Host a new lobby.
        /// </summary>
        /// <param name="player">The player that is creating the server.</param>
        /// <param name="settings">The settings to use for the lobby.</param>
        /// <returns>A lobby host if successful.</returns>
        public static LobbyHost CreateLobby(Player player, LobbySettings settings) {
            NetworkContext context = NetworkContext.CreateServer(player, settings.Password);

            return new LobbyHost(context, settings.MapManager, settings.SerializedMap);
        }
 protected void Reset()
 {
     TargetUpdatesPerSecond = 10;
     HostPlayer = new Player("Default Player");
 }
Пример #20
0
        /// <summary>
        /// Invoke all registered INetworkMessageHandlers for the given message and sender.
        /// </summary>
        public void InvokeHandlers(Player sender, INetworkMessage message) {
            var handlers = GetHandlers(message.GetType());

            if (handlers.Count == 0) {
                Log<NetworkMessageDispatcher>.Warn("No handlers for message " + message);
            }

            for (int i = 0; i < handlers.Count; ++i) {
                handlers[i].HandleNetworkMessage(sender, message);
            }
        }
 public void OnConnected(Player player) {
     _notReady.Add(player);
 }