Update gameserver.lua
This commit is contained in:
parent
08fdef42ce
commit
f557766c24
|
|
@ -3,6 +3,7 @@ const { readFile } = require("fs/promises")
|
|||
|
||||
const Job = require("./Job.js")
|
||||
const logger = require("../logger.js")
|
||||
const randport = require("../randport.js")
|
||||
|
||||
class GameJob extends Job {
|
||||
constructor() {
|
||||
|
|
@ -19,6 +20,8 @@ class GameJob extends Job {
|
|||
|
||||
logger.info(`[${this.id}] GameJob started for ${id}`)
|
||||
|
||||
const port = await randport.udp()
|
||||
|
||||
this.OpenJobEx({
|
||||
name: this.id,
|
||||
script: await readFile(__dirname + "/../../lua/gameserver.lua", { encoding: "utf-8" }),
|
||||
|
|
@ -30,12 +33,12 @@ class GameJob extends Job {
|
|||
{ type: "LUA_TSTRING", value: process.env.BASE_URL },
|
||||
|
||||
{ type: "LUA_TNUMBER", value: id },
|
||||
{ type: "LUA_TNUMBER", value: 50001 },
|
||||
{ type: "LUA_TNUMBER", value: port },
|
||||
],
|
||||
},
|
||||
}).catch((e) => reject(e))
|
||||
|
||||
resolve()
|
||||
resolve(port)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ exports.tcp = () => {
|
|||
exports.udp = () => {
|
||||
return new Promise((resolve) => {
|
||||
const server = dgram.createSocket()
|
||||
server.bind(0, () => {
|
||||
server.bind(Math.random() * (60_000 - 50_000) + 50_000, () => {
|
||||
const port = server.address().port
|
||||
server.close((err) => resolve(port))
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
local jobId, type, baseUrl, placeId, port = ...
|
||||
local jobId, type, baseUrl, placeId, port, key = ...
|
||||
|
||||
------------------- UTILITY FUNCTIONS --------------------------
|
||||
|
||||
function waitForChild(parent, childName)
|
||||
while true do
|
||||
local child = parent:findFirstChild(childName)
|
||||
if child then return child end
|
||||
parent.ChildAdded:wait()
|
||||
end
|
||||
while true do
|
||||
local child = parent:findFirstChild(childName)
|
||||
if child then
|
||||
return child
|
||||
end
|
||||
parent.ChildAdded:wait()
|
||||
end
|
||||
end
|
||||
|
||||
-----------------------------------END UTILITY FUNCTIONS -------------------------
|
||||
|
|
@ -15,11 +18,8 @@ end
|
|||
|
||||
pcall(function() settings().Network.UseInstancePacketCache = true end)
|
||||
pcall(function() settings().Network.UsePhysicsPacketCache = true end)
|
||||
--pcall(function() settings()["Task Scheduler"].PriorityMethod = Enum.PriorityMethod.FIFO end)
|
||||
pcall(function() settings()["Task Scheduler"].PriorityMethod = Enum.PriorityMethod.AccumulatedError end)
|
||||
|
||||
--settings().Network.PhysicsSend = 1 -- 1==RoundRobin
|
||||
--settings().Network.PhysicsSend = Enum.PhysicsSendMethod.ErrorComputation2
|
||||
settings().Network.PhysicsSend = Enum.PhysicsSendMethod.TopNErrors
|
||||
settings().Network.ExperimentalPhysicsEnabled = true
|
||||
settings().Network.WaitingForCharacterLogRate = 100
|
||||
|
|
@ -27,21 +27,17 @@ pcall(function() settings().Diagnostics:LegacyScriptMode() end)
|
|||
|
||||
-----------------------------------START GAME SHARED SCRIPT------------------------------
|
||||
|
||||
local assetId = placeId -- might be able to remove this now
|
||||
local UserInputService = game:GetService('UserInputService')
|
||||
local assetId = placeId
|
||||
|
||||
local scriptContext = game:GetService('ScriptContext')
|
||||
pcall(function() scriptContext:AddStarterScript(37801172) end)
|
||||
scriptContext.ScriptsDisabled = true
|
||||
|
||||
game:SetPlaceID(placeId, false)
|
||||
game:SetPlaceID(assetId, false)
|
||||
game:GetService("ChangeHistoryService"):SetEnabled(false)
|
||||
|
||||
-- establish this peer as the Server
|
||||
local ns = game:GetService("NetworkServer")
|
||||
local url = "http://www.kapish.fun"
|
||||
if url~=nil then
|
||||
print(baseUrl)
|
||||
|
||||
if baseUrl ~= nil then
|
||||
pcall(function() game:GetService("Players"):SetAbuseReportUrl(baseUrl .. "/AbuseReport/InGameChatHandler.ashx") end)
|
||||
pcall(function() game:GetService("ScriptInformationProvider"):SetAssetUrl(baseUrl .. "/Asset/") end)
|
||||
pcall(function() game:GetService("ContentProvider"):SetBaseUrl(baseUrl .. "/") end)
|
||||
|
|
@ -58,103 +54,59 @@ print(baseUrl)
|
|||
game:GetService("InsertService"):SetCollectionUrl(baseUrl .. "/Game/Tools/InsertAsset.ashx?sid=%d")
|
||||
game:GetService("InsertService"):SetAssetUrl(baseUrl .. "/Asset/?id=%d")
|
||||
game:GetService("InsertService"):SetAssetVersionUrl(baseUrl .. "/Asset/?assetversionid=%d")
|
||||
|
||||
|
||||
pcall(function() loadfile(baseUrl .. "/Game/LoadPlaceInfo.ashx?PlaceId=" .. placeId)() end)
|
||||
|
||||
-- pcall(function()
|
||||
-- if access then
|
||||
-- loadfile(baseUrl .. "/Game/PlaceSpecificScript.ashx?PlaceId=" .. placeId .. "&" .. access)()
|
||||
-- end
|
||||
-- end)
|
||||
end
|
||||
|
||||
pcall(function() game:GetService("NetworkServer"):SetIsPlayerAuthenticationRequired(false) end)
|
||||
pcall(function() game:GetService("NetworkServer"):SetIsPlayerAuthenticationRequired(true) end)
|
||||
settings().Diagnostics.LuaRamLimit = 0
|
||||
--settings().Network:SetThroughputSensitivity(0.08, 0.01)
|
||||
--settings().Network.SendRate = 35
|
||||
--settings().Network.PhysicsSend = 0 -- 1==RoundRobin
|
||||
|
||||
|
||||
--game:GetService("Players").PlayerAdded:connect(function(player)
|
||||
-- player:LoadCharacter()
|
||||
-- print("Player " .. player.userId .. " added")
|
||||
--end)
|
||||
game:GetService("Players").PlayerAdded:connect(function(player)
|
||||
print("Player " .. player.userId .. " added")
|
||||
end)
|
||||
|
||||
game:GetService("Players").PlayerRemoving:connect(function(player)
|
||||
print("Player " .. player.userId .. " leaving")
|
||||
end)
|
||||
|
||||
if placeId~=nil and baseUrl~=nil then
|
||||
-- yield so that file load happens in the heartbeat thread
|
||||
wait()
|
||||
|
||||
-- load the game
|
||||
game:Load("https://kapish.fun/asset/?id=" .. placeId .. "&placelol=true&key=" .. key)
|
||||
end
|
||||
|
||||
-- Now start the connection
|
||||
|
||||
ns:Start(port)
|
||||
|
||||
|
||||
scriptContext:SetTimeout(10)
|
||||
scriptContext.ScriptsDisabled = false
|
||||
local success, error = pcall(function()
|
||||
while true do
|
||||
-- UGLY HACK BECAUSE FOR SOME REASON HTTPPOST AND POSTASYNC CRASHES??
|
||||
-- WHAT THE FUCK?
|
||||
local playerIds = ""
|
||||
local players = game.Players:GetChildren()
|
||||
for i, player in pairs(players) do
|
||||
if player.ClassName == "Player" then
|
||||
if i ~= #players then
|
||||
playerIds = playerIds .. player.userId .. ","
|
||||
else
|
||||
playerIds = playerIds .. player.userId
|
||||
end
|
||||
local success, error = spawn(function()
|
||||
while wait(5) do
|
||||
-- UGLY HACK BECAUSE FOR SOME REASON HTTPPOST AND POSTASYNC CRASHES??
|
||||
-- WHAT THE FUCK?
|
||||
local playerIds = ""
|
||||
local players = game.Players:GetChildren()
|
||||
for i, player in pairs(players) do
|
||||
if player.ClassName == "Player" then
|
||||
if i ~= #players then
|
||||
playerIds = playerIds .. player.userId .. ","
|
||||
else
|
||||
playerIds = playerIds .. player.userId
|
||||
end
|
||||
end
|
||||
|
||||
game:HttpGet('http://kapish.fun/server/ping/' .. placeId .. '?players=' .. playerIds .. "&key=" .. key)
|
||||
|
||||
wait(5)
|
||||
end
|
||||
end)
|
||||
spawn(function()
|
||||
while true do
|
||||
wait(10)
|
||||
if #game.Players:GetPlayers() == 0 then
|
||||
pcall(function() game:HttpGet("http://144.126.135.224:2758/game/stop/" .. jobId) end)
|
||||
else
|
||||
pcall(function() game:HttpGet("http://144.126.135.224:2758/game/renew/" .. jobId .. "/360") end)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
game:HttpGet('http://kapish.fun/server/ping/' .. placeId .. '?players=' .. playerIds .. "&key=" .. key)
|
||||
end
|
||||
end)
|
||||
|
||||
spawn(function()
|
||||
game:GetService("Players").PlayerAdded:connect(function(player)
|
||||
print("Player " .. player.userId .. " added")
|
||||
player.CharacterAdded:connect(function(char)
|
||||
pcall(function()
|
||||
repeat wait() until char:FindFirstChildOfClass("Humanoid")
|
||||
local conn
|
||||
conn = char:FindFirstChildOfClass("Humanoid").Died:connect(function()
|
||||
wait(5)
|
||||
player:LoadCharacter()
|
||||
con:disconnect()
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
game:GetService("Players").PlayerRemoving:connect(function(player)
|
||||
print("Player " .. player.userId .. " leaving")
|
||||
while wait(10) do
|
||||
if #game.Players:GetPlayers() == 0 then
|
||||
pcall(function() game:HttpGet("https://kapish.fun/dielol/" .. placeId.."?key=" .. key) end)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
------------------------------END START GAME SHARED SCRIPT--------------------------
|
||||
|
||||
|
||||
|
||||
-- StartGame --
|
||||
game:GetService("RunService"):Run()
|
||||
|
|
|
|||
Loading…
Reference in New Issue