C# Master Server
by Ryan Mick · 08/08/2010 (11:37 pm) · 42 comments
Over a year ago I had started a conversion of the Push Button Master server into C#. Due to personal reasons I had to stop work on it. I am now able to pick up were I left off and so here it is, the C# Master Server. The code is a VS2008 project and all source code is provided. I tested the functionality as best I have not stress tested the application. It can be run as a console or windows app for flexibility. My goal is to have a second part of this that shows how to build in your own user account/profile handling thru a master server.
The project can be found here
Let me know if you have any questions or problems.
The project can be found here
Let me know if you have any questions or problems.
#2
08/09/2010 (3:48 pm)
Once I figured out how the Push Button master server worked it wasn't too difficult to create. It just took time to get it to a point where I could release it. Hopefully enough people play with it to give it a good stress test so I can resolve any issues that may come up. In the mean time I will work on a user login system thru the master server.
#3
08/11/2010 (6:05 am)
Ryan, have you ever looked at the MMO stuff Xerves was working on. I know it has a master server with login code in python. Python is a pretty simple version of programming to understand. Perhaps it could point you in the right direction?
#4
How to download it? I don't see any download buttons/links in your downloads page.
08/11/2010 (11:14 pm)
>Let me know if you have any questions or problems.How to download it? I don't see any download buttons/links in your downloads page.
#5
08/11/2010 (11:30 pm)
Sorry about that, forgot that I had set the downloads section to only allow registered users the ability to download. You can now download without having to register.
#6
I hope you will update, from time to time, your Master Server utility.
08/12/2010 (1:24 pm)
Thanks for your work, Ryan.I hope you will update, from time to time, your Master Server utility.
#7
Plus, where it should be located? For example I have installed apache server, how to make it accessible via localhost for example?
08/13/2010 (1:11 pm)
Ryan, tell me please how to set up properly Torque for query your master-server, not garagegames default?Plus, where it should be located? For example I have installed apache server, how to make it accessible via localhost for example?
#8
Now just make sure that in your torque game you change all instances of $pref::Master to point to the IP of the computer/server you are running the master server on. If you need to run them both locally then set $pref::Master to $pref::Master0 = "2:127.0.0.1:28002";
You will then need to make a change in code of your torque project. In winnet look for the following:
and change it to:
08/13/2010 (2:23 pm)
Usually a master server is ran on a separate box than one you run your server on, but you can set it up to work. This can be ran in 2 flavors, the first is as a windows application (look in MasterServe/bin/debug directory for the exe), the second is as a windows console application (look in MasterServerConsole/bin/debug directory for the exe). You can run either of those (not sure though if he console exe is up to date, you might have to rebuild it). By default the master server is listening in on port 28002. That can be changed in the preference (server.prf), you just have to restart the server for it to take effect.Now just make sure that in your torque game you change all instances of $pref::Master to point to the IP of the computer/server you are running the master server on. If you need to run them both locally then set $pref::Master to $pref::Master0 = "2:127.0.0.1:28002";
You will then need to make a change in code of your torque project. In winnet look for the following:
NetAddress &na = receiveEvent.sourceAddress;
if(na.type == NetAddress::IPAddress &&
na.netNum[0] == 127 &&
na.netNum[1] == 0 &&
na.netNum[2] == 0 &&
na.netNum[3] == 1 &&
na.port == netPort)
continue;
if(bytesRead <= 0)
continue;
receiveEvent.size = PacketReceiveEventHeaderSize + bytesRead;
Game->postEvent(receiveEvent);and change it to:
NetAddress &na = receiveEvent.sourceAddress;
//if(na.type == NetAddress::IPAddress &&
// na.netNum[0] == 127 &&
// na.netNum[1] == 0 &&
// na.netNum[2] == 0 &&
// na.netNum[3] == 1 &&
// na.port == netPort)
// continue;
if(bytesRead <= 0)
continue;
receiveEvent.size = PacketReceiveEventHeaderSize + bytesRead;
Game->postEvent(receiveEvent);That will allow you to connect locally. Rebuild your project and start it up. Let me know if you need anything else.
#9
>In winnet look for the following:
There is no such file(winnet) in, at least, T3D 1.1 Beta 2 source files. The piece of source code that you told me to change exists in x86UNITNet.cpp only. But anyway, I changed it as you told.
>Let me know if you need anything else.
Well, there is :) Why I tryed to create game, your master server told me:
----
The following exception occurred in the DataGridView.
System.IndexOutOfRangeException: Index 0 does not have a value. at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
at System.Windows.Forms.DatagridViewDataConnection.GetError(int32 rowIndex).
----
Here is extended trace:
----
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Forms.DataGridViewRow.GetErrorText(Int32 rowIndex)
at System.Windows.Forms.DataGridViewCell.PaintWork(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
at System.Windows.Forms.DataGridViewRow.PaintHeader(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow, DataGridViewPaintParts paintParts)
at System.Windows.Forms.DataGridViewRow.Paint(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow)
at System.Windows.Forms.DataGridView.PaintRows(Graphics g, Rectangle boundingRect, Rectangle clipRect, Boolean singleHorizontalBorderAdded)
at System.Windows.Forms.DataGridView.PaintGrid(Graphics g, Rectangle gridBounds, Rectangle clipRect, Boolean singleVerticalBorderAdded, Boolean singleHorizontalBorderAdded)
at System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
----
Plus, when I close Masterserver.exe - its still appear in Task manager. Have to kill it manually everytime.
P.S. Ryan, can I ask you for your MSN or ICQ, for a few extended questions?
08/13/2010 (9:09 pm)
Thanks for your help, Ryan. But there is still a few problems :)>In winnet look for the following:
There is no such file(winnet) in, at least, T3D 1.1 Beta 2 source files. The piece of source code that you told me to change exists in x86UNITNet.cpp only. But anyway, I changed it as you told.
>Let me know if you need anything else.
Well, there is :) Why I tryed to create game, your master server told me:
----
The following exception occurred in the DataGridView.
System.IndexOutOfRangeException: Index 0 does not have a value. at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
at System.Windows.Forms.DatagridViewDataConnection.GetError(int32 rowIndex).
----
Here is extended trace:
----
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Forms.DataGridViewRow.GetErrorText(Int32 rowIndex)
at System.Windows.Forms.DataGridViewCell.PaintWork(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
at System.Windows.Forms.DataGridViewRow.PaintHeader(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow, DataGridViewPaintParts paintParts)
at System.Windows.Forms.DataGridViewRow.Paint(Graphics graphics, Rectangle clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates rowState, Boolean isFirstDisplayedRow, Boolean isLastVisibleRow)
at System.Windows.Forms.DataGridView.PaintRows(Graphics g, Rectangle boundingRect, Rectangle clipRect, Boolean singleHorizontalBorderAdded)
at System.Windows.Forms.DataGridView.PaintGrid(Graphics g, Rectangle gridBounds, Rectangle clipRect, Boolean singleVerticalBorderAdded, Boolean singleHorizontalBorderAdded)
at System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
----
Plus, when I close Masterserver.exe - its still appear in Task manager. Have to kill it manually everytime.
P.S. Ryan, can I ask you for your MSN or ICQ, for a few extended questions?
#10
I am more than willing to give you my chat ID if you can answer me one question. How do you have access to any source code?
According to your profile you don't own any of the engines. I am more than willing to help but you have to be legit before I do so.
08/13/2010 (9:37 pm)
That is an interesting error. I have ran the master server on to completely different boxes with out a problem. What are you running it on? Do you have the latest VS2008 service pack installed?I am more than willing to give you my chat ID if you can answer me one question. How do you have access to any source code?
According to your profile you don't own any of the engines. I am more than willing to help but you have to be legit before I do so.
#11
Could you please post from an account that has access to the Professional version of the engine? That will help clear up any discrepancies.
08/13/2010 (9:49 pm)
@KinjalCould you please post from an account that has access to the Professional version of the engine? That will help clear up any discrepancies.
#12
Intel Q9550, 4 GB Ram, GeForce 9800GTX+, Win 7 x64. :)
>Do you have the latest VS2008 service pack installed?
Yes, I'd compiled it with VS2008 + SP1 installed.
>How do you have access to any source code?
Well, friend of mine gave me Torque 1.1 Beta 2 sources which have paid account here, because I said that I would like to try myself a bit in game development, and asked him about any 3D engine which I could to try. He told me about Unity3D, UDK and Torque3D, but he is added that he have paid license for T3D. So I decided to try T3D(but if its a bad idea, just tell me, i'll switch to something another). Because I'm not ready to pay that I don't know I paying for, firstly I'm trying to make something that will work with Torque version which currently I have (do not depend on default demos of course). If I manage it, I'll buy Torque 3D for sure. So please don't ban me for that, just understand my situation. I working with torque for a just few days, but I already like it. But I need to work with it a bit more, to decide buy it or not. First thing that scare me a bit is a crashes. Beta 2 crashes pretty often (I already made approx. ~6 crash fixes that I can send you guys in InstantAction, if you tell me where to send). Secondly is question of performance - physics demo have unstable fps (plus, its won't run on computer with Radeon gfx installed), and especially _empty scene_ in editor mode lagging a lot with no reason. Thirdly is network part (because I plan to make simple network-only 3d-arcade with thirdperson view) - I just run 'full' template as a host on my current machine, and joined to this via second machine(Athlon X3 425, 4GB Ram, Radeon 4850) through LAN - approx. every ~6-15 seconds happen extreme lag(as netgraph shows me) when latency from typical ~20-30 pump up to ~600. And fourthly is GUI(editor)... I have made a few improvements here into present GUI controls, but its an another story.
08/14/2010 (10:18 am)
>What are you running it on? Intel Q9550, 4 GB Ram, GeForce 9800GTX+, Win 7 x64. :)
>Do you have the latest VS2008 service pack installed?
Yes, I'd compiled it with VS2008 + SP1 installed.
>How do you have access to any source code?
Well, friend of mine gave me Torque 1.1 Beta 2 sources which have paid account here, because I said that I would like to try myself a bit in game development, and asked him about any 3D engine which I could to try. He told me about Unity3D, UDK and Torque3D, but he is added that he have paid license for T3D. So I decided to try T3D(but if its a bad idea, just tell me, i'll switch to something another). Because I'm not ready to pay that I don't know I paying for, firstly I'm trying to make something that will work with Torque version which currently I have (do not depend on default demos of course). If I manage it, I'll buy Torque 3D for sure. So please don't ban me for that, just understand my situation. I working with torque for a just few days, but I already like it. But I need to work with it a bit more, to decide buy it or not. First thing that scare me a bit is a crashes. Beta 2 crashes pretty often (I already made approx. ~6 crash fixes that I can send you guys in InstantAction, if you tell me where to send). Secondly is question of performance - physics demo have unstable fps (plus, its won't run on computer with Radeon gfx installed), and especially _empty scene_ in editor mode lagging a lot with no reason. Thirdly is network part (because I plan to make simple network-only 3d-arcade with thirdperson view) - I just run 'full' template as a host on my current machine, and joined to this via second machine(Athlon X3 425, 4GB Ram, Radeon 4850) through LAN - approx. every ~6-15 seconds happen extreme lag(as netgraph shows me) when latency from typical ~20-30 pump up to ~600. And fourthly is GUI(editor)... I have made a few improvements here into present GUI controls, but its an another story.
#13
08/14/2010 (3:42 pm)
Since you have an illicitly acquired version of the engine, I am forced to take action and lock your account. I have also contacted you via e-mail. Sorry for any confusion that the licensing clause on not sharing an engine with a non-licensee may have caused.
#14
Also, I am struggling to get any server instances to show (I am running everything from one box) although I can see the requests seem to get past the master filters, then it seems to drop out somewhere before Torque gets the message, back to the debugging!
If anyone is interested in a VB .Net version of the MSLib then let me know, I have ported it all over (although its VS2010)
09/08/2010 (3:08 pm)
Ryan, what sort of heartbeat times do you run with? I had to increase T3D and the Server quite a bit so it didn't keep removing them...Also, I am struggling to get any server instances to show (I am running everything from one box) although I can see the requests seem to get past the master filters, then it seems to drop out somewhere before Torque gets the message, back to the debugging!
If anyone is interested in a VB .Net version of the MSLib then let me know, I have ported it all over (although its VS2010)
#15
What version of T3D are you using?
09/08/2010 (4:43 pm)
The default is 3 minutes before a server is removed but can be changed in the server.prf file. Heartbeats originate from the host server not the master server the master server just processes a heartbeat and updates the servers time in the list.What version of T3D are you using?
#16
Yeah I get the servers sending the beat,
What I was going to ask and didn't (as I wasn't sure if I was not seeing something) was the client heart beats, it seems you will request the master server list, have a session created (for the client), then the new session just drops off when it's out of heartbeat limits, I expected the client session to be kept alive until they D/C?
I want to track a players session (no session no play) but the only way I can think to do it is add a heartbeat to the client or similar, what do you think?
Edit: Torque3D B2
09/08/2010 (5:03 pm)
Hey Ryan, Yeah I get the servers sending the beat,
What I was going to ask and didn't (as I wasn't sure if I was not seeing something) was the client heart beats, it seems you will request the master server list, have a session created (for the client), then the new session just drops off when it's out of heartbeat limits, I expected the client session to be kept alive until they D/C?
I want to track a players session (no session no play) but the only way I can think to do it is add a heartbeat to the client or similar, what do you think?
Edit: Torque3D B2
#17
09/08/2010 (5:10 pm)
Ok, just tried with 1.1B2 and the server was dropping from the list almost right away. Tested it with TGE 1.5.2 and didn't have a problem with it dropping from the list.
#18
What do you think about the Client Session though, is it intended to be dropping off like that, or should it to have a heartbeat too do you think?
On an earlier note, Kinjal mentioned about the data grid error, that error is defo there, I saw it a few times when switching between the two tabs while it was working, I can't point you to where it's at because I struggled to read the C# hence why I ported it over to VB and I haven't finished my ported version so I can't re-create the problem but if I find it I will let you know...
I also have 2 issues that I may have created myself,
Every time I request the master list, the master seems to process 5 packets, of which only 1 is valid, I then get a message in Torque saying it received packet 2 of 2 and then I get "Rerequesting server list packet #1..." followed by "Server list packet #1 timed out." (maybe this is related to those 5 packets sent from the client)
Also, when you request the master server list, get your server listed then request the list again, the server drops out, it seemed to be because m_RemoveServer was being set to true on the server object so it never got returned, if you wait about 3 min, then request again it pops back in... For now I have just disabled svr.RemoveServer = True in ServerStore.QueryServers and it seems to be happy now, the thing is I don't know if that is happening because of issue one, or something different....
It's going to be a long night ;)
09/08/2010 (5:40 pm)
Yeah all I have done is to increase the T3D heartbeat rate and raise the MasterServer heartbeat variable, it works well now (although I am sending a heartbeat every 12 seconds or so, I will lower that to your suggested 3 min)What do you think about the Client Session though, is it intended to be dropping off like that, or should it to have a heartbeat too do you think?
On an earlier note, Kinjal mentioned about the data grid error, that error is defo there, I saw it a few times when switching between the two tabs while it was working, I can't point you to where it's at because I struggled to read the C# hence why I ported it over to VB and I haven't finished my ported version so I can't re-create the problem but if I find it I will let you know...
I also have 2 issues that I may have created myself,
Every time I request the master list, the master seems to process 5 packets, of which only 1 is valid, I then get a message in Torque saying it received packet 2 of 2 and then I get "Rerequesting server list packet #1..." followed by "Server list packet #1 timed out." (maybe this is related to those 5 packets sent from the client)
Also, when you request the master server list, get your server listed then request the list again, the server drops out, it seemed to be because m_RemoveServer was being set to true on the server object so it never got returned, if you wait about 3 min, then request again it pops back in... For now I have just disabled svr.RemoveServer = True in ServerStore.QueryServers and it seems to be happy now, the thing is I don't know if that is happening because of issue one, or something different....
It's going to be a long night ;)
#19
@Trigger, the sessions time out after 30 seconds and are basically used to authenticated package requests. You can see multiple package requests for the server list if the client doesn't get a response in a certain time. If you are running everything on a single box you might not have enough resources for the master server to process in time. Also if you've change the time intervals of the processing queues that will cause an impact on processing. They are coded to 50 milliseconds by default which seemed to work fine in my testing but you can change them as needed.
If you want something like user profile integration that is something that will have to be built into the engine and the master server. It's not too difficult to do and I am working on a follow up to this with that in mind. I have a few things to finish up with before I can get to that though.
09/08/2010 (9:13 pm)
Ok, just uploaded a new zip with the fix for the servers dropping from the list and the error message for the grid.@Trigger, the sessions time out after 30 seconds and are basically used to authenticated package requests. You can see multiple package requests for the server list if the client doesn't get a response in a certain time. If you are running everything on a single box you might not have enough resources for the master server to process in time. Also if you've change the time intervals of the processing queues that will cause an impact on processing. They are coded to 50 milliseconds by default which seemed to work fine in my testing but you can change them as needed.
If you want something like user profile integration that is something that will have to be built into the engine and the master server. It's not too difficult to do and I am working on a follow up to this with that in mind. I have a few things to finish up with before I can get to that though.
#20
11/29/2010 (7:20 pm)
I now have this resource up on my site http://sacdeveloper.com/Projects/Torque.aspx so that I can keep better track of versions and changes. 
Torque 3D Owner Trigger
VW
Just Downloaded the code so I will have a look soon as I get chance, I was going to have a look at a .Net based one myself, so that's just saved so much work!!
Thanks Ryan!