<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LegacyWorlds Beta 6 &#187; game server</title>
	<atom:link href="http://blog.legacyworlds.com/index.php/tag/game-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.legacyworlds.com</link>
	<description>Updates on the new version&#039;s design and progress</description>
	<lastBuildDate>Sat, 26 Mar 2011 10:18:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Beta 6 Milestone 1 – Software architecture</title>
		<link>http://blog.legacyworlds.com/index.php/2010-07-11/beta-6-milestone-1-software-architecture/</link>
		<comments>http://blog.legacyworlds.com/index.php/2010-07-11/beta-6-milestone-1-software-architecture/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 12:00:18 +0000</pubDate>
		<dc:creator>TSeeker</dc:creator>
				<category><![CDATA[Milestones]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[game server]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[milestone 1]]></category>
		<category><![CDATA[software architecture]]></category>

		<guid isPermaLink="false">http://blog.legacyworlds.com/?p=168</guid>
		<description><![CDATA[I have stated numerous times that one of the primary goals of Milestone 1 was to have a clean basis for future development. This post – which will probably interest only a minority of people – is a brief overview of the design and technical choices that were made. Language A lot of the most [...]]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } -->I have stated numerous times that one of the primary goals of Milestone 1 was to have a clean basis for future development. This post – which will probably interest only a minority of people – is a brief overview of the design and technical choices that were made.</p>
<p><span id="more-168"></span></p>
<p><!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 		H2 { margin-bottom: 0.08in } 		H2.western { font-family: "Arial", sans-serif; font-size: 14pt; font-style: italic } 		H2.cjk { font-size: 14pt; font-style: italic } 		H2.ctl { font-size: 14pt; font-style: italic } 		A:link { so-language: zxx } --></p>
<h2>Language</h2>
<p>A lot of the most critical bugs in Beta 5 were caused by the features of PHP itself. First of all, PHP is not really meant to run something as computation-intensive as an online strategy game. Performance problems definitely ensued – even at this time, it takes at least ~40s to compute a complete hour tick. The other major problem that was encountered is that, well, I am clumsy. I make quite a lot of typos. And PHP is quite forgiving of typos in variable or property names – it will in fact completely ignore them, creating the new variable/property when writing, or returning <em>null</em> when reading&#8230; This kind of bug is hard to track down, especially because its consequences can become visible only in completely unrelated parts of the code, and because, when reading such code, your brain tends to “fix” what you&#8217;re reading for you. You won&#8217;t <em>see</em> that variable named $militart. You will in fact read the perfectly correct $military, because you know that&#8217;s what it should be.</p>
<p>Because of this (and also because <a href="http://news.php.net/php.internals/41374">some choices</a> made by the Zend team with regards to PHP 6 <a href="http://www.ebenoit.info/index.py/en/badmood">annoyed me</a>, but that is another matter entirely), Beta 6 was to be written in another language&#8230; But the question was – which one? There are dozens of candidates out there; in addition, it is often the case that language A is better at doing X than language B, but B is better at doing Y than A.</p>
<p>The criteria I used to guide this choice were performance, clarity, support for UTF-8, easy database integration. C++, C#, Java, Python, PHP 5 and 6 as well as Perl were considered.</p>
<p>Of course, in terms of performance, C++ revealed unbeatable, which is not really surprising. On Linux, the Mono implementation of C# turned out to be a little slower than Java, itself a good 10x slower than C++. Python, both PHP&#8217;s and Perl were&#8230; well, really much slower than either C# or Java (which is not really surprising either, but&#8230; I was still a little disappointed regarding Python). That pretty much sealed their fate. In terms of clarity, support for UTF-8 and database integration, C++ is terrible, which also eliminated it. C# and Java remained. In the end, despite C#&#8217;s cleaner typing, Mono&#8217;s I/O performance (and therefore database integration performance) is not that good, which led me to choose Java.</p>
<h2>General architecture</h2>
<p>Beta 5&#8242;s code has a major flaw, one that shouldn&#8217;t have happened but did anyway. I originally intended to completely separate game code – for example ticks, or the actual action that underlies sending a fleet – from display-related code. However, because Beta 5 was sort of rushed and did not undergo proper design, a lot of the game code ended up being coupled with the display code, which (in addition to the massive amount of delicious JavaScript spaghetti) made it totally unmaintainable. That mistake had to be avoided, especially if other interfaces (IRC bot, <span style="text-decoration: line-through;">smart</span>phones, dedicated client) are to be supported at some point.</p>
<p>The decision that was made for Beta 6 was to write a separate <em>game server</em>, which would run independently of any type of user interface. This server handles commands, background tasks such as game updates (“the things formerly known as ticks”) and returns raw data whenever appropriate. “Clients” which provide user interfaces then connect to the server, allowing players or administrators to interact with the game. At the moment, only two such clients exist – the main web site, and the administration site.</p>
<div id="attachment_170" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.legacyworlds.com/wp-content/uploads/2010/07/lw-deployment.png" rel="lightbox[168]" title="Software deployment"><img class="size-medium wp-image-170" title="Software deployment" src="http://blog.legacyworlds.com/wp-content/uploads/2010/07/lw-deployment-300x88.png" alt="" width="300" height="88" /></a><p class="wp-caption-text">Legacy Worlds software deployment</p></div>
<p><!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 		H2 { margin-bottom: 0.08in } 		H2.western { font-family: "Arial", sans-serif; font-size: 14pt; font-style: italic } 		H2.cjk { font-size: 14pt; font-style: italic } 		H2.ctl { font-size: 14pt; font-style: italic } -->As this diagram shows, it would be relatively easy to add new “clients”, connected to the game server and providing other types of interfaces.</p>
<h2>The game server</h2>
<p>Because of the “milestone” development process, the server has to follow one major constraint – it must be easy to replace parts of it. This imposes a component-based design where components are as independent as possible.</p>
<p>A client communicates with the server through a set of classes which represent commands, responses and actual data using a component called the SessionClient. This component has a server counterpart, the SessionManager, which supports different types of sessions with different authentication requirements, states and valid commands through specific components called “session definers”. At the moment (and for the foreseeable future), three such definers exist:</p>
<ul>
<li>the external session definer 	handles commands which can be executed by anyone (for example, 	requesting the list of supported languages),</li>
<li>the game session definer manages 	player sessions, their various states (disabled, banned, active, 	vacation mode&#8230;) and commands,</li>
<li>finally, the administrative 	session definer handles commands from the administration interface.</li>
</ul>
<p>While the session definers (and especially the game session definer) will definitely change in future milestones, the essential component that is the session manager itself is stable by now.</p>
<p>Session definers don&#8217;t do much by themselves. With the exception of basic constraints checking, most of the logic is actually implemented in lower layers. The validation and transformation components handle proper validation of the commands&#8217; data, forwarding all of this to the data access layer, and then transforming the results into something which can then be sent back to the session layer.</p>
<p>This lower layer (and, to some extent, the administration session definer) relies extensively on a set of system components. These components are in charge of all operations required for the good operation of the server, but which are not really related to the game logic. They include:</p>
<ul>
<li>the ConstantsManager, which caches 	game “constants” in memory for quick access and allows them to 	be updated by administrators, notifying components who use them as 	necessary,</li>
<li>the Ticker, which executes actions 	on a regular basis at various frequencies, relying on the 	ConstantsManager for its master frequency,</li>
<li>the Logging components allows 	asynchronous logging from the rest of the code, as well as log 	clean-up and querying,</li>
<li>the Internationalisation component 	caches translations from the database, and handles administrative 	commands updating these translations,</li>
<li>the Mailer which fetches 	internationalised e-mail templates, transforms them, and sends them.</li>
</ul>
<p>Both the system components and the data access layer can access the database. Access is (with one very small exception) never direct – all read-only operations read from views, while the update operations are implemented through stored procedures.</p>
<p>The diagram below shows the various components or groups of components of the server as well as an arbitrary, unnamed client.</p>
<div id="attachment_169" class="wp-caption aligncenter" style="width: 221px"><a href="http://blog.legacyworlds.com/wp-content/uploads/2010/07/lw-components.png" rel="lightbox[168]" title="Legacy Worlds game server"><img class="size-medium wp-image-169" title="Legacy Worlds game server" src="http://blog.legacyworlds.com/wp-content/uploads/2010/07/lw-components-211x300.png" alt="" width="211" height="300" /></a><p class="wp-caption-text">The various components of the Legacy Worlds game server</p></div>
<p><!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 		A:link { so-language: zxx } -->The components in green are stable – they will not change, with the exception of bug fixes. Yellow components contain mostly stable code, but are still missing some parts which will be added in later milestones (for example, the UserAccount component does not support <a href="../index.php/2010-03-11/contribution-credits-in-beta-6/">using contribution credits</a>). Finally, components in red are likely to be completely replaced or heavily modified.</p>
<p>What the diagram does not show is that the database is structured using namespaces, which follow the organisation of the server components quite closely.</p>
<h2>Next time, on the B6 blog&#8230;</h2>
<p>The next (and last) post of this series will tell you all about Milestone 2.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.legacyworlds.com/index.php/2010-07-11/beta-6-milestone-1-software-architecture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

