diff --git a/client/bootstrap.lua b/common/bootstrap.lua similarity index 90% rename from client/bootstrap.lua rename to common/bootstrap.lua index e658763c..563d101e 100644 --- a/client/bootstrap.lua +++ b/common/bootstrap.lua @@ -15,3 +15,4 @@ OnESX = function(cb) end +exports('OnESX', OnESX) diff --git a/es_extended.sql b/es_extended.sql index b36720c6..8339b75c 100644 --- a/es_extended.sql +++ b/es_extended.sql @@ -1,49 +1,54 @@ -CREATE DATABASE IF NOT EXISTS `es_extended`; +CREATE DATABASE IF NOT EXISTS `es_extended` USE `es_extended`; -CREATE TABLE `users` ( - `identifier` VARCHAR(40) NOT NULL, - `accounts` LONGTEXT NULL DEFAULT NULL, - `group` VARCHAR(50) NULL DEFAULT 'user', - `inventory` LONGTEXT NULL DEFAULT NULL, - `job` VARCHAR(20) NULL DEFAULT 'unemployed', - `job_grade` INT(11) NULL DEFAULT 0, - `loadout` LONGTEXT NULL DEFAULT NULL, - `position` VARCHAR(53) NULL DEFAULT '{"x":-269.4,"y":-955.3,"z":31.2,"heading":205.8}', +CREATE TABLE IF NOT EXISTS `migrations` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `module` varchar(50) NOT NULL, + `last` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - PRIMARY KEY (`identifier`) -); +CREATE TABLE IF NOT EXISTS `items` ( + `name` varchar(50) NOT NULL, + `label` varchar(50) NOT NULL, + `weight` int(11) NOT NULL DEFAULT 1, + `rare` tinyint(1) NOT NULL DEFAULT 0, + `can_remove` tinyint(1) NOT NULL DEFAULT 1, + PRIMARY KEY (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -CREATE TABLE `items` ( - `name` VARCHAR(50) NOT NULL, - `label` VARCHAR(50) NOT NULL, - `weight` INT(11) NOT NULL DEFAULT 1, - `rare` TINYINT(1) NOT NULL DEFAULT 0, - `can_remove` TINYINT(1) NOT NULL DEFAULT 1, +CREATE TABLE IF NOT EXISTS `jobs` ( + `name` varchar(50) NOT NULL, + `label` varchar(50) DEFAULT NULL, + PRIMARY KEY (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - PRIMARY KEY (`name`) -); +CREATE TABLE IF NOT EXISTS `job_grades` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `job_name` varchar(50) DEFAULT NULL, + `grade` int(11) NOT NULL, + `name` varchar(50) NOT NULL, + `label` varchar(50) NOT NULL, + `salary` int(11) NOT NULL, + `skin_male` longtext NOT NULL, + `skin_female` longtext NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8mb4; -CREATE TABLE `job_grades` ( - `id` INT(11) NOT NULL AUTO_INCREMENT, - `job_name` VARCHAR(50) DEFAULT NULL, - `grade` INT(11) NOT NULL, - `name` VARCHAR(50) NOT NULL, - `label` VARCHAR(50) NOT NULL, - `salary` INT(11) NOT NULL, - `skin_male` LONGTEXT NOT NULL, - `skin_female` LONGTEXT NOT NULL, - - PRIMARY KEY (`id`) -); - -INSERT INTO `job_grades` VALUES (1,'unemployed',0,'unemployed','Unemployed',200,'{}','{}'); - -CREATE TABLE `jobs` ( - `name` VARCHAR(50) NOT NULL, - `label` VARCHAR(50) DEFAULT NULL, - - PRIMARY KEY (`name`) -); - -INSERT INTO `jobs` VALUES ('unemployed','Unemployed'); +CREATE TABLE IF NOT EXISTS `users` ( + `identifier` varchar(40) NOT NULL, + `accounts` longtext DEFAULT NULL, + `group` varchar(50) DEFAULT 'user', + `inventory` longtext DEFAULT NULL, + `job` varchar(20) DEFAULT 'unemployed', + `job_grade` int(11) DEFAULT 0, + `loadout` longtext DEFAULT NULL, + `position` varchar(53) DEFAULT '{"x":-269.4,"y":-955.3,"z":31.2,"heading":205.8}', + `skin` longtext DEFAULT NULL, + `phone_number` int(11) DEFAULT NULL, + `name` varchar(255) DEFAULT NULL, + `status` longtext DEFAULT NULL, + `is_dead` tinyint(1) DEFAULT 0, + PRIMARY KEY (`identifier`), + UNIQUE KEY `index_users_phone_number` (`phone_number`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/fxmanifest.lua b/fxmanifest.lua index 77150781..3dce7eed 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -34,7 +34,9 @@ server_scripts { 'common/modules/math.lua', 'common/modules/table.lua', - 'common/functions.lua' + 'common/functions.lua', + + 'common/bootstrap.lua', } client_scripts { @@ -66,6 +68,8 @@ client_scripts { 'common/modules/math.lua', 'common/modules/table.lua', 'common/functions.lua', + + 'common/bootstrap.lua', } ui_page { @@ -108,11 +112,20 @@ esxmodule = function(name) end -esxmodule 'input' -esxmodule 'hud' -esxmodule 'menu_default' -esxmodule 'menu_dialog' -esxmodule 'menu_list' -esxmodule 'interact' +-- Misc +esxmodule 'input' -- Evented input manager +esxmodule 'interact' -- Interact menu (marker / npc) -esxmodule 'job_police' +-- Extend +esxmodule 'addonaccount' -- Addon account +esxmodule 'addoninventory' -- Addon inventory +esxmodule 'datastore' -- Arbitrary data store + +-- UI +esxmodule 'hud' -- Money / society etc... HUD +esxmodule 'menu_default' -- Default menu +esxmodule 'menu_dialog' -- Dialog menu +esxmodule 'menu_list' -- List menu + +-- Jobs +esxmodule 'job_police' -- Job police diff --git a/modules/addonaccount b/modules/addonaccount new file mode 160000 index 00000000..9e6b9b28 --- /dev/null +++ b/modules/addonaccount @@ -0,0 +1 @@ +Subproject commit 9e6b9b28249dc2c3745e243562c898d123cdcb4a diff --git a/modules/addoninventory b/modules/addoninventory new file mode 160000 index 00000000..c339d442 --- /dev/null +++ b/modules/addoninventory @@ -0,0 +1 @@ +Subproject commit c339d44214aaf4ec1e436df42fe85884df458cd1 diff --git a/modules/container/server/module.lua b/modules/container/server/module.lua new file mode 100644 index 00000000..4ac77dc8 --- /dev/null +++ b/modules/container/server/module.lua @@ -0,0 +1,3 @@ +ESX.Modules['container'] = {} +local self = ESX.Modules['container'] + diff --git a/modules/datastore b/modules/datastore new file mode 160000 index 00000000..88fd62fe --- /dev/null +++ b/modules/datastore @@ -0,0 +1 @@ +Subproject commit 88fd62fe7c566b998166a458df4abbbd67d5d538 diff --git a/modules/job_police/data/config.lua b/modules/job_police/data/config.lua index b039d9b1..7a7c0407 100644 --- a/modules/job_police/data/config.lua +++ b/modules/job_police/data/config.lua @@ -6,7 +6,7 @@ Config.MarkerSize = {x = 1.5, y = 1.5, z = 0.5} Config.MarkerColor = {r = 50, g = 50, b = 204, a = 100} Config.EnablePlayerManagement = false -Config.EnableArmoryManagement = false +Config.EnableArmoryManagement = true Config.EnableESXIdentity = false -- enable if you're using esx_identity Config.EnableLicenses = false -- enable if you're using esx_license diff --git a/server/functions.lua b/server/functions.lua index 5038c059..0edbd6f0 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -1,3 +1,70 @@ +ESX.EnsureMigrations = function(module) + + print('[esx] migrate => ' .. module) + + local dir + + if module == 'base' then + dir = 'migrations' + else + dir = 'modules/' .. module .. '/migrations' + end + + local result = MySQL.Sync.fetchAll('SELECT * FROM `migrations` WHERE `module` = @module', {['@module'] = module}) + local initial = true + local i = 0 + local hasmigrated = false + + if #result > 0 then + i = result[1].last + 1 + initial = false + end + + local sql = nil + + repeat + + sql = LoadResourceFile(GetCurrentResourceName(), dir .. '/' .. i .. '.sql') + + if sql ~= nil then + + print('[esx] [' .. module .. '] => running migration #' .. i) + + MySQL.Sync.execute(sql) + + if initial then + MySQL.Sync.execute('INSERT INTO `migrations` (module, last) VALUES (@module, @last)', {['@module'] = module, ['@last'] = 0}) + else + MySQL.Sync.execute('UPDATE `migrations` SET `last` = @last WHERE `module` = @module', {['@module'] = module, ['@last'] = i}) + end + + hasmigrated = true + + end + + i = i + 1 + + until sql == nil + + if not hasmigrated then + print('[esx] [' .. module .. '] => no pending migration') + end + +end + +ESX.FileExists = function(name) + + local f=io.open(name, 'r') + + if f~=nil then + io.close(f) + return true + else + return false + end + +end + ESX.Trace = function(msg) if Config.EnableDebug then print(('[es_extended] [^2TRACE^7] %s^7'):format(msg)) diff --git a/server/main.lua b/server/main.lua index 2e9b2ebb..8314cb3d 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,3 +1,17 @@ +MySQL.ready(function() + + print('[esx] ensuring migrations') + + TriggerEvent('esx:migrations:ensure', function(module) + ESX.EnsureMigrations(module) + end) + +end) + +AddEventHandler('esx:migrations:ensure', function(register) + register('base') +end) + RegisterNetEvent('esx:onPlayerJoined') AddEventHandler('esx:onPlayerJoined', function() if not ESX.Players[source] then