[Orxonox-commit 670] r3202 - in branches/netp5/src: network network/packet orxonox/objects/worldentities/pawns

scheusso at orxonox.net scheusso at orxonox.net
Sun Jun 21 00:27:20 CEST 2009


Author: scheusso
Date: 2009-06-21 00:27:19 +0200 (Sun, 21 Jun 2009)
New Revision: 3202

Modified:
   branches/netp5/src/network/Client.cc
   branches/netp5/src/network/Client.h
   branches/netp5/src/network/ClientConnection.cc
   branches/netp5/src/network/ClientConnection.h
   branches/netp5/src/network/Connection.cc
   branches/netp5/src/network/Connection.h
   branches/netp5/src/network/Server.cc
   branches/netp5/src/network/ServerConnection.cc
   branches/netp5/src/network/ServerConnection.h
   branches/netp5/src/network/packet/FunctionCalls.cc
   branches/netp5/src/network/packet/Packet.cc
   branches/netp5/src/orxonox/objects/worldentities/pawns/Pawn.cc
   branches/netp5/src/orxonox/objects/worldentities/pawns/Pawn.h
Log:
rest of the cleanup ( mostly client connection handling)
network is now single-threaded ( only in order to become multithreaded again, but thats another story ;) )


Modified: branches/netp5/src/network/Client.cc
===================================================================
--- branches/netp5/src/network/Client.cc	2009-06-20 17:21:46 UTC (rev 3201)
+++ branches/netp5/src/network/Client.cc	2009-06-20 22:27:19 UTC (rev 3202)
@@ -49,22 +49,18 @@
 #include "packet/Packet.h"
 #include "FunctionCallManager.h"
 
-// #include "packet/Acknowledgement.h"
-
 namespace orxonox
 {
-//   SetConsoleCommandShortcut(Client, chat);
 
 
   /**
   * Constructor for the Client class
   * initializes the address and the port to default localhost:NETWORK_PORT
   */
-  Client::Client(): client_connection(NETWORK_PORT,"127.0.0.1"){
-    // set server address to localhost
-    isConnected=false;
-    isSynched_=false;
-    gameStateFailure_=false;
+  Client::Client():
+      isSynched_(false),
+      gameStateFailure_(false)
+  {
   }
 
   /**
@@ -72,25 +68,14 @@
   * @param address the server address
   * @param port port of the application on the server
   */
-  Client::Client(const std::string& address, int port) : client_connection(port, address){
-    isConnected=false;
-    isSynched_=false;
-    gameStateFailure_=false;
+  Client::Client(const std::string& address, int port):
+      isSynched_(false),
+      gameStateFailure_(false)
+  {
   }
 
-  /**
-  * Constructor for the Client class
-  * @param address the server address
-  * @param port port of the application on the server
-  */
-  Client::Client(const char *address, int port) : client_connection(port, address){
-    isConnected=false;
-    isSynched_=false;
-    gameStateFailure_=false;
-  }
-
   Client::~Client(){
-    if(isConnected)
+    if ( ClientConnection::isConnected() )
       closeConnection();
   }
 
@@ -100,10 +85,7 @@
   */
   bool Client::establishConnection(){
     Synchronisable::setClient(true);
-    isConnected=client_connection.createConnection();
-    if(!isConnected)
-      COUT(1) << "could not create connection laber" << std::endl;
-    return isConnected;
+    return ClientConnection::establishConnection();
   }
 
   /**
@@ -111,12 +93,13 @@
   * @return true/false
   */
   bool Client::closeConnection(){
-    isConnected=false;
-    return client_connection.closeConnection();
+    return ClientConnection::closeConnection();
   }
 
   bool Client::queuePacket(ENetPacket *packet, int clientID){
-    return client_connection.addPacket(packet);
+    bool b = ClientConnection::addPacket(packet);
+    assert(b);
+    return b;
   }
 
   bool Client::processChat(const std::string& message, unsigned int playerID){
@@ -142,10 +125,12 @@
   void Client::update(const Clock& time){
     //this steers our network frequency
     timeSinceLastUpdate_+=time.getDeltaTime();
-    if(timeSinceLastUpdate_>=NETWORK_PERIOD){
+    if(timeSinceLastUpdate_>=NETWORK_PERIOD)
+    {
       timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
       //     COUT(3) << ".";
-      if(client_connection.isConnected() && isSynched_){
+      if ( isConnected() && isSynched_ )
+      {
         COUT(4) << "popping partial gamestate: " << std::endl;
         packet::Gamestate *gs = gamestate.getGamestate();
         //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
@@ -158,18 +143,9 @@
         FunctionCallManager::sendCalls();
       }
     }
+    sendPackets(); // flush the enet queue
     
-    ENetEvent *event;
-    // stop if the packet queue is empty
-    while(!(client_connection.queueEmpty())){
-      event = client_connection.getEvent();
-      COUT(5) << "tick packet size " << event->packet->dataLength << std::endl;
-      packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer);
-      // note: packet commits suicide here except for the GameState. That is then deleted by a GamestateHandler
-      bool b = packet->process();
-      assert(b);
-      delete event;
-    }
+    Connection::processQueue();
     if(gamestate.processGamestates())
     {
       if(!isSynched_)

Modified: branches/netp5/src/network/Client.h
===================================================================
--- branches/netp5/src/network/Client.h	2009-06-20 17:21:46 UTC (rev 3201)
+++ branches/netp5/src/network/Client.h	2009-06-20 22:27:19 UTC (rev 3202)
@@ -60,11 +60,10 @@
   * It is the root class of the network module
   *
   */
-  class _NetworkExport Client : public Host{
+  class _NetworkExport Client : public Host, public ClientConnection{
   public:
     Client();
     Client(const std::string& address, int port);
-    Client(const char *address, int port);
     ~Client();
 
     bool establishConnection();
@@ -73,7 +72,6 @@
     bool processChat(const std::string& message, unsigned int playerID);
     virtual bool chat(const std::string& message);
     virtual bool broadcast(const std::string& message) { return false; }
-    //bool sendChat(packet::Chat *chat);
 
     void update(const Clock& time);
 
@@ -81,9 +79,7 @@
     Client(const Client& copy); // not used
     virtual bool isServer_(){return false;}
 
-    ClientConnection client_connection;
     GamestateClient gamestate;
-    bool isConnected;
     bool isSynched_;
 
     bool gameStateFailure_;

Modified: branches/netp5/src/network/ClientConnection.cc
===================================================================
--- branches/netp5/src/network/ClientConnection.cc	2009-06-20 17:21:46 UTC (rev 3201)
+++ branches/netp5/src/network/ClientConnection.cc	2009-06-20 22:27:19 UTC (rev 3202)
@@ -26,240 +26,112 @@
  *
  */
 
-//
-// C++ Interface: ClientConnection
-//
-// Description: The Class ClientConnection manages the servers conenctions to the clients.
-// each connection is provided by a new process. communication between master process and
-// connection processes is provided by ...
-//
-//
-// Author:  Oliver Scheuss
-//
-
 #include "ClientConnection.h"
 
-#include <enet/enet.h>
 #include <iostream>
 #include <cassert>
-// boost.thread library for multithreading support
-#include <boost/thread/thread.hpp>
-#include <boost/bind.hpp>
-#include <boost/thread/recursive_mutex.hpp>
 
-#include "util/Sleep.h"
 #include "util/Debug.h"
 
 namespace orxonox
 {
-  //static boost::thread_group network_threads;
+  const unsigned int NETWORK_CLIENT_WAIT_TIME = 1;
+  const unsigned int NETWORK_CLIENT_CONNECTION_TIMEOUT = 3000; //millisecs
+  const unsigned int NETWORK_CLIENT_MAX_CONNECTIONS = 5;
+  const unsigned int NETWORK_CLIENT_CHANNELS = 2;
 
-  static boost::recursive_mutex enet_mutex_g;
 
-  ClientConnection::ClientConnection(int port, const std::string& address) {
-    quit_=false;
-    server=NULL;
-    serverAddress = new ENetAddress();
-    enet_address_set_host(serverAddress, address.c_str());
-    serverAddress->port = port;
-    established=false;
+  ClientConnection::ClientConnection():
+    server_(NULL),
+    established_(false)
+  {
+    this->serverAddress_ = new ENetAddress();
+    //set standard address and port
+    enet_address_set_host(this->serverAddress_, "127.0.0.1");
+    serverAddress_->port = NETWORK_PORT;
   }
 
-  ClientConnection::ClientConnection(int port, const char *address) {
-    quit_=false;
-    server=NULL;
-    serverAddress = new ENetAddress();
-    enet_address_set_host(serverAddress, address);
-    serverAddress->port = port;
-    established=false;
-  }
-
-  bool ClientConnection::waitEstablished(int milisec) {
-    for(int i=0; i<=milisec && !established; i++)
-      msleep(1);
-
-    return established;
-  }
-
   ClientConnection::~ClientConnection(){
-    if(established)
+    if(this->established_)
       closeConnection();
-    delete serverAddress; // surely was created
+    delete this->serverAddress_; // surely was created
   }
 
-  ENetEvent *ClientConnection::getEvent(){
-    if(!buffer.isEmpty())
-      return buffer.pop();
-    else
-      return NULL;
-  }
-
-  bool ClientConnection::queueEmpty() {
-    return buffer.isEmpty();
-  }
-
-  bool ClientConnection::createConnection() {
-    receiverThread_ = new boost::thread(boost::bind(&ClientConnection::receiverThread, this));
-    //network_threads.create_thread(boost::bind(boost::mem_fn(&ClientConnection::receiverThread), this));
-    // wait 10 seconds for the connection to be established
-    return waitEstablished(NETWORK_CLIENT_CONNECT_TIMEOUT);
-  }
-
-  bool ClientConnection::closeConnection() {
-    quit_=true;
-    //network_threads.join_all();
-    receiverThread_->join();
-    established=false;
-    return true;
-  }
-
-
-  bool ClientConnection::addPacket(ENetPacket *packet) {
-    if(server==NULL)
+  bool ClientConnection::establishConnection()
+  {
+    ENetEvent event;
+    
+    this->host_ = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0);
+    if ( this->host_ == NULL )
+    {
+      COUT(2) << "ClientConnection: host_ == NULL" << std::endl;
+      // error handling
       return false;
-    if(packet==NULL){
-      COUT(3) << "Cl.con: addpacket: invalid packet" << std::endl;
-      return false;
     }
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-    if(enet_peer_send(server, 0, packet)<0)
-      return false;
-    else
-      return true;
-  }
-
-  bool ClientConnection::sendPackets() {
-    if(server==NULL)
-      return false;
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-    enet_host_flush(client);
-    lock.unlock();
-    return true;
-  }
-
-  void ClientConnection::receiverThread() {
-    // what about some error-handling here ?
-    atexit(enet_deinitialize);
-    ENetEvent *event;
+    this->server_ = enet_host_connect(this->host_, serverAddress_, NETWORK_CLIENT_CHANNELS);
+    if ( this->server_==NULL )
     {
-      boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-      enet_initialize();
-      client = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0);
-      lock.unlock();
+      COUT(2) << "ClientConnection: server == NULL" << std::endl;
+      // error handling
+      return false;
     }
-    if(client==NULL) {
-      COUT(2) << "ClientConnection: could not create client host" << std::endl;
-      // add some error handling here ==========================
-      quit_=true;
-    }
-    //connect to the server
-    if(!establishConnection()){
-      COUT(2) << "clientConn: receiver thread: could not establishConnection" << std::endl;
-      quit_=true;
-      return;
-    }
-    event = new ENetEvent;
-    //main loop
-    while(!quit_){
-      //std::cout << "connection loop" << std::endl;
+    // handshake
+    for( unsigned int i=0; i<NETWORK_CLIENT_CONNECTION_TIMEOUT/NETWORK_CLIENT_WAIT_TIME; i++ )
+    {
+      if( enet_host_service(this->host_, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && event.type == ENET_EVENT_TYPE_CONNECT )
       {
-        boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-        if(enet_host_service(client, event, NETWORK_CLIENT_WAIT_TIME)<0){
-          // we should never reach this point
-// 	        assert(0);
-          printf("ClientConnection: ENet returned with an error!\n");
-//           quit_=true;
-          continue;
-          // add some error handling here ========================
-        }
-        lock.unlock();
+        this->established_=true;
+        return true;
       }
-      switch(event->type){
-        // log handling ================
-      case ENET_EVENT_TYPE_CONNECT:
-        break;
-      case ENET_EVENT_TYPE_RECEIVE:
-        //COUT(5) << "Cl.Con: receiver-Thread while loop: got new packet" << std::endl;
-        if ( !processData(event) ) COUT(2) << "Current packet was not pushed to packetBuffer -> ev ongoing SegFault" << std::endl;
-        //COUT(5) << "Cl.Con: processed Data in receiver-thread while loop" << std::endl;
-        event = new ENetEvent;
-        break;
-      case ENET_EVENT_TYPE_DISCONNECT:
-        quit_=true;
-        printf("Received disconnect Packet from Server!\n");
-        // server closed the connection
-        return;
-        break;
-      case ENET_EVENT_TYPE_NONE:
-        //receiverThread_->yield();
-        msleep(1);
-        break;
-      }
     }
-    delete event;
-    // now disconnect
-
-    if(!disconnectConnection())
-    {
-      printf("could not disconnect properly\n");
-      // if disconnecting failed destroy conn.
-      boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-      enet_peer_reset(server);
-    }
-    else
-      printf("properly disconnected\n");
-    return;
+    COUT(1) << "Could not connect to server" << endl;
   }
 
-  bool ClientConnection::disconnectConnection() {
+  bool ClientConnection::closeConnection() {
     ENetEvent event;
-    if(this->quit_)
+    
+    if ( !this->established_ )
       return true;
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-    enet_peer_disconnect(server, 0);
-    while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) >= 0){
-      switch (event.type)
+    this->established_ = false;
+    enet_peer_disconnect(this->server_, 0);
+    for( unsigned int i=0; i<NETWORK_CLIENT_CONNECTION_TIMEOUT/NETWORK_CLIENT_WAIT_TIME; i++)
+    {
+      if ( enet_host_service(this->host_, &event, NETWORK_CLIENT_WAIT_TIME) >= 0 )
       {
-      case ENET_EVENT_TYPE_NONE:
-      case ENET_EVENT_TYPE_CONNECT:
-      case ENET_EVENT_TYPE_RECEIVE:
-        enet_packet_destroy(event.packet);
-        break;
-      case ENET_EVENT_TYPE_DISCONNECT:
-        printf("received disconnect confirmation from server");
-        return true;
+        switch (event.type)
+        {
+          case ENET_EVENT_TYPE_NONE:
+          case ENET_EVENT_TYPE_CONNECT:
+            break;
+          case ENET_EVENT_TYPE_RECEIVE:
+            enet_packet_destroy(event.packet);
+            break;
+          case ENET_EVENT_TYPE_DISCONNECT:
+            COUT(4) << "received disconnect confirmation from server" << endl;
+            return true;
+        }
       }
     }
-    enet_peer_reset(server);
+    enet_peer_reset( this->server_ );
     return false;
   }
 
-  bool ClientConnection::establishConnection() {
-    ENetEvent event;
-    // connect to peer (server is type ENetPeer*)
-    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
-    server = enet_host_connect(client, serverAddress, NETWORK_CLIENT_CHANNELS);
-    if(server==NULL) {
-      COUT(2) << "ClientConnection: server == NULL" << std::endl;
-      // error handling
-      return false;
-    }
-    // handshake
-    while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && !quit_){
-      if( event.type == ENET_EVENT_TYPE_CONNECT ){
-        established=true;
-        return true;
-      }
-    }
-    COUT(2) << "ClientConnection: enet_host_service < 0 or event.type != ENET_EVENT_TYPE_CONNECT # EVENT:" << event.type << std::endl;
-    return false;
+
+  bool ClientConnection::addPacket(ENetPacket *packet) {
+    assert( this->server_ );
+    assert( packet );
+    return Connection::addPacket( packet, this->server_ );
   }
 
-  bool ClientConnection::processData(ENetEvent *event) {
-    COUT(5) << "Cl.Con: got packet, pushing to queue" << std::endl;
-    // just add packet to the buffer
-    // this can be extended with some preprocessing
-    return buffer.push(event);
+  void ClientConnection::addClient(ENetEvent* event)
+  {
+    assert(0);
   }
+  void ClientConnection::disconnectPeer(ENetEvent* event)
+  {
+    this->established_=false;
+    COUT(1) << "Received disconnect Packet from Server!" << endl;
+        // server closed the connection
+  }
 
 }

Modified: branches/netp5/src/network/ClientConnection.h
===================================================================
--- branches/netp5/src/network/ClientConnection.h	2009-06-20 17:21:46 UTC (rev 3201)
+++ branches/netp5/src/network/ClientConnection.h	2009-06-20 22:27:19 UTC (rev 3202)
@@ -25,76 +25,45 @@
  *      ...
  *
  */
-
-//
-// C++ Interface: ClientConnection
-//
-// Description:
-//
-//
-// Author:  Oliver Scheuss, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
+ 
 #ifndef _ClientConnection_H__
 #define _ClientConnection_H__
 
-#include "NetworkPrereqs.h"
-
 #include <string>
-#include "PacketBuffer.h"
 
-namespace boost { class thread; }
+#include "NetworkPrereqs.h"
+#include "Connection.h"
 
 namespace orxonox
 {
 
-    const int NETWORK_PORT = 55556;
-    const int NETWORK_CLIENT_MAX_CONNECTIONS = 5;
-    const int NETWORK_CLIENT_WAIT_TIME = 10;
-    const int NETWORK_CLIENT_CONNECT_TIMEOUT = 3000; // miliseconds
-    const int NETWORK_CLIENT_CHANNELS = 2;
-
-
-  class _NetworkExport ClientConnection{
+  class _NetworkExport ClientConnection: public Connection{
   public:
-    ClientConnection(int port, const std::string& address);
-    ClientConnection(int port, const char* address);
+    ClientConnection();
     ~ClientConnection();
+    
+    void setServerAddress( const std::string& serverAddress ){ enet_address_set_host (this->serverAddress_, serverAddress.c_str()); }
+    void setPort( unsigned int port ){ this->serverAddress_->port = port; }
+    
     ENetEvent *getEvent();
     // check wheter the packet queue is empty
     bool queueEmpty();
     // create a new listener thread
-    bool createConnection();
-    bool closeConnection();
+    virtual bool establishConnection();
+    virtual bool closeConnection();
     // add a packet to queue for the server
     bool addPacket(ENetPacket *packet);
-    // send out all queued packets
-    bool sendPackets();
-    // send out all queued packets and save result in event
-    //bool sendPackets(ENetEvent *event);
-    bool waitEstablished(int milisec);
-    inline bool isConnected(){return established;}
-    inline bool checkConnection(){ return !quit_ && isConnected(); }
+    inline bool isConnected(){ return this->established_; }
   private:
-    ClientConnection(const ClientConnection& copy); // not used
-    bool processData(ENetEvent *event);
-    // implementation of the listener
-    void receiverThread(); //thread2
-    //packetbuffer
-    bool establishConnection();
+    virtual void addClient(ENetEvent* event);
+    virtual void disconnectPeer(ENetEvent* event);
+    
     bool disconnectConnection();
-    PacketBuffer buffer;
     // enet stuff
-    ENetHost *client;
-    ENetAddress *serverAddress;
-    // quit-variable (communication with threads)
-    bool quit_;
-    bool established;
+    ENetAddress *serverAddress_;
+    bool established_;
     // clientlist
-    ENetPeer *server;
-    boost::thread *receiverThread_;
+    ENetPeer *server_;
 };
 
 

Modified: branches/netp5/src/network/Connection.cc
===================================================================
--- branches/netp5/src/network/Connection.cc	2009-06-20 17:21:46 UTC (rev 3201)
+++ branches/netp5/src/network/Connection.cc	2009-06-20 22:27:19 UTC (rev 3202)
@@ -30,6 +30,7 @@
 
 #include <iostream>
 #include <cassert>
+#include <OgreTimer.h>
 
 #include "util/Debug.h"
 #include "util/Math.h"
@@ -47,6 +48,8 @@
   {
     assert(instance_==0);
     Connection::instance_=this;
+    enet_initialize();
+    atexit(enet_deinitialize);
   }
 
   Connection::~Connection(){
@@ -71,8 +74,9 @@
     ENetEvent event;
     
     assert(this->host_);
+    Ogre::Timer timer;
 
-    if( enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
+    while( timer.getMilliseconds()<NETWORK_MAX_QUEUE_PROCESS_TIME && enet_host_service( this->host_, &event, NETWORK_WAIT_TIMEOUT ) > 0 )
     {
       switch(event.type){
         // log handling ================
@@ -80,7 +84,7 @@
           addClient( &event );
           break;
         case ENET_EVENT_TYPE_DISCONNECT:
-          disconnectClient( &event );
+          disconnectPeer( &event );
           break;
         case ENET_EVENT_TYPE_RECEIVE:
           processPacket( &event );

Modified: branches/netp5/src/network/Connection.h
===================================================================
--- branches/netp5/src/network/Connection.h	2009-06-20 17:21:46 UTC (rev 3201)
+++ branches/netp5/src/network/Connection.h	2009-06-20 22:27:19 UTC (rev 3202)
@@ -52,15 +52,10 @@
 {
     const int NETWORK_PORT = 55556;
     const int NETWORK_MAX_CONNECTIONS = 50;
-    const int NETWORK_WAIT_TIMEOUT = 1;
+    const int NETWORK_WAIT_TIMEOUT = 0;
     const int NETWORK_DEFAULT_CHANNEL = 0;
+    const int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
 
-//   struct _NetworkExport ClientList{
-//     ENetEvent *event;
-//     int ID;
-//     ClientList *next;
-//   };
-
   class _NetworkExport Connection{
   public:
     ~Connection();
@@ -78,7 +73,7 @@
     
     void processQueue();
     virtual void addClient(ENetEvent* event)=0;
-    virtual void disconnectClient(ENetEvent* event)=0;
+    virtual void disconnectPeer(ENetEvent* event)=0;
     virtual bool processPacket(ENetEvent* event){ packet::Packet *p = packet::Packet::createPacket(event->packet, event->peer); return p->process(); }
     
     ENetHost *host_;

Modified: branches/netp5/src/network/Server.cc
===================================================================
--- branches/netp5/src/network/Server.cc	2009-06-20 17:21:46 UTC (rev 3201)
+++ branches/netp5/src/network/Server.cc	2009-06-20 22:27:19 UTC (rev 3202)
@@ -143,15 +143,17 @@
   * @param time time since last tick
   */
   void Server::update(const Clock& time) {
-    ServerConnection::processQueue();
+    Connection::processQueue();
     gamestates_->processGamestates();
     //this steers our network frequency
     timeSinceLastUpdate_+=time.getDeltaTime();
-    if(timeSinceLastUpdate_>=NETWORK_PERIOD){
+    if(timeSinceLastUpdate_>=NETWORK_PERIOD)
+    {
       timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
       updateGamestate();
       FunctionCallManager::sendCalls();
     }
+    sendPackets(); // flush the enet queue
   }
 
   bool Server::queuePacket(ENetPacket *packet, int clientID){

Modified: branches/netp5/src/network/ServerConnection.cc
===================================================================
--- branches/netp5/src/network/ServerConnection.cc	2009-06-20 17:21:46 UTC (rev 3201)
+++ branches/netp5/src/network/ServerConnection.cc	2009-06-20 22:27:19 UTC (rev 3202)
@@ -52,8 +52,6 @@
   }
 
   bool ServerConnection::openListener() {
-    enet_initialize();
-    atexit(enet_deinitialize);
     this->host_ = enet_host_create(this->bindAddress_, NETWORK_MAX_CONNECTIONS, 0, 0);
     if ( this->host_ == NULL )
       return false;
@@ -90,11 +88,11 @@
   
   void ServerConnection::disconnectClient(ClientInformation *client)
   {
-    disconnectPeer( client->getPeer() );
+    Connection::disconnectPeer( client->getPeer() );
     delete client;
   }
   
-  void ServerConnection::disconnectClient( ENetEvent* event )
+  void ServerConnection::disconnectPeer( ENetEvent* event )
   {
     COUT(4) << "removing client from list" << std::endl;
     ClientInformation *client = ClientInformation::findClient(&event->peer->address);
@@ -114,7 +112,7 @@
     ENetEvent event;
     ClientInformation *temp = ClientInformation::getBegin();
     while(temp!=0){
-      disconnectPeer( temp->getPeer() );
+      disconnectPeer( &event );
       temp = temp->next();
     }
     temp = ClientInformation::getBegin();

Modified: branches/netp5/src/network/ServerConnection.h
===================================================================
--- branches/netp5/src/network/ServerConnection.h	2009-06-20 17:21:46 UTC (rev 3201)
+++ branches/netp5/src/network/ServerConnection.h	2009-06-20 22:27:19 UTC (rev 3202)
@@ -59,7 +59,7 @@
     static bool addPacket(ENetPacket *packet, unsigned int ID);
     static bool addPacketAll(ENetPacket *packet);
     virtual void disconnectClient(ClientInformation *client);
-    void disconnectClient( ENetEvent* event );
+    void disconnectPeer( ENetEvent* event );
     void disconnectClient(int clientID);
   protected:
     ServerConnection();

Modified: branches/netp5/src/network/packet/FunctionCalls.cc
===================================================================
--- branches/netp5/src/network/packet/FunctionCalls.cc	2009-06-20 17:21:46 UTC (rev 3201)
+++ branches/netp5/src/network/packet/FunctionCalls.cc	2009-06-20 22:27:19 UTC (rev 3202)
@@ -65,6 +65,7 @@
 
 
 bool FunctionCalls::process(){
+  printf("process function calls\n");
   assert(isDataENetAllocated());
   uint8_t* temp = data_+sizeof(uint32_t); //skip packetid
   this->nrOfCalls_ = *(uint32_t*)temp;

Modified: branches/netp5/src/network/packet/Packet.cc
===================================================================
--- branches/netp5/src/network/packet/Packet.cc	2009-06-20 17:21:46 UTC (rev 3201)
+++ branches/netp5/src/network/packet/Packet.cc	2009-06-20 22:27:19 UTC (rev 3202)
@@ -31,10 +31,7 @@
 
 #include <cassert>
 #include <enet/enet.h>
-#include <boost/bind.hpp>
-#include <boost/thread/recursive_mutex.hpp>
 
-#include "network/ConnectionManager.h"
 #include "network/ClientInformation.h"
 
 #include "Acknowledgement.h"
@@ -57,7 +54,6 @@
 
 std::map<size_t, Packet *> Packet::packetMap_;
 //! Static mutex for any packetMap_ access
-static boost::recursive_mutex packetMap_mutex_g;
 
 Packet::Packet(){
   flags_ = PACKET_FLAG_DEFAULT;
@@ -141,7 +137,6 @@
     {
       // Assures we don't create a packet and destroy it right after in another thread
       // without having a reference in the packetMap_
-      boost::recursive_mutex::scoped_lock lock(packetMap_mutex_g);
       packetMap_[(size_t)(void*)enetPacket_] = this;
     }
   }
@@ -227,7 +222,6 @@
     data we allocated ourselves.
 */
 void Packet::deletePacket(ENetPacket *enetPacket){
-  boost::recursive_mutex::scoped_lock lock(packetMap_mutex_g);
   // Get our Packet from a gloabal map with all Packets created in the send() method of Packet.
   std::map<size_t, Packet*>::iterator it = packetMap_.find((size_t)enetPacket);
   assert(it != packetMap_.end());

Modified: branches/netp5/src/orxonox/objects/worldentities/pawns/Pawn.cc
===================================================================
--- branches/netp5/src/orxonox/objects/worldentities/pawns/Pawn.cc	2009-06-20 17:21:46 UTC (rev 3201)
+++ branches/netp5/src/orxonox/objects/worldentities/pawns/Pawn.cc	2009-06-20 22:27:19 UTC (rev 3202)
@@ -58,8 +58,6 @@
 
         PawnManager::touch();
         this->bAlive_ = true;
-        this->fire_ = 0x0;
-        this->firehack_ = 0x0;
         this->bReload_ = false;
 
         this->health_ = 0;
@@ -121,7 +119,6 @@
         registerVariable(this->bAlive_,        variableDirection::toclient);
         registerVariable(this->health_,        variableDirection::toclient);
         registerVariable(this->initialHealth_, variableDirection::toclient);
-        registerVariable(this->fire_,          variableDirection::toserver);
         registerVariable(this->bReload_,       variableDirection::toserver);
     }
 
@@ -129,18 +126,6 @@
     {
         SUPER(Pawn, tick, dt);
 
-//        if (this->weaponSystem_ && GameMode::isMaster())
-//        {
-//            for (unsigned int firemode = 0; firemode < WeaponSystem::MAX_FIRE_MODES; firemode++)
-//                if (this->fire_ & WeaponSystem::getFiremodeMask(firemode))
-//                    this->weaponSystem_->fire(firemode);
-//
-//            if (this->bReload_)
-//                this->weaponSystem_->reload();
-//        }
-//
-//        this->fire_ = this->firehack_;
-//        this->firehack_ = 0x0;
         this->bReload_ = false;
 
         if (GameMode::isMaster())

Modified: branches/netp5/src/orxonox/objects/worldentities/pawns/Pawn.h
===================================================================
--- branches/netp5/src/orxonox/objects/worldentities/pawns/Pawn.h	2009-06-20 17:21:46 UTC (rev 3201)
+++ branches/netp5/src/orxonox/objects/worldentities/pawns/Pawn.h	2009-06-20 22:27:19 UTC (rev 3202)
@@ -136,8 +136,6 @@
             Pawn* lastHitOriginator_;
 
             WeaponSystem* weaponSystem_;
-            unsigned int fire_;
-            unsigned int firehack_;
             bool bReload_;
 
             std::string spawnparticlesource_;




More information about the Orxonox-commit mailing list