Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1360 for code


Ignore:
Timestamp:
May 22, 2008, 2:02:06 PM (16 years ago)
Author:
rgrieder
Message:

merged merge branch back to trunk

Location:
code/trunk/src
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/network/Client.cc

    r1293 r1360  
    120120    isConnected=client_connection.createConnection();
    121121    if(isConnected){
    122       COUT(4) << "sending connectrequest" << std::endl;
    123       client_connection.addPacket(pck_gen.generateConnectRequest());
    124       client_connection.sendPackets();
     122      COUT(3) << "sending connectrequest" << std::endl;
     123      if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets())
     124        COUT(1) << "could not create connection" << std::endl;
    125125    }else
    126126      COUT(1) << "could not create connection" << std::endl;
     
    229229  */
    230230  void Client::tick(float time){
     231//     COUT(3) << ".";
    231232    if(client_connection.isConnected() && isSynched_){
    232233      COUT(4) << "popping partial gamestate: " << std::endl;
     
    260261      if(!isSynched_)
    261262        isSynched_=true;
    262       client_connection.addPacket(pck_gen.acknowledgement(id));
     263      if(!client_connection.addPacket(pck_gen.acknowledgement(id)))
     264        return;
    263265        // we do this at the end of a tick
    264        if(!client_connection.sendPackets())
    265          COUT(2) << "Could not send acknowledgment" << std::endl;
     266      if(!client_connection.sendPackets())
     267        COUT(2) << "Could not send acknowledgment" << std::endl;
    266268    }
    267269  }
  • code/trunk/src/network/ClientInformation.cc

    r1293 r1360  
    4545namespace network
    4646{
     47  boost::recursive_mutex ClientInformation::mutex_;
     48 
    4749  ClientInformation::ClientInformation() {
    4850    gamestateID_=GAMESTATEID_INITIAL;
    4951    preve=0;
    5052    nexte=0;
    51     this->head=false;
     53    partialGamestateID_=GAMESTATEID_INITIAL-1;
     54    this->head_=false;
    5255    synched_=false;
    5356  }
     
    5760    preve=0;
    5861    nexte=0;
    59     this->head=head;
     62    partialGamestateID_=GAMESTATEID_INITIAL-1;
     63    this->head_=head;
    6064    synched_=false;
    6165  }
     
    8084
    8185  ClientInformation::~ClientInformation() {
     86    boost::recursive_mutex::scoped_lock lock(mutex_);
    8287    if(preve!=0)
    8388      preve->setNext(this->nexte);
     
    8792
    8893  ClientInformation *ClientInformation::next() {
     94    boost::recursive_mutex::scoped_lock lock(mutex_);
    8995    if(this!=0)
    9096      return this->nexte;
     
    9399  }
    94100  ClientInformation *ClientInformation::prev() {
     101    boost::recursive_mutex::scoped_lock lock(mutex_);
    95102    if(this!=0)
    96103      return this->preve;
     
    100107
    101108  bool ClientInformation::setPrev(ClientInformation *prev) {
    102     if(!head)
     109    boost::recursive_mutex::scoped_lock lock(mutex_);
     110    if(!head_)
    103111      this->preve = prev;
    104112    else
     
    108116
    109117  bool ClientInformation::setNext(ClientInformation *next) {
     118    boost::recursive_mutex::scoped_lock lock(mutex_);
    110119    this->nexte = next;
    111120    return true;
     
    113122
    114123  ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) {
     124    boost::recursive_mutex::scoped_lock lock(mutex_);
    115125    this->nexte->setPrev(ins);
    116126    ins->setNext(this->nexte);
     
    121131
    122132  ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
     133    boost::recursive_mutex::scoped_lock lock(mutex_);
     134    if(!this)
     135      return NULL;
    123136    this->prev()->setNext(ins);
    124137    ins->setPrev(this->preve);
     
    129142
    130143  void ClientInformation::setID(int clientID){
     144    boost::recursive_mutex::scoped_lock lock(mutex_);
    131145    clientID_ = clientID;
    132146  }
    133147
    134   void ClientInformation::setPeer(ENetPeer *peer){
     148  bool ClientInformation::setPeer(ENetPeer *peer){
     149    boost::recursive_mutex::scoped_lock lock(mutex_);
     150    if(!this)
     151      return false;
    135152    peer_ = peer;
    136   }
    137 
    138   void ClientInformation::setGamestateID(int id){
     153    return true;
     154  }
     155
     156  bool ClientInformation::setGamestateID(int id){
     157    boost::recursive_mutex::scoped_lock lock(mutex_);
     158    if(!this)
     159      return false;
    139160    gamestateID_=id;
     161    return true;
     162  }
     163 
     164  bool ClientInformation::setPartialGamestateID(int id){
     165    boost::recursive_mutex::scoped_lock lock(mutex_);
     166    if(!this)
     167      return false;
     168    partialGamestateID_=id;
     169    return true;
    140170  }
    141171
    142172  int ClientInformation::getID() {
    143     return clientID_;
     173    boost::recursive_mutex::scoped_lock lock(mutex_);
     174    if(!this)
     175      return CLIENTID_UNKNOWN;
     176    else
     177      return clientID_;
    144178  }
    145179
    146180  ENetPeer *ClientInformation::getPeer() {
    147     return peer_;
     181    boost::recursive_mutex::scoped_lock lock(mutex_);
     182    if(this)
     183      return peer_;
     184    else
     185      return NULL;
     186  }
     187 
     188  bool ClientInformation::getHead(){
     189    boost::recursive_mutex::scoped_lock lock(mutex_);
     190    return head_;
     191  }
     192 
     193  void ClientInformation::setHead(bool h){
     194    boost::recursive_mutex::scoped_lock lock(mutex_);
     195    head_=h;
     196  }
     197 
     198  int ClientInformation::getFailures(){
     199    boost::recursive_mutex::scoped_lock lock(mutex_);
     200    return failures_;
     201  }
     202  void ClientInformation::addFailure(){
     203    boost::recursive_mutex::scoped_lock lock(mutex_);
     204    failures_++;
     205  }
     206  void ClientInformation::resetFailures(){
     207    boost::recursive_mutex::scoped_lock lock(mutex_);
     208    failures_=0;
    148209  }
    149210
    150211  int ClientInformation::getGamestateID() {
    151     return gamestateID_;
     212    boost::recursive_mutex::scoped_lock lock(mutex_);
     213    if(this)
     214      return gamestateID_;
     215    else
     216      return -1;
     217  }
     218 
     219  int ClientInformation::getPartialGamestateID() {
     220    boost::recursive_mutex::scoped_lock lock(mutex_);
     221    if(this)
     222      return partialGamestateID_;
     223    else
     224      return -1;
    152225  }
    153226
    154227  ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
     228    boost::recursive_mutex::scoped_lock lock(mutex_);
     229    if(!this)
     230      return NULL;
    155231    ClientInformation *temp = this;
    156232    while(temp->next()!=0){
     
    163239
    164240  bool ClientInformation::removeClient(int clientID) {
     241    boost::recursive_mutex::scoped_lock lock(mutex_);
     242    if(!this || clientID==CLIENTID_UNKNOWN)
     243      return false;
    165244    ClientInformation *temp = this;
    166245    while(temp!=0 && temp->getID()!=clientID)
     
    173252
    174253  bool ClientInformation::removeClient(ENetPeer *peer) {
     254    boost::recursive_mutex::scoped_lock lock(mutex_);
     255    if(!this || !peer)
     256      return false;
    175257    ClientInformation *temp = this;
    176258    while(temp!=0){
    177       if(!temp->head)
     259      if(!temp->head_)
    178260        if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port)
    179261          break;
     
    193275  */
    194276  ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) {
    195     ClientInformation *temp = this;
    196     if (temp->head)
     277    boost::recursive_mutex::scoped_lock lock(mutex_);
     278    ClientInformation *temp = this;
     279    if (temp->head_)
    197280      temp=temp->next();
    198     //bugfix: temp to temp->next(), get last elem if not found, not segflt
    199     while(temp->next()!=0 && temp->getID()!=clientID){
     281    while(temp!=0 && temp->getID()!=clientID){
    200282      temp = temp->next();
    201283    }
     
    211293  */
    212294  ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
    213     ClientInformation *temp = this;
    214     //bugfix: temp to temp->next(), get last elem if not found, not segflt
    215     while(temp->next()!=0){
    216       if(temp->head){
     295    boost::recursive_mutex::scoped_lock lock(mutex_);
     296    ClientInformation *temp = this;
     297    while(temp!=0){
     298      if(temp->head_){
    217299        temp = temp->next();
    218300        continue;
     
    226308  }
    227309
    228   void ClientInformation::setSynched(bool s) {
     310  bool ClientInformation::setSynched(bool s) {
     311    boost::recursive_mutex::scoped_lock lock(mutex_);
     312    if(!this)
     313      return false;
    229314    synched_=s;
     315    return true;
    230316  }
    231317
    232318  bool ClientInformation::getSynched() {
    233     return synched_;
     319    boost::recursive_mutex::scoped_lock lock(mutex_);
     320    if(this)
     321      return synched_;
     322    else
     323      return false;
    234324  }
    235325
  • code/trunk/src/network/ClientInformation.h

    r1293 r1360  
    4444
    4545#include <enet/enet.h>
     46#include <boost/thread/recursive_mutex.hpp>
    4647
    4748#define GAMESTATEID_INITIAL -1
     49#define CLIENTID_UNKNOWN -2
    4850
    4951namespace network
     
    6264    ClientInformation *next();
    6365    ClientInformation *prev();
    64     bool setNext(ClientInformation *next);
    65     bool setPrev(ClientInformation *prev);
    66     ClientInformation *insertAfter(ClientInformation *ins);
    67     ClientInformation *insertBefore(ClientInformation *ins);
    6866    ClientInformation *insertBack(ClientInformation *ins);
    6967   
    7068    // set functions
    7169    void setID(int clientID);
    72     void setPeer(ENetPeer *peer);
    73     void setGamestateID(int id);
     70    bool setPeer(ENetPeer *peer);
     71    bool setGamestateID(int id);
     72    bool setPartialGamestateID(int id);
    7473    inline void setShipID(int id){ShipID_=id;}
    7574   
     
    7877    int getID();
    7978    int getGamestateID();
     79    int getPartialGamestateID();
    8080    ENetPeer *getPeer();
     81    bool getHead();
     82    void setHead(bool h);
    8183   
     84    int getFailures();
     85    void addFailure();
     86    void resetFailures();
    8287   
    8388    bool removeClient(int clientID);
     
    8893    ClientInformation *findClient(ENetAddress *address, bool look_backwards=false);
    8994
    90     void setSynched(bool s);
     95    bool setSynched(bool s);
    9196    bool getSynched();
    9297
    93     bool head;
    94     unsigned short failures_;
    9598
    96   private:
     99    private:
     100      bool setNext(ClientInformation *next);
     101      bool setPrev(ClientInformation *prev);
     102    ClientInformation *insertAfter(ClientInformation *ins);
     103    ClientInformation *insertBefore(ClientInformation *ins);
     104   
    97105    ClientInformation *preve;
    98106    ClientInformation *nexte;
     
    101109    int clientID_;
    102110    int gamestateID_;
     111    int partialGamestateID_;
    103112    int ShipID_;   // this is the unique objectID
    104113    bool synched_;
     114    bool head_;
     115    unsigned short failures_;
     116    static boost::recursive_mutex mutex_;
     117   
    105118  };
    106119
  • code/trunk/src/network/ConnectionManager.cc

    r1293 r1360  
    101101    ENetPacket *packet=getPacket(address);
    102102    ClientInformation *temp =head_->findClient(&address);
     103    if(!temp)
     104      return NULL;
    103105    clientID=temp->getID();
    104106    return packet;
     
    124126
    125127  bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) {
    126     if(enet_peer_send(peer, (enet_uint8)head_->findClient(&(peer->address))->getID() , packet)!=0)
     128    ClientInformation *temp = head_->findClient(&(peer->address));
     129    if(!temp)
     130      return false;
     131    if(enet_peer_send(peer, (enet_uint8)temp->getID() , packet)!=0)
    127132      return false;
    128133    return true;
     
    130135
    131136  bool ConnectionManager::addPacket(ENetPacket *packet, int clientID) {
    132     if(enet_peer_send(head_->findClient(clientID)->getPeer(), (enet_uint8)clientID, packet)!=0)
     137    ClientInformation *temp = head_->findClient(clientID);
     138    if(!temp)
     139      return false;
     140    if(enet_peer_send(temp->getPeer(), (enet_uint8)clientID, packet)!=0)
    133141      return false;
    134142    return true;
     
    185193          addClient(event);
    186194          //this is a workaround to ensure thread safety
    187           /*if(!addFakeConnectRequest(&event))
    188             COUT(3) << "Problem pushing fakeconnectRequest to queue" << std::endl;*/
    189195          COUT(5) << "Con.Man: connection event has occured" << std::endl;
    190196          break;
     
    195201          if(head_->findClient(&event->peer->address))
    196202            processData(event);
     203          else
     204            COUT(3) << "received a packet from a client we don't know" << std::endl;
    197205          break;
    198206        case ENET_EVENT_TYPE_DISCONNECT:
     
    200208          break;
    201209        case ENET_EVENT_TYPE_NONE:
     210          receiverThread_->yield();
    202211          break;
    203212      }
     
    233242      case ENET_EVENT_TYPE_DISCONNECT:
    234243        COUT(4) << "disconnecting all clients" << std::endl;
    235         delete head_->findClient(&(event.peer->address));
     244        if(head_->findClient(&(event.peer->address)))
     245          delete head_->findClient(&(event.peer->address));
    236246        //maybe needs bugfix: might also be a reason for the server to crash
    237247        temp = temp->next();
     
    259269  bool ConnectionManager::addClient(ENetEvent *event) {
    260270    ClientInformation *temp = head_->insertBack(new ClientInformation);
    261     if(temp->prev()->head) { //not good if you use anything else than insertBack
     271    if(!temp){
     272      COUT(2) << "Conn.Man. could not add client" << std::endl;
     273      return false;
     274    }
     275    if(temp->prev()->getHead()) { //not good if you use anything else than insertBack
    262276      temp->prev()->setID(0); //bugfix: not necessary but usefull
    263277      temp->setID(1);
     
    266280      temp->setID(temp->prev()->getID()+1);
    267281    temp->setPeer(event->peer);
    268     COUT(4) << "Con.Man: added client id: " << temp->getID() << std::endl;
     282    COUT(3) << "Con.Man: added client id: " << temp->getID() << std::endl;
    269283    return true;
    270284  }
     
    283297
    284298  void ConnectionManager::syncClassid(int clientID) {
    285     unsigned int network_id=0;
     299    unsigned int network_id=0, failures=0;
    286300    std::string classname;
    287301    orxonox::Identifier *id;
     
    293307      classname = id->getName();
    294308      network_id = id->getNetworkID();
     309      if(network_id==0)
     310        COUT(3) << "we got a null class id: " << id->getName() << std::endl;
    295311      COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl;
    296312
    297       addPacket(packet_gen.clid( (int)network_id, classname ), clientID);
    298 
     313      while(!addPacket(packet_gen.clid( (int)network_id, classname ), clientID) && failures < 10){
     314        failures++;
     315      }
    299316      ++it;
    300317    }
     
    305322  bool ConnectionManager::createClient(int clientID){
    306323    ClientInformation *temp = head_->findClient(clientID);
     324    if(!temp){
     325      COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
     326      return false;
     327    }
    307328    COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
    308329    syncClassid(temp->getID());
    309330    COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl;
    310331    // TODO: this is only a hack, untill we have a possibility to define default player-join actions
    311     createShip(temp);
    312     COUT(4) << "created spaceship" << std::endl;
     332    if(!createShip(temp))
     333      COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl;
     334    else
     335      COUT(3) << "created spaceship" << std::endl;
    313336    temp->setSynched(true);
    314     COUT(4) << "sending welcome" << std::endl;
     337    COUT(3) << "sending welcome" << std::endl;
    315338    sendWelcome(temp->getID(), temp->getShipID(), true);
    316339    return true;
     
    319342  bool ConnectionManager::removeClient(int clientID){
    320343    orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
     344    ClientInformation *client = head_->findClient(clientID);
     345    if(!client)
     346      return false;
    321347    while(it){
    322       if(it->objectID!=head_->findClient(clientID)->getShipID()){
     348      if(it->objectID!=client->getShipID()){
    323349        ++it;
    324350        continue;
     
    333359 
    334360  bool ConnectionManager::createShip(ClientInformation *client){
     361    if(!client)
     362      return false;
    335363    orxonox::Identifier* id = ID("SpaceShip");
    336364    if(!id){
     
    351379    no->setRotDamp(1.0);
    352380    no->setCamera("cam_"+client->getID());
     381    no->classID = id->getNetworkID();
    353382    no->create();
    354383   
     
    369398 
    370399  bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){
    371     addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID);
    372     sendPackets();
    373     return true;
     400    if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){
     401      sendPackets();
     402      return true;
     403    }else
     404      return false;
    374405  }
    375406 
  • code/trunk/src/network/GameStateClient.cc

    r1293 r1360  
    4747    COUT(5) << "this: " << this << std::endl;
    4848    last_diff_=0;
     49    last_gamestate_=GAMESTATEID_INITIAL-1;
    4950  }
    5051
     
    5657    printGameStateMap();
    5758    GameState *gs, *reference;
     59    /*if(compstate->id<last_gamestate_){
     60      // network packets got messed up
     61      COUT(3) << "received an obsolete gamestate" << std::endl;
     62      return false;
     63    }*/
    5864    if(compstate->diffed && compstate->base_id!=GAMESTATEID_INITIAL){
    5965      std::map<int, GameState*>::iterator it = gameStateMap.find(compstate->base_id);
     
    7783        COUT(4) << "adding decoded gs with id: " << gs->id << " diffed from: " << gs->base_id << std::endl;
    7884        last_diff_=gs->base_id;
     85        //last_gamestate_=gs->id;
    7986        return true;
    8087      }else{
     
    145152          if(!id){
    146153            COUT(4) << "We could not identify a new object; classid: " << sync.classID << std::endl;
    147             continue;
     154            return false;
    148155          }
    149156          Synchronisable *no = dynamic_cast<Synchronisable *>(id->fabricate());
    150157          COUT(4) << "loadsnapshot: classid: " << sync.classID << " objectID: " << sync.objectID << " length: " << sync.length << std::endl;
     158          if(!no){
     159            COUT(2) << "coudl not frabricate classid: " << sync.classID << " objectID: " << sync.objectID << " identifier: " << id << std::endl;
     160            break;
     161          }
    151162          no->objectID=sync.objectID;
    152163          no->classID=sync.classID;
    153164          // update data and create object/entity...
    154           if( !no->updateData(sync) )
     165          if( !no->updateData(sync) ){
    155166            COUT(1) << "We couldn't update the object: " << sync.objectID << std::endl;
     167            return false;
     168          }
    156169          if( !no->create() )
    157170            COUT(1) << "We couldn't manifest (create() ) the object: " << sync.objectID << std::endl;
     
    349362    COUT(4) << "using diffed gamestate" << std::endl;
    350363    GameState *t = decode(diff);
     364    if(!t)
     365      return NULL;
    351366    GameState *r = undiff(old, t);
    352367    delete[] t->data;
  • code/trunk/src/network/GameStateClient.h

    r1293 r1360  
    7171
    7272    int           last_diff_;
     73    int           last_gamestate_;
    7374    std::map<int, GameState *> gameStateMap;
    7475   
  • code/trunk/src/network/GameStateManager.cc

    r1293 r1360  
    117117        client = it->second;
    118118      GameState *server = reference;
    119       //head_->findClient(clientID)->setGamestateID(id);
    120119      COUT(3) << "client: " << client << " server: " << server << " gamestatemap: " << &gameStateMap << std::endl;
    121120      if(client)
     
    127126      GameState *server = reference;
    128127//       ackGameState(clientID, reference->id);
    129       //head_->findClient(clientID)->setGamestateID(id);
    130128      return encode(server);
    131129      // return an undiffed gamestate and set appropriate flags
     
    223221    orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
    224222    syncData sync;
     223    /*ClientInformation *client = head_->findClient(clientID);
     224    if(client)
     225      if(client->getPartialGamestateID()>state->id){
     226        COUT(3) << "we received an obsolete partial gamestate" << std::endl;
     227        return false;
     228      }
     229    else;*/
     230        //what should we do now ??
    225231    // loop as long as we have some data ;)
    226232    while(data < state->data+state->size){
     
    270276      ++it;
    271277    }
    272    
     278    //client->setPartialGamestateID(state->id);
    273279    return true;
    274280  }
     
    427433  void GameStateManager::ackGameState(int clientID, int gamestateID) {
    428434    ClientInformation *temp = head_->findClient(clientID);
     435    if(temp==0)
     436      return;
    429437    int curid = temp->getGamestateID();
     438    if(curid > gamestateID)
     439      // the network packets got messed up
     440      return;
    430441    COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
    431442    // decrease usage of gamestate and save it
    432443//     deleteUnusedGameState(curid);
    433444    //increase gamestateused
    434     --(gameStateUsed.find(curid)->second);
     445    if(curid!=GAMESTATEID_INITIAL)
     446      --(gameStateUsed.find(curid)->second);
    435447    ++(gameStateUsed.find(gamestateID)->second);
    436448    temp->setGamestateID(gamestateID);
     
    458470 
    459471  void GameStateManager::removeClient(ClientInformation* client){
    460     gameStateUsed[client->getGamestateID()]--;
     472    if(!client)
     473      return;
     474    if(client->getGamestateID()>=0)
     475      gameStateUsed[client->getGamestateID()]--;
    461476    head_->removeClient(client->getID());
    462477  }
  • code/trunk/src/network/NetworkPrereqs.h

    r1293 r1360  
    5656#endif
    5757
     58//-----------------------------------------------------------------------
     59// fixed width integers
     60//-----------------------------------------------------------------------
     61#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
     62typedef __int8            int8_t;
     63typedef __int16           int16_t;
     64typedef __int32           int32_t;
     65typedef __int64           int64_t;
     66typedef unsigned __int8   uint8_t;
     67typedef unsigned __int16  uint16_t;
     68typedef unsigned __int32  uint32_t;
     69typedef unsigned __int64  uint64_t;
     70#else
     71# include "inttypes.h"
     72#endif
    5873
    5974//-----------------------------------------------------------------------
  • code/trunk/src/network/PacketBuffer.cc

    r1293 r1360  
    4141namespace network
    4242{
    43   boost::mutex networkPacketBufferMutex;
     43   boost::recursive_mutex PacketBuffer::mutex_;
    4444
    4545  PacketBuffer::PacketBuffer() {
     
    5252
    5353  bool PacketBuffer::push(ENetEvent *ev) {
    54     boost::mutex::scoped_lock lock(networkPacketBufferMutex);
     54    boost::recursive_mutex::scoped_lock lock(mutex_);
    5555    //std::cout << "event size inside packetbuffer " << ev->packet->dataLength << std::endl;
    5656    //   if(closed)
     
    6161      last=first;
    6262      last->next=NULL;
    63       // change this!!!!!!!
     63      // change this!!!!!!!  ---- we are not doing stl so we won't change this
    6464      last->packet = ev->packet;
     65      last->address = ev->peer->address;
    6566      //last->address = ev->peer->address;
    6667    } else {
     
    7273      // save the packet to the new element
    7374      last->packet = ev->packet;
     75      last->address = ev->peer->address;
    7476      //last->address = ev->peer->address;
    7577    }
    76     // pseudo bugfix: added a return false statement for error handling
    77     if ( last->packet == ev->packet ) return true;
    78     return false;
     78    lock.unlock();
     79    return true;
    7980  }
    8081
     
    8283  //moving first pointer to next element
    8384  ENetPacket *PacketBuffer::pop() {
    84     boost::mutex::scoped_lock lock(networkPacketBufferMutex);
    85     //std::cout << "packetbuffer pop" << std::endl;
    86     if(first!=NULL /*&& !closed*/){
    87       QueueItem *temp = first;
    88       // get packet
    89       ENetPacket *pck=first->packet;
    90       // remove first element
    91       first = first->next;
    92       delete temp;
    93       //std::cout << "pop size of packet " << pck->dataLength << std::endl;
    94       return pck;
    95     } else{
    96       //std::cout << "nothing to return" << std::endl;
    97       return NULL;
    98     }
     85    ENetAddress address;
     86    return pop(address);
    9987  }
    10088
    10189  ENetPacket *PacketBuffer::pop(ENetAddress &address) {
    102     boost::mutex::scoped_lock lock(networkPacketBufferMutex);
     90    boost::recursive_mutex::scoped_lock lock(mutex_);
    10391    //std::cout << "packetbuffer pop(address)" << std::endl;
    10492    if(first!=NULL /*&& !closed*/){
     
    11098      first = first->next;
    11199      delete temp;
     100      lock.unlock();
    112101      //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl;
    113102      return pck;
    114103    } else{
     104      lock.unlock();
    115105      return NULL;
    116106    }
  • code/trunk/src/network/PacketBuffer.h

    r1293 r1360  
    4545
    4646#include <enet/enet.h>
     47#include <boost/thread/recursive_mutex.hpp>
    4748
    4849namespace network
     
    7677    QueueItem *last;
    7778    bool closed;
    78 
     79    static boost::recursive_mutex mutex_;
    7980  };
    8081
  • code/trunk/src/network/PacketDecoder.cc

    r1293 r1360  
    9191  }
    9292 
     93  bool PacketDecoder::testAndRemoveCRC(ENetPacket *packet){
     94    uint32_t submittetcrc;
     95    int dataLength = packet->dataLength;
     96    // get the submittet crc code
     97    memcpy(&submittetcrc, &packet->data[dataLength-sizeof(uint32_t)], sizeof(uint32_t));
     98    unsigned char *data = packet->data;
     99    uint32_t crc32=calcCRC(data, packet->dataLength-sizeof(uint32_t));
     100    // now append the crc to the packet data
     101    if(crc32==submittetcrc){
     102      dataLength-=sizeof(uint32_t);
     103      enet_packet_resize(packet, dataLength);
     104      return true;
     105    }
     106    COUT(3) << "gamestate crc: " << crc32 << std::endl;
     107    COUT(3) << "submitted crc: " << submittetcrc << std::endl;
     108    return false;
     109  }
     110 
    93111  // ATTENTION: TODO watch, that arguments we pass over to the processFunction gets deleted in THE PROCESSXXX function
    94112
     
    111129    void *data = (void *)new unsigned char[length];
    112130    memcpy(data, (void *)(packet->data+2*sizeof(int)), length);
     131    enet_packet_destroy( packet );
    113132    return true;
    114133  }
     
    156175  void PacketDecoder::gstate( ENetPacket* packet, int clientID )
    157176  {
     177    if(!testAndRemoveCRC(packet)){
     178      COUT(3) << "crc test of gamestate failed - dropping packet" << std::endl;
     179      return;
     180    }
    158181    GameStateCompressed* currentState = NULL;
    159182    currentState = new GameStateCompressed;
  • code/trunk/src/network/PacketGenerator.cc

    r1293 r1360  
    4646namespace network
    4747{
     48  void calcCRCBit(uint32_t &crc32, int bit){
     49    int hbit;
     50 
     51    hbit=(crc32 & 0x80000000) ? 1 : 0;
     52    if (hbit != bit)
     53      crc32=(crc32<<1) ^ NETWORK_CRC32POLY;
     54    else
     55      crc32=crc32<<1;
     56  }
     57 
     58  uint32_t calcCRC(unsigned char *data, unsigned int dataLength){
     59    uint32_t crc32=0;
     60    for(unsigned int i=0; i<dataLength; i++){
     61      calcCRCBit(crc32, (data[i]&0x1)>>0); // 1st bit
     62      calcCRCBit(crc32, (data[i]&0x2)>>1); // 2nd bit
     63      calcCRCBit(crc32, (data[i]&0x3)>>2); // 3rd bit
     64      calcCRCBit(crc32, (data[i]&0x4)>>3); // 4th bit
     65      calcCRCBit(crc32, (data[i]&0x5)>>4); // 5th bit
     66      calcCRCBit(crc32, (data[i]&0x6)>>5); // 6th bit
     67      calcCRCBit(crc32, (data[i]&0x7)>>6); // 7th bit
     68      calcCRCBit(crc32, (data[i]&0x8)>>7); // 8th bit
     69    }
     70    return crc32;
     71  }
     72 
    4873  PacketGenerator::PacketGenerator() { }
    4974
     
    6489  ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE )
    6590  {
    66     void *stream = new char[dataLength + 2*sizeof(int)];
     91    unsigned char *stream = new unsigned char[dataLength + 2*sizeof(int)];
    6792    if(!stream)
    6893      return NULL;
     
    135160    memcpy( (void*)(data+5*sizeof( int ) + sizeof(bool)), (const void*)&(states->complete), sizeof(bool) );
    136161    memcpy( (void*)(data+5*sizeof( int ) + 2*sizeof(bool)), (const void*)states->data, states->compsize );
     162   
    137163    //create an enet packet with the generated bytestream
    138164    COUT(4) << "PacketGenerator generating totalLen " << totalLen << std::endl;
    139165    ENetPacket *packet = enet_packet_create( data , totalLen, reliable );
    140166    delete[] data;
     167    if(!addCRC(packet))
     168      COUT(3) << "could not add crc to gamestate packet" << std::endl;
    141169    return packet;
    142170  }
     
    174202    return packet;
    175203  }
     204 
     205 
     206  bool PacketGenerator::addCRC( ENetPacket *packet){
     207    unsigned char *data = packet->data;
     208    uint32_t crc32=calcCRC(data, packet->dataLength);
     209    // now append the crc to the packet data
     210    int oldlength = packet->dataLength;
     211    if(enet_packet_resize(packet, packet->dataLength+sizeof(uint32_t))==0){
     212      memcpy(&packet->data[oldlength], &crc32, sizeof(uint32_t));
     213      return true;
     214    }else{
     215      COUT(3) << "could not add crc to gamestate" << std::endl;
     216      return false;
     217    }
     218  }
    176219
    177220}
  • code/trunk/src/network/PacketManager.h

    r1293 r1360  
    3838
    3939#define CLIENTID_CLIENT -1
     40#define NETWORK_CRC32POLY 0x04C11DB7 /* CRC-32 Polynom */
    4041
    4142//enum netowk generally used to set the type ID of a packet
     
    4849  *
    4950  */
     51  //void calcCRC(uint32_t &crc32, int bit);
     52  uint32_t calcCRC(unsigned char *data, unsigned int dataLength);
     53 
    5054  class PacketGenerator
    5155  {
     
    5357    PacketGenerator();
    5458    //call one of this functions out of an instance of PacketGenerator to create a packet
    55     ENetPacket* acknowledgement( int state, int reliable = ENET_PACKET_FLAG_RELIABLE );
     59    ENetPacket* acknowledgement( int state, int reliable = 0 ); // we do not want reliability
    5660    ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE );
    5761    ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE );
    5862    ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE );
    5963    ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE );
    60     ENetPacket* gstate( GameStateCompressed *states, int reliable = ENET_PACKET_FLAG_RELIABLE );
     64    ENetPacket* gstate( GameStateCompressed *states, int reliable = 0 ); // we do not want reliability of gamestates
    6165    ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE );
    6266    ENetPacket* generateWelcome( int clientID,int shipID, bool allowed, int reliable = ENET_PACKET_FLAG_RELIABLE );
    6367    ENetPacket* generateConnectRequest( int reliable = ENET_PACKET_FLAG_RELIABLE );
    6468  private:
     69    bool addCRC( ENetPacket *packet);
    6570  };
    6671
     
    8489
    8590  private:
    86 
     91    bool testAndRemoveCRC(ENetPacket *packet);
    8792
    8893
  • code/trunk/src/network/Server.cc

    r1293 r1360  
    117117    ENetPacket *packet = packet_gen.chatMessage(msg.c_str());
    118118    //std::cout <<"adding packets" << std::endl;
    119     connection->addPacketAll(packet);
     119    if(connection->addPacketAll(packet))
    120120    //std::cout <<"added packets" << std::endl;
    121     return connection->sendPackets();
     121      return connection->sendPackets();
     122    else
     123      return false;
    122124  }
    123125
     
    147149    processQueue();
    148150    updateGamestate();
    149 
    150151//     usleep(500000); // TODO remove
    151152    return;
     
    162163      //clientID here is a reference to grab clientID from ClientInformation
    163164      packet = connection->getPacket(clientID);
     165      if(!packet)
     166        continue;
    164167      //if statement to catch case that packetbuffer is empty
    165168      if( !elaborate(packet, clientID) )
    166         COUT(4) << "Server: PacketBuffer empty" << std::endl;
     169        COUT(3) << "Server: could not elaborate" << std::endl;
    167170    }
    168171  }
     
    189192    bool added=false;
    190193    while(temp != NULL){
    191       if(temp->head){
     194      if(temp->getHead()){
    192195        temp=temp->next();
    193196        //think this works without continue
     
    211214      //std::cout << "adding gamestate" << std::endl;
    212215      if ( !(connection->addPacket(packet_gen.gstate(gs), cid)) ){
    213         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->failures_ << std::endl;
    214         temp->failures_++;
    215         if(temp->failures_ > 20 )
     216        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
     217        temp->addFailure();
     218        if(temp->getFailures() > 20 )
    216219          disconnectClient(temp);
    217220      //std::cout << "added gamestate" << std::endl;
     
    238241 
    239242  bool Server::processConnectRequest( connectRequest *con, int clientID ){
    240     COUT(4) << "processing connectRequest " << std::endl;
     243    COUT(3) << "processing connectRequest " << std::endl;
    241244    //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID);
    242245    connection->createClient(clientID);
     
    250253        COUT(3) << "Could not push gamestate\t\t\t\t=====" << std::endl;
    251254    else
    252         clients->findClient(clientID)->failures_=0;
     255      if(clients->findClient(clientID))
     256        clients->findClient(clientID)->resetFailures();
    253257  }
    254258
    255259  void Server::disconnectClient(int clientID){
    256260    ClientInformation *client = clients->findClient(clientID);
    257     disconnectClient(client);
     261    if(client)
     262      disconnectClient(client);
    258263  }
    259264  void Server::disconnectClient( ClientInformation *client){
  • code/trunk/src/network/Synchronisable.cc

    r1293 r1360  
    153153  syncData Synchronisable::getData(unsigned char *mem){
    154154    //std::cout << "inside getData" << std::endl;
    155     classID=this->getIdentifier()->getNetworkID();
     155    if(classID==0)
     156      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
     157    this->classID=this->getIdentifier()->getNetworkID();
    156158    std::list<synchronisableVariable *>::iterator i;
    157159    syncData retVal;
  • code/trunk/src/network/diffTest.cc

    r1293 r1360  
    466466bool addClientTest( ENetEvent* event, ClientInformation*& head ) {
    467467  ClientInformation *temp = head->insertBack(new ClientInformation);
     468  if(!temp)
     469    return false;
    468470  if(temp->prev()->head) {
    469471    temp->prev()->setID(0);
     
    475477  std::cout << "added client id: " << temp->getID() << std::endl;
    476478
    477   temp->setSynched(true);
    478   return true;
     479  return temp->setSynched(true);
    479480}
    480481
    481482void printClientInformationBox( ClientInformation* box ) {
     483  if(!box)
     484    return;
    482485  std::cout << "ClientList: id: " << box->getID() << "\t";
    483486  std::cout << "g_id: " << box->getGamestateID() << " \t";
  • code/trunk/src/orxonox/OrxonoxPlatform.h

    r1293 r1360  
    196196//typedef unsigned short uint16;
    197197//typedef unsigned char uint8;
     198// proper approach
    198199
    199200#ifdef ORXONOX_DOUBLE_PRECISION
  • code/trunk/src/orxonox/objects/Projectile.cc

    r1293 r1360  
    6363
    6464        this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
     65        this->classID = this->getIdentifier()->getNetworkID(); // TODO: remove this hack
     66//        COUT(3) << this->classID << std::endl;
    6567    }
    6668
  • code/trunk/src/orxonox/objects/SpaceShip.cc

    r1349 r1360  
    6262    SpaceShip* SpaceShip::instance_s;
    6363
     64    SpaceShip *SpaceShip::getLocalShip(){
     65      Iterator<SpaceShip> it;
     66      for(it = ObjectList<SpaceShip>::start(); it; ++it){
     67        if((it)->server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==it->objectID ) )
     68          return *it;
     69      }
     70      return NULL;
     71    }
     72   
    6473    SpaceShip::SpaceShip() :
    6574      //testvector_(0,0,0),
     
    145154    void SpaceShip::init()
    146155    {
    147     if ((server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==objectID ) ))
    148     {
    149           if (!setMouseEventCallback_)
    150           {
    151               InputManager::addMouseHandler(this, "SpaceShip");
    152               setMouseEventCallback_ = true;
    153           }
    154     }
     156        if ((server_ || ( network::Client::getSingleton() && network::Client::getSingleton()->getShipID()==objectID ) ))
     157        {
     158              if (!setMouseEventCallback_)
     159              {
     160                  InputManager::addMouseHandler(this, "SpaceShip");
     161                  //InputManager::enableMouseHandler("SpaceShip");
     162                  setMouseEventCallback_ = true;
     163              }
     164        }
    155165
    156166        // START CREATING THRUSTER
     
    394404        if (this->bLMousePressed_ && this->timeToReload_ <= 0)
    395405        {
     406         
    396407            Projectile *p = new Projectile(this);
     408           
    397409            p->setBacksync(true);
    398410            this->timeToReload_ = this->reloadTime_;
  • code/trunk/src/orxonox/objects/SpaceShip.h

    r1349 r1360  
    4444    {
    4545        public:
     46         
     47            static SpaceShip *getLocalShip();
     48           
    4649            SpaceShip();
    4750            ~SpaceShip();
  • code/trunk/src/orxonox/objects/WorldEntity.cc

    r1293 r1360  
    138138      registerVar( (void*) &(this->getOrientation().z), sizeof(this->getOrientation().z), network::DATA, 0x3);
    139139      // register velocity_
    140 //       registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA, 0x3);
    141 //       registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA, 0x3);
    142 //       registerVar( (void*) &(this->getVelocity().z), sizeof(this->getVelocity().z), network::DATA, 0x3);
    143 //       // register rotationAxis/rate
    144 //       registerVar( (void*) &(this->getRotationRate()), sizeof(this->getRotationRate()), network::DATA, 0x3);
    145 //       registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA, 0x3);
    146 //       registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA, 0x3);
    147 //       registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA, 0x3);
     140      registerVar( (void*) &(this->getVelocity().x), sizeof(this->getVelocity().x), network::DATA, 0x3);
     141      registerVar( (void*) &(this->getVelocity().y), sizeof(this->getVelocity().y), network::DATA, 0x3);
     142      registerVar( (void*) &(this->getVelocity().z), sizeof(this->getVelocity().z), network::DATA, 0x3);
     143      // register rotationAxis/rate
     144      registerVar( (void*) &(this->getRotationRate()), sizeof(this->getRotationRate()), network::DATA, 0x3);
     145      registerVar( (void*) &(this->getRotationAxis().x), sizeof(this->getRotationAxis().x), network::DATA, 0x3);
     146      registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA, 0x3);
     147      registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA, 0x3);
    148148      // register scale of node
    149149      registerVar( (void*) &(this->getScale().x), sizeof(this->getScale().x), network::DATA, 0x3);
     
    152152      //register staticity
    153153      registerVar( (void*) &(this->bStatic_), sizeof(this->bStatic_), network::DATA, 0x3);
    154       //register acceleration
    155       // register velocity_
    156 //       registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3);
    157 //       registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3);
    158 //       registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3);
     154      //register acceleration & momentum
     155      registerVar( (void*) &(this->getAcceleration().x), sizeof(this->getAcceleration().x), network::DATA, 0x3);
     156      registerVar( (void*) &(this->getAcceleration().y), sizeof(this->getAcceleration().y), network::DATA, 0x3);
     157      registerVar( (void*) &(this->getAcceleration().z), sizeof(this->getAcceleration().z), network::DATA, 0x3);
     158      registerVar( (void*) &(this->getMomentum()), sizeof(this->getMomentum()), network::DATA);
    159159    }
    160160
Note: See TracChangeset for help on using the changeset viewer.