예제 #1
0
        private void StartJoinGame(HostedGameViewModel hostedGame, DataNew.Entities.Game game)
        {
            Log.InfoFormat("Starting to join a game {0} {1}", hostedGame.GameId, hostedGame.Name);
            Program.IsHost                = false;
            Program.GameEngine            = new GameEngine(game, Program.LobbyClient.Me.UserName);
            Program.CurrentOnlineGameName = hostedGame.Name;
            IPAddress hostAddress = Dns.GetHostAddresses(AppConfig.GameServerPath).FirstOrDefault();

            if (hostAddress == null)
            {
                Log.WarnFormat("Dns Error, couldn't resolve {0}", AppConfig.GameServerPath);
                throw new UserMessageException("There was a problem with your DNS. Please try again.");
            }

            try
            {
                Log.InfoFormat("Creating client for {0}:{1}", hostAddress, hostedGame.Port);
                Program.Client = new Client(hostAddress, hostedGame.Port);
                Log.InfoFormat("Connecting client for {0}:{1}", hostAddress, hostedGame.Port);
                Program.Client.Connect();
            }
            catch (Exception e)
            {
                Log.Warn("Start join game error ", e);
                throw new UserMessageException("Could not connect. Please try again.");
            }
        }
예제 #2
0
        private void StartJoinGame(HostedGameViewModel hostedGame, DataNew.Entities.Game game, bool spectate)
        {
            if (hostedGame.GameSource == "Online")
            {
                var client = new Octgn.Site.Api.ApiClient();
                if (!client.IsGameServerRunning(Program.LobbyClient.Username, Program.LobbyClient.Password))
                {
                    throw new UserMessageException("The game server is currently down. Please try again later.");
                }
            }
            Log.InfoFormat("Starting to join a game {0} {1}", hostedGame.GameId, hostedGame.Name);
            Program.IsHost        = false;
            Program.IsMatchmaking = false;
            var password = "";

            if (hostedGame.HasPassword)
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    var dlg  = new InputDlg("Password", "Please enter this games password", "");
                    password = dlg.GetString();
                }));
            }
            var username = (Program.LobbyClient.IsConnected == false ||
                            Program.LobbyClient.Me == null ||
                            Program.LobbyClient.Me.UserName == null) ? Prefs.Nickname : Program.LobbyClient.Me.UserName;

            Program.GameEngine            = new GameEngine(game, username, spectate, password);
            Program.CurrentOnlineGameName = hostedGame.Name;
            IPAddress hostAddress = hostedGame.IPAddress;

            if (hostAddress == null)
            {
                Log.WarnFormat("Dns Error, couldn't resolve {0}", AppConfig.GameServerPath);
                throw new UserMessageException("There was a problem with your DNS. Please try again.");
            }

            try
            {
                Log.InfoFormat("Creating client for {0}:{1}", hostAddress, hostedGame.Port);
                Program.Client = new ClientSocket(hostAddress, hostedGame.Port);
                Log.InfoFormat("Connecting client for {0}:{1}", hostAddress, hostedGame.Port);
                Program.Client.Connect();
            }
            catch (Exception e)
            {
                Log.Warn("Start join game error ", e);
                throw new UserMessageException("Could not connect. Please try again.");
            }
        }
예제 #3
0
        public Task <bool> JoinGame(HostedGameViewModel hostedGameViewModel, string username, bool spectate)
        {
            User user;

            if (Program.LobbyClient.User != null)
            {
                user = Program.LobbyClient.User;
            }
            else
            {
                user = new User(Guid.NewGuid().ToString(), Prefs.Username);
            }

            var hostedGame = hostedGameViewModel.HostedGame;

            DebugValidate(hostedGame, false);

            var args = "-j ";

            if (CommandLineHandler.Instance.DevMode)
            {
                args += "-x ";
            }

            new HostedGameProcess(
                hostedGame,
                X.Instance.Debug,
                true
                ).Start();

            args += $"-u \"{username}\" ";
            if (spectate)
            {
                args += "-s ";
            }
            args += "-k \"" + HostedGame.Serialize(hostedGame) + "\"";

            return(LaunchJodsEngine(args));
        }
예제 #4
0
        private void StartJoinGame(HostedGameViewModel hostedGame, Data.Game game)
        {
            Program.IsHost = false;
            Program.Game   = new Game(GameDef.FromO8G(game.FullPath), Program.LobbyClient.Me.UserName);
            Program.CurrentOnlineGameName = hostedGame.Name;
            IPAddress hostAddress = Dns.GetHostAddresses(Program.GameServerPath).FirstOrDefault();

            if (hostAddress == null)
            {
                throw new UserMessageException("There was a problem with your DNS. Please try again.");
            }

            try
            {
                Program.Client = new Client(hostAddress, hostedGame.Port);
                Program.Client.Connect();
            }
            catch (Exception)
            {
                throw new UserMessageException("Could not connect. Please try again.");
            }
        }