Skip to content

Commit 387f926

Browse files
committed
Update v2.1.0
* Added new VersionChecker * Added Config.customNotification * Integrated MSK Bansystem * Changes in Callbacks
1 parent bd652e6 commit 387f926

File tree

8 files changed

+390
-106
lines changed

8 files changed

+390
-106
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0
1+
2.1.0

client/cl_callback.lua

+33-45
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ local GenerateCallbackHandlerKey = function()
1111
end
1212
end
1313

14+
RegisterNetEvent("msk_core:client:callbackResponse", function(requestId, ...)
15+
if not CallbackHandler[requestId] then return end
16+
CallbackHandler[requestId] = {...}
17+
end)
18+
19+
RegisterNetEvent("msk_core:client:callbackNotFound", function(requestId)
20+
if not CallbackHandler[requestId] then return end
21+
CallbackHandler[requestId] = nil
22+
end)
23+
1424
----------------------------------------------------------------
15-
-- NEW Method for Client Callbacks
25+
-- Client Callbacks
1626
----------------------------------------------------------------
1727
MSK.Register = function(eventName, cb)
1828
Callbacks[eventName] = cb
@@ -33,7 +43,7 @@ RegisterNetEvent('msk_core:client:triggerClientCallback', function(playerId, eve
3343
end)
3444

3545
----------------------------------------------------------------
36-
-- NEW Method for Server Callbacks
46+
-- Server Callbacks with Method [return]
3747
----------------------------------------------------------------
3848
MSK.Trigger = function(eventName, ...)
3949
local requestId = GenerateCallbackHandlerKey()
@@ -45,7 +55,7 @@ MSK.Trigger = function(eventName, ...)
4555
p:reject(('Request Timed Out: [%s] [%s]'):format(eventName, requestId))
4656
end)
4757

48-
TriggerServerEvent('msk_core:server:triggerServerCallback', eventName, requestId, ...)
58+
TriggerServerEvent('msk_core:server:triggerCallback', eventName, requestId, false, ...)
4959

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

61-
RegisterNetEvent("msk_core:client:callbackResponse", function(requestId, ...)
62-
if not CallbackHandler[requestId] then return end
63-
CallbackHandler[requestId] = {...}
64-
end)
65-
66-
RegisterNetEvent("msk_core:client:callbackNotFound", function(requestId)
67-
if not CallbackHandler[requestId] then return end
68-
CallbackHandler[requestId] = nil
69-
end)
70-
7171
----------------------------------------------------------------
72-
-- OLD Method for Server Callbacks [OUTDATED - Do not use this!]
72+
-- Server Callbacks with Method [cb]
7373
----------------------------------------------------------------
74-
local callbackRequest = {}
75-
76-
local GenerateRequestKey = function()
77-
local requestId = math.random(1, 999999999)
78-
79-
if not callbackRequest[requestId] then
80-
return tostring(requestId)
81-
else
82-
GenerateRequestKey()
83-
end
84-
end
85-
86-
MSK.TriggerServerCallback = function(name, ...)
87-
local requestId = GenerateRequestKey()
88-
local response
74+
MSK.TriggerCallback = function(eventName, ...)
75+
local requestId = GenerateCallbackHandlerKey()
76+
local p = promise.new()
77+
CallbackHandler[requestId] = 'request'
8978

90-
callbackRequest[requestId] = function(...)
91-
response = {...}
92-
end
79+
SetTimeout(5000, function()
80+
CallbackHandler[requestId] = nil
81+
p:reject(('Request Timed Out: [%s] [%s]'):format(eventName, requestId))
82+
end)
83+
84+
TriggerServerEvent('msk_core:server:triggerCallback', eventName, requestId, true, ...)
9385

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

96-
while not response do Wait(0) end
89+
p:resolve(CallbackHandler[requestId])
90+
CallbackHandler[requestId] = nil
9791

98-
return table.unpack(response)
92+
local result = Citizen.Await(p)
93+
return table.unpack(result)
9994
end
100-
MSK.TriggerCallback = MSK.TriggerServerCallback
101-
exports('TriggerServerCallback', MSK.TriggerServerCallback)
102-
103-
RegisterNetEvent("msk_core:responseCallback")
104-
AddEventHandler("msk_core:responseCallback", function(requestId, ...)
105-
if callbackRequest[requestId] then
106-
callbackRequest[requestId](...)
107-
callbackRequest[requestId] = nil
108-
end
109-
end)
95+
MSK.TriggerServerCallback = MSK.TriggerCallback
96+
exports('TriggerCallback', MSK.TriggerCallback)
97+
exports('TriggerServerCallback', MSK.TriggerCallback)

client/main.lua

+6-4
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ elseif Config.Framework:match('qbcore') then
2929
end)
3030
end
3131

32+
exports('getCoreObject', function()
33+
return MSK
34+
end)
35+
3236
MSK.Notification = function(title, message, info, time)
3337
if Config.Notification == 'native' then
3438
SetNotificationTextEntry('STRING')
3539
AddTextComponentString(message)
3640
DrawNotification(false, true)
3741
elseif Config.Notification == 'okok' then
3842
exports['okokNotify']:Alert(title, message, time or 5000, info or 'info')
43+
elseif Config.Notification == 'custom' then
44+
Config.customNotification()
3945
else
4046
SendNUIMessage({
4147
action = 'notify',
@@ -148,8 +154,4 @@ end)
148154
RegisterNetEvent('msk_core:advancedNotification')
149155
AddEventHandler('msk_core:advancedNotification', function(text, title, subtitle, icon, flash, icontype)
150156
MSK.AdvancedNotification(text, title, subtitle, icon, flash, icontype)
151-
end)
152-
153-
exports('getCoreObject', function()
154-
return MSK
155157
end)

config.lua

+27-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ Config = {}
33
Config.Debug = false
44
Config.VersionChecker = true
55
----------------------------------------------------------------
6-
-- Only Required for MSK.RegisterCommand // View Wiki for more Information about that!
6+
-- Only Required for MSK.RegisterCommand and MSK.HasItem // View Docu for more Information about that!
77
Config.Framework = 'esx' -- Set to 'standalone', 'esx' or 'qbcore'
88
----------------------------------------------------------------
9+
-- /coords
910
Config.showCoords = {
1011
enable = true,
1112
command = 'coords',
@@ -15,8 +16,14 @@ Config.showCoords = {
1516
-- Set to 'native' for FiveM Native Notification
1617
-- Set to 'msk' for NUI Notification
1718
-- Set to 'okok' for OKOK Notification
19+
-- Set to 'custom' for Config.customNotification()
1820
Config.Notification = 'msk'
1921

22+
Config.customNotification = function()
23+
-- Set Config.Notification = 'custom'
24+
-- Add your own clientside Notification here
25+
end
26+
2027
Config.progressColor = "#5eb131" -- Default Color for ProgressBar
2128
----------------------------------------------------------------
2229
Config.LoggingTypes = {
@@ -28,16 +35,33 @@ Config.LoggingTypes = {
2835
Config.AntiCombatlog = {
2936
enable = false, -- Set to true if you want to use this Feature
3037
console = {
31-
enable = true,
38+
enable = false,
3239
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"
3340
},
3441
discord = {
3542
-- Webhook in sv_anticombatlog.lua
36-
enable = true,
43+
enable = false,
3744
color = "6205745", -- https://www.mathsisfun.com/hexadecimal-decimal-colors.html
3845
botName = "MSK Scripts",
3946
botAvatar = "https://i.imgur.com/PizJGsh.png",
4047
title = "Player Disconnected",
4148
text = "Der Spieler **%s** mit der **ID %s** hat den Server verlassen."
4249
}
50+
}
51+
----------------------------------------------------------------
52+
-- For more Information go to: https://github.com/MSK-Scripts/msk_bansystem/blob/main/README.md
53+
Config.BanSystem = {
54+
enable = false, -- Set to true if you want to use this Feature
55+
56+
discordLog = false, -- Set true to enable DiscordLogs // Webhook on sv_bansystem.lua
57+
botColor = "6205745", -- https://www.mathsisfun.com/hexadecimal-decimal-colors.html
58+
botName = "MSK Scripts",
59+
botAvatar = "https://i.imgur.com/PizJGsh.png",
60+
61+
commands = {
62+
enable = true,
63+
groups = {'superadmin', 'admin', 'god'},
64+
ban = 'banPlayer',
65+
unbank = 'unbanPlayer'
66+
}
4367
}

fxmanifest.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
fx_version 'adamant'
1+
fx_version 'cerulean'
22
games { 'gta5' }
33

44
author 'Musiker15 - MSK Scripts'
55
name 'msk_core'
66
description 'Core functions for MSK Scripts'
7-
version '2.0'
7+
version '2.1.0'
88

99
lua54 'yes'
1010

server/main.lua

+57-23
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
MSK = {}
22

3-
local RegisteredCommands = {}
4-
5-
AddEventHandler('onResourceStart', function(resource)
6-
if GetCurrentResourceName() ~= 'msk_core' then
7-
print('^1Please rename the Script to^3 msk_core^0!')
8-
print('^1Server will be shutdown^0!')
9-
Wait(250)
10-
os.exit()
11-
end
12-
end)
13-
143
if Config.Framework:match('esx') then
154
ESX = exports["es_extended"]:getSharedObject()
165
elseif Config.Framework:match('qbcore') then
176
QBCore = exports['qb-core']:GetCoreObject()
187
end
198

9+
exports('getCoreObject', function()
10+
return MSK
11+
end)
12+
13+
local RegisteredCommands = {}
2014
MSK.RegisterCommand = function(name, group, cb, console, framework, suggestion)
2115
if type(name) == 'table' then
2216
for k, v in ipairs(name) do
@@ -209,30 +203,70 @@ addChatSuggestions = function(name, suggestion)
209203
end
210204

211205
GithubUpdater = function()
212-
GetCurrentVersion = function()
213-
return GetResourceMetadata( GetCurrentResourceName(), "version" )
206+
local GetCurrentVersion = function()
207+
return GetResourceMetadata(GetCurrentResourceName(), "version")
214208
end
209+
210+
local isVersionIncluded = function(Versions, cVersion)
211+
for k, v in pairs(Versions) do
212+
if v.version == cVersion then
213+
return true
214+
end
215+
end
216+
217+
return false
218+
end
215219

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

219223
if Config.VersionChecker then
220-
PerformHttpRequest('https://raw.githubusercontent.com/MSK-Scripts/msk_core/main/VERSION', function(Error, NewestVersion, Header)
221-
print("###############################")
222-
if CurrentVersion == NewestVersion then
224+
PerformHttpRequest('https://raw.githubusercontent.com/Musiker15/VERSIONS/main/Lib.json', function(errorCode, jsonString, headers)
225+
if not jsonString then
226+
print(resourceName .. '^1 Update Check failed ^3Please Update to the latest Version:^9 https://github.com/MSK-Scripts/msk_core/ ^0')
227+
print(resourceName .. '^2 ✓ Resource loaded^0 - ^5Current Version: ^0' .. CurrentVersion)
228+
return
229+
end
230+
231+
local decoded = json.decode(jsonString)
232+
local version = decoded[1].version
233+
234+
if CurrentVersion == version then
223235
print(resourceName .. '^2 ✓ Resource is Up to Date^0 - ^5Current Version: ^2' .. CurrentVersion .. '^0')
224-
elseif CurrentVersion ~= NewestVersion then
236+
elseif CurrentVersion ~= version then
225237
print(resourceName .. '^1 ✗ Resource Outdated. Please Update!^0 - ^5Current Version: ^1' .. CurrentVersion .. '^0')
226-
print('^5Newest Version: ^2' .. NewestVersion .. '^0 - ^6Download here:^9 https://github.com/MSK-Scripts/msk_core/releases/tag/v'.. NewestVersion .. '^0')
238+
print('^5Latest Version: ^2' .. version .. '^0 - ^6Download here:^9 https://github.com/MSK-Scripts/msk_core/releases/tag/v'.. version .. '^0')
239+
print('')
240+
for i=1, #decoded do
241+
if decoded[i]['version'] == CurrentVersion then
242+
break
243+
elseif not isVersionIncluded(decoded, CurrentVersion) then
244+
print('^1You are using an^3 UNSUPPORTED VERSION^1 of ^0' .. resourceName)
245+
break
246+
end
247+
248+
if decoded[i]['changelogs'] then
249+
print('^3Changelogs v' .. decoded[i]['version'] .. '^0')
250+
251+
for _, c in ipairs(decoded[i]['changelogs']) do
252+
print(c)
253+
end
254+
end
255+
end
227256
end
228-
print("###############################")
229257
end)
230258
else
231-
print(resourceName .. '^2 ✓ Resource loaded^0')
259+
print(resourceName .. '^2 ✓ Resource loaded^0 - ^5Current Version: ^2' .. CurrentVersion .. '^0')
232260
end
233261
end
234262
GithubUpdater()
235263

236-
exports('getCoreObject', function()
237-
return MSK
238-
end)
264+
checkResourceName = function()
265+
if GetCurrentResourceName() ~= 'msk_core' then
266+
while true do
267+
print('^1Please rename the Script to^3 msk_core^0!')
268+
Wait(5000)
269+
end
270+
end
271+
end
272+
checkResourceName()

0 commit comments

Comments
 (0)