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
 private void OnEvent([FromSource] Player ped, int serverId, NetworkCallbackDelegate dCallbackDelegate)
 {
     try
     {
         var xPlayer = EsxService.ESX.GetPlayerFromId(serverId);
         xPlayer.addMoney(_config.MoneyPerTick);
         dCallbackDelegate.Invoke(_config.MoneyPerTick);
     }
     catch (Exception e)
     {
         Debug.WriteLine($"Error paying {e.Message}");
     }
 }
Ejemplo n.º 3
0
        private void GetPlayerCoords([FromSource] Player source, int playerId, NetworkCallbackDelegate callback)
        {
            if (IsPlayerAceAllowed(source.Handle, "vMenu.OnlinePlayers.Teleport") || IsPlayerAceAllowed(source.Handle, "vMenu.Everything") ||
                IsPlayerAceAllowed(source.Handle, "vMenu.OnlinePlayers.All"))
            {
                var coords = Players[playerId]?.Character?.Position ?? Vector3.Zero;

                _ = callback(coords);

                return;
            }

            _ = callback(Vector3.Zero);
        }
Ejemplo n.º 4
0
        private void OnFetchSessions([FromSource] Player player, NetworkCallbackDelegate networkCB)
        {
            WriteToConsole($"Sincronizzo sessioni con {player.Name} {player.Handle}");

            networkCB.Invoke(SerializeObject(SessionByHandle));
        }
Ejemplo n.º 5
0
 private void CallbackGroup([FromSource] Player Source, NetworkCallbackDelegate CB)
 {
     CB.Invoke(GetDataDatabase(Source));
 }
Ejemplo n.º 6
0
        private void UseInventoryItem([FromSource] Player _player, string _seshKey, int _itemID, NetworkCallbackDelegate _networkCallback)
        {
            if (_seshKey == null)
            {
                Utils.WriteLine($"Player[{_player.Name}] didn't have a session key!");
                return;
            }
            Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle);

            if (foundSesh.SessionKey != _seshKey)
            {
                Utils.WriteLine($"Players[{_player.Name}] session key didn't equal servers key!");
                return;
            }

            InventoryItem foundItem = foundSesh.selectedCharacter.Inventory.InventoryItems[_itemID];

            if (foundItem != null || foundItem.ItemAmount > 0)
            {
                _networkCallback(JsonConvert.SerializeObject(foundItem));
            }
            else
            {
                Utils.WriteLine("Found Item was either null or none was left!");
            }
        }
Ejemplo n.º 7
0
        private void FinishCharacterEditing([FromSource] Player _player, string _sessionkey, string _characterString, NetworkCallbackDelegate _networkCallback)
        {
            if (_sessionkey == null)
            {
                Utils.WriteLine($"Player[{_player.Name}] didn't have a session key!");
                return;
            }
            Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle);

            if (foundSesh.SessionKey != _sessionkey)
            {
                Utils.WriteLine($"Players[{_player.Name}] session key didn't equal servers key!");
                return;
            }
            Utils.DebugLine("Player Character Finished Editing!", "SSessionManager");
            Character character = JsonConvert.DeserializeObject <Character>(_characterString);

            foundSesh.selectedCharacter = character;

            foundSesh.UpdateCharacters(CharacterDBManager.UpdateCharacter(_player, foundSesh.User, character.Id));

            _networkCallback(JsonConvert.SerializeObject(character));
        }
Ejemplo n.º 8
0
        private void SellCardealerVehicle([FromSource] Player _player, string _seshKey, string _sellgarageItem, NetworkCallbackDelegate _networkCallback)
        {
            if (_seshKey == null)
            {
                Utils.WriteLine("Session key is missing!");
                return;
            }

            Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle);

            if (foundSesh == null || foundSesh.SessionKey != _seshKey)
            {
                Utils.WriteLine("Session either doesn't exist or the session key doesn't match up");
                return;
            }

            GarageItem sellgarageItem = JsonConvert.DeserializeObject <GarageItem>(_sellgarageItem);

            foreach (GarageItem gI in foundSesh.selectedCharacter.Garage.garageItems)
            {
                if (gI.garageID == sellgarageItem.garageID)
                {
                    foreach (string key in ConfigManager.MarkerConfig.Keys)
                    {
                        //Find the cardealers within the markers
                        if (key.ToLower().Contains("dealer"))
                        {
                            //Loop through vehicle dealer marker data
                            foreach (string dataKey in ConfigManager.MarkerConfig[key].MarkerData.Keys)
                            {
                                //Get the vehicles
                                if (dataKey.ToLower().Contains("vehicles"))
                                {
                                    string markerDataString = JsonConvert.SerializeObject(ConfigManager.MarkerConfig[key].MarkerData[dataKey]);
                                    Dictionary <string, CardealerItem> markerData = JsonConvert.DeserializeObject <Dictionary <string, CardealerItem> >(markerDataString);

                                    foreach (string dataKey2 in markerData.Keys)
                                    {
                                        if (dataKey2.ToLower().Contains(gI.vehicleModel))
                                        {
                                            //We have found the vehicle
                                            //We need to save the car to the garage and the garage to the database
                                            string        jsonString    = JsonConvert.SerializeObject(markerData[dataKey2]);
                                            CardealerItem cardealerItem = JsonConvert.DeserializeObject <CardealerItem>(jsonString);

                                            foundSesh.selectedCharacter.SellItem(cardealerItem.Price);
                                            foundSesh.selectedCharacter.SellVehicle(gI);

                                            foundSesh.UpdateCharacters(CharacterDBManager.UpdateCharacter(_player, foundSesh.User, foundSesh.selectedCharacter.Id));
                                            Utils.WriteLine("Updated character!");

                                            try
                                            {
                                                _networkCallback(true, JsonConvert.SerializeObject(gI), cardealerItem.Price);
                                                return;
                                            }
                                            catch (Exception _ex)
                                            {
                                                Utils.Throw(_ex);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            _networkCallback(false, null, 0);
        }
Ejemplo n.º 9
0
        private void BuyCardealerVehicle([FromSource] Player _player, string _seshKey, string _vehicleModel, NetworkCallbackDelegate _networkCallback)
        {
            Utils.WriteLine("Buying Cardealer vehicle!");
            if (_seshKey == null)
            {
                Utils.WriteLine("Session key is missing!");
                return;
            }

            Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle);

            if (foundSesh == null || foundSesh.SessionKey != _seshKey)
            {
                Utils.WriteLine("Session either doesn't exist or the session key doesn't match up");
                return;
            }

            Utils.WriteLine("Searching markers");
            foreach (string key in ConfigManager.MarkerConfig.Keys)
            {
                //Find the cardealers within the markers
                if (key.ToLower().Contains("dealer"))
                {
                    foreach (string dataKey in ConfigManager.MarkerConfig[key].MarkerData.Keys)
                    {
                        if (dataKey.ToLower().Contains("vehicles"))
                        {
                            string markerDataString = JsonConvert.SerializeObject(ConfigManager.MarkerConfig[key].MarkerData[dataKey]);
                            Dictionary <string, CardealerItem> markerData = JsonConvert.DeserializeObject <Dictionary <string, CardealerItem> >(markerDataString);

                            foreach (string dataKey2 in markerData.Keys)
                            {
                                if (dataKey2.ToLower().Contains(_vehicleModel))
                                {
                                    //We have found the vehicle
                                    //We need to save the car to the garage and the garage to the database
                                    string        jsonString    = JsonConvert.SerializeObject(markerData[dataKey2]);
                                    CardealerItem cardealerItem = JsonConvert.DeserializeObject <CardealerItem>(jsonString);
                                    if (!foundSesh.selectedCharacter.BuyItem(cardealerItem.Price))
                                    {
                                        Utils.WriteLine($"Player doesn't have enough money![{foundSesh.Player.Name}]");
                                        _networkCallback(false, null);
                                        return;
                                    }
                                    int        garageID   = foundSesh.selectedCharacter.Garage.garageItems.Count + 1;
                                    GarageItem garageItem = new GarageItem(garageID, foundSesh.selectedCharacter.Id, cardealerItem.CarName, cardealerItem.CarModel, Utils.CreateVehicleNumberPlate(), false, false, new Dictionary <string, int>());
                                    if (ConfigManager.ServerConfig.RPImpound)
                                    {
                                        garageItem.setImpounded(false);
                                    }
                                    else
                                    {
                                        garageItem.setImpounded(true);
                                    }
                                    garageItem.setStored(false);
                                    foundSesh.selectedCharacter.Garage.garageItems.Add(garageItem);
                                    foundSesh.UpdateCharacters(CharacterDBManager.UpdateCharacter(_player, foundSesh.User, foundSesh.selectedCharacter.Id));

                                    _networkCallback(true, JsonConvert.SerializeObject(garageItem));
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        private void RetrieveGarageVehicle([FromSource] Player _player, string _seshKey, int garageID, NetworkCallbackDelegate _networkCallback)
        {
            if (_seshKey == null)
            {
                Utils.WriteLine("Session key is missing!");
                return;
            }

            Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle);

            if (foundSesh == null || foundSesh.SessionKey != _seshKey)
            {
                Utils.WriteLine("Session either doesn't exist or the session key doesn't match up");
                return;
            }

            foreach (GarageItem gI in foundSesh.selectedCharacter.Garage.garageItems)
            {
                if (gI.garageID == garageID)
                {
                    if (ConfigManager.ServerConfig.RPImpound)
                    {
                        gI.setImpounded(false);
                    }
                    else
                    {
                        gI.setImpounded(true);
                    }

                    gI.setStored(false);

                    foundSesh.UpdateCharacters(CharacterDBManager.UpdateCharacter(_player, foundSesh.User, foundSesh.selectedCharacter.Id));

                    _networkCallback(true, JsonConvert.SerializeObject(gI));
                    return;
                }
            }
            _networkCallback(false, null);
        }
Ejemplo n.º 11
0
        private void GarageStoreVehicle([FromSource] Player _player, string _seshKey, string _garageItem, NetworkCallbackDelegate _networkCallback)
        {
            if (_seshKey == null)
            {
                Utils.WriteLine($"Player[{_player.Name}] didn't have a session key!");
                return;
            }
            Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle);

            if (foundSesh.SessionKey != _seshKey)
            {
                Utils.WriteLine($"Players[{_player.Name}] session key didn't equal servers key!");
                return;
            }

            GarageItem storinggarageItem = JsonConvert.DeserializeObject <GarageItem>(_garageItem);

            foreach (GarageItem gI in foundSesh.selectedCharacter.Garage.garageItems)
            {
                Utils.WriteLine($"Storing vehicle[{storinggarageItem.garageID}], garage vehicle [{gI.garageID}]");
                //Get the garage item in the servers memory
                if (storinggarageItem.garageID == gI.garageID)
                {
                    //Check if the garage item is not stored and is not impounded
                    if (ConfigManager.ServerConfig.RPImpound)
                    {
                        if (gI.impounded)
                        {
                            Utils.WriteLine("Vehicle is impounded!");  return;
                        }
                    }
                    if (!gI.stored)
                    {
                        gI.setImpounded(false);
                        gI.setStored(true);
                        gI.setNetworkID(0);
                        foundSesh.UpdateCharacters(CharacterDBManager.UpdateCharacter(_player, foundSesh.User, foundSesh.selectedCharacter.Id));
                        _networkCallback(true);
                        return;
                    }
                }
            }

            _networkCallback(false);
        }
Ejemplo n.º 12
0
 private void CallbackGetItemsDroped([FromSource] CitizenFX.Core.Player Source, NetworkCallbackDelegate CB)
 {
     if (Inventory.ItemsDroped.Count > 0)
     {
         CB.Invoke(Inventory.ItemsDroped, Inventory.ItemsDropedID);
     }
 }
Ejemplo n.º 13
0
        private void UpdateSerializeItems([FromSource] CitizenFX.Core.Player Source, IDictionary <string, dynamic> ItemsDropedClient, NetworkCallbackDelegate CB)
        {
            foreach (dynamic Item in ItemsDropedClient.Keys.ToList())
            {
                if (Enum.IsDefined(typeof(Weapon.Hash), ItemsDropedClient[Item].Name))
                {
                    ItemsDropedClient[Item].Label       = Inventory.Items[ItemsDropedClient[Item].Name].Label;
                    ItemsDropedClient[Item].Description = Inventory.Items[ItemsDropedClient[Item].Name].Description;
                    ItemsDropedClient[Item].Weight      = Inventory.Items[ItemsDropedClient[Item].Name].Weight;
                }
                else
                {
                    ItemsDropedClient[Item].Label       = Inventory.Items[ItemsDropedClient[Item].Name].Label;
                    ItemsDropedClient[Item].Description = Inventory.Items[ItemsDropedClient[Item].Name].Description;
                    ItemsDropedClient[Item].Weight      = Inventory.Items[ItemsDropedClient[Item].Name].Weight;
                    ItemsDropedClient[Item].Limit       = Inventory.Items[ItemsDropedClient[Item].Name].Limit;
                }
            }

            string NewInventory = JsonConvert.SerializeObject(ItemsDropedClient);

            CB.Invoke(NewInventory);
        }