Index: /code/branches/network/TODO
===================================================================
--- /code/branches/network/TODO	(revision 1490)
+++ /code/branches/network/TODO	(revision 1491)
@@ -0,0 +1,3 @@
+- should we use enet_peer_ping to test if a client is still alive ?
+- enet_host_broadcast ? (to all peers)
+- enet_host_check_events ? instead of enet_host_service
Index: /code/branches/network/src/network/ClientConnection.cc
===================================================================
--- /code/branches/network/src/network/ClientConnection.cc	(revision 1490)
+++ /code/branches/network/src/network/ClientConnection.cc	(revision 1491)
@@ -50,4 +50,6 @@
 {
   //static boost::thread_group network_threads;
+
+  boost::recursive_mutex ClientConnection::enet_mutex_;
 
   ClientConnection::ClientConnection(int port, std::string address) {
@@ -124,4 +126,5 @@
       return false;
     }
+    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     if(enet_peer_send(server, 0, packet)<0)
       return false;
@@ -143,4 +146,5 @@
     if(server==NULL)
       return false;
+    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     enet_host_flush(client);
     return true;
@@ -149,8 +153,11 @@
   void ClientConnection::receiverThread() {
     // what about some error-handling here ?
-    enet_initialize();
     atexit(enet_deinitialize);
     ENetEvent *event;
-    client = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0);
+    {
+      boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+      enet_initialize();
+      client = enet_host_create(NULL, NETWORK_CLIENT_MAX_CONNECTIONS, 0, 0);
+    }
     if(client==NULL) {
       COUT(2) << "ClientConnection: could not create client host" << std::endl;
@@ -168,8 +175,12 @@
       event = new ENetEvent;
       //std::cout << "connection loop" << std::endl;
-      if(enet_host_service(client, event, NETWORK_CLIENT_TIMEOUT)<0){
-        // we should never reach this point
-        quit=true;
-        // add some error handling here ========================
+      {
+        boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+        if(enet_host_service(client, event, NETWORK_CLIENT_TIMEOUT)<0){
+          // we should never reach this point
+          quit=true;
+          continue;
+          // add some error handling here ========================
+        }
       }
       switch(event->type){
@@ -196,4 +207,5 @@
     if(!disconnectConnection())
       // if disconnecting failed destroy conn.
+      boost::recursive_mutex::scoped_lock lock(enet_mutex_);
       enet_peer_reset(server);
     return;
@@ -202,4 +214,5 @@
   bool ClientConnection::disconnectConnection() {
     ENetEvent event;
+    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     enet_peer_disconnect(server, 0);
     while(enet_host_service(client, &event, NETWORK_CLIENT_TIMEOUT) > 0){
@@ -222,4 +235,5 @@
     ENetEvent event;
     // connect to peer (server is type ENetPeer*)
+    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     server = enet_host_connect(client, &serverAddress, NETWORK_CLIENT_CHANNELS);
     if(server==NULL) {
Index: /code/branches/network/src/network/ClientConnection.h
===================================================================
--- /code/branches/network/src/network/ClientConnection.h	(revision 1490)
+++ /code/branches/network/src/network/ClientConnection.h	(revision 1491)
@@ -96,4 +96,6 @@
     ENetPeer *server;
     boost::thread *receiverThread_;
+    
+    static boost::recursive_mutex enet_mutex_;
   };
 
Index: /code/branches/network/src/network/ConnectionManager.cc
===================================================================
--- /code/branches/network/src/network/ConnectionManager.cc	(revision 1490)
+++ /code/branches/network/src/network/ConnectionManager.cc	(revision 1491)
@@ -65,4 +65,5 @@
   
   ConnectionManager::ConnectionManager():receiverThread_(0){}
+  boost::recursive_mutex ConnectionManager::enet_mutex_;
   
   ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) {
@@ -143,4 +144,5 @@
     if(!temp)
       return false;
+    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     if(enet_peer_send(peer, (enet_uint8)temp->getID() , packet)!=0)
       return false;
@@ -152,4 +154,5 @@
     if(!temp)
       return false;
+    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     if(enet_peer_send(temp->getPeer(), (enet_uint8)clientID, packet)!=0)
       return false;
@@ -158,4 +161,5 @@
 
   bool ConnectionManager::addPacketAll(ENetPacket *packet) {
+    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     for(ClientInformation *i=head_->next(); i!=0; i=i->next()){
       if(enet_peer_send(i->getPeer(), (enet_uint8)i->getID(), packet)!=0)
@@ -177,4 +181,5 @@
     if(server==NULL)
       return false;
+    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     enet_host_flush(server);
     return true;
@@ -184,7 +189,10 @@
     // what about some error-handling here ?
     ENetEvent *event;
-    enet_initialize();
     atexit(enet_deinitialize);
-    server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
+    { //scope of the mutex
+      boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+      enet_initialize();
+      server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
+    }
     if(server==NULL){
       // add some error handling here ==========================
@@ -195,8 +203,12 @@
     while(!quit){
       event = new ENetEvent;
-      if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
-        // we should never reach this point
-        quit=true;
-        // add some error handling here ========================
+      { //mutex scope
+        boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+        if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
+          // we should never reach this point
+          quit=true;
+          continue;
+          // add some error handling here ========================
+        }
       }
       switch(event->type){
@@ -231,5 +243,8 @@
     disconnectClients();
     // if we're finishied, destroy server
-    enet_host_destroy(server);
+    {
+      boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+      enet_host_destroy(server);
+    }
   }
   
@@ -241,11 +256,14 @@
     ClientInformation *temp = head_->next();
     while(temp!=0){
-      enet_peer_disconnect(temp->getPeer(), 0);
+      {
+        boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+        enet_peer_disconnect(temp->getPeer(), 0);
+      }
       temp = temp->next();
     }
     //bugfix: might be the reason why server crashes when clients disconnects
-    //temp = temp->next();
     temp = head_->next();
-    while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) > 0){
+    boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+    while( temp!=0 && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) >= 0){
       switch (event.type)
       {
@@ -273,8 +291,4 @@
   }
 
-  /*bool ConnectionManager::clientDisconnect(ENetPeer *peer) {
-    COUT(4) << "removing client from list" << std::endl;
-    return removeClient(head_->findClient(&(peer->address))->getID());
-  }*/
 /**
 This function adds a client that connects to the clientlist of the server
@@ -422,5 +436,8 @@
   
   void ConnectionManager::disconnectClient(ClientInformation *client){
-    enet_peer_disconnect(client->getPeer(), 0);
+    {
+      boost::recursive_mutex::scoped_lock lock(enet_mutex_);
+      enet_peer_disconnect(client->getPeer(), 0);
+    }
     removeShip(client);
   }
Index: /code/branches/network/src/network/ConnectionManager.h
===================================================================
--- /code/branches/network/src/network/ConnectionManager.h	(revision 1490)
+++ /code/branches/network/src/network/ConnectionManager.h	(revision 1491)
@@ -48,4 +48,5 @@
 #include <enet/enet.h>
 #include <boost/thread/thread.hpp>
+#include <boost/thread/recursive_mutex.hpp>
 
 #include "PacketBuffer.h"
@@ -116,4 +117,5 @@
 
     boost::thread *receiverThread_;
+    static boost::recursive_mutex enet_mutex_;
 //     int getNumberOfClients();
     //functions to map what object every clients uses
Index: /code/branches/network/src/orxonox/Orxonox.cc
===================================================================
--- /code/branches/network/src/orxonox/Orxonox.cc	(revision 1490)
+++ /code/branches/network/src/orxonox/Orxonox.cc	(revision 1491)
@@ -186,4 +186,6 @@
     else if (mode == "server")
       mode_ = SERVER;
+    else if (mode == "dedicated")
+      mode_= DEDICATED;
     else
     {
@@ -215,5 +217,5 @@
   bool Orxonox::start()
   {
-    //if (mode == DEDICATED)
+    //if (mode_ == DEDICATED)
     // do something else
     //else
@@ -433,5 +435,6 @@
       // don't forget to call _fireFrameStarted in ogre to make sure
       // everything goes smoothly
-      ogreRoot._fireFrameStarted(evt);
+      if(mode_!=DEDICATED)
+        ogreRoot._fireFrameStarted(evt);
 
       // get current time
@@ -439,5 +442,6 @@
       calculateEventTime(now, eventTimes[2]);
 
-      ogreRoot._updateAllRenderTargets(); // only render in non-server mode
+      if(mode_!=DEDICATED)
+        ogreRoot._updateAllRenderTargets(); // only render in non-server mode
 
       // get current time
@@ -449,5 +453,6 @@
 
       // again, just to be sure ogre works fine
-      ogreRoot._fireFrameEnded(evt);
+      if(mode_!=DEDICATED)
+        ogreRoot._fireFrameEnded(evt);
 	  }
 
Index: /code/branches/network/src/orxonox/Orxonox.h
===================================================================
--- /code/branches/network/src/orxonox/Orxonox.h	(revision 1490)
+++ /code/branches/network/src/orxonox/Orxonox.h	(revision 1491)
@@ -50,5 +50,6 @@
     SERVER,
     CLIENT,
-    STANDALONE
+    STANDALONE,
+    DEDICATED
   };
 
