jump to navigation

The Game Server: Progress & Design July 25, 2010

Posted by aknartrebna in Uncategorized.
add a comment

As promised, here is the server design.  Note: this update may contain some technical jargon, but I will offer some short explanations in places.  I will not explicitly give out the protocol used for security reasons.

The Server is programmed in C in order to be as fast as possible.  The design is pretty straightforward — the listener is set up (listeners wait for incoming connections).  Once a connection is made, a thread is spawned to handle the new connection.  First, the server receives all of the incoming information via TCP and makes sure all of it is received (the amount of data sent in bytes is included in the sent data).  Then, depending on certain codes, will either be a log in, log out, find game, or end of game sequence (all of these are set up in one huge switch statement).  The database accesses occur in this section (to be more specific, all database access are preformed through the server code; whereas the clients can access the DB directly, for security reasons i’d rather this not happen).

Everything through the logins and logouts is written and tested, the rest will be finished when I’m ready to write that part of the client (or I get tired of doing graphical design).

Issues:

The biggest problem I have as of right now are memory leaks coming from the mysql.h library.  After googling the results from running Valgrind (a GNU debugging tool), I discovered that I was not the only one having this problem, and will attempt to find where the leaks are in the mysql library and fix them.  Since memory leaks tie up memory for as long as the program is running, the amount of memory used by the program increases every time the MySQL database is accessed by the program and I will have to restart the program every so often (depending on server usage).  I tested the server on my laptop with 3GB RAM and was able to complete 192,000 logins and logouts.  However, my old laptop (which the server will run on) has only 512MB RAM.  Not a big issue in the near future, as I can use chronjobs (a linux program that can be set to run programs at specific times) to run a script that will reboot the program.  Besides, if this truly becomes a huge problem it may be time to move to a professional server rather than an almost 7 year old lappy with Comcast (and hopefully it will get there)!

Current progress:

I am now working on character models and will hopefully have one walking on the screen soon.  I am using the .md2 file format with the md2loader C++ library.  Hopefully the next update will include a video of this!  (Which should be soon, if I can keep myself off of projecteuler.net and Starcraft 2 coming tuesday (WOOT!), but I’m usually good about being disciplined with my gaming, thankfully).

You can also watch my progress by following me on twitter, @aknartrebna, and the hashtag #bfoc.