Changeset 9347 in orxonox.OLD for branches/proxy/src
- Timestamp:
- Jul 20, 2006, 11:43:27 AM (18 years ago)
- Location:
- branches/proxy/src
- Files:
-
- 4 deleted
- 61 edited
- 21 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/defs/class_id.h
r9235 r9347 127 127 CL_NETWORK_MANAGER = 0x00000050, 128 128 CL_SHARED_NETWORK_DATA = 0x00000051, 129 CL_PROXY_SETTINGS = 0x00000052, 129 130 CL_ATMOSPHERIC_ENGINE = 0x00000061, 130 131 … … 422 423 CL_PLAYER_STATS = 0x00000d09, 423 424 CL_SIMPLE_SYNC = 0x00000d0a, 425 CL_NETWORK_MONITOR = 0x00000d0b, 424 426 425 427 -
branches/proxy/src/lib/collision_detection/obb_tree_node.cc
r9235 r9347 434 434 } 435 435 } 436 delete [] triangleCenter; 436 437 PRINTF(4)("\nPartition1: got \t%i Vertices \nPartition2: got \t%i Vertices\n", partition1.size(), partition2.size()); 437 438 … … 476 477 return; 477 478 478 float distanceMax = this->bvElement->radius + ((OBBTreeNode*)treeNode)->bvElement->radius;479 float distance = fabs((nodeA->getAbsCoor() - nodeB->getAbsCoor()).len());479 // float distanceMax = this->bvElement->radius + ((OBBTreeNode*)treeNode)->bvElement->radius; 480 // float distance = fabs((nodeA->getAbsCoor() - nodeB->getAbsCoor()).len()); 480 481 481 482 -
branches/proxy/src/lib/coord/p_node.h
r8711 r9347 20 20 21 21 #include "base_object.h" 22 #include "stdincl.h"23 22 #include "synchronizeable.h" 24 23 … … 112 111 /** @returns the absolute position */ 113 112 inline const Vector& getLastAbsCoor () const { return this->lastAbsCoordinate; }; 114 113 115 114 void shiftCoor (const Vector& shift); 116 115 void shiftCoor (float x, float y, float z) { this->shiftCoor(Vector(x, y, z)); }; -
branches/proxy/src/lib/graphics/effects/snow_effect.cc
r9235 r9347 1 1 /* 2 3 4 5 6 7 8 9 2 orxonox - the future of 3D-vertical-scrollers 3 4 Copyright (C) 2004 orx 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: hdavid, amaechler 13 13 */ 14 14 … … 35 35 SHELL_COMMAND(deactivate, SnowEffect, deactivateSnow); 36 36 37 using namespace std;38 37 39 38 CREATE_SCRIPTABLE_CLASS(SnowEffect, CL_SNOW_EFFECT, … … 46 45 SnowEffect::SnowEffect(const TiXmlElement* root) 47 46 { 48 this->setClassID(CL_SNOW_EFFECT, "SnowEffect"); 49 50 this->init(); 51 52 if (root != NULL) 53 this->loadParams(root); 54 55 //load wind sound 56 if (this->snowWindForce >= 1) { 57 if (this->windBuffer != NULL) 58 ResourceManager::getInstance()->unload(this->windBuffer); 59 this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV); 60 } 47 this->setClassID(CL_SNOW_EFFECT, "SnowEffect"); 48 49 this->init(); 50 51 if (root != NULL) 52 this->loadParams(root); 53 54 this->windBuffer = NULL; 55 //load wind sound 56 if (this->snowWindForce >= 1) { 57 this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV); 58 } 61 59 62 60 if(snowActivate) { 63 61 this->activate(); 64 62 SnowEffect::snowParticles->precache((int) this->snowLife); 65 63 } … … 69 67 SnowEffect::~SnowEffect() 70 68 { 71 69 this->deactivate(); 72 70 } 73 71 … … 76 74 void SnowEffect::loadParams(const TiXmlElement* root) 77 75 { 78 79 80 81 82 83 84 85 86 87 88 89 76 WeatherEffect::loadParams(root); 77 78 LoadParam(root, "numParticles", this, SnowEffect, numParticles); 79 LoadParam(root, "materialTexture", this, SnowEffect, materialTexture); 80 LoadParam(root, "lifeSpans", this, SnowEffect, lifeSpan); 81 LoadParam(root, "radius", this, SnowEffect, radius); 82 LoadParam(root, "mass", this, SnowEffect, mass); 83 LoadParam(root, "emissionRate", this, SnowEffect, emissionRate); 84 LoadParam(root, "emissionVelocity", this, SnowEffect, emissionVelocity); 85 LoadParam(root, "wind", this, SnowEffect, wind); 86 LoadParam(root, "size", this, SnowEffect, size); 87 LoadParam(root, "coord", this, SnowEffect, coord); 90 88 LoadParam(root, "cloudcolor", this, SnowEffect, setCloudColor); 91 89 LoadParam(root, "skycolor", this, SnowEffect, setSkyColor); 92 90 LoadParam(root, "fadetime", this, SnowEffect, setFadeTime); 93 91 94 95 96 97 98 92 LOAD_PARAM_START_CYCLE(root, element); 93 { 94 LoadParam_CYCLE(element, "option", this, SnowEffect, setSnowOption); 95 } 96 LOAD_PARAM_END_CYCLE(element); 99 97 } 100 98 101 99 void SnowEffect::init() 102 100 { 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 101 this->emitter = new PlaneEmitter(); 102 103 // Default values 104 this->snowActivate = false; 105 this->snowMove = false; 106 this->particles = 12000; 107 this->texture = "maps/snow_flake_01_32x32.png"; 108 this->snowLife = 8; 109 this->randomLife = 2; 110 this->snowRadius = 3.5; 111 this->randomRadius = 1; 112 this->snowMass = 1.0; 113 this->randomMass = 0.3; 114 this->rate = 900; 115 this->velocity = -100; 116 this->randomVelocity = 5; 117 this->angle = 0.5; 118 this->randomAngle = 0.2; 119 this->alpha = 0.5; 120 this->snowSize = Vector2D(2500, 2500); 121 this->snowCoord = Vector(100,450,400); 122 this->snowWindForce = 1; 123 126 124 this->fadeTime = 10; 127 125 this->cloudColor = Vector(0.2f, 0.2f, 0.2f); … … 131 129 void SnowEffect::activate() 132 130 { 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 131 PRINTF(3)("Activating SnowEffect\n"); 132 133 this->snowActivate = true; 134 135 SnowEffect::snowParticles = new SpriteParticles(particles); 136 SnowEffect::snowParticles->setName("SnowEffectTrailParticles"); 137 SnowEffect::snowParticles->setMaterialTexture(texture); 138 SnowEffect::snowParticles->setLifeSpan(snowLife, randomLife); 139 SnowEffect::snowParticles->setRadius(0.0, snowRadius, randomRadius); 140 SnowEffect::snowParticles->setRadius(0.2, snowRadius, randomRadius*0.8); 141 SnowEffect::snowParticles->setRadius(1.0, snowRadius, randomRadius*0.5); 142 SnowEffect::snowParticles->setMass(0, snowMass, randomMass); 143 SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); 144 SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); 145 SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); 146 147 this->emitter->setSystem(SnowEffect::snowParticles); 148 149 this->emitter->setRelCoor(snowCoord); 150 this->emitter->setEmissionRate(rate); 151 this->emitter->setEmissionVelocity(velocity, randomVelocity); 152 this->emitter->setSpread(angle * this->snowWindForce , randomAngle * this->snowWindForce); 153 this->emitter->setSize(snowSize); 156 154 157 155 if (this->snowWindForce != 0) 158 156 this->soundSource.play(this->windBuffer, 0.1f * this->snowWindForce, true); 159 157 160 158 // Store cloud- and sky color before the snow 161 159 this->oldCloudColor = CloudEffect::cloudColor; … … 171 169 void SnowEffect::deactivate() 172 170 { 173 174 175 176 177 178 179 180 171 PRINTF(3)("Deactivating SnowEffect\n"); 172 173 this->snowActivate = false; 174 this->emitter->setSystem(NULL); 175 176 if (this->windBuffer != NULL) 177 ResourceManager::getInstance()->unload(this->windBuffer); 178 181 179 // Restore the old cloud- and sky color 182 180 CloudEffect::changeCloudColor(this->oldCloudColor, this->fadeTime); … … 186 184 void SnowEffect::draw() const 187 185 { 188 189 186 if (!this->snowActivate) 187 return; 190 188 } 191 189 192 190 void SnowEffect::tick(float dt) 193 191 { 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 } 192 if (!this->snowActivate) 193 return; 194 195 /* 196 float distance = (State::getCameraNode()->getAbsCoor() - Vector(snowCoord.x, State::getCameraNode()->getAbsCoor().y, snowCoord.z)).len(); 197 198 if(activated) 199 { 200 if(distance > 0.3*snowSize.x || distance > 0.3*snowSize.y) 201 this->deactivate(); 202 else if(distance > 0.25*snowSize.x || distance > 0.25*snowSize.y) 203 this->alpha = 0.15; 204 else if(distance > 0.2*snowSize.x || distance > 0.2*snowSize.y) 205 this->alpha = 0.25; 206 else if(distance > 0.1*snowSize.x || distance > 0.1*snowSize.y) 207 this->alpha = 0.4; 208 209 SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); 210 SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); 211 SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); 212 } 213 else 214 { 215 if(distance < 0.3*snowSize.x || distance < 0.3*snowSize.y ) 216 this->activate(); 217 if( distance < 0.25*snowSize.x || distance < 0.25*snowSize.y ) 218 this->alpha = 0.25; 219 else if( distance < 0.2*snowSize.x || distance < 0.2*snowSize.y ) 220 this->alpha = 0.4; 221 else if( distance < 0.1*snowSize.x || distance < 0.1*snowSize.y ) 222 this->alpha = 0.5; 223 224 SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); 225 SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); 226 SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); 227 }*/ 228 229 if (this->snowMove) { 230 this->snowCoord = State::getCameraNode()->getAbsCoor(); 231 this->emitter->setRelCoor(this->snowCoord.x , this->snowCoord.y+300, this->snowCoord.z); 232 } 233 } -
branches/proxy/src/lib/graphics/effects/snow_effect.h
r9235 r9347 101 101 102 102 private: 103 int particles;103 int particles; 104 104 std::string texture; 105 float snowLife, randomLife;106 float snowRadius, randomRadius;107 float snowMass, randomMass;108 float rate;109 float velocity, randomVelocity;110 float angle, randomAngle;111 float alpha;112 float fadeTime;113 Vector snowCoord;114 Vector2D snowSize;115 int snowWindForce;105 float snowLife, randomLife; 106 float snowRadius, randomRadius; 107 float snowMass, randomMass; 108 float rate; 109 float velocity, randomVelocity; 110 float angle, randomAngle; 111 float alpha; 112 float fadeTime; 113 Vector snowCoord; 114 Vector2D snowSize; 115 int snowWindForce; 116 116 117 bool snowMove;118 bool snowActivate;117 bool snowMove; 118 bool snowActivate; 119 119 120 120 PlaneEmitter* emitter; 121 121 122 122 static SpriteParticles* snowParticles; 123 OrxSound::SoundSource soundSource;123 OrxSound::SoundSource soundSource; 124 124 OrxSound::SoundBuffer* windBuffer; 125 125 126 Vector oldSkyColor;127 Vector oldCloudColor;128 Vector skyColor;129 Vector cloudColor;126 Vector oldSkyColor; 127 Vector oldCloudColor; 128 Vector skyColor; 129 Vector cloudColor; 130 130 }; 131 131 -
branches/proxy/src/lib/graphics/importer/md3/md3_animation_cfg.cc
r8724 r9347 19 19 #include "md3_animation.h" 20 20 21 #include " tokenizer.h"21 #include "substring.h" 22 22 #include "helper_functions.h" 23 23 24 24 #include "debug.h" 25 25 26 #include <stdio.h>27 #include <stdlib.h>28 26 29 27 … … 98 96 if( inHeader && line.find("sex") == 0) { 99 97 //parse line: sex [m | f | ...] 100 std::vector<std::string> tokens; 101 Tokenizer::tokenize(line, tokens, " \t\n\r\f/"); 98 SubString tokens(line, " \t\n\r\f/"); 102 99 103 100 std::string sexStr = tokens.back(); … … 115 112 else if( inHeader && line.find("headoffset") == 0) { 116 113 // parse line: headoffset X Y Z 117 std::vector<std::string> tokens; 118 Tokenizer::tokenize(line, tokens, " \t\n\r\f/"); 114 SubString tokens(line, " \t\n\r\f/"); 119 115 120 116 float z = atof(tokens.back().c_str()); tokens.pop_back(); … … 128 124 else if( inHeader && line.find("footsteps") == 0) { 129 125 //parse line: footsteps [normal | mech | ...] 130 std::vector<std::string> tokens; 131 Tokenizer::tokenize(line, tokens, " \t\n\r\f/"); 126 SubString tokens (line, " \t\n\r\f/"); 132 127 133 128 this->footsteps = tokens.back(); … … 187 182 // parse the line: 188 183 // first frame, num frames, looping frames, frames per second (fps) 189 std::vector<std::string> tokens; 190 Tokenizer::tokenize(line, tokens, " \t\n\r\f/"); 184 SubString tokens(line, " \t\n\r\f/"); 191 185 192 186 anim->fps = atoi(tokens.back().c_str()); tokens.pop_back(); -
branches/proxy/src/lib/lang/base_object.cc
r8145 r9347 21 21 #include "util/loading/load_param.h" 22 22 #include "class_list.h" 23 24 #include "synchronizeable.h"25 26 using namespace std;27 28 23 29 24 /** … … 50 45 ClassList::removeFromClassList(this); 51 46 52 // delete []this->className;53 47 if (this->xmlElem != NULL) 54 48 delete this->xmlElem; … … 61 55 void BaseObject::loadParams(const TiXmlElement* root) 62 56 { 63 // all loadParams should sometime arrive here.57 // all loadParams should arrive here, and be tested for (root != NULL) 64 58 assert (root != NULL); 65 59 60 // copy the xml-element for to know how it was loaded. 66 61 if (this->xmlElem != NULL) 67 62 delete this->xmlElem; 68 63 this->xmlElem = root->Clone(); 64 69 65 // name setup 70 66 LoadParam(root, "name", this, BaseObject, setName) … … 92 88 /** 93 89 * @brief set the name of the Object 90 * @param objectName The new name of the Object. 94 91 */ 95 92 void BaseObject::setName (const std::string& objectName) … … 164 161 * @returns true on match, false otherwise. 165 162 */ 166 bool BaseObject::operator==(const std::string& objectName) 163 bool BaseObject::operator==(const std::string& objectName) const 167 164 { 168 165 return (this->objectName == objectName); 169 166 } 170 167 171 172 /**173 * @brief displays everything this class is174 * @TODO REIMPLEMENT WITH SENSE.175 */176 void BaseObject::whatIs() const177 {178 179 } -
branches/proxy/src/lib/lang/base_object.h
r8362 r9347 1 1 /*! 2 2 * @file base_object.h 3 * Definition of the base object class. 4 5 This is a global handler for all classes. 6 */ 3 * @brief Definition of the BaseObject class. 4 * 5 * This is a global handler for all classes Object and Class names 6 * 7 * BaseObject is the class, that handles object registration and 8 * is the only write-access member of ClassList, where the Objects 9 * References are stored. 10 */ 7 11 8 12 9 #ifndef _ BASE_OBJECT_H10 #define _ BASE_OBJECT_H13 #ifndef __BASE_OBJECT_H_ 14 #define __BASE_OBJECT_H_ 11 15 12 16 #include "class_id.h" … … 41 45 bool isA (ClassID classID) const; 42 46 bool isA (const std::string& className) const; 43 void whatIs() const;44 47 45 bool operator==(const std::string& objectName);46 48 /** @param classID comparer for a ClassID @returns true on match, false otherwise */ 47 bool operator==(ClassID classID) { return this->isA(classID); }; 49 bool operator==(ClassID classID) const { return this->isA(classID); }; 50 bool operator==(const std::string& objectName) const; 48 51 49 52 protected: … … 54 57 55 58 private: 56 57 59 std::string className; //!< the name of the class 58 60 long classID; //!< this is the id from the class_id.h enumeration … … 64 66 }; 65 67 66 #endif /* _ BASE_OBJECT_H*/68 #endif /* __BASE_OBJECT_H_ */ -
branches/proxy/src/lib/network/Makefile.am
r8623 r9347 8 8 shared_network_data.cc \ 9 9 network_socket.cc \ 10 connection_monitor.cc \11 10 network_stream.cc \ 12 11 data_stream.cc \ … … 20 19 network_game_manager.cc \ 21 20 converter.cc \ 21 peer_info.cc \ 22 22 message_manager.cc \ 23 23 network_log.cc \ … … 25 25 player_stats.cc \ 26 26 udp_broadcast.cc \ 27 \ 28 proxy/proxy_settings.cc \ 29 \ 30 monitor/connection_monitor.cc \ 31 monitor/network_monitor.cc \ 32 monitor/network_node.cc \ 27 33 \ 28 34 synchronizeable_var/synchronizeable_var.cc \ … … 33 39 synchronizeable_var/synchronizeable_float.cc \ 34 40 synchronizeable_var/synchronizeable_bool.cc \ 35 synchronizeable_var/synchronizeable_uint.cc 41 synchronizeable_var/synchronizeable_uint.cc \ 42 synchronizeable_var/synchronizeable_ip.cc \ 43 \ 44 ip.cc 36 45 37 46 … … 42 51 shared_network_data.h \ 43 52 network_socket.h \ 44 connection_monitor.h \45 53 network_stream.h \ 46 54 data_stream.h \ … … 54 62 network_game_manager.h \ 55 63 converter.h \ 64 peer_info.h \ 56 65 netdefs.h \ 57 66 message_manager.h \ … … 60 69 player_stats.h \ 61 70 udp_broadcast.h \ 71 \ 72 proxy/proxy_settings.cc \ 73 \ 74 monitor/connection_monitor.h \ 75 monitor/network_monitor.h \ 76 monitor/network_node.h \ 62 77 \ 63 78 synchronizeable_var/synchronizeable_var.h \ … … 68 83 synchronizeable_var/synchronizeable_float.h \ 69 84 synchronizeable_var/synchronizeable_bool.h \ 70 synchronizeable_var/synchronizeable_uint.h 85 synchronizeable_var/synchronizeable_uint.h \ 86 synchronizeable_var/synchronizeable_ip.h \ 87 \ 88 ip.h 71 89 72 90 -
branches/proxy/src/lib/network/handshake.cc
r9235 r9347 10 10 11 11 ### File Specific: 12 main-programmer: christoph13 co-programmer: 12 main-programmer: Christoph Renner (rennerc@ee.ethz.ch) 13 co-programmer: Patirck Boenzli (boenzlip@orxonox.ethz.ch) 14 14 */ 15 15 16 16 17 /* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module18 For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput19 */20 17 #define DEBUG_MODULE_NETWORK 21 18 … … 25 22 #include "debug.h" 26 23 27 Handshake::Handshake( bool server, int clientId, int networkGameManagerId, int messageManagerId ) 24 25 26 27 28 Handshake::Handshake( int nodeType, int clientId, int networkGameManagerId, int messageManagerId ) 28 29 : Synchronizeable() 29 30 { … … 31 32 this->setClassID(CL_HANDSHAKE, "Handshake"); 32 33 33 this->setIsServer(server); 34 34 // register all variable handlers 35 35 orxId_handler = registerVarId( new SynchronizeableInt( &localState.orxId, &remoteState.orxId, "orxonoxId", PERMISSION_ALL ) ); 36 36 version_handler = registerVarId( new SynchronizeableInt( &localState.version, &remoteState.version, "version", PERMISSION_ALL ) ); … … 42 42 errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", PERMISSION_ALL ) ); 43 43 44 this->nodeTypeHandler = registerVarId( new SynchronizeableInt( &localState.nodeType, &remoteState.nodeType, "nodeType", PERMISSION_ALL ) ); 45 44 46 candel_id = registerVarId( new SynchronizeableInt( &localState.canDel, &remoteState.canDel, "canDel", PERMISSION_ALL ) ); 45 47 46 48 registerVar( new SynchronizeableString( &localState.preferedNickName, &remoteState.preferedNickName, "preferedNickName", PERMISSION_ALL ) ); 49 // now synchronize only two of the available proxy server addresses 50 registerVar( new SynchronizeableIP( &localState.proxy1, &remoteState.proxy1, "proxy server 1", PERMISSION_ALL ) ); 51 registerVar( new SynchronizeableIP( &localState.proxy2, &remoteState.proxy1, "proxy server 2", PERMISSION_ALL ) ); 47 52 53 // init the local state 48 54 localState.completed = 0; 49 55 localState.error = 0; … … 54 60 localState.orxId = _ORXONOX_ID; 55 61 localState.version = _ORXONOX_VERSION; 62 localState.nodeType = nodeType; 56 63 localState.canDel = 0; 64 localState.redirectProxy = 0; 65 localState.proxy1 = IP(0, 0); 66 localState.proxy2 = IP (0, 0); 57 67 68 69 // init the remote state 58 70 remoteState.completed = 0; 59 71 remoteState.error = 0; … … 64 76 remoteState.orxId = 0; 65 77 remoteState.version = 0; 78 remoteState.nodeType = NET_CLIENT; 66 79 remoteState.canDel = 0; 80 remoteState.redirectProxy = 0; 81 remoteState.proxy1 = IP(0, 0); 82 remoteState.proxy2 = IP(0, 0); 67 83 84 // activate the synchronization process 68 85 this->setSynchronized(true); 69 86 PRINTF(0)("Handshake created clientId = %d\n", clientId); 70 87 } 88 71 89 72 90 /** … … 78 96 for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ ) 79 97 { 80 if ( *it == orxId_handler ) 98 // orxonox id handler 99 if ( *it == this->orxId_handler ) 81 100 { 82 101 if ( remoteState.orxId != _ORXONOX_ID ) … … 87 106 continue; 88 107 } 89 90 108 } 91 109 92 if ( *it == version_handler ) 110 // orxonox version handler 111 if ( *it == this->version_handler ) 93 112 { 94 113 if ( remoteState.version != _ORXONOX_VERSION ) … … 99 118 continue; 100 119 } 101 102 120 } 103 121 122 // node type handler: for each node type there is a specific action to be taken 123 if ( *it == this->nodeTypeHandler) 124 { 125 if ( remoteState.nodeType == NET_MASTER_SERVER ) 126 { 127 continue; 128 } 129 else if( remoteState.nodeType == NET_PROXY_SERVER_ACTIVE) 130 { 131 continue; 132 } 133 else if( remoteState.nodeType == NET_CLIENT) 134 { 135 continue; 136 } 137 } 138 139 // cancel 104 140 if ( *it == candel_id ) 105 141 { … … 109 145 } 110 146 111 if (112 113 remoteState.version == _ORXONOX_VERSION114 )147 // handshake completed 148 if ( remoteState.orxId == _ORXONOX_ID && 149 remoteState.version == _ORXONOX_VERSION ) 150 { 115 151 localState.completed = 1; 152 } 116 153 } 117 154 -
branches/proxy/src/lib/network/handshake.h
r9235 r9347 1 1 /*! 2 2 * @file network_stream.h 3 * implementation of a network pipe 3 * implementation of a network pipe. This node handles the handshake of two network nodes and exchanges informationas 4 * vial to the connection setup. 5 * 6 * the local node only writes in the localState variable. the remoteState variable will be written from the remote network node 7 * so don't write into it! 4 8 */ 5 9 … … 8 12 9 13 #include "base_object.h" 14 #include "ip.h" 10 15 #include "synchronizeable.h" 11 16 12 #define _ORXONOX_ID 0xF91337A0 17 //!< a struct to save the handshakes to 18 struct HandshakeState 19 { 20 int orxId; //!< orxonox id 21 int version; //!< network protocol version 13 22 14 #define _ORXONOX_VERSION 1 23 int networkManagerId; //!< unique id of the network manager 24 int messageManagerId; //!< unique id of the message manager 25 int hostId; //!< host id 26 int nodeType; //!< type of the network node 15 27 16 struct HandshakeState { 17 int orxId; 18 int version; 19 20 int networkManagerId; 21 int messageManagerId; 22 int hostId; 23 24 int completed; 25 int canDel; 26 27 int error; 28 29 std::string errorString; 30 28 int completed; //!< true if completed 29 int canDel; //!< true if marked for deletion 30 31 int error; //!< error number 32 33 std::string errorString; //!< error string 34 31 35 //additional data 32 std::string preferedNickName; 36 std::string preferedNickName; //!< prefered nick name 37 38 int redirectProxy; //!< true if the client should reconnect to a proxy server (either 1 or 2 ) 39 IP proxy1; //!< ip address of the first proxy (0.0.0.0 of not available) 40 IP proxy2; //!< ip address of the second proxy (0.0.0.0 of not available) 33 41 }; 34 42 43 44 //!< the handshake itself with some interface functions 35 45 class Handshake : public Synchronizeable 36 46 { 47 37 48 public: 38 Handshake( bool server, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 ); 39 inline bool completed(){ return localState.completed != 0 && remoteState.completed != 0; } 40 inline bool ok(){ return localState.error == 0 && remoteState.error == 0; } 41 inline int getHostId(){ return remoteState.hostId; } 42 inline int getNetworkGameManagerId(){ return remoteState.networkManagerId; } 43 inline int getMessageManagerId(){ return remoteState.messageManagerId; } 44 inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; } 45 inline bool canDel(){ return localState.canDel == 1 && remoteState.canDel == 1; } 46 inline bool allowDel(){ return localState.canDel == 1; } 47 inline void del(){ localState.canDel = 1; } 48 49 inline void setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; } 49 Handshake( int nodeType, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 ); 50 51 52 /* functions indicating states of the handshake */ 53 /** @returns true if the handshake is completed */ 54 inline bool completed(){ return localState.completed != 0 && remoteState.completed != 0; } 55 /** @returns true if no error has occured until now */ 56 inline bool ok(){ return localState.error == 0 && remoteState.error == 0; } 57 /** stops the handshake and reject the other side with @param reason: string describing the reason */ 58 inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; } 59 /** @returns true if the handshake is finished and the instances can be deleted */ 60 inline bool canDel(){ return localState.canDel == 1 && remoteState.canDel == 1; } 61 /** @returns true if the local state can be removed*/ 62 inline bool allowDel(){ return localState.canDel == 1; } 63 /** marks the handshake to be deleted */ 64 inline void del(){ localState.canDel = 1; } 65 66 67 /* the actual informations exchanged in the handshake */ 68 /** @returns the host id of the remote host */ 69 inline int getHostId(){ return remoteState.hostId; } 70 /** @returns the unique id of the network game manager*/ 71 inline int getNetworkGameManagerId(){ return remoteState.networkManagerId; } 72 /** @returns the unique id of the message manager */ 73 inline int getMessageManagerId(){ return remoteState.messageManagerId; } 74 /** @returns the node type of the remote host */ 75 inline int getRemoteNodeType() { return this->remoteState.nodeType; } 76 77 /** sets @param nick the prefereded nick name */ 78 inline void setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; } 79 /** @returns the prefered nick name */ 50 80 inline std::string getPreferedNickName(){ return remoteState.preferedNickName; } 51 81 82 /** @returns if true the local client should reconnect to a proxy server from the proxy server list */ 83 inline bool redirect() { return this->remoteState.redirectProxy;} 84 /** @param flag: indicating if the client should be redirected */ 85 inline void setRedirect(bool flag) { this->localState.redirectProxy = flag; } 86 87 /** @param address: the address of the proxy server 1 if any */ 88 inline void setProxy1Address(IP address) { this->localState.proxy1 = address; } 89 /** @returns the address of the proxy server 1 if any */ 90 inline IP getProxy1Address() { return this->remoteState.proxy1; } 91 /** @param address: the address of the proxy server 2 if any */ 92 inline void setProxy2Address(IP address) { this->localState.proxy2 = address; } 93 /** @returns the address of the proxy server 2 if any */ 94 inline IP getProxy2Address() { return this->remoteState.proxy2; } 95 96 97 /* variable handler function */ 52 98 virtual void varChangeHandler( std::list<int> & id ); 53 99 100 54 101 private: 55 HandshakeState localState; 56 HandshakeState remoteState; 57 58 int netManId_handler; 59 int msgManId_handler; 60 int hostId_handler; 61 int completed_handler; 62 int error_handler; 63 int errorString_handler; 64 int orxId_handler; 65 int version_handler; 66 int candel_id; 102 HandshakeState localState; //!< the local handshake state 103 HandshakeState remoteState; //!< the remote handshake state 104 105 int orxId_handler; //!< orxonox id handler 106 int version_handler; //!< orxonox version id handler 107 int netManId_handler; //!< network manager handler 108 int msgManId_handler; //!< message manager handler 109 int hostId_handler; //!< host id handler 110 int nodeTypeHandler; //!< node type handler 111 112 int completed_handler; //!< handshake completion handler 113 int error_handler; //!< handshake error handler 114 int errorString_handler; //!< handshake error string handler 115 int candel_id; //!< handshake deletion handler 116 int nodeType; //!, the type of the network node 67 117 68 118 }; -
branches/proxy/src/lib/network/message_manager.cc
r9059 r9347 52 52 } 53 53 } 54 54 55 55 it->second.messages.clear(); 56 56 it->second.toAck.clear(); 57 57 } 58 58 59 59 messageQueue.clear(); 60 60 61 61 this->messageHandlerMap.clear(); 62 62 63 63 MessageManager::singletonRef = NULL; 64 64 } … … 82 82 int i = 0; 83 83 int n; 84 84 85 85 n = Converter::intToByteArray( messageQueue[userId].toAck.size(), data + i, maxLength ); 86 86 i += n; 87 87 assert( n == INTSIZE ); 88 88 89 89 for ( std::list<int>::iterator it = messageQueue[userId].toAck.begin(); it != messageQueue[userId].toAck.end(); it++) 90 90 { … … 93 93 assert( n == INTSIZE ); 94 94 } 95 95 96 96 messageQueue[userId].toAck.clear(); 97 97 98 98 n = Converter::intToByteArray( messageQueue[userId].messages.size(), data + i, maxLength ); 99 99 i += n; 100 100 assert( n == INTSIZE ); 101 101 102 102 for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); it++ ) 103 103 { … … 105 105 i += n; 106 106 assert( n == INTSIZE ); 107 107 108 108 n = Converter::intToByteArray( it->number, data + i, maxLength ); 109 109 i += n; 110 110 assert( n == INTSIZE ); 111 111 112 112 n = Converter::intToByteArray( it->messageId, data + i, maxLength ); 113 113 i += n; 114 114 assert( n == INTSIZE ); 115 115 116 116 assert( i + it->length <= maxLength ); 117 117 memcpy( data + i, it->data, it->length ); 118 118 i += it->length; 119 119 } 120 120 121 121 return i; 122 122 } … … 136 136 int i = 0; 137 137 int n; 138 138 139 139 int nAcks; 140 140 141 141 assert( i + INTSIZE <= length ); 142 142 n = Converter::byteArrayToInt( data + i, &nAcks ); 143 143 assert( n == INTSIZE ); 144 144 i += n; 145 145 146 146 std::list<int> acks; 147 147 148 148 int number; 149 149 150 150 for ( int j = 0; j < nAcks; j++ ) 151 151 { … … 154 154 assert( n == INTSIZE ); 155 155 i += n; 156 156 157 157 acks.push_back( number ); 158 158 } 159 159 160 160 int nMessages; 161 161 162 162 assert( i + INTSIZE <= length ); 163 163 n = Converter::byteArrayToInt( data + i, &nMessages ); … … 166 166 167 167 int messageLength, messageId; 168 168 169 169 for ( int j = 0; j < nMessages; j++ ) 170 170 { … … 173 173 assert( n == INTSIZE ); 174 174 i += n; 175 175 176 176 assert( i + INTSIZE <= length ); 177 177 n = Converter::byteArrayToInt( data + i, &number ); 178 178 assert( n == INTSIZE ); 179 179 i += n; 180 180 181 181 assert( i + INTSIZE <= length ); 182 182 n = Converter::byteArrayToInt( data + i, &messageId ); 183 183 assert( n == INTSIZE ); 184 184 i += n; 185 185 186 186 if ( number > 0 ) 187 187 messageQueue[userId].toAck.push_back( number ); 188 188 189 189 assert( i + messageLength <= length ); 190 190 assert( messageHandlerMap.find( (MessageId)messageId ) != messageHandlerMap.end() ); … … 194 194 { 195 195 NetworkMessage msg; 196 196 197 197 msg.data = new byte[messageLength]; 198 198 memcpy( msg.data, data + i, messageLength ); … … 200 200 msg.messageId = (MessageId)messageId; 201 201 msg.number = userId; 202 202 203 203 incomingMessageBuffer.push_back( msg ); 204 204 } … … 207 207 i += messageLength; 208 208 } 209 210 209 210 211 211 //TODO maybe handle incomingMessage in tick function. else local messages will not be handled if no clients are connected 212 212 for ( std::list<NetworkMessage>::iterator it = incomingMessageBuffer.begin(); it != incomingMessageBuffer.end(); ) … … 223 223 it++; 224 224 } 225 225 226 226 //walk throu message queue and remove acked messages 227 227 for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); ) … … 236 236 it++; 237 237 } 238 238 239 239 //TODO find bether way. maybe with timestamp 240 240 if ( messageQueue[userId].recievedMessages.size() > 1000 ) … … 255 255 if ( messageQueue.find( userId ) == messageQueue.end() ) 256 256 return; 257 257 258 258 for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); it++ ) 259 259 { … … 262 262 it->data = NULL; 263 263 } 264 264 265 265 messageQueue[userId].toAck.clear(); 266 266 267 267 messageQueue.erase( userId ); 268 268 } … … 270 270 /** 271 271 * registers function to handle messages with id messageId. someData is passed to callbackfuntion 272 * @param messageId message id to handle 272 * @param messageId message id to handle 273 273 * @param cb function pointer to callback function 274 274 * @param someData this pointer is passed to callback function without modification … … 278 278 { 279 279 MessageHandler messageHandler; 280 280 281 281 messageHandler.cb = cb; 282 282 messageHandler.messageId = messageId; 283 283 messageHandler.someData = someData; 284 284 285 285 messageHandlerMap[messageId] = messageHandler; 286 286 287 287 return true; 288 288 } … … 309 309 * @param data pointer to data 310 310 * @param dataLength length of data 311 * @param recieverType 312 * @param reciever 311 * @param recieverType 312 * @param reciever 313 313 */ 314 314 void MessageManager::sendMessage( MessageId messageId, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority ) … … 316 316 for ( MessageQueue::iterator it = messageQueue.begin(); it != messageQueue.end(); it++ ) 317 317 { 318 if ( 318 if ( 319 319 recieverType == RT_ALL_ME || 320 320 recieverType == RT_ALL_NOT_ME || 321 321 recieverType == RT_USER && it->first == reciever || 322 322 recieverType == RT_NOT_USER && it->first != reciever || 323 recieverType == RT_SERVER && getNetworkStream()->isUser Server( it->first )323 recieverType == RT_SERVER && getNetworkStream()->isUserMasterServer( it->first ) 324 324 ) 325 325 { … … 336 336 } 337 337 } 338 338 339 339 if ( recieverType == RT_ALL_ME ) 340 340 { -
branches/proxy/src/lib/network/netdefs.h
r9246 r9347 1 /* 2 orxonox - the future of 3D-vertical-scrollers 1 3 4 Copyright (C) 2004 orx 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 ### File Specific: 12 main-programmer: Christoph Renner rennerc@ee.ethz.ch 13 co-programmer: Patrick Boenzli boenzlip@orxonox.ethz.ch 14 15 June 2006: finishing work on the network stream for pps presentation (rennerc@ee.ethz.ch) 16 July 2006: some code rearangement and integration of the proxy server mechanism (boenzlip@ee.ethz.ch) 17 */ 2 18 3 19 /*! 4 20 * @file network_manager.h 5 21 * Main interface for the network module. Manages all the modules 6 7 22 */ 8 23 9 24 #ifndef _NETDEFS 10 25 #define _NETDEFS 26 11 27 12 28 #ifdef HAVE_SDL_NET_H … … 17 33 18 34 19 #define MAX_CONNECTIONS 1000 35 //!< maximal connectinons for the server 36 #define NET_MAX_CONNECTIONS 100 20 37 38 //!< the amount of slots used before a proxy server is activated 39 #define NET_CONNECTION_SATURATION 0.75 40 41 //!< network polling frequency 21 42 #define NETWORK_FREQUENCY 66 43 44 45 //!< orxonox protocol id 46 #define _ORXONOX_ID 0xF91337A0 47 //!< orxonox network version identifier 48 #define _ORXONOX_VERSION 1 22 49 23 50 … … 27 54 //!< enum indicating the type of the node 28 55 typedef enum { 29 NET_SERVER, 30 NET_CLIENT 56 NET_MASTER_SERVER, 57 NET_PROXY_SERVER_ACTIVE, 58 NET_PROXY_SERVER_PASSIVE, 59 NET_CLIENT, 60 61 NET_NR_TYPES 62 31 63 } NodeType; 32 64 -
branches/proxy/src/lib/network/network_game_manager.cc
r9235 r9347 10 10 11 11 ### File Specific: 12 main-programmer: Benjamin Wuest 13 co-programmer: ... 12 main-programmer: Christoph Renner rennerc@ee.ethz.ch 13 co-programmer: Patrick Boenzli boenzlip@orxonox.ethz.ch 14 15 June 2006: finishing work on the network stream for pps presentation (rennerc@ee.ethz.ch) 16 July 2006: some code rearangement and integration of the proxy server mechanism (boenzlip@ee.ethz.ch) 14 17 */ 15 18 16 19 17 /* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module 18 For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput 19 */ 20 20 21 #define DEBUG_MODULE_NETWORK 21 22 … … 45 46 46 47 47 /* using namespace std is default, this needs to be here */48 48 using namespace std; 49 49 … … 62 62 63 63 this->setSynchronized(true); 64 64 65 65 MessageManager::getInstance()->registerMessageHandler( MSGID_DELETESYNCHRONIZEABLE, delSynchronizeableHandler, NULL ); 66 66 MessageManager::getInstance()->registerMessageHandler( MSGID_PREFEREDTEAM, preferedTeamHandler, NULL ); 67 67 MessageManager::getInstance()->registerMessageHandler( MSGID_CHATMESSAGE, chatMessageHandler, NULL ); 68 68 69 69 this->gameState = 0; 70 70 registerVar( new SynchronizeableInt( &gameState, &gameState, "gameState" ) ); … … 77 77 { 78 78 delete MessageManager::getInstance(); 79 79 80 80 PlayerStats::deleteAllPlayerStats(); 81 81 82 82 NetworkGameManager::singletonRef = NULL; 83 83 } … … 86 86 /** 87 87 * insert new player into game 88 * @param userId 89 * @return 88 * @param userId 89 * @return 90 90 */ 91 91 bool NetworkGameManager::signalNewPlayer( int userId ) 92 92 { 93 assert( SharedNetworkData::getInstance()->is GameServer() );93 assert( SharedNetworkData::getInstance()->isMasterServer() ); 94 94 assert( State::getGameRules() ); 95 95 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) ); 96 96 97 97 NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules())); 98 98 99 99 int team = rules.getTeamForNewUser(); 100 100 ClassID playableClassId = rules.getPlayableClassId( userId, team ); … … 102 102 std::string playableTexture = rules.getPlayableModelFileName( userId, team, playableClassId ); 103 103 float playableScale = rules.getPlayableScale( userId, team, playableClassId ); 104 104 105 105 BaseObject * bo = Factory::fabricate( playableClassId ); 106 106 107 107 assert( bo != NULL ); 108 108 assert( bo->isA( CL_PLAYABLE ) ); 109 109 110 110 Playable & playable = *(dynamic_cast<Playable*>(bo)); 111 111 112 112 playable.loadMD2Texture( playableTexture ); 113 113 114 114 playable.loadModel( playableModel, 100.0f ); 115 115 playable.setOwner( userId ); 116 116 playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 117 117 playable.setSynchronized( true ); 118 118 119 119 PlayerStats * stats = rules.getNewPlayerStats( userId ); 120 120 121 121 stats->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); 122 122 stats->setSynchronized( true ); 123 123 stats->setOwner( SharedNetworkData::getInstance()->getHostID() ); 124 124 125 125 stats->setTeamId( team ); 126 126 stats->setPlayableClassId( playableClassId ); 127 127 stats->setPlayableUniqueId( playable.getUniqueID() ); 128 128 stats->setModelFileName( playableModel ); 129 129 130 130 if ( userId == 0 ) 131 131 stats->setNickName( Preferences::getInstance()->getString( "multiplayer", "nickname", "Server" ) ); 132 132 133 133 if ( rules.isA( CL_MULTIPLAYER_TEAM_DEATHMATCH ) ) 134 134 dynamic_cast<MultiplayerTeamDeathmatch*>(&rules)->respawnPlayable( &playable, team, 0.0f ); 135 135 136 136 return true; 137 137 } … … 140 140 /** 141 141 * remove player from game 142 * @param userID 143 * @return 142 * @param userID 143 * @return 144 144 */ 145 145 bool NetworkGameManager::signalLeftPlayer(int userID) … … 151 151 delete PlayerStats::getStats( userID ); 152 152 } 153 153 154 154 return true; 155 155 } … … 159 159 /** 160 160 * handler for remove synchronizeable messages 161 * @param messageId 162 * @param data 163 * @param dataLength 164 * @param someData 165 * @param userId 161 * @param messageId 162 * @param data 163 * @param dataLength 164 * @param someData 165 * @param userId 166 166 * @return true on successfull handling else handler will be called again 167 167 */ 168 168 bool NetworkGameManager::delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 169 169 { 170 if ( getInstance()->isServer() )170 if ( SharedNetworkData::getInstance()->isMasterServer() ) 171 171 { 172 172 PRINTF(2)("Recieved DeleteSynchronizeable message from client %d!\n", userId); 173 173 return true; 174 174 } 175 175 176 176 int uniqueId = 0; 177 177 int len = Converter::byteArrayToInt( data, &uniqueId ); 178 178 179 179 if ( len != dataLength ) 180 180 { … … 182 182 return true; 183 183 } 184 184 185 185 const std::list<BaseObject*> * list = ClassList::getList( CL_SYNCHRONIZEABLE ); 186 186 187 187 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 188 188 { … … 194 194 return true; 195 195 } 196 196 197 197 delete dynamic_cast<Synchronizeable*>(*it); 198 198 return true; 199 199 } 200 200 } 201 201 202 202 return true; 203 203 } … … 210 210 { 211 211 byte buf[INTSIZE]; 212 212 213 213 assert( Converter::intToByteArray( uniqueId, buf, INTSIZE ) == INTSIZE ); 214 214 … … 220 220 /** 221 221 * handler for MSGID_PREFEREDTEAM message 222 * @param messageId 223 * @param data 224 * @param dataLength 225 * @param someData 226 * @param userId 227 * @return 222 * @param messageId 223 * @param data 224 * @param dataLength 225 * @param someData 226 * @param userId 227 * @return 228 228 */ 229 229 bool NetworkGameManager::preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 230 230 { 231 assert( NetworkGameManager::getInstance()->isServer() );232 231 assert( SharedNetworkData::getInstance()->isMasterServer() ); 232 233 233 int teamId = 0; 234 234 int len = Converter::byteArrayToInt( data, &teamId ); 235 235 236 236 if ( len != dataLength ) 237 237 { … … 239 239 return true; 240 240 } 241 241 242 242 NetworkGameManager::getInstance()->setPreferedTeam( userId, teamId ); 243 243 244 244 return true; 245 245 } … … 249 249 if ( !PlayerStats::getStats( userId ) ) 250 250 return; 251 251 252 252 PlayerStats & stats = *(PlayerStats::getStats( userId )); 253 253 254 254 stats.setPreferedTeamId( teamId ); 255 255 } … … 257 257 /** 258 258 * set prefered team for this host 259 * @param teamId 259 * @param teamId 260 260 */ 261 261 void NetworkGameManager::prefereTeam( int teamId ) 262 262 { 263 if ( isServer() )263 if ( SharedNetworkData::getInstance()->isMasterServer() ) 264 264 setPreferedTeam( SharedNetworkData::getInstance()->getHostID(), teamId ); 265 265 else 266 266 { 267 267 byte buf[INTSIZE]; 268 268 269 269 assert( Converter::intToByteArray( teamId, buf, INTSIZE) == INTSIZE ); 270 270 271 271 MessageManager::getInstance()->sendMessage( MSGID_PREFEREDTEAM, buf, INTSIZE, RT_USER, 0, MP_HIGHBANDWIDTH ); 272 272 } … … 285 285 { 286 286 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE ); 287 287 288 288 if ( list && std::find( list->begin(), list->end(), *it ) != list->end() ) 289 { 289 { 290 290 PRINTF(0)("Delete unused playable: %s owner: %d\n", (*it)->getClassName(), (*it)->getOwner() ); 291 291 std::list<Playable*>::iterator delit = it; … … 305 305 { 306 306 PRINTF(0)("NetworkGameManager::chatMessageHandler %d %d\n", userId, SharedNetworkData::getInstance()->getHostID() ); 307 if ( NetworkGameManager::getInstance()->isServer() && userId != SharedNetworkData::getInstance()->getHostID() )307 if ( SharedNetworkData::getInstance()->isMasterServer() && userId != SharedNetworkData::getInstance()->getHostID() ) 308 308 { 309 309 MessageManager::getInstance()->sendMessage( messageId, data, dataLength, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH ); 310 310 } 311 311 312 312 assert( State::getGameRules() ); 313 313 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) ); 314 314 315 315 NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules())); 316 316 317 317 if ( dataLength < 3*INTSIZE ) 318 318 { 319 319 PRINTF(2)("got too small chatmessage from client %d\n", userId); 320 320 321 321 return true; 322 322 } 323 323 324 324 int messageType = 0; 325 325 Converter::byteArrayToInt( data, &messageType ); … … 328 328 std::string message; 329 329 Converter::byteArrayToString( data+2*INTSIZE, message, dataLength-2*INTSIZE ); 330 330 331 331 rules.handleChatMessage( senderUserId, message, messageType ); 332 332 … … 346 346 assert( Converter::intToByteArray( SharedNetworkData::getInstance()->getHostID(), buf+INTSIZE, INTSIZE ) == INTSIZE ); 347 347 assert( Converter::stringToByteArray(message, buf+2*INTSIZE, message.length()+INTSIZE) == message.length()+INTSIZE ); 348 349 if ( this->isServer() )348 349 if ( SharedNetworkData::getInstance()->isMasterServer() ) 350 350 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_ME, 0, MP_HIGHBANDWIDTH ); 351 351 else 352 352 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH ); 353 353 354 354 355 355 delete [] buf; 356 356 } -
branches/proxy/src/lib/network/network_game_manager.h
r8708 r9347 28 28 NET_YOU_ARE_ENTITY, 29 29 NET_REQUEST_ENTITY_LIST, 30 NET_REQUEST_PNODE_PATH,31 NET_SEND_PNODE_PATH,32 30 33 31 NET_NUMBER … … 42 40 43 41 /*! 44 * a class that can create and remove entities 42 * a class that can create and remove entities over the network 45 43 */ 46 44 class NetworkGameManager: public Synchronizeable 47 45 { 46 48 47 public: 49 48 virtual ~NetworkGameManager(); 50 49 51 50 static NetworkGameManager* NetworkGameManager::getInstance() 52 51 { if (!NetworkGameManager::singletonRef) NetworkGameManager::singletonRef = new NetworkGameManager(); return NetworkGameManager::singletonRef; } … … 55 54 bool signalNewPlayer( int userId ); 56 55 bool signalLeftPlayer( int userID ); 57 58 void removeSynchronizeable( int uniqueId ); 59 56 60 57 void prefereTeam( int teamId ); 58 61 59 62 60 inline void setGameState( int gameState ){ this->gameState = gameState; } 63 61 inline int getGameState(){ return this->gameState; } 64 62 65 63 void tick( float ds ); 66 64 65 void removeSynchronizeable( int uniqueId ); 67 66 void sendChatMessage( const std::string & message, int messageType ); 67 68 68 69 69 private: 70 70 NetworkGameManager(); 71 71 72 72 static bool delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ); 73 73 static bool preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ); 74 74 static bool chatMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ); 75 75 76 76 void setPreferedTeam( int userId, int teamId ); 77 77 78 79 private: 78 80 static NetworkGameManager* singletonRef; 79 81 80 82 int gameState; 81 83 82 84 std::list<Playable*> playablesToDelete; 83 85 }; -
branches/proxy/src/lib/network/network_manager.cc
r9059 r9347 53 53 this->networkStream = NULL; 54 54 this->elapsedTime = 0.0f; 55 56 55 56 57 57 int port = Preferences::getInstance()->getInt( "network", "telnetport", 0 ); 58 58 59 59 if ( port > 0 ) 60 60 NetworkLog::getInstance()->listen( port ); … … 75 75 this->networkStream = NULL; 76 76 } 77 77 78 78 NetworkManager::singletonRef = NULL; 79 79 } … … 118 118 { 119 119 SharedNetworkData::getInstance()->setHostID(0); 120 SharedNetworkData::getInstance()->set GameServer(true);120 SharedNetworkData::getInstance()->setNodeType(NET_MASTER_SERVER); 121 121 this->networkStream = new NetworkStream(port); 122 122 SharedNetworkData::getInstance()->setDefaultSyncStream(this->networkStream); … … 148 148 if ( networkStream ) 149 149 networkStream->processData(); 150 150 151 151 NetworkGameManager::getInstance()->tick( this->elapsedTime ); 152 152 } -
branches/proxy/src/lib/network/network_manager.h
r9059 r9347 41 41 /** Returns the hostID @return The hostID of the object */ 42 42 inline int getHostID() { return SharedNetworkData::getInstance()->getHostID(); } 43 inline bool isGameServer() { return SharedNetworkData::getInstance()->isGameServer(); } 43 inline bool isMasterServer() { return SharedNetworkData::getInstance()->isMasterServer(); } 44 inline bool isProxyServer() { return SharedNetworkData::getInstance()->isProxyServer(); } 45 inline bool isClient() { return SharedNetworkData::getInstance()->isClient(); } 44 46 45 47 -
branches/proxy/src/lib/network/network_socket.cc
r7954 r9347 33 33 { 34 34 bOk = true; 35 this->ip.host = 0; 36 this->ip.port = 0; 35 37 } 36 38 -
branches/proxy/src/lib/network/network_socket.h
r7954 r9347 27 27 */ 28 28 virtual void connectToServer( std::string host, int port ) = 0; 29 29 30 30 /** 31 31 * disconnect from server 32 32 */ 33 33 virtual void disconnectServer() = 0; 34 35 /** 36 * reconnecting to another server by terminating old connection and init a new connection 37 */ 38 virtual void reconnectToServer( std::string host, int port) = 0; 39 40 /** 41 * reconnecting to anoter server softly 42 */ 43 virtual void reconnectToServerSoft( std::string host, int port) = 0; 34 44 35 45 /** … … 40 50 */ 41 51 virtual bool writePacket(byte * data, int length) = 0; 42 52 43 53 /** 44 54 * read a packet sent by another NetworkSocket … … 54 64 */ 55 65 inline bool isOk() { return this->bOk; } 56 66 67 /** @returns the ip adderess of the destination socket */ 68 IPaddress getRemoteAddress() { return ip; } 69 70 57 71 protected: 58 bool bOk; //!< check for socket status72 bool bOk; //!< check for socket status 59 73 74 IPaddress ip; //!< host,port 60 75 }; 61 76 -
branches/proxy/src/lib/network/network_stream.cc
r9246 r9347 12 12 main-programmer: Christoph Renner rennerc@ee.ethz.ch 13 13 co-programmer: Patrick Boenzli boenzlip@orxonox.ethz.ch 14 15 June 2006: finishing work on the network stream for pps presentation (rennerc@ee.ethz.ch) 16 July 2006: some code rearangement and integration of the proxy server mechanism (boenzlip@ee.ethz.ch) 14 17 */ 15 18 … … 22 25 #include "udp_socket.h" 23 26 #include "udp_server_socket.h" 24 #include "connection_monitor.h" 27 #include "monitor/connection_monitor.h" 28 #include "monitor/network_monitor.h" 25 29 #include "synchronizeable.h" 30 #include "ip.h" 26 31 #include "network_game_manager.h" 27 32 #include "shared_network_data.h" … … 42 47 #include <algorithm> 43 48 44 /* include your own header */ 49 45 50 #include "network_stream.h" 46 51 47 /* probably unnecessary */ 52 48 53 using namespace std; 49 54 … … 52 57 53 58 59 /** 60 * empty constructor 61 */ 54 62 NetworkStream::NetworkStream() 55 63 : DataStream() … … 57 65 this->init(); 58 66 /* initialize the references */ 59 this-> type = NET_CLIENT;60 } 61 62 63 /** 64 * connect to a server as a client67 this->pInfo->nodeType = NET_CLIENT; 68 } 69 70 71 /** 72 * start as a client, connect to a server 65 73 * @param host: host name (address) 66 74 * @param port: port number … … 68 76 NetworkStream::NetworkStream( std::string host, int port ) 69 77 { 70 this->type = NET_CLIENT;71 78 this->init(); 79 // init the peers[0] the server to ceonnect to 72 80 this->peers[0].socket = new UdpSocket( host, port ); 73 81 this->peers[0].userId = 0; 74 this->peers[0]. isServer = true;82 this->peers[0].nodeType = NET_MASTER_SERVER; 75 83 this->peers[0].connectionMonitor = new ConnectionMonitor( 0 ); 84 this->peers[0].ip = this->peers[0].socket->getRemoteAddress(); 85 // and set also the localhost 86 this->pInfo->nodeType = NET_CLIENT; 87 // get the local ip address 88 IPaddress ip; 89 SDLNet_ResolveHost( &ip, NULL, port ); 90 this->pInfo->ip = ip; 76 91 } 77 92 … … 83 98 NetworkStream::NetworkStream( int port ) 84 99 { 85 this->type = NET_SERVER;86 100 this->init(); 87 101 this->serverSocket = new UdpServerSocket(port); 88 this->bActive = true; 102 this->pInfo->nodeType = NET_MASTER_SERVER; 103 // get the local ip address 104 IPaddress ip; 105 SDLNet_ResolveHost( &ip, NULL, port ); 106 this->pInfo->ip = ip; 89 107 } 90 108 … … 97 115 /* set the class id for the base object */ 98 116 this->setClassID(CL_NETWORK_STREAM, "NetworkStream"); 99 this->bActive = false;100 117 this->serverSocket = NULL; 101 118 this->networkGameManager = NULL; 102 myHostId = 0; 103 currentState = 0; 119 this->networkMonitor = NULL; 120 121 this->pInfo = new PeerInfo(); 122 this->pInfo->userId = 0; 123 this->pInfo->lastAckedState = 0; 124 this->pInfo->lastRecvedState = 0; 125 126 127 this->currentState = 0; 104 128 105 129 remainingBytesToWriteToDict = Preferences::getInstance()->getInt( "compression", "writedict", 0 ); … … 147 171 for ( SynchronizeableList::const_iterator it = getSyncBegin(); it != getSyncEnd(); it ++ ) 148 172 (*it)->setNetworkStream( NULL ); 173 174 if( this->pInfo) 175 delete this->pInfo; 176 177 if( this->networkMonitor) 178 delete this->networkMonitor; 149 179 } 150 180 … … 165 195 /** 166 196 * starts the network handshake 197 * handsakes are always initialized from the client side first. this starts the handshake and therefore is only 198 * executed as client 167 199 */ 168 200 void NetworkStream::startHandshake() 169 201 { 170 Handshake* hs = new Handshake( false);202 Handshake* hs = new Handshake(this->pInfo->nodeType); 171 203 hs->setUniqueID( 0 ); 172 204 assert( peers[0].handshake == NULL ); 173 205 peers[0].handshake = hs; 174 206 207 // set the preferred nick name 175 208 hs->setPreferedNickName( Preferences::getInstance()->getString( "multiplayer", "nickname", "Player" ) ); 176 209 177 // peers[0].handshake->setSynchronized( true );178 //this->connectSynchronizeable(*hs);179 //this->connectSynchronizeable(*hs);180 210 PRINTF(0)("NetworkStream: Handshake created: %s\n", hs->getName()); 181 211 } … … 192 222 sync.setNetworkStream( this ); 193 223 194 this->bActive = true;224 // this->bActive = true; 195 225 } 196 226 … … 215 245 void NetworkStream::processData() 216 246 { 247 // create the network monitor after all the init work and before there is any connection handlings 248 if( this->networkMonitor == NULL) 249 this->networkMonitor = new NetworkMonitor(this); 250 251 217 252 int tick = SDL_GetTicks(); 218 253 219 currentState++; 220 221 if ( this->type == NET_SERVER ) 222 { 254 this->currentState++; 255 // there was a wrap around 256 if( this->currentState < 0) 257 { 258 PRINTF(1)("A wrap around in the state variable as occured. The server was running so long? Pls restart server or write a mail to the supporters!\n"); 259 } 260 261 if ( this->pInfo->nodeType == NET_MASTER_SERVER ) 262 { 263 // execute everytthing the master server shoudl do 223 264 if ( serverSocket ) 224 265 serverSocket->update(); 225 266 226 267 this->updateConnectionList(); 268 } 269 else if( this->pInfo->nodeType == NET_PROXY_SERVER_ACTIVE) 270 { 271 // execute everything the proxy server should do 227 272 } 228 273 else … … 249 294 cleanUpOldSyncList(); 250 295 handleHandshakes(); 296 297 // update the network monitor 298 this->networkMonitor->process(); 251 299 252 300 // order of up/downstream is important!!!! … … 258 306 259 307 /** 260 * if we are a server update the connection list to accept new connections (clients)261 * also start the handsake for the new clients308 * if we are a NET_MASTER_SERVER or NET_PROXY_SERVER_ACTIVE update the connection list to accept new 309 * connections (clients) also start the handsake for the new clients 262 310 */ 263 311 void NetworkStream::updateConnectionList( ) … … 276 324 clientId = freeSocketSlots.back(); 277 325 freeSocketSlots.pop_back(); 278 peers[clientId].socket = tempNetworkSocket;279 peers[clientId].handshake = new Handshake(true, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID() );280 peers[clientId].connectionMonitor = new ConnectionMonitor( clientId );281 peers[clientId].handshake->setUniqueID(clientId);282 peers[clientId].userId = clientId;283 peers[clientId].isServer = false;284 326 } 285 327 else … … 290 332 if ( it->first >= clientId ) 291 333 clientId = it->first + 1; 292 293 peers[clientId].socket = tempNetworkSocket; 294 peers[clientId].handshake = new Handshake(true, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID()); 295 peers[clientId].handshake->setUniqueID(clientId); 296 peers[clientId].connectionMonitor = new ConnectionMonitor( clientId ); 297 peers[clientId].userId = clientId; 298 peers[clientId].isServer = false; 299 300 PRINTF(0)("num sync: %d\n", synchronizeables.size()); 301 } 302 303 // check if there are too many clients connected 304 if ( clientId > MAX_CONNECTIONS ) 305 { 306 peers[clientId].handshake->doReject( "too many connections" ); 307 PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId); 308 } 309 else 310 { 311 PRINTF(0)("New Client: %d\n", clientId); 312 } 313 314 //this->connectSynchronizeable(*handshakes[clientId]); 334 } 335 336 peers[clientId].socket = tempNetworkSocket; 337 // create new handshake and init its variables 338 peers[clientId].handshake = new Handshake(this->pInfo->nodeType, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID() ); 339 peers[clientId].handshake->setUniqueID(clientId); 340 341 peers[clientId].connectionMonitor = new ConnectionMonitor( clientId ); 342 peers[clientId].userId = clientId; 343 344 PRINTF(0)("num sync: %d\n", synchronizeables.size()); 345 346 // get the proxy server informations and write them to the handshake, if any (proxy) 347 assert( this->networkMonitor != NULL); 348 PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy(); 349 if( pi != NULL) 350 { 351 peers[clientId].handshake->setProxy1Address( pi->ip); 352 PRINTF(0)("proxy1 ip set to: %s\n", pi->ip.ipString().c_str()); 353 } 354 355 pi = this->networkMonitor->getSecondChoiceProxy(); 356 if( pi != NULL) 357 peers[clientId].handshake->setProxy2Address( pi->ip); 358 359 // check if the connecting client should reconnect to a proxy server 360 peers[clientId].handshake->setRedirect(this->networkMonitor->isReconnectNextClient()); 361 362 // the connecting node of course is a client 363 peers[clientId].nodeType = NET_CLIENT; 364 peers[clientId].ip = peers[clientId].socket->getRemoteAddress(); 365 366 367 // check if there are too many clients connected (DEPRECATED: new: the masterserver sends a list of proxy servers) 368 // if ( clientId > SharedNetworkData::getInstance()->getMaxPlayer() ) 369 // { 370 // // peers[clientId].handshake->setRedirect(true); 371 // // 372 // // peers[clientId].handshake->doReject( "too many connections" ); 373 // PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId); 374 // } 375 // else 376 // { 377 // PRINTF(0)("New Client: %d\n", clientId); 378 // } 379 PRINTF(0)("New Client: %d\n", clientId); 380 381 315 382 } 316 383 … … 373 440 void NetworkStream::debug() 374 441 { 375 if( this->is Server())376 PRINT(0)(" Host ist Server with ID: %i\n", this-> myHostId);442 if( this->isMasterServer()) 443 PRINT(0)(" Host ist Server with ID: %i\n", this->pInfo->userId); 377 444 else 378 PRINT(0)(" Host ist Client with ID: %i\n", this-> myHostId);445 PRINT(0)(" Host ist Client with ID: %i\n", this->pInfo->userId); 379 446 380 447 PRINT(0)(" Got %i connected Synchronizeables, showing active Syncs:\n", this->synchronizeables.size()); … … 385 452 (*it)->getUniqueID(), (*it)->beSynchronized()); 386 453 } 387 PRINT(0)(" Maximal Connections: %i\n", MAX_CONNECTIONS);454 PRINT(0)(" Maximal Connections: %i\n", SharedNetworkData::getInstance()->getMaxPlayer() ); 388 455 389 456 } … … 414 481 if ( it->second.handshake ) 415 482 { 483 // handshake finished 416 484 if ( it->second.handshake->completed() ) 417 485 { 486 //handshake is correct 418 487 if ( it->second.handshake->ok() ) 419 488 { 420 489 if ( !it->second.handshake->allowDel() ) 421 490 { 422 if ( t ype != NET_SERVER)491 if ( this->pInfo->nodeType == NET_CLIENT ) 423 492 { 424 493 SharedNetworkData::getInstance()->setHostID( it->second.handshake->getHostId() ); 425 myHostId = SharedNetworkData::getInstance()->getHostID(); 426 494 this->pInfo->userId = SharedNetworkData::getInstance()->getHostID(); 495 496 it->second.nodeType = it->second.handshake->getRemoteNodeType(); 497 it->second.ip = it->second.socket->getRemoteAddress(); 498 // add the new server to the nodes list (it can be a NET_MASTER_SERVER or NET_PROXY_SERVER) 499 this->networkMonitor->addNode(&it->second); 500 // get proxy 1 address and add it 501 this->networkMonitor->addNode(it->second.handshake->getProxy1Address(), NET_PROXY_SERVER_ACTIVE); 502 PRINTF(0)("proxy1 ip read to: %s\n", it->second.handshake->getProxy1Address().ipString().c_str()); 503 // get proxy 2 address and add it 504 this->networkMonitor->addNode(it->second.handshake->getProxy2Address(), NET_PROXY_SERVER_ACTIVE); 505 506 // now check if the server accepted the connection 507 if( it->second.handshake->redirect()) 508 this->handleReconnect( it->second.userId); 509 510 // create the new network game manager and init it 427 511 this->networkGameManager = NetworkGameManager::getInstance(); 428 512 this->networkGameManager->setUniqueID( it->second.handshake->getNetworkGameManagerId() ); 513 // init the new message manager 429 514 MessageManager::getInstance()->setUniqueID( it->second.handshake->getMessageManagerId() ); 430 515 } … … 437 522 else 438 523 { 524 // handshake finished registring new player 439 525 if ( it->second.handshake->canDel() ) 440 526 { 441 if ( t ype == NET_SERVER )527 if ( this->pInfo->nodeType == NET_MASTER_SERVER ) 442 528 { 443 handleNewClient( it->second.userId ); 529 it->second.nodeType = it->second.handshake->getRemoteNodeType(); 530 it->second.ip = it->second.socket->getRemoteAddress(); 531 532 this->networkMonitor->addNode(&it->second); 533 534 this->handleNewClient( it->second.userId ); 444 535 445 536 if ( PlayerStats::getStats( it->second.userId ) && it->second.handshake->getPreferedNickName() != "" ) … … 468 559 469 560 /** 561 * this functions handles a reconnect event received from the a NET_MASTER_SERVER or NET_PROXY_SERVER 562 */ 563 void NetworkStream::handleReconnect(int userId) 564 { 565 PRINTF(0)("===============================================\n"); 566 PRINTF(0)("Client is redirected to the other proxy servers\n"); 567 PRINTF(0)("===============================================\n"); 568 569 PeerInfo* pInfo = &this->peers[userId]; 570 571 // reject the server 572 pInfo->handshake->doReject( "redirected to different server"); 573 574 // flush the old synchronization states, since the numbering could be completely different 575 pInfo->lastAckedState = 0; 576 pInfo->lastRecvedState = 0; 577 // not sure if this works as expected 578 if( pInfo->handshake) 579 delete pInfo->handshake; 580 581 // disconnect from the current server and reconnect to proxy server 582 pInfo->socket->reconnectToServer( pInfo->handshake->getProxy1Address().ipString(), pInfo->handshake->getProxy1Address().port()); 583 584 // and restart the handshake 585 this->startHandshake(); 586 } 587 588 589 /** 470 590 * handle upstream network traffic 471 591 */ … … 513 633 514 634 // if we are a server and this is not our handshake 515 if ( is Server() && sync.getLeafClassID() == CL_HANDSHAKE && sync.getUniqueID() != peer->second.userId )635 if ( isMasterServer() && sync.getLeafClassID() == CL_HANDSHAKE && sync.getUniqueID() != peer->second.userId ) 516 636 continue; 517 637 … … 524 644 525 645 // server fakes uniqueid == 0 for handshake 526 if ( this->is Server() && sync.getUniqueID() < MAX_CONNECTIONS- 1 )646 if ( this->isMasterServer() && sync.getUniqueID() < SharedNetworkData::getInstance()->getMaxPlayer() - 1 ) 527 647 n = Converter::intToByteArray( 0, buf + offset, UDP_PACKET_SIZE - offset ); 528 648 else … … 573 693 // now compress the data with the zip library 574 694 int compLength = 0; 575 if ( this->is Server() )695 if ( this->isMasterServer() ) 576 696 compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE, dictServer ); 577 697 else … … 637 757 assert( Converter::byteArrayToInt( buf + 2*INTSIZE, &fromState ) == INTSIZE ); 638 758 assert( Converter::byteArrayToInt( buf + 3*INTSIZE, &ackedState ) == INTSIZE ); 639 //NETPRINTF(n)("ackedstate: %d\n", ackedState);640 759 offset = 4*INTSIZE; 641 760 642 761 peer->second.connectionMonitor->processUnzippedIncomingPacket( tick, buf, packetLength, state, ackedState ); 643 762 644 //NETPRINTF(n)("got packet: %d, %d\n", length, packetLength); 645 646 //if this is an old state drop it 763 764 //if this is an old state drop it 647 765 if ( state <= peer->second.lastRecvedState ) 648 766 continue; … … 688 806 } 689 807 690 if ( !peers[peer->second.userId].is Server)808 if ( !peers[peer->second.userId].isMasterServer() ) 691 809 { 692 810 offset += syncDataLength; … … 779 897 /** 780 898 * is executed when a handshake has finished 781 * @todo create playable for new user782 899 */ 783 900 void NetworkStream::handleNewClient( int userId ) 784 901 { 902 // init and assign the message manager 785 903 MessageManager::getInstance()->initUser( userId ); 786 904 // do all game relevant stuff here 787 905 networkGameManager->signalNewPlayer( userId ); 788 } 906 907 // register the new client at the network monitor 908 // this->networkMonitor->addClient(); 909 } 910 789 911 790 912 /** -
branches/proxy/src/lib/network/network_stream.h
r9246 r9347 14 14 #include "server_socket.h" 15 15 #include "handshake.h" 16 #include " connection_monitor.h"16 #include "monitor/connection_monitor.h" 17 17 #include "udp_server_socket.h" 18 #include "peer_info.h" 19 20 #include "shared_network_data.h" 18 21 19 22 class Synchronizeable; … … 21 24 class ServerSocket; 22 25 class NetworkGameManager; 26 class NetworkMonitor; 23 27 24 //!< this structure contains informations about the network node25 class PeerInfo26 {27 public:28 PeerInfo() { clear(); }29 void clear() { userId = 0; isServer = false; socket = NULL; handshake = NULL; lastAckedState = 0; lastRecvedState = 0; connectionMonitor = NULL; }30 31 32 public:33 int userId;34 bool isServer;35 NetworkSocket * socket;36 Handshake * handshake;37 ConnectionMonitor * connectionMonitor;38 int lastAckedState;39 int lastRecvedState;40 };41 28 42 29 typedef std::list<Synchronizeable*> SynchronizeableList; … … 58 45 void startHandshake(); 59 46 47 /* synchronizeable interface */ 60 48 void connectSynchronizeable(Synchronizeable& sync); 61 49 void disconnectSynchronizeable(Synchronizeable& sync); 62 50 63 inline bool isServer() const { return (this->type == NET_SERVER)? true:false; } 64 inline bool isActive() const { return this->bActive; } 51 /* functions for the localhost settings */ 52 inline bool isMasterServer() const { return (this->pInfo->nodeType == NET_MASTER_SERVER)? true:false; } 53 inline bool isProxyServer() const { return (this->pInfo->nodeType == NET_PROXY_SERVER_ACTIVE)? true:false; } 54 inline bool isClient() const { return (this->pInfo->nodeType == NET_CLIENT)? true:false; } 55 // inline bool isActive() const { return this->bActive; } 56 inline int getMaxConnections(){ return SharedNetworkData::getInstance()->getMaxPlayer(); } 65 57 66 inline int getMaxConnections(){ return MAX_CONNECTIONS; } 58 /* functions for the peerInfo information retreival */ 59 inline bool isUserIdActive( int userID ) { return (peers.find(userID) != peers.end()); } 60 inline bool isUserMasterServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isMasterServer(); } 61 inline bool isUserProxyServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isProxyServer(); } 62 inline bool isUserClient( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isClient(); } 67 63 64 /* peering interface */ 65 inline PeerInfo & getPeerInfo( int userId ) { return peers[userId]; } 66 inline PeerInfo* getPeerInfo() { return this->pInfo; } 67 inline PeerList getPeerInfoList() { return this->peers; } 68 69 /* data processing*/ 68 70 virtual void processData(); 71 72 /* debugging */ 73 void debug(); 74 75 76 private: 69 77 70 78 inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); } 71 79 inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); } 80 void cleanUpOldSyncList(); 72 81 int getSyncCount(); 73 82 74 inline bool isUserIdActive( int userID ) { return (peers.find(userID) != peers.end()); }75 inline bool isUserServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isServer; }76 77 void debug();78 79 inline PeerInfo & getPeerInfo( int userId ) { return peers[userId]; }80 81 82 private:83 83 void updateConnectionList(); 84 /* handle processes */ 84 85 void handleHandshakes(); 85 86 void handleUpstream( int tick ); 86 87 void handleDownstream(int tick ); 88 89 /* handle events*/ 87 90 void handleNewClient( int userId ); 88 void cleanUpOldSyncList();91 void handleReconnect( int userId ); 89 92 90 93 void writeToNewDict( byte * data, int length, bool upstream ); … … 92 95 93 96 private: 94 SynchronizeableList synchronizeables; 95 PeerList peers; 96 ServerSocket* serverSocket; 97 int type; 98 bool bActive; 99 std::list<int> freeSocketSlots; 97 PeerList peers; //!< list of the network node informations 100 98 101 int myHostId;99 PeerInfo* pInfo; //!< the info about the local peer node (not in the PeerList) 102 100 101 std::list<int> freeSocketSlots; //!< list of free sockets (to ensure not to resycle sockets) 103 102 int currentState; //!< current state id 104 103 105 NetworkGameManager* networkGameManager; 104 NetworkMonitor* networkMonitor; //!< the network monitor 105 NetworkGameManager* networkGameManager; //!< reference to the network game manager 106 ServerSocket* serverSocket; //!< the listening socket of the server 106 107 107 108 std::map<int,int> oldSynchronizeables; //!< used to save recently deleted sync ids to not recreate them 109 SynchronizeableList synchronizeables; //!< list of the synchronizeables 108 110 109 111 byte buf[UDP_PACKET_SIZE]; //!< used by handleUp/Downstream 110 112 byte compBuf[UDP_PACKET_SIZE]; //!< used by handleUp/Downstream 111 112 113 int remainingBytesToWriteToDict; //!< if > 0 NetworkStream will write packets to DATA/dicts/newdict 113 114 114 int dictServer;115 int dictClient;115 int dictServer; //!< the zip dict for the server 116 int dictClient; //!< the zip dict for the client 116 117 }; 117 118 #endif /* _NETWORK_STREAM */ -
branches/proxy/src/lib/network/player_stats.cc
r9235 r9347 38 38 { 39 39 init(); 40 40 41 41 this->userId = userId; 42 42 } … … 62 62 this->nickName = "Player"; 63 63 this->oldNickName = "Player"; 64 64 65 65 userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) ); 66 66 teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) ); … … 71 71 modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) ); 72 72 nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName" ) ); 73 73 74 74 MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGENICKNAME, changeNickHandler, NULL ); 75 75 76 76 PRINTF(0)("PlayerStats created\n"); 77 77 } … … 96 96 { 97 97 this->setPlayableUniqueId( this->playableUniqueId ); 98 98 99 99 PRINTF(0)("uniqueID changed %d %d %d\n", userId, SharedNetworkData::getInstance()->getHostID(), getUniqueID()); 100 100 } 101 101 102 102 if ( std::find( id.begin(), id.end(), nickName_handler ) != id.end() ) 103 103 { … … 115 115 { 116 116 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 117 117 118 118 if ( !list ) 119 119 { 120 120 return NULL; 121 121 } 122 122 123 123 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 124 124 { … … 128 128 } 129 129 } 130 130 131 131 return NULL; 132 132 } … … 138 138 { 139 139 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE ); 140 140 141 141 if ( !list ) 142 142 { … … 144 144 return; 145 145 } 146 146 147 147 this->playable = NULL; 148 148 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) … … 156 156 } 157 157 } 158 158 159 159 if ( this->playable && userId == SharedNetworkData::getInstance()->getHostID() ) 160 160 { 161 161 State::getPlayer()->setPlayable( this->playable ); 162 162 } 163 163 164 164 this->playableUniqueId = uniqueId; 165 165 } … … 173 173 if ( playable ) 174 174 return playable; 175 175 176 176 assert( playableUniqueId > 0 ); 177 177 178 178 setPlayableUniqueId( playableUniqueId ); 179 179 180 180 assert( playable ); 181 181 182 182 return playable; 183 183 } … … 189 189 void PlayerStats::setNickName( std::string nick ) 190 190 { 191 if ( SharedNetworkData::getInstance()->is GameServer() )191 if ( SharedNetworkData::getInstance()->isMasterServer() ) 192 192 { 193 193 this->nickName = nick; … … 199 199 { 200 200 byte * data = new byte[nick.length()+INTSIZE]; 201 201 202 202 assert( Converter::stringToByteArray( nick, data, nick.length()+INTSIZE) == nick.length()+INTSIZE ); 203 203 204 204 MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, 0, MP_HIGHBANDWIDTH ); 205 205 return; … … 211 211 std::string newNick; 212 212 int res = Converter::byteArrayToString( data, newNick, dataLength ); 213 213 214 214 if ( res != dataLength ) 215 215 { … … 217 217 newNick = "invalid"; 218 218 } 219 219 220 220 if ( PlayerStats::getStats( userId ) ) 221 221 PlayerStats::getStats( userId )->setNickName( newNick ); 222 222 223 223 return true; 224 224 } … … 228 228 if ( getStats( SharedNetworkData::getInstance()->getHostID() ) ) 229 229 getStats( SharedNetworkData::getInstance()->getHostID() )->setNickName( newNick ); 230 230 231 231 Preferences::getInstance()->setString( "multiplayer", "nickname", newNick ); 232 232 } … … 237 237 { 238 238 const std::list<BaseObject*> * list; 239 239 240 240 while ( (list = ClassList::getList( CL_PLAYER_STATS )) != NULL && list->begin() != list->end() ) 241 241 delete *list->begin(); … … 247 247 { 248 248 ScoreList result; 249 249 250 250 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 251 251 252 252 if ( !list ) 253 253 { 254 254 return result; 255 255 } 256 256 257 257 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 258 258 { 259 259 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); 260 260 261 261 TeamScoreList::iterator it = result[stats.getTeamId()].begin(); 262 262 263 263 while ( it != result[stats.getTeamId()].end() && stats.score > it->score ) 264 264 { 265 265 it++; 266 266 } 267 267 268 268 PlayerScore score; 269 269 score.name = stats.getNickName(); 270 270 score.score = stats.getScore(); 271 271 272 272 result[stats.getTeamId()].insert(it, score); 273 273 } 274 274 275 275 return result; 276 276 } -
branches/proxy/src/lib/network/shared_network_data.cc
r9110 r9347 35 35 this->hostID = -1; 36 36 this->defaultSyncStream = NULL; 37 this->newUniqueID = MAX_CONNECTIONS + 2;38 this-> bGameServer = false;37 this->newUniqueID = NET_MAX_CONNECTIONS + 2; 38 this->nodeType = NET_CLIENT; 39 39 } 40 40 -
branches/proxy/src/lib/network/shared_network_data.h
r6695 r9347 8 8 9 9 #include "base_object.h" 10 #include "netdefs.h" 11 #include "proxy/proxy_settings.h" 10 12 11 13 12 14 class NetworkStream; 13 15 class Synchronizeable; 14 template<typename> 15 class tList; 16 16 17 17 18 /* and here is the class itsself*/ … … 25 26 26 27 /** @returns the next uniqueID free for an object */ 27 inline int getNewUniqueID() { return ( this-> bGameServer)?this->newUniqueID++:-1; }28 inline int getNewUniqueID() { return ( this->nodeType != NET_CLIENT)?this->newUniqueID++:-1; } 28 29 29 /** @returns true is this node is a game server */ 30 inline bool isGameServer() { return this->bGameServer; } 30 /** @returns true is this node is a master server */ 31 inline bool isMasterServer() { return this->nodeType == NET_MASTER_SERVER; } 32 /** @returns true is this node is a proxy server */ 33 inline bool isProxyServer() { return this->nodeType == NET_PROXY_SERVER_ACTIVE; } 34 /** @returns true is this node is a client*/ 35 inline bool isClient() { return this->nodeType == NET_CLIENT; } 31 36 /** sets the game server flag @param bGameServer true if it is a game server */ 32 inline void setGameServer(bool bGameServer) { this->bGameServer = bGameServer; } 37 inline void setNodeType(int nodeType) { this->nodeType = nodeType; } 38 39 /** @returns the maximum number of players for this server */ 40 inline int getMaxPlayer() { return ProxySettings::getInstance()->getMaxPlayer(); } 33 41 34 42 /** @returns the hostID of the node */ … … 49 57 private: 50 58 int newUniqueID; //!< next uniqueID 51 bool bGameServer; //!< true if it is a server 59 int nodeType; //!< saves the node type here 60 52 61 int hostID; //!< The Host-ID of the Manager 53 62 NetworkStream* defaultSyncStream; //!< default synchronize NetworkStream -
branches/proxy/src/lib/network/synchronizeable.cc
r9110 r9347 38 38 this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable"); 39 39 this->owner = 0; 40 this->setIsServer(SharedNetworkData::getInstance()->getHostID() == 0);40 // this->setIsServer(SharedNetworkData::getInstance()->getHostID() == 0); 41 41 this->uniqueID = NET_UID_UNASSIGNED; 42 42 this->networkStream = NULL; 43 43 this->bSynchronize = false; 44 44 45 45 if( State::isOnline()) 46 46 { … … 54 54 assert( syncVarList.size() == 0 ); 55 55 mLeafClassId = this->registerVarId( new SynchronizeableInt( (int*)&this->getLeafClassID(), (int*)&this->getLeafClassID(), "leafClassId" ) ); 56 56 57 57 this->registerVar( new SynchronizeableInt( &this->owner, &this->owner, "owner" ) ); 58 58 this->registerVar( new SynchronizeableString( &this->objectName, &this->objectName, "objectName" ) ); … … 69 69 { 70 70 this->networkStream->disconnectSynchronizeable(*this); 71 72 if ( this->isServer() && this->beSynchronized() && this->getUniqueID() > 0 && !this->isA( CL_MESSAGE_MANAGER ) )71 72 if ( SharedNetworkData::getInstance()->isMasterServer() && this->beSynchronized() && this->getUniqueID() > 0 && !this->isA( CL_MESSAGE_MANAGER ) ) 73 73 NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() ); 74 74 } 75 75 76 76 for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ ) 77 77 { … … 79 79 } 80 80 syncVarList.clear(); 81 81 82 82 for ( UserStateHistory::iterator it = recvStates.begin(); it != recvStates.end(); it++ ) 83 83 { … … 93 93 94 94 } 95 95 96 96 for ( UserStateHistory::iterator it = sentStates.begin(); it != sentStates.end(); it++ ) 97 97 { … … 105 105 delete *it2; 106 106 } 107 108 } 109 } 110 111 /** 112 * Sets the server flag to a given value 113 * @param isServer: the boolean value which the server flag is to set to 114 */ 115 void Synchronizeable::setIsServer(bool isServer) 116 { 117 if( isServer ) 118 this->state = this->state | STATE_SERVER; 119 else 120 this->state = this->state & (~STATE_SERVER); 121 } 122 123 124 /** 125 * Determines if the server flag is set 126 * @return true, if the server flag is true, false else 127 */ 128 bool Synchronizeable::isServer() 129 { 130 return (this->state & STATE_SERVER) >0; 107 } 131 108 } 132 109 … … 169 146 (*it2)->data = NULL; 170 147 } 171 148 172 149 delete *it2; 173 150 } … … 181 158 while ( it != sentStates[userId].end() && (*it)->stateId != fromStateId ) 182 159 it++; 183 184 // if ( getLeafClassID() == CL_SPACE_SHIP )185 // {186 // PRINTF(0)("getStateDiff:SpaceShip from: %d stateId: %d\n", (it == sentStates[userId].end())?-1:fromStateId, stateId);187 // }188 160 189 161 if ( it == sentStates[userId].end() ) … … 196 168 197 169 stateFrom = initialEntry; 198 170 199 171 sentStates[userId].push_back( stateFrom ); 200 172 } … … 205 177 206 178 sentStates[userId].push_back( stateTo ); 207 179 208 180 stateTo->stateId = stateId; 209 181 stateTo->dataLength = neededSize; … … 214 186 int i = 0; 215 187 int n; 216 188 217 189 bool hasPermission; 218 190 bool sizeChanged = false; … … 222 194 { 223 195 hasPermission = ( 224 this->isServer() && (*it)->checkPermission( PERMISSION_SERVER ) ||196 SharedNetworkData::getInstance()->isMasterServer() && (*it)->checkPermission( PERMISSION_MASTER_SERVER ) || 225 197 this->owner == SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) || 226 this->isServer() && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ) ||227 (*it)->checkPermission( PERMISSION_ALL ) 198 SharedNetworkData::getInstance()->isMasterServer() && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ) || 199 (*it)->checkPermission( PERMISSION_ALL ) 228 200 ); 229 230 if ( sizeIter == stateFrom->sizeList.end() || *sizeIter != (*it)->getSize() ) 201 202 if ( sizeIter == stateFrom->sizeList.end() || *sizeIter != (*it)->getSize() ) 231 203 sizeChanged = true; 232 204 233 205 if ( ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeChanged ) 234 206 { … … 303 275 it++; 304 276 305 277 306 278 // if ( getLeafClassID() == CL_SPACE_SHIP ) 307 279 // { … … 318 290 319 291 stateFrom = initialEntry; 320 292 321 293 recvStates[userId].push_back( stateFrom ); 322 294 } 323 295 else 324 296 stateFrom = (*it); 325 297 326 298 //apply diff 327 299 for ( int i = 0; i<length; i++ ) … … 331 303 else 332 304 stateTo->data[i] = data[i]; 333 334 } 335 305 306 } 307 336 308 //add state to state history 337 309 recvStates[userId].push_back( stateTo ); 338 310 339 311 int i = 0; 340 312 int n = 0; 341 313 std::list<int> changes; 342 314 343 315 for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ ) 344 316 { 345 317 if ( 346 (*it)->checkPermission( PERMISSION_ SERVER ) && networkStream->isUserServer( userId ) ||318 (*it)->checkPermission( PERMISSION_MASTER_SERVER ) && networkStream->isUserMasterServer( userId ) || 347 319 (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == userId || 348 networkStream->isUser Server( userId ) && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) ||349 (*it)->checkPermission( PERMISSION_ALL ) 320 networkStream->isUserMasterServer( userId ) && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER ) || 321 (*it)->checkPermission( PERMISSION_ALL ) 350 322 ) 351 323 { … … 361 333 else 362 334 { 363 // PRINTF(0)("DONT SET VAR BECAUSE OF PERMISSION: %s %d %d %d %d %d %d\n", (*it)->getName().c_str(), (*it)->checkPermission( PERMISSION_ SERVER ), (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_ALL ), networkStream->isUserServer( userId ), this->owner, userId );335 // PRINTF(0)("DONT SET VAR BECAUSE OF PERMISSION: %s %d %d %d %d %d %d\n", (*it)->getName().c_str(), (*it)->checkPermission( PERMISSION_MASTER_SERVER ), (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_ALL ), networkStream->isUserServer( userId ), this->owner, userId ); 364 336 n = (*it)->getSizeFromBuf( stateTo->data + i, stateTo->dataLength - i ); 365 337 //NETPRINTF(0)("%s::setvar %s %d\n", getClassName(), (*it)->getName().c_str(), n); … … 370 342 371 343 this->varChangeHandler( changes ); 372 344 373 345 return i; 374 346 } … … 423 395 (*it)->data = NULL; 424 396 } 425 397 426 398 delete *it; 427 399 } 428 400 recvStates[userId].clear(); 429 401 } 430 402 431 403 if ( sentStates.size() > userId ) 432 404 { 433 405 434 406 for ( std::list<StateHistoryEntry*>::iterator it = sentStates[userId].begin(); it != sentStates[userId].end(); it++ ) 435 407 { … … 439 411 (*it)->data = NULL; 440 412 } 441 413 442 414 delete *it; 443 415 } … … 448 420 /** 449 421 * this function is called after recieving a state. 450 * @param userId 451 * @param stateId 452 * @param fromStateId 422 * @param userId 423 * @param stateId 424 * @param fromStateId 453 425 */ 454 426 void Synchronizeable::handleRecvState( int userId, int stateId, int fromStateId ) … … 457 429 if ( recvStates.size() <= userId ) 458 430 recvStates.resize( userId+1 ); 459 431 460 432 //remove old states 461 433 StateHistory::iterator it = recvStates[userId].begin(); … … 485 457 StateHistory::iterator delIt = it; 486 458 it ++; 487 459 488 460 if ( (*delIt)->data ) 489 461 { … … 493 465 delete *delIt; 494 466 recvStates[userId].erase( delIt ); 495 467 496 468 continue; 497 469 } 498 470 it++; 499 471 } 500 472 501 473 StateHistory::iterator fromState = recvStates[userId].end(); 502 474 StateHistory::iterator toState = recvStates[userId].end(); 503 475 504 476 for ( it = recvStates[userId].begin(); it != recvStates[userId].end(); it++ ) 505 477 { … … 508 480 if ( (*it)->stateId == fromStateId ) 509 481 fromState = it; 510 482 511 483 if ( fromState != recvStates[userId].end() && toState != recvStates[userId].end() ) 512 484 break; 513 485 } 514 486 515 487 // setStateDiff was not called and i know fromStateId 516 488 if ( fromState != recvStates[userId].end() && toState == recvStates[userId].end() ) 517 489 { 518 490 StateHistoryEntry * entry = new StateHistoryEntry; 519 491 520 492 entry->dataLength = (*fromState)->dataLength; 521 493 if ( entry->dataLength > 0 ) 522 494 { 523 495 entry->data = new byte[entry->dataLength]; 524 496 525 497 assert( (*fromState)->data ); 526 498 memcpy( entry->data, (*fromState)->data, entry->dataLength ); … … 528 500 else 529 501 entry->data = NULL; 530 502 531 503 entry->sizeList = (*fromState)->sizeList; 532 504 entry->stateId = stateId; 533 505 534 506 recvStates[userId].push_back(entry); 535 507 } … … 538 510 /** 539 511 * this function is called after sending a state 540 * @param userId 541 * @param stateId 542 * @param fromStateId 512 * @param userId 513 * @param stateId 514 * @param fromStateId 543 515 */ 544 516 void Synchronizeable::handleSentState( int userId, int stateId, int fromStateId ) … … 557 529 StateHistory::iterator delIt = it; 558 530 it ++; 559 531 560 532 if ( (*delIt)->data ) 561 533 { … … 565 537 delete *delIt; 566 538 sentStates[userId].erase( delIt ); 567 539 568 540 continue; 569 541 } … … 571 543 } 572 544 573 545 574 546 StateHistory::iterator fromState = sentStates[userId].end(); 575 547 StateHistory::iterator toState = sentStates[userId].end(); 576 548 577 549 for ( it = sentStates[userId].begin(); it != sentStates[userId].end(); it++ ) 578 550 { … … 581 553 if ( (*it)->stateId == fromStateId ) 582 554 fromState = it; 583 555 584 556 if ( fromState != sentStates[userId].end() && toState != sentStates[userId].end() ) 585 557 break; 586 558 } 587 559 588 560 589 561 // getStateDiff was not called and i know fromStateId 590 562 if ( fromState != sentStates[userId].end() && toState == sentStates[userId].end() ) 591 563 { 592 564 StateHistoryEntry * entry = new StateHistoryEntry; 593 565 594 566 entry->dataLength = (*fromState)->dataLength; 595 567 if ( entry->dataLength > 0 ) 596 568 { 597 569 entry->data = new byte[entry->dataLength]; 598 570 599 571 assert( (*fromState)->data ); 600 572 memcpy( entry->data, (*fromState)->data, entry->dataLength ); … … 602 574 else 603 575 entry->data = NULL; 604 576 605 577 entry->sizeList = (*fromState)->sizeList; 606 578 entry->stateId = stateId; 607 579 608 580 sentStates[userId].push_back(entry); 609 581 } 610 611 } 612 613 614 582 583 } 584 585 586 -
branches/proxy/src/lib/network/synchronizeable.h
r8708 r9347 20 20 #include "synchronizeable_var/synchronizeable_bool.h" 21 21 #include "synchronizeable_var/synchronizeable_uint.h" 22 #include "synchronizeable_var/synchronizeable_ip.h" 22 23 23 24 … … 51 52 virtual ~Synchronizeable(); 52 53 53 void setIsServer( bool isServer );54 bool isServer();54 // void setIsServer( bool isServer ); 55 // bool isServer(); 55 56 56 57 virtual void varChangeHandler( std::list<int> & id ); … … 61 62 virtual void handleSentState( int userId, int stateId, int fromStateId ); 62 63 virtual void handleRecvState( int userId, int stateId, int fromStateId ); 63 64 64 65 void registerVar( SynchronizeableVar * var ); 65 66 int registerVarId( SynchronizeableVar * var ); … … 82 83 protected: 83 84 NetworkStream* networkStream; //!< reference network stream we are connected to 84 int state;85 // int state; 85 86 86 87 private: -
branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_bool.h
r7954 r9347 12 12 13 13 public: 14 SynchronizeableBool( bool * ptrIn, bool * ptrOut, std::string name, int permission = PERMISSION_ SERVER, int priority = 0 );14 SynchronizeableBool( bool * ptrIn, bool * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 15 15 virtual ~SynchronizeableBool(); 16 16 -
branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_float.h
r7954 r9347 12 12 13 13 public: 14 SynchronizeableFloat( float * ptrIn, float * ptrOut, std::string name, int permission = PERMISSION_ SERVER, int priority = 0 );14 SynchronizeableFloat( float * ptrIn, float * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 15 15 virtual ~SynchronizeableFloat(); 16 16 -
branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_int.h
r7954 r9347 12 12 13 13 public: 14 SynchronizeableInt( int * ptrIn, int * ptrOut, std::string name, int permission = PERMISSION_ SERVER, int priority = 0 );14 SynchronizeableInt( int * ptrIn, int * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 15 15 virtual ~SynchronizeableInt(); 16 16 -
branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_quaternion.h
r7954 r9347 14 14 15 15 public: 16 SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission = PERMISSION_ SERVER, int priority = 0 );16 SynchronizeableQuaternion( Quaternion * ptrIn, Quaternion * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 17 17 virtual ~SynchronizeableQuaternion(); 18 18 -
branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_string.h
r7954 r9347 15 15 16 16 public: 17 SynchronizeableString( std::string * ptrIn, std::string * ptrOut, std::string name, int permission = PERMISSION_ SERVER, int priority = 0 );17 SynchronizeableString( std::string * ptrIn, std::string * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 18 18 virtual ~SynchronizeableString(); 19 19 -
branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_uint.h
r7954 r9347 12 12 13 13 public: 14 SynchronizeableUInt( unsigned int * ptrIn, unsigned int * ptrOut, std::string name, int permission = PERMISSION_ SERVER, int priority = 0 );14 SynchronizeableUInt( unsigned int * ptrIn, unsigned int * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 15 15 virtual ~SynchronizeableUInt(); 16 16 -
branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_var.h
r7954 r9347 12 12 13 13 enum { 14 PERMISSION_SERVER = 1, 15 PERMISSION_OWNER = 2, 16 PERMISSION_ALL = 4 14 PERMISSION_MASTER_SERVER = 1, 15 PERMISSION_PROXY_SERVER = 2, 16 PERMISSION_OWNER = 4, 17 PERMISSION_ALL = 8 17 18 }; 18 19 … … 20 21 21 22 public: 22 SynchronizeableVar( void * ptrIn, void * ptrOut, std::string name, int length, int permission = PERMISSION_ SERVER, int priority = 0 );23 SynchronizeableVar( void * ptrIn, void * ptrOut, std::string name, int length, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 23 24 virtual ~SynchronizeableVar(); 24 25 … … 28 29 */ 29 30 inline bool beWatched(){ return this->bWatched; } 30 31 /** 31 32 /** 32 33 * set flag if synchronizeable wants to be informed on changes 33 34 */ … … 96 97 */ 97 98 inline void resetPriority() { this->priority = this->realPriority; } 98 99 99 100 /** 100 101 * reads actual size from buffer. this is used when size is not constant … … 104 105 */ 105 106 virtual inline int getSizeFromBuf( byte * buf, int maxLength ){ return this->getSize(); } 106 107 107 108 /** 108 109 * set variable id … … 110 111 */ 111 112 inline void setVarId( int id ){ this->varId = id; } 112 113 /** 113 114 /** 114 115 * get variable id 115 116 * @return variable id 116 117 */ 117 118 inline int getVarId(){ return varId; } 118 119 119 120 /** 120 121 * set hasChanged … … 122 123 */ 123 124 inline void setHasChanged( bool changed ){ this->changed = changed; } 124 125 /** 125 126 /** 126 127 * get hasChanged 127 128 * @return variable id 128 129 */ 129 130 inline bool getHasChanged(){ return changed; } 130 131 131 132 /** 132 133 * print out variable value … … 137 138 private: 138 139 bool bWatched; //!< true if synchronizeable wants to be informed on changes 139 140 140 141 int permission; //!< who is allowed to change this var 141 142 int priority; //!< priority assigned to var 142 143 int realPriority; //!< priority assigned to var, increased every time not sent 143 144 int varId; //!< id to identify varables 144 145 145 146 bool changed; //!< true if last readFromBuf changed anything 146 147 -
branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_vector.h
r7954 r9347 14 14 15 15 public: 16 SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission = PERMISSION_ SERVER, int priority = 0 );16 SynchronizeableVector( Vector * ptrIn, Vector * ptrOut, std::string name, int permission = PERMISSION_MASTER_SERVER, int priority = 0 ); 17 17 virtual ~SynchronizeableVector(); 18 18 -
branches/proxy/src/lib/network/tcp_server_socket.cc
r7954 r9347 136 136 _isListening = false; 137 137 } 138 -
branches/proxy/src/lib/network/tcp_server_socket.h
r7954 r9347 28 28 virtual void close(); 29 29 virtual void update() {}; 30 30 31 31 private: 32 32 TCPsocket listenSocket; … … 36 36 37 37 void init(); 38 38 39 39 }; 40 40 -
branches/proxy/src/lib/network/tcp_socket.h
r7954 r9347 1 1 /*! 2 * @file network_socket.h3 * Main interface for the network module. Manages all the modules2 * @file tcp_socket.h 3 * tcp socket network interface 4 4 5 5 */ … … 47 47 48 48 virtual void connectToServer( std::string host, int port ); 49 49 50 50 virtual void disconnectServer(); 51 virtual void reconnectToServer( std::string host, int port); 52 virtual void reconnectToServerSoft( std::string host, int port); 51 53 52 54 virtual bool writePacket(byte * data, int length); -
branches/proxy/src/lib/network/udp_socket.cc
r8802 r9347 74 74 { 75 75 this->init(); 76 this->ip = ip; 76 77 this->serverSocket = serverSocket; 77 78 this->userId = userId; … … 105 106 assert( serverSocket == NULL ); 106 107 107 IPaddress ip;108 109 108 this->randomByte = generateNewRandomByte(); 110 109 111 110 PRINTF(0)("connect to server %s on port %d\n", host.c_str(), port); 112 111 113 if ( SDLNet_ResolveHost( & ip, host.c_str(), port ) != 0 )112 if ( SDLNet_ResolveHost( &this->ip, host.c_str(), port ) != 0 ) 114 113 { 115 114 PRINTF(1)("SDLNet_ResolveHost: %s\n", SDLNet_GetError() ); … … 126 125 } 127 126 128 int channel = SDLNet_UDP_Bind(socket, 1, & ip);127 int channel = SDLNet_UDP_Bind(socket, 1, &this->ip); 129 128 if ( channel == -1 ) 130 129 { … … 147 146 bOk = false; 148 147 socket = NULL; 149 } 148 149 this->ip.host = 0; 150 this->ip.port = 0; 151 } 152 153 154 /** 155 * reconnects to 156 * @param host new server address 157 * @param port new port number 158 * 159 * this terminates the current connection and starts a new connection to the new server 160 */ 161 void UdpSocket::reconnectToServer( std::string host, int port) 162 { 163 // first disconnect the old server 164 this->disconnectServer(); 165 166 // now connect to the new 167 this->connectToServer( host, port); 168 } 169 170 171 /** 172 * reconnects to 173 * @param host new server address 174 * @param port new port number 175 * 176 * this terminates the current connection and starts a new connection to the new server 177 */ 178 void UdpSocket::reconnectToServerSoft( std::string host, int port) 179 {} 180 150 181 151 182 /** … … 179 210 180 211 byte udpCmd = 0; 181 212 182 213 if ( networkPacket.length > 0 ) 183 214 { … … 189 220 else 190 221 return 0; 191 222 192 223 if ( !checkRandomByte( networkPacket.data[0] ) ) 193 224 return 0; … … 198 229 networkPacket.data = NULL; 199 230 } 200 231 201 232 if ( !checkUdpCmd( udpCmd ) ) 202 233 return 0; … … 207 238 { 208 239 int numrecv = SDLNet_UDP_Recv( socket, packet); 209 240 210 241 byte udpCmd = 0; 211 242 … … 218 249 else 219 250 return 0; 220 251 221 252 if ( !checkRandomByte( packet->data[0] ) ) 222 253 return 0; 223 254 224 255 if ( !checkUdpCmd( udpCmd ) ) 225 256 return 0; … … 283 314 return false; 284 315 } 285 316 286 317 if ( !this->serverSocket && ( udpCmd & UDPCMD_INVALIDRNDBYTE ) ) 287 318 { … … 292 323 return false; 293 324 } 294 325 295 326 return true; 296 327 } … … 300 331 srand( SDL_GetTicks() ); 301 332 byte res = ( rand() & 0xFC ); 302 333 303 334 PRINTF(0)("generated random byte: %x\n", res); 304 335 305 336 return res; 306 337 } -
branches/proxy/src/lib/network/udp_socket.h
r8802 r9347 31 31 32 32 virtual void connectToServer( std::string host, int port ); 33 34 33 virtual void disconnectServer(); 35 34 35 virtual void reconnectToServer( std::string host, int port); 36 virtual void reconnectToServerSoft( std::string host, int port); 37 36 38 virtual bool writePacket(byte * data, int length ); 39 virtual int readPacket(byte * data, int maxLength); 37 40 38 virtual int readPacket(byte * data, int maxLength); 39 41 40 42 private: 41 43 UdpServerSocket * serverSocket; //!< will get packets here 42 44 int userId; //!< user id used by serverSocket 43 IPaddress ip; //!< host,port44 45 UDPsocket socket; //!< socket used to send/recieve 45 46 UDPpacket * packet; 46 47 47 48 byte randomByte; //!< contains random bytes & 0xFC 48 49 49 50 bool writeRawPacket( byte * data, int length ); 50 51 bool checkUdpCmd( byte udpCmd ); 51 52 bool checkRandomByte( byte rndByte ); 52 53 byte generateNewRandomByte(); 53 54 54 55 void init(); 55 56 -
branches/proxy/src/lib/shell/shell_command.cc
r9112 r9347 299 299 { 300 300 PRINT(0)("Command '%s' on '%s::%s'\n", sc->getName(), (*bo)->getClassName(), (*bo)->getName()); 301 (*sc->executor)((*bo), inputSplits. getSubSet(paramBegin));301 (*sc->executor)((*bo), inputSplits.subSet(paramBegin)); 302 302 } 303 303 return true; … … 375 375 // if(this->completors[parameter] == NULL) 376 376 // delete this->completors[parameter]; 377 // this->completors[parameter] = completorPlugin.clone(); 377 // this->completors[parameter] = completorPlugin.clone(); 378 378 } 379 379 return this; -
branches/proxy/src/lib/util/Makefile.am
r8724 r9347 6 6 libORXlibutil_a_SOURCES = \ 7 7 substring.cc \ 8 tokenizer.cc \9 8 color.cc \ 10 9 helper_functions.cc \ … … 32 31 noinst_HEADERS = \ 33 32 substring.h \ 34 tokenizer.h \35 33 multi_type.h \ 36 34 color.h \ -
branches/proxy/src/lib/util/executor/executor_functional.h
r8271 r9347 179 179 { 180 180 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( 181 fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)));181 (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0]))); 182 182 }; 183 183 … … 222 222 { 223 223 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( 224 fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)),225 fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)));224 (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0])), 225 (sub.size() > 1) ? fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)) : (fromMulti<type1>(this->defaultValue[1]))); 226 226 }; 227 227 … … 276 276 { 277 277 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( 278 fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)),279 fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)),280 fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2)));278 (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0])), 279 (sub.size() > 1) ? fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)) : (fromMulti<type1>(this->defaultValue[1])), 280 (sub.size() > 2) ? fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2)) : (fromMulti<type2>(this->defaultValue[2]))); 281 281 }; 282 282 … … 333 333 { 334 334 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( 335 fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)),336 fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)),337 fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2)),338 fromString<type3>(sub[3], getDefault<type3>(this->defaultValue, 3)));335 (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0])), 336 (sub.size() > 1) ? fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)) : (fromMulti<type1>(this->defaultValue[1])), 337 (sub.size() > 2) ? fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2)) : (fromMulti<type2>(this->defaultValue[2])), 338 (sub.size() > 3) ? fromString<type3>(sub[3], getDefault<type3>(this->defaultValue, 3)) : (fromMulti<type3>(this->defaultValue[3]))); 339 339 }; 340 340 … … 392 392 { 393 393 (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)( 394 fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)),395 fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)),396 fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2)),397 fromString<type3>(sub[3], getDefault<type3>(this->defaultValue, 3)),398 fromString<type4>(sub[4], getDefault<type4>(this->defaultValue, 4)));394 (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0])), 395 (sub.size() > 1) ? fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)) : (fromMulti<type1>(this->defaultValue[1])), 396 (sub.size() > 2) ? fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2)) : (fromMulti<type2>(this->defaultValue[2])), 397 (sub.size() > 3) ? fromString<type3>(sub[3], getDefault<type3>(this->defaultValue, 3)) : (fromMulti<type3>(this->defaultValue[3])), 398 (sub.size() > 4) ? fromString<type4>(sub[4], getDefault<type4>(this->defaultValue, 4)) : (fromMulti<type4>(this->defaultValue[4]))); 399 399 }; 400 400 -
branches/proxy/src/lib/util/executor/functor_list.h
r8894 r9347 135 135 136 136 //! mixed values: 137 FUNCTOR_LIST(2)(l_STRING, l_INT); 137 138 FUNCTOR_LIST(2)(l_STRING, l_FLOAT); 138 139 FUNCTOR_LIST(2)(l_UINT, l_LONG); -
branches/proxy/src/lib/util/multi_type.cc
r8316 r9347 18 18 #include "multi_type.h" 19 19 20 //#include "stdincl.h"21 #include <stddef.h>22 #include <stdlib.h>23 #include <string.h>24 #include <stdio.h>25 20 #include <sstream> 26 21 … … 28 23 #include "debug.h" 29 24 #endif 30 31 using namespace std;32 25 33 26 /** -
branches/proxy/src/lib/util/substring.cc
r7477 r9347 28 28 #include "substring.h" 29 29 30 #include <string.h>31 #include <cassert>32 33 34 30 /** 35 31 * @brief default constructor … … 108 104 109 105 /** @brief An empty String */ 110 const std::string SubString::emptyString = "";106 // const std::string SubString::emptyString = ""; 111 107 /** @brief Helper that gets you a String consisting of all White Spaces */ 112 108 const std::string SubString::WhiteSpaces = " \n\t"; … … 238 234 } 239 235 else 240 return SubString::emptyString; 236 { 237 static std::string empty; 238 return empty; 239 } 241 240 } 242 241 … … 250 249 * SubString::SubString(const SubString& subString, unsigned int subSetBegin) 251 250 */ 252 SubString SubString:: getSubSet(unsigned int subSetBegin) const251 SubString SubString::subSet(unsigned int subSetBegin) const 253 252 { 254 253 return SubString(*this, subSetBegin); … … 265 264 * SubString::SubString(const SubString& subString, unsigned int subSetBegin) 266 265 */ 267 SubString SubString:: getSubSet(unsigned int subSetBegin, unsigned int subSetEnd) const266 SubString SubString::subSet(unsigned int subSetBegin, unsigned int subSetEnd) const 268 267 { 269 268 return SubString(*this, subSetBegin, subSetEnd); … … 289 288 * Supports delimiters, escape characters, 290 289 * ignores special characters between safemode_char and between comment_char and linend '\n'. 291 *292 *293 290 */ 294 291 SubString::SPLIT_LINE_STATE -
branches/proxy/src/lib/util/substring.h
r8408 r9347 2 2 * @file substring.h 3 3 * @brief a small class to get the parts of a string separated by commas 4 * 5 * This class is also identified as a Tokenizer. It splits up one long 6 * String into multiple small ones by a designated Delimiter. 7 * 8 * Substring is Advanced, and it is possible, to split a string by ',' 9 * but also removing leading and trailing spaces around the comma. 10 * 11 * @example 12 * Split the String std::string st = "1345, The new empire , is , orxonox" 13 * is splitted with: 14 * SubString(st, ',', " \n\t") 15 * into 16 * "1345", "The new empire", "is", "orxonox" 17 * As you can see, the useless spaces around ',' were removed. 4 18 */ 5 19 6 #ifndef _ SUBSTRING_H7 #define _ SUBSTRING_H20 #ifndef __SUBSTRING_H__ 21 #define __SUBSTRING_H__ 8 22 9 23 #include <vector> … … 61 75 62 76 // retrieve a SubSet from the String 63 SubString getSubSet(unsigned int subSetBegin) const;64 SubString getSubSet(unsigned int subSetBegin, unsigned int subSetEnd) const;77 SubString subSet(unsigned int subSetBegin) const; 78 SubString subSet(unsigned int subSetBegin, unsigned int subSetEnd) const; 65 79 66 80 // retrieve Information from within … … 70 84 inline unsigned int size() const { return this->strings.size(); }; 71 85 /** @param i the i'th String @returns the i'th string from the subset of Strings */ 72 inline const std::string& operator[](unsigned int i) const { return (i < this->strings.size()) ? this->strings[i] : emptyString; };86 inline const std::string& operator[](unsigned int i) const { return this->strings[i]; }; 73 87 /** @param i the i'th String @returns the i'th string from the subset of Strings */ 74 88 inline const std::string& getString(unsigned int i) const { return (*this)[i]; }; 89 /** @returns the front of the StringList. */ 90 inline const std::string& front() const { return this->strings.front(); }; 91 /** @returns the back of the StringList. */ 92 inline const std::string& back() const { return this->strings.back(); }; 93 /** @brief removes the back of the strings list. */ 94 inline void pop_back() { this->strings.pop_back(); }; 75 95 76 96 // the almighty algorithm. … … 93 113 private: 94 114 std::vector<std::string> strings; //!< strings produced from a single string splitted in multiple strings 95 96 static const std::string emptyString;97 115 }; 98 116 99 #endif /* _ SUBSTRING_H*/117 #endif /* __SUBSTRING_H__ */ -
branches/proxy/src/orxonox.cc
r9240 r9347 453 453 if ( Preferences::getInstance()->getString("misc", "bt-to-file", "1") == "1" ) 454 454 { 455 SignalHandler::getInstance()->doCatch( argv[0] );456 455 SignalHandler::getInstance()->doCatch( argv[0], "orxonox.backtrace" ); 456 SignalHandler::getInstance()->registerCallback( EventHandler::releaseMouse, NULL ); 457 457 } 458 458 -
branches/proxy/src/story_entities/game_world_data.h
r7460 r9347 42 42 void loadGameRule(const TiXmlElement* root); 43 43 44 44 45 protected: 45 46 virtual ErrorMessage loadGUI(const TiXmlElement* root); -
branches/proxy/src/story_entities/multi_player_world_data.cc
r9235 r9347 47 47 #include "player_stats.h" 48 48 49 #include "proxy/proxy_settings.h" 49 50 50 51 #include "glmenu_imagescreen.h" … … 110 111 { 111 112 const TiXmlElement* element = NULL; 112 113 if( NetworkManager::getInstance()->is GameServer() )113 114 if( NetworkManager::getInstance()->isMasterServer() ) 114 115 { 115 116 /* load the spawning points */ … … 147 148 element = element->FirstChildElement(); 148 149 149 if( NetworkManager::getInstance()->is GameServer() )150 if( NetworkManager::getInstance()->isMasterServer() ) 150 151 { 151 152 while( element != NULL) … … 205 206 206 207 207 if( NetworkManager::getInstance()->is GameServer())208 if( NetworkManager::getInstance()->isMasterServer()) 208 209 { 209 210 this->localPlayer = new Player(); … … 280 281 GameWorldData::loadScene(root); 281 282 283 LoadParamXML(root, "ProxySettings", ProxySettings::getInstance(), ProxySettings, loadProxySettings); 284 282 285 // create server playable 283 if ( NetworkManager::getInstance()->is GameServer() )286 if ( NetworkManager::getInstance()->isMasterServer() ) 284 287 { 285 288 NetworkGameManager::getInstance()->signalNewPlayer( 0 ); … … 296 299 ErrorMessage MultiPlayerWorldData::unloadScene() 297 300 { 301 // delete the proxy settings 302 delete ProxySettings::getInstance(); 303 298 304 /* call underlying function */ 299 305 return GameWorldData::unloadScene(); -
branches/proxy/src/subprojects/network/network_unit_test.cc
r8623 r9347 208 208 209 209 /* esatblish a connection */ 210 IP addressip;210 IP ip; 211 211 int error = SDLNet_ResolveHost(&ip, "127.0.0.1", port); 212 212 //SDLNet_ResolveHost(&ip, "localhost", port); … … 353 353 printf("Connecting to %s, on port %i\n", name, port); 354 354 355 IP addressip;355 IP ip; 356 356 int error = SDLNet_ResolveHost(&ip, name, port); 357 357 if(error == -1) -
branches/proxy/src/util/Makefile.am
r8068 r9347 14 14 singleplayer_shootemup.cc \ 15 15 \ 16 \ 17 \ 16 18 mission_goal.cc\ 17 19 kill_target.cc\ … … 24 26 animation/animation_player.cc \ 25 27 \ 26 track/pilot_node.cc 28 track/pilot_node.cc \ 29 \ 30 network_stats_widget.cc 27 31 28 32 # track/track_manager.cc \ … … 50 54 animation/t_animation.h \ 51 55 \ 52 track/pilot_node.h 56 track/pilot_node.h \ 57 \ 58 network_stats_widget.h 59 53 60 54 61 # track/track_manager.h \ -
branches/proxy/src/util/game_rules.cc
r9008 r9347 88 88 void GameRules::registerKill(const Kill& kill) 89 89 { 90 if ( !SharedNetworkData::getInstance()->is GameServer() )90 if ( !SharedNetworkData::getInstance()->isMasterServer() ) 91 91 return; 92 92 -
branches/proxy/src/util/multiplayer_team_deathmatch.cc
r9235 r9347 204 204 assignPlayable(); 205 205 206 if ( !SharedNetworkData::getInstance()->is GameServer() )206 if ( !SharedNetworkData::getInstance()->isMasterServer() ) 207 207 return; 208 208 … … 214 214 this->killList.erase( this->killList.begin() ); 215 215 } 216 216 217 217 218 218 … … 268 268 void MultiplayerTeamDeathmatch::checkGameRules() 269 269 { 270 if ( !SharedNetworkData::getInstance()->is GameServer() )270 if ( !SharedNetworkData::getInstance()->isMasterServer() ) 271 271 return; 272 272 … … 320 320 return "maps/male_fiend.pcx"; 321 321 } 322 322 323 323 return ""; 324 324 } … … 330 330 return 10.0f; 331 331 } 332 332 333 333 return 1.0f; 334 334 } … … 680 680 char st[10]; 681 681 int i = 0; 682 682 683 683 i = 2; 684 684 for ( TeamScoreList::const_iterator it = scoreList[0].begin(); it != scoreList[0].end(); it++ ) … … 719 719 return; 720 720 } 721 721 722 722 int killerUserId = killer->getOwner(); 723 723 int victimUserId = victim->getOwner(); 724 724 725 725 PRINTF(0)("%d %d %x %x %s %s\n", killerUserId, victimUserId, killer, victim, killer->getClassName(), victim->getClassName()); 726 726 727 727 PlayerStats & victimStats = *PlayerStats::getStats( victimUserId ); 728 728 PlayerStats & killerStats = *PlayerStats::getStats( killerUserId ); 729 729 730 730 if ( killerStats.getPlayable() != killer || victimStats.getPlayable() != victim ) 731 731 { -
branches/proxy/src/util/signal_handler.cc
r9240 r9347 27 27 } 28 28 29 void SignalHandler::doCatch( std::string appName ) 29 /** 30 * register signal handlers for SIGSEGV and SIGABRT 31 * @param appName path to executable eg argv[0] 32 * @param fileName filename to append backtrace to 33 */ 34 void SignalHandler::doCatch( const std::string & appName, const std::string & fileName ) 30 35 { 31 36 this->appName = appName; 37 this->fileName = fileName; 38 39 // make sure doCatch is only called once without calling dontCatch 40 assert( sigRecList.size() == 0 ); 32 41 33 42 catchSignal( SIGSEGV ); … … 35 44 } 36 45 46 /** 47 * restore previous signal handlers 48 */ 37 49 void SignalHandler::dontCatch() 38 50 { … … 45 57 } 46 58 59 /** 60 * catch signal sig 61 * @param sig signal to catch 62 */ 47 63 void SignalHandler::catchSignal( int sig ) 48 64 { … … 58 74 } 59 75 76 /** 77 * sigHandler is called when receiving signals 78 * @param sig 79 */ 60 80 void SignalHandler::sigHandler( int sig ) 61 81 { … … 167 187 ) 168 188 charsFound++; 189 else 190 charsFound = 0; 169 191 170 192 if ( charsFound == 6 ) … … 183 205 write( sigPipe[1], &someData, sizeof(someData) ); 184 206 185 write( gdbIn[1], "bt\n q\n", 5);207 write( gdbIn[1], "bt\nk\nq\n", 7 ); 186 208 187 209 … … 202 224 ) 203 225 charsFound++; 226 else 227 charsFound = 0; 204 228 205 229 if ( charsFound == 6 ) … … 210 234 } 211 235 212 if ( promptFound == 2)236 if ( promptFound == 3 ) 213 237 { 214 238 break; … … 240 264 bt.insert(0, timeString); 241 265 242 FILE * f = fopen( GDB_BT_FILE, "a" );266 FILE * f = fopen( getInstance()->fileName.c_str(), "a" ); 243 267 244 268 if ( !f ) 245 269 { 246 perror( "could not append to " GDB_BT_FILE);270 perror( ( std::string( "could not append to " ) + getInstance()->fileName ).c_str() ); 247 271 exit(EXIT_FAILURE); 248 272 } … … 250 274 if ( fwrite( bt.c_str(), 1, bt.length(), f ) != bt.length() ) 251 275 { 252 printf( "could not write %d byte to " GDB_BT_FILE, bt.length());276 printf( ( std::string("could not write %d byte to ") + getInstance()->fileName ).c_str(), bt.length()); 253 277 exit(EXIT_FAILURE); 254 278 } -
branches/proxy/src/util/signal_handler.h
r9240 r9347 9 9 #include <list> 10 10 #include <string> 11 12 13 #define GDB_BT_FILE "orxonox.backtrace"14 11 15 12 typedef int (*SignalCallback)( void * someData ); … … 44 41 void registerCallback( SignalCallback cb, void * someData ); 45 42 46 void doCatch( std::string appName );43 void doCatch( const std::string & appName, const std::string & fileName ); 47 44 void dontCatch(); 48 45 … … 58 55 59 56 std::string appName; 57 std::string fileName; 60 58 }; 61 59 -
branches/proxy/src/world_entities/camera.cc
r9235 r9347 17 17 #include "camera.h" 18 18 #include "key_mapper.h" 19 #include "glincl.h" 19 20 20 21 /** -
branches/proxy/src/world_entities/creatures/fps_player.cc
r9235 r9347 287 287 //dealing damage 288 288 289 if ( State::isOnline() && SharedNetworkData::getInstance()->is GameServer() )289 if ( State::isOnline() && SharedNetworkData::getInstance()->isMasterServer() ) 290 290 { 291 291 this->damageTicker -= time; -
branches/proxy/src/world_entities/playable.cc
r9235 r9347 361 361 } 362 362 } 363 /**364 * @brief helps us colliding Playables365 * @param entity the Entity to collide366 * @param location where the collision occured.367 */368 void Playable::collidesWith(WorldEntity* entity, const Vector& location)369 {370 if (entity == collider)371 return;372 collider = entity;373 374 if ( entity->isA(CL_PROJECTILE) && ( !State::isOnline() || SharedNetworkData::getInstance()->isGameServer() ) )375 {376 this->decreaseHealth(entity->getHealth() *(float)rand()/(float)RAND_MAX);377 // EXTREME HACK378 if (this->getHealth() <= 0.0f)379 {380 // this->destory();381 382 if( State::getGameRules() != NULL)383 State::getGameRules()->registerKill(Kill(entity, this));384 }385 }386 }387 363 388 364 … … 413 389 } 414 390 this->bDead = true; 415 391 416 392 if( State::getGameRules() != NULL) 417 393 State::getGameRules()->registerKill(Kill(killer, this)); -
branches/proxy/src/world_entities/playable.h
r9235 r9347 82 82 virtual void destroy(WorldEntity* killer); 83 83 virtual void respawn(); 84 virtual void collidesWith(WorldEntity* entity, const Vector& location);85 84 virtual void process(const Event &event); 86 85 virtual void tick(float dt); … … 90 89 static const std::string& playmodeToString(Playable::Playmode playmode); 91 90 static const std::string playmodeNames[]; 92 91 93 92 inline bool beFire(){ return this->bFire; } 94 93 inline void fire(bool bF){ this->bFire = bF;} -
branches/proxy/src/world_entities/space_ships/space_ship.cc
r9235 r9347 314 314 if( entity->isA(CL_PROJECTILE) && entity != ref) 315 315 { 316 if ( isServer() )316 if ( SharedNetworkData::getInstance()->isMasterServer() ) 317 317 { 318 318 //TODO handle this -
branches/proxy/src/world_entities/spawning_point.cc
r9235 r9347 41 41 42 42 this->init(); 43 43 44 44 if (root != NULL) 45 45 this->loadParams(root); … … 50 50 this->setClassID(CL_SPAWNING_POINT, "SpawningPoint"); 51 51 PRINTF(0)("Created SpawningPoint\n"); 52 52 53 53 this->teamId = -1; 54 54 this->localTimer = 0.0f; 55 55 56 56 this->toList( OM_DEAD_TICK ); 57 57 58 58 MessageManager::getInstance()->registerMessageHandler( MSGID_RESPAWN, respawnMessageHandler, NULL ); 59 59 60 60 this->setSynchronized( true ); 61 61 } … … 94 94 qe.entity = entity; 95 95 qe.respawnTime = this->localTimer + delay; 96 96 97 97 queue.push_back( qe ); 98 98 } … … 105 105 { 106 106 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE ); 107 107 108 108 bool found = false; 109 109 110 110 if ( !list ) 111 111 return; 112 112 113 113 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ ) 114 114 { … … 119 119 } 120 120 } 121 121 122 122 if ( !found ) 123 123 return; … … 128 128 entity->setAbsCoor( this->getAbsCoor() ); 129 129 entity->setAbsDir( this->getAbsDir() ); 130 130 131 131 //TODO set camera (not smooth) 132 132 133 133 if ( State::getGameRules() ) 134 134 { 135 135 (State::getGameRules())->registerSpawn( entity ); 136 136 } 137 137 138 138 entity->respawn(); 139 139 } … … 157 157 //spawn the player 158 158 this->spawn(it->entity); 159 159 160 160 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE ); 161 161 162 162 bool found = false; 163 163 164 164 if ( !list ) 165 165 return; 166 166 167 167 for ( std::list<BaseObject*>::const_iterator it2 = list->begin(); it2 != list->end(); it2++ ) 168 168 { … … 173 173 } 174 174 } 175 176 if ( found && SharedNetworkData::getInstance()->is GameServer() )175 176 if ( found && SharedNetworkData::getInstance()->isMasterServer() ) 177 177 this->sendRespawnMessage( it->entity->getUniqueID() ); 178 178 179 179 std::list<QueueEntry>::iterator delit = it; 180 180 it++; 181 181 182 182 queue.erase( delit ); 183 183 184 184 continue; 185 185 } 186 186 187 187 it++; 188 188 } … … 204 204 { 205 205 byte * buf = new byte[2*INTSIZE]; 206 206 207 207 assert( Converter::intToByteArray( this->getUniqueID(), buf, INTSIZE ) == INTSIZE ); 208 208 assert( Converter::intToByteArray( uniqueId, buf + INTSIZE, INTSIZE ) == INTSIZE ); 209 209 210 210 MessageManager::getInstance()->sendMessage( MSGID_RESPAWN, buf, 2*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH ); 211 211 } … … 213 213 bool SpawningPoint::respawnMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 214 214 { 215 if ( SharedNetworkData::getInstance()->is GameServer() )215 if ( SharedNetworkData::getInstance()->isMasterServer() ) 216 216 { 217 217 PRINTF(2)("server received spawn message!\n"); 218 218 return true; 219 219 } 220 220 221 221 int spUniqueId; 222 222 int uniqueId; 223 223 224 224 if ( dataLength != 2*INTSIZE ) 225 225 { … … 227 227 return true; 228 228 } 229 229 230 230 assert( Converter::byteArrayToInt( data, &spUniqueId ) == INTSIZE ); 231 231 assert( Converter::byteArrayToInt( data+INTSIZE, &uniqueId ) == INTSIZE ); 232 232 233 233 PRINTF(0)("SPAWNMESSAGE %d\n", uniqueId); 234 234 235 235 SpawningPoint * sp = NULL; 236 236 Playable * playable = NULL; 237 237 238 238 const std::list<BaseObject*> * list = ClassList::getList( CL_SPAWNING_POINT ); 239 239 240 240 if ( list ) 241 241 { … … 250 250 } 251 251 } 252 252 253 253 if ( !sp ) 254 254 { … … 256 256 return false; 257 257 } 258 258 259 259 list = ClassList::getList( CL_PLAYABLE ); 260 260 261 261 if ( list ) 262 262 { … … 270 270 } 271 271 } 272 272 273 273 if ( !playable ) 274 274 { … … 276 276 return false; 277 277 } 278 278 279 279 sp->spawn( playable ); 280 280 281 281 return true; 282 282 }
Note: See TracChangeset
for help on using the changeset viewer.