The MUES Event Model

Overview

The MUES server is an event-driven server, which means that most of the activity that goes on in it is represented by the creation and dispatch of event objects. These events act as asynchronous function calls between parts of the server, and also between objects in the environments hosted by the server.

<p>For example, when someone connects to the server's listener socket, the following actions are taken:<br> <ol>

<li>Client connects to the listener socket</li> <li>Server generates a <code>SocketConnectEvent?</code></li> <li>The <code>SocketConnectEvent?</code> is dispatched to a security function to check for banned IPs, etc.</li> <li>If the security function succeeds, it creates a new player object. The player object's <code>IOEvent Stream?</code> handles authentication.</li> <li>If the user authenticates correctly, the Player object generates a <code>PlayerLoginEvent?</code>. If the user fails to authenticate, a <code>PlayerLoginFailureEvent?</code> is generated and dispatched instead.</li> <li>If the user disconnects without logging out sometime during the session a <code>PlayerDisconnectEvent?</code> is generated.</li> <li>When the player eventually logs out, a <code>PlayerLogoutEvent?</code> is generated.</li>

</ol></p>

Dispatch

<p>Events are dispatched by the Engine from an event queue which contains a scaled thread crew. The events are dispatched by calling <nobr><code>handleEvent( eventObject )</code></nobr> on each object which has registered itself as a handler for that particular type of event or one of its superclasses.</p>

<p>For example, the server's ObjectStore should receive any requests to store a game object, which will occur as a <code>SaveGameObjectEvent?</code>. This is accomplished by registering the ObjectStore as being interested in <code>SaveGameObjectEvent?</code>s:<br>

<pre> require "mues/ObjectStore" require "mues/Events"

objectStore = MUES::ObjectStore.new( "Bdb", "The Real World" ) engine().registerHandlerForEvents( objectStore, MUES::SaveGameObjectEvent? ) </pre></p>

<p>When an object needs to be saved to the ObjectStore, a <code>SaveGameObjectEvent?</code> is generated with the object to be saved as an attribute, and handed to the Engine for dispatch:<br>

<pre> ev = SaveGameObjectEvent?.new( objectToSave ) engine().dispatchEvents( ev ) </pre></p>

<p>This causes the event to be added to the server's event queue, and when a thread becomes available, the event will be handed to whatever objects have registered themselves with the <code>SaveGameObjectEvent?</code>, including the <code>ObjectStore</code> object.</p>