- Timestamp:
- May 24, 2008, 2:57:43 PM (16 years ago)
- Location:
- code/branches/network/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Client.cc
r1377 r1409 120 120 isConnected=client_connection.createConnection(); 121 121 if(isConnected){ 122 COUT(3) << "sending connectrequest" << std::endl;123 if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets())124 COUT(1) << "could not send connection request !!!!!!!!!" << std::endl;122 // COUT(3) << "sending connectrequest" << std::endl; 123 // if(!client_connection.addPacket(pck_gen.generateConnectRequest()) || !client_connection.sendPackets()) 124 // COUT(1) << "could not send connection request !!!!!!!!!" << std::endl; 125 125 }else 126 126 COUT(1) << "could not create connection laber" << std::endl; … … 239 239 } 240 240 } 241 ENet Packet *packet;241 ENetEvent *event; 242 242 // stop if the packet queue is empty 243 243 while(!(client_connection.queueEmpty())){ 244 packet = client_connection.getPacket();245 COUT(5) << "tick packet size " << packet->dataLength << std::endl;246 elaborate( packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)244 event = client_connection.getEvent(); 245 COUT(5) << "tick packet size " << event->packet->dataLength << std::endl; 246 elaborate(event->packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server) 247 247 } 248 248 if(!client_connection.sendPackets()) -
code/branches/network/src/network/ClientConnection.cc
r1377 r1409 75 75 76 76 77 ENetPacket *ClientConnection::getPacket(ENetAddress &address) {77 /*ENetPacket *ClientConnection::getPacket(ENetAddress &address) { 78 78 if(!buffer.isEmpty()) { 79 79 //std::cout << "###BUFFER IS NOT EMPTY###" << std::endl; … … 88 88 ENetAddress address; //sems that address is not needed 89 89 return getPacket(address); 90 }*/ 91 92 ENetEvent *ClientConnection::getEvent(){ 93 if(!buffer.isEmpty()) 94 return buffer.pop(); 95 else 96 return NULL; 90 97 } 91 98 … … 144 151 enet_initialize(); 145 152 atexit(enet_deinitialize); 146 ENetEvent event;153 ENetEvent *event; 147 154 client = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0); 148 155 if(client==NULL) { … … 159 166 //main loop 160 167 while(!quit){ 168 event = new ENetEvent; 161 169 //std::cout << "connection loop" << std::endl; 162 if(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT)<0){170 if(enet_host_service(client, event, NETWORK_CLIENT_TIMEOUT)<0){ 163 171 // we should never reach this point 164 172 quit=true; 165 173 // add some error handling here ======================== 166 174 } 167 switch(event .type){175 switch(event->type){ 168 176 // log handling ================ 169 177 case ENET_EVENT_TYPE_CONNECT: … … 171 179 case ENET_EVENT_TYPE_RECEIVE: 172 180 COUT(5) << "Cl.Con: receiver-Thread while loop: got new packet" << std::endl; 173 if ( !processData( &event) ) COUT(2) << "Current packet was not pushed to packetBuffer -> ev ongoing SegFault" << std::endl;181 if ( !processData(event) ) COUT(2) << "Current packet was not pushed to packetBuffer -> ev ongoing SegFault" << std::endl; 174 182 COUT(5) << "Cl.Con: processed Data in receiver-thread while loop" << std::endl; 175 183 break; -
code/branches/network/src/network/ClientConnection.h
r1377 r1409 63 63 ClientConnection(int port, std::string address); 64 64 ClientConnection(int port, const char* address); 65 ENetPacket *getPacket(ENetAddress &address); // thread1 66 ENetPacket *getPacket(); // thread1 65 //ENetPacket *getPacket(ENetAddress &address); // thread1 66 //ENetPacket *getPacket(); // thread1 67 ENetEvent *getEvent(); 67 68 // check wheter the packet queue is empty 68 69 bool queueEmpty(); -
code/branches/network/src/network/ConnectionManager.cc
r1389 r1409 44 44 #include "core/CoreIncludes.h" 45 45 #include "core/BaseObject.h" 46 #include "objects/SpaceShip.h" 46 47 #include "util/Math.h" 47 #include "objects/SpaceShip.h"48 48 #include "ClientInformation.h" 49 49 #include "ConnectionManager.h" … … 94 94 } 95 95 96 ENetPacket *ConnectionManager::getPacket(ENetAddress &address) {96 /*ENetPacket *ConnectionManager::getPacket(ENetAddress &address) { 97 97 if(!buffer.isEmpty()) 98 98 return buffer.pop(address); 99 99 else 100 100 return NULL; 101 } 101 }*/ 102 102 /** 103 103 This function only pops the first element in PacketBuffer (first in first out) 104 104 used by processQueue in Server.cc 105 105 */ 106 ENetPacket *ConnectionManager::getPacket(int &clientID) {106 /*ENetPacket *ConnectionManager::getPacket(int &clientID) { 107 107 ENetAddress address; 108 108 ENetPacket *packet=getPacket(address); … … 112 112 clientID=temp->getID(); 113 113 return packet; 114 }*/ 115 116 ENetEvent *ConnectionManager::getEvent(){ 117 if(!buffer.isEmpty()) 118 return buffer.pop(); 119 else 120 return NULL; 114 121 } 115 122 … … 176 183 void ConnectionManager::receiverThread() { 177 184 // what about some error-handling here ? 185 ENetEvent *event; 178 186 enet_initialize(); 179 187 atexit(enet_deinitialize); 180 ENetEvent *event = new ENetEvent;181 188 server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0); 182 189 if(server==NULL){ … … 187 194 188 195 while(!quit){ 196 event = new ENetEvent; 189 197 if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){ 190 198 // we should never reach this point … … 195 203 // log handling ================ 196 204 case ENET_EVENT_TYPE_CONNECT: 197 addClient(event); 205 COUT(3) << "adding event_type_connect to queue" << std::endl; 206 case ENET_EVENT_TYPE_DISCONNECT: 207 //addClient(event); 198 208 //this is a workaround to ensure thread safety 199 COUT(5) << "Con.Man: connection event has occured" << std::endl;200 break;209 //COUT(5) << "Con.Man: connection event has occured" << std::endl; 210 //break; 201 211 case ENET_EVENT_TYPE_RECEIVE: 202 212 //std::cout << "received data" << std::endl; 203 213 COUT(5) << "Con.Man: receive event has occured" << std::endl; 204 214 // only add, if client has connected yet and not been disconnected 205 if(head_->findClient(&event->peer->address))215 //if(head_->findClient(&event->peer->address)) 206 216 processData(event); 207 else208 COUT(3) << "received a packet from a client we don't know" << std::endl;217 // else 218 // COUT(3) << "received a packet from a client we don't know" << std::endl; 209 219 break; 210 case ENET_EVENT_TYPE_DISCONNECT:211 clientDisconnect(event->peer);212 break;220 //case ENET_EVENT_TYPE_DISCONNECT: 221 //clientDisconnect(event->peer); 222 //break; 213 223 case ENET_EVENT_TYPE_NONE: 224 delete event; 214 225 //receiverThread_->yield(); 215 226 break; … … 262 273 } 263 274 264 bool ConnectionManager::clientDisconnect(ENetPeer *peer) {275 /*bool ConnectionManager::clientDisconnect(ENetPeer *peer) { 265 276 COUT(4) << "removing client from list" << std::endl; 266 277 return removeClient(head_->findClient(&(peer->address))->getID()); 267 } 278 }*/ 268 279 /** 269 280 This function adds a client that connects to the clientlist of the server … … 271 282 addClientTest in diffTest.cc since addClient is not good for testing because of syncClassid 272 283 */ 273 bool ConnectionManager::addClient(ENetEvent *event) {284 /*bool ConnectionManager::addClient(ENetEvent *event) { 274 285 ClientInformation *temp = head_->insertBack(new ClientInformation); 275 286 if(!temp){ … … 286 297 COUT(3) << "Con.Man: added client id: " << temp->getID() << std::endl; 287 298 return true; 288 } 299 }*/ 289 300 290 301 int ConnectionManager::getClientID(ENetPeer peer) { … … 324 335 } 325 336 326 bool ConnectionManager::createClient(int clientID){337 /*bool ConnectionManager::createClient(int clientID){ 327 338 ClientInformation *temp = head_->findClient(clientID); 328 339 if(!temp){ … … 342 353 sendWelcome(temp->getID(), temp->getShipID(), true); 343 354 return true; 344 } 345 346 bool ConnectionManager::removeClient(int clientID){355 }*/ 356 357 /*bool ConnectionManager::removeClient(int clientID){ 347 358 boost::recursive_mutex::scoped_lock lock(head_->mutex_); 348 359 orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start(); … … 361 372 } 362 373 return false; 363 } 364 365 bool ConnectionManager::createShip(ClientInformation *client){374 }*/ 375 376 /* bool ConnectionManager::createShip(ClientInformation *client){ 366 377 if(!client) 367 378 return false; … … 389 400 client->setShipID(no->objectID); 390 401 return true; 391 } 402 }*/ 392 403 393 404 bool ConnectionManager::removeShip(ClientInformation *client){ -
code/branches/network/src/network/ConnectionManager.h
r1379 r1409 77 77 ConnectionManager(int port, const char *address, ClientInformation *head); 78 78 ConnectionManager(int port, std::string address, ClientInformation *head); 79 ENetPacket *getPacket(ENetAddress &address); // thread1 80 ENetPacket *getPacket(int &clientID); 79 //ENetPacket *getPacket(ENetAddress &address); // thread1 80 //ENetPacket *getPacket(int &clientID); 81 ENetEvent *getEvent(); 81 82 bool queueEmpty(); 82 83 void createListener(); … … 87 88 // bool sendPackets(ENetEvent *event); 88 89 bool sendPackets(); 89 bool createClient(int clientID);90 //bool createClient(int clientID); 90 91 void disconnectClient(ClientInformation *client); 92 void syncClassid(int clientID); 93 bool sendWelcome(int clientID, int shipID, bool allowed); 91 94 92 95 private: 93 bool clientDisconnect(ENetPeer *peer);94 bool removeClient(int clientID);96 // bool clientDisconnect(ENetPeer *peer); 97 // bool removeClient(int clientID); 95 98 bool processData(ENetEvent *event); 96 bool addClient(ENetEvent *event);99 //bool addClient(ENetEvent *event); 97 100 void receiverThread(); 98 101 void disconnectClients(); 99 102 int getClientID(ENetPeer peer); 100 103 int getClientID(ENetAddress address); 101 void syncClassid(int clientID);102 104 ENetPeer *getClientPeer(int clientID); 103 bool createShip(ClientInformation *client);105 //bool createShip(ClientInformation *client); 104 106 bool removeShip(ClientInformation *client); 105 bool sendWelcome(int clientID, int shipID, bool allowed);106 107 bool addFakeConnectRequest(ENetEvent *ev); 107 108 PacketBuffer buffer; -
code/branches/network/src/network/PacketBuffer.cc
r1360 r1409 62 62 last->next=NULL; 63 63 // change this!!!!!!! ---- we are not doing stl so we won't change this 64 last->packet = ev->packet; 65 last->address = ev->peer->address; 64 last->event = ev; 66 65 //last->address = ev->peer->address; 67 66 } else { … … 72 71 last->next=NULL; 73 72 // save the packet to the new element 74 last->packet = ev->packet; 75 last->address = ev->peer->address; 73 last->event = ev; 76 74 //last->address = ev->peer->address; 77 75 } … … 82 80 //returns the first element in the list without deleting it but 83 81 //moving first pointer to next element 84 ENetPacket *PacketBuffer::pop() {82 /*ENetPacket *PacketBuffer::pop() { 85 83 ENetAddress address; 86 84 return pop(address); 87 } 88 89 ENet Packet *PacketBuffer::pop(ENetAddress &address){85 }*/ 86 87 ENetEvent *PacketBuffer::pop(){ 90 88 boost::recursive_mutex::scoped_lock lock(mutex_); 91 89 //std::cout << "packetbuffer pop(address)" << std::endl; … … 93 91 QueueItem *temp = first; 94 92 // get packet 95 ENetPacket *pck=first->packet; 96 address = first->address; 93 ENetEvent *ev=first->event; 94 //address = first->address; 95 // remove first element 96 first = first->next; 97 delete temp; 98 lock.unlock(); 99 //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl; 100 return ev; 101 } else{ 102 lock.unlock(); 103 return NULL; 104 } 105 } 106 107 /*ENetPacket *PacketBuffer::pop(ENetAddress &address) { 108 boost::recursive_mutex::scoped_lock lock(mutex_); 109 //std::cout << "packetbuffer pop(address)" << std::endl; 110 if(first!=NULL ){ 111 QueueItem *temp = first; 112 // get packet 113 ENetPacket *pck=first->event->packet; 114 address = first->event->peer->address; 97 115 // remove first element 98 116 first = first->next; … … 105 123 return NULL; 106 124 } 107 } 125 }*/ 108 126 109 127 bool PacketBuffer::isEmpty() { -
code/branches/network/src/network/PacketBuffer.h
r1360 r1409 55 55 56 56 struct QueueItem{ 57 ENet Packet *packet;58 ENetAddress address;57 ENetEvent *event; 58 //ENetAddress address; 59 59 QueueItem *next; 60 60 }; … … 68 68 void print(); 69 69 // pops a packet from the queue 70 ENetPacket *pop(); 71 ENetPacket *pop(ENetAddress &address); 70 //ENetPacket *pop(); 71 //ENetPacket *pop(ENetAddress &address); 72 ENetEvent *pop(); 72 73 // pushs a packet to the queue 73 74 bool push(ENetEvent *ev); -
code/branches/network/src/network/Server.cc
r1389 r1409 50 50 //#include "NetworkFrameListener.h" 51 51 #include "util/Sleep.h" 52 #include "objects/SpaceShip.h" 52 53 53 54 … … 165 166 */ 166 167 void Server::processQueue() { 167 ENet Packet *packet;168 ENetEvent *event; 168 169 int clientID=-1; 169 170 while(!connection->queueEmpty()){ 170 171 //std::cout << "Client " << clientID << " sent: " << std::endl; 171 172 //clientID here is a reference to grab clientID from ClientInformation 172 packet = connection->getPacket(clientID);173 if(! packet)173 event = connection->getEvent(); 174 if(!event) 174 175 continue; 176 switch( event->type ) { 177 case ENET_EVENT_TYPE_CONNECT: 178 COUT(3) << "processing event_Type_connect" << std::endl; 179 addClient(event); 180 break; 181 case ENET_EVENT_TYPE_DISCONNECT: 182 if(clients->findClient(&event->peer->address)) 183 disconnectClient(event); 184 break; 185 case ENET_EVENT_TYPE_RECEIVE: 186 if(clients->findClient(&event->peer->address)){ 187 clientID = clients->findClient(&event->peer->address)->getID(); 188 if( !elaborate(event->packet, clientID) ) 189 COUT(3) << "Server: could not elaborate" << std::endl; 190 } 191 break; 192 } 193 delete event; 175 194 //if statement to catch case that packetbuffer is empty 176 if( !elaborate(packet, clientID) )177 COUT(3) << "Server: could not elaborate" << std::endl;178 195 } 179 196 } … … 250 267 251 268 bool Server::processConnectRequest( connectRequest *con, int clientID ){ 252 COUT(3) << "processing connectRequest " << std::endl;269 //(COUT(3) << "processing connectRequest " << std::endl; 253 270 //connection->addPacket(packet_gen.gstate(gamestates->popGameState(clientID)) , clientID); 254 connection->createClient(clientID);271 //createClient(clientID); 255 272 delete con; 256 273 return true; … … 265 282 clients->findClient(clientID)->resetFailures(); 266 283 } 284 285 bool Server::addClient(ENetEvent *event){ 286 ClientInformation *temp = clients->insertBack(new ClientInformation); 287 if(!temp){ 288 COUT(2) << "Server: could not add client" << std::endl; 289 return false; 290 } 291 if(temp->prev()->getHead()) { //not good if you use anything else than insertBack 292 temp->prev()->setID(0); //bugfix: not necessary but usefull 293 temp->setID(1); 294 } 295 else 296 temp->setID(temp->prev()->getID()+1); 297 temp->setPeer(event->peer); 298 COUT(3) << "Server: added client id: " << temp->getID() << std::endl; 299 return createClient(temp->getID()); 300 } 301 302 bool Server::createClient(int clientID){ 303 ClientInformation *temp = clients->findClient(clientID); 304 if(!temp){ 305 COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl; 306 return false; 307 } 308 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 309 connection->syncClassid(temp->getID()); 310 COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl; 311 // TODO: this is only a hack, untill we have a possibility to define default player-join actions 312 if(!createShip(temp)) 313 COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl; 314 else 315 COUT(3) << "created spaceship" << std::endl; 316 temp->setSynched(true); 317 COUT(3) << "sending welcome" << std::endl; 318 connection->sendWelcome(temp->getID(), temp->getShipID(), true); 319 return true; 320 } 321 322 bool Server::createShip(ClientInformation *client){ 323 if(!client) 324 return false; 325 orxonox::Identifier* id = ID("SpaceShip"); 326 if(!id){ 327 COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl; 328 return false; 329 } 330 orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate()); 331 no->setPosition(orxonox::Vector3(0,0,80)); 332 no->setScale(10); 333 //no->setYawPitchRoll(orxonox::Degree(-90),orxonox::Degree(-90),orxonox::Degree(0)); 334 no->setMesh("assff.mesh"); 335 no->setMaxSpeed(500); 336 no->setMaxSideAndBackSpeed(50); 337 no->setMaxRotation(1.0); 338 no->setTransAcc(200); 339 no->setRotAcc(3.0); 340 no->setTransDamp(75); 341 no->setRotDamp(1.0); 342 no->setCamera("cam_"+client->getID()); 343 no->classID = id->getNetworkID(); 344 no->create(); 345 346 client->setShipID(no->objectID); 347 return true; 348 } 349 350 bool Server::disconnectClient(ENetEvent *event){ 351 COUT(4) << "removing client from list" << std::endl; 352 //return removeClient(head_->findClient(&(peer->address))->getID()); 353 354 //boost::recursive_mutex::scoped_lock lock(head_->mutex_); 355 orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start(); 356 ClientInformation *client = clients->findClient(&event->peer->address); 357 if(!client) 358 return false; 359 while(it){ 360 if(it->objectID!=client->getShipID()){ 361 ++it; 362 continue; 363 } 364 orxonox::Iterator<orxonox::SpaceShip> temp=it; 365 ++it; 366 delete *temp; 367 return clients->removeClient(event->peer); 368 } 369 return false; 370 } 267 371 268 372 void Server::disconnectClient(int clientID){ -
code/branches/network/src/network/Server.h
r1379 r1409 72 72 void updateGamestate(); 73 73 private: 74 bool addClient(ENetEvent *event); 75 bool createClient(int clientID); 76 bool createShip(ClientInformation *client); 77 bool disconnectClient(ENetEvent *event); 74 78 void disconnectClient(int clientID); 75 79 void disconnectClient( ClientInformation *client); -
code/branches/network/src/orxonox/objects/Camera.cc
r1293 r1409 60 60 { 61 61 CameraHandler::getInstance()->releaseFocus(this); 62 GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->removeAndDestroyChild(cameraNode_->getName()); 62 63 } 63 64
Note: See TracChangeset
for help on using the changeset viewer.