Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9347 in orxonox.OLD


Ignore:
Timestamp:
Jul 20, 2006, 11:43:27 AM (18 years ago)
Author:
bensch
Message:

orxonox/proxy: merged the proxy.old back again, and it seems to work.

Merged with command
svn merge -r9247:HEAD https://svn.orxonox.net/orxonox/branches/proxy.old .

no conflicts

Location:
branches/proxy
Files:
4 deleted
62 edited
21 copied

Legend:

Unmodified
Added
Removed
  • branches/proxy/configure.ac

    r9237 r9347  
    449449    AC_CHECK_HEADERS([OpenGL/glu.h] ,,
    450450      [AC_MSG_ERROR([cannot find opengl headers]) ])
    451         AC_CHECK_LIB( OpenGL, main, , )
     451        AC_CHECK_LIB( OpenGL, main, , )
    452452   LIBS="$LIBS -framework OpenGL"
    453453
     
    560560#----#
    561561if test x$osX = xyes ; then
    562 #       PKG_CONFIG_PATH="$prefix"
    563 #       PKG_CHECK_MODULES( QT, QtOpenGL >= 4.01 QtCore >= 4.01 QtGui >= 4.0.1 )
    564 #       QT_INCLUDE_DIR=`$PKG_CONFIG --variable=includedir QtOpenGL QtCore QtGui`
     562#       PKG_CONFIG_PATH="$prefix"
     563#       PKG_CHECK_MODULES( QT, QtOpenGL >= 4.01 QtCore >= 4.01 QtGui >= 4.0.1 )
     564#       QT_INCLUDE_DIR=`$PKG_CONFIG --variable=includedir QtOpenGL QtCore QtGui`
    565565#----------#
    566             AC_PATH_PROG([QT_MOC], [moc], [no], ["${QT_BIN_DIRECTORY}:${PATH}"])
    567               if test x${QT_MOC} = xno ; then
    568                 AC_MSG_ERROR([QT MOC not found])
    569               fi
    570         AC_SUBST([QT_MOC])
    571 
    572         AC_PATH_PROG([QT_UIC], [uic], [no], ["${QT_BIN_DIRECTORY}:${PATH}"])
    573         AC_SUBST([QT_UIC])
    574 
    575         AC_PATH_PROG([QT_RCC], [rcc], [no], ["${QT_BIN_DIRECTORY}:${PATH}"])
    576 
    577         AC_SUBST([QT_RCC])
    578         AC_SUBST( QT_INCLUDE_DIR )
    579         AC_SUBST( QT_CFLAGS )
    580         AC_SUBST( QT_LDFLAGS )
    581         AC_SUBST( QT_LIBS )
    582         echo "QT_LIBS                   = $QT_LIBS"
    583         echo "QT_CFLAGS                 = $QT_CFLAGS"
    584         echo "QT_INCLUDE_DIR    = $QT_INCLUDE_DIR"
     566            AC_PATH_PROG([QT_MOC], [moc], [no], ["${QT_BIN_DIRECTORY}:${PATH}"])
     567              if test x${QT_MOC} = xno ; then
     568                AC_MSG_ERROR([QT MOC not found])
     569              fi
     570        AC_SUBST([QT_MOC])
     571
     572        AC_PATH_PROG([QT_UIC], [uic], [no], ["${QT_BIN_DIRECTORY}:${PATH}"])
     573        AC_SUBST([QT_UIC])
     574
     575        AC_PATH_PROG([QT_RCC], [rcc], [no], ["${QT_BIN_DIRECTORY}:${PATH}"])
     576
     577        AC_SUBST([QT_RCC])
     578        AC_SUBST( QT_INCLUDE_DIR )
     579        AC_SUBST( QT_CFLAGS )
     580        AC_SUBST( QT_LDFLAGS )
     581        AC_SUBST( QT_LIBS )
     582        echo "QT_LIBS                   = $QT_LIBS"
     583        echo "QT_CFLAGS                 = $QT_CFLAGS"
     584        echo "QT_INCLUDE_DIR    = $QT_INCLUDE_DIR"
    585585else
    586         AX_CHECK_QT([${QT_PREFIX}], [QtCore QtCore4],, [http://www.trolltech.com])
    587         if test x$have_qt = xno ; then
    588                 WITH_QT=no
    589         fi
     586        AX_CHECK_QT([${QT_PREFIX}], [QtCore QtCore4],, [http://www.trolltech.com])
     587        if test x$have_qt = xno ; then
     588                WITH_QT=no
     589        fi
    590590fi
    591591
     
    672672                 src/subprojects/collision_detection/Makefile
    673673                 src/subprojects/network/Makefile
     674                 src/subprojects/recapture_mouse/Makefile
    674675                 ])
    675676
  • branches/proxy/src/defs/class_id.h

    r9235 r9347  
    127127  CL_NETWORK_MANAGER            =    0x00000050,
    128128  CL_SHARED_NETWORK_DATA        =    0x00000051,
     129  CL_PROXY_SETTINGS             =    0x00000052,
    129130  CL_ATMOSPHERIC_ENGINE         =    0x00000061,
    130131
     
    422423  CL_PLAYER_STATS               =    0x00000d09,
    423424  CL_SIMPLE_SYNC                =    0x00000d0a,
     425  CL_NETWORK_MONITOR            =    0x00000d0b,
    424426
    425427
  • branches/proxy/src/lib/collision_detection/obb_tree_node.cc

    r9235 r9347  
    434434    }
    435435  }
     436  delete [] triangleCenter;
    436437  PRINTF(4)("\nPartition1: got \t%i Vertices \nPartition2: got \t%i Vertices\n", partition1.size(), partition2.size());
    437438
     
    476477    return;
    477478
    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());
    480481
    481482
  • branches/proxy/src/lib/coord/p_node.h

    r8711 r9347  
    2020
    2121#include "base_object.h"
    22 #include "stdincl.h"
    2322#include "synchronizeable.h"
    2423
     
    112111  /** @returns the absolute position */
    113112  inline const Vector& getLastAbsCoor () const { return this->lastAbsCoordinate; };
    114  
     113
    115114  void shiftCoor (const Vector& shift);
    116115  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  
    11/*
    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.
     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.
    1010
    1111### File Specific:
    12         main-programmer: hdavid, amaechler
     12        main-programmer: hdavid, amaechler
    1313*/
    1414
     
    3535SHELL_COMMAND(deactivate, SnowEffect, deactivateSnow);
    3636
    37 using namespace std;
    3837
    3938CREATE_SCRIPTABLE_CLASS(SnowEffect, CL_SNOW_EFFECT,
     
    4645SnowEffect::SnowEffect(const TiXmlElement* root)
    4746{
    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        }
    6159
    6260  if(snowActivate) {
    63                 this->activate();
     61                this->activate();
    6462    SnowEffect::snowParticles->precache((int) this->snowLife);
    6563  }
     
    6967SnowEffect::~SnowEffect()
    7068{
    71         this->deactivate();
     69        this->deactivate();
    7270}
    7371
     
    7674void SnowEffect::loadParams(const TiXmlElement* root)
    7775{
    78         WeatherEffect::loadParams(root);
    79 
    80         LoadParam(root, "numParticles", this, SnowEffect, numParticles);
    81         LoadParam(root, "materialTexture", this, SnowEffect, materialTexture);
    82         LoadParam(root, "lifeSpans", this, SnowEffect, lifeSpan);
    83         LoadParam(root, "radius", this, SnowEffect, radius);
    84         LoadParam(root, "mass", this, SnowEffect, mass);
    85         LoadParam(root, "emissionRate", this, SnowEffect, emissionRate);
    86         LoadParam(root, "emissionVelocity", this, SnowEffect, emissionVelocity);
    87         LoadParam(root, "wind", this, SnowEffect, wind);
    88         LoadParam(root, "size", this, SnowEffect, size);
    89         LoadParam(root, "coord", this, SnowEffect, coord);
     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);
    9088  LoadParam(root, "cloudcolor", this, SnowEffect, setCloudColor);
    9189  LoadParam(root, "skycolor", this, SnowEffect, setSkyColor);
    9290  LoadParam(root, "fadetime", this, SnowEffect, setFadeTime);
    9391
    94         LOAD_PARAM_START_CYCLE(root, element);
    95         {
    96                 LoadParam_CYCLE(element, "option", this, SnowEffect, setSnowOption);
    97         }
    98         LOAD_PARAM_END_CYCLE(element);
     92        LOAD_PARAM_START_CYCLE(root, element);
     93        {
     94                LoadParam_CYCLE(element, "option", this, SnowEffect, setSnowOption);
     95        }
     96        LOAD_PARAM_END_CYCLE(element);
    9997}
    10098
    10199void SnowEffect::init()
    102100{
    103         this->emitter = new PlaneEmitter();
    104 
    105         // Default values
    106         this->snowActivate = false;
    107         this->snowMove = false;
    108         this->particles = 12000;
    109         this->texture = "maps/snow_flake_01_32x32.png";
    110         this->snowLife = 8;
    111         this->randomLife = 2;
    112         this->snowRadius = 3.5;
    113         this->randomRadius = 1;
    114         this->snowMass = 1.0;
    115         this->randomMass = 0.3;
    116         this->rate = 900;
    117         this->velocity = -100;
    118         this->randomVelocity = 5;
    119         this->angle = 0.5;
    120         this->randomAngle = 0.2;
    121         this->alpha = 0.5;
    122         this->snowSize = Vector2D(2500, 2500);
    123         this->snowCoord = Vector(100,450,400);
    124         this->snowWindForce = 1;
    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
    126124  this->fadeTime = 10;
    127125  this->cloudColor = Vector(0.2f, 0.2f, 0.2f);
     
    131129void SnowEffect::activate()
    132130{
    133         PRINTF(3)("Activating SnowEffect\n");
    134 
    135         this->snowActivate = true;
    136 
    137         SnowEffect::snowParticles = new SpriteParticles(particles);
    138         SnowEffect::snowParticles->setName("SnowEffectTrailParticles");
    139         SnowEffect::snowParticles->setMaterialTexture(texture);
    140         SnowEffect::snowParticles->setLifeSpan(snowLife, randomLife);
    141         SnowEffect::snowParticles->setRadius(0.0, snowRadius, randomRadius);
    142         SnowEffect::snowParticles->setRadius(0.2, snowRadius, randomRadius*0.8);
    143         SnowEffect::snowParticles->setRadius(1.0, snowRadius, randomRadius*0.5);
    144         SnowEffect::snowParticles->setMass(0, snowMass, randomMass);
    145         SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
    146         SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
    147         SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
    148 
    149         this->emitter->setSystem(SnowEffect::snowParticles);
    150 
    151         this->emitter->setRelCoor(snowCoord);
    152         this->emitter->setEmissionRate(rate);
    153         this->emitter->setEmissionVelocity(velocity, randomVelocity);
    154         this->emitter->setSpread(angle * this->snowWindForce , randomAngle * this->snowWindForce);
    155         this->emitter->setSize(snowSize);
     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);
    156154
    157155  if (this->snowWindForce != 0)
    158156    this->soundSource.play(this->windBuffer, 0.1f * this->snowWindForce, true);
    159  
     157
    160158  // Store cloud- and sky color before the snow
    161159  this->oldCloudColor = CloudEffect::cloudColor;
     
    171169void SnowEffect::deactivate()
    172170{
    173         PRINTF(3)("Deactivating SnowEffect\n");
    174 
    175         this->snowActivate = false;
    176         this->emitter->setSystem(NULL);
    177 
    178         if (this->windBuffer != NULL)
    179                 ResourceManager::getInstance()->unload(this->windBuffer);
    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
    181179  // Restore the old cloud- and sky color
    182180  CloudEffect::changeCloudColor(this->oldCloudColor, this->fadeTime);
     
    186184void SnowEffect::draw() const
    187185{
    188         if (!this->snowActivate)
    189                 return;
     186        if (!this->snowActivate)
     187                return;
    190188}
    191189
    192190void SnowEffect::tick(float dt)
    193191{
    194         if (!this->snowActivate)
    195                 return;
    196 
    197         /*
    198         float distance = (State::getCameraNode()->getAbsCoor() - Vector(snowCoord.x, State::getCameraNode()->getAbsCoor().y, snowCoord.z)).len();
    199 
    200         if(activated)
    201         {
    202         if(distance > 0.3*snowSize.x || distance > 0.3*snowSize.y)
    203                         this->deactivate();
    204         else if(distance > 0.25*snowSize.x || distance > 0.25*snowSize.y)
    205         this->alpha = 0.15;
    206         else if(distance > 0.2*snowSize.x || distance > 0.2*snowSize.y)
    207         this->alpha = 0.25;
    208         else if(distance > 0.1*snowSize.x || distance > 0.1*snowSize.y)
    209         this->alpha = 0.4;
    210 
    211         SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
    212         SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
    213         SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
    214         }
    215         else
    216         {
    217         if(distance < 0.3*snowSize.x || distance < 0.3*snowSize.y )
    218         this->activate();
    219         if( distance < 0.25*snowSize.x || distance < 0.25*snowSize.y )
    220         this->alpha = 0.25;
    221         else if( distance < 0.2*snowSize.x || distance < 0.2*snowSize.y )
    222         this->alpha = 0.4;
    223         else if( distance < 0.1*snowSize.x || distance < 0.1*snowSize.y )
    224         this->alpha = 0.5;
    225 
    226         SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
    227         SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
    228         SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
    229         }*/
    230 
    231         if (this->snowMove) {
    232                 this->snowCoord = State::getCameraNode()->getAbsCoor();
    233                 this->emitter->setRelCoor(this->snowCoord.x , this->snowCoord.y+300, this->snowCoord.z);
    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  
    101101
    102102private:
    103     int         particles;
     103    int               particles;
    104104    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;
    116116
    117     bool        snowMove;
    118     bool        snowActivate;
     117    bool              snowMove;
     118    bool              snowActivate;
    119119
    120120    PlaneEmitter*     emitter;
    121121
    122122    static SpriteParticles*   snowParticles;
    123     OrxSound::SoundSource   soundSource;
     123    OrxSound::SoundSource     soundSource;
    124124    OrxSound::SoundBuffer*    windBuffer;
    125125
    126     Vector oldSkyColor;
    127     Vector oldCloudColor;
    128     Vector skyColor;
    129     Vector cloudColor;
     126    Vector            oldSkyColor;
     127    Vector            oldCloudColor;
     128    Vector            skyColor;
     129    Vector            cloudColor;
    130130};
    131131
  • branches/proxy/src/lib/graphics/importer/md3/md3_animation_cfg.cc

    r8724 r9347  
    1919#include "md3_animation.h"
    2020
    21 #include "tokenizer.h"
     21#include "substring.h"
    2222#include "helper_functions.h"
    2323
    2424#include "debug.h"
    2525
    26 #include <stdio.h>
    27 #include <stdlib.h>
    2826
    2927
     
    9896        if( inHeader && line.find("sex") == 0) {
    9997          //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/");
    10299
    103100          std::string sexStr = tokens.back();
     
    115112        else if( inHeader && line.find("headoffset") == 0) {
    116113          // 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/");
    119115
    120116          float z = atof(tokens.back().c_str()); tokens.pop_back();
     
    128124        else if( inHeader && line.find("footsteps") == 0) {
    129125          //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/");
    132127
    133128          this->footsteps = tokens.back();
     
    187182    // parse the line:
    188183    // 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/");
    191185
    192186    anim->fps = atoi(tokens.back().c_str()); tokens.pop_back();
  • branches/proxy/src/lib/lang/base_object.cc

    r8145 r9347  
    2121#include "util/loading/load_param.h"
    2222#include "class_list.h"
    23 
    24 #include "synchronizeable.h"
    25 
    26 using namespace std;
    27 
    2823
    2924/**
     
    5045  ClassList::removeFromClassList(this);
    5146
    52   //  delete []this->className;
    5347  if (this->xmlElem != NULL)
    5448    delete this->xmlElem;
     
    6155void BaseObject::loadParams(const TiXmlElement* root)
    6256{
    63   // all loadParams should sometime arrive here.
     57  // all loadParams should arrive here, and be tested for (root != NULL)
    6458  assert (root != NULL);
    6559
     60  // copy the xml-element for to know how it was loaded.
    6661  if (this->xmlElem != NULL)
    6762    delete this->xmlElem;
    6863  this->xmlElem = root->Clone();
     64
    6965  // name setup
    7066  LoadParam(root, "name", this, BaseObject, setName)
     
    9288/**
    9389 * @brief set the name of the Object
     90 * @param objectName The new name of the Object.
    9491 */
    9592void BaseObject::setName (const std::string& objectName)
     
    164161 * @returns true on match, false otherwise.
    165162 */
    166 bool BaseObject::operator==(const std::string& objectName)
     163bool BaseObject::operator==(const std::string& objectName) const
    167164{
    168165  return (this->objectName == objectName);
    169166}
    170167
    171 
    172 /**
    173  * @brief displays everything this class is
    174  * @TODO REIMPLEMENT WITH SENSE.
    175  */
    176 void BaseObject::whatIs() const
    177 {
    178 
    179 }
  • branches/proxy/src/lib/lang/base_object.h

    r8362 r9347  
    11/*!
    22 * @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 */
    711
    812
    9 #ifndef _BASE_OBJECT_H
    10 #define _BASE_OBJECT_H
     13#ifndef __BASE_OBJECT_H_
     14#define __BASE_OBJECT_H_
    1115
    1216#include "class_id.h"
     
    4145  bool isA (ClassID classID) const;
    4246  bool isA (const std::string& className) const;
    43   void whatIs() const;
    4447
    45   bool operator==(const std::string& objectName);
    4648  /** @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;
    4851
    4952protected:
     
    5457
    5558private:
    56 
    5759  std::string        className;        //!< the name of the class
    5860  long               classID;          //!< this is the id from the class_id.h enumeration
     
    6466};
    6567
    66 #endif /* _BASE_OBJECT_H */
     68#endif /* __BASE_OBJECT_H_ */
  • branches/proxy/src/lib/network/Makefile.am

    r8623 r9347  
    88                      shared_network_data.cc \
    99                      network_socket.cc \
    10                       connection_monitor.cc \
    1110                      network_stream.cc \
    1211                      data_stream.cc \
     
    2019                      network_game_manager.cc \
    2120                      converter.cc \
     21                      peer_info.cc \
    2222                      message_manager.cc \
    2323                      network_log.cc \
     
    2525                      player_stats.cc \
    2626                      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 \
    2733                      \
    2834                      synchronizeable_var/synchronizeable_var.cc \
     
    3339                      synchronizeable_var/synchronizeable_float.cc \
    3440                      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
    3645
    3746
     
    4251                 shared_network_data.h \
    4352                 network_socket.h \
    44                  connection_monitor.h \
    4553                 network_stream.h \
    4654                 data_stream.h \
     
    5462                 network_game_manager.h \
    5563                 converter.h \
     64                 peer_info.h \
    5665                 netdefs.h \
    5766                 message_manager.h \
     
    6069                 player_stats.h \
    6170                 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 \
    6277                 \
    6378                 synchronizeable_var/synchronizeable_var.h \
     
    6883                 synchronizeable_var/synchronizeable_float.h \
    6984                 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
    7189
    7290
  • branches/proxy/src/lib/network/handshake.cc

    r9235 r9347  
    1010
    1111### File Specific:
    12    main-programmer: christoph
    13    co-programmer:
     12   main-programmer: Christoph Renner (rennerc@ee.ethz.ch)
     13   co-programmer: Patirck Boenzli (boenzlip@orxonox.ethz.ch)
    1414*/
    1515
    1616
    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 */
    2017#define DEBUG_MODULE_NETWORK
    2118
     
    2522#include "debug.h"
    2623
    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 )
    2829  : Synchronizeable()
    2930{
     
    3132  this->setClassID(CL_HANDSHAKE, "Handshake");
    3233
    33   this->setIsServer(server);
    34 
     34  // register all variable handlers
    3535  orxId_handler = registerVarId( new SynchronizeableInt( &localState.orxId, &remoteState.orxId, "orxonoxId", PERMISSION_ALL ) );
    3636  version_handler = registerVarId( new SynchronizeableInt( &localState.version, &remoteState.version, "version", PERMISSION_ALL ) );
     
    4242  errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", PERMISSION_ALL ) );
    4343
     44  this->nodeTypeHandler = registerVarId( new SynchronizeableInt( &localState.nodeType, &remoteState.nodeType, "nodeType", PERMISSION_ALL ) );
     45
    4446  candel_id = registerVarId( new SynchronizeableInt( &localState.canDel, &remoteState.canDel, "canDel", PERMISSION_ALL ) );
    45  
     47
    4648  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 ) );
    4752
     53  // init the local state
    4854  localState.completed = 0;
    4955  localState.error = 0;
     
    5460  localState.orxId = _ORXONOX_ID;
    5561  localState.version = _ORXONOX_VERSION;
     62  localState.nodeType = nodeType;
    5663  localState.canDel = 0;
     64  localState.redirectProxy = 0;
     65  localState.proxy1 = IP(0, 0);
     66  localState.proxy2 = IP (0, 0);
    5767
     68
     69  // init the remote state
    5870  remoteState.completed = 0;
    5971  remoteState.error = 0;
     
    6476  remoteState.orxId = 0;
    6577  remoteState.version = 0;
     78  remoteState.nodeType = NET_CLIENT;
    6679  remoteState.canDel = 0;
     80  remoteState.redirectProxy = 0;
     81  remoteState.proxy1 = IP(0, 0);
     82  remoteState.proxy2 = IP(0, 0);
    6783
     84  // activate the synchronization process
    6885  this->setSynchronized(true);
    6986  PRINTF(0)("Handshake created clientId = %d\n", clientId);
    7087}
     88
    7189
    7290/**
     
    7896  for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ )
    7997  {
    80     if ( *it == orxId_handler )
     98    // orxonox id handler
     99    if ( *it == this->orxId_handler )
    81100    {
    82101      if ( remoteState.orxId != _ORXONOX_ID )
     
    87106        continue;
    88107      }
    89 
    90108    }
    91109
    92     if ( *it == version_handler )
     110    // orxonox version handler
     111    if ( *it == this->version_handler )
    93112    {
    94113      if ( remoteState.version != _ORXONOX_VERSION )
     
    99118        continue;
    100119      }
    101 
    102120    }
    103121
     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
    104140    if ( *it == candel_id )
    105141    {
     
    109145  }
    110146
    111   if (
    112       remoteState.orxId == _ORXONOX_ID &&
    113       remoteState.version == _ORXONOX_VERSION
    114      )
     147  // handshake completed
     148  if ( remoteState.orxId == _ORXONOX_ID &&
     149       remoteState.version == _ORXONOX_VERSION )
     150  {
    115151    localState.completed = 1;
     152  }
    116153}
    117154
  • branches/proxy/src/lib/network/handshake.h

    r9235 r9347  
    11/*!
    22 * @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!
    48 */
    59
     
    812
    913#include "base_object.h"
     14#include "ip.h"
    1015#include "synchronizeable.h"
    1116
    12 #define _ORXONOX_ID 0xF91337A0
     17//!< a struct to save the handshakes to
     18struct HandshakeState
     19{
     20  int           orxId;                         //!< orxonox id
     21  int           version;                       //!< network protocol version
    1322
    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
    1527
    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
    3135  //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)
    3341};
    3442
     43
     44//!< the handshake itself with some interface functions
    3545class Handshake : public Synchronizeable
    3646{
     47
    3748  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 */
    5080    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 */
    5298    virtual void varChangeHandler( std::list<int> & id );
    5399
     100
    54101  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
    67117
    68118};
  • branches/proxy/src/lib/network/message_manager.cc

    r9059 r9347  
    5252      }
    5353    }
    54    
     54
    5555    it->second.messages.clear();
    5656    it->second.toAck.clear();
    5757  }
    58  
     58
    5959  messageQueue.clear();
    60  
     60
    6161  this->messageHandlerMap.clear();
    62  
     62
    6363  MessageManager::singletonRef = NULL;
    6464}
     
    8282  int i = 0;
    8383  int n;
    84  
     84
    8585  n = Converter::intToByteArray( messageQueue[userId].toAck.size(), data + i, maxLength );
    8686  i += n;
    8787  assert( n == INTSIZE );
    88  
     88
    8989  for ( std::list<int>::iterator it = messageQueue[userId].toAck.begin(); it != messageQueue[userId].toAck.end(); it++)
    9090  {
     
    9393    assert( n == INTSIZE );
    9494  }
    95  
     95
    9696  messageQueue[userId].toAck.clear();
    97  
     97
    9898  n = Converter::intToByteArray( messageQueue[userId].messages.size(), data + i, maxLength );
    9999  i += n;
    100100  assert( n == INTSIZE );
    101  
     101
    102102  for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); it++ )
    103103  {
     
    105105    i += n;
    106106    assert( n == INTSIZE );
    107    
     107
    108108    n = Converter::intToByteArray( it->number, data + i, maxLength );
    109109    i += n;
    110110    assert( n == INTSIZE );
    111    
     111
    112112    n = Converter::intToByteArray( it->messageId, data + i, maxLength );
    113113    i += n;
    114114    assert( n == INTSIZE );
    115    
     115
    116116    assert( i + it->length <= maxLength );
    117117    memcpy( data + i, it->data, it->length );
    118118    i += it->length;
    119119  }
    120  
     120
    121121  return i;
    122122}
     
    136136  int i = 0;
    137137  int n;
    138  
     138
    139139  int nAcks;
    140  
     140
    141141  assert( i + INTSIZE <= length );
    142142  n = Converter::byteArrayToInt( data + i, &nAcks );
    143143  assert( n == INTSIZE );
    144144  i += n;
    145  
     145
    146146  std::list<int> acks;
    147  
     147
    148148  int number;
    149  
     149
    150150  for ( int j = 0; j < nAcks; j++ )
    151151  {
     
    154154    assert( n == INTSIZE );
    155155    i += n;
    156    
     156
    157157    acks.push_back( number );
    158158  }
    159  
     159
    160160  int nMessages;
    161  
     161
    162162  assert( i + INTSIZE <= length );
    163163  n = Converter::byteArrayToInt( data + i, &nMessages );
     
    166166
    167167  int messageLength, messageId;
    168  
     168
    169169  for ( int j = 0; j < nMessages; j++ )
    170170  {
     
    173173    assert( n == INTSIZE );
    174174    i += n;
    175    
     175
    176176    assert( i + INTSIZE <= length );
    177177    n = Converter::byteArrayToInt( data + i, &number );
    178178    assert( n == INTSIZE );
    179179    i += n;
    180  
     180
    181181    assert( i + INTSIZE <= length );
    182182    n = Converter::byteArrayToInt( data + i, &messageId );
    183183    assert( n == INTSIZE );
    184184    i += n;
    185    
     185
    186186    if ( number > 0 )
    187187      messageQueue[userId].toAck.push_back( number );
    188    
     188
    189189    assert( i + messageLength <= length );
    190190    assert( messageHandlerMap.find( (MessageId)messageId ) != messageHandlerMap.end() );
     
    194194      {
    195195        NetworkMessage msg;
    196        
     196
    197197        msg.data = new byte[messageLength];
    198198        memcpy( msg.data, data + i, messageLength );
     
    200200        msg.messageId = (MessageId)messageId;
    201201        msg.number = userId;
    202        
     202
    203203        incomingMessageBuffer.push_back( msg );
    204204      }
     
    207207    i += messageLength;
    208208  }
    209  
    210  
     209
     210
    211211  //TODO maybe handle incomingMessage in tick function. else local messages will not be handled if no clients are connected
    212212  for ( std::list<NetworkMessage>::iterator it = incomingMessageBuffer.begin(); it != incomingMessageBuffer.end();  )
     
    223223    it++;
    224224  }
    225  
     225
    226226  //walk throu message queue and remove acked messages
    227227  for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end();  )
     
    236236    it++;
    237237  }
    238  
     238
    239239  //TODO find bether way. maybe with timestamp
    240240  if ( messageQueue[userId].recievedMessages.size() > 1000 )
     
    255255  if ( messageQueue.find( userId ) == messageQueue.end() )
    256256    return;
    257    
     257
    258258  for ( std::list<NetworkMessage>::iterator it = messageQueue[userId].messages.begin(); it != messageQueue[userId].messages.end(); it++ )
    259259  {
     
    262262    it->data = NULL;
    263263  }
    264  
     264
    265265  messageQueue[userId].toAck.clear();
    266  
     266
    267267  messageQueue.erase( userId );
    268268}
     
    270270/**
    271271 * 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
    273273 * @param cb function pointer to callback function
    274274 * @param someData this pointer is passed to callback function without modification
     
    278278{
    279279  MessageHandler messageHandler;
    280  
     280
    281281  messageHandler.cb = cb;
    282282  messageHandler.messageId = messageId;
    283283  messageHandler.someData = someData;
    284  
     284
    285285  messageHandlerMap[messageId] = messageHandler;
    286  
     286
    287287  return true;
    288288}
     
    309309 * @param data pointer to data
    310310 * @param dataLength length of data
    311  * @param recieverType 
    312  * @param reciever 
     311 * @param recieverType
     312 * @param reciever
    313313 */
    314314void MessageManager::sendMessage( MessageId messageId, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority )
     
    316316  for ( MessageQueue::iterator it = messageQueue.begin(); it != messageQueue.end(); it++ )
    317317  {
    318     if ( 
     318    if (
    319319         recieverType == RT_ALL_ME ||
    320320         recieverType == RT_ALL_NOT_ME ||
    321321         recieverType == RT_USER && it->first == reciever ||
    322322         recieverType == RT_NOT_USER && it->first != reciever ||
    323          recieverType == RT_SERVER && getNetworkStream()->isUserServer( it->first )
     323         recieverType == RT_SERVER && getNetworkStream()->isUserMasterServer( it->first )
    324324       )
    325325    {
     
    336336    }
    337337  }
    338  
     338
    339339  if ( recieverType == RT_ALL_ME )
    340340  {
  • branches/proxy/src/lib/network/netdefs.h

    r9246 r9347  
     1/*
     2   orxonox - the future of 3D-vertical-scrollers
    13
     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*/
    218
    319/*!
    420 * @file network_manager.h
    521 *  Main interface for the network module. Manages all the modules
    6 
    722 */
    823
    924#ifndef _NETDEFS
    1025#define _NETDEFS
     26
    1127
    1228#ifdef HAVE_SDL_NET_H
     
    1733
    1834
    19 #define MAX_CONNECTIONS 1000
     35//!< maximal connectinons for the server
     36#define NET_MAX_CONNECTIONS 100
    2037
     38//!< the amount of slots used before a proxy server is activated
     39#define NET_CONNECTION_SATURATION 0.75
     40
     41//!< network polling frequency
    2142#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
    2249
    2350
     
    2754//!< enum indicating the type of the node
    2855typedef 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
    3163} NodeType;
    3264
  • branches/proxy/src/lib/network/network_game_manager.cc

    r9235 r9347  
    1010
    1111### 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)
    1417*/
    1518
    1619
    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
    2021#define DEBUG_MODULE_NETWORK
    2122
     
    4546
    4647
    47 /* using namespace std is default, this needs to be here */
    4848using namespace std;
    4949
     
    6262
    6363  this->setSynchronized(true);
    64  
     64
    6565  MessageManager::getInstance()->registerMessageHandler( MSGID_DELETESYNCHRONIZEABLE, delSynchronizeableHandler, NULL );
    6666  MessageManager::getInstance()->registerMessageHandler( MSGID_PREFEREDTEAM, preferedTeamHandler, NULL );
    6767  MessageManager::getInstance()->registerMessageHandler( MSGID_CHATMESSAGE, chatMessageHandler, NULL );
    68  
     68
    6969  this->gameState = 0;
    7070  registerVar( new SynchronizeableInt( &gameState, &gameState, "gameState" ) );
     
    7777{
    7878  delete MessageManager::getInstance();
    79  
     79
    8080  PlayerStats::deleteAllPlayerStats();
    81  
     81
    8282  NetworkGameManager::singletonRef = NULL;
    8383}
     
    8686/**
    8787 * insert new player into game
    88  * @param userId 
    89  * @return 
     88 * @param userId
     89 * @return
    9090 */
    9191bool NetworkGameManager::signalNewPlayer( int userId )
    9292{
    93   assert( SharedNetworkData::getInstance()->isGameServer() );
     93  assert( SharedNetworkData::getInstance()->isMasterServer() );
    9494  assert( State::getGameRules() );
    9595  assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) );
    96  
     96
    9797  NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules()));
    98  
     98
    9999  int team = rules.getTeamForNewUser();
    100100  ClassID playableClassId = rules.getPlayableClassId( userId, team );
     
    102102  std::string playableTexture = rules.getPlayableModelFileName( userId, team, playableClassId );
    103103  float       playableScale = rules.getPlayableScale( userId, team, playableClassId );
    104  
     104
    105105  BaseObject * bo = Factory::fabricate( playableClassId );
    106  
     106
    107107  assert( bo != NULL );
    108108  assert( bo->isA( CL_PLAYABLE ) );
    109  
     109
    110110  Playable & playable = *(dynamic_cast<Playable*>(bo));
    111  
     111
    112112  playable.loadMD2Texture( playableTexture );
    113  
     113
    114114  playable.loadModel( playableModel, 100.0f );
    115115  playable.setOwner( userId );
    116116  playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
    117117  playable.setSynchronized( true );
    118  
     118
    119119  PlayerStats * stats = rules.getNewPlayerStats( userId );
    120  
     120
    121121  stats->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
    122122  stats->setSynchronized( true );
    123123  stats->setOwner( SharedNetworkData::getInstance()->getHostID() );
    124  
     124
    125125  stats->setTeamId( team );
    126126  stats->setPlayableClassId( playableClassId );
    127127  stats->setPlayableUniqueId( playable.getUniqueID() );
    128128  stats->setModelFileName( playableModel );
    129  
     129
    130130  if ( userId == 0 )
    131131    stats->setNickName( Preferences::getInstance()->getString( "multiplayer", "nickname", "Server" ) );
    132  
     132
    133133  if ( rules.isA( CL_MULTIPLAYER_TEAM_DEATHMATCH ) )
    134134    dynamic_cast<MultiplayerTeamDeathmatch*>(&rules)->respawnPlayable( &playable, team, 0.0f );
    135  
     135
    136136  return true;
    137137}
     
    140140/**
    141141 * remove player from game
    142  * @param userID 
    143  * @return 
     142 * @param userID
     143 * @return
    144144 */
    145145bool NetworkGameManager::signalLeftPlayer(int userID)
     
    151151    delete PlayerStats::getStats( userID );
    152152  }
    153  
     153
    154154  return true;
    155155}
     
    159159/**
    160160 * 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
    166166 * @return true on successfull handling else handler will be called again
    167167 */
    168168bool NetworkGameManager::delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
    169169{
    170   if ( getInstance()->isServer() )
     170  if ( SharedNetworkData::getInstance()->isMasterServer() )
    171171  {
    172172    PRINTF(2)("Recieved DeleteSynchronizeable message from client %d!\n", userId);
    173173    return true;
    174174  }
    175  
     175
    176176  int uniqueId = 0;
    177177  int len = Converter::byteArrayToInt( data, &uniqueId );
    178  
     178
    179179  if ( len != dataLength )
    180180  {
     
    182182    return true;
    183183  }
    184  
     184
    185185  const std::list<BaseObject*> * list = ClassList::getList( CL_SYNCHRONIZEABLE );
    186  
     186
    187187  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    188188  {
     
    194194        return true;
    195195      }
    196      
     196
    197197      delete dynamic_cast<Synchronizeable*>(*it);
    198198      return true;
    199199    }
    200200  }
    201  
     201
    202202  return true;
    203203}
     
    210210{
    211211  byte buf[INTSIZE];
    212  
     212
    213213  assert( Converter::intToByteArray( uniqueId, buf, INTSIZE ) == INTSIZE );
    214214
     
    220220/**
    221221 * 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
    228228 */
    229229bool NetworkGameManager::preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
    230230{
    231   assert( NetworkGameManager::getInstance()->isServer() );
    232  
     231  assert( SharedNetworkData::getInstance()->isMasterServer() );
     232
    233233  int teamId = 0;
    234234  int len = Converter::byteArrayToInt( data, &teamId );
    235  
     235
    236236  if ( len != dataLength )
    237237  {
     
    239239    return true;
    240240  }
    241  
     241
    242242  NetworkGameManager::getInstance()->setPreferedTeam( userId, teamId );
    243  
     243
    244244  return true;
    245245}
     
    249249  if ( !PlayerStats::getStats( userId ) )
    250250    return;
    251  
     251
    252252  PlayerStats & stats = *(PlayerStats::getStats( userId ));
    253  
     253
    254254  stats.setPreferedTeamId( teamId );
    255255}
     
    257257/**
    258258 * set prefered team for this host
    259  * @param teamId 
     259 * @param teamId
    260260 */
    261261void NetworkGameManager::prefereTeam( int teamId )
    262262{
    263   if ( isServer() )
     263  if ( SharedNetworkData::getInstance()->isMasterServer() )
    264264    setPreferedTeam( SharedNetworkData::getInstance()->getHostID(), teamId );
    265265  else
    266266  {
    267267    byte buf[INTSIZE];
    268    
     268
    269269    assert( Converter::intToByteArray( teamId, buf, INTSIZE) == INTSIZE );
    270    
     270
    271271    MessageManager::getInstance()->sendMessage( MSGID_PREFEREDTEAM, buf, INTSIZE, RT_USER, 0, MP_HIGHBANDWIDTH );
    272272  }
     
    285285    {
    286286      const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
    287        
     287
    288288      if ( list && std::find( list->begin(), list->end(), *it ) != list->end() )
    289       {     
     289      {
    290290        PRINTF(0)("Delete unused playable: %s owner: %d\n", (*it)->getClassName(), (*it)->getOwner() );
    291291        std::list<Playable*>::iterator delit = it;
     
    305305{
    306306  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() )
    308308  {
    309309    MessageManager::getInstance()->sendMessage( messageId, data, dataLength, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
    310310  }
    311  
     311
    312312  assert( State::getGameRules() );
    313313  assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) );
    314  
     314
    315315  NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules()));
    316  
     316
    317317  if ( dataLength < 3*INTSIZE )
    318318  {
    319319    PRINTF(2)("got too small chatmessage from client %d\n", userId);
    320    
     320
    321321    return true;
    322322  }
    323  
     323
    324324  int messageType = 0;
    325325  Converter::byteArrayToInt( data, &messageType );
     
    328328  std::string message;
    329329  Converter::byteArrayToString( data+2*INTSIZE, message, dataLength-2*INTSIZE );
    330  
     330
    331331  rules.handleChatMessage( senderUserId, message, messageType );
    332332
     
    346346  assert( Converter::intToByteArray( SharedNetworkData::getInstance()->getHostID(), buf+INTSIZE, INTSIZE ) == INTSIZE );
    347347  assert( Converter::stringToByteArray(message, buf+2*INTSIZE, message.length()+INTSIZE) == message.length()+INTSIZE );
    348  
    349   if ( this->isServer() )
     348
     349  if ( SharedNetworkData::getInstance()->isMasterServer() )
    350350    MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_ME, 0, MP_HIGHBANDWIDTH );
    351351  else
    352352    MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
    353353
    354  
     354
    355355  delete [] buf;
    356356}
  • branches/proxy/src/lib/network/network_game_manager.h

    r8708 r9347  
    2828  NET_YOU_ARE_ENTITY,
    2929  NET_REQUEST_ENTITY_LIST,
    30   NET_REQUEST_PNODE_PATH,
    31   NET_SEND_PNODE_PATH,
    3230
    3331  NET_NUMBER
     
    4240
    4341/*!
    44  * a class that can create and remove entities
     42 * a class that can create and remove entities over the network
    4543 */
    4644class NetworkGameManager: public Synchronizeable
    4745{
     46
    4847  public:
    4948    virtual ~NetworkGameManager();
    50    
     49
    5150    static NetworkGameManager* NetworkGameManager::getInstance()
    5251    { if (!NetworkGameManager::singletonRef) NetworkGameManager::singletonRef = new NetworkGameManager(); return NetworkGameManager::singletonRef; }
     
    5554    bool signalNewPlayer( int userId );
    5655    bool signalLeftPlayer( int userID );
    57    
    58     void removeSynchronizeable( int uniqueId );
    59    
     56
    6057    void prefereTeam( int teamId );
     58
    6159
    6260    inline void setGameState( int gameState ){ this->gameState = gameState; }
    6361    inline int getGameState(){ return this->gameState; }
    64    
     62
    6563    void tick( float ds );
    66    
     64
     65    void removeSynchronizeable( int uniqueId );
    6766    void sendChatMessage( const std::string & message, int messageType );
     67
    6868
    6969  private:
    7070    NetworkGameManager();
    71    
     71
    7272    static bool delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
    7373    static bool preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
    7474    static bool chatMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
    75    
     75
    7676    void setPreferedTeam( int userId, int teamId );
    7777
     78
     79  private:
    7880    static NetworkGameManager*    singletonRef;
    79    
     81
    8082    int                           gameState;
    81    
     83
    8284    std::list<Playable*>          playablesToDelete;
    8385};
  • branches/proxy/src/lib/network/network_manager.cc

    r9059 r9347  
    5353  this->networkStream = NULL;
    5454  this->elapsedTime = 0.0f;
    55  
    56    
     55
     56
    5757  int port = Preferences::getInstance()->getInt( "network", "telnetport", 0 );
    58  
     58
    5959  if ( port > 0 )
    6060    NetworkLog::getInstance()->listen( port );
     
    7575    this->networkStream = NULL;
    7676  }
    77  
     77
    7878  NetworkManager::singletonRef = NULL;
    7979}
     
    118118{
    119119  SharedNetworkData::getInstance()->setHostID(0);
    120   SharedNetworkData::getInstance()->setGameServer(true);
     120  SharedNetworkData::getInstance()->setNodeType(NET_MASTER_SERVER);
    121121  this->networkStream = new NetworkStream(port);
    122122  SharedNetworkData::getInstance()->setDefaultSyncStream(this->networkStream);
     
    148148  if ( networkStream )
    149149    networkStream->processData();
    150  
     150
    151151  NetworkGameManager::getInstance()->tick( this->elapsedTime );
    152152}
  • branches/proxy/src/lib/network/network_manager.h

    r9059 r9347  
    4141    /** Returns the hostID @return The hostID of the object */
    4242    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(); }
    4446
    4547
  • branches/proxy/src/lib/network/network_socket.cc

    r7954 r9347  
    3333{
    3434  bOk = true;
     35  this->ip.host = 0;
     36  this->ip.port = 0;
    3537}
    3638
  • branches/proxy/src/lib/network/network_socket.h

    r7954 r9347  
    2727     */
    2828    virtual void connectToServer( std::string host, int port ) = 0;
    29    
     29
    3030    /**
    3131     * disconnect from server
    3232     */
    3333    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;
    3444
    3545    /**
     
    4050     */
    4151    virtual bool writePacket(byte * data, int length) = 0;
    42    
     52
    4353    /**
    4454     * read a packet sent by another NetworkSocket
     
    5464     */
    5565    inline bool isOk() { return this->bOk; }
    56  
     66
     67    /** @returns the ip adderess of the destination socket */
     68    IPaddress getRemoteAddress() { return ip; }
     69
     70
    5771  protected:
    58     bool bOk;            //!< check for socket status
     72    bool              bOk;            //!< check for socket status
    5973
     74    IPaddress         ip;             //!< host,port
    6075};
    6176
  • branches/proxy/src/lib/network/network_stream.cc

    r9246 r9347  
    1212   main-programmer: Christoph Renner rennerc@ee.ethz.ch
    1313   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)
    1417*/
    1518
     
    2225#include "udp_socket.h"
    2326#include "udp_server_socket.h"
    24 #include "connection_monitor.h"
     27#include "monitor/connection_monitor.h"
     28#include "monitor/network_monitor.h"
    2529#include "synchronizeable.h"
     30#include "ip.h"
    2631#include "network_game_manager.h"
    2732#include "shared_network_data.h"
     
    4247#include <algorithm>
    4348
    44 /* include your own header */
     49
    4550#include "network_stream.h"
    4651
    47 /* probably unnecessary */
     52
    4853using namespace std;
    4954
     
    5257
    5358
     59/**
     60 * empty constructor
     61 */
    5462NetworkStream::NetworkStream()
    5563    : DataStream()
     
    5765  this->init();
    5866  /* initialize the references */
    59   this->type = NET_CLIENT;
    60 }
    61 
    62 
    63 /**
    64  * connect to a server as a client
     67  this->pInfo->nodeType = NET_CLIENT;
     68}
     69
     70
     71/**
     72 * start as a client, connect to a server
    6573 *  @param host: host name (address)
    6674 *  @param port: port number
     
    6876NetworkStream::NetworkStream( std::string host, int port )
    6977{
    70   this->type = NET_CLIENT;
    7178  this->init();
     79  // init the peers[0] the server to ceonnect to
    7280  this->peers[0].socket = new UdpSocket( host, port );
    7381  this->peers[0].userId = 0;
    74   this->peers[0].isServer = true;
     82  this->peers[0].nodeType = NET_MASTER_SERVER;
    7583  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;
    7691}
    7792
     
    8398NetworkStream::NetworkStream( int port )
    8499{
    85   this->type = NET_SERVER;
    86100  this->init();
    87101  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;
    89107}
    90108
     
    97115  /* set the class id for the base object */
    98116  this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
    99   this->bActive = false;
    100117  this->serverSocket = NULL;
    101118  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;
    104128
    105129  remainingBytesToWriteToDict = Preferences::getInstance()->getInt( "compression", "writedict", 0 );
     
    147171  for ( SynchronizeableList::const_iterator it = getSyncBegin(); it != getSyncEnd(); it ++ )
    148172    (*it)->setNetworkStream( NULL );
     173
     174  if( this->pInfo)
     175    delete this->pInfo;
     176
     177  if( this->networkMonitor)
     178    delete this->networkMonitor;
    149179}
    150180
     
    165195/**
    166196 * 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
    167199 */
    168200void NetworkStream::startHandshake()
    169201{
    170   Handshake* hs = new Handshake(false);
     202  Handshake* hs = new Handshake(this->pInfo->nodeType);
    171203  hs->setUniqueID( 0 );
    172204  assert( peers[0].handshake == NULL );
    173205  peers[0].handshake = hs;
    174206
     207  // set the preferred nick name
    175208  hs->setPreferedNickName( Preferences::getInstance()->getString( "multiplayer", "nickname", "Player" ) );
    176209
    177 //   peers[0].handshake->setSynchronized( true );
    178   //this->connectSynchronizeable(*hs);
    179   //this->connectSynchronizeable(*hs);
    180210  PRINTF(0)("NetworkStream: Handshake created: %s\n", hs->getName());
    181211}
     
    192222  sync.setNetworkStream( this );
    193223
    194   this->bActive = true;
     224//   this->bActive = true;
    195225}
    196226
     
    215245void NetworkStream::processData()
    216246{
     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
    217252  int tick = SDL_GetTicks();
    218253
    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
    223264    if ( serverSocket )
    224265      serverSocket->update();
    225266
    226267    this->updateConnectionList();
     268  }
     269  else if( this->pInfo->nodeType == NET_PROXY_SERVER_ACTIVE)
     270  {
     271    // execute everything the proxy server should do
    227272  }
    228273  else
     
    249294  cleanUpOldSyncList();
    250295  handleHandshakes();
     296
     297  // update the network monitor
     298  this->networkMonitor->process();
    251299
    252300  // order of up/downstream is important!!!!
     
    258306
    259307/**
    260  * if we are a server update the connection list to accept new connections (clients)
    261  * also start the handsake for the new clients
     308 * 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
    262310 */
    263311void NetworkStream::updateConnectionList( )
     
    276324      clientId = freeSocketSlots.back();
    277325      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;
    284326    }
    285327    else
     
    290332        if ( it->first >= clientId )
    291333          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
    315382  }
    316383
     
    373440void NetworkStream::debug()
    374441{
    375   if( this->isServer())
    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);
    377444  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);
    379446
    380447  PRINT(0)(" Got %i connected Synchronizeables, showing active Syncs:\n", this->synchronizeables.size());
     
    385452               (*it)->getUniqueID(), (*it)->beSynchronized());
    386453  }
    387   PRINT(0)(" Maximal Connections: %i\n", MAX_CONNECTIONS );
     454  PRINT(0)(" Maximal Connections: %i\n", SharedNetworkData::getInstance()->getMaxPlayer() );
    388455
    389456}
     
    414481    if ( it->second.handshake )
    415482    {
     483      // handshake finished
    416484      if ( it->second.handshake->completed() )
    417485      {
     486        //handshake is correct
    418487        if ( it->second.handshake->ok() )
    419488        {
    420489          if ( !it->second.handshake->allowDel() )
    421490          {
    422             if ( type != NET_SERVER )
     491            if ( this->pInfo->nodeType == NET_CLIENT )
    423492            {
    424493              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
    427511              this->networkGameManager = NetworkGameManager::getInstance();
    428512              this->networkGameManager->setUniqueID( it->second.handshake->getNetworkGameManagerId() );
     513              // init the new message manager
    429514              MessageManager::getInstance()->setUniqueID( it->second.handshake->getMessageManagerId() );
    430515            }
     
    437522          else
    438523          {
     524            // handshake finished registring new player
    439525            if ( it->second.handshake->canDel() )
    440526            {
    441               if ( type == NET_SERVER )
     527              if ( this->pInfo->nodeType == NET_MASTER_SERVER )
    442528              {
    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 );
    444535
    445536                if ( PlayerStats::getStats( it->second.userId ) && it->second.handshake->getPreferedNickName() != "" )
     
    468559
    469560/**
     561 * this functions handles a reconnect event received from the a NET_MASTER_SERVER or NET_PROXY_SERVER
     562 */
     563void 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/**
    470590 * handle upstream network traffic
    471591 */
     
    513633
    514634      // if we are a server and this is not our handshake
    515       if ( isServer() && sync.getLeafClassID() == CL_HANDSHAKE && sync.getUniqueID() != peer->second.userId )
     635      if ( isMasterServer() && sync.getLeafClassID() == CL_HANDSHAKE && sync.getUniqueID() != peer->second.userId )
    516636        continue;
    517637
     
    524644
    525645      // server fakes uniqueid == 0 for handshake
    526       if ( this->isServer() && sync.getUniqueID() < MAX_CONNECTIONS - 1 )
     646      if ( this->isMasterServer() && sync.getUniqueID() < SharedNetworkData::getInstance()->getMaxPlayer() - 1 )
    527647        n = Converter::intToByteArray( 0, buf + offset, UDP_PACKET_SIZE - offset );
    528648      else
     
    573693    // now compress the data with the zip library
    574694    int compLength = 0;
    575     if ( this->isServer() )
     695    if ( this->isMasterServer() )
    576696      compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE, dictServer );
    577697    else
     
    637757      assert( Converter::byteArrayToInt( buf + 2*INTSIZE, &fromState ) == INTSIZE );
    638758      assert( Converter::byteArrayToInt( buf + 3*INTSIZE, &ackedState ) == INTSIZE );
    639       //NETPRINTF(n)("ackedstate: %d\n", ackedState);
    640759      offset = 4*INTSIZE;
    641760
    642761      peer->second.connectionMonitor->processUnzippedIncomingPacket( tick, buf, packetLength, state, ackedState );
    643762
    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
    647765      if ( state <= peer->second.lastRecvedState )
    648766        continue;
     
    688806          }
    689807
    690           if ( !peers[peer->second.userId].isServer )
     808          if ( !peers[peer->second.userId].isMasterServer() )
    691809          {
    692810            offset += syncDataLength;
     
    779897/**
    780898 * is executed when a handshake has finished
    781  * @todo create playable for new user
    782899 */
    783900void NetworkStream::handleNewClient( int userId )
    784901{
     902  // init and assign the message manager
    785903  MessageManager::getInstance()->initUser( userId );
    786 
     904  // do all game relevant stuff here
    787905  networkGameManager->signalNewPlayer( userId );
    788 }
     906
     907  // register the new client at the network monitor
     908//   this->networkMonitor->addClient();
     909}
     910
    789911
    790912/**
  • branches/proxy/src/lib/network/network_stream.h

    r9246 r9347  
    1414#include "server_socket.h"
    1515#include "handshake.h"
    16 #include "connection_monitor.h"
     16#include "monitor/connection_monitor.h"
    1717#include "udp_server_socket.h"
     18#include "peer_info.h"
     19
     20#include "shared_network_data.h"
    1821
    1922class Synchronizeable;
     
    2124class ServerSocket;
    2225class NetworkGameManager;
     26class NetworkMonitor;
    2327
    24 //!< this structure contains informations about the network node
    25 class PeerInfo
    26 {
    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 };
    4128
    4229typedef std::list<Synchronizeable*>  SynchronizeableList;
     
    5845    void startHandshake();
    5946
     47    /* synchronizeable interface */
    6048    void connectSynchronizeable(Synchronizeable& sync);
    6149    void disconnectSynchronizeable(Synchronizeable& sync);
    6250
    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(); }
    6557
    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(); }
    6763
     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*/
    6870    virtual void processData();
     71
     72    /* debugging */
     73    void debug();
     74
     75
     76  private:
    6977
    7078    inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); }
    7179    inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); }
     80    void cleanUpOldSyncList();
    7281    int getSyncCount();
    7382
    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:
    8383    void updateConnectionList();
     84    /* handle processes */
    8485    void handleHandshakes();
    8586    void handleUpstream( int tick );
    8687    void handleDownstream(int tick );
     88
     89    /* handle events*/
    8790    void handleNewClient( int userId );
    88     void cleanUpOldSyncList();
     91    void handleReconnect( int userId );
    8992
    9093    void writeToNewDict( byte * data, int length, bool upstream );
     
    9295
    9396  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
    10098
    101     int                        myHostId;
     99    PeerInfo*                  pInfo;                       //!< the info about the local peer node (not in the PeerList)
    102100
     101    std::list<int>             freeSocketSlots;             //!< list of free sockets (to ensure not to resycle sockets)
    103102    int                        currentState;                //!< current state id
    104103
    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
    106107
    107108    std::map<int,int>          oldSynchronizeables;         //!< used to save recently deleted sync ids to not recreate them
     109    SynchronizeableList        synchronizeables;            //!< list of the synchronizeables
    108110
    109111    byte                       buf[UDP_PACKET_SIZE];        //!< used by handleUp/Downstream
    110112    byte                       compBuf[UDP_PACKET_SIZE];    //!< used by handleUp/Downstream
    111 
    112113    int                        remainingBytesToWriteToDict; //!< if > 0 NetworkStream will write packets to DATA/dicts/newdict
    113114
    114     int dictServer;
    115     int dictClient;
     115    int                        dictServer;                  //!< the zip dict for the server
     116    int                        dictClient;                  //!< the zip dict for the client
    116117};
    117118#endif /* _NETWORK_STREAM */
  • branches/proxy/src/lib/network/player_stats.cc

    r9235 r9347  
    3838{
    3939  init();
    40  
     40
    4141  this->userId = userId;
    4242}
     
    6262  this->nickName = "Player";
    6363  this->oldNickName = "Player";
    64  
     64
    6565  userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) );
    6666  teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
     
    7171  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
    7272  nickName_handler = registerVarId( new SynchronizeableString( &nickName, &nickName, "nickName" ) );
    73  
     73
    7474  MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGENICKNAME, changeNickHandler, NULL );
    75  
     75
    7676  PRINTF(0)("PlayerStats created\n");
    7777}
     
    9696  {
    9797    this->setPlayableUniqueId( this->playableUniqueId );
    98    
     98
    9999    PRINTF(0)("uniqueID changed %d %d %d\n", userId, SharedNetworkData::getInstance()->getHostID(), getUniqueID());
    100100  }
    101  
     101
    102102  if ( std::find( id.begin(), id.end(), nickName_handler ) != id.end() )
    103103  {
     
    115115{
    116116  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
    117  
     117
    118118  if ( !list )
    119119  {
    120120    return NULL;
    121121  }
    122  
     122
    123123  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    124124  {
     
    128128    }
    129129  }
    130  
     130
    131131  return NULL;
    132132}
     
    138138{
    139139  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
    140  
     140
    141141  if ( !list )
    142142  {
     
    144144    return;
    145145  }
    146  
     146
    147147  this->playable = NULL;
    148148  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
     
    156156    }
    157157  }
    158  
     158
    159159  if ( this->playable && userId == SharedNetworkData::getInstance()->getHostID() )
    160160  {
    161161    State::getPlayer()->setPlayable( this->playable );
    162162  }
    163  
     163
    164164  this->playableUniqueId = uniqueId;
    165165}
     
    173173  if ( playable )
    174174    return playable;
    175  
     175
    176176  assert( playableUniqueId > 0 );
    177  
     177
    178178  setPlayableUniqueId( playableUniqueId );
    179  
     179
    180180  assert( playable );
    181  
     181
    182182  return playable;
    183183}
     
    189189void PlayerStats::setNickName( std::string nick )
    190190{
    191   if ( SharedNetworkData::getInstance()->isGameServer() )
     191  if ( SharedNetworkData::getInstance()->isMasterServer() )
    192192  {
    193193    this->nickName = nick;
     
    199199  {
    200200    byte * data = new byte[nick.length()+INTSIZE];
    201    
     201
    202202    assert( Converter::stringToByteArray( nick, data, nick.length()+INTSIZE) == nick.length()+INTSIZE );
    203    
     203
    204204    MessageManager::getInstance()->sendMessage( MSGID_CHANGENICKNAME, data, nick.length()+INTSIZE, RT_SERVER, 0, MP_HIGHBANDWIDTH );
    205205    return;
     
    211211  std::string newNick;
    212212  int res = Converter::byteArrayToString( data, newNick, dataLength );
    213  
     213
    214214  if ( res != dataLength )
    215215  {
     
    217217    newNick = "invalid";
    218218  }
    219  
     219
    220220  if ( PlayerStats::getStats( userId ) )
    221221    PlayerStats::getStats( userId )->setNickName( newNick );
    222  
     222
    223223  return true;
    224224}
     
    228228  if ( getStats( SharedNetworkData::getInstance()->getHostID() ) )
    229229    getStats( SharedNetworkData::getInstance()->getHostID() )->setNickName( newNick );
    230    
     230
    231231  Preferences::getInstance()->setString( "multiplayer", "nickname", newNick );
    232232}
     
    237237{
    238238  const std::list<BaseObject*> * list;
    239  
     239
    240240  while ( (list  = ClassList::getList( CL_PLAYER_STATS )) != NULL && list->begin() != list->end() )
    241241    delete *list->begin();
     
    247247{
    248248  ScoreList result;
    249  
     249
    250250  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
    251  
     251
    252252  if ( !list )
    253253  {
    254254    return result;
    255255  }
    256  
     256
    257257  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    258258  {
    259259    PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it);
    260    
     260
    261261    TeamScoreList::iterator it = result[stats.getTeamId()].begin();
    262    
     262
    263263    while (  it != result[stats.getTeamId()].end() && stats.score > it->score )
    264264    {
    265265      it++;
    266266    }
    267    
     267
    268268    PlayerScore score;
    269269    score.name = stats.getNickName();
    270270    score.score = stats.getScore();
    271    
     271
    272272    result[stats.getTeamId()].insert(it, score);
    273273  }
    274  
     274
    275275  return result;
    276276}
  • branches/proxy/src/lib/network/shared_network_data.cc

    r9110 r9347  
    3535  this->hostID = -1;
    3636  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;
    3939}
    4040
  • branches/proxy/src/lib/network/shared_network_data.h

    r6695 r9347  
    88
    99#include "base_object.h"
     10#include "netdefs.h"
     11#include "proxy/proxy_settings.h"
    1012
    1113
    1214class NetworkStream;
    1315class Synchronizeable;
    14 template<typename>
    15     class tList;
     16
    1617
    1718/* and here is the class itsself*/
     
    2526
    2627    /** @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; }
    2829
    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; }
    3136    /** 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(); }
    3341
    3442    /** @returns the hostID of the node */
     
    4957  private:
    5058    int                             newUniqueID;             //!< next uniqueID
    51     bool                            bGameServer;             //!< true if it is a server
     59    int                             nodeType;                //!< saves the node type here
     60
    5261    int                             hostID;                  //!< The Host-ID of the Manager
    5362    NetworkStream*                  defaultSyncStream;       //!< default synchronize NetworkStream
  • branches/proxy/src/lib/network/synchronizeable.cc

    r9110 r9347  
    3838  this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable");
    3939  this->owner = 0;
    40   this->setIsServer(SharedNetworkData::getInstance()->getHostID() == 0);
     40//   this->setIsServer(SharedNetworkData::getInstance()->getHostID() == 0);
    4141  this->uniqueID = NET_UID_UNASSIGNED;
    4242  this->networkStream = NULL;
    4343  this->bSynchronize = false;
    44  
     44
    4545  if( State::isOnline())
    4646  {
     
    5454  assert( syncVarList.size() == 0 );
    5555  mLeafClassId = this->registerVarId( new SynchronizeableInt( (int*)&this->getLeafClassID(), (int*)&this->getLeafClassID(), "leafClassId" ) );
    56    
     56
    5757  this->registerVar( new SynchronizeableInt( &this->owner, &this->owner, "owner" ) );
    5858  this->registerVar( new SynchronizeableString( &this->objectName, &this->objectName, "objectName" ) );
     
    6969  {
    7070    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 ) )
    7373      NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() );
    7474  }
    75    
     75
    7676  for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
    7777  {
     
    7979  }
    8080  syncVarList.clear();
    81  
     81
    8282  for ( UserStateHistory::iterator it = recvStates.begin(); it != recvStates.end(); it++ )
    8383  {
     
    9393
    9494  }
    95  
     95
    9696  for ( UserStateHistory::iterator it = sentStates.begin(); it != sentStates.end(); it++ )
    9797  {
     
    105105      delete *it2;
    106106    }
    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  }
    131108}
    132109
     
    169146        (*it2)->data = NULL;
    170147      }
    171      
     148
    172149      delete *it2;
    173150    }
     
    181158  while ( it != sentStates[userId].end() && (*it)->stateId != fromStateId )
    182159    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 //  }
    188160
    189161  if ( it == sentStates[userId].end() )
     
    196168
    197169    stateFrom = initialEntry;
    198    
     170
    199171    sentStates[userId].push_back( stateFrom );
    200172  }
     
    205177
    206178  sentStates[userId].push_back( stateTo );
    207  
     179
    208180  stateTo->stateId = stateId;
    209181  stateTo->dataLength = neededSize;
     
    214186  int i = 0;
    215187  int n;
    216  
     188
    217189  bool hasPermission;
    218190  bool sizeChanged = false;
     
    222194  {
    223195    hasPermission = (
    224             this->isServer() && (*it)->checkPermission( PERMISSION_SERVER ) ||
     196        SharedNetworkData::getInstance()->isMasterServer() && (*it)->checkPermission( PERMISSION_MASTER_SERVER ) ||
    225197        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 )
    228200                    );
    229    
    230     if ( sizeIter == stateFrom->sizeList.end() || *sizeIter != (*it)->getSize() ) 
     201
     202    if ( sizeIter == stateFrom->sizeList.end() || *sizeIter != (*it)->getSize() )
    231203      sizeChanged = true;
    232    
     204
    233205    if ( ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeChanged )
    234206    {
     
    303275    it++;
    304276
    305  
     277
    306278//  if ( getLeafClassID() == CL_SPACE_SHIP )
    307279//  {
     
    318290
    319291    stateFrom = initialEntry;
    320    
     292
    321293    recvStates[userId].push_back( stateFrom );
    322294  }
    323295  else
    324296    stateFrom = (*it);
    325  
     297
    326298  //apply diff
    327299  for ( int i = 0; i<length; i++ )
     
    331303    else
    332304      stateTo->data[i] = data[i];
    333    
    334   }
    335  
     305
     306  }
     307
    336308  //add state to state history
    337309  recvStates[userId].push_back( stateTo );
    338  
     310
    339311  int i = 0;
    340312  int n = 0;
    341313  std::list<int> changes;
    342  
     314
    343315  for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
    344316  {
    345317    if (
    346         (*it)->checkPermission( PERMISSION_SERVER ) && networkStream->isUserServer( userId ) ||
     318        (*it)->checkPermission( PERMISSION_MASTER_SERVER ) && networkStream->isUserMasterServer( userId ) ||
    347319        (*it)->checkPermission( PERMISSION_OWNER ) && this->owner == userId ||
    348         networkStream->isUserServer( 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 )
    350322       )
    351323    {
     
    361333    else
    362334    {
    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 );
    364336      n = (*it)->getSizeFromBuf( stateTo->data + i, stateTo->dataLength - i );
    365337      //NETPRINTF(0)("%s::setvar %s %d\n", getClassName(), (*it)->getName().c_str(), n);
     
    370342
    371343  this->varChangeHandler( changes );
    372  
     344
    373345  return i;
    374346}
     
    423395        (*it)->data = NULL;
    424396      }
    425    
     397
    426398      delete *it;
    427399    }
    428400    recvStates[userId].clear();
    429401  }
    430  
     402
    431403  if ( sentStates.size() > userId )
    432404  {
    433    
     405
    434406    for ( std::list<StateHistoryEntry*>::iterator it = sentStates[userId].begin(); it != sentStates[userId].end(); it++ )
    435407    {
     
    439411        (*it)->data = NULL;
    440412      }
    441    
     413
    442414      delete *it;
    443415    }
     
    448420/**
    449421 * 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
    453425 */
    454426void Synchronizeable::handleRecvState( int userId, int stateId, int fromStateId )
     
    457429  if ( recvStates.size() <= userId )
    458430    recvStates.resize( userId+1 );
    459  
     431
    460432  //remove old states
    461433  StateHistory::iterator it = recvStates[userId].begin();
     
    485457      StateHistory::iterator delIt = it;
    486458      it ++;
    487      
     459
    488460      if ( (*delIt)->data )
    489461      {
     
    493465      delete *delIt;
    494466      recvStates[userId].erase( delIt );
    495      
     467
    496468      continue;
    497469    }
    498470    it++;
    499471  }
    500  
     472
    501473  StateHistory::iterator fromState = recvStates[userId].end();
    502474  StateHistory::iterator toState = recvStates[userId].end();
    503  
     475
    504476  for ( it = recvStates[userId].begin(); it != recvStates[userId].end(); it++ )
    505477  {
     
    508480    if ( (*it)->stateId == fromStateId )
    509481      fromState = it;
    510    
     482
    511483    if ( fromState != recvStates[userId].end() && toState != recvStates[userId].end() )
    512484      break;
    513485  }
    514  
     486
    515487  // setStateDiff was not called and i know fromStateId
    516488  if ( fromState != recvStates[userId].end() && toState == recvStates[userId].end() )
    517489  {
    518490    StateHistoryEntry * entry = new StateHistoryEntry;
    519    
     491
    520492    entry->dataLength = (*fromState)->dataLength;
    521493    if ( entry->dataLength > 0 )
    522494    {
    523495      entry->data = new byte[entry->dataLength];
    524          
     496
    525497      assert( (*fromState)->data );
    526498      memcpy( entry->data, (*fromState)->data, entry->dataLength );
     
    528500    else
    529501      entry->data = NULL;
    530    
     502
    531503    entry->sizeList = (*fromState)->sizeList;
    532504    entry->stateId = stateId;
    533    
     505
    534506    recvStates[userId].push_back(entry);
    535507  }
     
    538510/**
    539511 * 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
    543515 */
    544516void Synchronizeable::handleSentState( int userId, int stateId, int fromStateId )
     
    557529      StateHistory::iterator delIt = it;
    558530      it ++;
    559      
     531
    560532      if ( (*delIt)->data )
    561533      {
     
    565537      delete *delIt;
    566538      sentStates[userId].erase( delIt );
    567      
     539
    568540      continue;
    569541    }
     
    571543  }
    572544
    573  
     545
    574546  StateHistory::iterator fromState = sentStates[userId].end();
    575547  StateHistory::iterator toState = sentStates[userId].end();
    576  
     548
    577549  for ( it = sentStates[userId].begin(); it != sentStates[userId].end(); it++ )
    578550  {
     
    581553    if ( (*it)->stateId == fromStateId )
    582554      fromState = it;
    583    
     555
    584556    if ( fromState != sentStates[userId].end() && toState != sentStates[userId].end() )
    585557      break;
    586558  }
    587559
    588  
     560
    589561  // getStateDiff was not called and i know fromStateId
    590562  if ( fromState != sentStates[userId].end() && toState == sentStates[userId].end() )
    591563  {
    592564    StateHistoryEntry * entry = new StateHistoryEntry;
    593    
     565
    594566    entry->dataLength = (*fromState)->dataLength;
    595567    if ( entry->dataLength > 0 )
    596568    {
    597569      entry->data = new byte[entry->dataLength];
    598      
     570
    599571      assert( (*fromState)->data );
    600572      memcpy( entry->data, (*fromState)->data, entry->dataLength );
     
    602574    else
    603575      entry->data = NULL;
    604    
     576
    605577    entry->sizeList = (*fromState)->sizeList;
    606578    entry->stateId = stateId;
    607    
     579
    608580    sentStates[userId].push_back(entry);
    609581  }
    610  
    611 }
    612 
    613 
    614 
     582
     583}
     584
     585
     586
  • branches/proxy/src/lib/network/synchronizeable.h

    r8708 r9347  
    2020#include "synchronizeable_var/synchronizeable_bool.h"
    2121#include "synchronizeable_var/synchronizeable_uint.h"
     22#include "synchronizeable_var/synchronizeable_ip.h"
    2223
    2324
     
    5152    virtual ~Synchronizeable();
    5253
    53     void setIsServer( bool isServer );
    54     bool isServer();
     54//     void setIsServer( bool isServer );
     55//     bool isServer();
    5556
    5657    virtual void varChangeHandler( std::list<int> & id );
     
    6162    virtual void handleSentState( int userId, int stateId, int fromStateId );
    6263    virtual void handleRecvState( int userId, int stateId, int fromStateId );
    63    
     64
    6465    void registerVar( SynchronizeableVar * var );
    6566    int registerVarId( SynchronizeableVar * var );
     
    8283  protected:
    8384    NetworkStream*    networkStream;  //!< reference network stream we are connected to
    84     int               state;
     85//     int               state;
    8586
    8687  private:
  • branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_bool.h

    r7954 r9347  
    1212
    1313  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 );
    1515    virtual ~SynchronizeableBool();
    1616   
  • branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_float.h

    r7954 r9347  
    1212
    1313  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 );
    1515    virtual ~SynchronizeableFloat();
    1616   
  • branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_int.h

    r7954 r9347  
    1212
    1313  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 );
    1515    virtual ~SynchronizeableInt();
    1616   
  • branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_quaternion.h

    r7954 r9347  
    1414
    1515  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 );
    1717    virtual ~SynchronizeableQuaternion();
    1818   
  • branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_string.h

    r7954 r9347  
    1515
    1616  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 );
    1818    virtual ~SynchronizeableString();
    1919   
  • branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_uint.h

    r7954 r9347  
    1212
    1313  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 );
    1515    virtual ~SynchronizeableUInt();
    1616   
  • branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_var.h

    r7954 r9347  
    1212
    1313enum {
    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
    1718};
    1819
     
    2021
    2122  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 );
    2324    virtual ~SynchronizeableVar();
    2425
     
    2829     */
    2930    inline bool beWatched(){ return this->bWatched; }
    30    
    31     /** 
     31
     32    /**
    3233     * set flag if synchronizeable wants to be informed on changes
    3334     */
     
    9697     */
    9798    inline void resetPriority() { this->priority = this->realPriority; }
    98    
     99
    99100    /**
    100101     * reads actual size from buffer. this is used when size is not constant
     
    104105     */
    105106    virtual inline int getSizeFromBuf( byte * buf, int maxLength ){ return this->getSize(); }
    106    
     107
    107108    /**
    108109     * set variable id
     
    110111     */
    111112    inline void setVarId( int id ){ this->varId = id; }
    112    
    113     /** 
     113
     114    /**
    114115     * get variable id
    115116     * @return variable id
    116117     */
    117118    inline int getVarId(){ return varId; }
    118    
     119
    119120    /**
    120121     * set hasChanged
     
    122123     */
    123124    inline void setHasChanged( bool changed ){ this->changed = changed; }
    124    
    125     /** 
     125
     126    /**
    126127     * get hasChanged
    127128     * @return variable id
    128129     */
    129130    inline bool getHasChanged(){ return changed; }
    130    
     131
    131132    /**
    132133     * print out variable value
     
    137138  private:
    138139    bool bWatched;      //!< true if synchronizeable wants to be informed on changes
    139    
     140
    140141    int permission;     //!< who is allowed to change this var
    141142    int priority;       //!< priority assigned to var
    142143    int realPriority;   //!< priority assigned to var, increased every time not sent
    143144    int varId;          //!< id to identify varables
    144    
     145
    145146    bool changed;       //!< true if last readFromBuf changed anything
    146147
  • branches/proxy/src/lib/network/synchronizeable_var/synchronizeable_vector.h

    r7954 r9347  
    1414
    1515  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 );
    1717    virtual ~SynchronizeableVector();
    1818   
  • branches/proxy/src/lib/network/tcp_server_socket.cc

    r7954 r9347  
    136136  _isListening = false;
    137137}
     138
  • branches/proxy/src/lib/network/tcp_server_socket.h

    r7954 r9347  
    2828    virtual void close();
    2929    virtual void update() {};
    30    
     30
    3131  private:
    3232    TCPsocket listenSocket;
     
    3636
    3737    void init();
    38  
     38
    3939};
    4040
  • branches/proxy/src/lib/network/tcp_socket.h

    r7954 r9347  
    11/*!
    2  * @file network_socket.h
    3   *  Main interface for the network module. Manages all the modules
     2 * @file tcp_socket.h
     3  *  tcp socket network interface
    44
    55*/
     
    4747
    4848    virtual void connectToServer( std::string host, int port );
    49    
     49
    5050    virtual void disconnectServer();
     51    virtual void reconnectToServer( std::string host, int port);
     52    virtual void reconnectToServerSoft( std::string host, int port);
    5153
    5254    virtual bool writePacket(byte * data, int length);
  • branches/proxy/src/lib/network/udp_socket.cc

    r8802 r9347  
    7474{
    7575  this->init();
     76  this->ip = ip;
    7677  this->serverSocket = serverSocket;
    7778  this->userId = userId;
     
    105106  assert( serverSocket == NULL );
    106107
    107   IPaddress ip;
    108  
    109108  this->randomByte = generateNewRandomByte();
    110109
    111110  PRINTF(0)("connect to server %s on port %d\n", host.c_str(), port);
    112111
    113   if ( SDLNet_ResolveHost( &ip, host.c_str(), port ) != 0 )
     112  if ( SDLNet_ResolveHost( &this->ip, host.c_str(), port ) != 0 )
    114113  {
    115114    PRINTF(1)("SDLNet_ResolveHost: %s\n", SDLNet_GetError() );
     
    126125  }
    127126
    128   int channel = SDLNet_UDP_Bind(socket, 1, &ip);
     127  int channel = SDLNet_UDP_Bind(socket, 1, &this->ip);
    129128  if ( channel == -1 )
    130129  {
     
    147146  bOk = false;
    148147  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 */
     161void 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 */
     178void UdpSocket::reconnectToServerSoft( std::string host, int port)
     179{}
     180
    150181
    151182/**
     
    179210
    180211    byte udpCmd = 0;
    181    
     212
    182213    if ( networkPacket.length > 0 )
    183214    {
     
    189220    else
    190221      return 0;
    191      
     222
    192223    if ( !checkRandomByte( networkPacket.data[0] ) )
    193224      return 0;
     
    198229      networkPacket.data = NULL;
    199230    }
    200    
     231
    201232    if ( !checkUdpCmd( udpCmd ) )
    202233      return 0;
     
    207238  {
    208239    int numrecv = SDLNet_UDP_Recv( socket, packet);
    209    
     240
    210241    byte udpCmd = 0;
    211242
     
    218249      else
    219250        return 0;
    220            
     251
    221252      if ( !checkRandomByte( packet->data[0] ) )
    222253        return 0;
    223              
     254
    224255      if ( !checkUdpCmd( udpCmd ) )
    225256        return 0;
     
    283314    return false;
    284315  }
    285  
     316
    286317  if ( !this->serverSocket && ( udpCmd & UDPCMD_INVALIDRNDBYTE ) )
    287318  {
     
    292323    return false;
    293324  }
    294  
     325
    295326  return true;
    296327}
     
    300331  srand( SDL_GetTicks() );
    301332  byte res = ( rand() & 0xFC );
    302  
     333
    303334  PRINTF(0)("generated random byte: %x\n", res);
    304  
     335
    305336  return res;
    306337}
  • branches/proxy/src/lib/network/udp_socket.h

    r8802 r9347  
    3131
    3232    virtual void connectToServer( std::string host, int port );
    33    
    3433    virtual void disconnectServer();
    3534
     35    virtual void reconnectToServer( std::string host, int port);
     36    virtual void reconnectToServerSoft( std::string host, int port);
     37
    3638    virtual bool writePacket(byte * data, int length );
     39    virtual int readPacket(byte * data, int maxLength);
    3740
    38     virtual int readPacket(byte * data, int maxLength);
    39    
     41
    4042  private:
    4143    UdpServerSocket * serverSocket;   //!< will get packets here
    4244    int               userId;         //!< user id used by serverSocket
    43     IPaddress         ip;             //!< host,port
    4445    UDPsocket         socket;         //!< socket used to send/recieve
    4546    UDPpacket *       packet;
    46    
     47
    4748    byte              randomByte;     //!< contains random bytes & 0xFC
    48    
     49
    4950    bool writeRawPacket( byte * data, int length );
    5051    bool checkUdpCmd( byte udpCmd );
    5152    bool checkRandomByte( byte rndByte );
    5253    byte generateNewRandomByte();
    53    
     54
    5455    void init();
    5556
  • branches/proxy/src/lib/shell/shell_command.cc

    r9112 r9347  
    299299      {
    300300        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));
    302302      }
    303303      return true;
     
    375375//       if(this->completors[parameter] == NULL)
    376376//       delete this->completors[parameter];
    377 //       this->completors[parameter] = completorPlugin.clone(); 
     377//       this->completors[parameter] = completorPlugin.clone();
    378378    }
    379379    return this;
  • branches/proxy/src/lib/util/Makefile.am

    r8724 r9347  
    66libORXlibutil_a_SOURCES = \
    77                substring.cc \
    8                 tokenizer.cc \
    98                color.cc \
    109                helper_functions.cc \
     
    3231noinst_HEADERS = \
    3332                substring.h \
    34                 tokenizer.h \
    3533                multi_type.h \
    3634                color.h \
  • branches/proxy/src/lib/util/executor/executor_functional.h

    r8271 r9347  
    179179  {
    180180    (__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])));
    182182  };
    183183
     
    222222  {
    223223    (__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])));
    226226  };
    227227
     
    276276  {
    277277    (__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])));
    281281  };
    282282
     
    333333  {
    334334    (__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])));
    339339  };
    340340
     
    392392  {
    393393    (__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])));
    399399  };
    400400
  • branches/proxy/src/lib/util/executor/functor_list.h

    r8894 r9347  
    135135
    136136  //! mixed values:
     137  FUNCTOR_LIST(2)(l_STRING, l_INT);
    137138  FUNCTOR_LIST(2)(l_STRING, l_FLOAT);
    138139  FUNCTOR_LIST(2)(l_UINT, l_LONG);
  • branches/proxy/src/lib/util/multi_type.cc

    r8316 r9347  
    1818#include "multi_type.h"
    1919
    20 //#include "stdincl.h"
    21 #include <stddef.h>
    22 #include <stdlib.h>
    23 #include <string.h>
    24 #include <stdio.h>
    2520#include <sstream>
    2621
     
    2823#include "debug.h"
    2924#endif
    30 
    31 using namespace std;
    3225
    3326/**
  • branches/proxy/src/lib/util/substring.cc

    r7477 r9347  
    2828#include "substring.h"
    2929
    30 #include <string.h>
    31 #include <cassert>
    32 
    33 
    3430/**
    3531 * @brief default constructor
     
    108104
    109105/** @brief An empty String */
    110 const std::string SubString::emptyString = "";
     106// const std::string SubString::emptyString = "";
    111107/** @brief Helper that gets you a String consisting of all White Spaces */
    112108const std::string SubString::WhiteSpaces = " \n\t";
     
    238234  }
    239235  else
    240     return SubString::emptyString;
     236  {
     237    static std::string empty;
     238    return empty;
     239  }
    241240}
    242241
     
    250249 * SubString::SubString(const SubString& subString, unsigned int subSetBegin)
    251250 */
    252 SubString SubString::getSubSet(unsigned int subSetBegin) const
     251SubString SubString::subSet(unsigned int subSetBegin) const
    253252{
    254253  return SubString(*this, subSetBegin);
     
    265264 * SubString::SubString(const SubString& subString, unsigned int subSetBegin)
    266265 */
    267 SubString SubString::getSubSet(unsigned int subSetBegin, unsigned int subSetEnd) const
     266SubString SubString::subSet(unsigned int subSetBegin, unsigned int subSetEnd) const
    268267{
    269268  return SubString(*this, subSetBegin, subSetEnd);
     
    289288 * Supports delimiters, escape characters,
    290289 * ignores special  characters between safemode_char and between comment_char and linend '\n'.
    291  *
    292  *
    293290 */
    294291SubString::SPLIT_LINE_STATE
  • branches/proxy/src/lib/util/substring.h

    r8408 r9347  
    22 * @file substring.h
    33 * @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.
    418 */
    519
    6 #ifndef _SUBSTRING_H
    7 #define _SUBSTRING_H
     20#ifndef __SUBSTRING_H__
     21#define __SUBSTRING_H__
    822
    923#include <vector>
     
    6175
    6276  // 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;
    6579
    6680  // retrieve Information from within
     
    7084  inline unsigned int size() const { return this->strings.size(); };
    7185  /** @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]; };
    7387  /** @param i the i'th String @returns the i'th string from the subset of Strings */
    7488  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(); };
    7595
    7696  // the almighty algorithm.
     
    93113private:
    94114  std::vector<std::string>  strings;                      //!< strings produced from a single string splitted in multiple strings
    95 
    96   static const std::string emptyString;
    97115};
    98116
    99 #endif /* _SUBSTRING_H */
     117#endif /* __SUBSTRING_H__ */
  • branches/proxy/src/orxonox.cc

    r9240 r9347  
    453453  if ( Preferences::getInstance()->getString("misc", "bt-to-file", "1") == "1" )
    454454  {
    455     SignalHandler::getInstance()->doCatch( argv[0] );
    456 
     455    SignalHandler::getInstance()->doCatch( argv[0], "orxonox.backtrace" );
     456    SignalHandler::getInstance()->registerCallback( EventHandler::releaseMouse, NULL );
    457457  }
    458458
  • branches/proxy/src/story_entities/game_world_data.h

    r7460 r9347  
    4242    void loadGameRule(const TiXmlElement* root);
    4343
     44
    4445  protected:
    4546    virtual ErrorMessage loadGUI(const TiXmlElement* root);
  • branches/proxy/src/story_entities/multi_player_world_data.cc

    r9235 r9347  
    4747#include "player_stats.h"
    4848
     49#include "proxy/proxy_settings.h"
    4950
    5051#include "glmenu_imagescreen.h"
     
    110111{
    111112  const TiXmlElement* element = NULL;
    112  
    113   if( NetworkManager::getInstance()->isGameServer() )
     113
     114  if( NetworkManager::getInstance()->isMasterServer() )
    114115  {
    115116    /* load the spawning points */
     
    147148    element = element->FirstChildElement();
    148149
    149     if( NetworkManager::getInstance()->isGameServer() )
     150    if( NetworkManager::getInstance()->isMasterServer() )
    150151    {
    151152      while( element != NULL)
     
    205206
    206207
    207     if( NetworkManager::getInstance()->isGameServer())
     208    if( NetworkManager::getInstance()->isMasterServer())
    208209    {
    209210      this->localPlayer = new Player();
     
    280281  GameWorldData::loadScene(root);
    281282
     283  LoadParamXML(root, "ProxySettings", ProxySettings::getInstance(), ProxySettings, loadProxySettings);
     284
    282285  // create server playable
    283   if ( NetworkManager::getInstance()->isGameServer() )
     286  if ( NetworkManager::getInstance()->isMasterServer() )
    284287  {
    285288    NetworkGameManager::getInstance()->signalNewPlayer( 0 );
     
    296299ErrorMessage MultiPlayerWorldData::unloadScene()
    297300{
     301  // delete the proxy settings
     302  delete ProxySettings::getInstance();
     303
    298304  /* call underlying function */
    299305  return GameWorldData::unloadScene();
  • branches/proxy/src/subprojects/network/network_unit_test.cc

    r8623 r9347  
    208208
    209209  /* esatblish a connection */
    210   IPaddress ip;
     210  IP ip;
    211211  int error = SDLNet_ResolveHost(&ip, "127.0.0.1", port);
    212212  //SDLNet_ResolveHost(&ip, "localhost", port);
     
    353353  printf("Connecting to %s, on port %i\n", name, port);
    354354
    355   IPaddress ip;
     355  IP ip;
    356356  int error = SDLNet_ResolveHost(&ip, name, port);
    357357  if(error == -1)
  • branches/proxy/src/util/Makefile.am

    r8068 r9347  
    1414                        singleplayer_shootemup.cc \
    1515                        \
     16                        \
     17                        \
    1618                        mission_goal.cc\
    1719                        kill_target.cc\
     
    2426                        animation/animation_player.cc \
    2527                        \
    26                         track/pilot_node.cc
     28                        track/pilot_node.cc \
     29                        \
     30                        network_stats_widget.cc
    2731
    2832#                       track/track_manager.cc \
     
    5054                        animation/t_animation.h \
    5155                        \
    52                         track/pilot_node.h
     56                        track/pilot_node.h \
     57                        \
     58                        network_stats_widget.h
     59
    5360
    5461#                       track/track_manager.h \
  • branches/proxy/src/util/game_rules.cc

    r9008 r9347  
    8888void GameRules::registerKill(const Kill& kill)
    8989{
    90   if ( !SharedNetworkData::getInstance()->isGameServer() )
     90  if ( !SharedNetworkData::getInstance()->isMasterServer() )
    9191    return;
    9292
  • branches/proxy/src/util/multiplayer_team_deathmatch.cc

    r9235 r9347  
    204204  assignPlayable();
    205205
    206   if ( !SharedNetworkData::getInstance()->isGameServer() )
     206  if ( !SharedNetworkData::getInstance()->isMasterServer() )
    207207    return;
    208208
     
    214214    this->killList.erase( this->killList.begin() );
    215215  }
    216  
     216
    217217
    218218
     
    268268void MultiplayerTeamDeathmatch::checkGameRules()
    269269{
    270   if ( !SharedNetworkData::getInstance()->isGameServer() )
     270  if ( !SharedNetworkData::getInstance()->isMasterServer() )
    271271    return;
    272272
     
    320320      return "maps/male_fiend.pcx";
    321321  }
    322  
     322
    323323  return "";
    324324}
     
    330330    return 10.0f;
    331331  }
    332  
     332
    333333  return 1.0f;
    334334}
     
    680680  char st[10];
    681681  int i = 0;
    682  
     682
    683683  i = 2;
    684684  for ( TeamScoreList::const_iterator it = scoreList[0].begin(); it != scoreList[0].end(); it++ )
     
    719719    return;
    720720  }
    721  
     721
    722722  int killerUserId = killer->getOwner();
    723723  int victimUserId = victim->getOwner();
    724  
     724
    725725  PRINTF(0)("%d %d %x %x %s %s\n", killerUserId, victimUserId, killer, victim, killer->getClassName(), victim->getClassName());
    726726
    727727  PlayerStats & victimStats = *PlayerStats::getStats( victimUserId );
    728728  PlayerStats & killerStats = *PlayerStats::getStats( killerUserId );
    729  
     729
    730730  if ( killerStats.getPlayable() != killer || victimStats.getPlayable() != victim )
    731731  {
  • branches/proxy/src/util/signal_handler.cc

    r9240 r9347  
    2727}
    2828
    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 */
     34void SignalHandler::doCatch( const std::string & appName, const std::string & fileName )
    3035{
    3136  this->appName = appName;
     37  this->fileName = fileName;
     38 
     39  // make sure doCatch is only called once without calling dontCatch
     40  assert( sigRecList.size() == 0 );
    3241
    3342  catchSignal( SIGSEGV );
     
    3544}
    3645
     46/**
     47 * restore previous signal handlers
     48 */
    3749void SignalHandler::dontCatch()
    3850{
     
    4557}
    4658
     59/**
     60 * catch signal sig
     61 * @param sig signal to catch
     62 */
    4763void SignalHandler::catchSignal( int sig )
    4864{
     
    5874}
    5975
     76/**
     77 * sigHandler is called when receiving signals
     78 * @param sig
     79 */
    6080void SignalHandler::sigHandler( int sig )
    6181{
     
    167187        )
    168188          charsFound++;
     189    else
     190      charsFound = 0;
    169191
    170192    if ( charsFound == 6 )
     
    183205  write( sigPipe[1], &someData, sizeof(someData) );
    184206
    185   write( gdbIn[1], "bt\nq\n", 5 );
     207  write( gdbIn[1], "bt\nk\nq\n", 7 );
    186208
    187209 
     
    202224        )
    203225          charsFound++;
     226    else
     227      charsFound = 0;
    204228
    205229    if ( charsFound == 6 )
     
    210234    }
    211235
    212     if ( promptFound == 2 )
     236    if ( promptFound == 3 )
    213237    {
    214238      break;
     
    240264  bt.insert(0, timeString);
    241265 
    242   FILE * f = fopen( GDB_BT_FILE, "a" );
     266  FILE * f = fopen( getInstance()->fileName.c_str(), "a" );
    243267
    244268  if ( !f )
    245269  {
    246     perror("could not append to " GDB_BT_FILE);
     270    perror( ( std::string( "could not append to " ) + getInstance()->fileName ).c_str() );
    247271    exit(EXIT_FAILURE);
    248272  }
     
    250274  if ( fwrite( bt.c_str(), 1, bt.length(), f ) != bt.length() )
    251275  {
    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());
    253277    exit(EXIT_FAILURE);
    254278  }
  • branches/proxy/src/util/signal_handler.h

    r9240 r9347  
    99#include <list>
    1010#include <string>
    11 
    12 
    13 #define GDB_BT_FILE "orxonox.backtrace"
    1411
    1512typedef int (*SignalCallback)( void * someData );
     
    4441    void registerCallback( SignalCallback cb, void * someData );
    4542
    46     void doCatch( std::string appName );
     43    void doCatch( const std::string & appName, const std::string & fileName );
    4744    void dontCatch();
    4845
     
    5855
    5956    std::string appName;
     57    std::string fileName;
    6058};
    6159
  • branches/proxy/src/world_entities/camera.cc

    r9235 r9347  
    1717#include "camera.h"
    1818#include "key_mapper.h"
     19#include "glincl.h"
    1920
    2021/**
  • branches/proxy/src/world_entities/creatures/fps_player.cc

    r9235 r9347  
    287287  //dealing damage
    288288
    289   if ( State::isOnline() && SharedNetworkData::getInstance()->isGameServer() )
     289  if ( State::isOnline() && SharedNetworkData::getInstance()->isMasterServer() )
    290290  {
    291291    this->damageTicker -= time;
  • branches/proxy/src/world_entities/playable.cc

    r9235 r9347  
    361361  }
    362362}
    363 /**
    364  * @brief helps us colliding Playables
    365  * @param entity the Entity to collide
    366  * @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 HACK
    378     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 }
    387363
    388364
     
    413389    }
    414390    this->bDead = true;
    415    
     391
    416392    if( State::getGameRules() != NULL)
    417393      State::getGameRules()->registerKill(Kill(killer, this));
  • branches/proxy/src/world_entities/playable.h

    r9235 r9347  
    8282  virtual void destroy(WorldEntity* killer);
    8383  virtual void respawn();
    84   virtual void collidesWith(WorldEntity* entity, const Vector& location);
    8584  virtual void process(const Event &event);
    8685  virtual void tick(float dt);
     
    9089  static const std::string& playmodeToString(Playable::Playmode playmode);
    9190  static const std::string playmodeNames[];
    92  
     91
    9392  inline bool beFire(){ return this->bFire; }
    9493  inline void fire(bool bF){ this->bFire = bF;}
  • branches/proxy/src/world_entities/space_ships/space_ship.cc

    r9235 r9347  
    314314  if( entity->isA(CL_PROJECTILE) && entity != ref)
    315315  {
    316     if ( isServer() )
     316    if ( SharedNetworkData::getInstance()->isMasterServer() )
    317317    {
    318318      //TODO handle this
  • branches/proxy/src/world_entities/spawning_point.cc

    r9235 r9347  
    4141
    4242  this->init();
    43  
     43
    4444  if (root != NULL)
    4545    this->loadParams(root);
     
    5050  this->setClassID(CL_SPAWNING_POINT, "SpawningPoint");
    5151  PRINTF(0)("Created SpawningPoint\n");
    52  
     52
    5353  this->teamId = -1;
    5454  this->localTimer = 0.0f;
    55  
     55
    5656  this->toList( OM_DEAD_TICK );
    57  
     57
    5858  MessageManager::getInstance()->registerMessageHandler( MSGID_RESPAWN, respawnMessageHandler, NULL );
    59  
     59
    6060  this->setSynchronized( true );
    6161}
     
    9494  qe.entity = entity;
    9595  qe.respawnTime = this->localTimer + delay;
    96  
     96
    9797  queue.push_back( qe );
    9898}
     
    105105{
    106106  const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
    107  
     107
    108108  bool found = false;
    109  
     109
    110110  if ( !list )
    111111    return;
    112    
     112
    113113  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
    114114  {
     
    119119    }
    120120  }
    121  
     121
    122122  if ( !found )
    123123    return;
     
    128128  entity->setAbsCoor( this->getAbsCoor() );
    129129  entity->setAbsDir( this->getAbsDir() );
    130  
     130
    131131  //TODO set camera (not smooth)
    132  
     132
    133133  if ( State::getGameRules() )
    134134  {
    135135    (State::getGameRules())->registerSpawn( entity );
    136136  }
    137  
     137
    138138  entity->respawn();
    139139}
     
    157157      //spawn the player
    158158      this->spawn(it->entity);
    159      
     159
    160160      const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
    161  
     161
    162162      bool found = false;
    163  
     163
    164164      if ( !list )
    165165        return;
    166    
     166
    167167      for ( std::list<BaseObject*>::const_iterator it2 = list->begin(); it2 != list->end(); it2++ )
    168168      {
     
    173173        }
    174174      }
    175  
    176       if ( found && SharedNetworkData::getInstance()->isGameServer() )
     175
     176      if ( found && SharedNetworkData::getInstance()->isMasterServer() )
    177177        this->sendRespawnMessage( it->entity->getUniqueID() );
    178178
    179179      std::list<QueueEntry>::iterator delit = it;
    180180      it++;
    181      
     181
    182182      queue.erase( delit );
    183      
     183
    184184      continue;
    185185    }
    186    
     186
    187187    it++;
    188188  }
     
    204204{
    205205  byte * buf = new byte[2*INTSIZE];
    206  
     206
    207207  assert( Converter::intToByteArray( this->getUniqueID(), buf, INTSIZE ) == INTSIZE );
    208208  assert( Converter::intToByteArray( uniqueId, buf + INTSIZE, INTSIZE ) == INTSIZE );
    209  
     209
    210210  MessageManager::getInstance()->sendMessage( MSGID_RESPAWN, buf, 2*INTSIZE, RT_ALL_NOT_ME, 0, MP_HIGHBANDWIDTH );
    211211}
     
    213213bool SpawningPoint::respawnMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
    214214{
    215   if ( SharedNetworkData::getInstance()->isGameServer() )
     215  if ( SharedNetworkData::getInstance()->isMasterServer() )
    216216  {
    217217    PRINTF(2)("server received spawn message!\n");
    218218    return true;
    219219  }
    220    
     220
    221221  int spUniqueId;
    222222  int uniqueId;
    223  
     223
    224224  if ( dataLength != 2*INTSIZE )
    225225  {
     
    227227    return true;
    228228  }
    229  
     229
    230230  assert( Converter::byteArrayToInt( data, &spUniqueId ) == INTSIZE );
    231231  assert( Converter::byteArrayToInt( data+INTSIZE, &uniqueId ) == INTSIZE );
    232  
     232
    233233  PRINTF(0)("SPAWNMESSAGE %d\n", uniqueId);
    234  
     234
    235235  SpawningPoint * sp = NULL;
    236236  Playable      * playable = NULL;
    237  
     237
    238238  const std::list<BaseObject*> * list = ClassList::getList( CL_SPAWNING_POINT );
    239  
     239
    240240  if ( list )
    241241  {
     
    250250    }
    251251  }
    252  
     252
    253253  if ( !sp )
    254254  {
     
    256256    return false;
    257257  }
    258  
     258
    259259  list = ClassList::getList( CL_PLAYABLE );
    260  
     260
    261261  if ( list )
    262262  {
     
    270270    }
    271271  }
    272  
     272
    273273  if ( !playable )
    274274  {
     
    276276    return false;
    277277  }
    278  
     278
    279279  sp->spawn( playable );
    280  
     280
    281281  return true;
    282282}
Note: See TracChangeset for help on using the changeset viewer.