コード例 #1
0
ファイル: GameHost.cs プロジェクト: lantsev1981/Agot2Server
        // GameService.GameHost.GetStep	90 050	1	17,28%	0,00%
        public List <WCFStep> GetStep(WCFGameUser clientUser, int stepIndex = 0)
        {
            try
            {
                if (stepIndex < 0 || clientUser == null)
                {
                    return(null);
                }

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

                    Game game = user.Game1;
                    game.GameHost    = this;
                    game.CurrentUser = user;
                    List <Step> stepList = null;
                    if (stepIndex == 0)
                    {
                        //первый забор
                        if (clientUser.LastStepIndex == 0)
                        {
                            //stepList = game.GameUser.Where(p => !string.IsNullOrEmpty(p.HomeType)).Select(p => p.LastStep).ToList();
                            stepList = game.LastHomeSteps.ToList();
                            stepList.Add(game.Vesteros.LastStep);
                        }
                        //новые ходы
                        else
                        {
                            stepList = game.AllSteps.Where(p => p.Id > clientUser.LastStepIndex).ToList();
                        }
                    }
                    else
                    {
                        //требуется конкретный ход
                        stepList = new List <Step> {
                            game.AllSteps.First(p => p.Id >= stepIndex)
                        };
                    }
                    List <WCFStep> result = stepList.Select(p => p.ToWCFStep()).ToList();

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

                    return(result);
                }
            }
            catch (Exception exp)
            {
                GameException.NewGameException(clientUser.Game, "Не удалось подготовить список ходов.", exp, false);
                throw;
            }
        }
コード例 #2
0
ファイル: GameHost.cs プロジェクト: lantsev1981/Agot2Server
        public void DisConnect(WCFGameUser clientUser)
        {
            if (!clientUser.CheckIn())
            {
                return;
            }

            DisConnectTask(clientUser);
        }
コード例 #3
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);
                }
            });
        }
コード例 #4
0
        static internal bool Check(this WCFGameUser o, GameUser serverUser)
        {
            if (o.Game != serverUser.Game)
            {
                return(false);
            }
            if (o.Login != serverUser.Login)
            {
                return(false);
            }
            if (o.HomeType != serverUser.HomeType)
            {
                return(false);
            }

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Проверяет входные данные
        /// </summary>
        /// <returns></returns>
        static internal bool CheckIn(this WCFGameUser o)
        {
            if (o.Id == Guid.Empty)
            {
                return(false);
            }
            if (o.Game == Guid.Empty)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(o.Login) || o.Login == "System" || o.Login == "Вестерос")
            {
                return(false);
            }

            return(true);
        }
コード例 #6
0
ファイル: GameHost.cs プロジェクト: lantsev1981/Agot2Server
        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);
        }
コード例 #7
0
ファイル: GameHost.cs プロジェクト: lantsev1981/Agot2Server
        public void DisConnect(WCFGameUser clientUser)
        {
            TaskFactory.StartNew(() =>
            {
                try
                {
                    if (!clientUser.CheckIn())
                    {
                        return;
                    }

                    DisConnectTask(clientUser);
                }
                catch (Exception exp)
                {
                    GameException.NewGameException(clientUser.Game, "Не удалось отключиться от игры.", exp, false);
                }
            });
        }
コード例 #8
0
ファイル: GameHost.cs プロジェクト: lantsev1981/Agot2Server
        // 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);
        }
コード例 #9
0
        public WCFGameUser ToWCFGameUser(GameUser serverUser = null, WCFGameUser clientUser = null)
        {
            WCFGameUser result = new WCFGameUser();

            result.Id            = this.Id;
            result.Game          = this.Game;
            result.Login         = this.Login;
            result.HomeType      = this.HomeType;
            result.NeedReConnect = this.NeedReConnect;

            if (serverUser != null)
            {
                result.OnLineStatus = (serverUser.LastUpdate - this.LastUpdate) < new TimeSpan(0, 0, 5);
            }

            if (clientUser != null)
            {
                result.NewStep = clientUser.LastStepIndex != this.Game1.StepIndex
                    ? true
                    : false;
            }

            return(result);
        }
コード例 #10
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());
                    }
                }
            }
        }