Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 17, 2010, 10:41:24 AM (14 years ago)
Author:
scheusso
Message:

network is now multithreaded again
further testing needed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network5/src/libraries/network/ServerConnection.cc

    r7459 r7772  
    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() {
     68  bool ServerConnection::openListener()
     69  {
    6770    this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0, 0);
    6871    if ( this->host_ == NULL )
     
    7881    else
    7982        COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl;
     83   
     84    Connection::startCommunicationThread();
    8085
    8186    return true;
    8287  }
    8388
    84   bool ServerConnection::closeListener() {
     89  bool ServerConnection::closeListener()
     90  {
    8591    this->bListening_=false;
    8692    disconnectClients();
     
    8995  }
    9096
    91   bool ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID) {
     97  void ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID, uint8_t channelID)
     98  {
    9299    if ( clientID == CLIENTID_UNKNOWN )
    93100    {
    94       return addPacketAll(packet);
     101      broadcastPacket(packet, channelID);
    95102    }
    96103    else
     
    99106      if(!temp){
    100107        COUT(3) << "C.Man: addPacket findClient failed" << std::endl;
    101         return false;
    102108      }
    103       return Connection::addPacket(packet, temp->getPeer());
     109      Connection::addPacket(packet, temp->getPeer(), channelID);
    104110    }
    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;
    112111  }
    113112
     
    117116  }
    118117
    119   void ServerConnection::disconnectClient(int clientID){
     118  void ServerConnection::disconnectClient(int clientID)
     119  {
    120120    ClientInformation *client = ClientInformation::findClient(clientID);
    121121    if(client)
     
    123123  }
    124124
    125   void ServerConnection::disconnectClients() {
    126     ENetEvent event;
     125  void ServerConnection::disconnectClients()
     126  {
    127127    ClientInformation *temp = ClientInformation::getBegin();
    128     while(temp!=0){
     128    while(temp!=0)
     129    {
    129130      ServerConnection::disconnectClient( temp );
    130131      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       }
    149132    }
    150133    return;
     
    152135
    153136
    154   int ServerConnection::getClientID(ENetPeer* peer) {
     137  int ServerConnection::getClientID(ENetPeer* peer)
     138  {
    155139    return getClientID(&(peer->address));
    156140  }
    157141
    158   int ServerConnection::getClientID(ENetAddress* address) {
     142  int ServerConnection::getClientID(ENetAddress* address)
     143  {
    159144    return ClientInformation::findClient(address)->getID();
    160145  }
    161146
    162   ENetPeer *ServerConnection::getClientPeer(int clientID) {
     147  ENetPeer *ServerConnection::getClientPeer(int clientID)
     148  {
    163149    return ClientInformation::findClient(clientID)->getPeer();
    164150  }
Note: See TracChangeset for help on using the changeset viewer.