Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 4, 2008, 9:45:05 PM (16 years ago)
Author:
scheusso
Message:

further changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/ConnectionManager.cc

    r1699 r1705  
    5151#include "ConnectionManager.h"
    5252#include "Synchronisable.h"
     53#include "packet/ClassID.h"
    5354
    5455namespace std
     
    7576    bindAddress.port = NETWORK_PORT;
    7677  }
    77   boost::recursive_mutex ConnectionManager::enet_mutex_;
     78  boost::recursive_mutex ConnectionManager::enet_mutex;
    7879 
    7980//   ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) {
     
    172173 
    173174  bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer) {
    174     boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex_);
     175    boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex);
    175176    if(enet_peer_send(peer, NETWORK_DEFAULT_CHANNEL, packet)!=0)
    176177      return false;
     
    190191    if(!instance_)
    191192      return false;
    192     boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex_);
     193    boost::recursive_mutex::scoped_lock lock(instance_->enet_mutex);
    193194    for(ClientInformation *i=ClientInformation::getBegin()->next(); i!=0; i=i->next()){
    194195      COUT(3) << "adding broadcast packet for client: " << i->getID() << std::endl;
     
    203204    if(server==NULL || !instance_)
    204205      return false;
    205     boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     206    boost::recursive_mutex::scoped_lock lock(enet_mutex);
    206207    enet_host_flush(server);
    207208    lock.unlock();
     
    214215    atexit(enet_deinitialize);
    215216    { //scope of the mutex
    216       boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     217      boost::recursive_mutex::scoped_lock lock(enet_mutex);
    217218      enet_initialize();
    218219      server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
     
    228229    while(!quit){
    229230      { //mutex scope
    230         boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     231        boost::recursive_mutex::scoped_lock lock(enet_mutex);
    231232        if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
    232233          // we should never reach this point
     
    270271    // if we're finishied, destroy server
    271272    {
    272       boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     273      boost::recursive_mutex::scoped_lock lock(enet_mutex);
    273274      enet_host_destroy(server);
    274275      lock.unlock();
     
    284285    while(temp!=0){
    285286      {
    286         boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     287        boost::recursive_mutex::scoped_lock lock(enet_mutex);
    287288        enet_peer_disconnect(temp->getPeer(), 0);
    288289        lock.unlock();
     
    292293    //bugfix: might be the reason why server crashes when clients disconnects
    293294    temp = ClientInformation::getBegin()->next();
    294     boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     295    boost::recursive_mutex::scoped_lock lock(enet_mutex);
    295296    while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) >= 0){
    296297      switch (event.type)
     
    337338    std::string classname;
    338339    orxonox::Identifier *id;
     340    packet::Packet packet;
     341    packet.setClientID(clientID);
     342    packet::ClassID *classid;
    339343    std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactoryBegin();
    340344    while(it != orxonox::Factory::getFactoryEnd()){
     
    348352      COUT(4) << "Con.Man:syncClassid:\tnetwork_id: " << network_id << ", classname: " << classname << std::endl;
    349353
    350       while(!addPacket(packet_gen.clid( (int)network_id, classname ), clientID) && failures < 10){
     354      classid = new packet::ClassID(network_id, classname);
     355      packet.setPacketContent(classid);
     356      while(!packet.send() && failures < 10){
    351357        failures++;
    352358      }
     359      delete classid;
    353360      ++it;
    354361    }
     362    packet.setPacketContent(0);
    355363    //sendPackets();
    356364    COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;
     
    370378  }
    371379 
    372   bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){
    373     if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){
    374       //sendPackets();
    375       return true;
    376     }else
    377       return false;
    378   }
    379380 
    380381  void ConnectionManager::disconnectClient(ClientInformation *client){
    381382    {
    382       boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     383      boost::recursive_mutex::scoped_lock lock(enet_mutex);
    383384      enet_peer_disconnect(client->getPeer(), 0);
    384385      lock.unlock();
     
    387388  }
    388389 
    389   bool ConnectionManager::addFakeConnectRequest(ENetEvent *ev){
    390     ENetEvent event;
    391     event.peer=ev->peer;
    392     event.packet = packet_gen.generateConnectRequest();
    393     return buffer.push(&event);
    394   }
    395  
    396  
    397390
    398391}
Note: See TracChangeset for help on using the changeset viewer.