Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8327


Ignore:
Timestamp:
Apr 25, 2011, 8:22:36 PM (14 years ago)
Author:
scheusso
Message:

merging network6 into trunk

Location:
code/trunk
Files:
4 deleted
38 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/Thread.cc

    r7284 r8327  
    2626 *
    2727 */
     28
     29#if defined(ORXONOX_PLATFORM_WINDOWS)
     30  #include "ThreadWin.cc"
     31#elif defined(ORXONOX_PLATFORM_UNIX)
     32
    2833
    2934#include "Thread.h"
     
    9196        while( !stopThread )
    9297        {
    93             //this->executorMutex_->lock();
     98            this->executorMutex_->lock();
    9499            ExecutorPtr executor = this->executor_;
    95             //this->executorMutex_->unlock();
     100            this->executorMutex_->unlock();
    96101            if( executor )
    97102            {
     
    108113                this->workerThread_->yield();
    109114            }
    110             //this->stopThreadMutex_->lock();
     115            this->stopThreadMutex_->lock();
    111116            stopThread = this->stopThread_;
    112             //this->stopThreadMutex_->unlock();
     117            this->stopThreadMutex_->unlock();
    113118        }
    114119    }
     
    127132    }
    128133}
     134
     135#endif
  • code/trunk/src/libraries/network/CMakeLists.txt

    r7801 r8327  
    2222  Client.cc
    2323  ClientConnection.cc
    24   ClientInformation.cc
    2524  ClientConnectionListener.cc
    2625  Connection.cc
     
    5049  ClientConnection.h
    5150  ClientConnectionListener.h
    52   ClientInformation.h
    5351  Connection.h
    5452  FunctionCall.h
  • code/trunk/src/libraries/network/Client.cc

    r7801 r8327  
    155155        COUT(4) << "popping partial gamestate: " << std::endl;
    156156//         packet::Gamestate *gs = GamestateClient::getGamestate();
    157         GamestateManager::update();
    158         std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
    159         std::vector<packet::Gamestate*>::iterator it;
    160         for( it = gamestates.begin(); it != gamestates.end(); ++it )
     157        if( GamestateManager::update() )
    161158        {
    162           (*it)->send( static_cast<Host*>(this) );
     159          std::vector<packet::Gamestate*> gamestates = GamestateManager::getGamestates();
     160          std::vector<packet::Gamestate*>::iterator it;
     161          for( it = gamestates.begin(); it != gamestates.end(); ++it )
     162          {
     163            (*it)->send( static_cast<Host*>(this) );
     164          }
    163165        }
    164166        //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
     
    207209    if( packet->isReliable() )
    208210    {
    209       if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
     211      if( this->getLastReceivedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
    210212        packet->process(static_cast<Host*>(this));
    211213      else
  • code/trunk/src/libraries/network/ClientConnection.cc

    r7801 r8327  
    4242
    4343  ClientConnection::ClientConnection():
     44    Connection(NETWORK_PEER_ID_SERVER),
    4445    established_(false),
    4546    server_(NULL)
     
    103104      if( enet_host_service(this->host_, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && event.type == ENET_EVENT_TYPE_CONNECT )
    104105      {
     106        // manually add server to list of peers
     107        /*incomingEvent inEvent = */Connection::preprocessConnectEvent(event);
     108//         addPeer(inEvent.peerID);
     109        // start communication thread
    105110        this->established_=true;
    106111        Connection::startCommunicationThread();
     
    118123      return true;
    119124    this->established_ = false;
     125   
     126    // stop communication thread and disconnect server
    120127    Connection::stopCommunicationThread();
    121128    enet_peer_disconnect(this->server_, 0);
     
    148155    assert( this->server_ );
    149156    assert( packet );
    150     return Connection::addPacket( packet, this->server_, channelID );
     157//     return Connection::addPacket( packet, NETWORK_PEER_ID_SERVER, channelID );
     158    // HACK: actually there should be a way to do this using addPacket and the correct peerID
     159    return Connection::broadcastPacket(packet, channelID);
    151160  }
    152161
    153   void ClientConnection::addPeer(ENetEvent* event)
     162  void ClientConnection::addPeer(uint32_t peerID)
    154163  {
    155164    assert(0);
    156165  }
    157   void ClientConnection::removePeer(ENetEvent* event)
     166  void ClientConnection::removePeer(uint32_t peerID)
    158167  {
    159168    this->established_=false;
  • code/trunk/src/libraries/network/ClientConnection.h

    r7801 r8327  
    5757    uint32_t getRTT();
    5858  private:
    59     virtual void addPeer(ENetEvent* event);
    60     virtual void removePeer(ENetEvent* event);
     59    virtual void addPeer(uint32_t peerID);
     60    virtual void removePeer(uint32_t peerID);
    6161
    6262    bool disconnectConnection();
  • code/trunk/src/libraries/network/ClientConnectionListener.cc

    r6417 r8327  
    3131#include "core/CoreIncludes.h"
    3232#include "core/GameMode.h"
    33 #include "ClientInformation.h"
     33// #include "ClientInformation.h"
    3434
    3535namespace orxonox
     
    5252    }
    5353
    54     void ClientConnectionListener::getConnectedClients()
    55     {
    56         ClientInformation* client = ClientInformation::getBegin();
    57         while (client)
    58         {
    59             this->clientConnected(client->getID());
    60             client = client->next();
    61         }
    62     }
     54//     void ClientConnectionListener::getConnectedClients()
     55//     {
     56//         ClientInformation* client = ClientInformation::getBegin();
     57//         while (client)
     58//         {
     59//             this->clientConnected(client->getID());
     60//             client = client->next();
     61//         }
     62//     }
    6363}
    6464
  • code/trunk/src/libraries/network/ClientConnectionListener.h

    r6417 r8327  
    4848
    4949        protected:
    50             void getConnectedClients();
     50//             void getConnectedClients();
    5151    };
    5252}
  • code/trunk/src/libraries/network/Connection.cc

    r7801 r8327  
    3838
    3939#include "packet/Packet.h"
     40#include <util/Sleep.h>
    4041
    4142namespace orxonox
    4243{
    43   const boost::posix_time::millisec NETWORK_COMMUNICATION_THREAD_WAIT_TIME(20);
    44 
    45   Connection::Connection():
    46     host_(0), bCommunicationThreadRunning_(false)
     44  const boost::posix_time::millisec NETWORK_COMMUNICATION_THREAD_WAIT_TIME(200);
     45  const unsigned int                NETWORK_DISCONNECT_TIMEOUT = 500;
     46
     47  Connection::Connection(uint32_t firstPeerID):
     48    host_(0), bCommunicationThreadRunning_(false), nextPeerID_(firstPeerID)
    4749  {
    4850    enet_initialize();
     
    5052    this->incomingEventsMutex_ = new boost::mutex;
    5153    this->outgoingEventsMutex_ = new boost::mutex;
     54//     this->overallMutex_ = new boost::mutex;
    5255  }
    5356
     
    7578  }
    7679
    77 
    78 //   int Connection::service(ENetEvent* event) {
    79 //     return enet_host_service( this->host_, event, NETWORK_WAIT_TIMEOUT );
    80 //   }
    81 
    82   void Connection::disconnectPeer(ENetPeer *peer)
    83   {
    84     assert(peer);
    85     outgoingEvent outEvent = { peer, outgoingEventType::disconnectPeer, (ENetPacket*)10, 15 };
     80  void Connection::disconnectPeer(uint32_t peerID)
     81  {
     82//     this->overallMutex_->lock();
     83    outgoingEvent outEvent = { peerID, outgoingEventType::disconnectPeer, 0, 0 };
    8684   
    8785    this->outgoingEventsMutex_->lock();
    8886    this->outgoingEvents_.push_back(outEvent);
    8987    this->outgoingEventsMutex_->unlock();
    90   }
    91 
    92   void Connection::addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID)
    93   {
    94     assert(peer);
    95     outgoingEvent outEvent = { peer, outgoingEventType::sendPacket, packet, channelID };
     88//     this->overallMutex_->unlock();
     89  }
     90 
     91  void Connection::disconnectPeers()
     92  {
     93    outgoingEvent outEvent = { 0, outgoingEventType::disconnectPeers, 0, 0 };
    9694   
    9795    this->outgoingEventsMutex_->lock();
     
    9997    this->outgoingEventsMutex_->unlock();
    10098  }
     99
     100  void Connection::addPacket(ENetPacket* packet, uint32_t peerID, uint8_t channelID)
     101  {
     102//     this->overallMutex_->lock();
     103    outgoingEvent outEvent = { peerID, outgoingEventType::sendPacket, packet, channelID };
     104   
     105    this->outgoingEventsMutex_->lock();
     106    this->outgoingEvents_.push_back(outEvent);
     107    this->outgoingEventsMutex_->unlock();
     108//     this->overallMutex_->unlock();
     109  }
    101110 
    102111  void Connection::broadcastPacket(ENetPacket* packet, uint8_t channelID)
    103112  {
    104     outgoingEvent outEvent = { (ENetPeer*)15, outgoingEventType::broadcastPacket, packet, channelID };
     113//     this->overallMutex_->lock();
     114    outgoingEvent outEvent = { 0, outgoingEventType::broadcastPacket, packet, channelID };
    105115   
    106116    this->outgoingEventsMutex_->lock();
    107117    this->outgoingEvents_.push_back(outEvent);
    108118    this->outgoingEventsMutex_->unlock();
     119//     this->overallMutex_->unlock();
    109120  }
    110121
     
    114125    ENetEvent event;
    115126   
     127//     this->overallMutex_->lock();
    116128    while( bCommunicationThreadRunning_ )
    117129    {
     
    119131      while( enet_host_check_events( this->host_, &event ) > 0 )
    120132      {
    121 //         COUT(0) << "incoming event" << endl;
    122         // received an event
    123         this->incomingEventsMutex_->lock();
    124         this->incomingEvents_.push_back(event);
    125         this->incomingEventsMutex_->unlock();
    126       }
     133        processIncomingEvent(event);
     134      }
     135     
     136//       this->overallMutex_->unlock();
     137      msleep(1);
     138//       this->overallMutex_->lock();
    127139     
    128140      // Send all waiting outgoing packets
     
    138150        this->outgoingEventsMutex_->unlock();
    139151       
    140         switch( outEvent.type )
    141         {
    142           case outgoingEventType::sendPacket:
    143             enet_peer_send( outEvent.peer, outEvent.channelID, outEvent.packet );
    144             break;
    145           case outgoingEventType::disconnectPeer:
    146             enet_peer_disconnect(outEvent.peer, 0);
    147             break;
    148           case outgoingEventType::broadcastPacket:
    149             enet_host_broadcast( this->host_, outEvent.channelID, outEvent.packet );
    150             break;
    151           default:
    152             assert(0);
    153         }
     152        processOutgoingEvent(outEvent);
     153       
    154154        this->outgoingEventsMutex_->lock();
    155155        outgoingEventsCount = this->outgoingEvents_.size();
     
    160160      if( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
    161161      {
    162 //         COUT(0) << "incoming event after wait" << endl;
    163         //received an event
    164         this->incomingEventsMutex_->lock();
    165         this->incomingEvents_.push_back(event);
    166         this->incomingEventsMutex_->unlock();
     162        processIncomingEvent(event);
     163      }
     164    }
     165//     this->overallMutex_->unlock();
     166  }
     167 
     168  void Connection::processIncomingEvent(ENetEvent& event)
     169  {
     170    incomingEvent inEvent;
     171    // preprocess event
     172    switch( event.type )
     173    {
     174      case ENET_EVENT_TYPE_CONNECT:
     175        inEvent = preprocessConnectEvent(event);
     176        break;
     177      case ENET_EVENT_TYPE_RECEIVE:
     178        inEvent = preprocessReceiveEvent(event);
     179        break;
     180      case ENET_EVENT_TYPE_DISCONNECT:
     181        inEvent = preprocessDisconnectEvent(event);
     182        break;
     183      case ENET_EVENT_TYPE_NONE:
     184      default:
     185        return;
     186    }
     187   
     188    // pushing event to queue
     189    this->incomingEventsMutex_->lock();
     190    this->incomingEvents_.push_back(inEvent);
     191    this->incomingEventsMutex_->unlock();
     192  }
     193 
     194  void Connection::processOutgoingEvent(outgoingEvent& event)
     195  {
     196    ENetPeer* peer;
     197    switch( event.type )
     198    {
     199      case outgoingEventType::sendPacket:
     200        // check whether the peer is still/already in the peer list
     201        if( this->peerMap_.find(event.peerID) != this->peerMap_.end() )
     202        {
     203          peer = this->peerMap_[event.peerID];
     204          enet_peer_send( peer, event.channelID, event.packet );
     205        }
     206        else
     207        {
     208          // peer probably already disconnected so just discard packet
     209          assert(event.peerID<this->nextPeerID_);
     210          enet_packet_destroy(event.packet);
     211        }
     212        break;
     213      case outgoingEventType::disconnectPeer:
     214        if( this->peerMap_.find(event.peerID) != this->peerMap_.end() )
     215        {
     216          peer = this->peerMap_[event.peerID];
     217          enet_peer_disconnect(peer, 0);
     218        }
     219        else
     220        {
     221          // peer probably already disconnected so just discard disconnect event
     222          assert(event.peerID<this->nextPeerID_);
     223        }
     224        break;
     225      case outgoingEventType::disconnectPeers:
     226        disconnectPeersInternal();
     227        break;
     228      case outgoingEventType::broadcastPacket:
     229        enet_host_broadcast( this->host_, event.channelID, event.packet );
     230        break;
     231      default:
     232        assert(0);
     233    }
     234  }
     235
     236
     237  void Connection::disconnectPeersInternal()
     238  {
     239    std::map<uint32_t, ENetPeer*>::iterator it;
     240    for( it=this->peerMap_.begin(); it!=this->peerMap_.end(); ++it )
     241    {
     242      enet_peer_disconnect(it->second, 0);
     243    }
     244    uint32_t iterations = NETWORK_DISCONNECT_TIMEOUT/NETWORK_WAIT_TIMEOUT;
     245    uint32_t i = 0;
     246    while( this->peerMap_.size() && i++ < iterations )
     247    {
     248      ENetEvent event;
     249      if( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
     250      {
     251        processIncomingEvent(event);
    167252      }
    168253    }
     
    171256  void Connection::processQueue()
    172257  {
    173     ENetEvent event;
     258    incomingEvent inEvent;
    174259
    175260    this->incomingEventsMutex_->lock();
     
    178263    while( incomingEventsCount > 0 )
    179264    {
    180       packet::Packet* p;
     265      // pop event from queue
    181266      this->incomingEventsMutex_->lock();
    182       event = this->incomingEvents_.front();
     267      inEvent = this->incomingEvents_.front();
    183268      this->incomingEvents_.pop_front();
    184269      this->incomingEventsMutex_->unlock();
    185270     
    186       switch(event.type)
    187       {
    188         // log handling ================
    189         case ENET_EVENT_TYPE_CONNECT:
    190           addPeer( &event );
     271      // process event
     272      switch( inEvent.type )
     273      {
     274        case incomingEventType::peerConnect:
     275          addPeer(inEvent.peerID);
    191276          break;
    192         case ENET_EVENT_TYPE_DISCONNECT:
    193           removePeer( &event );
     277        case incomingEventType::peerDisconnect:
     278          removePeer(inEvent.peerID);
    194279          break;
    195         case ENET_EVENT_TYPE_RECEIVE:
    196 //           COUT(0) << "ENET_EVENT_TYPE_RECEIVE" << endl;
    197           p = createPacket( &event );
    198           processPacket(p);
     280        case incomingEventType::receivePacket:
     281          processPacket(inEvent.packet);
    199282          break;
    200         case ENET_EVENT_TYPE_NONE:
     283        default:
    201284          break;
    202285      }
    203286     
     287      // check whether there are still events in the queue
    204288      this->incomingEventsMutex_->lock();
    205289      incomingEventsCount = this->incomingEvents_.size();
     
    207291    }
    208292  }
    209 
    210   packet::Packet* Connection::createPacket(ENetEvent* event)
    211   {
    212     packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer);
    213     return p;
    214 //     return p->process();
    215   }
     293 
     294  void Connection::waitOutgoingQueue()
     295  {
     296    uint32_t outgoingEventsCount;
     297    this->outgoingEventsMutex_->lock();
     298    outgoingEventsCount = this->outgoingEvents_.size();
     299    this->outgoingEventsMutex_->unlock();
     300    while( outgoingEventsCount )
     301    {
     302      msleep(1);
     303      this->outgoingEventsMutex_->lock();
     304      outgoingEventsCount = this->outgoingEvents_.size();
     305      this->outgoingEventsMutex_->unlock();
     306    }
     307  }
     308
     309
     310  incomingEvent Connection::preprocessConnectEvent(ENetEvent& event)
     311  {
     312    // make sure this peer doesn't exist
     313    assert( this->peerMap_.find(this->nextPeerID_) == this->peerMap_.end() );
     314    assert( this->peerIDMap_.find(event.peer) == this->peerIDMap_.end() );
     315   
     316    // give peer a new id and increase peerID for next peer
     317    uint32_t peerID = this->nextPeerID_;
     318    ++this->nextPeerID_;
     319   
     320    // add peer/peerID into peerMap_ and peerIDMap_
     321    this->peerMap_[peerID] = event.peer;
     322    this->peerIDMap_[event.peer] = peerID;
     323   
     324    // create new peerEvent and return it
     325    incomingEvent inEvent = { peerID, incomingEventType::peerConnect, 0 };
     326    return inEvent;
     327  }
     328 
     329  incomingEvent Connection::preprocessDisconnectEvent(ENetEvent& event)
     330  {
     331    // assert that the peer exists and get peerID
     332    assert( this->peerIDMap_.find(event.peer) != this->peerIDMap_.end() );
     333    uint32_t peerID = this->peerIDMap_[event.peer];
     334   
     335    // remove peer/peerID from maps
     336    this->peerIDMap_.erase(this->peerIDMap_.find(event.peer));
     337    this->peerMap_.erase(this->peerMap_.find(peerID));
     338   
     339    // create new peerEvent and return it
     340    incomingEvent inEvent = { peerID, incomingEventType::peerDisconnect, 0 };
     341    return inEvent;
     342  }
     343 
     344  incomingEvent Connection::preprocessReceiveEvent(ENetEvent& event)
     345  {
     346    // assert that the peer exists and get peerID
     347    assert( this->peerIDMap_.find(event.peer) != this->peerIDMap_.end() );
     348    uint32_t peerID = this->peerIDMap_[event.peer];
     349   
     350    // create new Packet from ENetPacket
     351    packet::Packet* p = packet::Packet::createPacket(event.packet, peerID);
     352   
     353    // create new peerEvent and return it
     354    incomingEvent inEvent = { peerID, incomingEventType::receivePacket, p };
     355    return inEvent;
     356  }
     357
    216358 
    217359  void Connection::enableCompression()
  • code/trunk/src/libraries/network/Connection.h

    r7801 r8327  
    4444
    4545#include <deque>
     46#include <map>
    4647#include <enet/enet.h>
     48#include <boost/concept_check.hpp>
    4749
    4850namespace boost
     
    5961  const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
    6062 
     63  namespace incomingEventType
     64  {
     65    enum Value
     66    {
     67      receivePacket   = 1,  // incoming packet
     68      peerConnect     = 2,  // incoming connect request
     69      peerDisconnect  = 3   // incoming disconnect request
     70    };
     71   
     72  }
     73 
    6174  namespace outgoingEventType
    6275  {
    6376    enum Value
    6477    {
    65       sendPacket      = 1,
    66       disconnectPeer  = 2,
    67       broadcastPacket = 3
     78      sendPacket      = 1,  // outgoing packet
     79      broadcastPacket = 2,  // outgoing broadcast packet
     80      disconnectPeer  = 3,  // outgoing disconnect request
     81      disconnectPeers = 4   // outgoing disconnect request
    6882    };
    6983   
    7084  }
    7185 
     86  struct _NetworkExport incomingEvent
     87  {
     88    uint32_t                  peerID;
     89    incomingEventType::Value  type;
     90    packet::Packet*           packet;
     91  };
     92 
    7293  struct _NetworkExport outgoingEvent
    7394  {
    74     ENetPeer*                 peer;
     95    uint32_t                  peerID;
    7596    outgoingEventType::Value  type;
    7697    ENetPacket*               packet;
     
    83104    virtual ~Connection();
    84105
    85     void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);
    86     void broadcastPacket(ENetPacket* packet, uint8_t channelID);
    87 //     ENetHost* getHost(){ return this->host_; }
    88 
    89106  protected:
    90     Connection();
    91 //     static Connection* getInstance(){ return Connection::instance_; }
    92 
    93 //     int service(ENetEvent* event);
     107    Connection(uint32_t firstPeerID = NETWORK_PEER_ID_SERVER+1);
     108   
    94109    void startCommunicationThread();
    95110    void stopCommunicationThread();
    96     void communicationThread();
    97     virtual void disconnectPeer(ENetPeer *peer);
     111   
     112    void addPacket(ENetPacket *packet, uint32_t peerID, uint8_t channelID);
     113    void broadcastPacket(ENetPacket* packet, uint8_t channelID);
     114    void disconnectPeer(uint32_t peerID);
     115    void disconnectPeers();
    98116   
    99117    void enableCompression();
    100118
    101119    void processQueue();
    102     virtual void addPeer(ENetEvent* event)=0;
    103     virtual void removePeer(ENetEvent* event)=0;
     120    void waitOutgoingQueue();     // wait for the outgoing queue to become empty (everything processed by communication thread)
     121    virtual void addPeer(uint32_t peerID)=0;
     122    virtual void removePeer(uint32_t peerID)=0;
    104123    virtual void processPacket( packet::Packet* packet)=0;
    105     virtual packet::Packet* createPacket(ENetEvent* event);
     124   
     125    incomingEvent preprocessConnectEvent(ENetEvent& event);
     126    incomingEvent preprocessDisconnectEvent(ENetEvent& event);
     127    incomingEvent preprocessReceiveEvent(ENetEvent& event);
     128   
     129    void processIncomingEvent(ENetEvent& event);
     130    void processOutgoingEvent(outgoingEvent& event);
     131   
     132    void disconnectPeersInternal();
    106133
    107     ENetHost*                   host_;
     134    ENetHost*                     host_;
    108135  private:
    109     boost::thread*              communicationThread_;
    110     bool                        bCommunicationThreadRunning_;
    111     ENetAddress*                bindAddress_;
    112     std::deque<ENetEvent>       incomingEvents_;
    113     std::deque<outgoingEvent>   outgoingEvents_;
    114     boost::mutex*               incomingEventsMutex_;
    115     boost::mutex*               outgoingEventsMutex_;
    116 
    117 //     static Connection *instance_;
     136    void communicationThread();
     137   
     138    boost::thread*                communicationThread_;
     139    bool                          bCommunicationThreadRunning_;
     140    ENetAddress*                  bindAddress_;
     141    std::deque<incomingEvent>     incomingEvents_;
     142    std::deque<outgoingEvent>     outgoingEvents_;
     143    boost::mutex*                 incomingEventsMutex_;
     144    boost::mutex*                 outgoingEventsMutex_;
     145    boost::mutex*                 overallMutex_;
     146    std::map<uint32_t, ENetPeer*> peerMap_;
     147    std::map<ENetPeer*, uint32_t> peerIDMap_;
     148    uint32_t                      nextPeerID_;
    118149
    119150  };
  • code/trunk/src/libraries/network/GamestateHandler.h

    r7801 r8327  
    5151    virtual bool      addGamestate(packet::Gamestate* gs, unsigned int clientID) = 0;
    5252    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int clientID) = 0;
    53     virtual uint32_t  getLastProcessedGamestateID( unsigned int clientID )=0;
     53    virtual uint32_t  getLastReceivedGamestateID( unsigned int clientID )=0;
    5454    virtual uint32_t  getCurrentGamestateID()=0;
    5555};
  • code/trunk/src/libraries/network/GamestateManager.cc

    r7801 r8327  
    5757
    5858namespace orxonox
    59 {
     59{ 
    6060  GamestateManager::GamestateManager() :
    6161  currentGamestate_(0), id_(0)
     
    122122  bool GamestateManager::sendAck(unsigned int gamestateID, uint32_t peerID)
    123123  {
     124    assert( gamestateID != ACKID_NACK );
    124125    packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, peerID);
    125126    if( !this->sendPacket(ack))
     
    139140    if ( currentGamestate_ != 0 )
    140141      delete currentGamestate_;
    141     currentGamestate_ = new packet::Gamestate();
    142142    uint8_t gsMode;
    143143    if( GameMode::isMaster() )
     
    149149      newID = ++id_;
    150150    else
    151       newID = peerMap_[NETWORK_PEER_ID_SERVER].lastProcessedGamestateID;
     151    {
     152      assert(peerMap_.size()!=0);
     153      newID = peerMap_[NETWORK_PEER_ID_SERVER].lastReceivedGamestateID;
     154      if( newID == GAMESTATEID_INITIAL )
     155      {
     156        return false;
     157      }
     158    }
    152159   
    153     if(!currentGamestate_->collectData(newID, gsMode)){ //we have no data to send
     160    currentGamestate_ = new packet::Gamestate();
     161   
     162    if(!currentGamestate_->collectData(newID, gsMode))
     163    { //we have no data to send
    154164      delete currentGamestate_;
    155165      currentGamestate_=0;
     166      return false;
    156167    }
    157168    return true;
     
    172183        continue;
    173184      }
    174       COUT(4) << "client id: " << peerIt->first << std::endl;
     185      COUT(5) << "client id: " << peerIt->first << std::endl;
    175186      COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl;
    176187      int peerID = peerIt->first; //get client id
     
    187198      }
    188199
    189       peerGamestates.push_back(0);  // insert an empty gamestate* to change
     200      peerGamestates.push_back(0);  // insert an empty gamestate* to be changed
    190201      finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ );
    191202      if( peerGamestates.back()==0 )
     
    244255//     assert(b);
    245256    clock.capture();
    246     COUT(4) << "diff and compress time: " << clock.getDeltaTime() << endl;
     257    COUT(5) << "diff and compress time: " << clock.getDeltaTime() << endl;
    247258//     COUT(5) << "sending gamestate with id " << gs->getID();
    248259//     if(gamestate->isDiffed())
     
    263274    unsigned int curid = it->second.lastAckedGamestateID;
    264275
    265     if(gamestateID == ACKID_NACK){
    266       it->second.lastAckedGamestateID = GAMESTATEID_INITIAL;
    267 //       temp->setGamestateID(GAMESTATEID_INITIAL);
    268       // now delete all saved gamestates for this client
    269       std::map<uint32_t, packet::Gamestate*>::iterator it2;
    270       for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){
    271         delete it2->second;
    272       }
    273       it->second.gamestates.clear();
    274       return true;
    275     }
    276 
    277     assert(curid==GAMESTATEID_INITIAL || curid<=gamestateID);
    278     COUT(5) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl;
     276    assert(gamestateID != ACKID_NACK);
     277//     if(gamestateID == ACKID_NACK){
     278//       it->second.lastAckedGamestateID = GAMESTATEID_INITIAL;
     279// //       temp->setGamestateID(GAMESTATEID_INITIAL);
     280//       // now delete all saved gamestates for this client
     281//       std::map<uint32_t, packet::Gamestate*>::iterator it2;
     282//       for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){
     283//         delete it2->second;
     284//       }
     285//       it->second.gamestates.clear();
     286//       return true;
     287//     }
     288
     289//    assert(curid==GAMESTATEID_INITIAL || curid<=gamestateID); // this line is commented out because acknowledgements are unreliable and may arrive in distorted order
     290    if( gamestateID <= curid )
     291        return true;
     292COUT(4) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl;
    279293    std::map<uint32_t, packet::Gamestate*>::iterator it2;
    280294    for( it2=it->second.gamestates.begin(); it2!=it->second.gamestates.end(); )
     
    300314  }
    301315 
    302   uint32_t GamestateManager::getLastProcessedGamestateID(unsigned int peerID)
     316  uint32_t GamestateManager::getLastReceivedGamestateID(unsigned int peerID)
    303317  {
    304318    assert( this->peerMap_.find(peerID)!=this->peerMap_.end() );
    305319    if( this->peerMap_.find(peerID) != this->peerMap_.end() )
    306       return this->peerMap_[peerID].lastProcessedGamestateID;
     320      return this->peerMap_[peerID].lastReceivedGamestateID;
    307321    else
    308322      return GAMESTATEID_INITIAL;
     
    314328    assert(peerMap_.find(peerID)==peerMap_.end());
    315329    peerMap_[peerID].peerID = peerID;
    316     peerMap_[peerID].lastProcessedGamestateID = GAMESTATEID_INITIAL;
     330    peerMap_[peerID].lastReceivedGamestateID = GAMESTATEID_INITIAL;
    317331    peerMap_[peerID].lastAckedGamestateID = GAMESTATEID_INITIAL;
    318332    if( GameMode::isMaster() )
     
    360374    if( gs->spreadData(gsMode) )
    361375    {
    362       this->peerMap_[gs->getPeerID()].lastProcessedGamestateID = gs->getID();
     376      this->peerMap_[gs->getPeerID()].lastReceivedGamestateID = gs->getID();
    363377      return true;
    364378    }
  • code/trunk/src/libraries/network/GamestateManager.h

    r7801 r8327  
    7373    {
    7474      uint32_t  peerID;
    75       uint32_t  lastProcessedGamestateID;
    76       uint32_t  lastAckedGamestateID;
     75      uint32_t  lastReceivedGamestateID;  //!< id of the last gamestate which was received (and processed) from the peer
     76      uint32_t  lastAckedGamestateID;     //!< id of the last gamestate on which we received an ack from the peer
    7777      bool      isSynched;
    7878      std::map< uint32_t, packet::Gamestate* > gamestates;
     
    8686    virtual bool      addGamestate(packet::Gamestate *gs, unsigned int peerID);
    8787    virtual bool      ackGamestate(unsigned int gamestateID, unsigned int peerID);
    88     virtual uint32_t  getLastProcessedGamestateID( unsigned int peerID );
     88    virtual uint32_t  getLastReceivedGamestateID( unsigned int peerID );
    8989    virtual uint32_t  getCurrentGamestateID(){ return currentGamestate_->getID(); }
    9090   
     
    101101      { assert(peerMap_.find(peerID)!=peerMap_.end()); peerMap_[peerID].isSynched = true; }
    102102    void removePeer( uint32_t peerID );
     103    bool hasPeers(){ return this->peerMap_.size()!=0; }
    103104//     void removeClient(ClientInformation *client);
    104105  protected:
  • code/trunk/src/libraries/network/Host.cc

    r8108 r8327  
    117117    {
    118118      for (ObjectList<ChatListener>::iterator it = ObjectList<ChatListener>::begin(); it != ObjectList<ChatListener>::end(); ++it)
    119         it->incomingChat(message, CLIENTID_UNKNOWN);
     119        it->incomingChat(message, NETWORK_PEER_ID_BROADCAST);
    120120      return true;
    121121    }
  • code/trunk/src/libraries/network/NetworkPrereqs.h

    r7801 r8327  
    6565{
    6666  static const unsigned int GAMESTATEID_INITIAL       = static_cast<unsigned int>(-1);
    67   static const unsigned int CLIENTID_UNKNOWN          = static_cast<unsigned int>(-2);
    6867  extern const char* LAN_DISCOVERY_MESSAGE;
    6968  extern const char* LAN_DISCOVERY_ACK;
    7069  static const unsigned int LAN_DISCOVERY_PORT          = 55558;
    7170  static const unsigned int NETWORK_PEER_ID_SERVER      = 0;
     71  static const unsigned int NETWORK_PEER_ID_BROADCAST   = static_cast<unsigned int>(-1);
     72  static const unsigned int NETWORK_PEER_ID_UNKNOWN     = static_cast<unsigned int>(-2);
    7273  static const unsigned int NETWORK_CHANNEL_DEFAULT     = 0;
    7374  static const unsigned int NETWORK_CHANNEL_UNRELIABLE  = 1;
  • code/trunk/src/libraries/network/Server.cc

    r7801 r8327  
    5757#include "packet/Welcome.h"
    5858#include "ChatListener.h"
    59 #include "ClientInformation.h"
     59// #include "ClientInformation.h"
    6060#include "FunctionCallManager.h"
    6161#include "GamestateManager.h"
     
    152152  bool Server::processChat(const std::string& message, unsigned int playerID)
    153153  {
    154     ClientInformation *temp = ClientInformation::getBegin();
     154//     ClientInformation *temp = ClientInformation::getBegin();
    155155    packet::Chat *chat;
    156     while(temp){
    157       chat = new packet::Chat(message, playerID);
    158       chat->setPeerID(temp->getID());
    159       if(!chat->send( static_cast<Host*>(this) ))
    160         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
    161       temp = temp->next();
    162     }
     156//     while(temp){
     157    chat = new packet::Chat(message, playerID);
     158    chat->setPeerID(NETWORK_PEER_ID_BROADCAST);
     159    chat->send( static_cast<Host*>(this) );
     160//         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
     161//       temp = temp->next();
     162//     }
    163163//    COUT(1) << "Player " << playerID << ": " << message << std::endl;
    164164    return true;
     
    207207    //helper_HandleMasterServerRequests();
    208208
    209     if ( ClientInformation::hasClients() )
     209    if ( GamestateManager::hasPeers() )
    210210    {
    211211      // process incoming gamestates
     
    237237  unsigned int Server::getRTT(unsigned int clientID)
    238238  {
    239     assert(ClientInformation::findClient(clientID));
    240     return ClientInformation::findClient(clientID)->getRTT();
     239//     assert(ClientInformation::findClient(clientID));
     240//     return ClientInformation::findClient(clientID)->getRTT();
     241    // TODO: reimplement
     242    return 0;
    241243  }
    242244
    243245  void Server::printRTT()
    244246  {
    245     for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() )
    246       COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl;
     247//     for( ClientInformation* temp=ClientInformation::getBegin(); temp!=0; temp=temp->next() )
     248//       COUT(0) << "Round trip time to client with ID: " << temp->getID() << " is " << temp->getRTT() << " ms" << endl;
    247249  }
    248250
     
    252254  double Server::getPacketLoss(unsigned int clientID)
    253255  {
    254     assert(ClientInformation::findClient(clientID));
    255     return ClientInformation::findClient(clientID)->getPacketLoss();
     256//     assert(ClientInformation::findClient(clientID));
     257//     return ClientInformation::findClient(clientID)->getPacketLoss();
     258    return 0.;
    256259  }
    257260
     
    261264  void Server::updateGamestate()
    262265  {
    263     if( ClientInformation::getBegin()==NULL )
     266    if( this->clientIDs_.size()==0 )
    264267      //no client connected
    265268      return;
     
    291294  bool Server::sendObjectDeletes()
    292295  {
    293     ClientInformation *temp = ClientInformation::getBegin();
    294     if( temp == NULL )
     296//     ClientInformation *temp = ClientInformation::getBegin();
     297//     if( temp == NULL )
    295298      //no client connected
     299    if( this->clientIDs_.size()==0 )
    296300      return true;
    297301    packet::DeleteObjects *del = new packet::DeleteObjects();
     
    302306    }
    303307//     COUT(3) << "sending DeleteObjects" << std::endl;
    304     while(temp != NULL){
    305       if( !(temp->getSynched()) )
    306       {
    307         COUT(5) << "Server: not sending gamestate" << std::endl;
    308         temp=temp->next();
    309         continue;
    310       }
    311       int cid = temp->getID(); //get client id
    312       packet::DeleteObjects *cd = new packet::DeleteObjects(*del);
    313       assert(cd);
    314       cd->setPeerID(cid);
    315       if ( !cd->send( static_cast<Host*>(this) ) )
    316         COUT(3) << "Server: packet with client id (cid): " << cid << " not sended" << std::endl;
    317       temp=temp->next();
     308//     while(temp != NULL){
     309//       if( !(temp->getSynched()) )
     310//       {
     311//         COUT(5) << "Server: not sending gamestate" << std::endl;
     312//         temp=temp->next();
     313//         continue;
     314//       }
     315//       int cid = temp->getID(); //get client id
     316//       packet::DeleteObjects *cd = new packet::DeleteObjects(*del);
     317//       assert(cd);
     318    del->setPeerID(NETWORK_PEER_ID_BROADCAST);
     319    if ( !del->send( static_cast<Host*>(this) ) )
     320      COUT(3) << "Server: could not broadcast deleteObjects packet" << std::endl;
     321//       temp=temp->next();
    318322      // gs gets automatically deleted by enet callback
    319     }
    320     delete del;
     323//     }
     324//     delete del;
    321325    return true;
    322326  }
    323327
    324328
    325   void Server::addPeer(ENetEvent *event)
    326   {
    327     static unsigned int newid=1;
    328 
    329     COUT(2) << "Server: adding client" << std::endl;
    330     ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
    331     if(!temp)
    332     {
    333       COUT(2) << "Server: could not add client" << std::endl;
    334     }
    335     temp->setID(newid);
    336     temp->setPeer(event->peer);
     329  void Server::addPeer(uint32_t peerID)
     330  {
     331//     static unsigned int newid=1;
     332//
     333//     COUT(2) << "Server: adding client" << std::endl;
     334//     ClientInformation *temp = ClientInformation::insertBack(new ClientInformation);
     335//     if(!temp)
     336//     {
     337//       COUT(2) << "Server: could not add client" << std::endl;
     338//     }
     339//     temp->setID(newid);
     340//     temp->setPeer(event->peer);
    337341
    338342    // inform all the listeners
    339     ClientConnectionListener::broadcastClientConnected(newid);
    340     GamestateManager::addPeer(newid);
    341 
    342     ++newid;
    343 
    344     COUT(3) << "Server: added client id: " << temp->getID() << std::endl;
    345     createClient(temp->getID());
     343    this->clientIDs_.push_back(peerID);
     344    ClientConnectionListener::broadcastClientConnected(peerID);
     345    GamestateManager::addPeer(peerID);
     346
     347//     ++newid;
     348
     349    COUT(3) << "Server: added client id: " << peerID << std::endl;
     350    createClient(peerID);
    346351}
    347352
    348   void Server::removePeer(ENetEvent *event)
     353  void Server::removePeer(uint32_t peerID)
    349354  {
    350355    COUT(4) << "removing client from list" << std::endl;
    351     ClientInformation *client = ClientInformation::findClient(&event->peer->address);
    352     if(!client)
    353       return;
    354     else
    355     {
    356       GamestateManager::removePeer(client->getID());
     356//     ClientInformation *client = ClientInformation::findClient(&event->peer->address);
     357//     if(!client)
     358//       return;
     359//     else
     360//     {
     361  std::vector<uint32_t>::iterator it;
     362  for( it=this->clientIDs_.begin(); it!=this->clientIDs_.end(); ++it )
     363  {
     364    if( *it == peerID )
     365    {
     366      this->clientIDs_.erase(it);
     367      break;
     368    }
     369  }
     370  ClientConnectionListener::broadcastClientDisconnected(peerID);
     371  GamestateManager::removePeer(peerID);
    357372      //ServerConnection::disconnectClient( client );
    358373      //ClientConnectionListener::broadcastClientDisconnected( client->getID() ); //this is done in ClientInformation now
    359       delete client;
    360     }
     374//       delete client;
     375//     }
    361376  }
    362377 
     
    365380    if( packet->isReliable() )
    366381    {
    367       if( this->getLastProcessedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
     382      if( this->getLastReceivedGamestateID(packet->getPeerID()) >= packet->getRequiredGamestateID() )
    368383        packet->process(static_cast<Host*>(this));
    369384      else
     
    377392  bool Server::createClient(int clientID)
    378393  {
    379     ClientInformation *temp = ClientInformation::findClient(clientID);
    380     if(!temp)
    381     {
    382       COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
    383       return false;
    384     }
    385     COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
     394//     ClientInformation *temp = ClientInformation::findClient(clientID);
     395//     if(!temp)
     396//     {
     397//       COUT(2) << "Server. could not create client with id: " << clientID << std::endl;
     398//       return false;
     399//     }
     400//     COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
    386401
    387402    // synchronise class ids
    388     syncClassid(temp->getID());
     403    syncClassid(clientID);
    389404
    390405    // now synchronise functionIDs
     
    394409    assert(b);
    395410
    396     temp->setSynched(true);
     411//     temp->setSynched(true);
    397412    GamestateManager::setSynched(clientID);
    398413   
    399414    COUT(4) << "sending welcome" << std::endl;
    400     packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
    401     w->setPeerID(temp->getID());
     415    packet::Welcome *w = new packet::Welcome(clientID, OBJECTID_UNKNOWN);
     416    w->setPeerID(clientID);
    402417    b = w->send( static_cast<Host*>(this) );
    403418    assert(b);
    404     packet::Gamestate *g = new packet::Gamestate();
    405     g->setPeerID(temp->getID());
    406     b = g->collectData(0,packet::GAMESTATE_MODE_SERVER);
    407     assert(b);
    408     if(!b)
    409       return false; //no data for the client
    410 //     b = g->compressData();
     419//     packet::Gamestate *g = new packet::Gamestate();
     420//     g->setPeerID(clientID);
     421//     b = g->collectData(0,packet::GAMESTATE_MODE_SERVER);
    411422//     assert(b);
    412     b = g->send( static_cast<Host*>(this) );
    413     assert(b);
     423//     if(!b)
     424//       return false; //no data for the client
     425// //     b = g->compressData();
     426// //     assert(b);
     427//     b = g->send( static_cast<Host*>(this) );
     428//     assert(b);
    414429    return true;
    415430  }
    416431
    417   void Server::disconnectClient( ClientInformation *client )
    418   {
    419     ServerConnection::disconnectClient( client );
    420     GamestateManager::removePeer(client->getID());
     432  void Server::disconnectClient( uint32_t clientID )
     433  {
     434    ServerConnection::disconnectClient( clientID );
     435    GamestateManager::removePeer( clientID );
    421436    // inform all the listeners
    422437    // ClientConnectionListener::broadcastClientDisconnected(client->getID()); // this is done in ClientInformation now
     
    430445  bool Server::broadcast(const std::string& message)
    431446  {
    432       return this->sendChat(message, CLIENTID_UNKNOWN);
     447      return this->sendChat(message, NETWORK_PEER_ID_BROADCAST);
    433448  }
    434449
    435450  bool Server::sendChat(const std::string& message, unsigned int clientID)
    436451  {
    437     ClientInformation *temp = ClientInformation::getBegin();
     452//     ClientInformation *temp = ClientInformation::getBegin();
    438453    packet::Chat *chat;
    439     while(temp)
     454//     while(temp)
    440455    {
    441456      chat = new packet::Chat(message, clientID);
    442       chat->setPeerID(temp->getID());
    443       if(!chat->send( static_cast<Host*>(this) ))
    444         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
    445       temp = temp->next();
     457      chat->setPeerID(NETWORK_PEER_ID_BROADCAST);
     458      chat->send( static_cast<Host*>(this) );
     459//         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
     460//       temp = temp->next();
    446461    }
    447462//    COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl;
  • code/trunk/src/libraries/network/Server.h

    r7801 r8327  
    3333
    3434#include <deque>
     35#include <vector>
    3536
    3637#include "util/UtilPrereqs.h"
     
    8081    unsigned int playerID(){return 0;}
    8182
    82     void addPeer(ENetEvent *event);
    83     void removePeer(ENetEvent *event);
     83    void addPeer(uint32_t peerID);
     84    void removePeer(uint32_t peerID);
    8485    void processPacket(packet::Packet* packet);
    8586
    8687    bool createClient(int clientID);
    87     void disconnectClient( ClientInformation *client);
     88    void disconnectClient( uint32_t clientID );
    8889    bool sendGameStates();
    8990    bool sendObjectDeletes();
     
    9596    float timeSinceLastUpdate_;
    9697    std::deque<packet::Packet*> packetQueue_;
     98    std::vector<uint32_t>       clientIDs_;
    9799  };
    98100
  • code/trunk/src/libraries/network/ServerConnection.cc

    r7801 r8327  
    3535
    3636#include "util/Debug.h"
    37 #include "ClientInformation.h"
     37#include <util/Sleep.h>
     38// #include "ClientInformation.h"
    3839
    3940namespace orxonox
     
    4445  {
    4546    this->bindAddress_ = new ENetAddress();
    46     memset(this->bindAddress_, 0, sizeof(ENetAddress));
     47//     memset(this->bindAddress_, 0, sizeof(ENetAddress));
    4748    this->bindAddress_->host = ENET_HOST_ANY;
    4849    this->bindAddress_->port = NETWORK_PORT;
     50    this->bindAddress_->scopeID = 0;
    4951  }
    5052
     
    104106  void ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID, uint8_t channelID)
    105107  {
    106     if ( clientID == CLIENTID_UNKNOWN )
     108    if ( clientID == NETWORK_PEER_ID_BROADCAST )
    107109    {
    108110      broadcastPacket(packet, channelID);
     
    110112    else
    111113    {
    112       ClientInformation *temp = ClientInformation::findClient(clientID);
    113       if(!temp){
    114         COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
    115       }
    116       Connection::addPacket(packet, temp->getPeer(), channelID);
     114//       ClientInformation *temp = ClientInformation::findClient(clientID);
     115//       if(!temp){
     116//         COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
     117//       }
     118      Connection::addPacket(packet, clientID, channelID);
    117119    }
    118120  }
    119121
    120   void ServerConnection::disconnectClient(ClientInformation *client)
    121   {
    122     Connection::disconnectPeer( client->getPeer() );
    123   }
     122//   void ServerConnection::disconnectClient(ClientInformation *client)
     123//   {
     124//     Connection::disconnectPeer( client->getPeer() );
     125//   }
    124126
    125127  void ServerConnection::disconnectClient(int clientID)
    126128  {
    127     ClientInformation *client = ClientInformation::findClient(clientID);
    128     if(client)
    129       ServerConnection::disconnectClient(client);
     129//     ClientInformation *client = ClientInformation::findClient(clientID);
     130//     if(client)
     131    ServerConnection::disconnectClient(clientID);
    130132  }
    131133
    132134  void ServerConnection::disconnectClients()
    133135  {
    134     ClientInformation *temp = ClientInformation::getBegin();
    135     while(temp!=0)
    136     {
    137       ServerConnection::disconnectClient( temp );
    138       temp = temp->next();
    139     }
     136    Connection::disconnectPeers();
     137    Connection::waitOutgoingQueue();
    140138    return;
    141139  }
    142140
    143141
    144   int ServerConnection::getClientID(ENetPeer* peer)
    145   {
    146     return getClientID(&(peer->address));
    147   }
     142//   int ServerConnection::getClientID(ENetPeer* peer)
     143//   {
     144//     return getClientID(&(peer->address));
     145//   }
    148146
    149   int ServerConnection::getClientID(ENetAddress* address)
    150   {
    151     return ClientInformation::findClient(address)->getID();
    152   }
    153 
    154   ENetPeer *ServerConnection::getClientPeer(int clientID)
    155   {
    156     return ClientInformation::findClient(clientID)->getPeer();
    157   }
     147//   int ServerConnection::getClientID(ENetAddress* address)
     148//   {
     149//     return ClientInformation::findClient(address)->getID();
     150//   }
     151//
     152//   ENetPeer *ServerConnection::getClientPeer(int clientID)
     153//   {
     154//     return ClientInformation::findClient(clientID)->getPeer();
     155//   }
    158156
    159157
  • code/trunk/src/libraries/network/ServerConnection.h

    r7801 r8327  
    5757    bool closeListener();
    5858    void addPacket(ENetPacket *packet, unsigned int ID, uint8_t channelID);
    59     virtual void disconnectClient(ClientInformation *client);
     59//     virtual void disconnectClient(ClientInformation *client);
    6060    void disconnectClient(int clientID);
    6161  protected:
     
    6464
    6565  private:
    66     int getClientID(ENetPeer* peer);
    67     int getClientID(ENetAddress* address);
    68     ENetPeer* getClientPeer(int clientID);
     66//     int getClientID(ENetPeer* peer);
     67//     int getClientID(ENetAddress* address);
     68//     ENetPeer* getClientPeer(int clientID);
    6969
    7070    ENetAddress* bindAddress_;
  • code/trunk/src/libraries/network/WANDiscovery.cc

    r7801 r8327  
    7171     * has changed.
    7272     */
    73     SetConfigValue( msaddress, "orxonox.net");
     73    SetConfigValue( msaddress, "master.orxonox.net");
    7474  }
    7575
  • code/trunk/src/libraries/network/packet/Gamestate.cc

    r7844 r8327  
    107107  uint32_t size = calcGamestateSize(id, mode);
    108108
    109   COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
     109  COUT(5) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
    110110  if(size==0)
    111111    return false;
     
    158158  //start write gamestate header
    159159  header_.setDataSize( currentsize );
     160  header_.setCompSize( 0 );
    160161  header_.setID( id );
    161162  header_.setBaseID( GAMESTATEID_INITIAL );
  • code/trunk/src/libraries/network/packet/Packet.cc

    r7801 r8327  
    4747#include "Welcome.h"
    4848#include "network/Host.h"
    49 #include "network/ClientInformation.h"
     49// #include "network/ClientInformation.h"
    5050
    5151namespace orxonox{
     
    8585
    8686
    87 Packet::Packet(const Packet &p){
     87Packet::Packet(const Packet &p)
     88{
    8889  enetPacket_=p.enetPacket_;
    8990  flags_=p.flags_;
     
    104105    That also means destroying the ENetPacket if one exists. There
    105106*/
    106 Packet::~Packet(){
     107Packet::~Packet()
     108{
    107109  // Deallocate data_ memory if necessary.
    108   if (this->bDataENetAllocated_){
     110  if (this->bDataENetAllocated_)
     111  {
    109112    // In this case ENet allocated data_ and will destroy it.
    110113  }
    111   else if (this->data_) {
     114  else if (this->data_)
     115  {
    112116    // This destructor was probably called as a consequence of ENet executing our callback.
    113117    // It simply serves us to be able to deallocate the packet content (data_) ourselves since
     
    119123  // Note: For the case ENet used the callback to destroy the packet, we have already set
    120124  // enetPacket_ to NULL to avoid destroying it again.
    121   if (this->enetPacket_){
     125  if (this->enetPacket_)
     126  {
    122127    // enetPacket_->data gets destroyed too by ENet if it was allocated by it.
    123128    enet_packet_destroy(enetPacket_);
     
    125130}
    126131
    127 bool Packet::send(orxonox::Host* host){
    128   if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional ){
     132bool Packet::send(orxonox::Host* host)
     133{
     134  if(packetDirection_ != Direction::Outgoing && packetDirection_ != Direction::Bidirectional )
     135  {
    129136    assert(0);
    130137    return false;
    131138  }
    132   if(!enetPacket_){
     139  if(!enetPacket_)
     140  {
    133141    if(!data_){
    134142      assert(0);
     
    175183}
    176184
    177 Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){
     185Packet *Packet::createPacket(ENetPacket* packet, uint32_t peerID)
     186{
    178187  uint8_t *data = packet->data;
    179   assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());
    180   unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();
     188//   assert(ClientInformation::findClient(&peer->address)->getID() != static_cast<unsigned int>(-2) || !Host::isServer());
     189//   unsigned int peerID = ClientInformation::findClient(&peer->address)->getID();
    181190  // HACK
    182   if( peerID==static_cast<unsigned int>(-2))
    183     peerID = NETWORK_PEER_ID_SERVER;
     191//   if( peerID==static_cast<unsigned int>(-2))
     192//     peerID = NETWORK_PEER_ID_SERVER;
    184193  Packet *p = 0;
    185194//   COUT(6) << "packet type: " << *(Type::Value *)&data[_PACKETID] << std::endl;
     
    235244    data we allocated ourselves.
    236245*/
    237 void Packet::deletePacket(ENetPacket *enetPacket){
     246void Packet::deletePacket(ENetPacket *enetPacket)
     247{
    238248  // Get our Packet from a global map with all Packets created in the send() method of Packet.
    239249  Packet::packetMapMutex_.lock();
  • code/trunk/src/libraries/network/packet/Packet.h

    r7801 r8327  
    3232#include <map>
    3333
    34 namespace orxonox {
     34namespace orxonox
     35{
    3536
    36 namespace packet{
     37namespace packet
     38{
    3739
    38 namespace Direction{
    39   enum Value{
     40namespace Direction
     41{
     42  enum Value
     43  {
    4044    Incoming,
    4145    Outgoing,
     
    4347  };
    4448}
    45 namespace Type{
    46   enum Value{
     49namespace Type
     50{
     51  enum Value
     52  {
    4753    Acknowledgement,
    4854    Chat,
     
    5965    @author Oliver Scheuss <scheusso [at] ee.ethz.ch>
    6066*/
    61 class _NetworkExport Packet{
     67class _NetworkExport Packet
     68{
    6269  public:
    6370    Packet(const Packet &p);
    6471    virtual ~Packet();
    65     static Packet *createPacket(ENetPacket *packet, ENetPeer *peer);
    66     static void deletePacket(ENetPacket *packet);
     72    static Packet* createPacket(ENetPacket* packet, uint32_t peerID);
     73    static void deletePacket(ENetPacket* packet);
    6774
    68     virtual unsigned char *getData(){ return data_; };
     75    virtual unsigned char* getData(){ return data_; };
    6976    virtual unsigned int getSize() const =0;
    7077    virtual bool process(orxonox::Host* host)=0;
  • code/trunk/src/libraries/network/synchronisable/Synchronisable.cc

    r7801 r8327  
    295295   * @param mem pointer to the bytestream
    296296   * @param mode same as in getData
    297    * @param forceCallback FIXME - add doc!
     297   * @param forceCallback this makes updateData call each callback
    298298   * @return true/false
    299299   */
     
    372372   * This function determines, wheter the object should be saved to the bytestream (according to its syncmode/direction)
    373373   * @param id gamestate id
    374    * @param mode FIXME - add doc!
     374   * @param mode Synchronisation mode (toclient, toserver or bidirectional)
    375375   * @return true/false
    376376   */
    377377  bool Synchronisable::doSync(int32_t id, uint8_t mode)
    378378  {
    379     if(mode==0x0)
    380       mode=state_;
     379//     if(mode==0x0)
     380//       mode=state_;
     381    assert(mode!=0x0);
    381382    return ( (this->objectMode_ & mode)!=0 && (!syncList_.empty() ) );
    382383  }
  • code/trunk/src/modules/overlays/hud/ChatOverlay.cc

    r7284 r8327  
    7171        std::string text;
    7272
    73         if (senderID != CLIENTID_UNKNOWN)
     73        if (senderID != NETWORK_PEER_ID_UNKNOWN)
    7474        {
    7575            std::string name = "unknown";
  • code/trunk/src/orxonox/ChatHistory.cc

    r7284 r8327  
    8282#ifndef CHATTEST
    8383    /* get sender ID and prepend it to the message */
    84     if (senderID != CLIENTID_UNKNOWN)
     84    if (senderID != NETWORK_PEER_ID_UNKNOWN)
    8585    {
    8686      /* if we can't find anything, use "unknown" as default */
  • code/trunk/src/orxonox/ChatInputHandler.cc

    r8079 r8327  
    220220
    221221    /* setup player name info */
    222     if (senderID != CLIENTID_UNKNOWN)
     222    if (senderID != NETWORK_PEER_ID_UNKNOWN)
    223223    {
    224224       PlayerInfo* player = PlayerManager::getInstance().getClient(senderID);
  • code/trunk/src/orxonox/PlayerManager.cc

    r7474 r8327  
    4545        RegisterRootObject(PlayerManager);
    4646
    47         this->getConnectedClients();
     47//         this->getConnectedClients();
    4848    }
    4949
  • code/trunk/src/orxonox/gamestates/GSRoot.cc

    r8079 r8327  
    183183    {
    184184        if (!GameMode::isStandalone())
    185             callStaticNetworkFunction(&TimeFactorListener::setTimeFactor, CLIENTID_UNKNOWN, factor_new);
     185            callStaticNetworkFunction(&TimeFactorListener::setTimeFactor, NETWORK_PEER_ID_BROADCAST, factor_new);
    186186    }
    187187
  • code/trunk/src/orxonox/gametypes/Dynamicmatch.cc

    r7284 r8327  
    452452                    if (!it->first)//in order to catch nullpointer
    453453                        continue;
    454                     if (it->first->getClientID() == CLIENTID_UNKNOWN)
     454                    if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    455455                        continue;
    456456                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
     
    467467                       if (!it->first)//in order to catch nullpointer
    468468                           continue;
    469                        if (it->first->getClientID() == CLIENTID_UNKNOWN)
     469                       if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    470470                           continue;
    471471                       else if (it->second==chaser)
     
    501501                    if (!it->first)//in order to catch nullpointer
    502502                        continue;
    503                     if (it->first->getClientID() == CLIENTID_UNKNOWN)
     503                    if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    504504                        continue;
    505505                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
     
    516516                       if (!it->first)
    517517                           continue;
    518                        if (it->first->getClientID() == CLIENTID_UNKNOWN)
     518                       if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    519519                           continue;
    520520                       else if (it->second==chaser)
     
    551551                    if (!it->first)//in order to catch nullpointer
    552552                        continue;
    553                     if (it->first->getClientID() == CLIENTID_UNKNOWN)
     553                    if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    554554                        continue;
    555555                    this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
     
    566566                       if (!it->first)
    567567                           continue;
    568                        if (it->first->getClientID() == CLIENTID_UNKNOWN)
     568                       if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    569569                           continue;
    570570                       else if (it->second==chaser)
     
    632632            for (std::map<PlayerInfo*, int>::iterator it = this->playerParty_.begin(); it != this->playerParty_.end(); ++it)
    633633            {
    634                 if (it->first->getClientID() == CLIENTID_UNKNOWN)
     634                if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    635635                    continue;
    636636                this->gtinfo_->sendStaticMessage("Selection phase: Shoot at everything that moves.",it->first->getClientID(),ColourValue(1.0f, 1.0f, 0.5f));
  • code/trunk/src/orxonox/gametypes/Gametype.cc

    r8079 r8327  
    263263                        it->second.frags_++;
    264264
    265                         if (killer->getPlayer()->getClientID() != CLIENTID_UNKNOWN)
     265                        if (killer->getPlayer()->getClientID() != NETWORK_PEER_ID_UNKNOWN)
    266266                            this->gtinfo_->sendKillMessage("You killed " + victim->getPlayer()->getName(), killer->getPlayer()->getClientID());
    267                         if (victim->getPlayer()->getClientID() != CLIENTID_UNKNOWN)
     267                        if (victim->getPlayer()->getClientID() != NETWORK_PEER_ID_UNKNOWN)
    268268                            this->gtinfo_->sendDeathMessage("You were killed by " + killer->getPlayer()->getName(), victim->getPlayer()->getClientID());
    269269                    }
  • code/trunk/src/orxonox/gametypes/LastManStanding.cc

    r8234 r8327  
    8686            if (it != this->players_.end())
    8787            {
    88                 if (it->first->getClientID()== CLIENTID_UNKNOWN)
     88                if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
    8989                    return true;
    9090                const std::string& message = ""; // resets Camper-Warning-message
     
    131131        for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
    132132        {
    133             if (it->first->getClientID() == CLIENTID_UNKNOWN)
     133            if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    134134                continue;
    135135
     
    194194        if (it != this->players_.end())
    195195        {
    196             if (it->first->getClientID()== CLIENTID_UNKNOWN)
     196            if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
    197197                return;
    198198            const std::string& message = ""; // resets Camper-Warning-message
     
    249249                    this->inGame_[it->first]=true;
    250250
    251                     if (it->first->getClientID()== CLIENTID_UNKNOWN)
     251                    if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
    252252                        continue;
    253253                    int output=1+(int)playerDelayTime_[it->first];
     
    261261                    {
    262262                        this->punishPlayer(it->first);
    263                         if (it->first->getClientID()== CLIENTID_UNKNOWN)
     263                        if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
    264264                            return;
    265265                        const std::string& message = ""; // resets Camper-Warning-message
     
    269269                else if (it->second<timeRemaining/5)//Warning message
    270270                {
    271                     if (it->first->getClientID()== CLIENTID_UNKNOWN)
     271                    if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
    272272                        continue;
    273273                    const std::string& message = "Camper Warning! Don't forget to shoot.";
  • code/trunk/src/orxonox/gametypes/LastTeamStanding.cc

    r8234 r8327  
    3030
    3131#include "core/CoreIncludes.h"
     32#include "network/NetworkPrereqs.h"
    3233#include "network/Host.h"
    3334#include "infos/PlayerInfo.h"
     
    135136            if (it != this->players_.end())
    136137            {
    137                 if (it->first->getClientID()== CLIENTID_UNKNOWN)
     138                if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
    138139                    return true;
    139140                const std::string& message = ""; // resets Camper-Warning-message
     
    169170        if (it != this->players_.end())
    170171        {
    171             if (it->first->getClientID()== CLIENTID_UNKNOWN)
     172            if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
    172173                return;
    173174            const std::string& message = ""; // resets Camper-Warning-message
     
    196197                    this->inGame_[it->first] = true;
    197198
    198                     if (it->first->getClientID()== CLIENTID_UNKNOWN)
     199                    if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
    199200                        continue;
    200201                    int output = 1 + (int)playerDelayTime_[it->first];
     
    208209                    {
    209210                        this->punishPlayer(it->first);
    210                         if (it->first->getClientID() == CLIENTID_UNKNOWN)
     211                        if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    211212                            return;
    212213                        const std::string& message = ""; // resets Camper-Warning-message
     
    216217                else if (it->second < timeRemaining/5)//Warning message
    217218                {
    218                     if (it->first->getClientID()== CLIENTID_UNKNOWN)
     219                  if (it->first->getClientID()== NETWORK_PEER_ID_UNKNOWN)
    219220                        continue;
    220221                    const std::string& message = "Camper Warning! Don't forget to shoot.";
     
    232233        for (std::map<PlayerInfo*, int>::iterator it = this->playerLives_.begin(); it != this->playerLives_.end(); ++it)
    233234        {
    234             if (it->first->getClientID() == CLIENTID_UNKNOWN)
     235          if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    235236                continue;
    236237
     
    247248                for (std::map<PlayerInfo*, int>::iterator it3 = this->teamnumbers_.begin(); it3 != this->teamnumbers_.end(); ++it3)
    248249                {
    249                     if (it3->first->getClientID() == CLIENTID_UNKNOWN)
     250                  if (it3->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    250251                        continue;
    251252                    if (it3->second == party)
  • code/trunk/src/orxonox/gametypes/TeamBaseMatch.cc

    r7284 r8327  
    190190            for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
    191191            {
    192                 if (it->first->getClientID() == CLIENTID_UNKNOWN)
     192                if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    193193                    continue;
    194194
  • code/trunk/src/orxonox/gametypes/UnderAttack.cc

    r6417 r8327  
    7676        for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
    7777        {
    78             if (it->first->getClientID() == CLIENTID_UNKNOWN)
     78            if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    7979                continue;
    8080
     
    158158                for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
    159159                {
    160                     if (it->first->getClientID() == CLIENTID_UNKNOWN)
     160                    if (it->first->getClientID() == NETWORK_PEER_ID_UNKNOWN)
    161161                        continue;
    162162
  • code/trunk/src/orxonox/infos/GametypeInfo.cc

    r7163 r8327  
    7474        if (GameMode::isMaster())
    7575        {
    76             callMemberNetworkFunction(GametypeInfo, dispatchAnnounceMessage, this->getObjectID(), CLIENTID_UNKNOWN, message);
     76            callMemberNetworkFunction(GametypeInfo, dispatchAnnounceMessage, this->getObjectID(), NETWORK_PEER_ID_BROADCAST, message);
    7777            this->dispatchAnnounceMessage(message);
    7878        }
  • code/trunk/src/orxonox/infos/HumanPlayer.cc

    r6417 r8327  
    3232#include "core/ConfigValueIncludes.h"
    3333#include "core/GameMode.h"
    34 #include "network/ClientInformation.h"
     34// #include "network/ClientInformation.h"
    3535#include "network/Host.h"
    3636#include "controllers/HumanController.h"
     
    144144    float HumanPlayer::getPing() const
    145145    {
    146         return static_cast<float>(ClientInformation::findClient(this->getClientID())->getRTT());
     146//         return static_cast<float>(ClientInformation::findClient(this->getClientID())->getRTT());
     147        return 0.; //TODO: reimplement this
    147148    }
    148149
    149150    float HumanPlayer::getPacketLossRatio() const
    150151    {
    151         return static_cast<float>(ClientInformation::findClient(this->getClientID())->getPacketLoss());
     152      //         return static_cast<float>(ClientInformation::findClient(this->getClientID())->getPacketLoss());
     153        return 0.; //TODO: reimplement this
    152154    }
    153155
  • code/trunk/src/orxonox/infos/PlayerInfo.cc

    r7163 r8327  
    3232
    3333#include "core/CoreIncludes.h"
    34 #include "network/ClientInformation.h"
     34// #include "network/ClientInformation.h"
    3535#include "gametypes/Gametype.h"
    3636#include "worldentities/ControllableEntity.h"
     
    4343        RegisterObject(PlayerInfo);
    4444
    45         this->clientID_ = CLIENTID_UNKNOWN;
     45        this->clientID_ = NETWORK_PEER_ID_UNKNOWN;
    4646        this->bHumanPlayer_ = false;
    4747        this->bLocalPlayer_ = false;
Note: See TracChangeset for help on using the changeset viewer.