public GameItemViewModel(WCFGame model)
 {
     Model        = model;
     GameTypeItem = MainWindow.GameTypes.Single(p => p.Id == model.Settings.GameType);
     User         = MainWindow.GamePortal.GetUser(model.Settings.CreatorLogin);
     UpdateGameStatus();
 }
Exemple #2
0
        public WCFGame NewGame(string clientVersion, WCFGameSettings gameSettings, string gamePassword)
        {
            try
            {
                if (IsDisableNewGame || gameSettings == null || !gameSettings.CheckInput())
                {
                    return(null);
                }

#if !DEBUG
                //проверка версии клиента
                if (!string.IsNullOrEmpty(_UpdaterService.ClientVersion) && clientVersion != _UpdaterService.ClientVersion)
                {
                    throw new Exception($"Неверная версия клиента: login={gameSettings.CreatorLogin}.");
                }
#endif

                WCFUser gpUser = _GamePortalService.GetProfileByLogin(gameSettings.CreatorLogin);

                //TODO проверка может ли пользователь поставить такие условия

                /*if (gpUser == null
                || gpUser.MindRate < gameSettings.RateSettings.MindRate
                || gpUser.HonorRate < gameSettings.RateSettings.HonorRate
                || gpUser.LikeRate < gameSettings.RateSettings.LikeRate
                || gpUser.DurationHours < gameSettings.RateSettings.DurationRate)
                ||  return Guid.Empty;*/

#if !DEBUG //запрет на много игр
                using (Agot2p6Entities dbContext = new Agot2p6Entities())
                {
                    if (dbContext.Game.Count(p => p.CloseTime == null && (p.CreatorLogin == gameSettings.CreatorLogin || p.GameUser.Any(p1 => !string.IsNullOrEmpty(p1.HomeType) && p1.Login == gameSettings.CreatorLogin))) > 0)
                    {
                        return(null);
                    }
                }
#endif

                WCFGame wcfGame = CreateGame(gameSettings, gamePassword);
                if (wcfGame == null)
                {
                    return(null);
                }

                //поднимаем хост и сообщаем о новой игре
                NewHost(wcfGame.Id);
                _NotifyService.AddGameNotifi(wcfGame);

                return(wcfGame);
            }
            catch (Exception exp)
            {
                GameException.NewGameException(null, "Не удалось создать игру.", exp, false);
                return(null);
            }
        }
 //LockFunc _ClientList
 public void AddGameNotifi(WCFGame newItem)
 {
     lock (_ClientList)
     {
         _ClientList.ForEach(p => p.NotifiList.Add(new Notifi()
         {
             Game = newItem
         }));
     }
 }
        public void Load(WCFGame game)
        {
            GameId = game.Id;
            children.ForEach(p => p.MouseUp -= Item_MouseUp);
            children.Clear();
            content.Children.Clear();

            game.GameUser.Where(p => !string.IsNullOrEmpty(p.HomeType)).Select(p => p.HomeType).ToList()
            .ForEach(p => children.Add(new HomeSelectItem(p, string.Format("/Image/HomeSelect/{0}.jpg", ExtHomeType.Keys[p]))));
            children.Add(new HomeSelectItem("Random", "/Image/HomeSelect/random.jpg"));
            children.ForEach(p =>
            {
                content.Children.Add(p);
                p.MouseUp += Item_MouseUp;
            });

            var cf = new ChannelFactory <IGameService>("AGOT2Game");

            cf.Endpoint.Address = new EndpointAddress($"http://{App.Config.Settings.ServerAddress}:{App.Config.Settings.ServerPort}/GameHost/{GameId}");
            GameService         = cf.CreateChannel();

            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                App.TaskFactory.StartNew(() =>
                {
                    try
                    {
                        children.ForEach(p =>
                        {
                            var result = GameService.CheckAccessHome(MainWindow.GamePortal.User.Login, p.HomeType);
                            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                p.Access = result;
                            }), DispatcherPriority.ApplicationIdle);
                        });

                        if (children.All(p => !p.Access))
                        {
                            App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("notify_connectionGame2"));
                        }
                        else
                        {
                            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                this.Visibility = Visibility.Visible;
                            }), DispatcherPriority.ApplicationIdle);
                        }
                    }
                    catch (Exception exp)
                    {
                        App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_error"), App.GetResources("error_checkHomeStatus") + exp.Message);
                    }
                });
            }), DispatcherPriority.ApplicationIdle);
        }
Exemple #5
0
        public static void AddTask()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                App.TaskFactory.StartNew(() =>
                {
                    try
                    {
                        WCFGame result = App.Service.NewGame(App.ClientVersion, MainWindow.ClientInfo.GameSettings, string.IsNullOrEmpty(MainWindow.ClientInfo.GamePassword) ? null : MainWindow.ClientInfo.GamePassword);

                        if (result == null)
                        {
                            MainWindow.ClientInfo.OnLineStatus = false;
                            App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("error_createGame2"));
                        }
                        else
                        {
                            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                App.Agot2.homeSelectView.Load(result);
                            }), DispatcherPriority.ApplicationIdle);
                        }
                    }
                    catch (Exception exp)
                    {
                        MainWindow.ClientInfo.OnLineStatus = false;
                        App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_error"), App.GetResources("error_createGame1") + exp.Message);
                    }

                    IsBusy = false;
                });
            }), DispatcherPriority.ApplicationIdle);
        }
        public static void AddTask(Guid gameId)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            MainWindow.ClientInfo.OnLineStatus = false;
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                App.TaskFactory.StartNew(() =>
                {
                    try
                    {
                        ChannelFactory <IGameService> cf = new ChannelFactory <IGameService>("AGOT2Game");
                        cf.Endpoint.Address  = new EndpointAddress($"http://{App.Config.Settings.ServerAddress}:{App.Config.Settings.ServerPort}/GameHost/{gameId}");
                        IGameService service = cf.CreateChannel();

                        WCFGame result = service.Connect(
                            MainWindow.GamePortal.User.Login,
                            string.IsNullOrEmpty(MainWindow.ClientInfo.GamePassword) ? null : MainWindow.ClientInfo.GamePassword,
                            MainWindow.ClientInfo.HomeSelected);

                        if (result == null)
                        {
                            MainWindow.ClientInfo.OnLineStatus = false;
                            MainWindow.ClientInfo.ClientGameId = null;
                            App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("notify_connectionGame"));
                        }
                        else
                        {
                            result.GameUser.Where(p => !string.IsNullOrEmpty(p.Login) && p.Login != "Вестерос").ToList().ForEach(p => MainWindow.GamePortal.GetUser(p.Login));
                            ExtGame game = null;
                            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                ArrowViewModel.GlobalDuration = new Duration(TimeSpan.FromSeconds(5));
                                game = new ExtGame(result, service);

                                //скрываем профиль игрока
                                if (game.WCFGame.CloseTime == null)
                                {
                                    game.ExtGameUser.Where(p => p.WCFGameUser.HomeType != null && p.WCFGameUser.Login != null && p.WCFGameUser.Login != "Вестерос")
                                    .ToList().ForEach(p =>
                                    {
                                        p.GPUser.LeaderBoardVisibility = Visibility.Collapsed;
                                        p.GPUser.OnPropertyChanged("LeaderBoardVisibility");
                                    });
                                }
                            }), DispatcherPriority.ApplicationIdle).Wait();

                            MainWindow.ClientInfo.ClientGame   = game;
                            MainWindow.ClientInfo.OnLineStatus = true;
                            App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_notify"), App.GetResources("notify_mapRender"));
                        }
                    }
                    catch (Exception exp)
                    {
                        MainWindow.ClientInfo.OnLineStatus = false;
                        MainWindow.ClientInfo.ClientGameId = null;
                        App.Agot2.errorView.ShowByDispatcher(App.GetResources("text_error"), App.GetResources("error_connection") + exp.Message);
                    }

                    IsBusy = false;
                });
            }), DispatcherPriority.ApplicationIdle);
        }
 public void Update(WCFGame p)
 {
     Model = p;
     UpdateGameStatus();
     this.OnPropertyChanged("");
 }