Esempio n. 1
0
        public void Update(HostedGameViewModel newer, Game[] games)
        {
            var game = games.FirstOrDefault(x => x.Id == this.gameId);
            var u    = new User(new User(User + "@" + AppConfig.ChatServerPath));

            if (u.ApiUser != null)
            {
                if (!String.IsNullOrWhiteSpace(u.ApiUser.IconUrl))
                {
                    if (previousIconUrl != u.ApiUser.IconUrl)
                    {
                        try
                        {
                            previousIconUrl = u.ApiUser.IconUrl;
                            UserImage       = new BitmapImage(new Uri(u.ApiUser.IconUrl));
                        }
                        catch (Exception e)
                        {
                            Log.Error("Can't set UserImage to Uri", e);
                        }
                    }
                }
            }
            var ts = new TimeSpan(DateTime.Now.Ticks - StartTime.Ticks);

            RunTime = string.Format("{0}h {1}m", Math.Floor(ts.TotalHours), ts.Minutes);
            if (newer != null)
            {
                Status = newer.Status;
            }
            UpdateVisibility();
            if (game == null)
            {
                this.CanPlay = false;
                return;
            }
            this.CanPlay = true;
        }
Esempio n. 2
0
        private void StartJoinGame(HostedGameViewModel hostedGame, DataNew.Entities.Game game)
        {
            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;
            var password = "";
            if (hostedGame.HasPassword)
            {
                Dispatcher.Invoke(new Action(() =>
                    {
                        var dlg = new InputDlg("Password", "Please enter this games password", "");
                        password = dlg.GetString();
                    }));
            }
            Program.GameEngine = new GameEngine(game, Program.LobbyClient.Me.UserName,password);
            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.");
            }
        }
Esempio n. 3
0
 public void Update(HostedGameViewModel newer, Game[] games)
 {
     var game = games.FirstOrDefault(x => x.Id == this.gameId);
     var u = new User(new User(User + "@" + AppConfig.ChatServerPath));
     if (u.ApiUser != null)
     {
         if (!String.IsNullOrWhiteSpace(u.ApiUser.IconUrl))
         {
             if (previousIconUrl != u.ApiUser.IconUrl)
             {
                 try
                 {
                     previousIconUrl = u.ApiUser.IconUrl;
                     UserImage = new BitmapImage(new Uri(u.ApiUser.IconUrl));
                 }
                 catch (Exception e)
                 {
                     Log.Error("Can't set UserImage to Uri", e);
                 }
             }
         }
     }
     var ts = new TimeSpan(DateTime.Now.Ticks - StartTime.Ticks);
     RunTime = string.Format("{0}h {1}m {2}s", Math.Floor(ts.TotalHours), ts.Minutes, ts.Seconds);
     if (newer != null)
     {
         Status = newer.Status;
     }
     UpdateVisibility();
     if (game == null)
     {
         this.CanPlay = false;
         return;
     }
     this.CanPlay = true;
 }
Esempio n. 4
0
        private void StartJoinGame(HostedGameViewModel hostedGame, Data.Game game)
        {
            Program.IsHost = false;
            Program.Game = new Game(GameDef.FromO8G(game.FullPath));
            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.");
            }
        }
Esempio n. 5
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.");
            }
        }