コード例 #1
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);
                }
            });
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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());
                    }
                }
            }
        }