diff --git a/server-data/resources/[esx_addons]/esx_datastore/LICENSE b/server-data/resources/[bpt_addons]/bpt_datastore/LICENSE similarity index 98% rename from server-data/resources/[esx_addons]/esx_datastore/LICENSE rename to server-data/resources/[bpt_addons]/bpt_datastore/LICENSE index 52fcac842..62f066311 100644 --- a/server-data/resources/[esx_addons]/esx_datastore/LICENSE +++ b/server-data/resources/[bpt_addons]/bpt_datastore/LICENSE @@ -1,7 +1,7 @@ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - esx_datastore - Copyright (C) 2015-2022 Jérémie N'gadi + + Copyright (C) 2024 bitpredator This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -645,14 +645,14 @@ the "copyright" line and a pointer to where the full notice is found. GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . + along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: - esx_datastore Copyright (C) 2015-2022 Jérémie N'gadi + Copyright (C) 2024 bitpredator This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. @@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see -. +. The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read -. \ No newline at end of file +. diff --git a/server-data/resources/[bpt_addons]/bpt_datastore/README.md b/server-data/resources/[bpt_addons]/bpt_datastore/README.md new file mode 100644 index 000000000..0d67890cc --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_datastore/README.md @@ -0,0 +1,19 @@ +

bpt_datastore

+

Discord + +Copyright (C) 2024 bitpredator + +This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version. + +This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details. + +ATTENTION: +You are not authorized to change the name of the resource and the resources within it. + +If you want to contribute you can open a pull request. + +You are not authorized to sell this software (this is free project). + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. \ No newline at end of file diff --git a/server-data/resources/[esx_addons]/esx_datastore/esx_datastore.sql b/server-data/resources/[bpt_addons]/bpt_datastore/bpt_datastore.sql similarity index 99% rename from server-data/resources/[esx_addons]/esx_datastore/esx_datastore.sql rename to server-data/resources/[bpt_addons]/bpt_datastore/bpt_datastore.sql index 589519d0e..ef87011a8 100644 --- a/server-data/resources/[esx_addons]/esx_datastore/esx_datastore.sql +++ b/server-data/resources/[bpt_addons]/bpt_datastore/bpt_datastore.sql @@ -17,4 +17,3 @@ CREATE TABLE `datastore_data` ( UNIQUE INDEX `index_datastore_data_name_owner` (`name`, `owner`), INDEX `index_datastore_data_name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - diff --git a/server-data/resources/[bpt_addons]/bpt_datastore/fxmanifest.lua b/server-data/resources/[bpt_addons]/bpt_datastore/fxmanifest.lua new file mode 100644 index 000000000..fe2c59587 --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_datastore/fxmanifest.lua @@ -0,0 +1,16 @@ +fx_version("adamant") + +game("gta5") + +description("Used for storing Data, such as society inventories") + +version("1.0.0") + +lua54("yes") + +server_scripts({ + "@es_extended/imports.lua", + "@oxmysql/lib/MySQL.lua", + "server/classes/datastore.lua", + "server/main.lua", +}) diff --git a/server-data/resources/[esx]/esx_society/server/main.lua b/server-data/resources/[esx]/esx_society/server/main.lua index 0236f212e..0374b9934 100644 --- a/server-data/resources/[esx]/esx_society/server/main.lua +++ b/server-data/resources/[esx]/esx_society/server/main.lua @@ -155,7 +155,7 @@ AddEventHandler("esx_society:putVehicleInGarage", function(societyName, vehicle) print(("[^3WARNING^7] Player ^5%s^7 attempted to put vehicle in non-existing society garage - ^5%s^7!"):format(source, societyName)) return end - TriggerEvent("esx_datastore:getSharedDataStore", society.datastore, function(store) + TriggerEvent("bpt_datastore:getSharedDataStore", society.datastore, function(store) local garage = store.get("garage") or {} table.insert(garage, vehicle) store.set("garage", garage) @@ -171,7 +171,7 @@ AddEventHandler("esx_society:removeVehicleFromGarage", function(societyName, veh print(("[^3WARNING^7] Player ^5%s^7 attempted to remove vehicle from non-existing society garage - ^5%s^7!"):format(source, societyName)) return end - TriggerEvent("esx_datastore:getSharedDataStore", society.datastore, function(store) + TriggerEvent("bpt_datastore:getSharedDataStore", society.datastore, function(store) local garage = store.get("garage") or {} for i = 1, #garage, 1 do @@ -398,7 +398,7 @@ ESX.RegisterServerCallback("esx_society:getVehiclesInGarage", function(_, cb, so print(("[^3WARNING^7] Attempting To get a non-existing society - %s!"):format(societyName)) return end - TriggerEvent("esx_datastore:getSharedDataStore", society.datastore, function(store) + TriggerEvent("bpt_datastore:getSharedDataStore", society.datastore, function(store) local garage = store.get("garage") or {} cb(garage) end) diff --git a/server-data/resources/[esx_addons]/esx_datastore/README.md b/server-data/resources/[esx_addons]/esx_datastore/README.md deleted file mode 100644 index 8f38d2890..000000000 --- a/server-data/resources/[esx_addons]/esx_datastore/README.md +++ /dev/null @@ -1,43 +0,0 @@ -

[ESX] Data Store

Discord - Website - Documentation - -A simple script for storing data :) - -# Usage - -There are two types of datastores: shared and not shared. - -- Shared datastores does not belong to a specific user, Example: police armory -- None-shared datastores are created for every user in the server. They are created in db when player is loaded, Example: property (weapons, dressing). - -## `datastore` database information - -An datastore must be configured in the database before using it. Don't forget to run a server restart afterwards (you can alternative restart the script and relog all clients) - -| `name` | `label` | `shared` | -| -------- | ------- | -------- | -| name of the datastore | label of the datastore (not used) | is the datastore shared with others? (boolean either `0` or `1`) | - -```lua -TriggerEvent('esx_datastore:getSharedDataStore', 'police', function(store) - local weapons = store.get('weapons') or {} - - table.insert(weapons, {name = 'WEAPON_PUMPSHOTGUN', ammo = 50}) - store.set('weapons', weapons) -end) - -TriggerEvent('esx_datastore:getDataStore', 'property', 'steam:0123456789', function(store) - local dressing = store.get('dressing') or {} -end) -``` - -# Legal - -esx_datastore - Datastore for ESX-Framework - -Copyright (C) 2015-2022 Jérémie N'gadi - -This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version. - -This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details. - -You should have received a copy Of the GNU General Public License along with this program. If Not, see http://www.gnu.org/licenses/. diff --git a/server-data/resources/[esx_addons]/esx_datastore/fxmanifest.lua b/server-data/resources/[esx_addons]/esx_datastore/fxmanifest.lua deleted file mode 100644 index ae4a4cb07..000000000 --- a/server-data/resources/[esx_addons]/esx_datastore/fxmanifest.lua +++ /dev/null @@ -1,14 +0,0 @@ -fx_version 'adamant' - -game 'gta5' - -description 'ESX Data Store' - -version '1.7.5' - -server_scripts { - '@es_extended/imports.lua', - '@oxmysql/lib/MySQL.lua', - 'server/classes/datastore.lua', - 'server/main.lua' -} diff --git a/server-data/resources/[esx_addons]/esx_datastore/server/classes/datastore.lua b/server-data/resources/[esx_addons]/esx_datastore/server/classes/datastore.lua deleted file mode 100644 index 537113861..000000000 --- a/server-data/resources/[esx_addons]/esx_datastore/server/classes/datastore.lua +++ /dev/null @@ -1,81 +0,0 @@ -function stringsplit(inputstr, sep) - if sep == nil then - sep = "%s" - end - - local t={} ; i=1 - for str in string.gmatch(inputstr, "([^"..sep.."]+)") do - t[i] = str - i = i + 1 - end - - return t -end - -function CreateDataStore(name, owner, data) - local self = {} - - self.name = name - self.owner = owner - self.data = type(data) == 'string' and json.decode(data) or data - - local timeoutCallbacks = {} - - function self.set(key, val) - data[key] = val - self.save() - end - - function self.get(key, i) - local path = stringsplit(key, '.') - local obj = self.data - - for i=1, #path, 1 do - obj = obj[path[i]] - end - - if i == nil then - return obj - else - return obj[i] - end - end - - function self.count(key, i) - local path = stringsplit(key, '.') - local obj = self.data - - for i=1, #path, 1 do - obj = obj[path[i]] - end - - if i ~= nil then - obj = obj[i] - end - - if obj == nil then - return 0 - else - return #obj - end - end - - function self.save() - for i=1, #timeoutCallbacks, 1 do - ESX.ClearTimeout(timeoutCallbacks[i]) - timeoutCallbacks[i] = nil - end - - local timeoutCallback = ESX.SetTimeout(10000, function() - if self.owner == nil then - MySQL.update('UPDATE datastore_data SET data = ? WHERE name = ?', {json.encode(self.data), self.name}) - else - MySQL.update('UPDATE datastore_data SET data = ? WHERE name = ? and owner = ?', {json.encode(self.data), self.name, self.owner}) - end - end) - - table.insert(timeoutCallbacks, timeoutCallback) - end - - return self -end diff --git a/server-data/resources/[esx_addons]/esx_datastore/server/main.lua b/server-data/resources/[esx_addons]/esx_datastore/server/main.lua deleted file mode 100644 index fee178219..000000000 --- a/server-data/resources/[esx_addons]/esx_datastore/server/main.lua +++ /dev/null @@ -1,80 +0,0 @@ -local DataStores, DataStoresIndex, SharedDataStores = {}, {}, {} - -AddEventHandler('onResourceStart', function(resourceName) - if resourceName == GetCurrentResourceName() then - local dataStore = MySQL.query.await('SELECT * FROM datastore_data LEFT JOIN datastore ON datastore_data.name = datastore.name UNION SELECT * FROM datastore_data RIGHT JOIN datastore ON datastore_data.name = datastore.name') - - local newData = {} - for i = 1, #dataStore do - local data = dataStore[i] - if data.shared == 0 then - if not DataStores[data.name] then - DataStoresIndex[#DataStoresIndex + 1] = data.name - DataStores[data.name] = {} - end - DataStores[data.name][#DataStores[data.name] + 1] = CreateDataStore(data.name, data.owner, json.decode(data.data)) - else - if data.data then - SharedDataStores[data.name] = CreateDataStore(data.name, nil, json.decode(data.data)) - else - newData[#newData + 1] = {data.name, '\'{}\''} - end - end - end - - if next(newData) then - MySQL.prepare('INSERT INTO datastore_data (name, data) VALUES (?, ?)', newData) - for i = 1, #newData do - local new = newData[i] - SharedDataStores[new[1]] = CreateDataStore(new[1], nil, {}) - end - end - end -end) - -function GetDataStore(name, owner) - for i=1, #DataStores[name], 1 do - if DataStores[name][i].owner == owner then - return DataStores[name][i] - end - end -end - -function GetDataStoreOwners(name) - local identifiers = {} - - for i=1, #DataStores[name], 1 do - table.insert(identifiers, DataStores[name][i].owner) - end - - return identifiers -end - -function GetSharedDataStore(name) - return SharedDataStores[name] -end - -AddEventHandler('esx_datastore:getDataStore', function(name, owner, cb) - cb(GetDataStore(name, owner)) -end) - -AddEventHandler('esx_datastore:getDataStoreOwners', function(name, cb) - cb(GetDataStoreOwners(name)) -end) - -AddEventHandler('esx_datastore:getSharedDataStore', function(name, cb) - cb(GetSharedDataStore(name)) -end) - -AddEventHandler('esx:playerLoaded', function(playerId, xPlayer) - for i=1, #DataStoresIndex, 1 do - local name = DataStoresIndex[i] - local dataStore = GetDataStore(name, xPlayer.identifier) - - if not dataStore then - MySQL.insert('INSERT INTO datastore_data (name, owner, data) VALUES (?, ?, ?)', {name, xPlayer.identifier, '{}'}) - - DataStores[name][#DataStores[name] + 1] = CreateDataStore(name, xPlayer.identifier, {}) - end - end -end) diff --git a/server-data/resources/[esx_addons]/esx_policejob/README.md b/server-data/resources/[esx_addons]/esx_policejob/README.md index f8974f415..fcf228bcd 100644 --- a/server-data/resources/[esx_addons]/esx_policejob/README.md +++ b/server-data/resources/[esx_addons]/esx_policejob/README.md @@ -7,7 +7,6 @@ This resource for ESX adds police armories, vehicle garages and ability for cops * [esx_vehicleshop](https://github.com/esx-framework/esx_vehicleshop) * Player management (boss actions and armory with buyable weapons) - * [esx_datastore](https://github.com/esx-framework/esx_datastore) * [esx_society](https://github.com/esx-framework/esx_society) * ESX Identity Support diff --git a/server-data/resources/[esx_addons]/esx_policejob/server/main.lua b/server-data/resources/[esx_addons]/esx_policejob/server/main.lua index c3316be83..d98adb818 100644 --- a/server-data/resources/[esx_addons]/esx_policejob/server/main.lua +++ b/server-data/resources/[esx_addons]/esx_policejob/server/main.lua @@ -263,7 +263,7 @@ ESX.RegisterServerCallback("esx_policejob:getVehicleInfos", function(source, cb, end) ESX.RegisterServerCallback("esx_policejob:getArmoryWeapons", function(source, cb) - TriggerEvent("esx_datastore:getSharedDataStore", "society_police", function(store) + TriggerEvent("bpt_datastore:getSharedDataStore", "society_police", function(store) local weapons = store.get("weapons") if weapons == nil then @@ -281,7 +281,7 @@ ESX.RegisterServerCallback("esx_policejob:addArmoryWeapon", function(source, cb, xPlayer.removeWeapon(weaponName) end - TriggerEvent("esx_datastore:getSharedDataStore", "society_police", function(store) + TriggerEvent("bpt_datastore:getSharedDataStore", "society_police", function(store) local weapons = store.get("weapons") or {} local foundWeapon = false @@ -309,7 +309,7 @@ ESX.RegisterServerCallback("esx_policejob:removeArmoryWeapon", function(source, local xPlayer = ESX.GetPlayerFromId(source) xPlayer.addWeapon(weaponName, 500) - TriggerEvent("esx_datastore:getSharedDataStore", "society_police", function(store) + TriggerEvent("bpt_datastore:getSharedDataStore", "society_police", function(store) local weapons = store.get("weapons") or {} local foundWeapon = false diff --git a/server-data/resources/[esx_addons]/esx_property/server/main.lua b/server-data/resources/[esx_addons]/esx_property/server/main.lua index 2c8c25ccd..989bcffcf 100644 --- a/server-data/resources/[esx_addons]/esx_property/server/main.lua +++ b/server-data/resources/[esx_addons]/esx_property/server/main.lua @@ -1041,7 +1041,7 @@ end) ESX.RegisterServerCallback("esx_property:getPlayerDressing", function(source, cb) local xPlayer = ESX.GetPlayerFromId(source) - TriggerEvent("esx_datastore:getDataStore", "property", xPlayer.identifier, function(store) + TriggerEvent("bpt_datastore:getDataStore", "property", xPlayer.identifier, function(store) local count = store.count("dressing") local labels = {} @@ -1270,7 +1270,7 @@ end) ESX.RegisterServerCallback("esx_property:getPlayerOutfit", function(source, cb, num) local xPlayer = ESX.GetPlayerFromId(source) - TriggerEvent("esx_datastore:getDataStore", "property", xPlayer.identifier, function(store) + TriggerEvent("bpt_datastore:getDataStore", "property", xPlayer.identifier, function(store) local outfit = store.get("dressing", num) cb(outfit.skin) end)