<?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>BakedOn Entertainment - Online Multiplayer Games &#187; Technology</title>
	<atom:link href="http://www.bakedon.com/category/technology/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bakedon.com</link>
	<description></description>
	<lastBuildDate>Fri, 23 Apr 2010 00:26:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to use Lidgren with Unity3D for MMOs &#8211; Part 1</title>
		<link>http://www.bakedon.com/2010/04/how-to-use-lidgren-with-unity3d-for-mmos-part-1/</link>
		<comments>http://www.bakedon.com/2010/04/how-to-use-lidgren-with-unity3d-for-mmos-part-1/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 23:58:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[lidgren]]></category>
		<category><![CDATA[MMORPG]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[udp]]></category>

		<guid isPermaLink="false">http://www.bakedon.com/?p=91</guid>
		<description><![CDATA[Why use Lidgren?
Don&#8217;t kid yourself.  Writing a multiplayer game that runs over the Internet can be tricky. If you are using Unity you have the entire .NET network library at your disposal. Simply making a TCP connection or sending UDP packets is pretty trivial. Why on earth would you bother using someone else&#8217;s library?

The debate [...]]]></description>
			<content:encoded><![CDATA[<h2>Why use Lidgren?</h2>
<p>Don&#8217;t kid yourself.  Writing a multiplayer game that runs over the Internet can be tricky. If you are using Unity you have the entire .NET network library at your disposal. Simply making a TCP connection or sending UDP packets is pretty trivial. Why on earth would you bother using someone else&#8217;s library?</p>
<p><span id="more-91"></span></p>
<p>The debate between TCP and UDP for MMOs is as strong as ever and I&#8217;m certainly not going to talk about it here. For <a href="http://www.ghostees.com">Ghostees</a>, I am using UDP and the <a title="Lidgren Network Library" href="http://code.google.com/p/lidgren-network/">Lidgren</a> library. It&#8217;s open source, free but best of all it solves a lot of the issues revolving around using UDP as your transport.</p>
<p>The types of things you can encounter with UDP can be a pain but since it is low level, you get incredible flexibility and performance.<a href="http://www.bakedon.com/wp-content/uploads/2010/04/Shoot-yourself-in-the-foot.jpg"><img class="alignright size-full wp-image-94" style="float: right;" title="Shoot yourself in the foot" src="http://www.bakedon.com/wp-content/uploads/2010/04/Shoot-yourself-in-the-foot.jpg" alt="" width="200" height="143" /></a> Think of UDP as a message passing protocol as opposed to TCP which is a stream based protocol.  TCP will ensure that your data makes its way across the trenches of the internet in tact and in order.  UDP on the other hand makes no guarantees.  Some messages may go missing.  You might even get two of the same or get messages out of order. Tricky stuff.  Lidgren takes care of all that stuff for your but only where you want it.  It will definitely let you shoot yourself in the foot also.</p>
<h2>The (very) Basic Server</h2>
<p>By the way, Lidgren builds in Mono so you can run your server on Linux. I&#8217;m pretty sure it works but I haven&#8217;t done enough testing to say 100% at this point and I&#8217;m pretty much a Windows guy. Enough yapping, lets get coding.</p>
<p>Start a new project for your server and create your server class. I prefer to add the Lidgren project to my solution but either way, add a reference to <strong>Lidgren.Network</strong>.</p>
<p>Your class will need two private members to start: NetServer and NetBuffer, both in the Lidgren.Network namespace.</p>
<pre class="brush: csharp;">
class MyServer
{
    private NetServer server;
    private NetBuffer buffer;

    public MyServer()
    {
        var config = new NetConfiguration(&quot;hello-world&quot;);
        config.Port = 42948;

        server = new NetServer(config);
        buffer = new NetBuffer();
        server.Start();
    }
}
</pre>
<p>Lets go through this quickly.  On line 3 the NetServer is the class from Lidgren that will listen for incoming traffic.  The NetBuffer on the next line is what we read our messages into.  We can reuse it so it is declared as a class member.</p>
<p>We create an instance of NetConfiguration to pass configuration information into the NetServer constructor. NetConfiguration takes a single string argument that is our application identifier.  This can be anything you like as long as both the client and server use the same string.</p>
<p><a href="http://www.bakedon.com/wp-content/uploads/2010/04/homer-doh.jpg"><img class="alignleft size-medium wp-image-112" title="homer-doh" src="http://www.bakedon.com/wp-content/uploads/2010/04/homer-doh-211x300.jpg" alt="" width="89" height="126" /></a><strong>DOH!</strong> you wouldn&#8217;t believe how many times I&#8217;ve had projects where I change the application identifier on either the client or server but not the other and then subsequently spend w-a-a-a-y too long trying to figure out why I can&#8217;t connect.</p>
<p>On line 9 I set the port that the server will listen on for incoming messages. Choose pretty much any number you like that is less than 65535 as long as it doesn&#8217;t conflict with another application listening on the same port. Only one port per network card can be in use at any time. You are best off choosing a number somewhere over 32768 to avoid &#8220;well known&#8221; ports.</p>
<p>Lastly, we just call Start() on the server to have it bind to the port and buffering messages.</p>
<h2>The Pump</h2>
<p><a href="http://www.bakedon.com/wp-content/uploads/2010/04/joeblowsport.jpg"><img class="alignright size-full wp-image-123" style="float: right;" title="joeblowsport" src="http://www.bakedon.com/wp-content/uploads/2010/04/joeblowsport.jpg" alt="" width="100" height="161" /></a>When the server receives a message, after some processing it places it into a queue. This all happens behind the scenes in another thread. You need to write code to retrieve them.  I usually have a single thread reading and distributing incoming messages and you might as well make it your main thread.  Add this method to your server class:</p>
<pre class="brush: csharp;">
    public void Process()
    {
        NetMessageType type;
        NetConnection source;

        while (server.ReadMessage(buffer, out type, out source))
        {
            HandleMessage(buffer, type, source);
        }
    }
</pre>
<p>Your server host, whether its a console application or Windows service, will be responsible for pumping the messages by calling Process. Avoid the temptation of over complicating your server with a thread for the message pump. You won&#8217;t see any speed or efficiency increase putting more threads in here.</p>
<p>Each time through the while loop, the server will hand you one message. It will also give you the type of message and which client connection it came from.</p>
<h2>The Mail Room</h2>
<p><a href="http://www.bakedon.com/wp-content/uploads/2010/04/Wood-36-Compartment-Mail-Sorter-7766GR_big.jpg"><img class="alignleft size-full wp-image-126" style="float: right;" title="Wood-36-Compartment-Mail-Sorter-(7766GR)_big" src="http://www.bakedon.com/wp-content/uploads/2010/04/Wood-36-Compartment-Mail-Sorter-7766GR_big.jpg" alt="" width="150" height="153" /></a>Now we need to decide what&#8217;s in the message we just got, and what to do with it. You will receive messages not only from your connected clients but also from Lidgren.  Lets cover Lidgren&#8217;s messages first.</p>
<p>Among the several types of messages Lidgren can send you, debug messages are one of the two basic ones you definitely want to handle. They will simply be strings that you can output to the console or debug stream.</p>
<p>Another  message you want to handle is the StatusChanged message. This message tells you when someone has connected or disconnected. I&#8217;ve created another method called HandleMessage which is where I will switch on the message type.</p>
<p>The last of the most basic messages is the Data message. These are messages sent to you from your connected clients.</p>
<p>I would suggest you throw an exception or at least log a warning if a message comes through that you didn&#8217;t handle. I&#8217;ve caught many weird bugs this way simply because I wasn&#8217;t aware I was receiving a BadMessageReceived or other message.</p>
<pre class="brush: csharp;">
    public event Action&lt;NetConnection&gt; ConnectionStatus;

    private void HandleMessage(NetBuffer buffer, NetMessageType type, NetConnection source)
    {
        switch (type)
        {
            case NetMessageType.DebugMessage:
                {
                    Debug.WriteLine(buffer.ReadString());
                    break;
                }

            case NetMessageType.StatusChanged:
                {
                    if (ConnectionStatus != null)
                        ConnectionStatus(source);
                    break;
                }

            case NetMessageType.Data:
                {
                    if (DataReceived != null)
                        DataReceived(source, buffer);
                    break;
                }

            default:
                throw new NotImplementedException(&quot;Message type not handled: &quot; + type.ToString());
        }
    }
</pre>
<p>You can see in the snippet above on the first two lines, I&#8217;ve declared two public events. Other classes in your server will want to know when a client comes and goes so its wise to publish this information. The other event gets fired when we receive data from clients.</p>
<p>HandleMessage works its magic by simply switching on the message type. In the case of a debug message, we simply write it to the debug stream.  In the case of a ConnectionStatus or Data message, we fire the appropriate events.</p>
<p>OK so here is the code so far:</p>
<pre class="brush: csharp;">
using System;
using System.Diagnostics;
using Lidgren.Network;

namespace BakedOn
{
    class MyServer
    {
        private NetServer server;
        private NetBuffer buffer;

        public event Action&lt;NetConnection&gt; ConnectionStatus;
        public event Action&lt;NetConnection, NetBuffer&gt; DataReceived;

        public MyServer()
        {
            var config = new NetConfiguration(&quot;hello-world&quot;);
            config.Port = 42948;

            server = new NetServer(config);
            buffer = server.CreateBuffer();
        }

        public void Process()
        {
            NetMessageType type;
            NetConnection source;

            while (server.ReadMessage(buffer, out type, out source))
            {
                HandleMessage(buffer, type, source);
            }
        }

        private void HandleMessage(NetBuffer buffer, NetMessageType type, NetConnection source)
        {
            switch (type)
            {
                case NetMessageType.DebugMessage:
                    {
                        Debug.WriteLine(buffer.ReadString());
                        break;
                    }

                case NetMessageType.StatusChanged:
                    {
                        if (ConnectionStatus != null)
                            ConnectionStatus(source);
                        break;
                    }

                case NetMessageType.Data:
                    {
                        if (DataReceived != null)
                            DataReceived(source, buffer);
                        break;
                    }

                default:
                    throw new NotImplementedException(&quot;Message type not handled: &quot; + type.ToString());
            }
        }
    }
}
</pre>
<p>In the next part, I will show you how to create a client that will work within Unity. It&#8217;s not tough at all. And if you deep-tech readers are concerned what we have done here is far too simplistic, not to worry. We will be going much deeper. After the client, we will start talking about message formats, serialization and message envelopes.</p>
<p>If this topic is useful or interesting to you, shoot me a quick comment and let me know so I&#8217;ll keep going with it.</p>
<ul class="socialwrap row">
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.bakedon.com%2F2010%2F04%2Fhow-to-use-lidgren-with-unity3d-for-mmos-part-1%2F&amp;title=How+to+use+Lidgren+with+Unity3D+for+MMOs+%26%238211%3B+Part+1" title="Save on Delicious How to use Lidgren with Unity3D for MMOs &#8211; Part 1"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/delicious.png" height="16"  width="16" /> <span class="head">Bookmark on Delicious</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.bakedon.com%2F2010%2F04%2Fhow-to-use-lidgren-with-unity3d-for-mmos-part-1%2F&amp;title=How+to+use+Lidgren+with+Unity3D+for+MMOs+%26%238211%3B+Part+1" title="Digg this post - How to use Lidgren with Unity3D for MMOs &#8211; Part 1"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/digg.png" height="16"  width="16" /> <span class="head">Digg this post</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.bakedon.com%2F2010%2F04%2Fhow-to-use-lidgren-with-unity3d-for-mmos-part-1%2F&#038;t=How+to+use+Lidgren+with+Unity3D+for+MMOs+%26%238211%3B+Part+1" title="Share this post - How to use Lidgren with Unity3D for MMOs &#8211; Part 1"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/facebook.png" height="16"  width="16" /> <span class="head">Recommend on Facebook</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.bakedon.com%2F2010%2F04%2Fhow-to-use-lidgren-with-unity3d-for-mmos-part-1%2F&amp;title=How+to+use+Lidgren+with+Unity3D+for+MMOs+%26%238211%3B+Part+1" title="Share on Reddit: How to use Lidgren with Unity3D for MMOs &#8211; Part 1"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/reddit.png" height="16"  width="16" /> <span class="head">share via Reddit</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.bakedon.com%2F2010%2F04%2Fhow-to-use-lidgren-with-unity3d-for-mmos-part-1%2F&amp;title=How+to+use+Lidgren+with+Unity3D+for+MMOs+%26%238211%3B+Part+1" title="Submit to Stumble: How to use Lidgren with Unity3D for MMOs &#8211; Part 1"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/stumbleupon.png" height="16"  width="16" /> <span class="head">Share with Stumblers</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://twitter.com/home/?status=http%3A%2F%2Fwww.bakedon.com%2F2010%2F04%2Fhow-to-use-lidgren-with-unity3d-for-mmos-part-1%2F" title="Tweet this post : How to use Lidgren with Unity3D for MMOs &#8211; Part 1"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/twitter.png" height="16"  width="16" /> <span class="head">Tweet about it</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://www.bakedon.com/2010/04/how-to-use-lidgren-with-unity3d-for-mmos-part-1/feed" title="Track this post - How to use Lidgren with Unity3D for MMOs &#8211; Part 1 - via RSS"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/rss.png" height="16"  width="16" /> <span class="head">Subscribe to the comments on this post</span></a></li>
</ul>
<div class="clean"></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bakedon.com/2010/04/how-to-use-lidgren-with-unity3d-for-mmos-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ghostees: Unity3D GUI and Facebook Integration</title>
		<link>http://www.bakedon.com/2010/02/ghostees-unity3d-gui-and-facebook-integration/</link>
		<comments>http://www.bakedon.com/2010/02/ghostees-unity3d-gui-and-facebook-integration/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 03:28:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[Ghostees]]></category>
		<category><![CDATA[unity3d]]></category>

		<guid isPermaLink="false">http://www.bakedon.com/?p=78</guid>
		<description><![CDATA[I&#8217;ve spent the last couple of days working with Unity3D&#8217;s GUI system. Here is a screenshot of the character creation screen.
I&#8217;ve also been adding Facebook integration.  So far the integration solutions for Unity3D that I&#8217;ve found so far have had huge security holes so I&#8217;ve had to come up with something myself. Not to say [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent the last couple of days working with Unity3D&#8217;s GUI system. Here is a screenshot of the character creation screen.</p>
<p>I&#8217;ve also been adding Facebook integration.  So far the integration solutions for Unity3D that I&#8217;ve found so far have had huge security holes so I&#8217;ve had to come up with something myself. Not to say it doesn&#8217;t have holes either but at least I tried to keep people from hacking the app <img src='http://www.bakedon.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span id="more-78"></span></p>
<p style="text-align: center;"><a href="http://www.bakedon.com/wp-content/uploads/2010/02/2010-02-27-Ghostees-create.png"><img class="size-full wp-image-77 aligncenter" title="2010-02-27-Ghostees-create" src="http://www.bakedon.com/wp-content/uploads/2010/02/2010-02-27-Ghostees-create.png" alt="Early Ghostees Character Create Sreenshot" width="483" height="487" /></a></p>
<p>What I&#8217;ve done is use the .NET Facebook API. I validate the Facebook user and look up their details in SimpleDB and put it all together in a class.  I serialize the class, RSA encrypt the bits salt and sign the data.  I send this as a cookie that gets picked up in the Facebook page and forwarded to Unity3D through JavaScript.</p>
<p>Unity3D takes this blob of data when establishing communication with the UDP server.  The server can then validate the signature, decrypt the data and viola.</p>
<ul class="socialwrap row">
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.bakedon.com%2F2010%2F02%2Fghostees-unity3d-gui-and-facebook-integration%2F&amp;title=Ghostees%3A+Unity3D+GUI+and+Facebook+Integration" title="Save on Delicious Ghostees: Unity3D GUI and Facebook Integration"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/delicious.png" height="16"  width="16" /> <span class="head">Bookmark on Delicious</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.bakedon.com%2F2010%2F02%2Fghostees-unity3d-gui-and-facebook-integration%2F&amp;title=Ghostees%3A+Unity3D+GUI+and+Facebook+Integration" title="Digg this post - Ghostees: Unity3D GUI and Facebook Integration"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/digg.png" height="16"  width="16" /> <span class="head">Digg this post</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.bakedon.com%2F2010%2F02%2Fghostees-unity3d-gui-and-facebook-integration%2F&#038;t=Ghostees%3A+Unity3D+GUI+and+Facebook+Integration" title="Share this post - Ghostees: Unity3D GUI and Facebook Integration"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/facebook.png" height="16"  width="16" /> <span class="head">Recommend on Facebook</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.bakedon.com%2F2010%2F02%2Fghostees-unity3d-gui-and-facebook-integration%2F&amp;title=Ghostees%3A+Unity3D+GUI+and+Facebook+Integration" title="Share on Reddit: Ghostees: Unity3D GUI and Facebook Integration"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/reddit.png" height="16"  width="16" /> <span class="head">share via Reddit</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.bakedon.com%2F2010%2F02%2Fghostees-unity3d-gui-and-facebook-integration%2F&amp;title=Ghostees%3A+Unity3D+GUI+and+Facebook+Integration" title="Submit to Stumble: Ghostees: Unity3D GUI and Facebook Integration"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/stumbleupon.png" height="16"  width="16" /> <span class="head">Share with Stumblers</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://twitter.com/home/?status=http%3A%2F%2Fwww.bakedon.com%2F2010%2F02%2Fghostees-unity3d-gui-and-facebook-integration%2F" title="Tweet this post : Ghostees: Unity3D GUI and Facebook Integration"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/twitter.png" height="16"  width="16" /> <span class="head">Tweet about it</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://www.bakedon.com/2010/02/ghostees-unity3d-gui-and-facebook-integration/feed" title="Track this post - Ghostees: Unity3D GUI and Facebook Integration - via RSS"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/rss.png" height="16"  width="16" /> <span class="head">Subscribe to the comments on this post</span></a></li>
</ul>
<div class="clean"></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bakedon.com/2010/02/ghostees-unity3d-gui-and-facebook-integration/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ghostees: Load Testing The Server</title>
		<link>http://www.bakedon.com/2010/01/ghostees-load-testing-the-server/</link>
		<comments>http://www.bakedon.com/2010/01/ghostees-load-testing-the-server/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 21:01:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Ghostees]]></category>
		<category><![CDATA[MMORPG]]></category>
		<category><![CDATA[unity3d]]></category>

		<guid isPermaLink="false">http://www.bakedon.com/?p=68</guid>
		<description><![CDATA[I created this video while I was testing the connection load of the server.  Each capsule you see is an automated connection moving randomly through the world. Since then I have changed them to actual character animations which looks way cooler but I haven&#8217;t taken time to record a video.
The server culls down how [...]]]></description>
			<content:encoded><![CDATA[<p>I created this video while I was testing the connection load of the server.  Each capsule you see is an automated connection moving randomly through the world. Since then I have changed them to actual character animations which looks way cooler but I haven&#8217;t taken time to record a video.</p>
<p><span id="more-68"></span>The server culls down how many entities the game client will see so not to overload it.  On the server I have masks that are used to categorize and prioritize what needs to be seen on any client.  Click the video to head on over to youtube.com and watch it in HD.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="292" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/kCp2-nfibzY&amp;hl=en_US&amp;fs=1&amp;rel=0" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="480" height="292" src="http://www.youtube.com/v/kCp2-nfibzY&amp;hl=en_US&amp;fs=1&amp;rel=0" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><!--more-->As of this writing, I&#8217;ve had the server up to 400 concurrent connections @ 50% cpu but in the next build I think I can double that performance.  There are many optimizations I know I can do at this point. Load has a lot to do with the number of entities that can see each other at any one time which corresponds to the number of messages I need to generate.</p>
<p>The chart below is with 95 connected entities that can all literally see each other.</p>
<p><a href="http://www.bakedon.com/wp-content/uploads/2010/01/load-with-95-npc-connections.jpg"><img class="alignnone size-medium wp-image-72" title="Server load with 95 npc connections" src="http://www.bakedon.com/wp-content/uploads/2010/01/load-with-95-npc-connections-279x300.jpg" alt="" width="279" height="300" /></a></p>
<p>As it is in that video, every entity can see every other entity within a vision radius. To achieve the 400 connections, I reduced the vision radius of NPCs and left the larger radius for actual players. This is where the masking comes in.  NPCs don&#8217;t really care about a lot of entities.  They may not care about any entities of their same race for instance.  They may only care about players or perhaps even entities of a race they are at war with.  The mask is simply a set of flags that determine who they care about seeing.  Combine this with an appropriate vision radius.  For instance, NPC&#8217;s don&#8217;t have to see as far as players. They only need to see as far as their maximum aggro radius.  On the other hand, players need to see further so that characters don&#8217;t magically warp in.</p>
<p>World design also plays a part in controlling this.  If you can see a great distance in front of you at any one time, you could potentially see a lot of entities.  Have a look carefully at the design of Orgimmar or Iron Forge in World of Warcraft.  Also think about how dungeon instances are designed. These areas are designed either to manage a high density of players or to keep game latency down to a minimum by carefully managing your visual distance.  This will keep both the client and server snappy.</p>
<p>If you have other ideas for managing this, I&#8217;d love to hear them. Please post a comment!</p>
<ul class="socialwrap row">
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.bakedon.com%2F2010%2F01%2Fghostees-load-testing-the-server%2F&amp;title=Ghostees%3A+Load+Testing+The+Server" title="Save on Delicious Ghostees: Load Testing The Server"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/delicious.png" height="16"  width="16" /> <span class="head">Bookmark on Delicious</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.bakedon.com%2F2010%2F01%2Fghostees-load-testing-the-server%2F&amp;title=Ghostees%3A+Load+Testing+The+Server" title="Digg this post - Ghostees: Load Testing The Server"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/digg.png" height="16"  width="16" /> <span class="head">Digg this post</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.bakedon.com%2F2010%2F01%2Fghostees-load-testing-the-server%2F&#038;t=Ghostees%3A+Load+Testing+The+Server" title="Share this post - Ghostees: Load Testing The Server"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/facebook.png" height="16"  width="16" /> <span class="head">Recommend on Facebook</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.bakedon.com%2F2010%2F01%2Fghostees-load-testing-the-server%2F&amp;title=Ghostees%3A+Load+Testing+The+Server" title="Share on Reddit: Ghostees: Load Testing The Server"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/reddit.png" height="16"  width="16" /> <span class="head">share via Reddit</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.bakedon.com%2F2010%2F01%2Fghostees-load-testing-the-server%2F&amp;title=Ghostees%3A+Load+Testing+The+Server" title="Submit to Stumble: Ghostees: Load Testing The Server"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/stumbleupon.png" height="16"  width="16" /> <span class="head">Share with Stumblers</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://twitter.com/home/?status=http%3A%2F%2Fwww.bakedon.com%2F2010%2F01%2Fghostees-load-testing-the-server%2F" title="Tweet this post : Ghostees: Load Testing The Server"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/twitter.png" height="16"  width="16" /> <span class="head">Tweet about it</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://www.bakedon.com/2010/01/ghostees-load-testing-the-server/feed" title="Track this post - Ghostees: Load Testing The Server - via RSS"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/rss.png" height="16"  width="16" /> <span class="head">Subscribe to the comments on this post</span></a></li>
</ul>
<div class="clean"></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bakedon.com/2010/01/ghostees-load-testing-the-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ghostees: Server Technology</title>
		<link>http://www.bakedon.com/2008/07/ghostees-server-technology/</link>
		<comments>http://www.bakedon.com/2008/07/ghostees-server-technology/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 06:07:09 +0000</pubDate>
		<dc:creator>Tricky</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Ghostees]]></category>
		<category><![CDATA[Ghostees server technology]]></category>
		<category><![CDATA[MMORPG]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.bakedon.com/?p=31</guid>
		<description><![CDATA[Ghostees is not just an RPG, it is a proof of concept of the server platform. The server platform is designed so that we can develop additional MMORPG-style games and leverage all that back end technology as much as possible.
The server technology is interesting. Our background is primarily in high performance serverdevelopment. We wanted a [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Ghostees: Flash MMORPG Virtual World" href="http://www.ghostees.com" target="_blank">Ghostees</a> is not just an RPG, it is a proof of concept of the server platform. The server platform is designed so that we can develop additional MMORPG-style games and leverage all that back end technology as much as possible.<span id="more-31"></span></p>
<p>The server technology is interesting. Our background is primarily in <a title="Second largest DNS server on the planet" href="http://royal.pingdom.com/?p=125" target="_blank">high performance server</a>development. We wanted a design that could scale to support a very large number of players. Who doesn&#8217;t? Server-side tasks are logically divided into services and architected so that they can run and live independently on remote hardware. This way we can distribute the load based on capacities any particular service can handle.</p>
<p>Servers are auto discoverable and communicate with each other efficiently over <a title="UDP Reference" href="http://en.wikipedia.org/wiki/User_Datagram_Protocol" target="_blank">UDP</a>. This is a huge benefit. As servers come on and offline, we don&#8217;t need to do any reconfiguring of dependent servers. They are designed to locate the appropriate service by dropping a service discovery packet on the network. All servers that provide that service respond with server information and current server load. This way the seeking server can choose among servers with more available capacity.</p>
<blockquote><p>Servers are auto discoverable and communicate with each other efficiently over UDP</p></blockquote>
<p>For instance we have a combat service. All it does is create and maintain a combat encounter for a set of entities (players and NPCs). A <a title="Ghostees: Flash MMORPG Virtual World" href="http://www.ghostees.com" target="_blank">Ghostees</a>player initiating combat will cause the player&#8217;s gateway server to request a combat encounter instance on an available combat server. Other players and NPCs can join a combat encounter even if they are <strong>not </strong>on the same gateway.</p>
<p>A gateway is the server a player&#8217;s browser communicates directly with. It takes care of the core <a title="RTMP Reference" href="http://en.wikipedia.org/wiki/Real_Time_Messaging_Protocol" target="_blank">RTMP</a> / <a title="AMF Reference" href="http://en.wikipedia.org/wiki/Action_Message_Format" target="_blank">AMF</a>stuff that Flash communicates with natively. It is also responsible for persisting player information to the database and also for facilitating access to the other servers in the system. It does not do chat, movement, routing or even quests or NPC AI. Those are all different services potentially running elsewhere.</p>
<p style="text-align: center;"><a title="Ghostees: Flash MMORPG Virtual World" href="http://www.ghostees.com" target="_blank"><img class="size-medium wp-image-34 aligncenter" title="Ghostees Flash MMORPG Logo" src="http://www.bakedon.com/wp-content/uploads/2008/07/ghostees_logo_color.jpg" alt="Ghostees Flash MMORPG Logo" width="256" height="128" /></a></p>
<p>A zone server is responsible for simply tracking the entrance/exit and movement of entities. When an entity enters a zone (player or NPC), the zone broadcasts to all connected gateways that they need to subscribe to this new entity. It also sends messages back to the connecting player information about the zone, such as graphic asset information, music, collision layers and other existing entities.</p>
<blockquote><p>To a zone server, an NPC looks just like any other player.</p></blockquote>
<p>On each simulation step the zone server updates the positions of entities it knows about. When a player or NPC requests a route to a new destination, the zone server facilitates the route calculation, obstacle avoidance and potential zone transfers. Once the route is calculated it is sent to the requesting entity. This overrides any predicted route done by the client.  It&#8217;s pretty cool actually!</p>
<p>NPC AI runs on their own gateway server. To a zone server, an NPC looks just like any other player. NPCs can be scripted to request routes and respond to player interactions among other things just like a player.</p>
<p>I think your getting the idea by now. We&#8217;re really enjoying working with this design. It&#8217;s quite flexible and powerful.</p>
<ul class="socialwrap row">
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.bakedon.com%2F2008%2F07%2Fghostees-server-technology%2F&amp;title=Ghostees%3A+Server+Technology" title="Save on Delicious Ghostees: Server Technology"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/delicious.png" height="16"  width="16" /> <span class="head">Bookmark on Delicious</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.bakedon.com%2F2008%2F07%2Fghostees-server-technology%2F&amp;title=Ghostees%3A+Server+Technology" title="Digg this post - Ghostees: Server Technology"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/digg.png" height="16"  width="16" /> <span class="head">Digg this post</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.bakedon.com%2F2008%2F07%2Fghostees-server-technology%2F&#038;t=Ghostees%3A+Server+Technology" title="Share this post - Ghostees: Server Technology"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/facebook.png" height="16"  width="16" /> <span class="head">Recommend on Facebook</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.bakedon.com%2F2008%2F07%2Fghostees-server-technology%2F&amp;title=Ghostees%3A+Server+Technology" title="Share on Reddit: Ghostees: Server Technology"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/reddit.png" height="16"  width="16" /> <span class="head">share via Reddit</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.bakedon.com%2F2008%2F07%2Fghostees-server-technology%2F&amp;title=Ghostees%3A+Server+Technology" title="Submit to Stumble: Ghostees: Server Technology"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/stumbleupon.png" height="16"  width="16" /> <span class="head">Share with Stumblers</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://twitter.com/home/?status=http%3A%2F%2Fwww.bakedon.com%2F2008%2F07%2Fghostees-server-technology%2F" title="Tweet this post : Ghostees: Server Technology"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/twitter.png" height="16"  width="16" /> <span class="head">Tweet about it</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://www.bakedon.com/2008/07/ghostees-server-technology/feed" title="Track this post - Ghostees: Server Technology - via RSS"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/rss.png" height="16"  width="16" /> <span class="head">Subscribe to the comments on this post</span></a></li>
</ul>
<div class="clean"></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bakedon.com/2008/07/ghostees-server-technology/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ghostees Technology: The Client</title>
		<link>http://www.bakedon.com/2007/11/ghostees-technology-the-client/</link>
		<comments>http://www.bakedon.com/2007/11/ghostees-technology-the-client/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 18:14:39 +0000</pubDate>
		<dc:creator>Tricky</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.bakedon.com/2007/11/ghostees-technology-the-client/</guid>
		<description><![CDATA[There are many pieces that collectively make Ghostees work. It has a distributed design that allows us to spread the load between many servers and provide the very fast throughput for all players.
The most obvious piece is the game client. This is the part that everyone sees. It is a Flash based application that runs [...]]]></description>
			<content:encoded><![CDATA[<p>There are many pieces that collectively make <a href="http://www.ghostees.com" title="Ghostees holiday virtual world for kids" target="_blank">Ghostees</a> work. It has a distributed design that allows us to spread the load between many servers and provide the very fast throughput for all players.<span id="more-9"></span></p>
<p>The most obvious piece is the game client. This is the part that everyone sees. It is a Flash based application that runs in your browser written with the Flex 2 SDK. Some of us use Flex Builder and some like to just build from the command line and use other text editors.</p>
<p>The client itself is made up of many pieces that get downloaded on demand to reduce the initial download size. The Ghostees world is very large and would take a very long time to download if you had to get the whole thing at startup. Static content, such as artwork and images, is delivered from <a href="http://cachefly.com/demo.html" title="CacheFly">CacheFly</a>. CacheFly is a content delivery system designed for very high speed and 100% uptime availability.</p>
<p>One distictive feature of Ghostees is the smooth scrolling of the world rather than going &#8220;screen-to-screen&#8221; as is more common in other virtual worlds. The way we accomplish this is by downloading the pieces of the world that are nearby only when they are needed and we can discard pieces that are no longer needed to save memory. The browser caches the previous downloads for us so subsequent requests to download world pieces are much faster.</p>
<p>The client talks to a variety of servers to not only get content but also take direction and negotiate transactions. Each server has a distinct job so that the overall application can be spread out. One of the most important servers that I&#8217;ll talk about in another post is the Map Server. This server is responsible for any given portion of the world. The Map Server is where everything &#8220;lives&#8221; and the client is just a viewport into it, responding to direction given by the server. In all cases the Map Server is the authority to what is going on in the world.</p>
<p>To take care of the inevitable network latency, one of the client&#8217;s jobs is to smooth this out. The client makes predictions of what the server is going to say and will initiate actions based on those predictions and uses the server&#8217;s message as confirmation. If the server issues a different message than expected, it is up to the client to smooth out the discrepancy.</p>
<p>Other servers include the Authentication, Chat, Auditing, Exchange (not mail but game currency), the API, Inventory/Shopping and a Mini-Game Server per Mini Game. All of these <em>could</em> run on a single box if that&#8217;s all we needed but the system was designed to scale out based on demand. The goal is to be able to pack as many people into the world as we can by distributing the work and keep the experience as fluid as possible.</p>
<ul class="socialwrap row">
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.bakedon.com%2F2007%2F11%2Fghostees-technology-the-client%2F&amp;title=Ghostees+Technology%3A+The+Client" title="Save on Delicious Ghostees Technology: The Client"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/delicious.png" height="16"  width="16" /> <span class="head">Bookmark on Delicious</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.bakedon.com%2F2007%2F11%2Fghostees-technology-the-client%2F&amp;title=Ghostees+Technology%3A+The+Client" title="Digg this post - Ghostees Technology: The Client"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/digg.png" height="16"  width="16" /> <span class="head">Digg this post</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.bakedon.com%2F2007%2F11%2Fghostees-technology-the-client%2F&#038;t=Ghostees+Technology%3A+The+Client" title="Share this post - Ghostees Technology: The Client"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/facebook.png" height="16"  width="16" /> <span class="head">Recommend on Facebook</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.reddit.com/submit?url=http%3A%2F%2Fwww.bakedon.com%2F2007%2F11%2Fghostees-technology-the-client%2F&amp;title=Ghostees+Technology%3A+The+Client" title="Share on Reddit: Ghostees Technology: The Client"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/reddit.png" height="16"  width="16" /> <span class="head">share via Reddit</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank"  href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.bakedon.com%2F2007%2F11%2Fghostees-technology-the-client%2F&amp;title=Ghostees+Technology%3A+The+Client" title="Submit to Stumble: Ghostees Technology: The Client"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/stumbleupon.png" height="16"  width="16" /> <span class="head">Share with Stumblers</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://twitter.com/home/?status=http%3A%2F%2Fwww.bakedon.com%2F2007%2F11%2Fghostees-technology-the-client%2F" title="Tweet this post : Ghostees Technology: The Client"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/twitter.png" height="16"  width="16" /> <span class="head">Tweet about it</span></a></li>
<li class="iconOnly"><a rel="nofollow" target="_blank" href="http://www.bakedon.com/2007/11/ghostees-technology-the-client/feed" title="Track this post - Ghostees Technology: The Client - via RSS"><img src="http://www.bakedon.com/wp-content/plugins/share-and-follow/default/16/rss.png" height="16"  width="16" /> <span class="head">Subscribe to the comments on this post</span></a></li>
</ul>
<div class="clean"></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bakedon.com/2007/11/ghostees-technology-the-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
