Game Development Community

How To? Dedicated Server with variables???

by DALO · in Technical Issues · 07/08/2008 (1:20 pm) · 13 replies

Hello,
In my quest to figure out how to setup the whole networking aspects of our game it amazes me how much I've searched and how little I find. Even with the new book: Multiplayer Gaming and engine coding, there still aren't any answers.....just general concepts.....still a good book though.

In the TGE download you get a "Starter.FPS Dedicated.bat" file that has this:

torqueDemo.exe -game starter.fps -dedicated -mission starter.fps/data/missions/stronghold.mis

Ok, great, I understand that but what if you have variables that need to be set such as clock timers, the number of bots, skills levels of the bots, kill count limit if in arena mode, etc....all things like this need to be factored into creating that dedicated game server.
Any help would be greatly appreciated.......Thx.

#1
07/08/2008 (1:42 pm)
You would want to set them up in the server scripts in the starter.fps directory. You will also need to make sure that the clients know what the server is doing, however.
#2
07/10/2008 (7:34 am)
One option is to use the -config parameter when you run the server. Create a config/ folder and stick a script in it for each server you want to run.

Then you can run serveral dedicated servers from the same install, but each can have different variables such as port it's listening on, game mode, max player count, admin password... Which will override the usual server defaults.

As David mentions though, you'll need to make sure anything the client needs to know is sent across. Although in the cases of the above that's either already in place or the client doesn't need that info.
#3
07/10/2008 (7:59 am)
Good call. I forgot completely about -config when posting! I swear my brain is dead some days.
#4
07/14/2008 (9:37 pm)
Hey thanks a bunch Gary and David, that got me looking into the main.cs (first one the engine looks at....duh, kinda forgot about that file) and I noticed all those options. I'm guessing that you ultimately can pass whatever you want into the bat file as long as it's parsed......am I right? Now when you say, make a folder to run different servers, how do you get torque to exec that .bat file?
I finally was able to get 2 servers running from my place of business with some static ip's hooray....now I want to set it up so that users can start a dedicated game.....ok.....so now, how would this be done? Client creates game and sets up game variables, being type of game, max players, number of bots, bot intelligence level...etc. If client is able to send this info to the server how would a the .bat file be executed on the server.....? I'm hoping you or someone will be able share how this process/concept is done......would really appreciate it.
Thx in advance.
#5
07/15/2008 (10:38 am)
Well one thing worth mentioning is that .bat files are windows specific, so if your game relies on the comp. running your game being able to run a bat file it is also windows specific. Maybe thats a problem maybe not, but anyway...

Basically you need to look up shell execute in Win32 programming and write a Torque wrapper for it (or search for shellExecute and see if somethings already there).

We needed a client to automatically start a second process running a dedicated server on-startup, so I wrote a little consoleFunction that uses shellExecute to do that. If you are interested in that code email me.
#6
07/15/2008 (12:37 pm)
Quote:I'm guessing that you ultimately can pass whatever you want into the bat file as long as it's parsed......am I right? Now when you say, make a folder to run different servers, how do you get torque to exec that .bat file?

If you're using windows, right click on the Torque.exe and select "Create Shortcut". Then right click on the short-cut you just made and select "properties". You'll see a "Target" field which will contain something like

c:\Torque\example\Torque.exe

Depending upon where you installed Torque to.

Change that to be

c:\Torque\example\Torque.exe -dedicated -config ./configs/server1.cs

Then simply create a new folder called "configs" within the example folder, create a new script file named server1.cs and enter into it any variables you want for this instance of the server. Such as the admin password, max players, port, server name etc

Now you just double click that short-cut and it will run the server and then run your server1.cs file. To run more servers, just copy the server1.cs file, name it server2.cs and make any changes you want, then copy the shortcut and change ./configs/server1.cs to ./configs/server2.cs

You can of course just type this into a cmd prompt, but having short-cuts will save typing if you constantly bring up and shut down servers.

If you're doing this on linux, just drop the commands into a shell script or run then from the command line with nohup.

There's nothing wrong with putting those commands in a bat file on windows, but there is also no real reason to when you can create a couple of short-cuts. Unless you plan on having a ton of servers.
#7
07/15/2008 (1:46 pm)
Ah, perfect, thanks sooooo much.
#8
07/17/2008 (4:25 pm)
Hey Gary,
Thanks for all the help thus far. I have one last question. My 2 servers are windows based and I'm wondering how to actually start the dedicated game. For Example, let's say there's a person wanting to start a dedicated game for he and his friends and he lives in........New York and my servers are in Las Vegas. How is that once the client hit's start mission that the servers in Las Vegas will be able to start a dedicated game.......run.....then STOP and close the dedicated game once the battle is over?

Does anyone know how many dedicated servers can run on one machine?

I'm starting to get a hang of the this but just need to clear this concept up. Any insight would be greatly appreciated.
#9
07/18/2008 (5:01 am)
Quote:How is that once the client hit's start mission that the servers in Las Vegas will be able to start a dedicated game.......run.....then STOP and close the dedicated game once the battle is over?

Your clients need to "join" the same dedicated server in order to play together and those servers need to already be up and running. One way of doing this is providing your players a list of all available servers such as the fps demo does.

When the players join the server, it is up to your scripts as to what happens, you could have the game drop them into an already running game, or you could script it so that when there are no players in the dedicated server it returns to a lobby mode. Then as and when players join, they're dropped into a "lobby" where they can chat, select the level/game mode and so on. There's lots of ways to accomplish this which are really just tweaks on the existing script code.

You could dynamically start/stop new dedicated servers, but that wouldn't be supported out of the box. You'd need to provide additional back end support to do so.

Quote:Does anyone know how many dedicated servers can run on one machine?

This depends on several things, firstly the cpu/memory available. How much you need per server will depend on your game. The other is bandwidth usage, both up and down stream. This depends upon how many packets of data you're sending per second and how many players you want to support per server.

Have a look at the following variables
$pref::Net::PacketRateToClient
   $pref::Net::PacketRateToServer
   $pref::Net::PacketSize
   $pref::Server::MaxPlayers

PacketRateToClient * PacketSize * MaxPlayers is the upload bandwidth you need PER server. Likewise, PacketRateToServer * PacketSize * MaxPlayers will be download bandwidth your server needs available. Both figures will be in bytes per second.


Those will be the maximum limits the server would need, but in actual running, you may find it uses less since you may have fewer players connected, or some clients may have lower PacketRate/Size settings.

One thing to also consider, is that your players don't have to use dedicated servers. You can set up one player as the "host" and have them local Join the game, then the rest of the players can connect to that server in the same way they would a dedicated server. The downside to this, is you have to contend with firewalls and the limited bandwidth most players may have.
#10
07/18/2008 (5:12 am)
Hope I'm not hi-jacking a thread, but I have a quick question on the config files. Should the variables that are entered into the .cs be in the Pref::Server:XXXX format?
#11
07/18/2008 (10:04 am)
Quote:Should the variables that are entered into the .cs be in the Pref::Server:XXXX format?

Yes. It's just a standard torque script file, so if you wanted to set max players to 12, you'd enter

$Pref::Server::MaxPlayers = 12;
#12
07/18/2008 (10:06 am)
Thanks. That makes configuring the server much easier.
#13
07/18/2008 (10:21 am)
Hey Gary,
Yeah, it's all ready to go right now for anyone to play where one client would be server and client. Koth, the game that I'm trying to get out, is composed of multiple Arena Games that are either timed games or game ends based on number of kills, the usual arena type match. There is a somewhat longer game type called Transcendance Games but essentially it's just another short multiplayer shoot em up, which doesn't last too long. And of course like I mentioned before there are a lot of variables that need to be set for each game. We've been testing the LAN version quite a bit and it runs really great for all the clients but the person hosting seems to lag, hence the search for dynamic dedicated servers. I may just have to set up some shortcut's like you mentioned earlier and allow users that might have 2 computers in the home to run a dedicated game themselves or something......? But for me to implement dynamic dedicated servers on my servers will have to be done down the road. Thanks a bunch for all of your input.