This repository was archived by the owner on Dec 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathServer_Compiler.lua
More file actions
409 lines (324 loc) · 9.6 KB
/
Server_Compiler.lua
File metadata and controls
409 lines (324 loc) · 9.6 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
--[[
Server Compiler
Dep: <ModuleScript> Report
DONT TOUCH OR >>RIOT<<
Made by
AdjacentPhoenix
]]
local Tags = {
["Critical"] = {};
["Regular"] = {};
["Minor"] = {};
["Resetable"] = {};
}
local Settings = {
DataStore = "QSERF_Server_Data";
Version = "2.001";
Debug = true;
Levels = {
["Critical"] = "EMERGENCY";
["Regular"] = "ERROR";
["Minor"] = "MINOR";
};
}
if Settings.Debug == true then
warn("Begin Server Load")
end
local Logs = {Errors = {}; Scripts = {};}
local Report = require(script.Report)
local Service = {
["Workspace"] = game:GetService("Workspace");
["workspace"] = game:GetService("Workspace");
["Lighting"] = game:GetService("Lighting");
["ServerStorage"] = game:GetService("ServerStorage");
["ReplicatedStorage"] = game:GetService("ReplicatedStorage");
["Players"] = game:GetService("Players");
["Chat"] = game:GetService("Chat");
["CollectionService"] = game:GetService("CollectionService");
["RunService"] = game:GetService("RunService");
["Run Service"] = game:GetService("RunService");
["ServerScriptService"] = game:GetService("ServerScriptService");
["HttpService"] = game:GetService("HttpService");
["DataStoreService"] = game:GetService("DataStoreService");
["DataStore"] = game:GetService("DataStoreService");
["ScriptContext"] = game:GetService("ScriptContext");
}
--//-SCRIPT-CONSTANTS-\\--
local OrgPrint = print
local OrgWarn = warn
local OrgError = error
--\\------------------//--
--//-SCRIPT-FUNCTIONS-\\--
local GetTagged = function(Script)
local Return = {Level = "N/A"; Tags = {};}
--// Critical
if Tags.Critical[Script] ~= nil then
Return.Level = "Critical"
end
--// Regular
if Tags.Regular[Script] ~= nil then
Return.Level = "Regular"
end
--// Minor
if Tags.Minor[Script] ~= nil then
Return.Level = "Minor"
end
--// Resetable
if Tags.Resetable[Script] ~= nil then
Return.Tags["Resetable"] = "Resetable"
end
return Return
end
local CloneTable = function(Table)
local NewTable = {}
for Index, Value in pairs(Table) do
NewTable[Index] = Value
end
return NewTable
end
local Pcall = function(Critical, Function, ...)
local Args = {...}
local Ran, Error = pcall(function()
Function(unpack(Args))
end)
if Error then
Logs.Errors[#Logs.Errors + 1] = Error
if Critical == true then
Report.Push.Message(script, "EMERGENCY", Error)
else
Report.Push.Message(script, "ERROR", Error)
end
end
end
--\\------------------//--
--// \/ OVERRIDE SCRIPT FUNCTION GLOBALS DOWN HERE \/ \\--
local print = function(...)
for Index, Value in pairs({...}) do
if Settings.Debug == true then
OrgPrint("[".. getfenv(2).script.Name .."]: ".. tostring(Value))
end
end
end
local warn = function(...)
for Index, Value in pairs({...}) do
OrgWarn("[".. getfenv(2).script.Name .."]: ".. tostring(Value))
end
end
local error = function(...)
for Index, Value in pairs({...}) do
OrgError("[".. getfenv(2).script.Name .."]: ".. tostring(Value))
end
end
--------------------------------------------------------
local Env = {
Report = Report, Service = Service, _G = _G, game = game, getfenv = getfenv, setfenv = setfenv,
getmetatable = getmetatable, setmetatable = setmetatable, coroutine = coroutine,
rawequal = rawequal, typeof = typeof, print = print, math = math, warn = warn,
error = error, pcall = pcall, xpcall = xpcall, rawset = rawset, rawget = rawget,
ipairs = ipairs, pairs = pairs, next = next, Rect = Rect, Axes = Axes, os = os,
tick = tick, Faces = Faces, unpack = unpack, string = string, Color3 = Color3,
newproxy = newproxy, tostring = tostring, tonumber = tonumber, Instance = Instance,
TweenInfo = TweenInfo, BrickColor = BrickColor, NumberRange = NumberRange,
ColorSequence = ColorSequence, NumberSequence = NumberSequence,
ColorSequenceKeypoint = ColorSequenceKeypoint, NumberSequenceKeypoint = NumberSequenceKeypoint,
PhysicalProperties = PhysicalProperties, Region3int16 = Region3int16, Vector3int16 = Vector3int16,
elapsedTime = elapsedTime, require = require, table = table, type = type, wait = wait,
Enum = Enum, UDim = UDim, UDim2 = UDim2, Vector2 = Vector2, Vector3 = Vector3,
Region3 = Region3, CFrame = CFrame, Ray = Ray, Random = Random, spawn = spawn
};
local TagList = {
["Critical"] = "High";
["Regular"] = "Med";
["Minor"] = "Low";
};
local SetEnv = function(Function, Extra, Additional)
local OrgFuncEnv = getfenv(Function)
local Table = nil
if Extra then
Table = OrgFuncEnv.RESET
end
local Reset
if Table ~= nil then
Reset = CloneTable(Table)
end
setfenv(Function, setmetatable({},{
__index = function(Self, Index)
if Table ~= nil then
if Table[Index] ~= nil then
return Extra[Index]
elseif Index == "RESETSCRIPTENV" then
for Index, Value in pairs(Reset) do
Table[Index] = Value
end
return function() return "RESET" end
end
end
if Additional ~= nil then
if Additional[Index] ~= nil then
return Additional[Index]
end
end
if Env[Index] ~= nil then
return Env[Index]
else
return OrgFuncEnv[Index]
end
end;
__newindex = function(Self, Index, Key)
Table[Index] = Key
end;
__metatable = {};
}))
end
local GetFunctions = function(Return)
local Functions = {}
local GetTable; GetTable = function(Table)
for Index, Value in pairs(Table) do
if type(Value) == "table" then
GetTable(Value)
elseif type(Value) == "function" then
Functions[#Functions + 1] = Value
end
end
end
if type(Return) == "table" then
for Index, Value in pairs(Return) do
if type(Value) == "table" then
GetTable(Value)
elseif type(Value) == "function" then
Functions[#Functions + 1] = Value
end
end
else
Functions[#Functions + 1] = Return
end
return Functions
end
local Run = function(Module, Function)
local Ran, Error = pcall(Function)
if Error then
Report.Push.Message(Module, Settings.Levels[GetTagged(Module).Level], Error)
OrgWarn("[GAME]: Script ".. tostring(Module.Name) .." ERROR | ".. tostring(Error))
else
OrgPrint("[GAME]: Script ".. tostring(Module.Name) .. " Ran without error")
end
end
local LoadModuleScript = function(Module)
Logs.Scripts[#Logs.Scripts + 1] = Module
local Tags = GetTagged(Module)
local Functions = GetFunctions(require(Module))
for Index, Function in pairs(Functions) do
if Tags.Tags.Resetable ~= nil then
SetEnv(Function, true)
else
SetEnv(Function)
end
end
for Index, Function in pairs(Functions) do
spawn(function() Run(Module, Function) end)
end
end
local LoadScript = function(Script)
Logs.Scripts[#Logs.Scripts + 1] = Script
Script.Disabled = false
end
local Game_Version = function()
local DataStoreService = Service.DataStore
local ServerData = DataStoreService:GetDataStore(Settings.DataStore)
local Version = ServerData:GetAsync("Version")
--// Check if we can get it from the Datastore or Reset
if Version == nil then
Version = Settings.Version
end
--// Fix it if it goes into a float value (IDK Why)
if string.len(tostring(Version)) > 5 then
local Fixed = string.sub(tostring(Version), 1, 5)
if tonumber(Fixed) ~= nil then
Version = tonumber(Fixed)
else
Version = Settings.Version
end
end
--// Increase it if it's Studio
if Service.RunService:IsStudio() == true then
Version = Version + 0.001
ServerData:SetAsync("Version", Version)
end
--// Client Get Version
local GetVersionClient = Instance.new("RemoteFunction")
GetVersionClient.Name = "Get_Game_Version"
GetVersionClient.OnServerInvoke = function()
return Version
end
--GetVersionClient.Parent = game:GetService("ReplicatedStorage").Game.Events.Misc
Settings.Version = Version
_G.Version = Version
end
local Unpackage = function()
for Index, Module in pairs(Service.CollectionService:GetTagged("Env")) do
Pcall(true, function()
Env[Module.Name] = require(Module)
end)
end
end
local CompileTaggedData = function()
for Index, Tag in pairs(Tags) do
for In, TagToSet in pairs(Service.CollectionService:GetTagged(Index)) do
Tag[TagToSet] = TagToSet
end
end
end
local Load = function()
for Index, Script in pairs(Service.CollectionService:GetTagged("Critical")) do
if Script.ClassName == "ModuleScript" then
LoadModuleScript(Script)
else
LoadScript(Script)
end
end
for Index, Script in pairs(Service.CollectionService:GetTagged("Regular")) do
if Script.ClassName == "ModuleScript" then
LoadModuleScript(Script)
else
LoadScript(Script)
end
end
for Index, Script in pairs(Service.CollectionService:GetTagged("Minor")) do
if Script.ClassName == "ModuleScript" then
LoadModuleScript(Script)
else
LoadScript(Script)
end
end
end
local Events = function()
game.Close:Connect(function()
Report.Push.Close()
end)
--// If a tagged script is a Script and not a Module Script
local Logged = {}
Service.ScriptContext.Error:Connect(function(MESSAGE, STACK, SCRIPT)
local Tags = GetTagged(SCRIPT)
if Tags.Level ~= "N/A" and Logged[MESSAGE] == nil then
Logged[MESSAGE] = MESSAGE
Logs.Errors[#Logs.Errors + 1] = MESSAGE
Report.Push.Message(SCRIPT, Settings.Levels[Tags.Level], MESSAGE)
end
end)
end
--// Init the Server
local Init = function()
print("Init Called!")
local Message = Instance.new("Message")
Message.Parent = game:GetService("Workspace")
Message.Text = "Server is starting, please wait!"
Pcall(false, Game_Version)
Report.Push.Load(Settings.Version)
Pcall(true, CompileTaggedData)
Pcall(false, Events)
Pcall(true, Unpackage)
Pcall(true, Load)
OrgWarn("[GAME]: Loaded | Server Version: ".. Settings.Version .. " | Errors: ".. tostring(#Logs.Errors).. " | Scripts ".. tostring(#Logs.Scripts))
Message:Destroy()
end
Pcall(true, Init)