Game Server hosting proccess, how should it be?

Hey guys

When player login to the game client app in the lobby tab he can create one or more campaigns, then he can invite friends to his campaign to play with.

When a campaign is created master server will assign it a secret token. The game server will use this token to communicate with the master server. For each campaign, there needs to be a game server running.

Here is the setup process I am thinking about, I want to hear your thoughts about it.

The player will download the game server executables separately.

Through the client app, from the lobby section, the player will be able to create one or more campaigns. Each campaign will have a unique name assigned by the player and a secret token given by the master server.

When the player clicks on the campaign, a Campaign Hosting Guide button will be shown, if the player clicks on it a panel will be displayed with these contents:

Please create a directory on your computer hard disk and name it to your campaign name. Inside that folder create a file named and copy and paste the below text into it:

secretToken=bla bla bla…

Now you can execute the game server, upon start it will open a console and asks for a path to the directory you created above. Please set the path and press enter to continue. Done! your server is running now.

After the game server started it will look up that directory and will read the server configuration from there and, it also will create the entities database files inside that directory (this process will be done by Zay-ES).

Now if the player wants to host multiple campaigns he will just need to re-run the game server executable and provide the path to the directory of the campaign he wants to host.

And to determine the game server public IP address, as some clients might have dynamic IP which gets renewed by ISP every time they restart the modem, I thought it would be better to determine it on the master-server side when the game server makes a REST call to my master server (that handles the REST services) to update its status. I can get the game server IP address from HttpServletRequest.getRemoteAddr() and give it to anyone who wants to connect to that campaign server. Is this a good idea?

What do you guys think, could this whole hosting process be any simpler? Do you have any other suggestions?

Any help is appreciated :slightly_smiling_face:



Note, I am taking out the NAT port forwarding process for the moment.

Also, any hint how I can gracefully shutdown the already running game server which is running in the background? :thinking:
(in which all game systems get properly cleaned up)

A solution to work on all platforms!

I usually handle the graceful cleanup of various networking in a jvm shutdown hook.

This lets you execute code after jvm recieved a SIGTERM (ctrl + c in most terminals), exited normally or the OS is shutting down.

1 Like

How did you launch it?

For almost all of my game servers, I try to give them a simple command line console. So if you run it from a terminal then you have some simple commands you can enter and one of those is to gracefully shut down.

If you spawn the server as an external process from within a JVM then you can still grab the stdin and stdout streams if you want to still support sending/receiving commands/responses.

Shutdown hooks are nice but sometimes things have already gone too far to do some things… depending on what other libraries you use and whether they also hooked shutdown. It does work in most cases but it’s maybe not as graceful as a shutdown command.

1 Like

Thanks, indeed a good idea, going to use the same approach. Not sure why have not noticed it before in the sim-eth-es example, I see how you are doing it there.

I suppose you are talking about ProcessBuilder, Yes?

This one is a good idea as well, going to take a look at it. With this approach I guess I can make the hosting process much smoother for the player. So he can directly manage the campaign server from the lobby panel with a single click :slightly_smiling_face:

How were you launching the server before?

In the development environment using runServer gradle task within IDE.

err,… and even before that as an embedded server inside the client.

That’s what I mean… launching from the lobby I wondered how you were doing it. With an embedded server you have all of the control so your question made me think you were doing something else.

So now I feel like I must have missed something in my first read-through.

1 Like