• Welcome to SC4 Devotion Forum Archives.

Server Documentation

Started by croxis, October 03, 2009, 10:36:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

croxis

This is a draft of the server implementation.  I hope to get it into actual python documentation using http://sphinx.pocoo.org/ as soon as I can figure out how to get it to work ;)

The Simulation Server is written with the Model-View-Controller paradigm in mind and syntax loosely based on the Panda3D engine. It is a Python 2.6 program using python and c/c++ with python bindings.

The primary means of communication is with the messenger system.  The module in question will need to inherent engine.py. This will place the messenger instance into the top level name system. A message is sent with the following call

messenger.post("eventNameString", [item1, item2])

The event manager identifies events using strings. The second parameter is a list of parameters to be passed to the receiving function (more on this later).

In order for a function to listen for an event it must be part of a function that inherits the Entity class from engine.py.  The class then registers any functions it wishes with any event using the self.accept() function.  Example:
import engine
class MyClass(engine.Entity):
    def __init__(self):
        self.accept("eventNameString", self.aFunction)
    def self.aFunction(parameter1, parameter2):
        pass

myclass = MyClass()

self.accept takes two parameters: the event string that it is listening for and the function to be executed when that event is posted.  Note that the event in the first code sample will pass item1 and item2 into the function variables parameter1 and parameter2.

#TODO: Finish network data handling

Please post any comments on the documentation or how the server works

croxis

Network objects are transmitted using google protocol buffer objects.  These objects are processed in the CommandProcessor object and then converted to the engine message system.  The first parameter is the peer tuple.  This is the player id as (ip, port).  This will probably be modified in the future.

Broadcasting data to all clients is used with the broadcastData message.
messenger.send("broadcastData", [protocolObject])
protocolObject is a valid protocol object.  To send data to a specific user the event should be "sendData"
messenger.send("sendData", [peer, protocolObject])
peer is a valid peer tuple

tomkeus

Why does server needs 3D engine?
#define TRUE FALSE /*Happy debugging suckers*/

croxis

#3
There is no 3D engine in the server. Modified post to clear up language,