Example #1
0
        public async void Login(Client sender, string username, string password)
        {
            Master masterAccount;

            if (username.Contains("@"))
            {
                masterAccount = await MasterRepository.GetMasterDataByEmail(username);
            }
            else
            {
                masterAccount = await MasterRepository.GetMasterDataByName(username);
            }

            if (masterAccount != null)
            {
                if (Crypter.CheckPassword(password, masterAccount.Password))
                {
                    string[]      charNames = new string[5];
                    List <string> charImgs  = new List <string>()
                    {
                        "", "", "", "", ""
                    };
                    string[] factions = new string[5];
                    masterAccount.Players = await PlayerRepository.GetAllPlayerDataByMasterAccount(masterAccount);

                    masterAccount.Client = sender;
                    int count = 0;
                    foreach (Player p in masterAccount.Players)
                    {
                        charNames[count] = p.Username.Roleplay();
                        charImgs[count]  = p.Skin == 797459875 ?  Images.SkinBlobs[p.Skin] : "";
                        if (p.FactionId != 0)
                        {
                            factions[count] =
                                $"{FactionRepository.GetFactionById(p.FactionId).Name}<br/>{RankRepository.GetRankByFactionAndId(p.FactionId, p.FactionRank).Title}";
                        }
                        else
                        {
                            factions[count] = "Civilian";
                        }
                        count++;
                    }

                    Master.MasterData.Add(masterAccount);
                    API.triggerClientEvent(sender, "playerLogResult", "success", masterAccount.Players.Count,
                                           string.Join(",", charNames), string.Join(",", factions), string.Join(".", charImgs));

                    masterAccount.LatestLogin = Server.Date;
                    masterAccount.LatestIP    = sender.address;

                    masterAccount.ActiveConnectionLog = new ConnectionLog(masterAccount.Id, -1, API.getPlayerAddress(sender));
                    ConnectionLogRepository.AddNew(masterAccount.ActiveConnectionLog);
                    MasterRepository.UpdateAsync(masterAccount);
                    masterAccount.AdminLevel = 6;
                }
                else
                {
                    API.triggerClientEvent(sender, "playerLogResult", "incorrect-pass");
                    API.SendErrorNotification(sender, "You have entered an incorrect password");
                }
            }
            else
            {
                API.triggerClientEvent(sender, "playerLogResult", "invalid-user");
                API.SendErrorNotification(sender, "You have entered an invalid username");
            }
        }
Example #2
0
        public async void PlayerInit(Player player)
        {
            API.setPlayerNametag(player.Client, player.Username.Roleplay());
            API.setPlayerName(player.Client, player.Username.Roleplay());
            API.setPlayerHealth(player.Client, (int)player.Health);
            API.setPlayerArmor(player.Client, (int)player.Armour);
            API.setEntityDimension(player.Client, player.Dimension);

            player.IsInInterior = (player.Dimension > 0);
            if (player.IsInInterior)
            {
                player.PropertyIn = PropertyManager.Properties.FirstOrDefault(p => p.Dimension == player.Dimension);
            }

            Skin playerSkin = await SkinRepository.GetSkinById(player.Skin);

            API.setPlayerSkin(player.Client, (PedHash)playerSkin.Model);

            List <SkinVariations> skinVars = playerSkin.Variations();

            player.ChatIndicatorLabel       = API.createTextLabel("typing...", player.Client.position, 50, 0.35f, false, player.Dimension);
            player.ChatIndicatorLabel.color = new Color(0, 0, 0, 0);
            player.ChatIndicatorLabel.attachTo(player.Client, null, new Vector3(0, 0, 0.9f), new Vector3());

            for (int i = 0; i < 12; i++)
            {
                API.setPlayerClothes(player.Client, i, skinVars[i].Drawable, skinVars[i].Texture);
            }

            player.IsLogged = true;

            player.MasterAccount.ActiveConnectionLog.PlayerId = player.Id;
            ConnectionLogRepository.UpdateAsync(player.MasterAccount.ActiveConnectionLog);

            if (player.FactionId > 0)
            {
                player.Faction = Faction.FactionData.Single(f => f.Id == player.FactionId);
            }

            player.Weapons = await WeaponRepository.GetAllWeaponsByPlayerIdAsync(player.Id);

            foreach (Weapon w in player.Weapons)
            {
                API.givePlayerWeapon(player.Client, w.Model, w.Ammo, false, false);
            }

            player.Inventory = await InventoryRepository.GetInventoryByOwnerIdAsync(player.Id);

            player.PopulateWeaponSkills();

            await player.LoadPlayerVehicles();

            foreach (Inventory i in player.Inventory)
            {
                if (i.IsPhone())
                {
                    Phone p = PhoneRepository.GetPhoneByIMEI(long.Parse(i.Value));

                    if (p.IsPrimary)
                    {
                        player.PrimaryPhone = p;
                        if (p.PoweredOn)
                        {
                            if (p.BatteryLevel > 3)
                            {
                                p.TurnOn(player.Client);
                            }
                            else
                            {
                                p.TurnOff(player.Client);
                            }
                        }
                        else
                        {
                            p.TurnOff(player.Client);
                        }
                        break;
                    }
                }
            }

            player.InEvent = PlayerEvent.None;

            player.Client.freeze(false);
            player.Client.ToggleCursorLock(false);
            player.Client.transparency = 255;
            API.sendNativeToAllPlayers(Hash.SET_CURRENT_PED_WEAPON, player.Client, (int)WeaponHash.Unarmed, true);

            Player.PlayerData.Add(player.Client, player);

            if (player.LastPosition != new Vector3(0, 0, 0))
            {
                player.Client.position = player.LastPosition;
            }

            API.triggerClientEvent(player.Client, "hasLoggedIn",
                                   ((char)player.MasterAccount.KeyCursor).ToString(),
                                   ((char)player.MasterAccount.KeyInventory).ToString(),
                                   ((char)player.MasterAccount.KeyInteract).ToString());

            API.triggerClientEvent(player.Client, "executeSkillTimer");
            API.triggerClientEvent(player.Client, "loadScoreboard");
            API.triggerClientEvent(player.Client, "initInteractionMenu");

            API.sendNativeToPlayer(player.Client, Hash.SET_CAM_AFFECTS_AIMING, player.Client, true);

            //API.sendNativeToPlayer(player.Client, Hash.SET_PED_CAN_BE_SHOT_IN_VEHICLE, player.Client, true);
            player.Client.invincible = true;

            for (int i = 0; i < 12; i++)
            {
                API.exported.doormanager.refreshDoorState(i);
            }

            UpdateNatives(player);

            PrisonManager.LoadPrisonSentenceForPlayer(player);
            OnPlayerLoggedIn(player);
        }
        public void DisconnectPlayer(Client player)
        {
            Player user = null;

            try
            {
                user = Player.PlayerData[player];
            }
            catch
            {
                user = Player.PlayerData.Values.FirstOrDefault(i => i.Username.Roleplay() == player.name);
            }

            if (user != null)
            {
                if (user.IsLogged)
                {
                    user.IsLogged     = false;
                    user.LastPosition = player.position;
                    user.LastRotation = player.rotation;
                    user.Health       = player.health;
                    user.Armour       = player.armor;
                    user.Dimension    = player.dimension;

                    user.ChatIndicatorLabel.text = "";
                    API.deleteEntity(user.ChatIndicatorLabel);

                    user.WeaponSkillData = string.Join(",", user.WeaponSkill.Values);

                    user.SavePlayerVehicles();

                    if (user.InEvent == PlayerEvent.VehicleDealership)
                    {
                        user.LastPosition = new Vector3(-257.5197 + (new Random().Next(-50, 50) / 20), 6211.149 + (new Random().Next(-50, 50) / 20), z: 31.48923);
                        user.LastRotZ     = 121.6988;
                    }
                    Vehicle ve = Vehicle.VehicleData.Values.FirstOrDefault(v => v.IsDealerVehicle && v.OwnerId == user.Id);

                    if (ve != null)
                    {
                        API.deleteEntity(ve.DealershipEmployee);
                        ve.Entity.Delete();
                    }

                    if (user.SelectedCash != null)
                    {
                        InventoryRepository.UpdateAsync(user.SelectedCash);
                    }
                    if (user.SelectedCardAccount != null)
                    {
                        BankRepository.UpdateAsync(user.SelectedCardAccount);
                    }

                    user.MasterAccount.ActiveConnectionLog.DisconnectTime = Server.Date;
                    ConnectionLogRepository.UpdateAsync(user.MasterAccount.ActiveConnectionLog);
                    WeaponRepository.UpdateAllAsync(user.Weapons);
                    PlayerRepository.UpdateAsync(user);
                    Player.PlayerData.Remove(user.Client);
                }
                else
                {
                    Player.PlayerData.Remove(user.Client);
                }
                Master.MasterData.Remove(user.MasterAccount);
            }
            player.FadeIn(0);
            API.triggerClientEvent(player, "onPlayerDisconnect");
        }