Changeset 3201
- Timestamp:
- Jun 20, 2009, 7:21:46 PM (15 years ago)
- Location:
- code/branches/netp5/src/network
- Files:
-
- 4 added
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/netp5/src/network/CMakeLists.txt
r3196 r3201 24 24 ClientInformation.cc 25 25 ClientConnectionListener.cc 26 Connection Manager.cc26 Connection.cc 27 27 FunctionCallManager.cc 28 28 GamestateManager.cc … … 33 33 PacketBuffer.cc 34 34 Server.cc 35 ServerConnection.cc 35 36 TrafficControl.cc 36 37 ) -
code/branches/netp5/src/network/NetworkPrereqs.h
r3084 r3201 89 89 class ClientFrameListener; 90 90 class ClientInformation; 91 class Connection Manager;91 class Connection; 92 92 class FunctionCallManager; 93 93 class GamestateClient; … … 104 104 class PacketBuffer; 105 105 class Server; 106 class ServerConnection; 106 107 class ServerFrameListener; 107 108 class Synchronisable; -
code/branches/netp5/src/network/Server.cc
r3198 r3201 46 46 47 47 48 #include "ConnectionManager.h"48 // #include "ConnectionManager.h" 49 49 #include "ClientConnectionListener.h" 50 50 #include "GamestateManager.h" … … 58 58 #include "packet/Welcome.h" 59 59 #include "packet/DeleteObjects.h" 60 #include "packet/ClassID.h" 60 61 #include "util/Convert.h" 61 62 #include "ChatListener.h" … … 74 75 Server::Server() { 75 76 timeSinceLastUpdate_=0; 76 connection = new ConnectionManager();77 77 gamestates_ = new GamestateManager(); 78 78 } 79 79 80 80 Server::Server(int port){ 81 this->setPort( port ); 81 82 timeSinceLastUpdate_=0; 82 connection = new ConnectionManager(port);83 83 gamestates_ = new GamestateManager(); 84 84 } … … 90 90 */ 91 91 Server::Server(int port, const std::string& bindAddress) { 92 this->setPort( port ); 93 this->setBindAddress( bindAddress ); 92 94 timeSinceLastUpdate_=0; 93 connection = new ConnectionManager(port, bindAddress);94 95 gamestates_ = new GamestateManager(); 95 96 } 96 97 97 98 /** 98 * Constructor99 * @param port Port to listen on100 * @param bindAddress Address to listen on101 */102 Server::Server(int port, const char *bindAddress) {103 timeSinceLastUpdate_=0;104 connection = new ConnectionManager(port, bindAddress);105 gamestates_ = new GamestateManager();106 }107 108 /**109 99 * @brief Destructor 110 100 */ 111 101 Server::~Server(){ 112 if(connection)113 delete connection;114 102 if(gamestates_) 115 103 delete gamestates_; … … 120 108 */ 121 109 void Server::open() { 122 connection->createListener(); 110 COUT(4) << "opening server" << endl; 111 this->openListener(); 123 112 return; 124 113 } … … 128 117 */ 129 118 void Server::close() { 130 ClientInformation *temp = ClientInformation::getBegin(); 131 ClientInformation *temp2; 132 // disconnect all connected clients 133 while( temp ) 134 { 135 temp2 = temp; 136 temp = temp->next(); 137 disconnectClient( temp2 ); 138 } 139 connection->quitListener(); 119 COUT(4) << "closing server" << endl; 120 this->disconnectClients(); 121 this->closeListener(); 140 122 return; 141 123 } … … 162 144 */ 163 145 void Server::update(const Clock& time) { 164 processQueue();146 ServerConnection::processQueue(); 165 147 gamestates_->processGamestates(); 166 148 //this steers our network frequency … … 174 156 175 157 bool Server::queuePacket(ENetPacket *packet, int clientID){ 176 return connection->addPacket(packet, clientID);158 return ServerConnection::addPacket(packet, clientID); 177 159 } 178 160 … … 191 173 assert(ClientInformation::findClient(clientID)); 192 174 return ClientInformation::findClient(clientID)->getPacketLoss(); 193 }194 195 /**196 * processes all the packets waiting in the queue197 */198 void Server::processQueue() {199 ENetEvent *event;200 while(!connection->queueEmpty()){201 //std::cout << "Client " << clientID << " sent: " << std::endl;202 //clientID here is a reference to grab clientID from ClientInformation203 event = connection->getEvent();204 if(!event)205 continue;206 assert(event->type != ENET_EVENT_TYPE_NONE);207 switch( event->type ) {208 case ENET_EVENT_TYPE_CONNECT:209 COUT(4) << "processing event_Type_connect" << std::endl;210 addClient(event);211 break;212 case ENET_EVENT_TYPE_DISCONNECT:213 if(ClientInformation::findClient(&event->peer->address))214 disconnectClient(event);215 break;216 case ENET_EVENT_TYPE_RECEIVE:217 if(!processPacket(event->packet, event->peer))218 COUT(3) << "processing incoming packet failed" << std::endl;219 break;220 default:221 break;222 }223 delete event;224 //if statement to catch case that packetbuffer is empty225 }226 175 } 227 176 … … 318 267 319 268 320 boolServer::addClient(ENetEvent *event){269 void Server::addClient(ENetEvent *event){ 321 270 static unsigned int newid=1; 322 271 … … 325 274 if(!temp){ 326 275 COUT(2) << "Server: could not add client" << std::endl; 327 return false; 328 } 329 /*if(temp==ClientInformation::getBegin()) { //not good if you use anything else than insertBack 330 newid=1; 331 } 332 else 333 newid=temp->prev()->getID()+1;*/ 276 } 334 277 temp->setID(newid); 335 278 temp->setPeer(event->peer); … … 342 285 } 343 286 344 newid++;287 ++newid; 345 288 346 289 COUT(3) << "Server: added client id: " << temp->getID() << std::endl; 347 returncreateClient(temp->getID());290 createClient(temp->getID()); 348 291 } 349 292 … … 357 300 358 301 // synchronise class ids 359 connection->syncClassid(temp->getID());302 syncClassid(temp->getID()); 360 303 361 304 // now synchronise functionIDs … … 382 325 return true; 383 326 } 384 385 bool Server::disconnectClient(ENetEvent *event){386 COUT(4) << "removing client from list" << std::endl;387 //return removeClient(head_->findClient(&(peer->address))->getID());388 389 //boost::recursive_mutex::scoped_lock lock(head_->mutex_);390 ClientInformation *client = ClientInformation::findClient(&event->peer->address);391 if(!client)392 return false;393 else394 disconnectClient( client );395 return true;396 }397 398 void Server::disconnectClient(int clientID){399 ClientInformation *client = ClientInformation::findClient(clientID);400 if(client)401 disconnectClient(client);402 }403 327 404 void Server::disconnectClient( ClientInformation *client ){405 connection->disconnectClient(client);328 void Server::disconnectClient( ClientInformation *client ){ 329 ServerConnection::disconnectClient( client ); 406 330 gamestates_->removeClient(client); 407 331 // inform all the listeners … … 439 363 } 440 364 365 void Server::syncClassid(unsigned int clientID) { 366 int failures=0; 367 packet::ClassID *classid = new packet::ClassID(); 368 classid->setClientID(clientID); 369 while(!classid->send() && failures < 10){ 370 failures++; 371 } 372 assert(failures<10); 373 COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl; 374 } 375 441 376 } -
code/branches/netp5/src/network/Server.h
r3084 r3201 35 35 36 36 #include "Host.h" 37 #include "ServerConnection.h" 37 38 #include "GamestateManager.h" 38 39 … … 44 45 * It implements all functions necessary for a Server 45 46 */ 46 class _NetworkExport Server : public Host {47 class _NetworkExport Server : public Host, public ServerConnection{ 47 48 public: 48 49 Server(); 49 50 Server(int port); 50 51 Server(int port, const std::string& bindAddress); 51 Server(int port, const char *bindAddress);52 52 ~Server(); 53 53 … … 60 60 double getPacketLoss(unsigned int clientID); 61 61 protected: 62 void processQueue();63 62 void updateGamestate(); 64 63 private: … … 67 66 unsigned int playerID(){return 0;} 68 67 69 booladdClient(ENetEvent *event);68 void addClient(ENetEvent *event); 70 69 bool createClient(int clientID); 71 bool disconnectClient(ENetEvent *event);72 void disconnectClient(int clientID);73 70 void disconnectClient( ClientInformation *client); 74 71 bool processPacket( ENetPacket *packet, ENetPeer *peer ); … … 78 75 virtual bool broadcast(const std::string& message); 79 76 bool sendChat(const std::string& message, unsigned int clientID); 77 void syncClassid(unsigned int clientID); 80 78 81 //void processChat( chat *data, int clientId);82 ConnectionManager *connection;83 79 GamestateManager *gamestates_; 84 80
Note: See TracChangeset
for help on using the changeset viewer.