Hey all!
I’m releasing something I’ve been toying with for the last few days based on an idea I had a long time ago.
https://www.roblox.com/library/5972092620/PrimaryServer
This is best called PrimaryServer because it’s just that: a primary server to act as the middleman for all servers.
Say you have settings on Trello that you run your game on, it wouldn’t make sense for 50 servers to make 50 requests when you can select 1 server to be the gateway.
This is something I failed to enact, but hopefully will re-make with, in my past release [Open Source] Fast-Flag System - #12 by LordMerc
Some pictures of the PrimaryServer in action:
https://media.discordapp.net/attachments/770711776139411476/778699347826311238/unknown.png
This is two different servers, the left side is the current host while the right side is another server.
Some examples can be found in the primaryserver script, but feel free to read the module itself if you can bear in mind the pain of the code. It’s not the best formatted, but it works.
local API = require(script.ServerSelector)
local Service = API:init()
Service:on('ready',function()
print('API is now ready to be used!')
print(Service:GetCurrentServer())
end)
Service:on('HostChanged',function(HostID)
if HostID == game.JobId then
print('This is now the current host server!')
else
print('Server',HostID,'is now the host server!')
end
end)
local tab = {
"LordMerc is cool man!"
}
Service:on("Trello",function(SentTab)
print('Received update from the host server!')
print(SentTab)
end)
while wait(3) do
if Service:GetHostServer() == game.JobId then
print('As host, you are the one sending data')
Service:Trello(tab)
end
end
Fair note, any function (example being the Service:Trello()), will not run on the host server as that can be done when you are sending the data out at the time same.
while wait(3) do
if Service:GetHostServer() == game.JobId then
print('As host, you are the one sending data')
Service:Trello(tab)
-- Now your server runs the code here or in a function outside
end
end
So far after testing it many times I’ve yet to run into any problems, but it’s unavoidable to happen. If you have issues or questions feel free to ask!