Changeset 7163 for code/trunk/src/libraries/network/Server.cc
- Timestamp:
- Aug 11, 2010, 8:55:13 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/network/Server.cc
r6417 r7163 69 69 * 70 70 */ 71 Server::Server() { 71 Server::Server() 72 { 72 73 this->timeSinceLastUpdate_=0; 73 74 } 74 75 75 Server::Server(int port){ 76 Server::Server(int port) 77 { 76 78 this->setPort( port ); 77 79 this->timeSinceLastUpdate_=0; … … 83 85 * @param bindAddress Address to listen on 84 86 */ 85 Server::Server(int port, const std::string& bindAddress) { 87 Server::Server(int port, const std::string& bindAddress) 88 { 86 89 this->setPort( port ); 87 90 this->setBindAddress( bindAddress ); … … 92 95 * @brief Destructor 93 96 */ 94 Server::~Server(){ 97 Server::~Server() 98 { 95 99 } 96 100 … … 98 102 * This function opens the server by creating the listener thread 99 103 */ 100 void Server::open() { 104 void Server::open() 105 { 106 Host::setActive(true); 101 107 COUT(4) << "opening server" << endl; 102 108 this->openListener(); 109 LANDiscoverable::setActivity(true); 103 110 return; 104 111 } … … 107 114 * This function closes the server 108 115 */ 109 void Server::close() { 116 void Server::close() 117 { 118 Host::setActive(false); 110 119 COUT(4) << "closing server" << endl; 111 120 this->disconnectClients(); 112 121 this->closeListener(); 122 LANDiscoverable::setActivity(false); 113 123 return; 114 124 } 115 125 116 bool Server::processChat(const std::string& message, unsigned int playerID){ 126 bool Server::processChat(const std::string& message, unsigned int playerID) 127 { 117 128 ClientInformation *temp = ClientInformation::getBegin(); 118 129 packet::Chat *chat; … … 134 145 * @param time time since last tick 135 146 */ 136 void Server::update(const Clock& time) { 147 void Server::update(const Clock& time) 148 { 137 149 // receive incoming packets 138 150 Connection::processQueue(); 151 // receive and process incoming discovery packets 152 LANDiscoverable::update(); 139 153 140 154 if ( ClientInformation::hasClients() ) … … 157 171 } 158 172 159 bool Server::queuePacket(ENetPacket *packet, int clientID){ 173 bool Server::queuePacket(ENetPacket *packet, int clientID) 174 { 160 175 return ServerConnection::addPacket(packet, clientID); 161 176 } … … 164 179 * @brief: returns ping time to client in milliseconds 165 180 */ 166 unsigned int Server::getRTT(unsigned int clientID){ 181 unsigned int Server::getRTT(unsigned int clientID) 182 { 167 183 assert(ClientInformation::findClient(clientID)); 168 184 return ClientInformation::findClient(clientID)->getRTT(); … … 178 194 * @brief: return packet loss ratio to client (scales from 0 to 1) 179 195 */ 180 double Server::getPacketLoss(unsigned int clientID){ 196 double Server::getPacketLoss(unsigned int clientID) 197 { 181 198 assert(ClientInformation::findClient(clientID)); 182 199 return ClientInformation::findClient(clientID)->getPacketLoss(); … … 186 203 * takes a new snapshot of the gamestate and sends it to the clients 187 204 */ 188 void Server::updateGamestate() { 205 void Server::updateGamestate() 206 { 189 207 if( ClientInformation::getBegin()==NULL ) 190 208 //no client connected … … 208 226 * sends the gamestate 209 227 */ 210 bool Server::sendGameState() { 228 bool Server::sendGameState() 229 { 211 230 // COUT(5) << "Server: starting function sendGameState" << std::endl; 212 231 // ClientInformation *temp = ClientInformation::getBegin(); … … 244 263 } 245 264 246 bool Server::sendObjectDeletes(){ 265 bool Server::sendObjectDeletes() 266 { 247 267 ClientInformation *temp = ClientInformation::getBegin(); 248 268 if( temp == NULL ) … … 257 277 // COUT(3) << "sending DeleteObjects" << std::endl; 258 278 while(temp != NULL){ 259 if( !(temp->getSynched()) ){ 279 if( !(temp->getSynched()) ) 280 { 260 281 COUT(5) << "Server: not sending gamestate" << std::endl; 261 282 temp=temp->next(); … … 276 297 277 298 278 void Server::addPeer(ENetEvent *event){ 299 void Server::addPeer(ENetEvent *event) 300 { 279 301 static unsigned int newid=1; 280 302 281 303 COUT(2) << "Server: adding client" << std::endl; 282 304 ClientInformation *temp = ClientInformation::insertBack(new ClientInformation); 283 if(!temp){ 305 if(!temp) 306 { 284 307 COUT(2) << "Server: could not add client" << std::endl; 285 308 } … … 310 333 } 311 334 312 bool Server::createClient(int clientID){ 335 bool Server::createClient(int clientID) 336 { 313 337 ClientInformation *temp = ClientInformation::findClient(clientID); 314 if(!temp){ 338 if(!temp) 339 { 315 340 COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl; 316 341 return false; … … 345 370 } 346 371 347 void Server::disconnectClient( ClientInformation *client ){ 372 void Server::disconnectClient( ClientInformation *client ) 373 { 348 374 ServerConnection::disconnectClient( client ); 349 375 GamestateManager::removeClient(client); … … 352 378 } 353 379 354 bool Server::chat(const std::string& message){ 380 bool Server::chat(const std::string& message) 381 { 355 382 return this->sendChat(message, Host::getPlayerID()); 356 383 } 357 384 358 bool Server::broadcast(const std::string& message){ 385 bool Server::broadcast(const std::string& message) 386 { 359 387 return this->sendChat(message, CLIENTID_UNKNOWN); 360 388 } 361 389 362 bool Server::sendChat(const std::string& message, unsigned int clientID){ 390 bool Server::sendChat(const std::string& message, unsigned int clientID) 391 { 363 392 ClientInformation *temp = ClientInformation::getBegin(); 364 393 packet::Chat *chat; 365 while(temp){ 394 while(temp) 395 { 366 396 chat = new packet::Chat(message, clientID); 367 397 chat->setClientID(temp->getID()); … … 377 407 } 378 408 379 void Server::syncClassid(unsigned int clientID) { 409 void Server::syncClassid(unsigned int clientID) 410 { 380 411 int failures=0; 381 412 packet::ClassID *classid = new packet::ClassID();
Note: See TracChangeset
for help on using the changeset viewer.