Changeset 7801 for code/trunk/src/libraries/network/ServerConnection.cc
- Timestamp:
- Dec 22, 2010, 7:24:24 PM (13 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/network/ServerConnection.cc
r7459 r7801 49 49 } 50 50 51 ServerConnection::~ServerConnection(){ 51 ServerConnection::~ServerConnection() 52 { 52 53 if ( this->bListening_ ) 53 54 closeListener(); … … 55 56 } 56 57 57 void ServerConnection::setBindAddress( const std::string& bindAddress ) { 58 void ServerConnection::setBindAddress( const std::string& bindAddress ) 59 { 58 60 if (enet_address_set_host (this->bindAddress_, bindAddress.c_str()) < 0) 59 61 COUT(1) << "Error: Could not resolve \"" << bindAddress << "\"." << std::endl; … … 64 66 } 65 67 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 68 73 if ( this->host_ == NULL ) 69 74 { … … 71 76 return false; 72 77 } 78 79 // enable compression 80 this->enableCompression(); 73 81 assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL ); 74 82 if (this->host_->socket4 == ENET_SOCKET_NULL) … … 78 86 else 79 87 COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl; 88 89 // start communication thread 90 Connection::startCommunicationThread(); 80 91 81 92 return true; 82 93 } 83 94 84 bool ServerConnection::closeListener() { 95 bool ServerConnection::closeListener() 96 { 85 97 this->bListening_=false; 86 98 disconnectClients(); 99 Connection::stopCommunicationThread(); 87 100 enet_host_destroy(this->host_); 88 101 return true; 89 102 } 90 103 91 bool ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID) { 104 void ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID, uint8_t channelID) 105 { 92 106 if ( clientID == CLIENTID_UNKNOWN ) 93 107 { 94 return addPacketAll(packet);108 broadcastPacket(packet, channelID); 95 109 } 96 110 else … … 99 113 if(!temp){ 100 114 COUT(3) << "C.Man: addPacket findClient failed" << std::endl; 101 return false;102 115 } 103 return Connection::addPacket(packet, temp->getPeer());116 Connection::addPacket(packet, temp->getPeer(), channelID); 104 117 } 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;112 118 } 113 119 … … 117 123 } 118 124 119 void ServerConnection::disconnectClient(int clientID){ 125 void ServerConnection::disconnectClient(int clientID) 126 { 120 127 ClientInformation *client = ClientInformation::findClient(clientID); 121 128 if(client) … … 123 130 } 124 131 125 void ServerConnection::disconnectClients() {126 ENetEvent event;132 void ServerConnection::disconnectClients() 133 { 127 134 ClientInformation *temp = ClientInformation::getBegin(); 128 while(temp!=0){ 135 while(temp!=0) 136 { 129 137 ServerConnection::disconnectClient( temp ); 130 138 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 }149 139 } 150 140 return; … … 152 142 153 143 154 int ServerConnection::getClientID(ENetPeer* peer) { 144 int ServerConnection::getClientID(ENetPeer* peer) 145 { 155 146 return getClientID(&(peer->address)); 156 147 } 157 148 158 int ServerConnection::getClientID(ENetAddress* address) { 149 int ServerConnection::getClientID(ENetAddress* address) 150 { 159 151 return ClientInformation::findClient(address)->getID(); 160 152 } 161 153 162 ENetPeer *ServerConnection::getClientPeer(int clientID) { 154 ENetPeer *ServerConnection::getClientPeer(int clientID) 155 { 163 156 return ClientInformation::findClient(clientID)->getPeer(); 164 157 }
Note: See TracChangeset
for help on using the changeset viewer.