Пример #1
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); }
        }
Пример #2
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}"
                    });
                }
            }
        }
Пример #3
0
        public ActionResult CreateChat(string username)
        {
            Chat c = new Chat();

            chatService.AddChat(c);

            ApplicationUser currentUser  = accountService.getUserByName(User.Identity.Name);
            ApplicationUser userChatWIth = accountService.getUserByName(username);

            chatService.AddUserToChat(c, currentUser);
            chatService.AddUserToChat(c, userChatWIth);

            string url = this.Request.UrlReferrer.AbsoluteUri;

            return(Redirect(url));
        }
Пример #4
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;
            }
        }
Пример #5
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());
            }
        }
Пример #6
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());
                    }
                }
            }
        }