= Network = == Overview == The image below displays the basic concept of the Network Engine: [[Image(conceptoverview.png, 100%)]] The basic jobs of the Network Engine are: * Synchronise all objects of the universe between server and clients * Provide a chatting mechanism * Transmit all neccessary information about the players (nickname, score, ...) The server and client components manage all the other network components. They call all necessary functions every network tick (not exactly the same as a game tick). == Components == This is a description of the important network components and/or classes: || '''Component''' || '''Description''' || '''Classes included''' || || [wiki:network/Host Host] || Interface class of the Network Engine || Host, Server, Client, ClientInformation || || [wiki:network/Gamestate Gamestate] || Management of the object information to be synchronised || GamestateHandler, GamestateManager, GamestateClient || || [wiki:network/Packet Packet] || Management of the data to be transmitted || Packet, Acknowledgement, Chat, ClassID, DeleteObjects, Gamestate, Welcome || || [wiki:network/Connection Connection] || Management of the network connection between server and client || ConnectionManager, ClientConnection || || [wiki:network/Synchronisable Synchronisable] || Interface class for all network objects, that need synchronisation || Synchronisable || == External API == === Synchronisable === The most important part of the Network API is the Synchronisable Class (see also [wiki:network/Synchronisable Synchronisable]): * This class provides the functionality for objects to get synchronised over the network: * REGISTERDATA/REGISTERSTRING: these functions register a variable (to the Network Engine) that needs synchronisation * setObjectMode: this function sets the direction of synchronisation (server->client / server<->client / server<-client) * Every class that needs synchronisation must fullfill some dependencies: * It must (public) inherit from Synchronisable * It must have a default constructor * All steps in object creation that need data (from the levelfile or the network) must be in the create() function * It must implement the following functions: * registerAllVariables: register all variables (currently only basic types and strings), that need synchronisation, to the network engine by calling REGISTERDATA and/or REGISTERSTRING * create: (as described above) * set appropriate synchronisation direction (default: server->client) by calling setObjectMode ''' Synchronisable functions:'''[[BR]] ''REGISTERDATA(varname)''[[BR]] Use this makro to synchronise a membervariable of a class (like position, velocity, ...). This makro sets the sync-direction of the variable to server->client {{{ int SomeClass::i; // membervariable i REGISTERDATA(i); }}} ''REGISTERDATA_WITHMODE(varname, mode)''[[BR]] Use this makro if you want to sync a variable using a different direction than the default. {{{ int SomeClass::i; //membervariable i REGISTERDATA_WITHMODE(i, network::direction::toclient); //same as REGISTERDATA(i) //or REGISTERDATA_WITHMODE(i, network::direction::toserver); //sync i only to the server (be carefull when using this) //or REGISTERDATA_WITHMODE(i, network::direction::bidirectional); //sync i in both directions }}} ''REGISTERSTRING(stringname)''[[BR]] same as REGISTERDATA but for strings ''REGISTERSTRING_WITHMODE(stringname, mode)''[[BR]] same as REGISTERDATA_WITHMODE but for strings ''setObjectMode''[[BR]] this sets the sync direction of the whole object (default: server->client). '''Note:''' if you don't call setObjectMode with a value other than network::direction::toclient then the variables will only be synchronised to the client (if at all) === Host ===