Ejemplo n.º 1
0
        private void CallbackGetInventory([FromSource] CitizenFX.Core.Player Source, NetworkCallbackDelegate CB)
        {
            string PlayerInventory = Inventory.GetInventory(Source);
            var    InventoryItems  = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(PlayerInventory);

            foreach (dynamic Item in InventoryItems.Keys.ToList())
            {
                if (Enum.IsDefined(typeof(Weapon.Hash), Item))
                {
                    InventoryItems[Item].Label       = Inventory.Items[Item].Label;
                    InventoryItems[Item].Description = Inventory.Items[Item].Description;
                    InventoryItems[Item].Weight      = Inventory.Items[Item].Weight;
                }
                else
                {
                    var OldValue = InventoryItems[Item];
                    InventoryItems[Item]        = Inventory.Items[Item];
                    InventoryItems[Item].Amount = OldValue;
                }
            }

            var NUIInventory = JsonConvert.SerializeObject(InventoryItems);

            CB.Invoke(NUIInventory);
        }
Ejemplo n.º 2
0
        public static void AddItem([FromSource] CitizenFX.Core.Player Source, string Name, int Amount)
        {
            if (!Enum.IsDefined(typeof(Weapon.Hash), Name) && Inventory.Items.ContainsKey(Name))
            {
                string PlayerInventory = Inventory.GetInventory(Source);
                var    Dictionary      = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(PlayerInventory);

                bool found = false;
                foreach (var Item in Dictionary)
                {
                    if (Item.Key == Name)
                    {
                        Dictionary[Name] += Amount;
                        found             = true;
                        break;
                    }
                }
                if (!found)
                {
                    Dictionary.Add(Name, Amount);
                }

                string NewInventory = JsonConvert.SerializeObject(Dictionary);
                Inventory.UpdateInventory(Source, NewInventory);
            }
            else
            {
                ChatMessage.Error(Source, $"Item [{Name}] does not exist in table \"items\" database!");
            }
        }
Ejemplo n.º 3
0
        private void OnDeath([FromSource] CitizenFX.Core.Player source, int killerId)
        {
            try {
                var session = Server.Sessions.FromPlayer(source);
                if (session == null)
                {
                    return;
                }

                Kill(session.NetId);

                var killer = Server.Sessions.FromPlayer(killerId);

                var killerData = GameState?.Players.FirstOrDefault(p => p.NetId == killerId);

                if (killerData != null)
                {
                    killerData.Kills++;
                }

                var propCount = GameState?.Players.Count(p => p.Team == Team.Prop && p.IsAlive);
                BaseScript.TriggerClientEvent("PropHunt.Died", session.NetId, $"~r~{session.Name}~s~ {(killerData != null ? $"was killed by ~r~{killer.Name}~s~!" : "has died.")}~n~~r~{propCount}~s~ prop{(propCount == 1 ? "" : "s")} left!");
                Log.Info($"Player {session.Name} (net:{session.NetId}) {(killerData == null ? "has died" : $"was killed by {killer.Name}")}");

                session.TriggerEvent("PropHunt.Sound", "death");
            }
Ejemplo n.º 4
0
        public void SetPlayerRegistered([FromSource] CitizenFX.Core.Player source, string name, string dob, string gender, string group, string faction, string money)
        {
            string Identifier = source.Identifiers[Config.PlayerIdentifier];

            Debug.WriteLine($"{name} {dob} {gender} {group}");
            Database.ExecuteUpdateQuery($"UPDATE users SET Name = '{name}', `Date Of Birth` = '{dob}', Sex = '{gender}', `Group` = '{group}', Faction = '{faction}', Money = '{money}' WHERE Identifier = '{Identifier}'");
        }
Ejemplo n.º 5
0
        private static async void DeleteCharacter([FromSource] Citizen citizen, string characterId)
        {
            User user = await User.GetOrCreate(citizen);

            if (user.Characters == null)
            {
                user.Characters = new List <Character>();
            }

            var id = Guid.Parse(characterId);

            var character = user.Characters.FirstOrDefault(c => c.Id == id);

            if (character == null)
            {
                return;
            }

            character.Deleted = DateTime.UtcNow;

            Db.Characters.AddOrUpdate(character);
            await Db.SaveChangesAsync();

            GetCharacters(citizen);
        }
Ejemplo n.º 6
0
 public static void ServerToClient(string message, CitizenFX.Core.Player player = null, bool toChat = true)
 {
     if (toChat)
     {
         if (player == null)
         {
             BaseScript.TriggerClientEvent("Log.PrintToClientConsole", message);
         }
         else
         {
             BaseScript.TriggerClientEvent(player, "Log.PrintToClientConsole", message);
         }
     }
     else
     {
         if (player == null)
         {
             BaseScript.TriggerClientEvent("Chat.Message", "LOG FROM SERVER", consoleNameColorInClientChat, message);
         }
         else
         {
             BaseScript.TriggerClientEvent(player, "Chat.Message", "LOG FROM SERVER", consoleNameColorInClientChat, message);
         }
     }
 }
Ejemplo n.º 7
0
        private async void OnPlayerConnecting([FromSource] CitizenFX.Core.Player source, string playerName, dynamic setKickReason, dynamic deferrals)
        {
            await Delay(0);

            var Identifier = source.Identifiers[Config.PlayerIdentifier];
            var IP         = source.Identifiers["ip"];

            if (!string.IsNullOrEmpty(Identifier))
            {
                if (!GetPlayerExistDB(Identifier))
                {
                    Database.ExecuteInsertQuery($"INSERT INTO users (Identifier, Nickname) VALUES ('{Identifier}', '{playerName}')");
                    Console.Info($"{playerName} [{Identifier}] - Joined for first time to server!");
                }
                else
                {
                    Console.Info($"{playerName} - User Authenticated {Identifier}");
                }
            }
            else
            {
                deferrals.done($"You dont have {Config.PlayerIdentifier} identifier used for this server.");
            }

            deferrals.done();
        }
Ejemplo n.º 8
0
        private static async void LoadCharacter([FromSource] Citizen citizen, string characterId)
        {
            User user = await User.GetOrCreate(citizen);

            if (user.Characters == null)
            {
                user.Characters = new List <Character>();
            }

            var id = Guid.Parse(characterId);

            var character = user.Characters.NotDeleted().FirstOrDefault(c => c.Id == id);

            if (character == null)
            {
                return;
            }

            character.LastPlayed = DateTime.UtcNow;

            Db.Characters.AddOrUpdate(character);
            await Db.SaveChangesAsync();

            TriggerClientEvent(citizen, RpcEvents.CharacterLoad, JsonConvert.SerializeObject(character));
        }
Ejemplo n.º 9
0
        public static bool CanCarryItem([FromSource] CitizenFX.Core.Player Source, string Name, int Amount)
        {
            string PlayerInventory = Inventory.GetInventory(Source);
            var    Dictionary      = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(PlayerInventory);

            bool found = false;

            foreach (var Item in Dictionary)
            {
                if (Item.Key == Name)
                {
                    found = true;
                    if (Convert.ToInt32(Inventory.Items[Name].Limit) >= (Convert.ToInt32(Item.Value) + Amount))
                    {
                        return(true);

                        break;
                    }
                }
            }
            if (!found)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 10
0
        private async Task ClaimObject <T>([FromSource] Citizen claimer, string objectIdString) where T : class, IObject
        {
            Log($"{objectIdString}");

            var  claimerSteamId = claimer.Identifiers["steam"];
            User claimerUser    = Db.Users.First(u => u.SteamId == claimerSteamId);

            Guid objectId = Guid.Parse(objectIdString);
            T    obj      = Db.Set <T>().First(c => c.Id == objectId);

            Guid currentTrackerId = obj.TrackingUserId;

            obj.TrackingUserId = claimerUser.Id;

            Db.Set <T>().AddOrUpdate(obj);
            await Db.SaveChangesAsync();

            if (currentTrackerId == Guid.Empty)
            {
                return;
            }

            User currentTrackerUser = Db.Users.First(u => u.Id == currentTrackerId);

            try
            {
                TriggerClientEvent(
                    this.Players.First(p => p.Identifiers["steam"] == currentTrackerUser.SteamId),
                    $"igi:{typeof(T).Name}:unclaim",
                    JsonConvert.SerializeObject(obj));
            }
            catch (Exception ex) { Log(ex.Message); }
        }
Ejemplo n.º 11
0
        public static void AtmWithdraw([FromSource] Citizen citizen, string atmIdString, string memberIdString, string amountString)
        {
            Server.Log($"AtmWithdraw called: {atmIdString}  {memberIdString}  {amountString}");
            try
            {
                Guid              atmId    = JsonConvert.DeserializeObject <Guid>(atmIdString);
                BankAtm           atm      = Server.Db.BankAtms.First(a => a.Id == atmId);
                Guid              memberId = JsonConvert.DeserializeObject <Guid>(memberIdString);
                BankAccountMember member   = Server.Db.BankAccountMembers.First(m => m.Id == memberId);
                double            amount   = JsonConvert.DeserializeObject <double>(amountString);

                member.Account.Balance -= amount;

                Server.Db.BankAccountMembers.AddOrUpdate(member);
                Server.Db.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Server.Log($"AtmWithdraw Failed: {e.Message}");
                BaseScript.TriggerClientEvent(RpcEvents.BankAtmWithdraw, JsonConvert.SerializeObject(false));
                return;
            }

            BaseScript.TriggerClientEvent(RpcEvents.BankAtmWithdraw, JsonConvert.SerializeObject(true));
        }
Ejemplo n.º 12
0
        private void UpdateItemDroped([FromSource] CitizenFX.Core.Player Source, IDictionary <string, dynamic> ItemsDropedClient, string NewItemsDropedID)
        {
            ItemsDroped    = ItemsDropedClient;
            ItemsDropedID += 1;

            TriggerClientEvent("Inventory:UpdateItemsDropedCallback", ItemsDroped, NewItemsDropedID);
        }
Ejemplo n.º 13
0
        private void PlayerGiveItem([FromSource] CitizenFX.Core.Player Source, int PlayerID, string Name, int Amount)
        {
            CitizenFX.Core.Player TargetPlayer = new PlayerList()[PlayerID];

            if (Player.GetCurrentWeight(TargetPlayer) < Config.MaxPlayerWeight)
            {
                if (Player.CanCarryItem(TargetPlayer, Name, Amount))
                {
                    Player.RemoveItem(Source, Name, Amount);
                    Player.AddItem(TargetPlayer, Name, Amount);

                    if (Amount > 1)
                    {
                        UI.ShowNotification(Source, $"~b~[Info]~s~ You gave an ~y~{GetItemLabel(Name)}~s~ x{Amount} to ~b~{Player.GetName(TargetPlayer)}~s~.");
                        UI.ShowNotification(TargetPlayer, $"~b~[Info]~s~ You received an ~y~{GetItemLabel(Name)}~s~ x{Amount} from ~b~{Player.GetName(Source)}~s~.");
                    }
                    else
                    {
                        UI.ShowNotification(Source, $"~b~[Info]~s~ You gave an ~y~{GetItemLabel(Name)}~s~ to ~b~{Player.GetName(TargetPlayer)}~s~.");
                        UI.ShowNotification(TargetPlayer, $"~b~[Info]~s~ You received an ~y~{GetItemLabel(Name)}~s~ from ~b~{Player.GetName(Source)}~s~.");
                    }
                }
                else
                {
                    UI.ShowNotification(Source, $"~y~[Warning]~s~ You tried gave an ~y~{GetItemLabel(Name)}~s~ to ~b~{Player.GetName(TargetPlayer)}~s~, but he can't take more.");
                    UI.ShowNotification(TargetPlayer, $"~y~[Warning]~s~ ~b~{Player.GetName(Source)}~s~ tried to gave you an ~y~{GetItemLabel(Name)}~s~, but you can't take more.");
                }
            }
            else
            {
                UI.ShowNotification(Source, $"~y~[Warning]~s~ You tried gave an ~y~{GetItemLabel(Name)}~s~ to ~b~{Player.GetName(TargetPlayer)}~s~, but he can't carry more things.");
                UI.ShowNotification(TargetPlayer, $"~y~[Warning]~s~ ~b~{Player.GetName(Source)}~s~ tried to gave you an ~y~{GetItemLabel(Name)}~s~, but you can't carry more things.");
            }
        }
Ejemplo n.º 14
0
        private void PlayerGiveWeapon([FromSource] CitizenFX.Core.Player Source, int PlayerID, string Name, int Ammo)
        {
            CitizenFX.Core.Player TargetPlayer = new PlayerList()[PlayerID];

            if (Player.GetCurrentWeight(TargetPlayer) < Config.MaxPlayerWeight)
            {
                if (!Player.HasWeapon(TargetPlayer, Name))
                {
                    Player.AddWeapon(TargetPlayer, Name, Ammo);
                    Player.RemoveWeapon(Source, Name);

                    UI.ShowNotification(Source, $"~b~[Info]~s~ You gave an ~y~{GetItemLabel(Name)}~s~ to ~b~{Player.GetName(TargetPlayer)}~s~.");
                    UI.ShowNotification(TargetPlayer, $"~b~[Info]~s~ You received an ~y~{GetItemLabel(Name)}~s~ from ~b~{Player.GetName(Source)}~s~.");
                }
                else
                {
                    UI.ShowNotification(Source, $"~y~[Warning]~s~ You tried gave an ~y~{GetItemLabel(Name)}~s~ to ~b~{Player.GetName(TargetPlayer)}~s~, but he already has one.");
                    UI.ShowNotification(TargetPlayer, $"~y~[Warning]~s~ ~b~{Player.GetName(Source)}~s~ tried to gave you an ~y~{GetItemLabel(Name)}~s~, but you already have one.");
                }
            }
            else
            {
                UI.ShowNotification(Source, $"~y~[Warning]~s~ You tried gave an ~y~{GetItemLabel(Name)}~s~ to ~b~{Player.GetName(TargetPlayer)}~s~, but he can't carry more things.");
                UI.ShowNotification(TargetPlayer, $"~y~[Warning]~s~ ~b~{Player.GetName(Source)}~s~ tried to gave you an ~y~{GetItemLabel(Name)}~s~, but you can't carry more things.");
            }
        }
Ejemplo n.º 15
0
        public static void UpdateInventory([FromSource] CitizenFX.Core.Player Source, string Items)
        {
            string Identifier = Source.Identifiers[Config.PlayerIdentifier];

            Database.ExecuteUpdateQuery($"UPDATE users SET Inventory = '{Items}' WHERE Identifier = '{Identifier}'");
            TriggerClientEvent("Inventory:Update");
        }
Ejemplo n.º 16
0
 private void CallbackGetItemsDroped([FromSource] CitizenFX.Core.Player Source, NetworkCallbackDelegate CB)
 {
     if (Inventory.ItemsDroped.Count > 0)
     {
         CB.Invoke(Inventory.ItemsDroped, Inventory.ItemsDropedID);
     }
 }
Ejemplo n.º 17
0
 private void OnPlayerDropped([FromSource] CitizenFX.Core.Player player, string reason)
 {
     if (PlayerManager.Instance.DestroyExtendedPlayer(player))
     {
         MessagesManager.Instance.DebugMessage(player.Name + " disconnected! Removing from ExtendedPlayerList!");
     }
 }
Ejemplo n.º 18
0
        private void OnSessionLoaded([FromSource] CitizenFX.Core.Player player)
        {
            try {
                var session = FromPlayer(player);
                if (session == null)
                {
                    return;
                }

                foreach (var p in new PlayerList())
                {
                    var data = new SessionDataModel {
                        Name       = session.Name,
                        NetId      = session.NetId,
                        SharedData = session.SharedData
                    };
                    if (p.Handle == player.Handle)
                    {
                        data.ProtectedData = session.ProtectedData;
                    }
                    p.TriggerEvent("Session.Join", session.NetId, JsonConvert.SerializeObject(data));
                }
                Log.Verbose($"Player {session.Name} has finished loading.");
            }
            catch (Exception ex) {
                Log.Error(ex);
            }
        }
Ejemplo n.º 19
0
        private static async void OnPlayerDropped([FromSource] Citizen citizen, string disconnectMessage, CallbackDelegate kickReason)
        {
            var user = await User.GetOrCreate(citizen);

            var session = await Session.End(user, disconnectMessage);

            Log($"[DISCONNECT] [{session.Id}] Player \"{user.Name}\" disconnected: {disconnectMessage}");
        }
Ejemplo n.º 20
0
        private static void AssignVehicle(IVehicle vehicle, Citizen citizen)
        {
            Log($"Assinging vehicle to {citizen.Name} via event: 'igi:{vehicle.VehicleType().Name}:claim'");

            BaseScript.TriggerClientEvent(
                citizen,
                $"igi:{vehicle.VehicleType().Name}:claim",
                JsonConvert.SerializeObject(vehicle));
        }
Ejemplo n.º 21
0
 private void OnPropUpdate([FromSource] CitizenFX.Core.Player source, int netId, uint hash)
 {
     try {
         BaseScript.TriggerClientEvent("PropHunt.Prop", source.Handle, netId, hash);
     }
     catch (Exception ex) {
         Log.Error(ex);
     }
 }
Ejemplo n.º 22
0
        private static async void AcceptRules([FromSource] Citizen citizen, string jsonDateTime)
        {
            var user = await User.GetOrCreate(citizen);

            user.AcceptedRules = JsonConvert.DeserializeObject <DateTime>(jsonDateTime);

            Db.Users.AddOrUpdate(user);
            await Db.SaveChangesAsync();
        }
Ejemplo n.º 23
0
        public override async void Handle(CitizenFX.Core.Player source, ChatMessage data)
        {
            var parts = data.Message.Split(' ').ToList();

            parts.RemoveAt(0);
            var message = String.Join(" ", parts);

            data.Message = $"[color=gray]{data.Character.FirstName} {data.Character.LastName} [Local OOC]: {message}[/color]";
            Broadcast(data);
        }
Ejemplo n.º 24
0
 private string GetItemLimit([FromSource] CitizenFX.Core.Player Source, string Name)
 {
     foreach (dynamic Item in Items.Keys)
     {
         if (Item == Name)
         {
             return(Items[Item].Limit);
         }
     }
     return($"Item [{Name}] does not exist!");
 }
Ejemplo n.º 25
0
 private void RemoveItem([FromSource] CitizenFX.Core.Player Source, string Name, int Amount)
 {
     if (Enum.IsDefined(typeof(Weapon.Hash), Name))
     {
         Player.RemoveWeapon(Source, Name);
     }
     else
     {
         Player.RemoveItem(Source, Name, Amount);
     }
 }
Ejemplo n.º 26
0
 public void PlayerActivated([FromSource] CitizenFX.Core.Player source)
 {
     try
     {
         //TriggerClientEvent("Chat.Message", "", "#FFFFFF", $@"^2*{source.Name} ^0joined.");
     }
     catch (Exception ex)
     {
         Debug.WriteLine($"PlayerActivated ERROR: {ex.Message}");
     }
 }
Ejemplo n.º 27
0
        public bool DestroyExtendedPlayer(CitizenFX.Core.Player player)
        {
            if (playerExtendedList.ContainsKey(int.Parse(player.Handle)))
            {
                playerExtendedList[int.Parse(player.Handle)].Save();
                playerExtendedList.Remove(int.Parse(player.Handle));

                return(true);
            }
            return(false);
        }
Ejemplo n.º 28
0
        private static async void GetCharacters([FromSource] Citizen citizen)
        {
            User user = await User.GetOrCreate(citizen);

            if (user.Characters == null)
            {
                user.Characters = new List <Character>();
            }

            TriggerClientEvent(citizen, RpcEvents.GetCharacters, JsonConvert.SerializeObject(user.Characters.NotDeleted().OrderBy(c => c.Created)));
        }
Ejemplo n.º 29
0
 private static void ClientReady([FromSource] Citizen citizen)
 {
     TriggerClientEvent(citizen, RpcEvents.GetServerInformation, JsonConvert.SerializeObject(new ServerInformation
     {
         ResourceName = API.GetCurrentResourceName(),
         ServerName   = Config.ServerName,
         DateTime     = DateTime.UtcNow,
         Weather      = "EXTRASUNNY",            // TODO
         Atms         = Db.BankATMs.ToList(),
         Branches     = Db.BankBranches.ToList()
     }));
 }
Ejemplo n.º 30
0
        private static async void OnPlayerConnecting([FromSource] Citizen citizen, string playerName, CallbackDelegate kickReason)
        {
            var user = await User.GetOrCreate(citizen);

            user.Name = citizen.Name;

            Db.Users.AddOrUpdate(user);
            await Db.SaveChangesAsync();

            var session = await Session.Create(citizen, user);

            Log($"[CONNECT] [{session.Id}] Player \"{user.Name}\" connected from {session.IpAddress}");
        }