- Timestamp:
- Dec 17, 2010, 10:41:24 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network5/src/libraries/network/ServerConnection.cc
r7459 r7772 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() { 68 bool ServerConnection::openListener() 69 { 67 70 this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0, 0); 68 71 if ( this->host_ == NULL ) … … 78 81 else 79 82 COUT(3) << "Info: Using IPv4 and IPv6 Sockets." << std::endl; 83 84 Connection::startCommunicationThread(); 80 85 81 86 return true; 82 87 } 83 88 84 bool ServerConnection::closeListener() { 89 bool ServerConnection::closeListener() 90 { 85 91 this->bListening_=false; 86 92 disconnectClients(); … … 89 95 } 90 96 91 bool ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID) { 97 void ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID, uint8_t channelID) 98 { 92 99 if ( clientID == CLIENTID_UNKNOWN ) 93 100 { 94 return addPacketAll(packet);101 broadcastPacket(packet, channelID); 95 102 } 96 103 else … … 99 106 if(!temp){ 100 107 COUT(3) << "C.Man: addPacket findClient failed" << std::endl; 101 return false;102 108 } 103 return Connection::addPacket(packet, temp->getPeer());109 Connection::addPacket(packet, temp->getPeer(), channelID); 104 110 } 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 111 } 113 112 … … 117 116 } 118 117 119 void ServerConnection::disconnectClient(int clientID){ 118 void ServerConnection::disconnectClient(int clientID) 119 { 120 120 ClientInformation *client = ClientInformation::findClient(clientID); 121 121 if(client) … … 123 123 } 124 124 125 void ServerConnection::disconnectClients() {126 ENetEvent event;125 void ServerConnection::disconnectClients() 126 { 127 127 ClientInformation *temp = ClientInformation::getBegin(); 128 while(temp!=0){ 128 while(temp!=0) 129 { 129 130 ServerConnection::disconnectClient( temp ); 130 131 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 132 } 150 133 return; … … 152 135 153 136 154 int ServerConnection::getClientID(ENetPeer* peer) { 137 int ServerConnection::getClientID(ENetPeer* peer) 138 { 155 139 return getClientID(&(peer->address)); 156 140 } 157 141 158 int ServerConnection::getClientID(ENetAddress* address) { 142 int ServerConnection::getClientID(ENetAddress* address) 143 { 159 144 return ClientInformation::findClient(address)->getID(); 160 145 } 161 146 162 ENetPeer *ServerConnection::getClientPeer(int clientID) { 147 ENetPeer *ServerConnection::getClientPeer(int clientID) 148 { 163 149 return ClientInformation::findClient(clientID)->getPeer(); 164 150 }
Note: See TracChangeset
for help on using the changeset viewer.