-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
executable file
·104 lines (91 loc) · 4.02 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
--[[
Config generator by Mr0maks and ProfessorBrain for GG Project servers
You are free to use it with this License: https://www.gnu.org/licenses/gpl-3.0.en.html
]]
local http = require('http')
local json = require('json')
local temp = io.open("config.json", "r")
local config = json.decode(temp:read("*a"))
temp:close()
local postdata_backup = {
['token'] = config.backend.token,
['account_type'] = "steam64id",
}
local options_backup = {
host = config.backend.host,
port = config.backend.port,
path = '/api/privilege/get_with_link',
method = 'POST',
headers = {
['Content-Type'] = 'application/json',
}
}
for _, server in pairs(config.servers) do
if server.disabled == 1 then return end
local postdata = postdata_backup
postdata.server = server.name
postdata = json.encode(postdata)
local options = options_backup
options["headers"]["Content-Length"] = #postdata
local req = http.request(options, function(res)
local buffer = {}
local string_buffer = nil
-- p("on_connect", {statusCode = res.statusCode, headers = res.headers})
res:on('data', function (chunk)
-- p("on_data", {chunk=chunk, len = #chunk})
table.insert( buffer, chunk )
end)
res:on("end", function ()
-- p(buffer)
string_buffer = table.concat( buffer )
-- p(string_buffer)
local result = json.decode(string_buffer)['data']
p(result)
local privileges = {}
local reserved_slots = {}
table.insert(privileges, os.date("#GENERATE DATE: %x at %X MSK\n#THIS CONFIG IS AUTOGENERATED! DONT MODIFY IT!\n#CONFIG GENERATOR AUTHORS - Mr0maks, ProfessorBrain\nMembers:\n"))
table.insert(reserved_slots, os.date("#GENERATE DATE: %x at %X MSK\n#THIS CONFIG IS AUTOGENERATED! DONT MODIFY IT!\n#CONFIG GENERATOR AUTHOR - ProfessorBrain\n"))
local got_priority_roles = {}
for i=1, #result do
for k, v in pairs(server.priority_roles) do
if result[i].privilege == v then
if result[i].account == nil then
table.insert(privileges, string.format('#%s\n - %s@discord: %s\n', result[i].userid, result[i].userid, result[i].privilege))
else
table.insert(privileges, string.format('#%s\n - %s@steam: %s\n', result[i].userid, result[i].account, result[i].privilege))
table.insert(privileges, string.format('#%s\n - %s@discord: %s\n', result[i].userid, result[i].userid, result[i].privilege))
end
got_priority_roles[result[i].userid] = true
end
end
end
for i=1, #result do
if got_priority_roles[result[i].userid] ~= true and result[i].privilege ~= 'reserved_slot' then
if result[i].account == nil then
table.insert(privileges, string.format('#%s\n - %s@discord: %s\n', result[i].userid, result[i].userid, result[i].privilege))
else
table.insert(privileges, string.format('#%s\n - %s@steam: %s\n', result[i].userid, result[i].account, result[i].privilege))
table.insert(privileges, string.format('#%s\n - %s@discord: %s\n', result[i].userid, result[i].userid, result[i].privilege))
end
end
if result[i].privilege == 'reserved_slot' then
if result[i].account == nil then
table.insert(reserved_slots, string.format('#%s\n%s@discord\n', result[i].userid, result[i].userid))
else
table.insert(reserved_slots, string.format('#%s\n%s@steam\n', result[i].userid, result[i].account))
table.insert(reserved_slots, string.format('#%s\n%s@discord\n', result[i].userid, result[i].userid))
end
end
end
local config_path = "config/"..server.endport.."/"
local admin_config = io.open(config_path.."config_remoteadmin.txt", "w")
admin_config:write(table.concat(privileges)):write('\n')
local admin_config_settings = io.open(server.endport.."-admin_config_settings.txt", "r")
admin_config:write(admin_config_settings:read("*a")):close()
admin_config_settings:close()
io.open(config_path.."UserIDReservedSlots.txt", "w"):write(table.concat(reserved_slots)):close()
end)
end)
req:done(postdata)
-- p(req)
end