Introducing LiveServersService!
LiveServersService (hereafter referred to as LSS) is a simple module (written in under 200 lines lol) that can help you fetch running servers by writing just a few lines of code!
Installation
Why do I need this?
LSS might come in handy in some cases, such as when you want to make a server list for players to pick another server to join when they found themselves in a high-ping server.
Example Code
local LSS = require(path.to.LiveServersService)
LSS:Initiate()
LSS:AddToLiveServers()
while task.wait(60) do
_G.LiveServers = LSS:GetLiveServers() —>> Container does not necessarily have to be _G.
end
It’s just that simple!
API (only methods are there lol)
:Initiate()
Initiates memory data, in case it is the first time running. You must run this before calling any other methods.
:AddToLiveServers(refreshRate: number?)
Uploads the running server of the module (LSS) instance to the memory list. Any server must call this method before being able to be fetched by other servers as a running server. refreshRate
(defaults to 300) decides for how long will it wait for between each server information update (as of now, only the number of players will be updated).
:RemoveFromLiveServers()
Removes the running server of the module (LSS) instance from the memory list. After calling this method, other servers will no longer be able to fetch the server as a running server. This method is automatically called when server is about to shutdown, after calling :Initiate()
.
:GetLiveServers(maxNo: number?, excludeSelf: boolean?, placeId: number?)
Fetches a maximum of maxNo
(defaults to 20) currently running servers from the memory list. The returned table will be as following:
{
[jobId_of_the_server_instance: string] = {
NumberOfPlayers = number
IsPrivateServer = boolean
PlaceVersion = number
Location = string -- Geographical location of the server, e.g. 'Tokyo, Japan'.
}
}
If excludeSelf
is nil
or true
and the running server of the module (LSS) is found to be included in the returned list, it is automatically removed from the list. However, note that the no. of items in the list would be [original number - 1] because of this. If placeId
(defaults to the place’s Id) is given, it will return running servers of that place if that servers of that place has been added to the memory list.
Wanna donate?
This would help me a lot! Donate!
Lastly, rating the module would help a lot!
- This module is awesome!
- Somewhat solid, but I don’t think I would be using it.
- Not really that good.