HTTPMP - multi-player game server over HTTP =========================================== HTTPMP (c) Guido Wesdorp, 2007 All rights reserved. What is it? ----------- HTTPMP is a framework for building real-time multi-player games that are networked over HTTP. It features a built-in web-server that supports many clients at the same time (of course performance of the game can be an issue) and provides a set of simple interfaces and APIs that allow building complex real-time games. How does it work? ----------------- On booting an instance of the Engine (see engine.py), an HTTPServer (see httpserver.py) is started, and the game is initialized. The server exposes two paths (URLs): one as '/out' and one as '/in'. When an event occurs on a client, it is sent to the server using a GET request (XMLHttpRequest) to '/in'. When such an event is received, a ClientEvent (see clientevent.py) object is created, and placed in the Client's (see client.py) InChannel (see inchannel.py). A number of times (config.fps, see config.py) per second, the InChannels for all Clients are emptied, and FrameState (see framestate.py) objects are created out of the ClientEvents contained, which form a snapshot of the state of all the client's buttons, and a list of additional (custom) events. After this has been done, the Game's (see game.py) state gets updated, and Command (see command.py) instances are generated for all Sprites (see game.py) and the Game itself, which provide information for the client about where to render sprites, game score, etc. The Command instances are written to the output channel of the Client, and the cycle is restarted. Main components --------------- Engine ++++++ The engine class forms the core of the application, and glues together the other components. Client ++++++ Each connected client, a Client class is instantiated that holds references to the InChannel and the outchannel (HTTPChannel, see httpserver.py). InChannel +++++++++ The InChannel class receives the ClientEvents from a single client, and places them in a FIFO (after some processing) so the Engine can read them later. HTTPServer ++++++++++ A simple (asynchronous) web server that provides a path to write (POST) ClientEvent data to, and one to read (GET) ServerEvents from. A dictionairy is used to hold info about what handlers should be used for what paths, handlers are iterators or generators, but allow 'breaking out' of the loop to for instance hand control over to other threads. FrameState ++++++++++ The state of a client (what keys are pressed, where the mouse is, etc.) on a single moment in time. ClientEvent +++++++++++ An event (usually keypress) originating on the client - when an event on the client occurs (if a handler is registered for it), the event is serialized and sent over to the server as the body of an HTTP request. On the server, a ClientEvent is created for the request and placed in an InChannel queue. A couple of times per second (depending on config.framerate), the queued events are processed into a FrameState and passed to the Game and Sprite instances that are alive at that point to allow them to calculate their new state. Command +++++++ This is a producer for the asynchat web server (see the asyncore documentation for more details about such producers) that holds the commands to send to the client. Such commands direct the client to add, remove or re-position sprites, update scores, display chat messages, etc. After each frame, the Commands for that frame are placed in the outchannel so they can be picked up by the webserver as response data. Game ++++ The 'game world' of a game, holds the state and logic of a game. The game contains functionality to manage sprites, maintain and update state, and serialize the state to a Command which contain the commands sent to the client to allow it to update its view. Sprite ++++++ A game object that holds state and logic. Copyright notice ++++++++++++++++ Currently this code is not licensed, but all is (c) Guido Wesdorp 2007, and usage in any form is currently (development period) strictly forbidden and will afterwards be subject to an EULA.