/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: christoph co-programmer: */ /* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput */ #define DEBUG_MODULE_NETWORK #include "handshake.h" #include "network_log.h" #include Handshake::Handshake( bool server, int clientId, int networkGameManagerId, int messageManagerId ) : Synchronizeable() { /* set the class id for the base object */ this->setClassID(CL_HANDSHAKE, "Handshake"); this->setIsServer(server); orxId_handler = registerVarId( new SynchronizeableInt( &localState.orxId, &remoteState.orxId, "orxonoxId", PERMISSION_ALL ) ); version_handler = registerVarId( new SynchronizeableInt( &localState.version, &remoteState.version, "version", PERMISSION_ALL ) ); netManId_handler = registerVarId( new SynchronizeableInt( &localState.networkManagerId, &remoteState.networkManagerId, "networkManagerId", PERMISSION_ALL ) ); msgManId_handler = registerVarId( new SynchronizeableInt( &localState.messageManagerId, &remoteState.messageManagerId, "messageManagerId", PERMISSION_ALL ) ); hostId_handler = registerVarId( new SynchronizeableInt( &localState.hostId, &remoteState.hostId, "hostId", PERMISSION_ALL ) ); completed_handler = registerVarId( new SynchronizeableInt( &localState.completed, &remoteState.completed, "completed", PERMISSION_ALL ) ); error_handler = registerVarId( new SynchronizeableInt( &localState.error, &remoteState.error, "error", PERMISSION_ALL ) ); errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", PERMISSION_ALL ) ); localState.completed = 0; localState.error = 0; localState.errorString = ""; localState.hostId = clientId; localState.networkManagerId = networkGameManagerId; this->localState.messageManagerId = messageManagerId; localState.orxId = _ORXONOX_ID; localState.version = _ORXONOX_VERSION; remoteState.completed = 0; remoteState.error = 0; remoteState.errorString = ""; remoteState.hostId = -1; remoteState.networkManagerId = -1; remoteState.messageManagerId = -1; remoteState.orxId = 0; remoteState.version = 0; this->setSynchronized(true); PRINTF(0)("Handshake created clientId = %d\n", clientId); } /** * handler for changes in synced vars * @param id id's which have changed */ void Handshake::varChangeHandler( std::list< int > & id ) { for ( std::list::iterator it = id.begin(); it != id.end(); it++ ) { if ( *it == orxId_handler ) { if ( remoteState.orxId != _ORXONOX_ID ) { localState.error = 1; localState.completed = 1; localState.errorString = "Seems not to be orxonox!"; return; } else if ( remoteState.version -= _ORXONOX_VERSION ) localState.completed = 1; } if ( *it == version_handler ) { if ( remoteState.version != _ORXONOX_VERSION ) { localState.error = 2; localState.completed = 1; localState.errorString = "Versions of server and client do not match!"; return; } else if ( remoteState.orxId == _ORXONOX_ID ) localState.completed = 1; } } PRINTF(0)("=======================BEGIN============================="); for ( std::list::iterator it = id.begin(); it != id.end(); it++ ) { if ( *it == netManId_handler ) PRINTF(0)("netManId_handler\n"); if ( *it == msgManId_handler ) PRINTF(0)("msgManId_handler\n"); if ( *it == hostId_handler ) PRINTF(0)("hostId_handler\n"); if ( *it == completed_handler ) PRINTF(0)("completed_handler\n"); if ( *it == error_handler ) PRINTF(0)("error_handler\n"); if ( *it == errorString_handler ) PRINTF(0)("errorString_handler\n"); if ( *it == orxId_handler ) PRINTF(0)("orxId_handler\n"); if ( *it == version_handler ) PRINTF(0)("version_handler\n"); } PRINTF(0)("========================================================="); }