Index: code/branches/FICN/src/network/CMakeLists.txt
===================================================================
--- code/branches/FICN/src/network/CMakeLists.txt	(revision 337)
+++ code/branches/FICN/src/network/CMakeLists.txt	(revision 337)
@@ -0,0 +1,7 @@
+PROJECT(Orxonox)
+
+SET(SRC_FILES Client.cc ConnectionManager.cc PacketBuffer.cc PacketGenerator.cc Synchronisable.cc ClientConnection.cc GameStateManager.cc PacketDecoder.cc Server.cc)
+
+INCLUDE_DIRECTORIES(..)
+
+ADD_LIBRARY(network ${SRC_FILES} ${ENet_LIBRARY})
Index: code/branches/FICN/src/network/Client.cc
===================================================================
--- code/branches/FICN/src/network/Client.cc	(revision 337)
+++ code/branches/FICN/src/network/Client.cc	(revision 337)
@@ -0,0 +1,142 @@
+//
+// C++ Implementation: Client
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "Client.h"
+
+namespace network{
+
+  /**
+   * 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
+    //server_address="127.0.0.1";
+    //port = NETWORK_PORT;
+    isConnected=false;
+  }
+
+  /**
+   * Constructor for the Client class
+   * @param address the server address
+   * @param port port of the application on the server
+   */
+  Client::Client(std::string address, int port) : client_connection(port, address){
+    //server_address=address.c_str();
+    //this->port = port;
+    isConnected=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){
+    //server_address = address;
+    //this->port = port;
+    isConnected=false;
+  }
+
+  /**
+   * Establish the Connection to the Server
+   * @return true/false
+   */
+  bool Client::establishConnection(){
+    isConnected=client_connection.createConnection();
+    return isConnected;
+  }
+
+  /**
+   * closes the Connection to the Server
+   * @return true/false
+   */
+  bool Client::closeConnection(){
+    isConnected=false;
+    return client_connection.closeConnection();
+  }
+
+  /**
+   * submits a MouseAction to the server
+   * @param x x Coordinate
+   * @param y y Coordinate
+   * @return true/false
+   */
+  bool Client::sendMouse(double x, double y){
+    ENetEvent event;
+    // generate packet and add it to the queue
+    if(!client_connection.addPacket(pck_gen.mousem(x, y)))
+        return false;
+    // send packets
+    client_connection.sendPackets(&event);
+    if(event.type==ENET_EVENT_TYPE_NONE)
+      return true;
+    else
+      return false;
+  }
+
+  /**
+   * submits a Keystrike to the server
+   * @param key_code code to submit
+   * @return true/false
+   */
+  bool Client::sendKeyboard(char key_code){
+    ENetEvent event;
+    // generate packet and add it to queue
+    if(!client_connection.addPacket(pck_gen.keystrike(key_code)))
+        return false;
+    // send packets
+    client_connection.sendPackets(&event);
+    if(event.type==ENET_EVENT_TYPE_NONE)
+      return true;
+    else
+      return false;
+  }
+
+  /**
+   * Adds a MouseAction to the PacketQueue
+   * @param x x Coordinate
+   * @param y y Coordinate
+   * @return true/false
+   */
+  bool Client::addMouse(double x, double y){
+    // generate packet and add it to the queue
+    if(client_connection.addPacket(pck_gen.mousem(x, y)))
+      return true;
+    else
+      return false;
+  }
+
+  /**
+   * Adds a Keystrike to the PacketQueue
+   * @param key_code
+   * @return true/false
+   */
+  bool Client::addKeyboard(char key_code){
+    ENetEvent event;
+    // generate packet and add it to queue
+    if(client_connection.addPacket(pck_gen.keystrike(key_code)))
+      return true;
+    else
+      return false;
+  }
+
+  /**
+   * Performs a GameState update
+   */
+  void Client::update(){
+    // to be implemented ==================
+
+
+  }
+
+}
Index: code/branches/FICN/src/network/Client.h
===================================================================
--- code/branches/FICN/src/network/Client.h	(revision 337)
+++ code/branches/FICN/src/network/Client.h	(revision 337)
@@ -0,0 +1,58 @@
+//
+// C++ Interface: Client
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef NETWORK_CLIENT_H
+#define NETWORK_CLIENT_H
+
+#include <string>
+
+#include "ClientConnection.h"
+#include "PacketManager.h"
+
+
+namespace network{
+
+/**
+ * The network/Client class
+ * This class implements all necessary function for the network communication
+ * It is the root class of the network module
+ *
+ */
+class Client : PacketDecoder{
+  public:
+  Client();
+  Client(std::string address, int port);
+  Client(const char *address, int port);
+
+  bool establishConnection();
+  bool closeConnection();
+
+  bool sendMouse(double x, double y);
+  bool sendKeyboard(char key_code);
+
+  bool addMouse(double x, double y);
+  bool addKeyboard(char key_code);
+
+  void update();
+
+  private:
+  ClientConnection client_connection;
+  PacketGenerator pck_gen;
+
+  //const char *server_address;
+  //int port;
+  bool isConnected;
+};
+
+}
+
+#endif
Index: code/branches/FICN/src/network/ClientConnection.cc
===================================================================
--- code/branches/FICN/src/network/ClientConnection.cc	(revision 337)
+++ code/branches/FICN/src/network/ClientConnection.cc	(revision 337)
@@ -0,0 +1,172 @@
+//
+// 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"
+
+namespace network{
+
+  boost::thread_group network_threads;
+
+  ClientConnection::ClientConnection(int port, std::string address){
+    quit=false;
+    server=NULL;
+    enet_address_set_host(&serverAddress, address.c_str());
+    serverAddress.port = NETWORK_PORT;
+    established=false;
+  }
+
+  ClientConnection::ClientConnection(int port, const char *address){
+    quit=false;
+    server=NULL;
+    enet_address_set_host(&serverAddress, address);
+    serverAddress.port = NETWORK_PORT;
+    established=false;
+  }
+
+  bool ClientConnection::waitEstablished(int milisec){
+    for(int i=0; i<=milisec && !established; i++)
+      usleep(1000);
+    return established;
+  }
+
+
+  ENetPacket *ClientConnection::getPacket(ENetAddress &address){
+    if(!buffer.isEmpty())
+      return buffer.pop(address);
+    else
+        return NULL;
+  }
+
+  bool ClientConnection::queueEmpty(){
+    return buffer.isEmpty();
+  }
+
+  bool ClientConnection::createConnection(){
+    network_threads.create_thread(boost::bind(boost::mem_fn(&ClientConnection::receiverThread), this));
+    // wait 10 seconds for the connection to be established
+    return waitEstablished(10000);
+  }
+
+  bool ClientConnection::closeConnection(){
+    quit=true;
+    network_threads.join_all();
+    established=false;
+    return true;
+  }
+
+
+  bool ClientConnection::addPacket(ENetPacket *packet){
+    if(server==NULL)
+      return false;
+    if(enet_peer_send(server, 1, packet)!=0)
+      return false;
+    else
+      return true;
+  }
+
+  bool ClientConnection::sendPackets(ENetEvent *event){
+    if(server==NULL)
+      return false;
+    if(enet_host_service(client, event, NETWORK_SEND_WAIT)>=0)
+      return true;
+    else
+      return false;
+  }
+
+  bool ClientConnection::sendPackets(){
+    ENetEvent event;
+    if(server==NULL)
+      return false;
+    if(enet_host_service(client, &event, NETWORK_SEND_WAIT)>=0)
+      return true;
+    else
+      return false;
+  }
+
+  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);
+    if(client==NULL)
+      // add some error handling here ==========================
+      quit=true;
+    //connect to the server
+    if(!establishConnection())
+      quit=true;
+    //main loop
+    while(!quit){
+      if(enet_host_service(client, &event, NETWORK_WAIT_TIMEOUT)<0){
+        // we should never reach this point
+        quit=true;
+        // add some error handling here ========================
+      }
+      switch(event.type){
+        // log handling ================
+      case ENET_EVENT_TYPE_RECEIVE:
+        processData(&event);
+        break;
+      case ENET_EVENT_TYPE_DISCONNECT:
+        // add some error/log handling here
+        // extend =====================
+        break;
+      }
+    }
+    // now disconnect
+
+    if(!disconnectConnection())
+    // if disconnecting failed destroy conn.
+      enet_peer_reset(server);
+    return;
+  }
+
+  bool ClientConnection::disconnectConnection(){
+    ENetEvent event;
+//     enet_peer_disconnect(server);
+    enet_peer_disconnect(server, 0);
+    while(enet_host_service(client, &event, NETWORK_WAIT_TIMEOUT) > 0){
+      switch (event.type)
+      {
+        case ENET_EVENT_TYPE_RECEIVE:
+          enet_packet_destroy(event.packet);
+          break;
+        case ENET_EVENT_TYPE_DISCONNECT:
+          return true;
+      }
+    }
+    enet_peer_reset(server);
+  }
+
+  bool ClientConnection::establishConnection(){
+    ENetEvent event;
+    // connect to peer
+    server = enet_host_connect(client, &serverAddress, NETWORK_CLIENT_CHANNELS);
+    if(server==NULL)
+      // error handling
+      return false;
+    // handshake
+    if(enet_host_service(client, &event, NETWORK_WAIT_TIMEOUT)>0 && event.type == ENET_EVENT_TYPE_CONNECT){
+      established=true;
+      return true;
+    }
+    else
+      return false;
+  }
+
+  bool ClientConnection::processData(ENetEvent *event){
+    // just add packet to the buffer
+    // this can be extended with some preprocessing
+    return buffer.push(event);
+  }
+
+
+}
Index: code/branches/FICN/src/network/ClientConnection.h
===================================================================
--- code/branches/FICN/src/network/ClientConnection.h	(revision 337)
+++ code/branches/FICN/src/network/ClientConnection.h	(revision 337)
@@ -0,0 +1,79 @@
+//
+// C++ Interface: ClientConnection
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef NETWORK_CLIENTCONNECTION_H
+#define NETWORK_CLIENTCONNECTION_H
+
+#include <iostream>
+#include <string>
+// enet library for networking support
+#include <enet/enet.h>
+// boost.thread library for multithreading support
+#include <boost/thread/thread.hpp>
+#include <boost/bind.hpp>
+// headerfile
+#include "ClientConnection.h"
+#include "PacketBuffer.h"
+
+namespace network{
+  //
+#define NETWORK_PORT 55556
+#define NETWORK_CLIENT_MAX_CONNECTIONS 5
+#define NETWORK_WAIT_TIMEOUT 5000
+#define NETWORK_SEND_WAIT 5
+#define NETWORK_CLIENT_CHANNELS 2
+
+
+  class ClientConnection{
+    public:
+    ClientConnection(int port, std::string address);
+    ClientConnection(int port, const char* address);
+    ENetPacket *getPacket(ENetAddress &address); // thread1
+    // check wheter the packet queue is empty
+    bool queueEmpty();
+    // create a new listener thread
+    bool createConnection();
+    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);
+    private:
+    bool processData(ENetEvent *event);
+    // implementation of the listener
+    void receiverThread(); //thread2
+    //packetbuffer
+    bool establishConnection();
+    bool disconnectConnection();
+    PacketBuffer buffer;
+    // enet stuff
+    ENetHost *client;
+    ENetAddress serverAddress;
+    // quit-variable (communication with threads)
+    bool quit;
+    bool established;
+    // clientlist
+    ENetPeer *server;
+  };
+
+
+
+
+
+
+
+
+}
+
+#endif
Index: code/branches/FICN/src/network/ConnectionManager.cc
===================================================================
--- code/branches/FICN/src/network/ConnectionManager.cc	(revision 337)
+++ code/branches/FICN/src/network/ConnectionManager.cc	(revision 337)
@@ -0,0 +1,206 @@
+//
+// C++ Interface: ConnectionManager
+//
+// Description: The Class ConnectionManager 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 "ConnectionManager.h"
+
+namespace network{
+
+  boost::thread_group network_threads;
+
+  void test(){
+    return;
+  }
+
+  ConnectionManager::ConnectionManager(){
+    quit=false;
+    client=NULL;
+    bindAddress.host = ENET_HOST_ANY;
+    bindAddress.port = NETWORK_PORT;
+  }
+
+  ConnectionManager::ConnectionManager(int port, std::string address){
+    quit=false;
+    client=NULL;
+    enet_address_set_host (& bindAddress, address.c_str());
+    bindAddress.port = NETWORK_PORT;
+  }
+
+  ConnectionManager::ConnectionManager(int port, const char *address){
+    quit=false;
+    client=NULL;
+    enet_address_set_host (& bindAddress, address);
+    bindAddress.port = NETWORK_PORT;
+  }
+
+  ENetPacket *ConnectionManager::getPacket(ENetAddress &address){
+    if(!buffer.isEmpty())
+      return buffer.pop(address);
+    else
+        return NULL;
+  }
+
+  bool ConnectionManager::queueEmpty(){
+    return buffer.isEmpty();
+  }
+
+  void ConnectionManager::createListener(){
+    network_threads.create_thread(boost::bind(boost::mem_fn(&ConnectionManager::receiverThread), this));
+//     boost::thread thr(boost::bind(boost::mem_fn(&ConnectionManager::receiverThread), this));
+    return;
+  }
+
+  bool ConnectionManager::quitListener(){
+    quit=true;
+    network_threads.join_all();
+    return true;
+  }
+
+  bool ConnectionManager::addPacket(ENetPacket *packet, ENetPeer *peer){
+    if(client=NULL)
+      return false;
+    ClientList *temp=client;
+    while(peer->host != temp->event->peer->host){
+      temp=temp->next;
+      if(temp==NULL)
+        return false;
+    }
+    if(enet_peer_send(temp->event->peer, temp->ID, packet)!=0)
+      return false;
+    return true;
+  }
+
+  bool ConnectionManager::addPacket(ENetPacket *packet, int ID){
+    if(client==NULL)
+      return false;
+    ClientList *temp=client;
+    while(ID != temp->ID){
+      temp=temp->next;
+      if(temp==NULL)
+        return false;
+    }
+    if(enet_peer_send(temp->event->peer, temp->ID, packet)!=0)
+      return false;
+    else
+      return true;
+  }
+
+  bool ConnectionManager::addPacketAll(ENetPacket *packet){
+    ClientList *temp=client;
+    while(temp!=NULL){
+      if(enet_peer_send(temp->event->peer, temp->ID, packet)!=0)
+         return false;
+    }
+    return true;
+  }
+
+  bool ConnectionManager::sendPackets(ENetEvent *event){
+    if(server==NULL)
+      return false;
+    if(enet_host_service(server, event, NETWORK_SEND_WAIT)>=0)
+      return true;
+    else
+      return false;
+  }
+
+  void ConnectionManager::receiverThread(){
+    // what about some error-handling here ?
+    enet_initialize();
+    atexit(enet_deinitialize);
+    ENetEvent event;
+    server = enet_host_create(&bindAddress, NETWORK_MAX_CONNECTIONS, 0, 0);
+    if(server==NULL)
+      // add some error handling here ==========================
+      quit=true;
+
+    while(!quit){
+      if(enet_host_service(server, &event, NETWORK_WAIT_TIMEOUT)<0){
+        // we should never reach this point
+        quit=true;
+        // add some error handling here ========================
+      }
+      switch(event.type){
+        // log handling ================
+        case ENET_EVENT_TYPE_CONNECT:
+        addClient(&event);
+        break;
+      case ENET_EVENT_TYPE_RECEIVE:
+        processData(&event);
+        break;
+      case ENET_EVENT_TYPE_DISCONNECT:
+        // add some error/log handling here
+        clientDisconnect(event.peer);
+        break;
+      }
+    }
+    // if we're finishied, destroy server
+    enet_host_destroy(server);
+  }
+
+  bool ConnectionManager::processData(ENetEvent *event){
+    // just add packet to the buffer
+    // this can be extended with some preprocessing
+    return buffer.push(event);
+  }
+
+  bool ConnectionManager::clientDisconnect(ENetPeer *peer){
+    ClientList *temp=client;
+    // do we have to remove the first item ?
+    if(temp->event->peer->host==peer->host){
+      if(temp->next==NULL){
+        client=NULL;
+      } else{
+        client=temp->next;
+      }
+      delete temp;
+      return true;
+    } else {
+      while(temp->next!=NULL){
+        if(temp->next->event->peer->host==peer->host){
+          // do a correct relink and delete the disconnected client
+          ClientList *temp2=temp->next;
+          temp->next=temp2->next;
+          delete temp2;
+          return true;
+        } else
+          //otherwise keep on searching ;)
+          temp=temp->next;
+      }
+    }
+    return false;
+  }
+
+  bool ConnectionManager::addClient(ENetEvent *event){
+
+    // first client?
+    if(client==NULL){
+      client =new ClientList;
+      client->ID=1;
+      client->next=NULL;
+      client->event = event;
+    } else {
+      // otherwise add a new element to clientlist
+      ClientList *temp = client;
+      int i=1;
+      while(temp->next != NULL){
+        temp=temp->next;
+        i++;
+      }
+      temp->next=new ClientList;
+      temp=temp->next;
+      temp->ID=i+1;
+      temp->event=event;
+      temp->next=NULL;
+    }
+    return true;
+  }
+
+
+}
Index: code/branches/FICN/src/network/ConnectionManager.h
===================================================================
--- code/branches/FICN/src/network/ConnectionManager.h	(revision 337)
+++ code/branches/FICN/src/network/ConnectionManager.h	(revision 337)
@@ -0,0 +1,91 @@
+//
+// C++ Interface: ConnectionManager
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef NETWORK_CONNECTIONMANAGER_H
+#define NETWORK_CONNECTIONMANAGER_H
+
+#include <iostream>
+#include <string>
+// enet library for networking support
+#include <enet/enet.h>
+// boost.thread library for multithreading support
+#include <boost/thread/thread.hpp>
+#include <boost/bind.hpp>
+// headerfile
+#include "ConnectionManager.h"
+#include "PacketBuffer.h"
+
+namespace network{
+  //
+#define NETWORK_PORT 55556
+#define NETWORK_MAX_CONNECTIONS 50
+#define NETWORK_WAIT_TIMEOUT 5000
+#define NETWORK_SEND_WAIT 5
+  //just some defines to make life easier ;)
+// #define ENetEvent std::ENetEvent
+// #define ENetHost std::ENetHost
+// #define ENetAddress std::ENetAddress
+// #define ENetPeer std::ENetPeer
+
+  struct ClientList{
+    ENetEvent *event;
+    int ID;
+    ClientList *next;
+  };
+
+  class ConnectionManager{
+    public:
+    ConnectionManager();
+    ConnectionManager(int port, const char *address);
+    ConnectionManager(int port, std::string address);
+    ENetPacket *getPacket(ENetAddress &address); // thread1
+    // check wheter the packet queue is empty
+    bool queueEmpty();
+    // create a new listener thread
+    void createListener();
+    bool quitListener();
+    // add a packet to queue for a specific client peer
+    bool addPacket(ENetPacket *packet, ENetPeer *peer);
+    // add ad packet to queue for a specific client ID
+    bool addPacket(ENetPacket *packet, int ID);
+    // add a packet to queue for all clients
+    bool addPacketAll(ENetPacket *packet);
+    // send out all queued packets
+    bool sendPackets(ENetEvent *event);
+    private:
+    bool clientDisconnect(ENetPeer *peer);
+    bool processData(ENetEvent *event);
+    bool addClient(ENetEvent *event);
+    // implementation of the listener
+    void receiverThread(); //thread2
+    //packetbuffer
+    PacketBuffer buffer;
+    // enet stuff
+    ENetHost *server;
+    ENetAddress bindAddress;
+    // quit-variable (communication with threads)
+    bool quit;
+    // clientlist
+    ClientList *client;
+//     thread group
+//     boost::thread_group threads;
+  };
+
+
+
+
+
+
+
+
+}
+
+#endif
Index: code/branches/FICN/src/network/GameStateManager.cc
===================================================================
--- code/branches/FICN/src/network/GameStateManager.cc	(revision 337)
+++ code/branches/FICN/src/network/GameStateManager.cc	(revision 337)
@@ -0,0 +1,127 @@
+//
+// C++ Implementation: GameStateManager
+//
+// Description: 
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#include "GameStateManager.h"
+
+namespace network {
+
+GameStateManager::GameStateManager()
+{
+}
+
+GameStateManager::~GameStateManager()
+{
+}
+
+/**
+ * This function goes through the whole list of synchronisables and 
+ * saves all the synchronisables to a flat "list".
+ * @return struct of type gamestate containing the size of the whole gamestate and a pointer linking to the flat list
+ */
+GameState GameStateManager::getSnapshot(int id)
+{
+  //the size of the gamestate
+  int totalsize=0;
+  //the size of one specific synchronisable
+  int tempsize=0;
+  // get the start of the Synchronisable list
+  orxonox::Iterator<Synchronisable> it;
+  // struct for return value of Synchronisable::getData()
+  syncData sync;
+  
+  GameState retval; //return value
+  retval.id=id;
+  // reserve a little memory and increase it later on
+  retval.data = (unsigned char*)malloc(1);
+  
+  // offset of memory functions
+  int offset=0;
+  // go through all Synchronisables
+  for(it = orxonox::ObjectList<Synchronisable>::start(); it != 0; ++it){
+    //get size of the synchronisable
+    tempsize=it->getSize();
+    // add place for data and 3 ints (length,classid,objectid)
+    totalsize+=tempsize+3*sizeof(int);
+    // allocate additional space
+    retval.data = (unsigned char *)realloc((void *)retval.data, totalsize);
+    
+    // run Synchronisable::getData with offset and additional place for 3 ints in between (for ids and length)
+    sync=it->getData(retval.data+offset+3*sizeof(int));
+    *(retval.data+offset)=sync.length;
+    *(retval.data+offset+sizeof(int))=sync.objectID;
+    *(retval.data+offset+2*sizeof(int))=sync.classID;
+    // increase data pointer
+    offset+=tempsize+3*sizeof(int);
+  }
+  retval.size=totalsize;
+  return retval;
+}
+
+/**
+ * This function loads a Snapshort of the gamestate into the universe
+ * @param state a GameState struct containing the size of the gamestate and a pointer linking to a flat list (returned by getSnapshot)
+ */
+bool GameStateManager::loadSnapshot(GameState state)
+{
+  unsigned char *data=state.data;
+  // get the start of the Synchronisable list
+  orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
+  syncData sync;
+  // loop as long as we have some data ;)
+  while(data < state.data+state.size){
+    // prepare the syncData struct
+    sync.length = *(int *)data;
+    data+=sizeof(int);
+    sync.objectID = *(int *)data;
+    data+=sizeof(int);
+    sync.classID = *(int *)data;
+    data+=sizeof(int);
+    sync.data = data;
+    data+=sync.length;
+    
+    if(it->objectID!=sync.objectID){
+      // bad luck ;)
+      // delete the synchronisable (obviously seems to be deleted on the server)
+      while(it != 0 && it->objectID!=sync.objectID){
+        removeObject(it);
+      }
+      if(it==0){  // add the new object
+        
+      }
+    } else {
+      // we have our object
+      if(! it->updateData(sync))
+        std::cout << "We couldn't update objectID: " \
+          << sync.objectID << "; classID: " << sync.classID << std::endl;
+    }
+    
+  }
+  
+  
+}
+
+/**
+ * This function removes a Synchronisable out of the universe
+ * @param it iterator of the list pointing to the object
+ * @return iterator pointing to the next object in the list
+ */
+// orxonox::Iterator<Synchronisable> removeObject(orxonox::Iterator<Synchronisable> it){
+void removeObject(orxonox::Iterator<Synchronisable> &it){
+  orxonox::Iterator<Synchronisable> temp=it;
+  ++it;
+  delete  *temp;
+//   return it;
+}
+
+
+}
+
+
Index: code/branches/FICN/src/network/GameStateManager.h
===================================================================
--- code/branches/FICN/src/network/GameStateManager.h	(revision 337)
+++ code/branches/FICN/src/network/GameStateManager.h	(revision 337)
@@ -0,0 +1,52 @@
+//
+// C++ Interface: GameStateManager
+//
+// Description: 
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef NETWORK_GAMESTATEMANAGER_H
+#define NETWORK_GAMESTATEMANAGER_H
+
+#include "Synchronisable.h"
+#include "orxonox/core/IdentifierIncludes.h"
+#include "orxonox/core/Iterator.h"
+
+namespace network {
+
+/**
+ * This struct defines a gamestate:
+ * size: total size of the data in *data
+ * data: pointer to the data allocated in the memory
+ */
+  struct GameState{
+  int id;
+  int size;
+  unsigned char *data;
+};
+
+/**
+ * This Class implements a manager for gamestates:
+ * - creating snapshots of gamestates
+ * - writing gamestates to universe
+ * - diffing gamestates ?
+ * @author Oliver Scheuss
+*/
+class GameStateManager{
+public:
+  GameStateManager();
+  ~GameStateManager();
+  GameState getSnapshot(int id);
+  bool loadSnapshot(GameState state);
+private:
+  bool removeObject(orxonox::Iterator<Synchronisable> it);
+
+};
+
+}
+
+#endif
Index: code/branches/FICN/src/network/Makefile.norm
===================================================================
--- code/branches/FICN/src/network/Makefile.norm	(revision 337)
+++ code/branches/FICN/src/network/Makefile.norm	(revision 337)
@@ -0,0 +1,40 @@
+CC=g++
+MAIN_INC=..
+INC=-I ${MAIN_INC}
+
+all: server client
+
+# Link command:
+server: PacketBuffer.o ConnectionManager.o dummyserver.o PacketDecoder.o PacketGenerator.o
+	${CC} PacketDecoder.o PacketGenerator.o ConnectionManager.o dummyserver.o PacketBuffer.o -o server -lenet -lboost_thread -g
+
+dummyserver.o: dummyserver.cc
+	${CC} -c dummyserver.cc -o dummyserver.o -g ${INC}
+# Compilation commands:
+ConnectionManager.o: ConnectionManager.cc ConnectionManager.h
+	${CC} -c ConnectionManager.cc -o ConnectionManager.o -g ${INC}
+ClientConnection.o: ClientConnection.cc ClientConnection.h
+	${CC} -c ClientConnection.cc -o ClientConnection.o -g ${INC}
+
+PacketBuffer.o: PacketBuffer.cc
+	${CC} -c PacketBuffer.cc -o PacketBuffer.o -g ${INC}
+PacketGenerator.o: PacketGenerator.cc
+	${CC} -c PacketGenerator.cc -o PacketGenerator.o -g ${INC}
+PacketDecoder.o: PacketDecoder.cc
+	${CC} -c PacketDecoder.cc -o PacketDecoder.o -g ${INC}
+Client.o: Client.cc
+	${CC} -c Client.cc -g ${INC}
+Server.o: Server.cc
+	${CC} -c Server.cc -g ${INC}
+Synchronisable.o: Synchronisable.cc
+	${CC} -c Synchronisable.cc -g ${INC}
+GameStateManager.o: GameStateManager.cc
+	${CC} -c GameStateManager.cc -g ${INC}
+
+clean:
+	rm -rf *.o
+
+client_old: PacketGenerator.o dummyclient.cc
+	${CC} dummyclient.cc PacketGenerator.o -o client -lenet -g ${INC}
+client: PacketGenerator.o ClientConnection.o PacketBuffer.o dummyclient2.cc 
+	${CC} dummyclient2.cc PacketGenerator.o PacketBuffer.o ClientConnection.o -o client -lenet -lboost_thread -g ${INC}
Index: code/branches/FICN/src/network/Makefile.tardis
===================================================================
--- code/branches/FICN/src/network/Makefile.tardis	(revision 337)
+++ code/branches/FICN/src/network/Makefile.tardis	(revision 337)
@@ -0,0 +1,39 @@
+all: server client
+
+CC=g++-4.1.1
+
+BOOST_INC=/usr/pack/boost-1.34.1-sd/i686-debian-linux3.1/include/boost-1_34_1/
+BOOST_LIB=/usr/pack/boost-1.34.1-sd/i686-debian-linux3.1/lib/
+MAIN_INC=..
+ENET_INC=/usr/pack/enet-2007-sd/include/
+ENET_LIB=/usr/pack/enet-2007-sd/i686-debian-linux3.1/lib/
+INC=-I ${BOOST_INC} -I ${MAIN_INC} -I ${ENET_INC}
+LIB=-L ${BOOST_LIB} -L ${ENET_LIB}
+
+# Link command:
+server: clean PacketBuffer.o ConnectionManager.o dummyserver.o PacketGenerator.o PacketDecoder.o
+	${CC} ConnectionManager.o dummyserver.o PacketBuffer.o PacketDecoder.o PacketGenerator.o -o server -lenet -lboost_thread-gcc41-mt -g ${INC} ${LIB} -Wl,-rpath,${BOOST_LIB} -Wl,-rpath,${ENET_LIB}
+
+dummyserver.o:
+	${CC} -c dummyserver.cc -o dummyserver.o -g ${INC}
+# Compilation commands:
+
+ConnectionManager.o:
+	${CC} -c ConnectionManager.cc -o ConnectionManager.o -g ${INC}
+
+PacketBuffer.o: 
+	${CC} -c PacketBuffer.cc -o PacketBuffer.o -g ${INC}
+PacketGenerator.o: PacketGenerator.cc
+	${CC} -c PacketGenerator.cc -o PacketGenerator.o -g ${INC}
+PacketDecoder.o: PacketDecoder.cc
+	${CC} -c PacketDecoder.cc -o PacketDecoder.o -g ${INC}
+Synchronisable.o: Synchronisable.cc
+	${CC} -c Synchronisable.cc -g ${INC}
+GameStateManager.o: GameStateManager.cc
+	${CC} -c GameStateManager.cc -g ${INC}
+
+clean:
+	rm -rf *.o
+
+client: dummyclient.cc PacketDecoder.o PacketGenerator.o
+	${CC} PacketGenerator.o PacketDecoder.o dummyclient.cc -o client -lenet ${LIB} ${INC} -Wl,-rpath,${BOOST_LIB}
Index: code/branches/FICN/src/network/PacketBuffer.cc
===================================================================
--- code/branches/FICN/src/network/PacketBuffer.cc	(revision 337)
+++ code/branches/FICN/src/network/PacketBuffer.cc	(revision 337)
@@ -0,0 +1,103 @@
+// C++ PacketBuffer
+// d
+// Author Oliver Scheuss
+
+#ifndef NETWORK_PACKETBUFFER_CC
+#define NETWORK_PACKETBUFFER_CC
+
+#include <iostream>
+#include "PacketBuffer.h"
+
+namespace network{
+
+   boost::mutex networkPacketBufferMutex;
+
+PacketBuffer::PacketBuffer(){
+  closed=false;
+  first=NULL;
+  last=NULL;
+}
+    //this is needed in order to make the packetbuffer threadsafe
+
+
+bool PacketBuffer::push(ENetEvent *ev){
+  boost::mutex::scoped_lock lock(networkPacketBufferMutex);
+//   if(closed)
+//     return false;
+  // first element?
+  if(first==NULL){
+    first=new QueueItem;
+    last=first;
+    last->next=NULL;
+    // change this!!!!!!!
+    last->packet = ev->packet;
+    last->address = ev->peer->address;
+    } else {
+    //insert a new element at the bottom
+    last->next = new QueueItem;
+    last=last->next;
+    // initialize last->next
+    last->next=NULL;
+    // save the packet to the new element
+    last->packet = ev->packet;
+    last->address = ev->peer->address;
+  }
+  return true;
+}
+
+ENetPacket *PacketBuffer::pop(){
+  boost::mutex::scoped_lock lock(networkPacketBufferMutex);
+  if(first!=NULL /*&& !closed*/){
+    QueueItem *temp = first;
+    // get packet
+    ENetPacket *pck=first->packet;
+    // remove first element
+    first = first->next;
+    delete temp;
+    return pck;
+  } else{
+    return NULL;
+  }
+}
+
+ENetPacket *PacketBuffer::pop(ENetAddress &address){
+  boost::mutex::scoped_lock lock(networkPacketBufferMutex);
+  if(first!=NULL /*&& !closed*/){
+    QueueItem *temp = first;
+    // get packet
+    ENetPacket *pck=first->packet;
+    address = first->address;
+    // remove first element
+    first = first->next;
+    delete temp;
+    return pck;
+  } else{
+    return NULL;
+  }
+}
+
+bool PacketBuffer::isEmpty(){
+  return (first==NULL);
+}
+
+void PacketBuffer::print(){
+  QueueItem *temp=first;
+  while(temp!=NULL){
+//    std::cout << temp->packet->data << std::endl;
+    temp=temp->next;
+  }
+
+}
+
+bool PacketBuffer::isClosed(){
+  return closed;
+}
+
+void PacketBuffer::setClosed(bool value){
+  closed=value;
+  return;
+}
+
+}// namespace network
+
+#endif
Index: code/branches/FICN/src/network/PacketBuffer.h
===================================================================
--- code/branches/FICN/src/network/PacketBuffer.h	(revision 337)
+++ code/branches/FICN/src/network/PacketBuffer.h	(revision 337)
@@ -0,0 +1,58 @@
+//
+// C++ Interface: PacketBuffer
+//
+// Description: 
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef NETWORK_PACKETBUFFER_H 
+#define NETWORK_PACKETBUFFER_H
+
+#include <queue>
+#include <string>
+#include <enet/enet.h>
+#include <boost/bind.hpp>
+#include <boost/thread/mutex.hpp>
+
+
+namespace network{
+
+
+struct PacketEnvelope{
+  int length;
+  int data;
+};
+
+struct QueueItem{
+  ENetPacket *packet;
+  ENetAddress address;
+  QueueItem *next;
+};
+
+class PacketBuffer{
+public:
+  PacketBuffer();
+  bool isEmpty();
+  bool isClosed();
+  void setClosed(bool value);
+  void print();
+  // pops a packet from the queue
+  ENetPacket *pop();
+  ENetPacket *pop(ENetAddress &address);
+  // pushs a packet to the queue
+  bool push(ENetEvent *ev);
+  
+private:
+  QueueItem *first;
+  QueueItem *last;
+  bool closed;
+  
+};
+
+} //namespace
+#endif /* NETWORK_PACKETBUFFER_H */
Index: code/branches/FICN/src/network/PacketBufferTest.cc
===================================================================
--- code/branches/FICN/src/network/PacketBufferTest.cc	(revision 337)
+++ code/branches/FICN/src/network/PacketBufferTest.cc	(revision 337)
@@ -0,0 +1,25 @@
+#include "PacketBuffer.h"
+#include "PacketBuffer.cc"
+#include <iostream>
+#include <string>
+
+using namespace network;
+
+int main(int argc, char **argv[]){
+  PacketBuffer test = PacketBuffer();
+  PacketEnvelope p={8, 5};
+  if(test.isEmpty())
+    std::cout << "empty buffer" << std::endl;
+  for(int i=0; i<10; i++){
+    p.data=i*i;
+    std::cout << i << ": pushing " << p.data << std::endl;
+    test.push(p);
+  }
+  std::cout << std::endl << "queue.print()" << std::endl;
+  test.print();
+  while(!test.isEmpty()){
+    int i=test.pop().data;
+    std::cout << "We popped the value " << i << std::endl;
+  }
+  return 0;
+}
Index: code/branches/FICN/src/network/PacketBufferTestExt.cc
===================================================================
--- code/branches/FICN/src/network/PacketBufferTestExt.cc	(revision 337)
+++ code/branches/FICN/src/network/PacketBufferTestExt.cc	(revision 337)
@@ -0,0 +1,51 @@
+#include <string>
+#include <iostream>
+#include <enet/enet.h>
+#include <boost/thread/thread.hpp>
+#include "PacketBuffer.h"
+#include "PacketBuffer.cc"
+
+using namespace network;
+
+
+void write(PacketBuffer *test){
+  ENetPacket *packet;
+  if(test->isEmpty())
+    std::cout << "empty buffer" << std::endl;
+  for(int i=0; i<10; i++){
+    std::string temp = "packet ";
+    packet = enet_packet_create("packet", strlen("packet ")+1,
+ENET_PACKET_FLAG_RELIABLE);
+    std::cout << i << ": pushing " << packet->data << std::endl;
+    test->push(packet);
+    if(i==5)
+      usleep(200000);
+  }
+  test->setClosed(true);
+  return;
+}
+
+void read(PacketBuffer *test){
+  //test->print();
+  // exit if the queue is closed and empty
+  while(!test->isClosed() || !test->isEmpty()){
+    // only pop if the queue isn't empty
+    while(!test->isEmpty()){
+      std::cout << "We popped the value " << test->pop()->data << std::endl;
+    }
+  }
+  return;
+}
+
+
+int main(int argc, char **argv[]){
+  PacketBuffer test = PacketBuffer();
+  boost::thread thrd1(boost::bind(&write, &test));
+  boost::thread thrd2(boost::bind(&read, &test));
+
+  thrd1.join();
+  thrd2.join();
+
+  return 0;
+}
+
Index: code/branches/FICN/src/network/PacketDecoder.cc
===================================================================
--- code/branches/FICN/src/network/PacketDecoder.cc	(revision 337)
+++ code/branches/FICN/src/network/PacketDecoder.cc	(revision 337)
@@ -0,0 +1,155 @@
+/*
+ * Class contains functions to determine and decode incomming packages
+ * ->don't read this without the class PacketGenerator, since they belong together
+ * 
+ * Autor: Dumeni Manatschal
+ * 
+*/
+
+#include "enet/enet.h"
+#include "PacketManager.h"
+#include <iostream>
+
+using namespace std;
+using namespace network;
+
+PacketDecoder::PacketDecoder(){}
+
+//call this function out of an instance of PacketDecoder
+//it will determine the type id and call the right decode function
+bool PacketDecoder::elaborate( ENetPacket* packet, int clientId )
+{
+	int client = clientId;
+	cout << "clientId: " << client << endl; //control cout, not important, just debugging info
+	int id = (int)*packet->data; //the first 4 bytes are always the enet packet id
+	switch( id ) {
+	case ACK:
+		acknowledgement( packet );
+		return true;
+		break;
+	case MOUSE:
+		mousem( packet );
+		return true;
+		break;
+	case KEYBOARD:
+		keystrike( packet );
+		return true;
+		break;
+	case CHAT:
+		chatMessage( packet );
+		return true;
+		break;
+	case GAMESTATE:
+		gstate( packet );
+		return true;
+		break;
+	}
+	return false;
+}
+
+//following are the decode functions for the data of the packets
+
+void PacketDecoder::acknowledgement( ENetPacket* packet )
+{
+	ack* a = new ack;
+	*a = *(ack*)packet->data; //press pattern of ack on new data
+	
+	//clean memory
+	enet_packet_destroy( packet );
+	
+	printAck( a ); //debug info
+}
+
+void PacketDecoder::mousem( ENetPacket* packet )
+{
+	mouse* mouseMove = new mouse;
+	//copy data of packet->data to new struct
+	*mouseMove = *(mouse*)packet->data; 
+	
+	//clean memory
+	enet_packet_destroy( packet );
+	
+	printMouse( mouseMove ); //debug info
+}
+
+void PacketDecoder::keystrike( ENetPacket* packet )
+{
+	keyboard* key = new keyboard;
+	*key = *(keyboard*)packet->data; //see above
+	
+	//clean memory
+	enet_packet_destroy( packet );
+	
+	printKey( key ); //debug info
+
+}
+
+void PacketDecoder::chatMessage( ENetPacket* packet )
+{
+	chat* chatting = new chat;
+	chatting->id = (int)*packet->data; //first copy id into new struct
+	//since the chat message is a char*, allocate the memory needed
+	char* reserve = new char[packet->dataLength-4]; 
+	//copy the transmitted bytestream into the new generated char*,
+	//note the lenght of the message is represented as "packet->dataLength-sizeof( int )" 
+	memcpy( &reserve[0], packet->data+sizeof(int), packet->dataLength-sizeof(int) );
+	//put pointer of chatting struct to the begining of the new generated char*
+	chatting->message = reserve;
+	
+	//clean memory
+	enet_packet_destroy( packet );
+	
+	printChat( chatting ); //debug info
+	
+}
+
+void PacketDecoder::gstate( ENetPacket* packet )
+{
+	GameState* currentState = new GameState;
+	//since it's not alowed to use void* for pointer arithmetic
+	unsigned char* data = (unsigned char*)packet->data;
+	//copy the gamestate id into the struct, which is located at second place data+sizeof( int )
+	memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) );
+	//copy the size of the gamestate data into the new gamestate struct, located at 3th
+	//position of the data stream, data+2*sizeof( int )
+	memcpy( (void*)&(currentState->size), (const void*)(data+2*sizeof( int )), sizeof( int) );
+	//since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream
+	currentState->data = (unsigned char*)(malloc( currentState->size ));
+	//copy the gamestate data
+	memcpy( (void*)(currentState->data), (const void*)(data+3*sizeof( int )), currentState->size );
+	
+	//clean memory
+	enet_packet_destroy( packet );
+}
+
+//these are some print functions for test stuff
+
+void PacketDecoder::printAck( ack* data )
+{
+	cout << "data id: " << data->id << endl;
+	cout << "data:    " << data->a << endl;
+}
+
+void PacketDecoder::printMouse( mouse* data )
+{
+	cout << "data id: " << data->id << endl;
+	cout << "data:    " << data->x << " " << data->y << endl;
+}
+
+void PacketDecoder::printKey( keyboard* data )
+{
+	cout << "data id: " << data->id << endl;
+	cout << "data:    " << (char)data->press << endl;
+}
+
+void PacketDecoder::printChat( chat* data )
+{
+	cout << "data id: " << data->id << endl;
+	cout << "data:    " << data->message << endl;
+}
+
+void PacketDecoder::printGamestate( GameState* data )
+{
+	cout << "id of gamestate:   " << data->id << endl;
+	cout << "size of gamestate: " << data->size << endl;
+}
Index: code/branches/FICN/src/network/PacketGenerator.cc
===================================================================
--- code/branches/FICN/src/network/PacketGenerator.cc	(revision 337)
+++ code/branches/FICN/src/network/PacketGenerator.cc	(revision 337)
@@ -0,0 +1,87 @@
+/*
+ *Class generates packets that can be send by enet
+ * ->don't read this without the class PacketDecoder, since they belong together
+ * 
+ * Autor: Dumeni Manatschal
+ *  
+*/
+
+#include "PacketManager.h"
+#include "enet/enet.h"
+#include <iostream>
+#include <list>
+#include <string>
+#include <cstring>
+
+using namespace std;
+using namespace network;
+
+PacketGenerator::PacketGenerator() {}
+
+//following functions create a packet in form of bytestream
+
+ENetPacket* PacketGenerator::acknowledgement( int state, int reliable )
+{
+	cout << "generating new acknowledgement" << endl;
+	ack* ackreq = new ack;
+	ackreq->id = ACK;
+	ackreq->a = state;
+	
+	ENetPacket *packet = enet_packet_create( ackreq , sizeof( *ackreq ), reliable );
+	
+	return packet;
+}
+/*### mouseupdates */
+ENetPacket* PacketGenerator::mousem( double x, double y, int reliable )
+{
+	cout << "generating new mouse" << endl;
+	mouse* mousemove = new mouse;
+	mousemove->id = MOUSE;
+	mousemove->x = x;
+	mousemove->y = y;
+	
+	ENetPacket *packet = enet_packet_create( mousemove , sizeof( *mousemove ), reliable );
+	
+	return packet;
+}
+/*### keystrikes updates */
+ENetPacket* PacketGenerator::keystrike( char press, int reliable )
+{
+	cout << "generating new keyboard" << endl;
+	keyboard* key = new keyboard;
+	key->id = KEYBOARD;
+	key->press = press;
+	
+	ENetPacket *packet = enet_packet_create( key , sizeof( *key ), reliable );
+	
+	return packet;
+}
+/*### chat messages packet */
+ENetPacket* PacketGenerator::chatMessage( const char* message, int reliable )
+{
+	int* trans = new int[sizeof(int) + strlen(message) + 1];
+	*trans = CHAT;
+	//be carefull here, don't forget to allocate the space before using it ;-)
+	memcpy( &trans[1], (const void*)message, strlen( message ) + 1);
+	ENetPacket *packet = enet_packet_create( trans , sizeof( int ) + strlen( message ) + 1, reliable );
+	
+	return packet;
+}
+
+/*### gamestate packet */
+ENetPacket* PacketGenerator::gstate( GameState* states, int reliable )
+{
+	int* gid; *gid = GAMESTATE; //first assign the correct enet id
+	int totalLen = 3*sizeof( int ) + states->size; //calculate the total size of the datastream memory
+	unsigned char* data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream
+	memcpy( (void*)(data), (const void*)gid, sizeof( int ) ); //this is the enet id
+	memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the gamestate id
+	//this is the size of the gamestate data, place at 3th position of the enet datastream
+	memcpy( (void*)(data+2*sizeof(int)), (const void*)&(states->size), sizeof(int)); 
+	//place the gamestate data at the end of the enet datastream
+	memcpy( (void*)(data+3*sizeof( int )), (const void*)states->data, states->size );
+	//create an enet packet with the generated bytestream
+	ENetPacket *packet = enet_packet_create( data , totalLen, reliable );
+	
+	return packet;
+}
Index: code/branches/FICN/src/network/PacketManager.h
===================================================================
--- code/branches/FICN/src/network/PacketManager.h	(revision 337)
+++ code/branches/FICN/src/network/PacketManager.h	(revision 337)
@@ -0,0 +1,103 @@
+#ifndef PACKETMANAGER_H_
+#define PACKETMANAGER_H_
+
+#include <enet/enet.h>
+#include <network/GameStateManager.h>
+
+//enum netowk generaly used to set the type ID of a packet
+namespace network
+{
+enum packet_id {
+	ACK,
+	MOUSE,
+	KEYBOARD,
+	CHAT,
+	GAMESTATE
+};
+
+/*
+ * class to generate packets
+ * 
+ * @autor: Dumeni Manatschal
+ * 
+*/ 
+class PacketGenerator
+{
+public:
+	PacketGenerator();
+	//call one of this functions out of an instance of PacketGenerator to create a packet
+	ENetPacket* acknowledgement( int state, int reliable = ENET_PACKET_FLAG_RELIABLE );
+	ENetPacket* mousem( double x, double y, int reliable = ENET_PACKET_FLAG_RELIABLE );
+	ENetPacket* keystrike( char press, int reliable = ENET_PACKET_FLAG_RELIABLE );
+	ENetPacket* chatMessage( const char* message, int reliable = ENET_PACKET_FLAG_RELIABLE );
+	ENetPacket* gstate( GameState* states, int reliable = ENET_PACKET_FLAG_RELIABLE );
+private:
+	//used to set the bytes in the right order
+	struct ack {
+		int id;
+		int a;
+	};
+
+	struct mouse {
+		int id;
+		double x;
+		double y;
+	};
+
+	struct keyboard {
+		int id;
+		char press;
+	};	
+};
+
+/*
+ * class used to decode incoming packets
+ * 
+ * @autor: Dumeni Manatschal
+ * 
+*/
+class PacketDecoder
+{
+public:
+	PacketDecoder();
+	//call this function to decode, it calls the right decoding function below
+	bool elaborate( ENetPacket* packet, int clientId );
+private:
+	struct ack {
+		int id;
+		int a;
+	};
+
+	struct mouse {
+		int id;
+		double x;
+		double y;
+	};
+
+	struct keyboard {
+		int id;
+		char press;
+	};
+	//only in this class, not PacketGenerator, used as pattern to put incoming
+	//bytes inside
+	struct chat {
+		int id;
+		const char* message;
+	};
+	
+	void acknowledgement( ENetPacket* packet );
+	void mousem( ENetPacket* packet );
+	void keystrike( ENetPacket* packet );
+	void chatMessage( ENetPacket* packet );
+	void gstate( ENetPacket* packet );
+	
+	//print functions
+	void printAck( ack* data );
+	void printMouse( mouse* data );
+	void printKey( keyboard* data );
+	void printChat( chat* data );
+	void printGamestate( GameState* data );
+};
+}
+
+#endif /*PACKETMANAGER_H_*/
Index: code/branches/FICN/src/network/Server.cc
===================================================================
--- code/branches/FICN/src/network/Server.cc	(revision 337)
+++ code/branches/FICN/src/network/Server.cc	(revision 337)
@@ -0,0 +1,53 @@
+//
+// C++ Implementation: Server
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+
+#include "Server.h"
+
+namespace network{
+
+  /**
+   * Constructor for default values (bindaddress is set to ENET_HOST_ANY
+   *
+   */
+  Server::Server(){
+
+
+  }
+
+  /**
+   * Constructor
+   * @param port Port to listen on
+   * @param bindAddress Address to listen on
+   */
+  Server::Server(int port, std::string bindAddress) : connection(port, bindAddress){
+
+
+  }
+
+  /**
+   * Constructor
+   * @param port Port to listen on
+   * @param bindAddress Address to listen on
+   */
+  Server::Server(int port, const char *bindAddress) : connection(port, bindAddress){
+
+
+
+
+  }
+
+
+
+
+
+}
Index: code/branches/FICN/src/network/Server.h
===================================================================
--- code/branches/FICN/src/network/Server.h	(revision 337)
+++ code/branches/FICN/src/network/Server.h	(revision 337)
@@ -0,0 +1,51 @@
+//
+// C++ Interface: Server
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef NETWORK_SERVER_H
+#define NETWORK_SERVER_H
+
+#include <string>
+
+#include "ConnectionManager.h"
+#include "PacketManager.h"
+
+
+namespace network{
+
+  /**
+   * This class is the root class of the network module for a server.
+   * It implements all functions necessary for a Server
+   */
+  class Server : PacketDecoder{
+    public:
+    Server();
+    Server(int port, std::string bindAddress);
+    Server(int port, const char *bindAddress);
+
+    private:
+    ConnectionManager connection;
+
+
+
+
+
+
+
+  };
+
+
+
+
+
+}
+
+#endif
Index: code/branches/FICN/src/network/Synchronisable.cc
===================================================================
--- code/branches/FICN/src/network/Synchronisable.cc	(revision 337)
+++ code/branches/FICN/src/network/Synchronisable.cc	(revision 337)
@@ -0,0 +1,141 @@
+//
+// C++ Implementation: synchronisable
+//
+// Description:
+//
+//
+// Author:  Dumeni, Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+
+#include "Synchronisable.h"
+
+namespace network {
+
+/**
+ * Constructor:
+ * calls registarAllVariables, that has to be implemented by the inheriting classID
+ */
+Synchronisable::Synchronisable()
+{
+  datasize=0;
+  registerAllVariables();
+}
+
+
+Synchronisable::~Synchronisable()
+{
+
+}
+
+/**
+ * This function is used to register a variable to be synchronized
+ * also counts the total datasize needed to save the variables
+ * @param var pointer to the variable
+ * @param size size of the datatype the variable consists of
+ */
+void Synchronisable::registerVar(const void *var, int size){
+  // create temporary synch.Var struct
+  synchronisableVariable temp={size, var};
+  // increase datasize
+  datasize+=sizeof(int)+size;
+  // push temp to syncList (at the bottom)
+  syncList.push_back(temp);
+}
+
+/**
+ * note: only use this function for debug use, because it's inefficient (in order to produce a gamestate, you have to copy the whole data again to another memory location after this process)
+ * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct
+ * structure of the bitstream:
+ * (var1_size,var1,var2_size,var2,...)
+ * varx_size: size = sizeof(int)
+ * varx: size = varx_size
+ * @return data containing all variables and their sizes
+ */
+syncData Synchronisable::getData(){
+  std::list<synchronisableVariable>::iterator i;
+  int totalsize=0;
+  //figure out size of data to be allocated
+  for(i=syncList.begin(); i!=syncList.end(); i++){
+    // increase size (size of variable and size of size of variable ;)
+    totalsize+=sizeof(int)+i->size;
+  }
+  syncData retVal;
+  retVal.objectID=this->objectID;
+  retVal.classID=this->classID;
+  retVal.length=totalsize;
+  // allocate memory
+  retVal.data = (unsigned char *)malloc(totalsize);
+  // copy to location
+  //CHANGED: REMOVED DECLARATION int n=0 FROM LOOP
+  int n=0;
+  for(i=syncList.begin(); n<totalsize && i!=syncList.end(); i++){
+	//CHANGED: i->size TO (const void*)(&(i->size)) memcpy WANTS A CONST VOID* SO CONVERT INT TO CONST VOID*
+    std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int));
+    n+=sizeof(int);
+    //CHANGED: i->var TO (const void*)(&(i->var)) SINCE var IS A POINTER, NO & BEFORE i
+    std::memcpy(retVal.data+n, (const void*)(i->var), i->size);
+    n+=i->size;
+  }
+  return retVal;
+}
+/**
+ * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct
+ * Difference to the above function:
+ * takes a pointer to already allocated memory (must have at least getSize bytes length)
+ * structure of the bitstream:
+ * (var1_size,var1,var2_size,var2,...)
+ * varx_size: size = sizeof(int)
+ * varx: size = varx_size
+ * @return data containing all variables and their sizes
+ */
+syncData Synchronisable::getData(unsigned char *mem){
+  std::list<synchronisableVariable>::iterator i;
+  syncData retVal;
+  retVal.objectID=this->objectID;
+  retVal.classID=this->classID;
+  retVal.length=datasize;
+  retVal.data=mem;
+  // copy to location
+  //CHANGED: REMOVED DECLARATION int n=0 FROM LOOP
+  int n=0;
+  for(i=syncList.begin(); n<datasize && i!=syncList.end(); i++){
+        //CHANGED: i->size TO (const void*)(&(i->size)) memcpy WANTS A CONST VOID* SO CONVERT INT TO CONST VOID*
+    std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int));
+    n+=sizeof(int);
+    //CHANGED: i->var TO (const void*)(&(i->var)) SINCE var IS A POINTER, NO & BEFORE i
+    std::memcpy(retVal.data+n, (const void*)(i->var), i->size);
+    n+=i->size;
+  }
+  return retVal;
+}
+
+/**
+ * This function takes a syncData struct and takes it to update the variables
+ * @param vars data of the variables
+ * @return true/false
+ */
+bool Synchronisable::updateData(syncData vars){
+  unsigned char *data=vars.data;
+  std::list<synchronisableVariable>::iterator i;
+  for(i=syncList.begin(); i!=syncList.end(); i++){
+    if((int)*data==i->size){
+      data+=sizeof(int);
+      //CHANGED: THIS FROM i->var TO (void*)i->var SINCE var IS A CONST VOID* AND memcpy NEEDS A VOID* AS FIRST ARGUMENT
+      memcpy((void*)i->var, data, i->size);
+      data+=i->size;
+    } else
+      return false; //there was some problem with registerVar
+  }
+}
+
+/**
+ * This function returns the total amount of bytes needed by getData to save the whole content of the variables
+ * @return amount of bytes
+ */
+int Synchronisable::getSize(){
+  return datasize;
+}
+
+}
Index: code/branches/FICN/src/network/Synchronisable.h
===================================================================
--- code/branches/FICN/src/network/Synchronisable.h	(revision 337)
+++ code/branches/FICN/src/network/Synchronisable.h	(revision 337)
@@ -0,0 +1,65 @@
+//
+// C++ Interface: synchronisable
+//
+// Description: 
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef NETWORK_SYNCHRONISABLE_H
+#define NETWORK_SYNCHRONISABLE_H
+
+#include <list>
+#include <iostream>
+
+#include "orxonox/core/IdentifierIncludes.h"
+
+namespace network {
+
+  
+struct syncData{
+  int length;
+  int objectID;
+  int classID;
+  unsigned char *data;
+};
+
+typedef struct synchronisableVariable{
+  int size;
+  const void *var;
+}SYNCVAR;
+
+  
+/**
+ * This class is the base class of all the Objects in the universe that need to be synchronised over the network
+ * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list. Additionally it also has to provide a Constructor, that takes exactly the variables in this linked list.
+ * @author Oliver Scheuss
+*/
+class Synchronisable{
+public:
+  Synchronisable();
+
+  virtual ~Synchronisable();
+  int objectID;
+  int classID;
+    
+  void registerVar(const void *var, int size);
+  syncData getData();
+  syncData getData(unsigned char *mem);
+  int getSize();
+  bool updateData(syncData vars);
+  virtual void registerAllVariables();
+
+private:
+/*  bool removeObject(Iterator<Synchronisable> it);*/
+  
+  std::list<SYNCVAR> syncList;
+  int datasize;
+};
+
+}
+
+#endif
Index: code/branches/FICN/src/network/dummyclient.cc
===================================================================
--- code/branches/FICN/src/network/dummyclient.cc	(revision 337)
+++ code/branches/FICN/src/network/dummyclient.cc	(revision 337)
@@ -0,0 +1,93 @@
+//
+// Dummy client to test ConnectionManager and PacketBuffer classes
+//
+// Author: Oliver Scheuss
+
+#include <iostream>
+#include <string>
+#include <enet/enet.h>
+#include "PacketManager.h"
+
+using namespace std;
+
+int main(){
+  ENetHost * client;
+  ENetAddress address;
+  ENetEvent event;
+  ENetPeer *peer;
+  network::PacketGenerator pck;
+
+  enet_initialize();
+  atexit(enet_deinitialize);
+
+  cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << endl;
+  string str;
+  getline(cin, str);
+  cout << "You entered: " << str << endl;
+  if(str.compare("")==0)
+    str="127.0.0.1";
+
+  enet_address_set_host(&address, str.c_str());
+  address.port = 55556;
+
+        // create client object
+  client = enet_host_create(NULL, 2, 0, 0);
+
+  if(client==NULL){
+    fprintf(stderr, "An error occured");
+    exit(EXIT_FAILURE);
+  }
+        // connect peer
+  peer = enet_host_connect(client, &address, 2);
+  if(peer==NULL){
+    fprintf(stderr, "Peer establishing error");
+    exit(EXIT_FAILURE);
+  }
+        // wait 5 seconds for the connection attempt to succeed
+  if(enet_host_service(client, &event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT){
+    cout << "Connection to " << str << " succeeded." << endl;
+    //puts("Connection to localhost:5555 succeeded.");
+  }else{
+    enet_peer_reset(peer);
+    cout << "Connection to " << str << " failed." << endl;
+    //puts("Connection to localhost:5555 failed.");
+    exit(EXIT_FAILURE);
+  }
+
+  for(int i=0; i<10; i++){
+        // weihnachtsmann bringt packete
+    //ENetPacket *packet = enet_packet_create ("packet1234", strlen("packet1234") + 1, ENET_PACKET_FLAG_RELIABLE);
+        // extend the packet and append the string foo to it
+        // send packet to peer on channel id 0
+    enet_peer_send(peer, 1, pck.chatMessage("test2"));
+        // keep the timeout very small for low delay
+    if(enet_host_service(client, &event, 1)==0){
+      cout << "successfully sent: " << event.type << endl;
+    }else{
+      cout << "failed sending" << endl;
+    }
+    usleep(1000000);
+  }
+
+        // now disconnect
+//   enet_peer_disconnect (peer);
+  enet_peer_disconnect (peer, 0);
+        // 3 seconds timeout
+  while(enet_host_service(client, &event, 3000) > 0){
+    switch (event.type)
+    {
+      case ENET_EVENT_TYPE_RECEIVE:
+        enet_packet_destroy(event.packet);
+        break;
+      case ENET_EVENT_TYPE_DISCONNECT:
+        puts("Disconnection succeeded.");
+        return 0;
+    }
+  }
+        // if disconnect failed
+  enet_peer_reset(peer);
+
+
+
+  return 0;
+}
Index: code/branches/FICN/src/network/dummyclient2.cc
===================================================================
--- code/branches/FICN/src/network/dummyclient2.cc	(revision 337)
+++ code/branches/FICN/src/network/dummyclient2.cc	(revision 337)
@@ -0,0 +1,61 @@
+//
+// Dummy client to test ConnectionManager, PacketBuffer, ClientConnection and other classes
+//
+// Author: Oliver Scheuss
+
+#include <iostream>
+#include <string>
+#include <enet/enet.h>
+#include "PacketManager.h"
+#include "ClientConnection.h"
+
+using namespace network;
+
+int main(){
+  network::PacketGenerator pck;
+
+  std::cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl;
+  std::string str;
+  std::getline(std::cin, str);
+  std::cout << "You entered: " << str << std::endl;
+  if(str.compare("")==0)
+    str="127.0.0.1";
+
+  ClientConnection client = ClientConnection(55556, str);
+
+  client.createConnection();
+
+  if(client.waitEstablished(10000))
+    std::cout << "Connection established" << std::endl;
+  else
+    std::cout << "Connection failed" << std::endl;
+
+  ENetPacket *packet;
+  ENetEvent event;
+
+
+
+  for(int i=0; i<10; i++){
+        // weihnachtsmann bringt packete
+        // extend the packet and append the string foo to it
+        // send packet to peer on channel id 0
+    client.addPacket(pck.chatMessage("test"));
+        // keep the timeout very small for low delay
+    if(client.sendPackets(&event)){
+      std::cout << "successfully sent: " << event.type << std::endl;
+    }else{
+      std::cout << "failed sending" << std::endl;
+    }
+    //usleep(100000);
+  }
+
+        // now disconnect
+  if(client.closeConnection())
+    std::cout << "Connection successfully closed" << std::endl;
+  else
+    std::cout << "Connection closing failed" << std::endl;
+
+        // 3 seconds timeout
+  return 0;
+}
+
Index: code/branches/FICN/src/network/dummyserver.cc
===================================================================
--- code/branches/FICN/src/network/dummyserver.cc	(revision 337)
+++ code/branches/FICN/src/network/dummyserver.cc	(revision 337)
@@ -0,0 +1,42 @@
+//
+// Dummy server to test ConnectionManager and PacketBuffer classes
+//
+// Author: Oliver Scheuss
+
+
+#include <iostream>
+#include "enet/enet.h"
+#include "ConnectionManager.h"
+#include "PacketManager.h"
+
+using namespace network;
+
+int main(){
+  ConnectionManager server = ConnectionManager();
+  bool quit=false;
+  ENetPacket *packet;
+  ENetEvent event;
+  server.createListener();
+
+  PacketDecoder dec;
+
+  while(!quit){
+    if(server.queueEmpty())
+      usleep(100);
+    else{
+      ENetAddress addr;
+      packet=server.getPacket(addr);
+      if(packet==NULL){
+        // there was some error
+        //std::cout << "null pointer" << std::endl;
+        quit=true;
+      }
+      else{
+        //std::cout << "We received: " << packet->data << std::endl;
+        dec.elaborate(packet, 1);
+      }
+    }
+  }
+  server.quitListener();
+  return 0;
+}
