Exemplo n.º 1
0
        public static void NewGameException(Guid?gameId, string specialText, Exception exp, bool sendMsg)
        {
            GameException result = new GameException
            {
                Game       = gameId,
                Message    = $"{GameException.CombineMsg(exp, specialText)}",
                stackTrace = exp.StackTrace
            };

            using (Agot2p6Entities agot2p6Entities = new Agot2p6Entities())
            {
                agot2p6Entities.GameException.Add(result);
                agot2p6Entities.SaveChanges();
            }

            if (sendMsg)
            {
                lock (Service.WebSockServiceList)
                {
                    ChatService item = Service.WebSockServiceList.SingleOrDefault(p => p.GameId == gameId) as ChatService;
                    item?.AddChat(new Chat()
                    {
                        Creator = "Вестерос", Message = $"dynamic_error*error_criticalError*!\n{result.Message}"
                    });
                }
            }
        }
Exemplo n.º 2
0
        public AntiCheatException(Guid userId, string message)
        {
            Guid gameId = Guid.Empty;

            try
            {
                using (Agot2p6Entities agot2p6Entities = new Agot2p6Entities())
                {
                    GameUser user = agot2p6Entities.GameUser.Single(p => p.Id == userId);
                    gameId             = user.Game;
                    user.NeedReConnect = true;
                    agot2p6Entities.SaveChanges();

                    lock (Service.WebSockServiceList)
                    {
                        ChatService item = Service.WebSockServiceList.SingleOrDefault(p => p.GameId == gameId) as ChatService;
                        item?.AddChat(new Chat()
                        {
                            Creator = "Вестерос", Message = $"dynamic_errorStep*homeType_{user.HomeType}*{message}"
                        });
                    }
                }
            }
            catch (Exception exp) { GameException.NewGameException(gameId, "Не удалось обработать результаты \"чит проверки\" (Failed to process the results of \"cheat validate\").", exp, false); }
        }
Exemplo n.º 3
0
        public void SendStep(WCFStep wcfStep)
        {
            TaskFactory.StartNew(() =>
            {
#if DEBUG
                /*var xml = new PublicFileJson<WCFStep>("SendStep.txt");
                 * xml.Value = wcfStep;
                 * xml.Write();*/
#endif
                try
                {
                    using (Agot2p6Entities dbContext = new Agot2p6Entities())
                    {
                        var user             = dbContext.GameUser.Single(p => p.Id == wcfStep.GameUser);
                        user.Game1.DbContext = dbContext;
                        user.Game1.GameHost  = this;

                        Step serverStep = user.Game1.HomeUsersSL.Select(p => p.LastStep).Single(p => p.Id == wcfStep.Id);
                        wcfStep.Update(serverStep);

                        if (user.Game1.HomeUsersSL.SelectMany(p => p.Step).All(p => p.IsFull))
                        {
                            NextStage(user.Game1);
                        }

                        ArrowsData.AddToDbContext(user.Game1);
                        dbContext.SaveChanges();
                    }
                }
                catch (TheEndException) { }
                catch (AntiCheatException) { }
                catch (Exception exp) { GameException.NewGameException(wcfStep.Game, string.Format("Не удалось обработать ход (Failed to process the step): {0}", wcfStep != null ? wcfStep.StepType : "пустой ход"), exp, true); }
            });
        }
Exemplo n.º 4
0
        static TimeSpan _TimerPeriod   = TimeSpan.FromMilliseconds(-1);//off

        void CheckGameActivity()
        {
            TaskFactory.StartNew(() =>
            {
                try
                {
                    using (Agot2p6Entities dbContext = new Agot2p6Entities())
                    {
                        var game       = dbContext.Game.Single(p => p.Id == this.GameId);
                        game.GameHost  = this;
                        game.DbContext = dbContext;

                        if (game.CreatorLogin == "System")
                        {
                            return;
                        }

                        if (game.CloseTime == null)
                        {
                            RemoveUser(game);

                            var time = DateTimeOffset.UtcNow - GameHost._AutoCloseTime;
                            if (game.OpenTime != null && game.GameUser.Any(p => !string.IsNullOrEmpty(p.HomeType) && !p.LastStep.IsFull && p.LastUpdate < time))
                            {
                                game.TheEnd();
                            }
                        }
                        //игру можно удалять и она закрыта
                        else if (!game.IsDeleteIgnore)
                        {
                            //удаление брошенных партий или завершённых (через сутки)
                            if (game.OpenTime == null || DateTimeOffset.UtcNow - game.CloseTime > GameHost._GameLiveTime)
                            {
                                dbContext.Game.Remove(game);
                                if (Closed != null)
                                {
                                    Closed(this);
                                }
                            }
                        }

                        dbContext.SaveChanges();
                    }
                }
                catch (TheEndException) { }
                catch (Exception exp)
                {
                    GameException.NewGameException(this.GameId, "Не удалось проверить активность партии.", exp, false);
                }

                if (_Timer != null)
                {
                    _Timer.Change(_TimerDueTime, _TimerPeriod);
                }
            });
        }
Exemplo n.º 5
0
        public void DisConnectTask(WCFGameUser clientUser)
        {
            GameHost.TaskFactory.StartNew(() =>
            {
                try
                {
                    using (Agot2p6Entities dbContext = new Agot2p6Entities())
                    {
                        GameUser user = dbContext.GameUser.SingleOrDefault(p => p.Id == clientUser.Id);
                        if (user == null || !clientUser.Check(user))
                        {
                            return;
                        }

                        Game game = user.Game1;
                        if (game.CreateTime < DateTimeOffset.UtcNow && game.CloseTime == null && !string.IsNullOrEmpty(user.HomeType))
                        {
                            var profile = GamePortalServer.GetProfileByLogin(user.Login);

                            if (game.OpenTime != null)
                            {
                                GamePortalServer.StopUserGame(user.Login, game.Id);
                            }
                            else
                            {
                                GameHost.AddUserNotifiFunc(profile, string.Format("dynamic_leftGame1*{0}", user.HomeType));
                            }

                            if (!string.IsNullOrEmpty(user.HomeType))
                            {
                                var whois    = profile == null ? user.Login : profile.Api["FIO"];
                                var response = ExtHttp.Post($"http://{GameHost.Config.Settings.ServerAddress}:{GameHost.Config.Settings.ServerPort}/ChatService/AddChat",
                                                            JsonConvert.SerializeObject(new { roomId = game.Id, creator = "Вестерос", message = $"dynamic_Exile*{user.HomeType}*{whois}" }));
                                //GameHost.AddChatFunc(game.Id, "Вестерос", string.Format("dynamic_Exile*homeType_{0}*{1}",
                                //    user.HomeType,
                                //    profile == null ? user.Login : profile.Api["FIO"]));
                            }

                            _DeniedLogin.Add(user.Login);
                            user.Login = null;
                            dbContext.SaveChanges();

                            //TODO перенести в Realease
                            if (game.OpenTime != null)
                            {
                                GameHost.AddGameNotifiFunc(game.ToWCFGame());
                            }
                        }
                    }
                }
                catch (Exception exp)
                {
                    GameException.NewGameException(clientUser.Game, "Не удалось отключиться от игры.", exp, false);
                }
            });
        }
Exemplo n.º 6
0
        public List <WCFGameUser> GetUserInfo(WCFGameUser clientUser)
        {
            if (clientUser == null || !clientUser.CheckIn())
            {
                return(null);
            }

            return(TaskFactory.StartNew(() =>
            {
                try
                {
                    using (Agot2p6Entities dbContext = new Agot2p6Entities())
                    {
                        var user = dbContext.GameUser.SingleOrDefault(p => p.Id == clientUser.Id);
                        if (user == null || !clientUser.Check(user))
                        {
                            return null;
                        }

                        user.LastUpdate = DateTimeOffset.UtcNow;
                        var game = user.Game1;
                        List <WCFGameUser> result = game.GameUser.Select(p => p.ToWCFGameUser(user, clientUser)).ToList();
                        if (game.OpenTime == null && result.Where(p => !string.IsNullOrEmpty(p.HomeType)).All(p => !string.IsNullOrEmpty(p.Login) && p.OnLineStatus))
                        {
                            game.HomeUsersSL.ForEach(p => GamePortalServer.StartUserGame(p.Login, p.HomeType, game.Id, game.Type + (game.RandomIndex > 0 || game.IsRandomSkull ? 1 : 0)));
                            game.OpenTime = DateTimeOffset.UtcNow;
                            game.NewThink();
                        }
                        dbContext.SaveChanges();

#if DEBUG
                        /*var xml = new PublicFileJson<List<WCFGameUser>>("GetUserInfo.txt");
                         * xml.Value = result;
                         * xml.Write();*/
#endif

                        return result;
                    }
                }
                catch (Exception exp)
                {
                    GameException.NewGameException(clientUser.Game, "Не удалось подготовить спискок игроков.", exp, false);
                    return null;
                }
            }).Result);
        }
Exemplo n.º 7
0
        // GameService.GameHost+<>c__DisplayClass60_0.<GetUserInfo>b__0	47 245	13	9,07%	0,00%
        public List <WCFGameUser> GetUserInfo(WCFGameUser clientUser)
        {
            return(TaskFactory.StartNew(() =>
            {
                try
                {
                    if (clientUser == null || !clientUser.CheckIn())
                    {
                        return null;
                    }

                    using (Agot2p6Entities dbContext = new Agot2p6Entities())
                    {
                        GameUser user = dbContext.GameUser.SingleOrDefault(p => p.Id == clientUser.Id);
                        if (user == null || !clientUser.Check(user))
                        {
                            return null;
                        }

                        user.LastUpdate = DateTimeOffset.UtcNow;
                        Game game = user.Game1;
                        List <WCFGameUser> result = game.GameUser.Select(p => p.ToWCFGameUser(user, clientUser)).ToList();

                        dbContext.SaveChanges();

#if DEBUG
                        /*var xml = new PublicFileJson<List<WCFGameUser>>("GetUserInfo.txt");
                         * xml.Value = result;
                         * xml.Write();*/
#endif

                        return result;
                    }
                }
                catch (Exception exp)
                {
                    GameException.NewGameException(clientUser.Game, "Не удалось подготовить спискок игроков.", exp, false);
                    return null;
                }
            }).Result);
        }
Exemplo n.º 8
0
        public AntiCheatException(Guid userId, string message)
        {
            GameHost.TaskFactory.StartNew(() =>
            {
                Guid gameId = Guid.Empty;
                try
                {
                    using (Agot2p6Entities agot2p6Entities = new Agot2p6Entities())
                    {
                        var user           = agot2p6Entities.GameUser.Single(p => p.Id == userId);
                        gameId             = user.Game;
                        user.NeedReConnect = true;
                        agot2p6Entities.SaveChanges();

                        var response = ExtHttp.Post($"http://{GameHost.Config.Settings.ServerAddress}/ChatService/AddChat",
                                                    JsonConvert.SerializeObject(new { roomId = gameId, creator = "Вестерос", message = $"dynamic_errorStep*homeType_{user.HomeType}*{message}" }));
                        //GameHost.AddChatFunc(gameId, "Вестерос", string.Format("dynamic_errorStep*homeType_{0}*{1}", user.HomeType, message));
                    }
                }
                catch (Exception exp) { GameException.NewGameException(gameId, "Не удалось обработать результаты \"чит проверки\" (Failed to process the results of \"cheat validate\").", exp, false); }
            });
        }
Exemplo n.º 9
0
        public static void NewGameException(Guid gameId, string specialText, Exception exp, bool sendMsg)
        {
            GameException result = new GameException();

            result.Game    = gameId;
            result.Login   = "******";
            result.Message = string.Format("{0}\n{1}", specialText, exp.ToString());

            GameHost.TaskFactory.StartNew(() =>
            {
                using (Agot2p6Entities agot2p6Entities = new Agot2p6Entities())
                {
                    agot2p6Entities.GameException.Add(result);
                    agot2p6Entities.SaveChanges();
                }
            });

            if (sendMsg)
            {
                var response = ExtHttp.Post($"http://{GameHost.Config.Settings.ServerAddress}/ChatService/AddChat",
                                            JsonConvert.SerializeObject(new { roomId = gameId, creator = "Вестерос", message = $"dynamic_error*error_criticalError*!\n{specialText}\n{exp.Message}" }));
                //GameHost.AddChatFunc(gameId, "Вестерос", string.Format("dynamic_error*error_criticalError*!\n{0}\n{1}", specialText, exp.Message));
            }
        }
Exemplo n.º 10
0
        private void CheckGameActivity()
        {
            TaskFactory.StartNew(() =>
            {
                InternetConnection newInetStatus = null;
                try
                {
                    #region Ожидание при отключении/подключения к интернету
                    dateTimeNow   = DateTimeOffset.UtcNow;
                    newInetStatus = new InternetConnection();

                    //если произошло переподключение
                    if ((lastInetStatus == null || !lastInetStatus.IsInternetConnected) && newInetStatus.IsInternetConnected)
                    {
                        inetConnectionTime = dateTimeNow;
                        royalPardon        = true;

                        //Начало проверки после запуска через...
                        _Timer?.Change(_InetRestartTime, _TimerPeriod);
                        lastInetStatus = newInetStatus;
                        return;
                    }
                    #endregion

                    if (newInetStatus.IsInternetConnected)
                    {
                        using (Agot2p6Entities dbContext = new Agot2p6Entities())
                        {
                            Game game = dbContext.Game.Single(p => p.Id == this.GameId);
                            if (game.CreatorLogin == "System")
                            {
                                return;
                            }

                            game.GameHost  = this;
                            game.DbContext = dbContext;

                            if (game.CloseTime == null)
                            {
                                RemoveUser(game);

                                if (game.OpenTime != null)
                                {
                                    GameUser user = game.GameUser.FirstOrDefault(p => !string.IsNullOrEmpty(p.HomeType) && !p.LastStep.IsFull && p.LastUpdate < dateTimeNow - _AutoCloseTime);
                                    if (user != null && !Capitulate(game, user))
                                    {
                                        game.TheEnd();
                                    }
                                }
                            }
                            //игру можно удалять и она закрыта
                            else if (!game.IsDeleteIgnore)
                            {
                                //удаление брошенных партий или завершённых (через сутки)
                                if (game.OpenTime == null || dateTimeNow - game.CloseTime > GameHost._GameLiveTime)
                                {
                                    dbContext.Game.Remove(game);
                                    Closed?.Invoke(this);
                                }
                            }

                            dbContext.SaveChanges();
                        }
                    }
                }
                catch (TheEndException) { }
                catch (Exception exp)
                {
                    GameException.NewGameException(this.GameId, "Не удалось проверить активность партии.", exp, false);
                }

                _Timer?.Change(_TimerDueTime, _TimerPeriod);
                lastInetStatus = newInetStatus;
            });
        }
Exemplo n.º 11
0
        private WCFGame ConnectTask(string login, string gamePassword, string homeType)
        {
            //если дом занят или недоступен то наблюдатель
            if (homeType != null && !CheckAccessHomeFunc(login, homeType))
            {
                homeType = null;
            }

            using (Agot2p6Entities dbContext = new Agot2p6Entities())
            {
                WCFUser  profile  = GamePortalServer.GetProfileByLogin(login);
                Game     game     = dbContext.Game.Single(p => p.Id == GameId);
                GameUser gameUser = game.GameUser.SingleOrDefault(p => p.Login == login);

                //Пользователь уже принимал участие
                //_DeniedLogin.TryGetValue(login, out int liaveCount);
                IEnumerable <WCFUserGame> usergames = profile.UserGames.Where(p => p.GameId == this.GameId);
                if (usergames.Count(p => p.EndTime.HasValue && !p.IsIgnoreHonor) > GameHost.MaxLiaveCount)
                {
                    homeType = null;
                    ChatService.AddChat(new Chat()
                    {
                        Creator = "Вестерос", Message = $"dynamic_ExileEarlier*{profile.Api["FIO"]}"
                    });
                }
                else
                {
                    //потенциаьный лорд
                    if (gameUser == null || gameUser.HomeType == null)
                    {
                        //выбран дом и игра не закрыта
                        if (!string.IsNullOrEmpty(homeType) && game.CloseTime == null)
                        {
                            //пароль отсутствует или указан верно
                            if (string.IsNullOrEmpty(game.Password) || game.Password == gamePassword)
                            {
                                //Удаляем наблюдателя
                                if (gameUser != null && gameUser.HomeType == null)
                                {
                                    dbContext.GameUser.Remove(gameUser);
                                    gameUser = null;
                                }

                                //конкретный дом
                                if (homeType != "Random")
                                {
                                    gameUser       = game.HomeUsersSL.SingleOrDefault(p => p.HomeType == homeType);
                                    gameUser.Login = login;
                                }
                                //Случайный дом
                                else
                                {
                                    //Определяем свободные дома и сортируем по имени дома
                                    List <GameUser> freeHome = game.HomeUsersSL.Where(p => p.Login == null).OrderBy(p => p.HomeType).ToList();

                                    //если игрок ранее заходил в эту игру, то определяем за какой дом в последний раз он играл
                                    WCFUserGame lastgame = usergames.OrderBy(p => p.StartTime).LastOrDefault();
                                    if (lastgame != null)
                                    {
                                        //Если этот дом свободен, то отдаём его пользователю
                                        gameUser = freeHome.FirstOrDefault(p => p.HomeType == lastgame.HomeType);
                                        if (gameUser != null)
                                        {
                                            gameUser.Login = login;
                                        }
                                    }

                                    //если дом не присвоен
                                    if (gameUser == null)
                                    {
                                        //отдаём тот дом за который пользователь играл меньше всего
                                        gameUser       = freeHome.OrderBy(p => profile.UserGames.Count(p1 => p1.HomeType == p.HomeType)).First();
                                        gameUser.Login = login;
                                    }

                                    //if (lastgame == null)
                                    //{
                                    //    int index = GameHost.Rnd.Next(freeHome.Count());
                                    //    gameUser = freeHome.ElementAt(index);
                                    //    gameUser.Login = login;
                                    //}
                                }

                                ChatService.AddChat(new Chat()
                                {
                                    Creator = "Вестерос", Message = $"dynamic_hiLord*Faceless Men*homeType_{gameUser.HomeType}"
                                });                                                                                                //profile.Api["FIO"]
                                GameHost.AddUserNotifiFunc(profile, $"dynamic_inGame*{game.Name ?? "text_newGame"}*unknown home"); //{gameUser.HomeType}
                                if (game.OpenTime != null)
                                {
                                    GamePortalServer.StartUserGame(gameUser.Login, gameUser.HomeType, game.Id, game.Type + (game.RandomIndex > 0 || game.IsRandomSkull ? 1 : 0), game.NoTimer, true);
                                }
                            }
                            else
                            {
                                ChatService.AddChat(new Chat()
                                {
                                    Creator = "Вестерос", Message = $"dynamic_passwordDenied*Faceless Men"
                                });                                                                                                        //{profile.Api["FIO"]}
                            }
                        }
                    }
                }

                //наблюдатель
                if (gameUser == null)
                {
                    gameUser = new GameUser(game)
                    {
                        Login = login
                    };

                    game.GameUser.Add(gameUser);
                }

                gameUser.LastUpdate    = DateTimeOffset.UtcNow;
                gameUser.NeedReConnect = false;


                if (game.OpenTime == null && game.HomeUsersSL.All(p => !string.IsNullOrEmpty(p.Login) && (DateTimeOffset.UtcNow - p.LastUpdate) < new TimeSpan(0, 0, 5)))
                {
                    game.HomeUsersSL.ForEach(p => GamePortalServer.StartUserGame(p.Login, p.HomeType, game.Id, game.Type + (game.RandomIndex > 0 || game.IsRandomSkull ? 1 : 0), game.NoTimer));
                    game.OpenTime = DateTimeOffset.UtcNow;
                    game.NewThink();
                }

                dbContext.SaveChanges();

                System.Collections.Generic.IEnumerable <GameUser> gameUsers = game.HomeUsersSL.Where(p => p.Login != null);
                var privateDate = gameUsers.Select(p => new { gameUser = p, privateDate = GamePortalServer.GetPrivateProfileData(p.Login) }).ToList();
                var groupe      = privateDate.GroupBy(p => p.privateDate["clientId"]).Where(p => p.Count() > 1).ToList();
                groupe.AddRange(privateDate.GroupBy(p => p.privateDate["email"]).Where(p => p.Key != null && p.Count() > 1).ToList());
                groupe.AddRange(privateDate.GroupBy(p => p.privateDate["password"]).Where(p => p.Count() > 1).ToList());
                groupe.SelectMany(p => p.Select(p1 => string.Concat(p.Select(p2 => "\n" + p2.gameUser.HomeType)))).Distinct().ToList().ForEach(p =>
                {
                    ChatService.AddChat(new Chat()
                    {
                        Creator = "Вестерос", Message = $"dynamic_samePC*{p}"
                    });
                });

                return(game.ToWCFGame());
            }
        }
Exemplo n.º 12
0
        public void DisConnectTask(WCFGameUser clientUser)
        {
            using (Agot2p6Entities dbContext = new Agot2p6Entities())
            {
                GameUser user = dbContext.GameUser.SingleOrDefault(p => p.Id == clientUser.Id);
                if (user == null || !clientUser.Check(user))
                {
                    return;
                }

                Game game = user.Game1;
                game.GameHost  = this;
                game.DbContext = dbContext;
                if (game.CreateTime < DateTimeOffset.UtcNow && game.CloseTime == null && !string.IsNullOrEmpty(user.HomeType))
                {
//                    bool hasVaule = _DeniedLogin.TryGetValue(user.Login, out int oldLiaveCount);
//                    int newLiaveCount = game.OpenTime == null ? GameHost.MaxLiaveCount + 1 : oldLiaveCount + 1;
//#if !DEBUG
//                    if (!hasVaule) _DeniedLogin.TryAdd(user.Login, newLiaveCount);
//                    else _DeniedLogin.TryUpdate(user.Login, newLiaveCount, oldLiaveCount);
//#endif

                    GamePortal.WCFUser profile = GamePortalServer.GetProfileByLogin(user.Login);

                    if (game.OpenTime != null)
                    {
                        GamePortalServer.StopUserGame(user.Login, game.Id);
#if DEBUG
                        Capitulate(game, user);
#endif
                    }
                    else
                    {
                        GameHost.AddUserNotifiFunc(profile, $"dynamic_leftGame1*unknown home");//{user.HomeType}
                    }
                    string whois      = profile == null ? user.Login : profile.Api["FIO"];
                    int    liaveCount = profile.UserGames.Count(p => p.GameId == this.GameId && p.EndTime.HasValue && !p.IsIgnoreHonor);
                    if (liaveCount > GameHost.MaxLiaveCount)
                    {
                        ChatService.AddChat(new Chat()
                        {
                            Creator = "Вестерос", Message = $"dynamic_Exile*homeType_{user.HomeType}*Faceless Men"
                        });                                                                                                                        //{whois}
                    }
                    else if (game.OpenTime != null)
                    {
                        ChatService.AddChat(new Chat()
                        {
                            Creator = "Вестерос", Message = $"dynamic_leftGame*homeType_{user.HomeType}*Faceless Men*{GameHost.MaxLiaveCount - liaveCount + 1}"
                        });                                                                                                                                                                     //{whois}
                    }
                    user.Login = null;
                    dbContext.SaveChanges();

                    if (game.OpenTime != null)
                    {
                        GameHost.AddGameNotifiFunc(game.ToWCFGame());
                    }
                }
            }
        }
Exemplo n.º 13
0
        WCFGame ConnectTask(string login, string gamePassword, string homeType)
        {
            return(GameHost.TaskFactory.StartNew(() =>
            {
                try
                {
                    //если дом занят или недоступен то наблюдатель
                    if (homeType != null && !CheckAccessHomeFunc(login, homeType))
                    {
                        homeType = null;
                    }

                    using (Agot2p6Entities dbContext = new Agot2p6Entities())
                    {
                        var profile = GamePortalServer.GetProfileByLogin(login);
                        var game = dbContext.Game.Single(p => p.Id == GameId);
                        var gameUser = game.GameUser.SingleOrDefault(p => p.Login == login);

                        //Пользователь уже принимал участие
                        if (_DeniedLogin.Any(p => p == login))
                        {
                            homeType = null;
                            var whois = profile.Api["FIO"];
                            var response = ExtHttp.Post($"http://{GameHost.Config.Settings.ServerAddress}:{GameHost.Config.Settings.ServerPort}/ChatService/AddChat",
                                                        JsonConvert.SerializeObject(new { roomId = game.Id, creator = "Вестерос", message = $"dynamic_ExileEarlier*{whois}" }));
                            //GameHost.AddChatFunc(game.Id, "Вестерос", string.Format("dynamic_ExileEarlier*{0}", profile.Api["FIO"]));
                        }
                        else
                        {
                            //потенциаьный лорд
                            if (gameUser == null || gameUser.HomeType == null)
                            {
                                //выбран дом и игра не закрыта
                                if (!string.IsNullOrEmpty(homeType) && game.CloseTime == null)
                                {
                                    //игра открыта или проходит по рейтингу
                                    //if (game.OpenTime != null || profile.CheckRateAllow(game.RateSettings))
                                    {
                                        //небыл изгнан ранее
                                        if (!profile.UserGames.Any(p => p.GameId == GameId && p.EndTime.HasValue))
                                        {
                                            //пароль отсутствует или указан верно
                                            if (string.IsNullOrEmpty(game.Password) || game.Password == gamePassword)
                                            {
                                                //Удаляем наблюдателя
                                                if (gameUser != null && gameUser.HomeType == null)
                                                {
                                                    dbContext.GameUser.Remove(gameUser);
                                                    gameUser = null;
                                                }

                                                //конкретный дом
                                                if (homeType != "Random")
                                                {
                                                    gameUser = game.HomeUsersSL.SingleOrDefault(p => p.HomeType == homeType);
                                                    gameUser.Login = login;
                                                }
                                                //Случайный дом
                                                else
                                                {
                                                    var freeHome = game.HomeUsersSL.Where(p => p.Login == null).ToList();
                                                    int index = GameHost.Rnd.Next(freeHome.Count());
                                                    gameUser = freeHome.ElementAt(index);
                                                    gameUser.Login = login;
                                                }

                                                var whois = profile.Api["FIO"];
                                                var response = ExtHttp.Post($"http://{GameHost.Config.Settings.ServerAddress}:{GameHost.Config.Settings.ServerPort}/ChatService/AddChat",
                                                                            JsonConvert.SerializeObject(new { roomId = game.Id, creator = "Вестерос", message = $"dynamic_hiLord*{whois}*homeType_{gameUser.HomeType}" }));
                                                //GameHost.AddChatFunc(game.Id, "Вестерос", string.Format("dynamic_hiLord*{0}*homeType_{1}", profile.Api["FIO"], gameUser.HomeType));
                                                GameHost.AddUserNotifiFunc(profile, string.Format("dynamic_inGame*{0}*{1}", string.IsNullOrEmpty(game.Name) ? "text_newGame" : game.Name, gameUser.HomeType));
                                                if (game.OpenTime != null)
                                                {
                                                    GamePortalServer.StartUserGame(gameUser.Login, gameUser.HomeType, game.Id, game.Type + (game.RandomIndex > 0 || game.IsRandomSkull ? 1 : 0), true);
                                                }
                                            }
                                            else
                                            {
                                                var whois = profile.Api["FIO"];
                                                var response = ExtHttp.Post($"http://{GameHost.Config.Settings.ServerAddress}:{GameHost.Config.Settings.ServerPort}/ChatService/AddChat",
                                                                            JsonConvert.SerializeObject(new { roomId = game.Id, creator = "Вестерос", message = $"dynamic_passwordDenied*{whois}" }));
                                                //GameHost.AddChatFunc(game.Id, "Вестерос", string.Format("dynamic_passwordDenied*{0}", profile.Api["FIO"]));
                                            }
                                        }
                                        else
                                        {
                                            _DeniedLogin.Add(login);
                                            var whois = profile.Api["FIO"];
                                            var response = ExtHttp.Post($"http://{GameHost.Config.Settings.ServerAddress}:{GameHost.Config.Settings.ServerPort}/ChatService/AddChat",
                                                                        JsonConvert.SerializeObject(new { roomId = game.Id, creator = "Вестерос", message = $"dynamic_ExileEarlier*{whois}" }));
                                            //GameHost.AddChatFunc(game.Id, "Вестерос", string.Format("dynamic_ExileEarlier*{0}", profile.Api["FIO"]));
                                        }
                                    }
                                    //else  GameHost.AddChatFunc(game.Id, "Вестерос", string.Format("{0}, у вас низкий рейтинг.", profile.Api["FIO"]));
                                }
                            }
                        }

                        //наблюдатель
                        if (gameUser == null)
                        {
                            gameUser = new GameUser(game);
                            gameUser.Login = login;

                            //if (game.CloseTime == null)
                            //     GameHost.AddChatFunc(game.Id, "Вестерос", string.Format("{0}, приветствуем Вас!", profile.Api["FIO"]));

                            game.GameUser.Add(gameUser);
                        }

                        gameUser.LastUpdate = DateTimeOffset.UtcNow;
                        gameUser.NeedReConnect = false;
                        dbContext.SaveChanges();

                        /*foreach (var item in game.HomeUsersSL.Where(p => p.Login != null).GroupBy(p => GamePortalServer.GetProfileByLogin(p.Login).ClientId).Where(p => p.Count() > 1).ToList())
                         *  GameHost.AddChatFunc(game.Id, "Вестерос", string.Format("dynamic_samePC*{0}", String.Concat(item.Select(p => "\n" + p.HomeType))));*/

                        var gameUsers = game.HomeUsersSL.Where(p => p.Login != null);
                        var privateDate = gameUsers.Select(p => new { gameUser = p, privateDate = GamePortalServer.GetPrivateProfileData(p.Login) }).ToList();
                        var groupe = privateDate.GroupBy(p => p.privateDate["clientId"]).Where(p => p.Count() > 1).ToList();
                        groupe.AddRange(privateDate.GroupBy(p => p.privateDate["email"]).Where(p => p.Key != null && p.Count() > 1).ToList());
                        groupe.AddRange(privateDate.GroupBy(p => p.privateDate["password"]).Where(p => p.Count() > 1).ToList());
                        groupe.SelectMany(p => p.Select(p1 => String.Concat(p.Select(p2 => "\n" + p2.gameUser.HomeType)))).Distinct().ToList().ForEach(p =>
                        {
                            var whois = profile.Api["FIO"];
                            var response = ExtHttp.Post($"http://{GameHost.Config.Settings.ServerAddress}:{GameHost.Config.Settings.ServerPort}/ChatService/AddChat",
                                                        JsonConvert.SerializeObject(new { roomId = game.Id, creator = "Вестерос", message = $"dynamic_samePC*{p}" }));
                            //GameHost.AddChatFunc(game.Id, "Вестерос", string.Format("dynamic_samePC*{0}", p));
                        });

                        return game.ToWCFGame();
                    }
                }
                catch (Exception exp)
                {
                    GameException.NewGameException(GameId, "Не удалось подключиться к игре.", exp, false);
                    return null;
                }
            }).Result);
        }