-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgameserver.lua
More file actions
635 lines (540 loc) · 18.9 KB
/
Copy pathgameserver.lua
File metadata and controls
635 lines (540 loc) · 18.9 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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
-- Start Game Script Arguments
local placeId, port, sleeptime, timeout, domain, libraryRegistrationScriptAssetID, universeId, protocol, jobId, testing =
{requestId}, {port}, 10, 10, "{domain}", 37801172, {universeId}, "http://", "{jobId}", false
-----------------------------------"CUSTOM" SHARED CODE----------------------------------
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
pcall(function() settings().Network.UseInstancePacketCache = true end)
pcall(function() settings().Network.UsePhysicsPacketCache = true end)
pcall(function() settings()["Task Scheduler"].PriorityMethod = Enum.PriorityMethod.AccumulatedError end)
settings().Network.PhysicsSend = Enum.PhysicsSendMethod.TopNErrors
settings().Network.ExperimentalPhysicsEnabled = true
settings().Network.WaitingForCharacterLogRate = 100
pcall(function() settings().Diagnostics:LegacyScriptMode() end)
local shuttingDown = false
local shouldCountDown = true
local countdownTimer = 15
local commands = {";ec", ";cock", ";raymonf", ";gage", ";minecraft", ";suicide", ";energycell", ";cancer", ";bleach", ";sex", ";kms", ";death", ";robloxsuckingpenis", ";korone", ";austiblox", ";pekora", ";liam", ";amir", ";brickplanet", ";polytoriacrashed", ";wm"}
local retroSound = 453
local elivSound = 255
local ecSounds = {63,66,68,252,253,254,451,452}
local function onChatted(msg, speaker)
msg = string.lower(msg)
local character = speaker.Character
if not character then return end
local humanoid = character:FindFirstChild("Humanoid")
local head = character:FindFirstChild("Head")
if not humanoid or not head then return end
if msg == "!rejoin" then
spawn(function()
wait(0.2)
TeleportService:Teleport(game.PlaceId, speaker)
end)
return
end
if msg == "!!!reset" then
humanoid.Health = 0
return
end
for i = 1, #commands do
if msg == commands[i] and humanoid.Health > 0 then
humanoid.Health = 0
local sound = Instance.new("Sound")
sound.Parent = head
sound.SoundId = protocol .. domain .. "/asset/?id=" .. ecSounds[math.random(1, #ecSounds)]
wait(0.2)
sound:Play()
end
end
if msg == ";eliv" and humanoid.Health > 0 then
humanoid.Health = 0
local sound = Instance.new("Sound")
sound.Parent = head
sound.SoundId = protocol .. domain .. "/asset/?id=" .. elivSound
wait(0.2)
sound:Play()
end
if msg == "retro" and humanoid.Health > 0 then
humanoid.Health = 0
local sound = Instance.new("Sound")
sound.Parent = head
sound.SoundId = protocol .. domain .. "/asset/?id=" .. retroSound
wait(0.2)
sound:Play()
end
if game:GetService("Players").ArbysChibkenEnabled then
if msg == "arbys chibken" then
local sound = Instance.new("Sound")
sound.SoundId = "arlassetid://256"
sound.Volume = 0.5
sound.Parent = character:WaitForChild("Head")
sound:Play()
wait(2)
local torso = character:FindFirstChild("Torso")
if torso then
local explosion = Instance.new("Explosion")
explosion.Position = torso.Position
explosion.Parent = workspace
end
end
end
end
Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(msg)
onChatted(msg, player)
end)
end)
if (placeId == 3724) then
warn("Testing enabled")
testing = true
end
local function waitForAccoutrement(character)
local tries = 0
while tries < 20 do
local hasAccoutrement = false
for _, child in ipairs(character:GetChildren()) do
if child:IsA("Accoutrement") then
hasAccoutrement = true
break
end
end
if hasAccoutrement then
break
end
wait(0.05)
tries += 1
end
end
local function waitForClothing(character)
local tries = 0
while tries < 20 do
local hasClothing = false
for _, child in ipairs(character:GetChildren()) do
if child:IsA("Shirt") or child:IsA("Pants") or child:IsA("ShirtGraphic") then
hasClothing = true
break
end
end
if hasClothing then
break
end
wait(0.05)
tries += 1
end
end
-----------------------------------START GAME SHARED SCRIPT------------------------------
local assetId = placeId -- might be able to remove this now
local url = nil
local saveUrl = nil
local whitelist = {
1,
43,
62
}
if domain~=nil and protocol ~= nil then
url = protocol .. domain
saveUrl = url .. "/Data/Upload.ashx?assetid=" .. placeId
end
local scriptContext = game:GetService('ScriptContext')
pcall(function() scriptContext:AddStarterScript(libraryRegistrationScriptAssetID) end)
scriptContext.ScriptsDisabled = true
game:SetPlaceID(assetId, false)
pcall(function () if universeId ~= nil then game:SetUniverseId(universeId) end end)
game:GetService("ChangeHistoryService"):SetEnabled(false)
function GetAsync(url)
url = HttpRbx .. url
local response, result = pcall(function()
game:HttpGet(url)
end)
wait()
if response then
return response
else
return warn(result)
end
end
function PostAsync(url, data, contentType)
contentType = contentType or "application/x-www-form-urlencoded"
if type(data) == "table" then
local str = ""
for k, v in pairs(data) do
if str ~= "" then
str = str .. "&"
end
str = str .. tostring(k) .. "=" .. tostring(v)
end
data = str
end
local ok, response = pcall(function()
return game:GetService("HttpRbxApiService"):PostAsync(url, data, contentType)
end)
wait()
if ok and response and response ~= "" then
return response
else
if not ok then
warn(response)
elseif response == "" then
warn("Empty response returned")
end
return nil
end
end
-- establish this peer as the Server
local ns = game:GetService("NetworkServer")
-- Detect cloud edit mode by checking bool from arbiter
local isCloudEdit = {teamcreate}
-- Configure CloudEdit saving after place has been loaded
if isCloudEdit then
if testing then
warn("Configuring as CloudEdit Server")
end
local doPeriodicSaves = true
local delayBetweenSavesSeconds = 5 * 60 -- 5 minutes
local function periodicSave()
if doPeriodicSaves then
warn("Saving place!")
local response, result = pcall(function() game:Save(saveUrl) end)
if not response then
warn(result)
end
delay(delayBetweenSavesSeconds, periodicSave)
end
end
-- Spawn thread to save in the future
delay(delayBetweenSavesSeconds, periodicSave)
-- Hook into OnClose to save on shutdown
game.OnClose = function()
doPeriodicSaves = false
warn("Saving place!")
local response, result = pcall(function() game:Save(saveUrl) end)
if not response then
warn(result)
end
-- yield so that file save happens in the heartbeat thread
wait()
end
ns:ConfigureAsCloudEditServer()
else
game.OnClose = function()
warn("Server is shutting down!")
game:HttpGet(url .. "/api/gameservers/close?jobID="..jobId)
end
end
local badgeUrlFlagExists, badgeUrlFlagValue = pcall(function () return settings():GetFFlag("NewBadgeServiceUrlEnabled") end)
local newBadgeUrlEnabled = badgeUrlFlagExists and badgeUrlFlagValue
if url~=nil then
if testing then
warn("Loading NetworkServer and data")
end
pcall(function() game:GetService("Players"):SetAbuseReportUrl(url .. "/AbuseReport/InGameChatHandler.ashx") end)
pcall(function() game:GetService("ScriptInformationProvider"):SetAssetUrl(url .. "/Asset/") end)
pcall(function() game:GetService("ContentProvider"):SetBaseUrl(url .. "/") end)
pcall(function() game:GetService("Players"):SetChatFilterUrl(url .. "/Game/ChatFilter.ashx") end)
if gameCode then
game:SetVIPServerId(tostring(gameCode))
end
game:GetService("BadgeService"):SetPlaceId(placeId)
if newBadgeUrlEnabled then
game:GetService("BadgeService"):SetAwardBadgeUrl(url .. "/assets/award-badge?userId=%d&badgeId=%d&placeId=%d")
end
if not newBadgeUrlEnabled then
game:GetService("BadgeService"):SetAwardBadgeUrl(url .. "/Game/Badge/AwardBadge.ashx?UserID=%d&BadgeID=%d&PlaceID=%d")
end
game:GetService("BadgeService"):SetHasBadgeUrl(url .. "/Game/Badge/HasBadge.ashx?UserID=%d&BadgeID=%d")
game:GetService("BadgeService"):SetIsBadgeDisabledUrl(url .. "/Game/Badge/IsBadgeDisabled.ashx?BadgeID=%d&PlaceID=%d")
game:GetService("FriendService"):SetMakeFriendUrl(url .. "/Game/CreateFriend?firstUserId=%d&secondUserId=%d")
game:GetService("FriendService"):SetBreakFriendUrl(url .. "/Game/BreakFriend?firstUserId=%d&secondUserId=%d")
game:GetService("FriendService"):SetGetFriendsUrl(url .. "/Game/AreFriends?userId=%d")
game:GetService("BadgeService"):SetIsBadgeLegalUrl("")
game:GetService("InsertService"):SetBaseSetsUrl(url .. "/Game/Tools/InsertAsset.ashx?nsets=10&type=base")
game:GetService("InsertService"):SetUserSetsUrl(url .. "/Game/Tools/InsertAsset.ashx?nsets=20&type=user&userid=%d")
game:GetService("InsertService"):SetCollectionUrl(url .. "/Game/Tools/InsertAsset.ashx?sid=%d")
game:GetService("InsertService"):SetAssetUrl(url .. "/Asset/?id=%d")
game:GetService("InsertService"):SetAssetVersionUrl(url .. "/Asset/?assetversionid=%d")
if gameCode then
pcall(function() loadfile(url .. "/Game/LoadPlaceInfo.slua?PlaceId=" .. placeId .. "&gameCode=" .. tostring(gameCode))() end)
else
pcall(function() loadfile(url .. "/Game/LoadPlaceInfo.slua?PlaceId=" .. placeId)() end)
end
pcall(function() loadfile(url .. "/Game/PlaceSpecificScript.slua?PlaceId=" .. placeId)() end)
end
pcall(function() game:GetService("NetworkServer"):SetIsPlayerAuthenticationRequired(false) end)
settings().Diagnostics.LuaRamLimit = 0
game:GetService("Players").PlayerAdded:connect(function(player)
shouldCountDown = false
if url and placeId and player and player.userId then
print("Player " .. player.userId .. " added")
local userid = string.gsub(tostring(player.userId), "%-", "")
userid = string.gsub(tostring(player.userId), "-", "")
player.CharacterAppearance = "http://{domain}/Asset/CharacterFetch.ashx?userId=" .. userid .. "&placeId=" .. placeId
if testing then
local allowed = false
for _, id in ipairs(whitelist) do
if player.UserId == id then
allowed = true
break
end
end
if not allowed then
return player:Kick("You cannot join this server because this game is private.")
end
end
-- the fuck?
local didTeleportIn = "False"
if player.TeleportedIn then didTeleportIn = "True" end
if testing then
warn("Validating " .. player.Name)
end
local playerResult = game:HttpGet(url .. "/api/gameservers/validateplayer?jobID="..jobId.."&userID=" .. tostring(userid), true)
if playerResult ~= "OK" then
warn("Kicking " .. player.Name .. " because invalid")
warn(playerResult)
player:Kick("This game has shut down")
end
player.Chatted:connect(function(msg)
onChatted(msg, player)
end)
if not player:FindFirstChild("HandleEmote") then
Instance.new("BindableEvent", player).Name = "HandleEmote"
end
player.CharacterAdded:connect(function(character)
--[[player.CharacterAppearanceLoaded:wait()
for _, accessory in ipairs(character:GetChildren()) do
if accessory:IsA("Accoutrement") then
local success, reason = _G.validateHat({accessory})
if not success then
warn("Kicking " .. player.Name .. " due to invalidation: " .. reason)
player:Kick("This game has shut down")
return
else
if testing then
print(player.Name .. " passed validation")
end
end
end
end
spawn(function()
waitForAccoutrement(character)
for _, accessory in ipairs(character:GetChildren()) do
if accessory:IsA("Accoutrement") then
local success, reason = _G.validateHat({accessory})
if not success then
warn("Kicking " .. player.Name .. " due to invalid hat: " .. reason)
player:Kick("This game has shut down")
return
end
end
end
waitForClothing(character)
for _, clothing in ipairs(character:GetChildren()) do
if clothing:IsA("Shirt") or clothing:IsA("Pants") or clothing:IsA("ShirtGraphic") then
local success, reason = _G.validateClothing({clothing})
if not success then
warn("Kicking " .. player.Name .. " due to invalid clothing: " .. reason)
player:Kick("This game has shut down")
return
end
end
end
if testing then
warn(player.Name .. " passed validation")
end
end)]]
local starterPlayer = game:GetService("StarterPlayer")
local starterCharacter = starterPlayer:FindFirstChild("StarterCharacter")
local folders = starterPlayer:WaitForChild("StarterCharacterScripts")
local soundScript = character:WaitForChild("Sound")
if folders:FindFirstChild("Sound") then
soundScript:Remove()
end
local animateScript = character:WaitForChild("Animate")
if folders:FindFirstChild("Animate") then
animateScript:Remove()
end
for _, v in pairs(folders:GetChildren()) do
v:Clone().Parent = character
end
starterCharacter = false
if starterCharacter then
for _, v in pairs(character:GetChildren()) do
if v.Name ~= "HumanoidRootPart" and not v:IsA("LocalScript") and not v:IsA("Script") and not v:IsA("BasePart") and not v:IsA("Humanoid") then
v:Remove()
end
end
for _, v in pairs(starterCharacter:GetChildren()) do
if v.Name ~= "HumanoidRootPart" and not v:IsA("BasePart") and not v:IsA("Humanoid") then
v:Clone().Parent = character
end
end
end
if game:GetService("Players").EmoteSoundsEnabled then
Instance.new("Sound", character:WaitForChild("Torso")).Name = "EmoteSounderEffect"
end
end)
end
end)
game:GetService("Players").PlayerRemoving:connect(function(player)
local isTeleportingOut = "False"
if player.Teleported then isTeleportingOut = "True" end
if url and placeId and player and player.userId then
print("Player " .. player.userId .. " leaving")
if testing then
warn("Removing " .. player.Name .. " from database")
end
game:HttpGet(url .. "/api/gameservers/removeplayer?jobID="..jobId.."&userID=" .. tostring(player.userId))
if #game:GetService("Players"):GetPlayers() == 0 then
shuttingDown = true
if isCloudEdit then
warn("Saving place!")
local response, result = pcall(function() game:Save(saveUrl) end)
if not response then
warn(result)
end
-- yield so that file save happens in the heartbeat thread
wait()
end
warn("Server is being shutdown!")
game:HttpGet(url .. "/api/gameservers/close?jobID="..jobId)
end
end
end)
local onlyCallGameLoadWhenInRccWithAccessKey = newBadgeUrlEnabled
if placeId ~= nil and url ~= nil then
-- yield so that file load happens in the heartbeat thread
wait()
-- load the game
game:Load(url .. "/asset/?id=" .. placeId)
end
-- Now start the connection
ns:Start(port, sleeptime)
if timeout then
scriptContext:SetTimeout(timeout)
end
scriptContext.ScriptsDisabled = false
-- FilteringEnabled Detection
local FilteringEnabled = workspace.FilteringEnabled
if not FilteringEnabled then
warn("This place doesn't use FilteringEnabled. This means your place is vulnerable to exploits. You should turn it on.")
end
-- StartGame --
if not isCloudEdit then
if injectScriptAssetID and (injectScriptAssetID < 0) then
pcall(function() Game:LoadGame(injectScriptAssetID * -1) end)
else
pcall(function() Game:GetService("ScriptContext"):AddStarterScript(injectScriptAssetID) end)
end
if game:GetService("Players").EmoteSoundsEnabled then
local emoteEvent = game:GetService("ReplicatedStorage"):FindFirstChild("ANORRLEMOTEEVENTERTHING")
if not emoteEvent then
emoteEvent = Instance.new("RemoteEvent", game:GetService("ReplicatedStorage"))
emoteEvent.Name = "ANORRLEMOTEEVENTERTHING"
end
emoteEvent.OnServerEvent:connect(function(player, emoteName, state)
if player.Character then
local emoteSounder = player.Character:WaitForChild("Torso"):FindFirstChild("EmoteSounderEffect")
if not emoteSounder then
emoteSounder = Instance.new("Sound", player.Character:WaitForChild("Torso"))
emoteSounder.Name = "EmoteSounderEffect"
end
emoteSounder.Volume = 0.5
emoteSounder.Looped = true
emoteSounder:Stop()
local emoteSounds = { -- grace please consider taking lua classes
californiagurls = "arlassetid://257",
dwyec = "arlassetid://258",
caramelldansen = "arlassetid://259",
awakening = "arlassetid://261",
unlockit = "arlassetid://260",
otsukare = "arlassetid://262",
hakari = "arlassetid://263",
mannrobics = "arlassetid://264",
gangnam = "arlassetid://265",
gmod = "arlassetid://266",
jumpstyle = "arlassetid://267",
awesomeface = "arlassetid://268",
creeper = "arlassetid://269",
rampage = "arlassetid://275"
}
if state == "play" then
local soundId = emoteSounds[emoteName]
if soundId then
emoteSounder.SoundId = soundId
wait()
emoteSounder:Play()
else
emoteSounder:Stop()
end
end
end
end)
end
-- filteringenabled warning
Game:GetService("RunService"):Run()
else
Game:GetService("RunService"):Stop()
end
pcall(function()
while wait(25) do
print("renewing lease lalala")
game:HttpGet("http://{domain}/api/gameservers/renewlease?jobID="..jobId)
end
end)
if not isCloudEdit then
print("nnumber of workspaces ", #workspace:GetDescendants())
for _, v in pairs(workspace:GetDescendants()) do
if v:IsA("Seat") then
print("found", v)
v.ChildAdded:connect(function(obj)
print("child added", obj)
if obj.Name ~= "SeatWeld" then return end
local torso = obj.Part1
if not torso then return end
print("found torso")
local player = game.Players:GetPlayerFromCharacter(torso.Parent)
if not player then return end
print("found player")
local character = player.Character
while obj.Parent and player.Parent and character.Parent and character:FindFirstChild("Humanoid") and character.Humanoid.Health > 0 do
wait()
end
v.Velocity = Vector3.new(0,0,0)
v.RotVelocity = Vector3.new(0,0,0)
if not (player.Parent and character.Parent) then return end
print("ResetVelocity")
for _, v in pairs(character:GetChildren()) do
if v.className == "Part" then
v.Velocity = Vector3.new(0,0,0)
v.RotVelocity = Vector3.new(0,0,0)
end
end
end)
end
end
end
-- Heartbeat --
while wait(1) do
print(shouldCountDown)
if shouldCountDown then
print(countdownTimer)
countdownTimer -= 1
if shouldCountDown and countdownTimer <= 0 then
warn("Server is being shutdown!")
if isCloudEdit then
warn("Saving place!")
local response, result = pcall(function() game:Save(saveUrl) end)
if not response then
warn(result)
end
-- yield so that file save happens in the heartbeat thread
wait()
end
game:HttpGet(url .. "/api/gameservers/close?jobID="..jobId)
break
end
end
if not isCloudEdit and workspace.FilteringEnabled ~= FilteringEnabled then
warn("Something tried to change FilteringEnabled! Reverting...")
workspace.FilteringEnabled = FilteringEnabled
end
end