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