Skip to content

Commit

Permalink
Update v2.1.0
Browse files Browse the repository at this point in the history
* Added new VersionChecker
* Added Config.customNotification
* Integrated MSK Bansystem
* Changes in Callbacks
  • Loading branch information
Musiker15 committed Jun 1, 2024
1 parent bd652e6 commit 387f926
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 106 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0
2.1.0
78 changes: 33 additions & 45 deletions client/cl_callback.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ local GenerateCallbackHandlerKey = function()
end
end

RegisterNetEvent("msk_core:client:callbackResponse", function(requestId, ...)
if not CallbackHandler[requestId] then return end
CallbackHandler[requestId] = {...}
end)

RegisterNetEvent("msk_core:client:callbackNotFound", function(requestId)
if not CallbackHandler[requestId] then return end
CallbackHandler[requestId] = nil
end)

----------------------------------------------------------------
-- NEW Method for Client Callbacks
-- Client Callbacks
----------------------------------------------------------------
MSK.Register = function(eventName, cb)
Callbacks[eventName] = cb
Expand All @@ -33,7 +43,7 @@ RegisterNetEvent('msk_core:client:triggerClientCallback', function(playerId, eve
end)

----------------------------------------------------------------
-- NEW Method for Server Callbacks
-- Server Callbacks with Method [return]
----------------------------------------------------------------
MSK.Trigger = function(eventName, ...)
local requestId = GenerateCallbackHandlerKey()
Expand All @@ -45,7 +55,7 @@ MSK.Trigger = function(eventName, ...)
p:reject(('Request Timed Out: [%s] [%s]'):format(eventName, requestId))
end)

TriggerServerEvent('msk_core:server:triggerServerCallback', eventName, requestId, ...)
TriggerServerEvent('msk_core:server:triggerCallback', eventName, requestId, false, ...)

while CallbackHandler[requestId] == 'request' do Wait(0) end
if not CallbackHandler[requestId] then return end
Expand All @@ -58,52 +68,30 @@ MSK.Trigger = function(eventName, ...)
end
exports('Trigger', MSK.Trigger)

RegisterNetEvent("msk_core:client:callbackResponse", function(requestId, ...)
if not CallbackHandler[requestId] then return end
CallbackHandler[requestId] = {...}
end)

RegisterNetEvent("msk_core:client:callbackNotFound", function(requestId)
if not CallbackHandler[requestId] then return end
CallbackHandler[requestId] = nil
end)

----------------------------------------------------------------
-- OLD Method for Server Callbacks [OUTDATED - Do not use this!]
-- Server Callbacks with Method [cb]
----------------------------------------------------------------
local callbackRequest = {}

local GenerateRequestKey = function()
local requestId = math.random(1, 999999999)

if not callbackRequest[requestId] then
return tostring(requestId)
else
GenerateRequestKey()
end
end

MSK.TriggerServerCallback = function(name, ...)
local requestId = GenerateRequestKey()
local response
MSK.TriggerCallback = function(eventName, ...)
local requestId = GenerateCallbackHandlerKey()
local p = promise.new()
CallbackHandler[requestId] = 'request'

callbackRequest[requestId] = function(...)
response = {...}
end
SetTimeout(5000, function()
CallbackHandler[requestId] = nil
p:reject(('Request Timed Out: [%s] [%s]'):format(eventName, requestId))
end)

TriggerServerEvent('msk_core:server:triggerCallback', eventName, requestId, true, ...)

TriggerServerEvent('msk_core:triggerCallback', name, requestId, ...)
while CallbackHandler[requestId] == 'request' do Wait(0) end
if not CallbackHandler[requestId] then return end

while not response do Wait(0) end
p:resolve(CallbackHandler[requestId])
CallbackHandler[requestId] = nil

return table.unpack(response)
local result = Citizen.Await(p)
return table.unpack(result)
end
MSK.TriggerCallback = MSK.TriggerServerCallback
exports('TriggerServerCallback', MSK.TriggerServerCallback)

RegisterNetEvent("msk_core:responseCallback")
AddEventHandler("msk_core:responseCallback", function(requestId, ...)
if callbackRequest[requestId] then
callbackRequest[requestId](...)
callbackRequest[requestId] = nil
end
end)
MSK.TriggerServerCallback = MSK.TriggerCallback
exports('TriggerCallback', MSK.TriggerCallback)
exports('TriggerServerCallback', MSK.TriggerCallback)
10 changes: 6 additions & 4 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ elseif Config.Framework:match('qbcore') then
end)
end

exports('getCoreObject', function()
return MSK
end)

MSK.Notification = function(title, message, info, time)
if Config.Notification == 'native' then
SetNotificationTextEntry('STRING')
AddTextComponentString(message)
DrawNotification(false, true)
elseif Config.Notification == 'okok' then
exports['okokNotify']:Alert(title, message, time or 5000, info or 'info')
elseif Config.Notification == 'custom' then
Config.customNotification()
else
SendNUIMessage({
action = 'notify',
Expand Down Expand Up @@ -148,8 +154,4 @@ end)
RegisterNetEvent('msk_core:advancedNotification')
AddEventHandler('msk_core:advancedNotification', function(text, title, subtitle, icon, flash, icontype)
MSK.AdvancedNotification(text, title, subtitle, icon, flash, icontype)
end)

exports('getCoreObject', function()
return MSK
end)
30 changes: 27 additions & 3 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ Config = {}
Config.Debug = false
Config.VersionChecker = true
----------------------------------------------------------------
-- Only Required for MSK.RegisterCommand // View Wiki for more Information about that!
-- Only Required for MSK.RegisterCommand and MSK.HasItem // View Docu for more Information about that!
Config.Framework = 'esx' -- Set to 'standalone', 'esx' or 'qbcore'
----------------------------------------------------------------
-- /coords
Config.showCoords = {
enable = true,
command = 'coords',
Expand All @@ -15,8 +16,14 @@ Config.showCoords = {
-- Set to 'native' for FiveM Native Notification
-- Set to 'msk' for NUI Notification
-- Set to 'okok' for OKOK Notification
-- Set to 'custom' for Config.customNotification()
Config.Notification = 'msk'

Config.customNotification = function()
-- Set Config.Notification = 'custom'
-- Add your own clientside Notification here
end

Config.progressColor = "#5eb131" -- Default Color for ProgressBar
----------------------------------------------------------------
Config.LoggingTypes = {
Expand All @@ -28,16 +35,33 @@ Config.LoggingTypes = {
Config.AntiCombatlog = {
enable = false, -- Set to true if you want to use this Feature
console = {
enable = true,
enable = false,
text = "Der Spieler ^3%s^0 mit der ^3ID %s^0 hat den Server verlassen.\n^4Uhrzeit:^0 %s\n^4Grund:^0 %s\n^4Identifier:^0\n %s\n %s\n %s\n^4Koordinaten:^0 %s"
},
discord = {
-- Webhook in sv_anticombatlog.lua
enable = true,
enable = false,
color = "6205745", -- https://www.mathsisfun.com/hexadecimal-decimal-colors.html
botName = "MSK Scripts",
botAvatar = "https://i.imgur.com/PizJGsh.png",
title = "Player Disconnected",
text = "Der Spieler **%s** mit der **ID %s** hat den Server verlassen."
}
}
----------------------------------------------------------------
-- For more Information go to: https://github.com/MSK-Scripts/msk_bansystem/blob/main/README.md
Config.BanSystem = {
enable = false, -- Set to true if you want to use this Feature

discordLog = false, -- Set true to enable DiscordLogs // Webhook on sv_bansystem.lua
botColor = "6205745", -- https://www.mathsisfun.com/hexadecimal-decimal-colors.html
botName = "MSK Scripts",
botAvatar = "https://i.imgur.com/PizJGsh.png",

commands = {
enable = true,
groups = {'superadmin', 'admin', 'god'},
ban = 'banPlayer',
unbank = 'unbanPlayer'
}
}
4 changes: 2 additions & 2 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
fx_version 'adamant'
fx_version 'cerulean'
games { 'gta5' }

author 'Musiker15 - MSK Scripts'
name 'msk_core'
description 'Core functions for MSK Scripts'
version '2.0'
version '2.1.0'

lua54 'yes'

Expand Down
80 changes: 57 additions & 23 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
MSK = {}

local RegisteredCommands = {}

AddEventHandler('onResourceStart', function(resource)
if GetCurrentResourceName() ~= 'msk_core' then
print('^1Please rename the Script to^3 msk_core^0!')
print('^1Server will be shutdown^0!')
Wait(250)
os.exit()
end
end)

if Config.Framework:match('esx') then
ESX = exports["es_extended"]:getSharedObject()
elseif Config.Framework:match('qbcore') then
QBCore = exports['qb-core']:GetCoreObject()
end

exports('getCoreObject', function()
return MSK
end)

local RegisteredCommands = {}
MSK.RegisterCommand = function(name, group, cb, console, framework, suggestion)
if type(name) == 'table' then
for k, v in ipairs(name) do
Expand Down Expand Up @@ -209,30 +203,70 @@ addChatSuggestions = function(name, suggestion)
end

GithubUpdater = function()
GetCurrentVersion = function()
return GetResourceMetadata( GetCurrentResourceName(), "version" )
local GetCurrentVersion = function()
return GetResourceMetadata(GetCurrentResourceName(), "version")
end

local isVersionIncluded = function(Versions, cVersion)
for k, v in pairs(Versions) do
if v.version == cVersion then
return true
end
end

return false
end

local CurrentVersion = GetCurrentVersion()
local resourceName = "^0[^2"..GetCurrentResourceName().."^0]"

if Config.VersionChecker then
PerformHttpRequest('https://raw.githubusercontent.com/MSK-Scripts/msk_core/main/VERSION', function(Error, NewestVersion, Header)
print("###############################")
if CurrentVersion == NewestVersion then
PerformHttpRequest('https://raw.githubusercontent.com/Musiker15/VERSIONS/main/Lib.json', function(errorCode, jsonString, headers)
if not jsonString then
print(resourceName .. '^1 Update Check failed ^3Please Update to the latest Version:^9 https://github.com/MSK-Scripts/msk_core/ ^0')
print(resourceName .. '^2 ✓ Resource loaded^0 - ^5Current Version: ^0' .. CurrentVersion)
return
end

local decoded = json.decode(jsonString)
local version = decoded[1].version

if CurrentVersion == version then
print(resourceName .. '^2 ✓ Resource is Up to Date^0 - ^5Current Version: ^2' .. CurrentVersion .. '^0')
elseif CurrentVersion ~= NewestVersion then
elseif CurrentVersion ~= version then
print(resourceName .. '^1 ✗ Resource Outdated. Please Update!^0 - ^5Current Version: ^1' .. CurrentVersion .. '^0')
print('^5Newest Version: ^2' .. NewestVersion .. '^0 - ^6Download here:^9 https://github.com/MSK-Scripts/msk_core/releases/tag/v'.. NewestVersion .. '^0')
print('^5Latest Version: ^2' .. version .. '^0 - ^6Download here:^9 https://github.com/MSK-Scripts/msk_core/releases/tag/v'.. version .. '^0')
print('')
for i=1, #decoded do
if decoded[i]['version'] == CurrentVersion then
break
elseif not isVersionIncluded(decoded, CurrentVersion) then
print('^1You are using an^3 UNSUPPORTED VERSION^1 of ^0' .. resourceName)
break
end

if decoded[i]['changelogs'] then
print('^3Changelogs v' .. decoded[i]['version'] .. '^0')

for _, c in ipairs(decoded[i]['changelogs']) do
print(c)
end
end
end
end
print("###############################")
end)
else
print(resourceName .. '^2 ✓ Resource loaded^0')
print(resourceName .. '^2 ✓ Resource loaded^0 - ^5Current Version: ^2' .. CurrentVersion .. '^0')
end
end
GithubUpdater()

exports('getCoreObject', function()
return MSK
end)
checkResourceName = function()
if GetCurrentResourceName() ~= 'msk_core' then
while true do
print('^1Please rename the Script to^3 msk_core^0!')
Wait(5000)
end
end
end
checkResourceName()
Loading

0 comments on commit 387f926

Please sign in to comment.