forked from jonnyboy0719/Cuberite-Portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportal_web.lua
66 lines (57 loc) · 1.48 KB
/
portal_web.lua
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
function HandleRequest_Portals(Request)
local Query = getQuery(Request.URL)
if Request.Method == 'POST' then
local params = Request.PostParams
local name = params['name']
local del = params['del']
local disable = params['disable']
if disable then
toggleDisable(disable)
end
if name then
saveNewPortal(name, params)
end
if del then
delPortal(del)
end
end
local path = StringSplit(Request.URL, "?")[1]
return renderGuiForm(DATA.portals, Query.edit, path)
end
function saveNewPortal(name, fields)
if not DATA.portals[name] then
DATA.portals[name] = {}
end
for key, val in pairs(fields) do
if key ~= "name" then
if key == 'target' then
DATA.portals[name][key] = StringSplit(val, ",")
else
DATA.portals[name][key] = val
end
end
end
end
function delPortal(portalName)
if DATA.portals[portalName] then
DATA.portals[portalName] = nil
end
end
function toggleDisable(portalName)
if portalName == "global_disable" then
DATA.all_portals_disabled = not DATA.all_portals_disabled
elseif DATA.portals[portalName] then
DATA.portals[portalName].disabled = not DATA.portals[portalName].disabled
end
end
function getQuery(url)
-- local <return vals here> = cUrlParser:Parse( url ) -- this did not work for some reason
local Query = StringSplit(url, '?')[2]
local querySplit = StringSplit(Query, '&')
local query = {}
for i, val in pairs(querySplit) do
local keyVal = StringSplit(val, '=')
query[keyVal[1]] = keyVal[2]
end
return query
end