Beispiel #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);
        }