- Timestamp:
- Oct 10, 2018, 3:06:55 PM (6 years ago)
- Location:
- code/branches/mergeFS18
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/mergeFS18
- Property svn:mergeinfo changed
/code/branches/Masterserver_FS18 (added) merged: 11816,11829,11842,11856,11858,11880,11889,11905,11907,11910,11929-11930,11937,11962-11963,11973,11983,11990
- Property svn:mergeinfo changed
-
code/branches/mergeFS18/src/libraries/network/ServerConnection.cc
r11071 r12027 36 36 #include "util/Output.h" 37 37 #include <util/Sleep.h> 38 // #include "ClientInformation.h"39 38 40 39 namespace orxonox 41 40 { 42 41 /** 42 * Constructor 43 */ 43 44 ServerConnection::ServerConnection(): 44 45 bListening_(false) 45 46 { 46 47 this->bindAddress_ = new ENetAddress(); 47 // memset(this->bindAddress_, 0, sizeof(ENetAddress));48 48 this->bindAddress_->host = ENET_HOST_ANY; 49 49 this->bindAddress_->port = NETWORK_PORT; … … 51 51 } 52 52 53 /** 54 * Destructor 55 */ 53 56 ServerConnection::~ServerConnection() 54 57 { 55 if ( this->bListening_ ) 56 closeListener(); 58 if (this->bListening_) 59 { 60 this->closeListener(); 61 } 57 62 delete this->bindAddress_; 58 63 } 59 64 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) 61 70 { 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 } 64 75 } 65 76 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) { 67 82 this->bindAddress_->port = port; 68 83 } … … 73 88 this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, NETWORK_CHANNEL_COUNT, 0, 0); 74 89 75 if ( this->host_ == nullptr)90 if (this->host_ == nullptr) 76 91 { 77 92 orxout(internal_error, context::network) << "ServerConnection: host_ == nullptr" << endl; … … 81 96 // enable compression 82 97 this->enableCompression(); 98 99 // ensure that either IPv4 or IPv6 succeeded 83 100 assert( this->host_->socket4 != ENET_SOCKET_NULL || this->host_->socket6 != ENET_SOCKET_NULL ); 101 84 102 if (this->host_->socket4 == ENET_SOCKET_NULL) 103 { 85 104 orxout(internal_warning, context::network) << "IPv4 Socket failed." << endl; 105 } 86 106 else if (this->host_->socket6 == ENET_SOCKET_NULL) 107 { 87 108 orxout(internal_warning, context::network) << "IPv6 Socket failed." << endl; 109 } 88 110 else 111 { 89 112 orxout(internal_info, context::network) << "Using IPv4 and IPv6 Sockets." << endl; 113 } 90 114 91 115 // start communication thread … … 95 119 } 96 120 121 /** 122 * Stop listening. 123 */ 97 124 bool ServerConnection::closeListener() 98 125 { 99 this->bListening_ =false;100 disconnectClients();126 this->bListening_ = false; 127 this->disconnectClients(); 101 128 Connection::stopCommunicationThread(); 102 129 enet_host_destroy(this->host_); … … 104 131 } 105 132 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 */ 106 139 void ServerConnection::addPacket(ENetPacket *packet, unsigned int clientID, uint8_t channelID) 107 140 { 108 if ( clientID == NETWORK_PEER_ID_BROADCAST)141 if (clientID == NETWORK_PEER_ID_BROADCAST) 109 142 { 110 broadcastPacket(packet, channelID);143 this->broadcastPacket(packet, channelID); 111 144 } 112 145 else 113 146 { 114 // ClientInformation *temp = ClientInformation::findClient(clientID);115 // if(!temp){116 // orxout(internal_warning, context::network) << "C.Man: addPacket findClient failed" << endl;117 // }118 147 Connection::addPacket(packet, clientID, channelID); 119 148 } 120 149 } 121 150 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 */ 127 155 void ServerConnection::disconnectClient(int clientID) 128 156 { 129 // ClientInformation *client = ClientInformation::findClient(clientID);130 // if(client)131 157 Connection::disconnectPeer(clientID); 132 158 } 133 159 160 /** 161 * Disconnect all peers. 162 */ 134 163 void ServerConnection::disconnectClients() 135 164 { … … 138 167 return; 139 168 } 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 158 169 }
Note: See TracChangeset
for help on using the changeset viewer.