forked from thisdp/dgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
72 lines (66 loc) · 2.4 KB
/
server.lua
File metadata and controls
72 lines (66 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-----------Config Loader
dgsConfig = {}
dgsConfig.updateCheck = true -- Enable:true;Disable:false
dgsConfig.updateCheckInterval = 120 -- Minutes
dgsConfig.updateCheckNoticeInterval = 120 -- Minutes
dgsConfig.updateSystemDisabled = false -- Minutes
dgsConfig.backupMeta = true -- Backup meta.xml
dgsConfig.backupStyleMeta = true -- Backup style files meta index from meta.xml
dgsConfig.g2d = true -- GUI To DGS command line
function loadConfig()
if fileExists("config.txt") then
local file = fileOpen("config.txt")
if file then
local str = fileRead(file,fileGetSize(file))
fileClose(file)
local fnc = loadstring(str)
if fnc then
fnc()
outputDebugString("[DGS]Config File Loaded!")
else
outputDebugString("[DGS]Invaild Config File!",2)
end
else
outputDebugString("[DGS]Invaild Config File!",2)
end
end
if dgsConfig.g2d then
outputDebugString("[DGS]G2D is enabled!")
end
--Regenerate config file
local file = fileCreate("config.txt")
local str = ""
for k,v in pairs(dgsConfig) do
local value = type(v) == "string" and '"'..v..'"' or tostring(v)
str = str.."\r\ndgsConfig."..k.." = "..value
end
fileWrite(file,str:sub(3))
fileClose(file)
end
loadConfig()
-----------Remote Stuff
addEvent("DGSI_RequestQRCode",true)
addEvent("DGSI_RequestIP",true)
addEvent("DGSI_RequestRemoteImage",true)
addEvent("DGSI_RequestAboutData",true)
addEventHandler("DGSI_RequestQRCode",resourceRoot,function(str,w,h,id)
fetchRemote("https://api.qrserver.com/v1/create-qr-code/?size="..w.."x"..h.."&data="..str,{},function(data,info,player,id)
triggerClientEvent(player,"DGSI_ReceiveQRCode",resourceRoot,data,info.success,id)
end,{client,id})
end)
addEventHandler("DGSI_RequestRemoteImage",resourceRoot,function(website,id)
fetchRemote(website,{},function(data,info,player,id)
triggerClientEvent(player,"DGSI_ReceiveRemoteImage",resourceRoot,data,info,id)
end,{client,id})
end)
function getMyIP()
triggerClientEvent(client,"DGSI_ReceiveIP",resourceRoot,getPlayerIP(client))
end
addEventHandler("DGSI_RequestIP",resourceRoot,getMyIP)
setElementData(root,"DGS-ResName",getResourceName(getThisResource()))
-----------About DGS
addEventHandler("DGSI_RequestAboutData",resourceRoot,function()
fetchRemote("https://raw.githubusercontent.com/thisdp/dgs/master/README.md",{},function(data,info,player)
triggerClientEvent(player,"DGSI_SendAboutData",resourceRoot,data)
end,{client})
end)