Esempio n. 1
0
        public bool?CheckBlackList(string login)
        {
            if (string.IsNullOrEmpty(login) || login == "System" || login == "Вестерос")
            {
                return(false);
            }

            using (Agot2p6Entities dbContext = new Agot2p6Entities())
            {
                var game     = dbContext.Game.SingleOrDefault(p => p.Id == GameId);
                var homeUser = game.HomeUsersSL;

                //уже играет
                if (homeUser.Any(p => p.Login == login))
                {
                    return(true);
                }

                //находится в чёрном списке у одного из игроков
                var users = homeUser.Where(p => !string.IsNullOrEmpty(p.Login)).Select(p => GamePortalServer.GetProfileByLogin(p.Login)).ToList();
                if (users.Any(p => p.SpecialUsers.Any(p1 => p1.IsBlock && p1.SpecialLogin == login)))
                {
                    return(false);
                }

                //один из игроков в чёрном списке
                var user = GamePortalServer.GetProfileByLogin(login);
                if (users.Any(p => user.SpecialUsers.Any(p1 => p1.IsBlock && p1.SpecialLogin == p.Login)))
                {
                    return(null);
                }
            }

            return(true);
        }
Esempio n. 2
0
        private bool CheckAccessHomeFunc(string login, string homeType)
        {
            //наблюдатель
            if (string.IsNullOrEmpty(homeType))
            {
                return(true);
            }
            //выбранный дом
            if (homeType != "Random" && GamePortalServer.GetProfileByLogin(login).AllPower < 400)
            {
                return(false);
            }

            using (Agot2p6Entities dbContext = new Agot2p6Entities())
            {
                Game            game     = dbContext.Game.Single(p => p.Id == GameId);
                List <GameUser> freeHome = game.HomeUsersSL.Where(p => p.Login == null).ToList();
                //доступных домов нет
                if (freeHome.Count == 0)
                {
                    return(false);
                }
                //выбранный дом занят или не существует
                if (homeType != "Random" && !freeHome.Any(p => p.HomeType == homeType))
                {
                    return(false);
                }

                return(true);
            }
        }
Esempio n. 3
0
        private bool CheckAccessHomeFunc(string login, string homeType)
        {
            //наблюдатель
            if (string.IsNullOrEmpty(homeType))
            {
                return(true);
            }
            //выбранный дом
            if (homeType != "Random" && GamePortalServer.GetProfileByLogin(login).AllPower < 400)
            {
                return(false);
            }

            try
            {
                using (Agot2p6Entities dbContext = new Agot2p6Entities())
                {
                    var game     = dbContext.Game.Single(p => p.Id == GameId);
                    var freeHome = game.HomeUsersSL.Where(p => p.Login == null).ToList();
                    //доступных домов нет
                    if (freeHome.Count == 0)
                    {
                        return(false);
                    }
                    //выбранный дом занят или не существует
                    if (homeType != "Random" && !freeHome.Any(p => p.HomeType == homeType))
                    {
                        return(false);
                    }

                    return(true);
                }
            }
            catch (Exception exp) { GameException.NewGameException(GameId, "Не удалось проверить доступность дома.", exp, false); return(false); }
        }
Esempio n. 4
0
        public WCFGame Connect(string login, string gamePassword, string homeType)
        {
            if (string.IsNullOrEmpty(login) || login == "System" || login == "Вестерос")
            {
                return(null);
            }
            if (CheckBlackList(login) == false)
            {
                return(null);
            }

#if !DEBUG //запрет на много игр
            using (Agot2p6Entities dbContext = new Agot2p6Entities())
            {
                if (dbContext.Game.Count(p => p.CloseTime == null && p.GameUser.Any(p1 => !string.IsNullOrEmpty(p1.HomeType) && p1.Login == login)) > 1)
                {
                    var profile = GamePortalServer.GetProfileByLogin(login);
                    if (profile.AllPower < 400 || (int)profile.UserGames.Where(p => !p.IsIgnoreHonor && p.EndTime.HasValue).Sum(p => (p.EndTime.Value - p.StartTime).TotalHours) < 48)
                    {
                        return(null);
                    }
                }
            }
#endif

            var result = ConnectTask(login, gamePassword, homeType);

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

            return(result);
        }
Esempio n. 5
0
        //Проверяет доступность дома соблюдая последовательность подключения к базе
        public bool CheckAccessHome(string login, string homeType)
        {
            try
            {
                if (string.IsNullOrEmpty(homeType))
                {
                    return(true);
                }
                else
                {
                    WCFUser profile    = GamePortalServer.GetProfileByLogin(login);
                    int     liaveCount = profile.UserGames.Count(p => p.GameId == this.GameId && p.EndTime.HasValue && !p.IsIgnoreHonor);
                    if (liaveCount > GameHost.MaxLiaveCount)
                    {
                        return(false);
                    }
                }

                return(CheckAccessHomeFunc(login, homeType));
            }
            catch (Exception exp)
            {
                GameException.NewGameException(GameId, "Не удалось проверить доступность дома.", exp, false);
                return(false);
            }
        }
Esempio n. 6
0
        private void RemoveUser(Game game)
        {
            var time     = DateTimeOffset.UtcNow - GameHost._UserLiveTime;
            var userList = game.GameUser.Where(p => !string.IsNullOrEmpty(p.Login) && p.Login != "Вестерос" && p.LastUpdate < time);

            //if (DateTimeOffset.UtcNow - game.CreateTime < _UserLiveTime)
            //    userList = userList.Where(p => string.IsNullOrEmpty(p.HomeType));

            //лишаем лордства неактивных
            foreach (var user in userList.ToList())
            {
                var profile = GamePortalServer.GetProfileByLogin(user.Login);

                if (game.OpenTime != null)
                {
                    GamePortalServer.StopUserGame(user.Login, game.Id);
                }
                else if (!string.IsNullOrEmpty(user.HomeType))
                {
                    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*homeType_{user.HomeType}*{whois}" }));
                    //GameHost.AddChatFunc(game.Id, "Вестерос", string.Format("dynamic_Exile*homeType_{0}*{1}",
                    //        user.HomeType,
                    //        profile == null ? user.Login : profile.Api["FIO"]));
                }

                //наблюдателей удаляем
                if (string.IsNullOrEmpty(user.HomeType))
                {
                    game.DbContext.GameUser.Remove(user);
                }
                else
                {
                    _DeniedLogin.Add(user.Login);
                    user.Login = null;

                    //сообщаем что требуется замена
                    if (game.OpenTime != null)
                    {
                        GameHost.AddGameNotifiFunc(game.ToWCFGame());
                    }
                }
            }

            //если партию покинули все игроки
            if (game.HomeUsersSL.All(p => p.Login == null))
            {
                game.CloseTime = DateTimeOffset.UtcNow;
            }
        }
        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);
                }
            });
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        public bool?CheckBlackList(string login)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(login) || login == "System" || login == "Вестерос")
                {
                    return(false);
                }

                using (Agot2p6Entities dbContext = new Agot2p6Entities())
                {
                    Game            game     = dbContext.Game.SingleOrDefault(p => p.Id == GameId);
                    List <GameUser> homeUser = game.HomeUsersSL;

                    //уже играл
                    WCFUser user = GamePortalServer.GetProfileByLogin(login);
                    if (user.UserGames.Any(p => p.GameId == this.GameId))
                    {
                        return(true);
                    }

                    //находится в чёрном списке у одного из игроков
                    List <WCFUser> users = homeUser.Where(p => !string.IsNullOrEmpty(p.Login)).Select(p => GamePortalServer.GetProfileByLogin(p.Login)).ToList();
                    if (users.Any(p => p.SpecialUsers.Any(p1 => p1.IsBlock && p1.SpecialLogin == login)))
                    {
                        return(false);
                    }

                    //один из игроков в чёрном списке
                    user = GamePortalServer.GetProfileByLogin(login);
                    if (users.Any(p => user.SpecialUsers.Any(p1 => p1.IsBlock && p1.SpecialLogin == p.Login)))
                    {
                        return(null);
                    }
                }

                return(true);
            }
            catch (Exception exp)
            {
                GameException.NewGameException(GameId, "CheckBlackList", exp, false);
                return(false);
            }
        }
Esempio n. 10
0
        public WCFGame Connect(string login, string gamePassword, string homeType)
        {
            return(TaskFactory.StartNew <WCFGame>(() =>
            {
                try
                {
                    if (CheckBlackList(login) == false)
                    {
                        return null;
                    }

#if !DEBUG //запрет на много игр
                    using (Agot2p6Entities dbContext = new Agot2p6Entities())
                    {
                        if (!dbContext.GameUser.Any(p1 => !string.IsNullOrEmpty(p1.HomeType) && p1.Login == login) &&
                            dbContext.Game.Count(p => p.CloseTime == null &&
                                                 p.GameUser.Any(p1 => !string.IsNullOrEmpty(p1.HomeType) && p1.Login == login)) > 1)
                        {
                            WCFUser profile = GamePortalServer.GetProfileByLogin(login);
                            if (profile.AllPower < 400 || (int)profile.UserGames.Where(p => !p.IsIgnoreHonor && p.EndTime.HasValue).Sum(p => (p.EndTime.Value - p.StartTime).TotalHours) < 48)
                            {
                                return null;
                            }
                        }
                    }
#endif

                    return ConnectTask(login, gamePassword, homeType);
                }
                catch (Exception exp)
                {
                    GameException.NewGameException(GameId, "Не удалось подключиться к игре.", exp, false);
                    return null;
                }
            }).Result);
        }
Esempio n. 11
0
        private void RemoveUser(Game game)
        {
            DateTimeOffset         time     = dateTimeNow - _UserLiveTime;
            IEnumerable <GameUser> userList = game.GameUser.Where(p => !string.IsNullOrEmpty(p.Login) && p.Login != "Вестерос" && p.LastUpdate < time);

            //лишаем лордства неактивных
            foreach (GameUser user in userList.ToList())
            {
                //лорды
                if (!string.IsNullOrEmpty(user.HomeType))
                {
                    WCFUser profile = GamePortalServer.GetProfileByLogin(user.Login);
                    //                    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
                    if (game.OpenTime != null)
                    {
                        GamePortalServer.StopUserGame(user.Login, game.Id, 0, royalPardon);
                    }
                    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;

                    //сообщаем что требуется замена
                    if (game.OpenTime != null)
                    {
                        GameHost.AddGameNotifiFunc(game.ToWCFGame());
                    }
                }
                //наблюдателей удаляем
                else
                {
                    game.DbContext.GameUser.Remove(user);
                }
            }

            royalPardon = false;

            //если партию покинули все игроки
            if (game.HomeUsersSL.All(p => p.Login == null))
            {
                game.CloseTime = dateTimeNow;
            }
        }
Esempio n. 12
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());
            }
        }
Esempio n. 13
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());
                    }
                }
            }
        }
Esempio n. 14
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);
        }
Esempio n. 15
0
 public GameHost(GamePortalServer gamePortalServer)
 {
     GamePortalServer = gamePortalServer;
     _DeniedLogin     = new List <string>();
     _Timer           = new Timer((o) => CheckGameActivity());
 }
Esempio n. 16
0
 public GameHost(GamePortalServer gamePortalServer)
 {
     GamePortalServer = gamePortalServer;
     //_DeniedLogin = new ConcurrentDictionary<string, int>();
     _Timer = new Timer((o) => CheckGameActivity());
 }