Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 22, 2010, 7:24:24 PM (13 years ago)
Author:
dafrick
Message:

Merging presentation2 branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/network/ServerConnection.cc

    r7459 r7801  
    4949  }
    5050
    51   ServerConnection::~ServerConnection(){
     51  ServerConnection::~ServerConnection()
     52  {
    5253    if ( this->bListening_ )
    5354      closeListener();
     
    5556  }
    5657
    57   void ServerConnection::setBindAddress( const std::string& bindAddress ) {
     58  void ServerConnection::setBindAddress( const std::string& bindAddress )
     59  {
    5860    if (enet_address_set_host (this->bindAddress_, bindAddress.c_str()) < 0)
    5961        COUT(1) << "Error: Could not resolve \"" << bindAddress << "\"." << std::endl;
     
    6466  }
    6567
    66   bool ServerConnection::openListener() {
    67     this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0, 0);
     68  bool ServerConnection::openListener()
     69  {
     70    // create host
     71    this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, NETWORK_CHANNEL_COUNT, 0, 0);
     72   
    6873    if ( this->host_ == NULL )
    6974    {
     
    7176        return false;
    7277    }
     78   
     79    // enable compression
     80    this->enableCompression();
    7381    assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL );
    7482    if (this->host_->socket4 == ENET_SOCKET_NULL)
     
    7886    else
    7987        COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl;
     88   
     89    // start communication thread
     90    Connection::startCommunicationThread();
    8091
    8192    return true;
    8293  }
    8394
    84   bool ServerConnection::closeListener() {
     95  bool ServerConnection::closeListener()
     96  {
    8597    this->bListening_=false;
    8698    disconnectClients();
     99    Connection::stopCommunicationThread();
    87100    enet_host_destroy(this->host_);
    88101    return true;
    89102  }
    90103
    91   bool ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID) {
     104  void ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID, uint8_t channelID)
     105  {
    92106    if ( clientID == CLIENTID_UNKNOWN )
    93107    {
    94       return addPacketAll(packet);
     108      broadcastPacket(packet, channelID);
    95109    }
    96110    else
     
    99113      if(!temp){
    100114        COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
    101         return false;
    102115      }
    103       return Connection::addPacket(packet, temp->getPeer());
     116      Connection::addPacket(packet, temp->getPeer(), channelID);
    104117    }
    105   }
    106 
    107   bool ServerConnection::addPacketAll(ENetPacket *packet) {
    108 //     if ( !Connection::getInstance() )
    109 //       return false;
    110     enet_host_broadcast( Connection::getHost(), 0, packet);
    111     return true;
    112118  }
    113119
     
    117123  }
    118124
    119   void ServerConnection::disconnectClient(int clientID){
     125  void ServerConnection::disconnectClient(int clientID)
     126  {
    120127    ClientInformation *client = ClientInformation::findClient(clientID);
    121128    if(client)
     
    123130  }
    124131
    125   void ServerConnection::disconnectClients() {
    126     ENetEvent event;
     132  void ServerConnection::disconnectClients()
     133  {
    127134    ClientInformation *temp = ClientInformation::getBegin();
    128     while(temp!=0){
     135    while(temp!=0)
     136    {
    129137      ServerConnection::disconnectClient( temp );
    130138      temp = temp->next();
    131     }
    132     temp = ClientInformation::getBegin();
    133     while( temp!=0 ){
    134       if( service( &event ) )
    135       {
    136         switch (event.type)
    137         {
    138         case ENET_EVENT_TYPE_NONE: break;
    139         case ENET_EVENT_TYPE_CONNECT: break;
    140         case ENET_EVENT_TYPE_RECEIVE:
    141           enet_packet_destroy(event.packet);
    142           break;
    143         case ENET_EVENT_TYPE_DISCONNECT:
    144           removePeer( &event );
    145           temp = ClientInformation::getBegin();
    146           break;
    147         }
    148       }
    149139    }
    150140    return;
     
    152142
    153143
    154   int ServerConnection::getClientID(ENetPeer* peer) {
     144  int ServerConnection::getClientID(ENetPeer* peer)
     145  {
    155146    return getClientID(&(peer->address));
    156147  }
    157148
    158   int ServerConnection::getClientID(ENetAddress* address) {
     149  int ServerConnection::getClientID(ENetAddress* address)
     150  {
    159151    return ClientInformation::findClient(address)->getID();
    160152  }
    161153
    162   ENetPeer *ServerConnection::getClientPeer(int clientID) {
     154  ENetPeer *ServerConnection::getClientPeer(int clientID)
     155  {
    163156    return ClientInformation::findClient(clientID)->getPeer();
    164157  }
Note: See TracChangeset for help on using the changeset viewer.