Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

How to limit the amount of servers there are? NOT PLAYER COUNT, NOT ASKING FOR SCRIPT.

Asked by
Voltoxus 248 Moderation Voter
9 years ago

I am asking for suggestions, not a script to limit the amount of servers running not how many players there are!

This was reported as spam for no reason >_< any way I am currently kicking the 50th player in a 50 player server to prevent more then one server opening, I am simply wondering if there is a more efficient way to do this.

0
Why do you want to prevent more than one server opening? BlueTaslem 18071 — 9y
0
I think it's an interesting Idea I don't see why people are disliking @BlueTaslem It's probably for a group game to prevent more than 1 server opening up say there's a group raiding people will make it to where there's another server just so they can win 1 and lose 1 usually creates issues for groups Prioxis 673 — 9y
0
If it's for a group oriented event like above, then require the server to have a specific rank in order for it to stay running. I have no other idea on how to control the server count. PreciseLogic 271 — 9y
0
I am planning on making a personal server kinda thing with out using a personal server settings, I want to test the Universe service. Voltoxus 248 — 9y
0
And preventing more then 1 server from opening eliminates data overwriting, also it makes more sense to limit it to one server if it is a build server it would be more easy to manage with moderation and such. Voltoxus 248 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

The answer to your problem lies in a feature of programming called a mutex. A mutex allows us to lock and unlock a variable, this is usually used in programming languages that allow for true, OS-level thread concurrency, like C++ in std::thread, where both getting and setting the same memory across multiple threads will cause undefined behaviour. A mutex, in simple terms, is setting a variable to true when we're using a feature we'd like to lock and release it to false once we're done, this allows us to wait until the mutex is set back to false before operating on it. In your situation there's more than one way to do it, I can think of two ways:

  1. Use datastores. When a server is created (game.Players.PlayerAdded is fired as the incoming player becomes the first player of the server) check whether the 'mutex' value is true or false. If true, kick the player, causing the server to shut down as there are no players in the server. If false, set the mutex value to true and continue the game's execution (making sure to not check the mutex value again.) Once the game is shutting down (as the parameter passed from game.Players.PlayerRemoving is the last player in the server) set the mutex value to false.

  2. HTTP requests I don't recommend this, but it's just as possible although it requires some knowledge of a web framework. The same process with a different method.

BEWARE Either methods WILL cause issues in the case of a server crash. If the server closes from undefined behaviour, such as an infinite loop without wait()s, the mutex value will remained locked despite no server being active.

Fixing this requires some kind of heartbeat system to make sure that the blocking server is indeed alive. In the case the server drops off without gracefully finishing the mutex is set to false for the next server.

Ad

Answer this question