Python Master Server
by Andy Rollins · 04/28/2008 (11:55 am) · 55 comments
Download Code File
When a game client wants to connect to a game server it can scan the network to look for servers on a particular port, this is quite an effective solution when on a small network such as a Home/Office LAN but consider trying to scan the entire Internet looking for a game server, you'd be there for quite some time!!
Instead we employ a Master Server which is hosted at a fixed known address, for example the standard Garagegames master server used in the Starter FPS can be found at master.garagegames.com on port 28002. As each game server starts up it registers itself with the master server which then maintains a list of known servers, when a game client wishes to connect it requests the list of available servers from the master server.
The basic process flow for game servers is:
1. Game server sends a heartbeat to the master server to register itself (packet type 22)
2. Master server sends an Info Request (packet type 10) to the game server requesting more information i.e. game type, mission, number of players, number of bots, etc.
3. Game server Responds with info data and is added to the list of available servers. (packet type 12)
4. Master server drops server from it's list if it hasn't had a heartbeat in about 180 seconds.
5. About every 180 seconds game server sends another heartbeat and the process starts from step 1.
The basic flow for game clients is:
1. Game client sends a list request to the master server (packet type:6)
2. Master server responds with the list of available servers (packet type:8)
3. Game client then pings the game server
4. game server responds to ping request
5. Game client sends request for information to game server
6. Game server responds to information request.
7. The list of available game servers appears in the GUI (see script joinServerGui.gui in the starter.fps)
Ideally the master server filters the results based on game type, mission, num players, etc before responding to the client in step 2 - this is currently not implemented in this version of the master server although I do store all the data so you could easily add a function to do it.
I've tested this version using Python 2.5 and both TGE 1.5.2 and TGEA 1.7 so you should have any problems with those versions, to use it you should just edit the Configuration section at the top of the Masterserver.py and set the port to whichever number you require.
Then in your game edit the server\defaults.cs file where you should see a line that looks like:
to point at your master server (remember to alter the port number to also match the one you set in the masterserver.py file. Examples:
Note the "2:" before the hostname/ip address needs to be there it's an old thing from tribes and the engine expects it to be there.
I've been coding Python for the sum total of 4 days now so there are no doubt bugs within the code, let me know if/as you find them and I'll endeavour to update the resource with any fixes or improvements that people come up with.
Please feel free to use the code however you wish without restriction, although it would be nice to receive some credit if you do use it.
When a game client wants to connect to a game server it can scan the network to look for servers on a particular port, this is quite an effective solution when on a small network such as a Home/Office LAN but consider trying to scan the entire Internet looking for a game server, you'd be there for quite some time!!
Instead we employ a Master Server which is hosted at a fixed known address, for example the standard Garagegames master server used in the Starter FPS can be found at master.garagegames.com on port 28002. As each game server starts up it registers itself with the master server which then maintains a list of known servers, when a game client wishes to connect it requests the list of available servers from the master server.
The basic process flow for game servers is:
1. Game server sends a heartbeat to the master server to register itself (packet type 22)
2. Master server sends an Info Request (packet type 10) to the game server requesting more information i.e. game type, mission, number of players, number of bots, etc.
3. Game server Responds with info data and is added to the list of available servers. (packet type 12)
4. Master server drops server from it's list if it hasn't had a heartbeat in about 180 seconds.
5. About every 180 seconds game server sends another heartbeat and the process starts from step 1.
The basic flow for game clients is:
1. Game client sends a list request to the master server (packet type:6)
2. Master server responds with the list of available servers (packet type:8)
3. Game client then pings the game server
4. game server responds to ping request
5. Game client sends request for information to game server
6. Game server responds to information request.
7. The list of available game servers appears in the GUI (see script joinServerGui.gui in the starter.fps)
Ideally the master server filters the results based on game type, mission, num players, etc before responding to the client in step 2 - this is currently not implemented in this version of the master server although I do store all the data so you could easily add a function to do it.
I've tested this version using Python 2.5 and both TGE 1.5.2 and TGEA 1.7 so you should have any problems with those versions, to use it you should just edit the Configuration section at the top of the Masterserver.py and set the port to whichever number you require.
Then in your game edit the server\defaults.cs file where you should see a line that looks like:
$pref::Master0 = "2:master.garagegames.com:28002";
to point at your master server (remember to alter the port number to also match the one you set in the masterserver.py file. Examples:
using the local machine i.e. your own pc/laptop: $pref::Master0 = "2:localhost:28002"; or via IP address: $pref::Master0 = "2:192.168.0.200:28666"; or even an external site: $pref::Master0 = "2:my_cool_domain.com:27531";
Note the "2:" before the hostname/ip address needs to be there it's an old thing from tribes and the engine expects it to be there.
I've been coding Python for the sum total of 4 days now so there are no doubt bugs within the code, let me know if/as you find them and I'll endeavour to update the resource with any fixes or improvements that people come up with.
Please feel free to use the code however you wish without restriction, although it would be nice to receive some credit if you do use it.
#42
C:\master.py (hit enter and it should run)
05/05/2010 (2:30 pm)
Provided that you have Python installed on your machine. You should be able to just open up your dos window and simply type the name of the python script. For ex. If it's called master.py and it's on the root level then punch it in, should look like this below:C:\master.py (hit enter and it should run)
#43
Thank You For your reply.
I have run the python script.Like your way.
MasterServer.py
but i am receving an error
return_num +=ord<c> *multiplier
SyntaxError:invalid syntax
Shall i have made any changes in python script to run the
Master Server.
05/11/2010 (5:01 am)
@DALO Thank You For your reply.
I have run the python script.Like your way.
MasterServer.py
but i am receving an error
return_num +=ord<c> *multiplier
SyntaxError:invalid syntax
Shall i have made any changes in python script to run the
Master Server.
#44
05/11/2010 (9:25 am)
The script is good to go and does not need to be changed. Of course you can customize it if you'd like. As for me I've never had that error before so I'm not sure? Has anyone else had this error?
#45
I have done the following Changes
in defaults.cs
$pref::Master[0] = "2:35.54.34.234:28002";
only i have done the changes.
I am running remove server. and ihave run the python scripting in the remote server.
but the client shows that NO MASTER SERVER FOUND...
what are the changes i have to do in client and server.is it enough
05/12/2010 (1:40 am)
@Dalo Thank You For your replyI have done the following Changes
in defaults.cs
$pref::Master[0] = "2:35.54.34.234:28002";
only i have done the changes.
I am running remove server. and ihave run the python scripting in the remote server.
but the client shows that NO MASTER SERVER FOUND...
what are the changes i have to do in client and server.is it enough
#46
05/13/2010 (3:40 am)
hi
#47
Thank you.Now i am executing Python Scripting in remote server.
i have done changes in core/server.cs
$pref::Master[0] = "2:37.74.36.511:28002";
when i have clicked the MasterServer button.
In remote server the python scripting says:
the game type,mission type and min and max players
and final it says
SENDING LIST DATA FOR 0 SERVER
the client says the Master server is not found..
why it is happened.
shall i have to run the dedicated server as well as the python script..
could any one help me.
05/13/2010 (3:42 am)
@Dalo Thank you.Now i am executing Python Scripting in remote server.
i have done changes in core/server.cs
$pref::Master[0] = "2:37.74.36.511:28002";
when i have clicked the MasterServer button.
In remote server the python scripting says:
the game type,mission type and min and max players
and final it says
SENDING LIST DATA FOR 0 SERVER
the client says the Master server is not found..
why it is happened.
shall i have to run the dedicated server as well as the python script..
could any one help me.
#48
05/13/2010 (8:56 am)
It's been awhile since I have looked at the script but as soon as you start your hosted game the master server should kick out messages indicating it's getting pinged. So if you run your game and the master server window is doing nothing then my guess is that you have some sort of firewall or something stopping the connection. Is your machine that's running that master server under a router? Do you have antivirus software? how about windows firewall? Check that out, hopefully it's one of those that can be switched off.
#49
I have switched off the Windows Fire Wall
The Server shows
n remote server the python scripting says:
the game type,mission type and min and max players
and final it says
SENDING LIST DATA FOR 0 SERVER
I client it says
ServerQuery: start Querying master server 0
No master servers found in this region, trying IP:37.74.36.511:28002.
Requesting the server list from master server IP:37.74.36.511:28002 (2 tries left)...
Received server list packet 1 of 1 from the master server (0 servers).
ServerQuery: done No servers found. 1
shall i have to run the Dedicated server command like
StarterFPS -dedicated -mission levels/starterfps.mis
or any some other way..
i have one other doubt.
this python scripting code will work for all project or it will run only for starter fps folder.
could any help me .how to setup the master server.
05/14/2010 (4:52 am)
@ DALO Thank You For you reply I have switched off the Windows Fire Wall
The Server shows
n remote server the python scripting says:
the game type,mission type and min and max players
and final it says
SENDING LIST DATA FOR 0 SERVER
I client it says
ServerQuery: start Querying master server 0
No master servers found in this region, trying IP:37.74.36.511:28002.
Requesting the server list from master server IP:37.74.36.511:28002 (2 tries left)...
Received server list packet 1 of 1 from the master server (0 servers).
ServerQuery: done No servers found. 1
shall i have to run the Dedicated server command like
StarterFPS -dedicated -mission levels/starterfps.mis
or any some other way..
i have one other doubt.
this python scripting code will work for all project or it will run only for starter fps folder.
could any help me .how to setup the master server.
#50
The problem lies with your game server (dedicated server), if you open your console.log for the game server you should see a line that looks something like:
If you read the process flow for the game server as part of the resource you'll understand what those two lines mean, have a hunt for them and see if they're pointing at the same place.
From memory some versions of TGE/TGEA have the master server location stored in a couple of places in the scripts so search all your .cs files for master.garagegames.com and replace all instances with your IP address, also delete all the cs.dso files to make sure it's picked up your changes.
When the game server connects correctly to the master server, then the master server will show you something like:
Hope that helps.
For your other query, this will work for any game made with Torque not just the starter.fps - the example above is from the AFX pack working with this.
05/18/2010 (3:54 am)
Your game client and the master server are working correctly, as you can see the client connects and gets a response back from the master server.The problem lies with your game server (dedicated server), if you open your console.log for the game server you should see a line that looks something like:
Sending heartbeat to master server [IP:192.168.1.6:28002] Received info request from a master server [IP:192.168.1.6:28002].
If you read the process flow for the game server as part of the resource you'll understand what those two lines mean, have a hunt for them and see if they're pointing at the same place.
From memory some versions of TGE/TGEA have the master server location stored in a couple of places in the scripts so search all your .cs files for master.garagegames.com and replace all instances with your IP address, also delete all the cs.dso files to make sure it's picked up your changes.
When the game server connects correctly to the master server, then the master server will show you something like:
Heartbeat from IP: 192.168.1.11 Port: 28000
Sending Game Info Request IP: 192.168.1.11 Port: 28000
Game Info response from IP: 192.168.1.11 port: 28000
Game type : afxDemo
Mission type : MageVSMage
Number Bots : 0
Num players : 0Hope that helps.
For your other query, this will work for any game made with Torque not just the starter.fps - the example above is from the AFX pack working with this.
#51
Thank you for you reply.
I have applied your method. I have run the python scrip +dedicated server
when i run the client Strong hold demo
It shows the
GameServer list request from IP:132.28.0.202 Port :1358
Game Type : Stronghold
Mission Type : Any
Min Players : 0
Max Players : 100
Region Mask : 2
Version : 0
Filter Flags : 0
Max Bots : 0
Min Bots : 0
Buddy Count : 0
Sending list data for 1 servers
Heartbeat from IP: 132.28.0.202 Port: 28001
Sending Game Info Request IP: 132.28.0.202 Port: 28001
Game Info Response from IP: 132.28.0.202 port : 28001
Game type: FPS Starter Kit
Mission type: Deat Match
Number Bots : 0
Num Players : 0
but the client shows the No Server Found.
I have also checked the two cs files it points to the Master Server address Correctly.
The console Shows
Sending heartbeat to master server [IP:132.28.0.202:28000]
Received info request from a master server [IP:132.28.0.202:28000].
Sending heartbeat to master server [IP:132.28.0.202:28000]
but
when i click the Query Master Server
The client displays NO SERVER FOUND. Instead of NO MASTER SERVER FOUND.
NO SERVER FOUND means....
what i have done wrong with it.
I dont reason why?
could any one please help me...
05/21/2010 (4:48 am)
@Andy Rollins Thank you for you reply.
I have applied your method. I have run the python scrip +dedicated server
when i run the client Strong hold demo
It shows the
GameServer list request from IP:132.28.0.202 Port :1358
Game Type : Stronghold
Mission Type : Any
Min Players : 0
Max Players : 100
Region Mask : 2
Version : 0
Filter Flags : 0
Max Bots : 0
Min Bots : 0
Buddy Count : 0
Sending list data for 1 servers
Heartbeat from IP: 132.28.0.202 Port: 28001
Sending Game Info Request IP: 132.28.0.202 Port: 28001
Game Info Response from IP: 132.28.0.202 port : 28001
Game type: FPS Starter Kit
Mission type: Deat Match
Number Bots : 0
Num Players : 0
but the client shows the No Server Found.
I have also checked the two cs files it points to the Master Server address Correctly.
The console Shows
Sending heartbeat to master server [IP:132.28.0.202:28000]
Received info request from a master server [IP:132.28.0.202:28000].
Sending heartbeat to master server [IP:132.28.0.202:28000]
but
when i click the Query Master Server
The client displays NO SERVER FOUND. Instead of NO MASTER SERVER FOUND.
NO SERVER FOUND means....
what i have done wrong with it.
I dont reason why?
could any one please help me...
#52
The extract from the master server log shows a gameserver list request before your server sent a heartbeat which isn't right - that can't be full thing.
One shows Game type: FPS Starter Kit and the other on Stronghold?!? so which are using?
05/21/2010 (7:29 am)
I'm sorry but I'm finding it very hard to understand your English making it very difficult to therefore figure out what you've done or what your setup is.The extract from the master server log shows a gameserver list request before your server sent a heartbeat which isn't right - that can't be full thing.
One shows Game type: FPS Starter Kit and the other on Stronghold?!? so which are using?
#53
I have successfully setup the Master Server in torque 3d.
I have run the python script +dedicated server and client program.
when i click the query Master server.. The Master Server name is displayed...
Your coding is working fine and good.
Great Work..... Congratulations........
Thank you...
05/24/2010 (9:55 pm)
@Andy Rollins Thank you for your reply ...I have successfully setup the Master Server in torque 3d.
I have run the python script +dedicated server and client program.
when i click the query Master server.. The Master Server name is displayed...
Your coding is working fine and good.
Great Work..... Congratulations........
Thank you...
#54
07/26/2012 (11:17 pm)
Is there any chance of getting a reupload of this? The file seems to be missing 
CloudFire