Server Code

From UODemo Wiki
Jump to: navigation, search

The core versus The runtime engine.

The server side consist of atleast 3 big engines:

1) the communication engine (sending and receiving packets)
2) the time manager
3) the runtime engine


The communication engine

Inside the main loop of the server the sequence is always:

1) receive packets
2) send packets
3) handle packets
4) execute the time manager

After packets are received they are handled immediately. If a new packet needs to be sent it will be put in a buffer that's send on the next loop.


The runtime engine

The runtime engine executes the scripts, scripts are linked either in the template stable (a file containing all object definitions) or the skill table (a file containing all skill definitions). Thus the runtime engine is not really an engine on its own but gets called through player interaction and through the time manager in case of events.

A complete list of commands the scripts can use has been published here: Ultima Online Demo Command List

The event system

Inside the scripts we can find event function definitions. Since scripts are attached (dynamically) to objects those events are attached to the objects too. When an event is triggered then the related event function is executed (operating on the specific object). The events are triggered throughout the server code depending on the event meaning. For example, the "washit" (was hit) event is triggered when damage is applied to a mobile and when "doDamageXXX" functions are called. Another method of triggering an event is the "triggerScript" function which is used in some scripts like the "dragonai" script.

Event definitions can preceeded with a number between 0 and 1000. This number is a chance indicator. The following check can be found inside the server code:

// EIP=004CE288
if(event_chance == 1000)
{
  // add event to the execute list
}
else if(rand() & 0x3FF < event_chance)
{
  // add event to the execute list
}

Event functions must return a number either 0 or 1. When the returned value is 0 then the remaining triggers are not executed. This was found by testing only and has not yet been proved inside the server code!