Index: code/branches/FICN/src/network/Client.cc
===================================================================
--- code/branches/FICN/src/network/Client.cc	(revision 368)
+++ code/branches/FICN/src/network/Client.cc	(revision 369)
@@ -21,7 +21,7 @@
   Client::Client(): client_connection(NETWORK_PORT,"127.0.0.1"){
     // set server address to localhost
-    //server_address="127.0.0.1";
-    //port = NETWORK_PORT;
     isConnected=false;
+    pck_gen = PacketGenerator();
+    gamestate = GameStateManager();
   }
 
@@ -32,7 +32,7 @@
    */
   Client::Client(std::string address, int port) : client_connection(port, address){
-    //server_address=address.c_str();
-    //this->port = port;
     isConnected=false;
+    pck_gen = PacketGenerator();
+    gamestate = GameStateManager();
   }
 
@@ -43,7 +43,7 @@
    */
   Client::Client(const char *address, int port) : client_connection(port, address){
-    //server_address = address;
-    //this->port = port;
     isConnected=false;
+    pck_gen = PacketGenerator();
+    gamestate = GameStateManager();
   }
 
@@ -78,9 +78,5 @@
         return false;
     // send packets
-    client_connection.sendPackets(&event);
-    if(event.type==ENET_EVENT_TYPE_NONE)
-      return true;
-    else
-      return false;
+    return client_connection.sendPackets();
   }
 
@@ -96,9 +92,5 @@
         return false;
     // send packets
-    client_connection.sendPackets(&event);
-    if(event.type==ENET_EVENT_TYPE_NONE)
-      return true;
-    else
-      return false;
+    return client_connection.sendPackets();
   }
 
@@ -131,12 +123,34 @@
   }
 
+  /** 
+   * Sends out all the packets queued by addXXX
+   */
+  bool Client::sendPackets(){
+    ENetEvent event;
+    // send packets
+    client_connection.sendPackets(&event);
+    if(event.type==ENET_EVENT_TYPE_NONE)
+      return true;
+    else
+      return false;
+  }
+  
   /**
    * Performs a GameState update
    */
   void Client::update(){
-    // to be implemented ==================
-
-
+    ENetPacket *packet;
+    // stop if the packet queue is empty
+    while(!client_connection.queueEmpty()){
+      packet = client_connection.getPacket();
+      elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
+    }
+    return;
   }
-
+  
+  void Client::processGamestate( GameState *data){
+    gamestate.loadSnapshot( *data );
+    return;
+  }
+  
 }
Index: code/branches/FICN/src/network/Client.h
===================================================================
--- code/branches/FICN/src/network/Client.h	(revision 368)
+++ code/branches/FICN/src/network/Client.h	(revision 369)
@@ -18,4 +18,5 @@
 #include "ClientConnection.h"
 #include "PacketManager.h"
+#include "GameStateManager.h"
 
 
@@ -43,4 +44,6 @@
   bool addKeyboard(char key_code);
 
+  bool sendPackets();
+  
   void update();
 
@@ -48,8 +51,9 @@
   ClientConnection client_connection;
   PacketGenerator pck_gen;
-
-  //const char *server_address;
-  //int port;
+  GameStateManager gamestate;
   bool isConnected;
+  
+  // implement data processing functions of PacketDecoder
+  void processGamestate( GameState *data);
 };
 
Index: code/branches/FICN/src/network/ClientConnection.cc
===================================================================
--- code/branches/FICN/src/network/ClientConnection.cc	(revision 368)
+++ code/branches/FICN/src/network/ClientConnection.cc	(revision 369)
@@ -54,4 +54,9 @@
   }
 
+  ENetPacket *ClientConnection::getPacket(){
+    ENetAddress address;
+    return getPacket(address);
+  }
+  
   bool ClientConnection::queueEmpty(){
     return buffer.isEmpty();
@@ -110,6 +115,8 @@
       quit=true;
     //connect to the server
-    if(!establishConnection())
+    if(!establishConnection()){
       quit=true;
+      return;
+    }
     //main loop
     while(!quit){
@@ -126,6 +133,7 @@
         break;
       case ENET_EVENT_TYPE_DISCONNECT:
-        // add some error/log handling here
-        // extend =====================
+        quit=true;
+        // server closed the connection
+        return;
         break;
       case ENET_EVENT_TYPE_NONE:
@@ -143,5 +151,4 @@
   bool ClientConnection::disconnectConnection(){
     ENetEvent event;
-//     enet_peer_disconnect(server);
     enet_peer_disconnect(server, 0);
     while(enet_host_service(client, &event, NETWORK_WAIT_TIMEOUT) > 0){
Index: code/branches/FICN/src/network/ClientConnection.h
===================================================================
--- code/branches/FICN/src/network/ClientConnection.h	(revision 368)
+++ code/branches/FICN/src/network/ClientConnection.h	(revision 369)
@@ -38,4 +38,5 @@
     ClientConnection(int port, const char* address);
     ENetPacket *getPacket(ENetAddress &address); // thread1
+    ENetPacket *getPacket(); // thread1
     // check wheter the packet queue is empty
     bool queueEmpty();
Index: code/branches/FICN/src/network/ConnectionManager.cc
===================================================================
--- code/branches/FICN/src/network/ConnectionManager.cc	(revision 368)
+++ code/branches/FICN/src/network/ConnectionManager.cc	(revision 369)
@@ -106,4 +106,14 @@
       return false;
     if(enet_host_service(server, event, NETWORK_SEND_WAIT)>=0)
+      return true;
+    else
+      return false;
+  }
+  
+  bool ConnectionManager::sendPackets(){
+    ENetEvent event;
+    if(server==NULL)
+      return false;
+    if(enet_host_service(server, &event, NETWORK_SEND_WAIT)>=0)
       return true;
     else
@@ -117,7 +127,9 @@
     ENetEvent event;
     server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
-    if(server==NULL)
+    if(server==NULL){
       // add some error handling here ==========================
       quit=true;
+      return;
+    }
 
     while(!quit){
@@ -143,6 +155,32 @@
       }
     }
+    disconnectClients();
     // if we're finishied, destroy server
     enet_host_destroy(server);
+  }
+  
+  void ConnectionManager::disconnectClients(){
+    bool disconnected=false;
+    ENetEvent event;
+    ClientList *temp=client;
+    while(temp!=NULL){
+      enet_peer_disconnect(temp->event->peer, 0);
+      while( !disconnected && enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT) > 0){
+        switch (event.type)
+        {
+          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:
+            disconnected=true;
+            break;
+        }
+      }
+      temp = temp->next;
+      disconnected=false;
+    }
+    return;
   }
 
Index: code/branches/FICN/src/network/ConnectionManager.h
===================================================================
--- code/branches/FICN/src/network/ConnectionManager.h	(revision 368)
+++ code/branches/FICN/src/network/ConnectionManager.h	(revision 369)
@@ -61,4 +61,5 @@
     // send out all queued packets
     bool sendPackets(ENetEvent *event);
+    bool sendPackets();
     private:
     bool clientDisconnect(ENetPeer *peer);
@@ -67,4 +68,5 @@
     // implementation of the listener
     void receiverThread(); //thread2
+    void disconnectClients();
     //packetbuffer
     PacketBuffer buffer;
Index: code/branches/FICN/src/network/GameStateManager.cc
===================================================================
--- code/branches/FICN/src/network/GameStateManager.cc	(revision 368)
+++ code/branches/FICN/src/network/GameStateManager.cc	(revision 369)
@@ -95,5 +95,9 @@
       }
       if(it==0){  // add the new object
-        
+        // =================== factory command to add object
+        // can we be sure the object really was added?
+        it=orxonox::ObjectList<Synchronisable>::end();
+        it->objectID=sync.objectID;
+        it->classID=sync.classID;
       }
     } else {
Index: code/branches/FICN/src/network/PacketDecoder.cc
===================================================================
--- code/branches/FICN/src/network/PacketDecoder.cc	(revision 368)
+++ code/branches/FICN/src/network/PacketDecoder.cc	(revision 369)
@@ -100,5 +100,5 @@
 	enet_packet_destroy( packet );
 	
-	printChat( chatting ); //debug info
+	processChat( chatting ); //debug info
 	
 }
@@ -118,7 +118,15 @@
 	//copy the gamestate data
 	memcpy( (void*)(currentState->data), (const void*)(data+3*sizeof( int )), currentState->size );
-	
+  
 	//clean memory
 	enet_packet_destroy( packet );
+  //run processGamestate
+  processGamestate(currentState);
+}
+
+// now the data processing functions:
+
+void PacketDecoder::processChat( chat *data){
+  printChat(data);
 }
 
Index: code/branches/FICN/src/network/PacketManager.h
===================================================================
--- code/branches/FICN/src/network/PacketManager.h	(revision 368)
+++ code/branches/FICN/src/network/PacketManager.h	(revision 369)
@@ -92,4 +92,9 @@
 	void gstate( ENetPacket* packet );
 	
+  //process data
+  virtual void processGamestate(GameState *state);
+  virtual void processChat( chat *data);
+  virtual void processAck( ack *data);
+  
 	//print functions
 	void printAck( ack* data );
Index: code/branches/FICN/src/network/Server.cc
===================================================================
--- code/branches/FICN/src/network/Server.cc	(revision 368)
+++ code/branches/FICN/src/network/Server.cc	(revision 369)
@@ -21,6 +21,7 @@
    */
   Server::Server(){
-
-
+    connection = ConnectionManager();
+    gamestates = GameStateManager();
+    packet_gen = PacketGenerator();
   }
 
@@ -30,7 +31,8 @@
    * @param bindAddress Address to listen on
    */
-  Server::Server(int port, std::string bindAddress) : connection(port, bindAddress){
-
-
+  Server::Server(int port, std::string bindAddress){
+    connection = ConnectionManager(port, bindAddress);
+    gamestates = GameStateManager();
+    packet_gen = PacketGenerator();
   }
 
@@ -40,14 +42,49 @@
    * @param bindAddress Address to listen on
    */
-  Server::Server(int port, const char *bindAddress) : connection(port, bindAddress){
-
-
-
-
+  Server::Server(int port, const char *bindAddress){
+    connection = ConnectionManager(port, bindAddress);
+    gamestates = GameStateManager();
+    packet_gen = PacketGenerator();
   }
-
-
-
-
-
+  
+  /**
+   * This function opens the server by creating the listener thread
+   */
+  void Server::open(){
+    connection.createListener();
+    return;
+  }
+  
+  /**
+   * This function closes the server
+   */
+  void Server::close(){
+    connection.quitListener();
+    return;
+  }
+  
+  /**
+   * This function sends out a message to all clients
+   * @param msg message
+   * @return true/false
+   */
+  bool Server::sendMSG(std::string msg){
+    ENetPacket *packet = packet_gen.chatMessage(msg.c_str());
+    connection.addPacketAll(packet);
+    return connection.sendPackets();
+  }
+  /**
+   * This function sends out a message to all clients
+   * @param msg message
+   * @return true/false
+   */
+  bool Server::sendMSG(const char *msg){
+    ENetPacket *packet = packet_gen.chatMessage(msg);
+    connection.addPacketAll(packet);
+    return connection.sendPackets();
+  }
+  
+  void Server::tick(){
+  }
+  
 }
Index: code/branches/FICN/src/network/Server.h
===================================================================
--- code/branches/FICN/src/network/Server.h	(revision 368)
+++ code/branches/FICN/src/network/Server.h	(revision 369)
@@ -18,5 +18,5 @@
 #include "ConnectionManager.h"
 #include "PacketManager.h"
-
+#include "enet/enet.h"
 
 namespace network{
@@ -31,13 +31,13 @@
     Server(int port, std::string bindAddress);
     Server(int port, const char *bindAddress);
-
+    void open();
+    void close();
+    bool sendMSG(std::string msg);
+    bool sendMSG(const char *msg);
+    void tick();
     private:
     ConnectionManager connection;
-
-
-
-
-
-
+    GameStateManager gamestates;
+    PacketGenerator packet_gen;
 
   };
