Exemplo n.º 1
0
        /// <summary>
        /// Обработчик логина игрока
        /// </summary>
        private void PlayerLogin(Client player, object[] args)
        {
            var email    = args[0].ToString();
            var password = args[1].ToString();
            var account  = _accountsProvider.Get(email, password);

            if (account == null)
            {
                API.triggerClientEvent(player, ServerEvent.BAD_LOGIN);
                return;
            }
            var playerInfo = _playersProvider.GetInfo(account.Id);

            _playerInfoManager.Add(player, playerInfo);
            API.setPlayerHealth(player, playerInfo.Health);
            API.triggerClientEvent(player, ServerEvent.HIDE_AUTH);
            if (!string.IsNullOrEmpty(playerInfo.Name))
            {
                ProcessLogin(player, playerInfo);
                LoadPlayerVehicles(player, playerInfo);
                _inventoryManager.EquipWeapon(player);
                _giftsManager.ProcessDaysGift(player, account);
            }
            else
            {
                API.setEntityDimension(player, (int)-playerInfo.AccountId);
                _creatingCharManager.ShowCreator(player);
            }
            account.LastLogin = DateTime.Now;
            _accountsProvider.Update(account);
            _giftsManager.StartGiftsTimer(player);
        }
        /// <summary>
        /// Возвращает игрока и его данные по идентификатору
        /// </summary>
        public PlayerWithData GetWithData(long accountId, bool needFromDb = true)
        {
            var player = API.getAllPlayers().FirstOrDefault(e => e.hasData(ID_KEY) && accountId == (long)e.getData(ID_KEY));

            if (PlayerHelper.PlayerCorrect(player, true))
            {
                return(new PlayerWithData {
                    Player = player, PlayerInfo = GetInfo(player)
                });
            }
            PlayerInfo playerInfo = null;

            if (needFromDb)
            {
                playerInfo          = _playersProvider.GetInfo(accountId);
                playerInfo.Vehicles = _vehiclesProvider.GetVehicles(accountId).ToDictionary(e => e.Id);
            }
            return(new PlayerWithData {
                Player = null, PlayerInfo = playerInfo
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Обработчик регистрации нового игрока
        /// </summary>
        private void PlayerRegister(Client player, object[] args)
        {
            var email         = args[0].ToString();
            var password      = args[1].ToString();
            var friendReferal = args[2].ToString();
            var createResult  = _accountsProvider.Create(email, password, friendReferal);

            if (!createResult)
            {
                API.triggerClientEvent(player, ServerEvent.BAD_REGISTER);
                return;
            }
            var account = _accountsProvider.Get(email, password);

            _playersProvider.Add(account);
            var playerInfo = _playersProvider.GetInfo(account.Id);

            _playerInfoManager.Add(player, playerInfo);
            API.triggerClientEvent(player, ServerEvent.HIDE_AUTH);
            API.setEntityDimension(player, (int)-account.Id);
            _creatingCharManager.ShowCreator(player);
        }