Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 10, 2018, 3:06:55 PM (6 years ago)
Author:
merholzl
Message:

Merged Masterserver, refresh button had to be removed

Location:
code/branches/mergeFS18
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/mergeFS18

  • code/branches/mergeFS18/src/libraries/network/ServerConnection.cc

    r11071 r12027  
    3636#include "util/Output.h"
    3737#include <util/Sleep.h>
    38 // #include "ClientInformation.h"
    3938
    4039namespace orxonox
    4140{
    42 
     41  /**
     42   * Constructor
     43   */
    4344  ServerConnection::ServerConnection():
    4445    bListening_(false)
    4546  {
    4647    this->bindAddress_ = new ENetAddress();
    47 //     memset(this->bindAddress_, 0, sizeof(ENetAddress));
    4848    this->bindAddress_->host = ENET_HOST_ANY;
    4949    this->bindAddress_->port = NETWORK_PORT;
     
    5151  }
    5252
     53  /**
     54   * Destructor
     55   */
    5356  ServerConnection::~ServerConnection()
    5457  {
    55     if ( this->bListening_ )
    56       closeListener();
     58    if (this->bListening_)
     59    {
     60      this->closeListener();
     61    }
    5762    delete this->bindAddress_;
    5863  }
    5964
    60   void ServerConnection::setBindAddress( const std::string& bindAddress )
     65  /**
     66   * Set address on which to listen.
     67   * @param bindAddress The address on which to listen
     68   */
     69  void ServerConnection::setBindAddress(const std::string& bindAddress)
    6170  {
    62     if (enet_address_set_host (this->bindAddress_, bindAddress.c_str()) < 0)
    63         orxout(internal_error, context::network) << "Could not resolve \"" << bindAddress << "\"." << endl;
     71    if (enet_address_set_host(this->bindAddress_, bindAddress.c_str()) < 0)
     72    {
     73      orxout(internal_error, context::network) << "Could not resolve \"" << bindAddress << "\"." << endl;
     74    }
    6475  }
    6576
    66   void ServerConnection::setPort( unsigned int port ) {
     77  /**
     78   * Set port on which to listen on.
     79   * @param port The port on which to listen on.
     80   */
     81  void ServerConnection::setPort(unsigned int port) {
    6782      this->bindAddress_->port = port;
    6883  }
     
    7388    this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, NETWORK_CHANNEL_COUNT, 0, 0);
    7489   
    75     if ( this->host_ == nullptr )
     90    if (this->host_ == nullptr)
    7691    {
    7792        orxout(internal_error, context::network) << "ServerConnection: host_ == nullptr" << endl;
     
    8196    // enable compression
    8297    this->enableCompression();
     98
     99    // ensure that either IPv4 or IPv6 succeeded
    83100    assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL );
     101
    84102    if (this->host_->socket4 == ENET_SOCKET_NULL)
     103    {
    85104        orxout(internal_warning, context::network) << "IPv4 Socket failed." << endl;
     105    }
    86106    else if (this->host_->socket6 == ENET_SOCKET_NULL)
     107    {
    87108        orxout(internal_warning, context::network) << "IPv6 Socket failed." << endl;
     109    }
    88110    else
     111    {
    89112        orxout(internal_info, context::network) << "Using IPv4 and IPv6 Sockets." << endl;
     113    }
    90114   
    91115    // start communication thread
     
    95119  }
    96120
     121  /**
     122   * Stop listening.
     123   */
    97124  bool ServerConnection::closeListener()
    98125  {
    99     this->bListening_=false;
    100     disconnectClients();
     126    this->bListening_ = false;
     127    this->disconnectClients();
    101128    Connection::stopCommunicationThread();
    102129    enet_host_destroy(this->host_);
     
    104131  }
    105132
     133  /**
     134   * Add outgoing packet to queue.
     135   * @param packet The packet to send
     136   * @param clientID The ID of the recipient
     137   * @param channelID The channel ID
     138   */
    106139  void ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID, uint8_t channelID)
    107140  {
    108     if ( clientID == NETWORK_PEER_ID_BROADCAST )
     141    if (clientID == NETWORK_PEER_ID_BROADCAST)
    109142    {
    110       broadcastPacket(packet, channelID);
     143      this->broadcastPacket(packet, channelID);
    111144    }
    112145    else
    113146    {
    114 //       ClientInformation *temp = ClientInformation::findClient(clientID);
    115 //       if(!temp){
    116 //         orxout(internal_warning, context::network) << "C.Man: addPacket findClient failed" << endl;
    117 //       }
    118147      Connection::addPacket(packet, clientID, channelID);
    119148    }
    120149  }
    121150
    122 //   void ServerConnection::disconnectClient(ClientInformation *client)
    123 //   {
    124 //     Connection::disconnectPeer( client->getPeer() );
    125 //   }
    126 
     151  /**
     152   * Terminate connection with a peer.
     153   * @param clientID The peer with which to terminate the connection.
     154   */
    127155  void ServerConnection::disconnectClient(int clientID)
    128156  {
    129 //     ClientInformation *client = ClientInformation::findClient(clientID);
    130 //     if(client)
    131157    Connection::disconnectPeer(clientID);
    132158  }
    133159
     160  /**
     161   * Disconnect all peers.
     162   */
    134163  void ServerConnection::disconnectClients()
    135164  {
     
    138167    return;
    139168  }
    140 
    141 
    142 //   int ServerConnection::getClientID(ENetPeer* peer)
    143 //   {
    144 //     return getClientID(&(peer->address));
    145 //   }
    146 
    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 //   }
    156 
    157 
    158169}
Note: See TracChangeset for help on using the changeset viewer.