SC4 Devotion Forum Archives

Other City-Building Games => [Archived] CityMania - Open Source Sim City => Other games => CityMania Programming => Topic started by: croxis on October 03, 2009, 10:36:07 PM

Title: Server Documentation
Post by: croxis on October 03, 2009, 10:36:07 PM
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
Title: Re: Server Documentation
Post by: croxis on October 04, 2009, 03:35:43 PM
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
Title: Re: Server Documentation
Post by: tomkeus on October 05, 2009, 02:47:53 AM
Why does server needs 3D engine?
Title: Re: Server Documentation
Post by: croxis on October 05, 2009, 08:49:49 AM
There is no 3D engine in the server. Modified post to clear up language,