diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6806385 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,116 @@ +name: Release + +# Publishes a release when a push to main bumps the fxmanifest.lua version. +# Tags/titles are bare versions (0.13.4) to match this repo's existing releases. +# +# The "Update Webhook Notification" workflow listens for release:published, and +# GitHub suppresses workflow triggers for events raised by GITHUB_TOKEN. Add a +# classic PAT with repo scope as the RELEASE_PAT secret to keep the Discord +# announcement firing; without it the release still publishes, silently. + +on: + push: + branches: + - main + paths: + - 'fxmanifest.lua' + workflow_dispatch: + +permissions: + contents: write + +jobs: + check-version: + runs-on: ubuntu-latest + outputs: + should_release: ${{ steps.meta.outputs.should_release }} + version: ${{ steps.meta.outputs.version }} + steps: + - name: Checkout + uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Detect fxmanifest version change + id: meta + run: | + CURRENT=$(grep -E '^version ' fxmanifest.lua | sed -E "s/^version[[:space:]]+['\"]([^'\"]+)['\"].*/\1/") + echo "version=$CURRENT" >> "$GITHUB_OUTPUT" + + if [ -z "$CURRENT" ]; then + echo "::error::No version found in fxmanifest.lua" + exit 1 + fi + + # Never re-release an existing version: a duplicate release would + # announce itself to Discord as if it were new. + if git rev-parse "refs/tags/$CURRENT" >/dev/null 2>&1; then + echo "should_release=false" >> "$GITHUB_OUTPUT" + echo "Tag $CURRENT already exists; skipping release." + exit 0 + fi + + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "should_release=true" >> "$GITHUB_OUTPUT" + echo "Manual run; releasing version $CURRENT" + exit 0 + fi + + BEFORE="${{ github.event.before }}" + if [ "$BEFORE" = "0000000000000000000000000000000000000000" ] || [ -z "$BEFORE" ]; then + echo "should_release=true" >> "$GITHUB_OUTPUT" + echo "Initial or force push; releasing version $CURRENT" + exit 0 + fi + + PREVIOUS=$(git show "$BEFORE:fxmanifest.lua" 2>/dev/null | grep -E '^version ' | sed -E "s/^version[[:space:]]+['\"]([^'\"]+)['\"].*/\1/" || true) + if [ "$CURRENT" = "$PREVIOUS" ]; then + echo "should_release=false" >> "$GITHUB_OUTPUT" + echo "fxmanifest changed but version is still $CURRENT; skipping release." + else + echo "should_release=true" >> "$GITHUB_OUTPUT" + echo "Version updated: ${PREVIOUS:-unknown} -> $CURRENT" + fi + + release: + runs-on: ubuntu-latest + needs: check-version + if: needs.check-version.outputs.should_release == 'true' + + steps: + - name: Checkout + uses: actions/checkout@v5 + + - name: Prepare release package + run: | + RELEASE_ROOT="release/community_bridge" + mkdir -p "$RELEASE_ROOT" + + rsync -a \ + --exclude '.git' \ + --exclude '.gitattributes' \ + --exclude '.gitignore' \ + --exclude '.github' \ + --exclude 'release' \ + --exclude 'node_modules' \ + ./ "$RELEASE_ROOT/" + + - name: Create zip archive + run: | + cd release + zip -r "../community_bridge.zip" community_bridge + + - name: Upload workflow artifact + uses: actions/upload-artifact@v5 + with: + name: community_bridge + path: community_bridge.zip + + - name: Publish GitHub Release + uses: softprops/action-gh-release@v2 + with: + token: ${{ secrets.RELEASE_PAT || github.token }} + tag_name: ${{ needs.check-version.outputs.version }} + name: ${{ needs.check-version.outputs.version }} + files: community_bridge.zip + generate_release_notes: true diff --git a/fxmanifest.lua b/fxmanifest.lua index 58b471c..b2f17b5 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -5,7 +5,7 @@ use_experimental_fxv2_oal 'yes' author 'The Order of the Sacred Framework' name 'community_bridge' description 'A Universal Bridge for Our Community, created by a group of contributors with a shared vision to enhance both user and developer experiences. This bridge connects various frameworks, inventories, target systems, notification systems, and more, fostering compatibility and seamless integration.' -version '0.13.4' +version '0.13.5' shared_scripts { '@ox_lib/init.lua', diff --git a/lib/sql/server/sqlHandler.lua b/lib/sql/server/sqlHandler.lua index 644467e..9e35fec 100644 --- a/lib/sql/server/sqlHandler.lua +++ b/lib/sql/server/sqlHandler.lua @@ -1,21 +1,67 @@ +--[[ + DEPRECATED: the SQL helper module is deprecated in its entirety and will be + REMOVED on 2026-08-22. Migrate to oxmysql directly — MySQL.query.await(query, + params) with ? placeholders — which is safer and more flexible than these + wrappers ever were. +]] + SQL = {} Require("lib/MySQL.lua", "oxmysql") +local warnedResources = {} + +local function warnDeprecated() + local caller = GetInvokingResource() or GetCurrentResourceName() + if warnedResources[caller] then return end + warnedResources[caller] = true + print(("^3[community_bridge] SQL helpers are deprecated and will be REMOVED on 2026-08-22. '%s' should migrate to oxmysql directly (MySQL.query.await with ? placeholders).^0"):format(caller)) +end + +-- Identifiers (table/column names) cannot be parameterized, so they are +-- validated against a strict pattern and backtick-quoted instead. Values are +-- never concatenated into queries - they always go through ? placeholders. +local function quoteIdentifier(name) + assert(type(name) == "string" and name:match("^[%a_][%w_]*$"), + ("SQL: unsafe identifier '%s' - table/column names may only contain letters, digits and underscores"):format(tostring(name))) + return "`" .. name .. "`" +end + +--- Builds a parameterized WHERE clause from a table of column = value pairs. +-- Raw WHERE strings are intentionally rejected: they made SQL injection +-- unavoidable whenever a player-influenced value reached these helpers. +local function buildWhere(where) + assert(type(where) == "table" and next(where) ~= nil, + "SQL: where must be a non-empty table of column = value pairs (raw WHERE strings are no longer accepted)") + + local conditions = {} + local params = {} + + for column, value in pairs(where) do + table.insert(conditions, quoteIdentifier(column) .. " = ?") + table.insert(params, value) + end + + return table.concat(conditions, " AND "), params +end + --- Creates a table in the database if it does not exist. -- @param tableName The name of the table to create. Example: {{ name = "identifier", type = "VARCHAR(50)", primary = true }} -- @param columns A table containing column definitions, where each column is a table with 'name' and 'type'. ---@return nil +---@deprecated Removed on 2026-08-22 — use oxmysql directly. function SQL.Create(tableName, columns) + warnDeprecated() assert(MySQL, "Tried using module SQL without MySQL being loaded") local columnsList = {} for i, column in pairs(columns) do - table.insert(columnsList, string.format("%s %s", column.name, column.type)) + assert(type(column.type) == "string", "SQL: column type must be a string") + table.insert(columnsList, string.format("%s %s", quoteIdentifier(column.name), column.type)) end local query = string.format("CREATE TABLE IF NOT EXISTS %s (%s);", - tableName, + quoteIdentifier(tableName), table.concat(columnsList, ", ") ) @@ -23,50 +69,70 @@ function SQL.Create(tableName, columns) end -- insert if not exist otherwise update +---@deprecated Removed on 2026-08-22 — use oxmysql directly. function SQL.InsertOrUpdate(tableName, data) + warnDeprecated() assert(MySQL, "Tried using module SQL without MySQL being loaded") local columns = {} - local values = {} + local placeholders = {} local updates = {} + local params = {} for column, value in pairs(data) do - table.insert(columns, column) - table.insert(values, "'" .. value .. "'") -- Ensure values are properly quoted - table.insert(updates, column .. " = VALUES(" .. column .. ")") -- Use VALUES() for update + local quoted = quoteIdentifier(column) + table.insert(columns, quoted) + table.insert(placeholders, "?") + table.insert(updates, quoted .. " = VALUES(" .. quoted .. ")") -- Use VALUES() for update + table.insert(params, value) end local query = string.format( "INSERT INTO %s (%s) VALUES (%s) ON DUPLICATE KEY UPDATE %s;", - tableName, + quoteIdentifier(tableName), table.concat(columns, ", "), - table.concat(values, ", "), + table.concat(placeholders, ", "), table.concat(updates, ", ") ) - MySQL.query.await(query) + MySQL.query.await(query, params) end +--- Selects rows matching the given filters. +-- @param tableName The table to query. +-- @param where Table of column = value pairs, joined with AND. Example: { citizenid = cid } +---@deprecated Removed on 2026-08-22 — use oxmysql directly. function SQL.Get(tableName, where) + warnDeprecated() assert(MySQL, "Tried using module SQL without MySQL being loaded") - local query = string.format("SELECT * FROM %s WHERE %s;", tableName, where) - local result = MySQL.query.await(query) + local conditions, params = buildWhere(where) + local query = string.format("SELECT * FROM %s WHERE %s;", quoteIdentifier(tableName), conditions) + local result = MySQL.query.await(query, params) return result end +---@deprecated Removed on 2026-08-22 — use oxmysql directly. function SQL.GetAll(tableName) + warnDeprecated() assert(MySQL, "Tried using module SQL without MySQL being loaded") - local query = string.format("SELECT * FROM %s;", tableName) + local query = string.format("SELECT * FROM %s;", quoteIdentifier(tableName)) local result = MySQL.query.await(query) return result end +--- Deletes rows matching the given filters. +-- @param tableName The table to delete from. +-- @param where Table of column = value pairs, joined with AND. Example: { citizenid = cid } +---@deprecated Removed on 2026-08-22 — use oxmysql directly. function SQL.Delete(tableName, where) + warnDeprecated() assert(MySQL, "Tried using module SQL without MySQL being loaded") - local query = string.format("DELETE FROM %s WHERE %s;", tableName, where) - MySQL.query.await(query) + local conditions, params = buildWhere(where) + local query = string.format("DELETE FROM %s WHERE %s;", quoteIdentifier(tableName), conditions) + MySQL.query.await(query, params) end exports('SQL', function() + warnDeprecated() return SQL end) diff --git a/modules/framework/qbx_core/server.lua b/modules/framework/qbx_core/server.lua index f8431aa..53071bd 100644 --- a/modules/framework/qbx_core/server.lua +++ b/modules/framework/qbx_core/server.lua @@ -547,4 +547,30 @@ AddEventHandler("playerDropped", function() TriggerEvent("community_bridge:Server:OnPlayerUnload", src) end) -return Framework \ No newline at end of file +Framework.Commands = Framework.Commands or {} + +---@description Adds a command to the Qbox framework +---@param name string +---@param help string +---@param arguments table +---@param argsrequired boolean +---@param callback function +---@param permission string +---@param ... any +Framework.Commands.Add = function(name, help, arguments, argsrequired, callback, permission, ...) + lib.addCommand(name, { + help = help or "", + params = arguments or {}, + restricted = false + }, function(source, args, raw) + if permission and permission ~= "user" then + if not Framework.GetIsFrameworkAdmin(source) then + return + end + end + + callback(source, args or {}, raw) + end) +end + +return Framework diff --git a/modules/inventory/tgiann-inventory/server.lua b/modules/inventory/tgiann-inventory/server.lua index c77e0e1..a3d8e99 100644 --- a/modules/inventory/tgiann-inventory/server.lua +++ b/modules/inventory/tgiann-inventory/server.lua @@ -129,9 +129,10 @@ end ---@description This will return a boolean if the player has the item. ---@param src number ---@param item string +---@param requiredCount number (optional) ---@return boolean -Inventory.HasItem = function(src, item) - return tgiann:HasItem(src, item, 1) +Inventory.HasItem = function(src, item, requiredCount) + return tgiann:HasItem(src, item, requiredCount or 1) end ---@description This is to get if there is available space in the inventory, will return boolean. diff --git a/modules/notify/msk_core/client.lua b/modules/notify/msk_core/client.lua new file mode 100644 index 0000000..59838e6 --- /dev/null +++ b/modules/notify/msk_core/client.lua @@ -0,0 +1,38 @@ +---@diagnostic disable: duplicate-set-field +Notify = Notify or {} +local resourceName = "msk_core" +local configValue = BridgeSharedConfig.Notify +if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end + +Notify.GetResourceName = function() + return resourceName +end + +local Language = Language or Require("modules/locales/shared.lua") +local locale = Language.Locale +local placeHolderText = locale("Notifications.PlaceholderTitle") + +---DEPRICATED: PLEASE SWITCH TO Notify.SendNotification +---@param message string +---@param _type string +---@param time number +---@return nil +Notify.SendNotify = function(message, _type, time) + time = time or 3000 + return exports.msk_core:Notify(nil, message, _type, time) +end + +---This will send a notify message of the type and time passed +---@param title string +---@param message string +---@param _type string +---@param time number +---@param props table optional +---@return nil +Notify.SendNotification = function(title, message, _type, time, props) + time = time or 3000 + if not title then title = placeHolderText end + return exports.msk_core:Notify(title, message, _type or "success", time) +end + +return Notify diff --git a/modules/progressbar/msk_core/client.lua b/modules/progressbar/msk_core/client.lua new file mode 100644 index 0000000..5c993d8 --- /dev/null +++ b/modules/progressbar/msk_core/client.lua @@ -0,0 +1,66 @@ +---@diagnostic disable: duplicate-set-field +local resourceName = "msk_core" +local configValue = BridgeClientConfig.ProgressBarSystem +if (configValue == "auto" and GetResourceState(resourceName) ~= "started") or (configValue ~= "auto" and configValue ~= resourceName) then return end + +ProgressBar = ProgressBar or {} + +---Converts bridge/ox-style progress options into the msk_core Progress.Start format. +---@param options table +---@return table +local function convertToMsk(options) + options = options or {} + + -- QB exposes animation under .animation.animDict/.anim and disables under .controlDisables + local anim = options.anim or options.animation + local animation + if anim then + animation = { + dict = anim.dict or anim.animDict, + anim = anim.clip or anim.anim, + flag = anim.flag or anim.flags or 49, + } + end + + -- ox uses options.disable.{move,car,combat,mouse}, QB uses options.controlDisables.* + local d = options.disable or options.controlDisables or {} + local disable = { + move = d.move or d.disableMovement, + vehicle = d.car or d.disableCarMovement, + combat = d.combat or d.disableCombat, + mouse = d.mouse or d.disableMouse, + } + + return { + duration = options.duration, + text = options.label or options.text or '', + disable = disable, + animation = animation, + forceOverride = options.forceOverride, + } +end + +---This will open a progress bar (blocking until it completes). +---@param options table +---@param cb any optional callback receiving the success boolean +---@param isQBInput boolean optional +---@return boolean success true if the progress completed without being cancelled +function ProgressBar.Open(options, cb, isQBInput) + local data = convertToMsk(options) + + -- msk_core Progress.Start blocks for the full duration; if it is interrupted + -- it stops early. We treat a fully elapsed bar as success. + exports.msk_core:Progressbar(data) + + local active = exports.msk_core:ProgressActive() + local success = not active + + if cb then cb(success) end + return success +end + +ProgressBar.GetResourceName = function() + return resourceName +end + +return ProgressBar diff --git a/settings/clientConfig.lua b/settings/clientConfig.lua index f1d54d9..69dc9e5 100644 --- a/settings/clientConfig.lua +++ b/settings/clientConfig.lua @@ -1,7 +1,7 @@ BridgeClientConfig = {} BridgeClientConfig.InputSystem = "auto" -- [ auto | ox_lib | lation_ui | qb-input ] BridgeClientConfig.MenuSystem = "auto" -- [ auto | ox_lib | wasabi_uikit | lation_ui | qb-menu ] -BridgeClientConfig.ProgressBarSystem = "auto" -- [ auto | ox_lib | wasabi_uikit | lation_ui | ZSX_UIV2 | keep-progressbar | progressbar ] +BridgeClientConfig.ProgressBarSystem = "auto" -- [ auto | ox_lib | wasabi_uikit | lation_ui | ZSX_UIV2 | keep-progressbar | progressbar | msk_core ] BridgeClientConfig.VehicleKey = "auto" -- [ auto | qb-vehiclekeys | MrNewbVehicleKeys | jaksams_VehiclesKeys | wasabi_carlock | mk_vehiclekeys | qbx_vehiclekeys | qs-vehiclekeys | t1ger_keys | Renewed-Vehiclekeys | mono_carkeys| cd_garage | okokGarage | F_RealCarKeysSystem BridgeClientConfig.Fuel = "auto" -- [ auto | LegacyFuel | ox_fuel | ps-fuel | qs-fuelstations | Renewed-Fuel | ti_fuel | lc_fuel | x-fuel | cdn-fuel | esx-sna-fuel | BigDaddy-Fuel | okokGasStation ] BridgeClientConfig.TargetSystem = "auto" -- [ auto | ox_target | qb-target | sleepless_interact ] -- sleepless is only partially supported and would need another system in place diff --git a/settings/sharedConfig.lua b/settings/sharedConfig.lua index 3bc3a79..7b55311 100644 --- a/settings/sharedConfig.lua +++ b/settings/sharedConfig.lua @@ -1,7 +1,7 @@ BridgeSharedConfig = {} BridgeSharedConfig.Lang = "auto" -- Change this to your preferred language (must match the locale file name ex. en or fr etc) BridgeSharedConfig.DebugLevel = 0 -- Change this to your Debug level, 0 for none, 1 for some, 2 for all data -BridgeSharedConfig.Notify = "auto" -- [ auto | ox_lib | r_notify | wasabi_notify | lation_ui | ZSX_UIV2 | okokNotify | mythic_notify | pNotify | t-notify | brutal_notify | FL-Notify] +BridgeSharedConfig.Notify = "auto" -- [ auto | ox_lib | r_notify | wasabi_notify | lation_ui | ZSX_UIV2 | okokNotify | mythic_notify | pNotify | t-notify | brutal_notify | FL-Notify | msk_core] BridgeSharedConfig.HelpText = "auto" -- [ auto | ox_lib | jg-textui | lation_ui | ZSX_UIV2 | cd_drawtextui | lab-HintUI | okokTextUI] BridgeSharedConfig.Phone = "auto" -- [ auto | qs-smartphone | lb-phone | gksphone] BridgeSharedConfig.Skills = "auto" -- [ auto | OT_skills | evolent_skills | pickle_xp]