示例#1
0
        public void Start(Player player)
        {
            Player = player;

            AutoRebirthUts = RandomUtilities.GetCurrentMilliseconds() + 1200000; //30 minutes

            Player.LifeStats.Kill();
            PlayerLogic.PleyerDied(player);
        }
示例#2
0
        public void Close()
        {
            if (m_gameAccount != null)
            {
                m_gameAccount.LastOnlineUtc = RandomUtilities.GetCurrentMilliseconds();
            }

            Client.Disconnect();
        }
示例#3
0
        public void ProcessDamage(Player player)
        {
            if (player.Duel == null)
            {
                return;
            }

            player.Duel.LastKickUtc = RandomUtilities.GetCurrentMilliseconds();
        }
示例#4
0
        protected void RandomWalkAction()
        {
            if (Npc.Target != null || MoveController.IsActive)
            {
                return;
            }

            if (Npc.Attack != null && !Npc.Attack.IsFinished)
            {
                return;
            }

            if (Npc.NpcTemplate.Shape.WalkSpeed <= 0)
            {
                return;
            }

            if (Npc.Instance.IsEditingMode)
            {
                if (Npc.Position.FastDistanceTo(Npc.BindPoint) > 0)
                {
                    MoveController.MoveTo(Creature.BindPoint);
                }

                return;
            }

            long now = RandomUtilities.GetCurrentMilliseconds();

            if (now - 10000 < LastWalkUts)
            {
                return;
            }

            LastWalkUts = RandomUtilities.GetCurrentMilliseconds() + Random.Next(5000, 10000);

            if (Random.Next(0, 100) < 50)
            {
                return;
            }

            double distanceToBind = Npc.BindPoint.DistanceTo(Creature.Position);

            if (distanceToBind > 500)
            {
                MoveController.MoveTo(Creature.BindPoint);
                return;
            }

            MoveController.MoveTo(Npc.Position.X
                                  + Random.Next(150, 300)
                                  * (Random.Next(0, 100) < 50 ? 1 : -1)
                                  ,
                                  Npc.Position.Y
                                  + Random.Next(150, 300)
                                  * (Random.Next(0, 100) < 50 ? 1 : -1));
        }
        public async Task <ActionResult <MainResponse> > TokenRefresh()
        {
            User user = HttpContext.GetUser();

            if (user == null)
            {
                return(MainResponse.GetError(Enums.RequestError.UserNotFound));
            }

            if (!HttpContext.Request.Cookies.Any(p => p.Key == "refresh-token"))
            {
                return(Forbid());
            }

            Auth auth = _context.Auth.FirstOrDefault(p => p.RefreshToken == HttpContext.Request.Cookies["refresh-token"]);

            if (auth == null)
            {
                return(Forbid());
            }

            auth.Token        = RandomUtilities.GetCryptoRandomString(32);
            auth.RefreshToken = RandomUtilities.GetCryptoRandomString(32);
            auth.Expire       = DateTime.Now.AddSeconds(_serverConfig.Users.TokenExpirationTime);

            _context.Auth.Update(auth);
            await _context.SaveChangesAsync();

            HttpContext.Response.Cookies.Append("refresh-token", auth.RefreshToken, new CookieOptions()
            {
                Domain   = coockieDomain,
                HttpOnly = true,
                Path     = "/api/auth/token-refresh"
            });

            HttpContext.Response.Cookies.Append("auth-token", auth.Token, new CookieOptions()
            {
                Domain   = coockieDomain,
                HttpOnly = true,
                Path     = "/api"
            });

            HttpContext.Response.Cookies.Append("auth-token", auth.Token, new CookieOptions()
            {
                Domain   = coockieDomain,
                HttpOnly = true,
                Path     = "/sockets"
            });

            TokenRefreshResponse response = new TokenRefreshResponse()
            {
                EncryptionKey = auth.LocalDataEncryptionKey
            };

            return(MainResponse.GetSuccess(response));
        }
示例#6
0
        public void LogGradientCheck()
        {
            var x   = new PlaceHolder <T>("x");
            var fun = ConvNetSharp <T> .Instance.Log(x);

            var shape    = new Shape(2, 2, 3, 4);
            var location = NewVolume(RandomUtilities.RandomDoubleArray(shape.TotalLength, 20.0, 1.0, true), shape);

            GradientCheck(fun, location, 1e-2);
        }
示例#7
0
        public void TanhGradientCheck()
        {
            var x   = new PlaceHolder <T>("x");
            var fun = ConvNetSharp <T> .Instance.Tanh(x);

            var shape    = new Shape(2, 2, 3, 4);
            var location = NewVolume(RandomUtilities.RandomDoubleArray(shape.TotalLength), shape);

            GradientCheck(fun, location);
        }
示例#8
0
        public void ProcessGather()
        {
            Gather.CurrentGatherCounter--;

            if (Gather.CurrentGatherCounter <= 0)
            {
                Gather.CurrentGatherCounter = 0;
                DieUtc = RandomUtilities.GetCurrentMilliseconds();
            }
        }
示例#9
0
        public virtual async Task <AppDomainResult> ForgotPassword(string userName)
        {
            AppDomainResult appDomainResult = new AppDomainResult();
            bool            isValidEmail    = ValidateUserName.IsEmail(userName);
            bool            isValidPhone    = ValidateUserName.IsPhoneNumber(userName);

            // Kiểm tra đúng định dạng email và số điện thoại chưa
            if (!isValidEmail && !isValidPhone)
            {
                throw new AppException("Vui lòng nhập email hoặc số điện thoại!");
            }
            // Tạo mật khẩu mới
            // Kiểm tra email/phone đã tồn tại chưa?
            var userInfos = await this.userService.GetAsync(e => !e.Deleted &&
                                                            (e.UserName == userName ||
                                                             e.Email == userName ||
                                                             e.Phone == userName
                                                            )
                                                            );

            Users userInfo = null;

            if (userInfos != null && userInfos.Any())
            {
                userInfo = userInfos.FirstOrDefault();
            }
            if (userInfo == null)
            {
                throw new AppException("Số điện thoại hoặc email không tồn tại");
            }
            // Cấp mật khẩu mới
            var newPasswordRandom = RandomUtilities.RandomString(8);

            userInfo.Password = SecurityUtils.HashSHA1(newPasswordRandom);
            bool success = await this.userService.UpdateAsync(userInfo);

            if (success)
            {
                // Gửi mã qua Email
                if (isValidEmail)
                {
                    string emailBody = string.Format("<p>Your new password: {0}</p>", newPasswordRandom);
                    emailConfigurationService.Send("Change Password", new string[] { userInfo.Email }, null, null, new EmailContent()
                    {
                        Content = emailBody,
                        IsHtml  = true,
                    });
                }
                // Gửi SMS
                else if (isValidPhone)
                {
                }
            }
            return(appDomainResult);
        }
示例#10
0
        public void SigmoidGradientCheck()
        {
            var cns = new ConvNetSharp <T>();
            var x   = cns.PlaceHolder("x");
            var fun = cns.Sigmoid(x);

            var shape    = new Shape(2, 2, 3, 4);
            var location = this.NewVolume(RandomUtilities.RandomDoubleArray(shape.TotalLength), shape);

            this.GradientCheck(cns, fun, location, 1e-3);
        }
示例#11
0
        public void SqrtGradientCheck()
        {
            var cns = new ConvNetSharp <T>();
            var x   = cns.PlaceHolder("x");
            var fun = cns.Sqrt(x);

            var shape    = new Shape(2, 2, 3, 4);
            var location = this.NewVolume(RandomUtilities.RandomDoubleArray(shape.TotalLength, posisitveOnly: true), shape);

            this.GradientCheck(cns, fun, location);
        }
示例#12
0
        public void LeakyReluGradientCheck()
        {
            var cns = new ConvNetSharp <T>();
            var x   = cns.PlaceHolder("x");
            var fun = cns.LeakyRelu(x, (T)Convert.ChangeType(0.01, typeof(T)));

            var shape    = new Shape(2, 2, 3, 4);
            var location = NewVolume(RandomUtilities.RandomDoubleArray(shape.TotalLength), shape);

            GradientCheck(cns, fun, location, 1e-5);
        }
示例#13
0
        public void TanhGradientCheck()
        {
            var cns = new ConvNetSharp <T>();
            var x   = cns.PlaceHolder("x");
            var fun = cns.Tanh(x);

            var shape    = new Shape(2, 2, 3, 4);
            var location = NewVolume(RandomUtilities.RandomDoubleArray(shape.TotalLength), shape);

            GradientCheck(cns, fun, location);
        }
示例#14
0
        public void DivideGradientCheck()
        {
            var shape    = new Shape(2, 2, 3, 4);
            var location = NewVolume(RandomUtilities.RandomDoubleArray(shape.TotalLength), shape);

            var x = new PlaceHolder <T>("x");
            var z = new Const <T>(NewVolume(new double[shape.TotalLength].Populate(1.0), shape), "z");

            GradientCheck(x / z, location, 1e-5);
            GradientCheck(z / x, location, 1e-5);
        }
示例#15
0
        public void MatMultiplyGradientCheck()
        {
            var shape    = new Shape(2, 2, 1, 4);
            var location = NewVolume(RandomUtilities.RandomDoubleArray(shape.TotalLength), shape);

            var cns = new ConvNetSharp <T>();
            var x   = cns.PlaceHolder("x");
            var z   = cns.Const(NewVolume(new double[shape.TotalLength].Populate(1.0), shape), "z");

            GradientCheck(cns, cns.MatMult(x, z), location);
            GradientCheck(cns, cns.MatMult(z, x), location);
        }
示例#16
0
        public override void Action()
        {
            if (Player.Controller is DeathController)
            {
                return;
            }

            if (UsedCampfire != null)
            {
                if (UsedCampfire.Instance != Player.Instance ||
                    UsedCampfire.Position.FastDistanceTo(Player.Position) > (UsedCampfire.Type == 4 ? 200 : 100))
                {
                    UsedCampfire = null;

                    if (Player.PlayerMode == PlayerMode.Relax)
                    {
                        Player.PlayerMode = PlayerMode.Normal;
                        Global.VisibleService.Send(Player, new SpCharacterState(Player));
                    }
                }
                else if (Player.PlayerMode == PlayerMode.Normal)
                {
                    Player.PlayerMode = PlayerMode.Relax;
                    Global.VisibleService.Send(Player, new SpCharacterState(Player));
                }
            }

            long now = RandomUtilities.GetCurrentMilliseconds();

            if (Player.Controller is BattleController)
            {
                LastBattleUts = now;
            }

            while (now >= NextRegenUts)
            {
                Regenerate();
                NextRegenUts += Player.Controller is BattleController ? 5000 : 2000;
            }

            while (now > NextDistressUts)
            {
                int timeout = (Player.LifeStats.Stamina > 100) ? 90000 : 60000;

                if (Player.Controller is BattleController)
                {
                    timeout -= 30000;
                }

                Distress();
                NextDistressUts += timeout;
            }
        }
示例#17
0
        public void PowerGradientCheck()
        {
            var cns      = new ConvNetSharp <T>();
            var shape    = new Shape(2, 2, 3, 4);
            var location = this.NewVolume(RandomUtilities.RandomDoubleArray(shape.TotalLength), shape);

            var x = cns.PlaceHolder("x");
            var z = cns.Const(this.NewVolume(new double[shape.TotalLength].Populate(2.0), shape), "z");

            this.GradientCheck(cns, x ^ z, location);
            this.GradientCheck(cns, z ^ x, location);
        }
示例#18
0
        public void SumGradientCheck()
        {
            var x   = new PlaceHolder <T>("x");
            var fun = ConvNetSharp <T> .Instance.Sum(x, new Shape(1, 1, 1, 4));

            var shape    = new Shape(2, 2, 3, 4);
            var location = NewVolume(RandomUtilities.RandomDoubleArray(shape.TotalLength), shape);

            var grad = NewVolume(new[] { 1.0, 1.0, 1.0, 1.0 }, new Shape(1, 1, 1, 4));

            GradientCheck(fun, location, 1e-4, grad);
        }
示例#19
0
        public void SubstractGradientCheck()
        {
            var shape    = new Shape(2, 2, 3, 4);
            var location = NewVolume(RandomUtilities.RandomDoubleArray(shape.TotalLength), shape);

            var cns = new ConvNetSharp <T>();
            var x   = cns.PlaceHolder("x");
            var z   = cns.Const(NewVolume(new double[shape.TotalLength].Populate(1.0), shape), "z");

            GradientCheck(cns, x - z, location);
            GradientCheck(cns, z - x, location);
        }
示例#20
0
        protected static void MainLoop()
        {
            while (ServerIsWork)
            {
                try
                {
                    if (RandomUtilities.GetCurrentMilliseconds() - Cache.LastSaveUts > 600000) // Backup Every 10 Min
                    {
                        Cache.LastSaveUts = RandomUtilities.GetCurrentMilliseconds();
                        Cache.SaveData();
                    }
                    //Services:

                    FeedbackService.Action();
                    AccountService.Action();
                    PlayerService.Action();
                    MapService.Action();
                    ChatService.Action();
                    VisibleService.Action();
                    ControllerService.Action();
                    CraftService.Action();
                    ItemService.Action();
                    AiService.Action();
                    GeoService.Action();
                    StatsService.Action();
                    ObserverService.Action();
                    TeleportService.Action();
                    AreaService.Action();
                    PartyService.Action();
                    SkillsLearnService.Action();
                    GuildService.Action();
                    DuelService.Action();

                    //Engines:

                    ActionEngine.Action();
                    AdminEngine.Action();
                    SkillEngine.Action();
                    QuestEngine.Action();

                    //Others:

                    DelayedAction.CheckActions();
                }
                catch (Exception ex)
                {
                    Logger.WriteLine(LogState.Exception, "MainLoop: " + ex.Message + " St: " + ex.StackTrace);
                }

                Thread.Sleep(10);
            }
        }
示例#21
0
        private bool CanUseItem(Player player, StorageItem item, Player secondPlayer = null, bool sendmessages = false)
        {
            int groupId = ItemTemplate.Factory(item.ItemId).CoolTimeGroup;

            if (item.ItemTemplate.RequiredUserStatus != null &&
                !item.ItemTemplate.RequiredUserStatus.Contains(player.PlayerMode.ToString().ToUpper()))
            {
                return(false);
            }

            if (player.PlayerLevel < item.ItemTemplate.Level)
            {
                if (sendmessages)
                {
                    SystemMessages.YouMustBeAHigherLevelToUseThat.Send(player.Connection);
                }

                return(false);
            }

            if (item.ItemTemplate.RequiredSecondCharacter && secondPlayer == null)
            {
                return(false);
            }

            if (groupId != 0 && player.ItemCoodowns.ContainsKey(groupId) && (RandomUtilities.GetCurrentMilliseconds() - player.ItemCoodowns[groupId]) / 1000 < item.ItemTemplate.Cooltime)
            {
                //todo System message
                return(false);
            }
            if (item.ItemTemplate.CombatItemType == CombatItemType.RECIPE && player.Recipes.Contains(item.ItemId))
            {
                if (!Data.Data.Recipes.ContainsKey(item.ItemId))
                {
                    Logger.WriteLine(LogState.Warn, "ItemService: Can't find recipe {0}", item.ItemId);
                    return(false);
                }

                if (player.Recipes.Contains(item.ItemId))
                {
                    //todo System message
                    return(false);
                }
                if (player.PlayerCraftStats.GetCraftSkills(Data.Data.Recipes[item.ItemId].CraftStat) < Data.Data.Recipes[item.ItemId].ReqMin)
                {
                    //todo System message
                    return(false);
                }
            }

            return(true);
        }
示例#22
0
        public void ConcatGradientCheck()
        {
            var leftShape  = new Shape(2, 2, 1, 1);
            var rightShape = new Shape(3, 1, 1, 1);

            var cns      = new ConvNetSharp <T>();
            var location = NewVolume(RandomUtilities.RandomDoubleArray(leftShape.TotalLength), new Shape(2, 2, 1, 1));
            var x        = cns.PlaceHolder("x");
            var z        = cns.Const(NewVolume(new double[rightShape.TotalLength].Populate(1.0), rightShape), "z");
            var fun      = cns.Concat(x, z);

            GradientCheck(cns, fun, location, 1e-5);
        }
示例#23
0
        private void Start()
        {
            textComponent = GetComponent <Text>();
            shadow        = GetComponent <Shadow>();

            if (shadow)
            {
                shadow.effectColor = textComponent.color * shadowMultiplier;
            }

            lerpColour = RandomUtilities.Colour();
            lerpColour = new Color(Mathf.Clamp(0.3f, 0.8f, lerpColour.r), Mathf.Clamp(0.2f, 0.8f, lerpColour.g), Mathf.Clamp(0.3f, 0.8f, lerpColour.b));
        }
示例#24
0
        public void AddHistoryEvent(Guild guild, HistoryEvent hEvent, Player initiator = null)
        {
            if (guild == null)
            {
                return;
            }

            hEvent.Date = RandomUtilities.GetRoundedUtc();

            guild.GuildHistory.Add(hEvent);

            //TODO update
        }
示例#25
0
        public void SumGradientCheck()
        {
            var cns = new ConvNetSharp <T>();
            var x   = cns.PlaceHolder("x");
            var fun = cns.Sum(x, new Shape(1, 1, 1, 4));

            var shape    = new Shape(2, 2, 3, 4);
            var location = this.NewVolume(RandomUtilities.RandomDoubleArray(shape.TotalLength), shape);

            var grad = this.NewVolume(new[] { 1.0, 1.0, 1.0, 1.0 }, new Shape(1, 1, 1, 4));

            this.GradientCheck(cns, fun, location, 1e-4, grad);
        }
示例#26
0
        public void AssertThat_AddEdges_IncreasesCount()
        {
            var r = new Random(123);

            for (var i = 0; i < 3000; i++)
            {
                _set.Add(new LineSegment2(
                             new Vector2(RandomUtilities.RandomSingle(r.NextDouble, -100, 100), RandomUtilities.RandomSingle(r.NextDouble, -100, 100)),
                             new Vector2(RandomUtilities.RandomSingle(r.NextDouble, -100, 100), RandomUtilities.RandomSingle(r.NextDouble, -100, 100))
                             ), 1);

                Assert.AreEqual(i + 1, _set.Count);
            }
        }
示例#27
0
        public override void Init(Creature creature)
        {
            base.Init(creature);

            Projectile = (Projectile)creature;

            if (Projectile.TargetPosition != null)
            {
                MoveController = new NpcMoveController(creature);
                MoveController.MoveTo(Projectile.TargetPosition);
            }

            DieUts = RandomUtilities.GetCurrentMilliseconds() + Projectile.Lifetime;
        }
示例#28
0
        public void RaisesMessages()
        {
            BaseClassMockWithChildren obj = new BaseClassMockWithChildren();
            MessengerMonitor <BaseClassMockWithChildren> monitor = new MessengerMonitor <BaseClassMockWithChildren>(obj);

            for (int i = 0; i < new Random().Next(5, 20); i++)
            {
                string message = RandomUtilities.GetRandomString(obj.Message);
                obj.ChangeMessage(message);

                monitor.AssertMessageNotification(message, false);
                monitor.AssertMessageCount(i + 1, false);
            }
        }
示例#29
0
文件: Spawn.cs 项目: sdbezerra/Temu
        private void CreateGroup(IConnection connection)
        {
            var npcs = Global.VisibleService.FindTargets(connection.Player,
                                                         connection.Player.Position,
                                                         50,
                                                         TargetingAreaType.Enemy);

            npcs.Sort((c1, c2) =>
            {
                Npc npc1 = c1 as Npc;
                Npc npc2 = c2 as Npc;
                if (npc1 == null || npc2 == null)
                {
                    return(0);
                }

                return(npc2.NpcTemplate.Size.GetHashCode()
                       .CompareTo(npc1.NpcTemplate.Size.GetHashCode()));
            });

            int counter    = 0;
            int startAngle = RandomUtilities.Random().Next(0, 359);

            foreach (var creature in npcs)
            {
                Npc npc = creature as Npc;
                if (npc == null)
                {
                    continue;
                }

                int count = int.Parse(GetValue(connection, "Enter count of: [" + npc.NpcTemplate.Name + "]"));
                if (count > 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        SpawnTemplate spawnTemplate = npc.SpawnTemplate.Clone();

                        spawnTemplate.X += (float)(150f * Math.Cos(startAngle + counter * 30) * counter / 2 / Math.PI + RandomUtilities.Random().Next(-25, 25));
                        spawnTemplate.Y += (float)(150f * Math.Sin(startAngle + counter * 30) * counter / 2 / Math.PI + RandomUtilities.Random().Next(-25, 25));

                        Global.MapService.SpawnTeraObject(MapService.CreateNpc(spawnTemplate), npc.Instance);
                        counter++;
                    }

                    Global.MapService.DespawnTeraObject(npc);
                }
            }
        }
示例#30
0
        private async void StartCondition(Duel duel)
        {
            new SpDuelCounter().Send(duel.Initiator);
            new SpDuelCounter().Send(duel.Initiated);

            await Task.Delay(5000);

            duel.LastKickUtc = RandomUtilities.GetCurrentMilliseconds();

            Communication.Global.RelationService.ResendRelation(duel.Initiator);
            Communication.Global.RelationService.ResendRelation(duel.Initiated);

            lock (DuelsLock)
                Duels.Add(duel);
        }