Index: code/trunk/src/network/CMakeLists.txt
===================================================================
--- code/trunk/src/network/CMakeLists.txt	(revision 790)
+++ code/trunk/src/network/CMakeLists.txt	(revision 790)
@@ -0,0 +1,98 @@
+SET( NETWORK_SRC_FILES
+  Client.cc
+  ClientConnection.cc
+  ClientInformation.cc
+  ConnectionManager.cc
+  GameStateManager.cc
+  GameStateClient.cc
+  PacketBuffer.cc
+  PacketDecoder.cc
+  PacketGenerator.cc
+  Server.cc
+  Synchronisable.cc
+  dummyserver3.cc
+)
+
+IF(WIN32)
+  ADD_LIBRARY( network ${NETWORK_SRC_FILES})
+ELSE(WIN32)
+  ADD_LIBRARY( network SHARED ${NETWORK_SRC_FILES})
+ENDIF(WIN32)
+
+SET_TARGET_PROPERTIES( network PROPERTIES LINK_FLAGS "--no-undefined" )
+
+TARGET_LINK_LIBRARIES( network
+  ${ZLIB_LIBRARY}
+  ${ENet_LIBRARY}
+  ${Boost_thread_LIBRARIES}
+  core
+)
+
+# build those parts only on request.
+IF(NETWORK_TESTING_ENABLED)
+  SET( CHATCLIENT_SRC_FILES
+    ClientConnection.cc
+    Client.cc
+    PacketBuffer.cc
+    PacketDecoder.cc
+    PacketGenerator.cc
+    dummyclient3.cc
+  )
+
+  SET( CHATSERVER_SRC_FILES
+    ConnectionManager.cc
+    GameStateManager.cc
+    PacketBuffer.cc
+    PacketDecoder.cc
+    PacketGenerator.cc
+    dummyserver3.cc
+  )
+
+  # chatserver for testing purposes
+  ADD_EXECUTABLE(chatserver ${CHATSERVER_SRC_FILES})
+  TARGET_LINK_LIBRARIES( chatserver
+    ${OGRE_LIBRARIES}
+    network
+    core
+    #objects
+    ${ENet_LIBRARY}
+    ${ZLIB_LIBRARY}
+    ${WINDOWS_ENET_DEPENDENCIES}
+  )
+
+  # chatclient for testing purpose
+  ADD_EXECUTABLE(chatclient ${CHATCLIENT_SRC_FILES})
+  TARGET_LINK_LIBRARIES( chatclient
+    ${OGRE_LIBRARIES}
+    network
+    core
+    #objects
+    ${ENet_LIBRARY}
+    ${ZLIB_LIBRARY}
+    ${WINDOWS_ENET_DEPENDENCIES}
+  )
+
+  # client for testing purpose
+  ADD_EXECUTABLE(client dummyclient2.cc)
+  TARGET_LINK_LIBRARIES( client
+    ${OGRE_LIBRARIES}
+    network
+    core
+    #objects
+    ${ENet_LIBRARY}
+    ${ZLIB_LIBRARY}
+    ${WINDOWS_ENET_DEPENDENCIES}
+  )
+
+  # server for testing purpose
+  ADD_EXECUTABLE(server dummyserver.cc)
+  TARGET_LINK_LIBRARIES( server
+    ${OGRE_LIBRARIES}
+    network
+    core
+    #objects
+    ${ENet_LIBRARY}
+    ${ZLIB_LIBRARY}
+    ${WINDOWS_ENET_DEPENDENCIES}
+  )
+ENDIF(NETWORK_TESTING_ENABLED)
Index: code/trunk/src/network/Client.cc
===================================================================
--- code/trunk/src/network/Client.cc	(revision 790)
+++ code/trunk/src/network/Client.cc	(revision 790)
@@ -0,0 +1,212 @@
+/*
+*   ORXONOX - the hottest 3D action shooter ever to exist
+*
+*
+*   License notice:
+*
+*   This program is free software; you can redistribute it and/or
+*   modify it under the terms of the GNU General Public License
+*   as published by the Free Software Foundation; either version 2
+*   of the License, or (at your option) any later version.
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with this program; if not, write to the Free Software
+*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+*   Author:
+*      Oliver Scheuss, (C) 2007
+*   Co-authors:
+*      ...
+*
+*/
+
+//
+// C++ Implementation: Client
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "core/CoreIncludes.h"
+#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
+    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){
+    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){
+    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){
+    // generate packet and add it to the queue
+    if(!isConnected)
+      return false;
+    if(!client_connection.addPacket(pck_gen.mousem(x, y)))
+      return false;
+    // send packets
+    return client_connection.sendPackets();
+  }
+
+  /**
+  * submits a Keystrike to the server
+  * @param key_code code to submit
+  * @return true/false
+  */
+  bool Client::sendKeyboard(char key_code){
+    // generate packet and add it to queue
+    if(!isConnected)
+      return false;
+    if(!client_connection.addPacket(pck_gen.keystrike(key_code)))
+      return false;
+    // send packets
+    return client_connection.sendPackets();
+  }
+
+  /**
+  * submits a chat message to the server
+  * @param message message to send
+  * @return true/false
+  */
+  bool Client::sendChat( std::string message ){
+    // generate packet and add it to queue
+    if(!isConnected)
+      return false;
+    if(client_connection.addPacket(pck_gen.chatMessage( message.c_str() )))
+      return client_connection.sendPackets();
+    // send packets
+    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){
+    // generate packet and add it to queue
+    if(client_connection.addPacket(pck_gen.keystrike(key_code)))
+      return true;
+    else
+      return false;
+  }
+
+  /**
+  * Sends out all the packets queued by addXXX
+  */
+  bool Client::sendPackets(){
+    if(!isConnected)
+      return false;
+    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::tick(float time){
+    ENetPacket *packet;
+    // stop if the packet queue is empty
+    while(!(client_connection.queueEmpty())){
+      packet = client_connection.getPacket();
+      //std::cout << "tick packet size " << packet->dataLength << std::endl;
+      elaborate(packet, 0); // ================= i guess we got to change this .... (client_ID is always same = server)
+    }
+    return;
+  }
+
+  void Client::processGamestate( GameStateCompressed *data){
+    gamestate.pushGameState(data);
+    std::cout << "received gamestate id: " << data->id << std::endl;
+    client_connection.addPacket(pck_gen.acknowledgement(data->id));
+    client_connection.sendPackets();
+    return;
+  }
+
+  void Client::processClassid(classid *clid){
+    orxonox::Identifier *id;
+    id=ID(std::string(clid->message));
+    if(id!=NULL)
+      id->setNetworkID(clid->clid);
+    return;
+  }
+
+  void Client::processChat( chat *data){
+    std::cout << "Server: " << data->message << std::endl;
+  }
+
+}
Index: code/trunk/src/network/Client.h
===================================================================
--- code/trunk/src/network/Client.h	(revision 790)
+++ code/trunk/src/network/Client.h	(revision 790)
@@ -0,0 +1,69 @@
+//
+// C++ Interface: Client
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef _Client_H__
+#define _Client_H__
+
+#include <string>
+
+#include "NetworkPrereqs.h"
+#include "ClientConnection.h"
+#include "PacketManager.h"
+#include "GameStateClient.h"
+//#include "NetworkFrameListener.h"
+
+
+namespace network
+{
+  /**
+  network::Client *client;
+  * The network/Client class
+  * This class implements all necessary function for the network communication
+  * It is the root class of the network module
+  *
+  */
+  class _NetworkExport 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 sendChat( std::string message );
+
+    bool addMouse(double x, double y);
+    bool addKeyboard(char key_code);
+
+    bool sendPackets();
+
+    void tick(float time);
+
+  private:
+    ClientConnection client_connection;
+    PacketGenerator pck_gen;
+    GameStateClient gamestate;
+    bool isConnected;
+
+    // implement data processing functions of PacketDecoder
+    void processGamestate( GameStateCompressed *data);
+    void processClassid(classid *clid);
+    void processChat( chat *data);
+  };
+
+
+}
+
+#endif /* _Client_H__ */
Index: code/trunk/src/network/ClientConnection.cc
===================================================================
--- code/trunk/src/network/ClientConnection.cc	(revision 790)
+++ code/trunk/src/network/ClientConnection.cc	(revision 790)
@@ -0,0 +1,223 @@
+/*
+*   ORXONOX - the hottest 3D action shooter ever to exist
+*
+*
+*   License notice:
+*
+*   This program is free software; you can redistribute it and/or
+*   modify it under the terms of the GNU General Public License
+*   as published by the Free Software Foundation; either version 2
+*   of the License, or (at your option) any later version.
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with this program; if not, write to the Free Software
+*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+*   Author:
+*      Oliver Scheuss, (C) 2007
+*   Co-authors:
+*      ...
+*
+*/
+
+//
+// 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 <iostream>
+// boost.thread library for multithreading support
+#include <boost/thread/thread.hpp>
+#include <boost/bind.hpp>
+
+#include "util/Sleep.h"
+#include "ClientConnection.h"
+
+namespace network
+{
+  static 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()) {
+      //std::cout << "###BUFFER IS NOT EMPTY###" << std::endl;
+      return buffer.pop(address);
+    }
+    else{
+      return NULL;
+    }
+  }
+
+  ENetPacket *ClientConnection::getPacket() {
+    ENetAddress address;
+    return getPacket(address);
+  }
+
+  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;
+    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;
+      return;
+    }
+    //main loop
+    while(!quit){
+      //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 ========================
+      }
+      switch(event.type){
+        // log handling ================
+      case ENET_EVENT_TYPE_CONNECT:
+      case ENET_EVENT_TYPE_RECEIVE:
+        //std::cout << "got packet" << std::endl;
+        processData(&event);
+        break;
+      case ENET_EVENT_TYPE_DISCONNECT:
+        quit=true;
+        // server closed the connection
+        return;
+        break;
+      case ENET_EVENT_TYPE_NONE:
+        continue;
+      }
+    }
+    // now disconnect
+
+    if(!disconnectConnection())
+      // if disconnecting failed destroy conn.
+      enet_peer_reset(server);
+    return;
+  }
+
+  bool ClientConnection::disconnectConnection() {
+    ENetEvent event;
+    enet_peer_disconnect(server, 0);
+    while(enet_host_service(client, &event, NETWORK_CLIENT_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:
+        return true;
+      }
+    }
+    enet_peer_reset(server);
+    return false;
+  }
+
+  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_CLIENT_TIMEOUT)>0 && event.type == ENET_EVENT_TYPE_CONNECT){
+      established=true;
+      return true;
+    }
+    else
+      return false;
+  }
+
+  bool ClientConnection::processData(ENetEvent *event) {
+    //std::cout << "got packet, pushing to queue" << std::endl;
+    // just add packet to the buffer
+    // this can be extended with some preprocessing
+    return buffer.push(event);
+  }
+
+}
Index: code/trunk/src/network/ClientConnection.h
===================================================================
--- code/trunk/src/network/ClientConnection.h	(revision 790)
+++ code/trunk/src/network/ClientConnection.h	(revision 790)
@@ -0,0 +1,76 @@
+//
+// 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 <string>
+#include <enet/enet.h>
+
+#include "NetworkPrereqs.h"
+#include "PacketBuffer.h"
+
+namespace network
+{
+
+#define NETWORK_PORT 55556
+#define NETWORK_CLIENT_MAX_CONNECTIONS 5
+#define NETWORK_CLIENT_TIMEOUT 10
+#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
+    ENetPacket *getPacket(); // 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 /* _ClientConnection_H__ */
Index: code/trunk/src/network/ClientInformation.cc
===================================================================
--- code/trunk/src/network/ClientInformation.cc	(revision 790)
+++ code/trunk/src/network/ClientInformation.cc	(revision 790)
@@ -0,0 +1,233 @@
+/*
+*   ORXONOX - the hottest 3D action shooter ever to exist
+*
+*
+*   License notice:
+*
+*   This program is free software; you can redistribute it and/or
+*   modify it under the terms of the GNU General Public License
+*   as published by the Free Software Foundation; either version 2
+*   of the License, or (at your option) any later version.
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with this program; if not, write to the Free Software
+*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+*   Author:
+*      ...
+*   Co-authors:
+*      ...
+*
+*/
+
+//
+// C++ Implementation: ClientInformation
+//
+// Description:
+//
+//
+// Author:  <>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include <iostream> //debug
+
+#include "ClientInformation.h"
+
+namespace network
+{
+  ClientInformation::ClientInformation() {
+    gamestateID_=GAMESTATEID_INITIAL;
+    preve=0;
+    nexte=0;
+    this->head=false;
+    synched_=false;
+  }
+
+  ClientInformation::ClientInformation(bool head) {
+    gamestateID_=GAMESTATEID_INITIAL;
+    preve=0;
+    nexte=0;
+    this->head=head;
+    synched_=false;
+  }
+
+  // ClientInformation::ClientInformation(ClientInformation *prev) {
+  //   if(prev->next()!=0){
+  //     this->nexte=prev->next();
+  //     this->nexte->setPrev(this);
+  //   }
+  //   else
+  //     this->nexte = 0;
+  //   prev->setNext(this);
+  //   this->preve = pref;
+  // }
+  //
+  // ClientInformation::ClientInformation(ClientInformation *prev, ClientInformation *next){
+  //   this->nexte = next;
+  //   this->preve = prev;
+  //   this->preve->setNext(this);
+  //   this->nexte->setPrev(this);
+  // }
+
+  ClientInformation::~ClientInformation() {
+    if(preve!=0)
+      preve->setNext(this->nexte);
+    if(nexte!=0)
+      nexte->setPrev(this->preve);
+  }
+
+  ClientInformation *ClientInformation::next() {
+    if(this!=0)
+      return this->nexte;
+    else
+      return 0;
+  }
+  ClientInformation *ClientInformation::prev() {
+    if(this!=0)
+      return this->preve;
+    else
+      return 0;
+  }
+
+  bool ClientInformation::setPrev(ClientInformation *prev) {
+    if(!head)
+      this->preve = prev;
+    else
+      return false;
+    return true;
+  }
+
+  bool ClientInformation::setNext(ClientInformation *next) {
+    this->nexte = next;
+    return true;
+  }
+
+  ClientInformation *ClientInformation::insertAfter(ClientInformation *ins) {
+    this->nexte->setPrev(ins);
+    ins->setNext(this->nexte);
+    ins->setPrev(this);
+    this->nexte = ins;
+    return ins;
+  }
+
+  ClientInformation *ClientInformation::insertBefore(ClientInformation *ins){
+    this->prev()->setNext(ins);
+    ins->setPrev(this->preve);
+    this->preve=ins;
+    ins->setNext(this);
+    return ins;
+  }
+
+  void ClientInformation::setID(int clientID){
+    clientID_ = clientID;
+  }
+
+  void ClientInformation::setPeer(ENetPeer *peer){
+    peer_ = peer;
+  }
+
+  void ClientInformation::setGamestateID(int id){
+    gamestateID_=id;
+  }
+
+  int ClientInformation::getID() {
+    return clientID_;
+  }
+
+  ENetPeer *ClientInformation::getPeer() {
+    return peer_;
+  }
+
+  int ClientInformation::getGamestateID() {
+    return gamestateID_;
+  }
+
+  ClientInformation *ClientInformation::insertBack(ClientInformation *ins) {
+    ClientInformation *temp = this;
+    while(temp->next()!=0){
+      temp = temp->next();
+    }
+    temp->setNext(ins);
+    ins->setPrev(temp);
+    return ins;
+  }
+
+  bool ClientInformation::removeClient(int clientID) {
+    ClientInformation *temp = this;
+    while(temp!=0 && temp->getID()!=clientID)
+      temp = temp->next();
+    if(temp==0)
+      return false;
+    delete temp;
+    return true;
+  }
+
+  bool ClientInformation::removeClient(ENetPeer *peer) {
+    ClientInformation *temp = this;
+    while(temp!=0){
+      if(!temp->head)
+        if(temp->getPeer()->address.host==peer->address.host && temp->getPeer()->address.port==peer->address.port)
+          break;
+      temp = temp->next();
+    }
+    if(temp==0)
+      return false;
+    delete temp;
+    return true;
+  }
+
+  /**
+  * This function goes forward through the list and looks for an element with clientID
+  * This function should only be applied to the head of the list
+  * @param clientID id to look for
+  * @return pointer to the element in the list or 0 if the search was unsuccessfull
+  */
+  ClientInformation *ClientInformation::findClient(int clientID, bool look_backwards) {
+    ClientInformation *temp = this;
+    if (temp->head)
+      temp=temp->next();
+    while(temp!=0 && temp->getID()!=clientID){
+      temp = temp->next();
+    }
+    // returns 0 if nothing has been found
+    return temp;
+  }
+
+  /**
+  * This function goes forward through the list and looks for an element with clientID
+  * This function should only be applied to the head of the list
+  * @param peer peer to look for
+  * @return pointer to the element in the list
+  */
+  ClientInformation *ClientInformation::findClient(ENetAddress *address, bool look_backwards) {
+    ClientInformation *temp = this;
+    while(temp!=0){
+      if(temp->head){
+        temp = temp->next();
+        continue;
+      }
+      if(temp->getPeer()->address.host==address->host && temp->getPeer()->address.port == address->port)
+        break;
+      temp = temp->next();
+    }
+    // returns 0 if nothing has been found
+    return temp;
+  }
+
+  void ClientInformation::setSynched(bool s) {
+    synched_=s;
+  }
+
+  bool ClientInformation::getSynched() {
+    return synched_;
+  }
+
+}
Index: code/trunk/src/network/ClientInformation.h
===================================================================
--- code/trunk/src/network/ClientInformation.h	(revision 790)
+++ code/trunk/src/network/ClientInformation.h	(revision 790)
@@ -0,0 +1,69 @@
+//
+// C++ Interface: ClientInformation
+//
+// Description: 
+//
+//
+// Author:  <>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef _ClientInformation_H__
+#define _ClientInformation_H__
+
+#include <enet/enet.h>
+
+#include "NetworkPrereqs.h"
+
+#define GAMESTATEID_INITIAL -1
+
+namespace network
+{
+  /**
+  * This class implements a list for client informations
+  * @author Oliver Scheuss
+  */
+  class ClientInformation{
+  public:
+    ClientInformation();
+    ClientInformation(bool head);
+    //   ClientInformation(ClientInformation *prev, ClientInformation *next);
+    //   ClientInformation(ClientInformation *prev);
+    ~ClientInformation();
+    ClientInformation *next();
+    ClientInformation *prev();
+    bool setNext(ClientInformation *next);
+    bool setPrev(ClientInformation *prev);
+    ClientInformation *insertAfter(ClientInformation *ins);
+    ClientInformation *insertBefore(ClientInformation *ins);
+    ClientInformation *insertBack(ClientInformation *ins);
+    void setID(int clientID);
+    void setPeer(ENetPeer *peer);
+    void setGamestateID(int id);
+    int getID();
+    ENetPeer *getPeer();
+    int getGamestateID();
+    bool removeClient(int clientID);
+    bool removeClient(ENetPeer *peer);
+    ClientInformation *findClient(int clientID, bool look_backwards=false);
+    ClientInformation *findClient(ENetAddress *address, bool look_backwards=false);
+
+    void setSynched(bool s);
+    bool getSynched();
+
+    bool head;
+
+  private:
+    ClientInformation *preve;
+    ClientInformation *nexte;
+    //actual information:
+    ENetPeer *peer_;
+    int clientID_;
+    int gamestateID_;
+    bool synched_;
+  };
+
+}
+
+#endif /* _ClientInformation_H__ */
Index: code/trunk/src/network/ConnectionManager.cc
===================================================================
--- code/trunk/src/network/ConnectionManager.cc	(revision 790)
+++ code/trunk/src/network/ConnectionManager.cc	(revision 790)
@@ -0,0 +1,283 @@
+/*
+*   ORXONOX - the hottest 3D action shooter ever to exist
+*
+*
+*   License notice:
+*
+*   This program is free software; you can redistribute it and/or
+*   modify it under the terms of the GNU General Public License
+*   as published by the Free Software Foundation; either version 2
+*   of the License, or (at your option) any later version.
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with this program; if not, write to the Free Software
+*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+*   Author:
+*      Oliver Scheuss, (C) 2007
+*   Co-authors:
+*      ...
+*
+*/
+
+//
+// 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 <iostream>
+// boost.thread library for multithreading support
+#include <boost/thread/thread.hpp>
+#include <boost/bind.hpp>
+
+#include "core/CoreIncludes.h"
+#include "ClientInformation.h"
+#include "ConnectionManager.h"
+
+namespace std
+{
+  bool operator< (ENetAddress a, ENetAddress b) {
+    if(a.host <= b.host)
+      return true;
+    else
+      return false;
+  }
+}
+
+namespace network
+{
+  boost::thread_group network_threads;
+
+  ConnectionManager::ConnectionManager(ClientInformation *head) {
+    quit=false;
+    bindAddress.host = ENET_HOST_ANY;
+    bindAddress.port = NETWORK_PORT;
+    head_ = head;
+  }
+
+  ConnectionManager::ConnectionManager(int port, std::string address, ClientInformation *head) {
+    quit=false;
+    enet_address_set_host (& bindAddress, address.c_str());
+    bindAddress.port = NETWORK_PORT;
+    head_ = head;
+  }
+
+  ConnectionManager::ConnectionManager(int port, const char *address, ClientInformation *head) {
+    quit=false;
+    enet_address_set_host (& bindAddress, address);
+    bindAddress.port = NETWORK_PORT;
+    head_ = head;
+  }
+
+  ENetPacket *ConnectionManager::getPacket(ENetAddress &address) {
+    if(!buffer.isEmpty())
+      return buffer.pop(address);
+    else
+      return NULL;
+  }
+
+  ENetPacket *ConnectionManager::getPacket(int &clientID) {
+    ENetAddress address;
+    ENetPacket *packet=getPacket(address);
+    ClientInformation *temp =head_->findClient(&address);
+    clientID=temp->getID();
+    return packet;
+  }
+
+  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(enet_peer_send(peer, head_->findClient(&(peer->address))->getID() , packet)!=0)
+      return false;
+    return true;
+  }
+
+  bool ConnectionManager::addPacket(ENetPacket *packet, int clientID) {
+    if(enet_peer_send(head_->findClient(clientID)->getPeer(), clientID, packet)!=0)
+      return false;
+    return true;
+  }
+
+  bool ConnectionManager::addPacketAll(ENetPacket *packet) {
+    for(ClientInformation *i=head_->next(); i!=0; i=i->next()){
+      if(enet_peer_send(i->getPeer(), i->getID(), 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;
+  }
+
+  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;
+      return;
+    }
+
+    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:
+          //std::cout << "received data" << std::endl;
+          processData(&event);
+          break;
+        case ENET_EVENT_TYPE_DISCONNECT:
+          // add some error/log handling here
+          clientDisconnect(event.peer);
+          break;
+        case ENET_EVENT_TYPE_NONE:
+          break;
+      }
+    }
+    disconnectClients();
+    // if we're finishied, destroy server
+    enet_host_destroy(server);
+  }
+
+  void ConnectionManager::disconnectClients() {
+    ENetEvent event;
+    ClientInformation *temp = head_->next();
+    while(temp!=0){
+      enet_peer_disconnect(temp->getPeer(), 0);
+      temp = temp->next();
+    }
+    temp = temp->next();
+    while( temp!=0 && 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:
+        std::cout << "disconnecting client" << std::endl;
+        delete head_->findClient(&(event.peer->address));
+        temp = temp->next();
+        break;
+      }
+    }
+    return;
+  }
+
+  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) {
+  //  return clientDisconnect(*peer);
+  //}
+
+  bool ConnectionManager::clientDisconnect(ENetPeer *peer) {
+    return head_->removeClient(peer);
+  }
+
+  bool ConnectionManager::addClient(ENetEvent *event) {
+    ClientInformation *temp = head_->insertBack(new ClientInformation);
+    if(temp->prev()->head)
+      temp->setID(1);
+    else
+      temp->setID(temp->prev()->getID()+1);
+    temp->setPeer(event->peer);
+    std::cout << "added client id: " << temp->getID() << std::endl;
+    syncClassid(temp->getID());
+    temp->setSynched(true);
+    return true;
+  }
+
+  int ConnectionManager::getClientID(ENetPeer peer) {
+    return getClientID(peer.address);
+  }
+
+  int ConnectionManager::getClientID(ENetAddress address) {
+    return head_->findClient(&address)->getID();
+  }
+
+  ENetPeer *ConnectionManager::getClientPeer(int clientID) {
+    return head_->findClient(clientID)->getPeer();
+  }
+
+  void ConnectionManager::syncClassid(int clientID) {
+    int i=0;
+    std::string classname;
+    bool abort=false;
+    orxonox::Identifier *id;
+    while(!abort){
+      id = ID(i);
+      std::cout << "syncid: " << i << ", ID(id): " << id << std::endl;
+      if(id == NULL){
+        if(i!=0)
+          abort=true;
+        else{
+          ++i;
+          continue;
+        }
+      }
+      else{
+        classname = id->getName();
+        addPacket(packet_gen.clid( i, classname ),clientID);
+      }
+      ++i;
+    }
+    sendPackets();
+  }
+
+}
Index: code/trunk/src/network/ConnectionManager.h
===================================================================
--- code/trunk/src/network/ConnectionManager.h	(revision 790)
+++ code/trunk/src/network/ConnectionManager.h	(revision 790)
@@ -0,0 +1,86 @@
+//
+// C++ Interface: ConnectionManager
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef _ConnectionManager_H__
+#define _ConnectionManager_H__
+
+#include <string>
+// enet library for networking support
+#include <enet/enet.h>
+
+#include "NetworkPrereqs.h"
+#include "PacketBuffer.h"
+#include "PacketManager.h"
+
+namespace std
+{
+  bool operator<(ENetAddress a, ENetAddress b);
+}
+
+namespace network
+{
+#define NETWORK_PORT 55556
+#define NETWORK_MAX_CONNECTIONS 50
+#define NETWORK_WAIT_TIMEOUT 5000
+#define NETWORK_SEND_WAIT 5
+
+  struct ClientList{
+    ENetEvent *event;
+    int ID;
+    ClientList *next;
+  };
+
+  class ConnectionManager{
+  public:
+    ConnectionManager(ClientInformation *head);
+    ConnectionManager(int port, const char *address, ClientInformation *head);
+    ConnectionManager(int port, std::string address, ClientInformation *head);
+    ENetPacket *getPacket(ENetAddress &address); // thread1
+    ENetPacket *getPacket(int &clientID);
+    bool queueEmpty();
+    void createListener();
+    bool quitListener();
+    bool addPacket(ENetPacket *packet, ENetPeer *peer);
+    bool addPacket(ENetPacket *packet, int ID);
+    bool addPacketAll(ENetPacket *packet);
+    bool sendPackets(ENetEvent *event);
+    bool sendPackets();
+  private:
+    bool clientDisconnect(ENetPeer *peer);
+    //bool clientDisconnect(ENetPeer peer);
+    bool processData(ENetEvent *event);
+    bool addClient(ENetEvent *event);
+    void receiverThread();
+    void disconnectClients();
+    int getClientID(ENetPeer peer);
+    int getClientID(ENetAddress address);
+    void syncClassid(int clientID);
+    ENetPeer *getClientPeer(int clientID);
+    PacketBuffer buffer;
+    PacketGenerator packet_gen;
+
+    ENetHost *server;
+    ENetAddress bindAddress;
+
+    bool quit; // quit-variable (communication with threads)
+    ClientInformation *head_;
+  };
+
+
+
+
+
+
+
+
+}
+
+#endif /* _ConnectionManager_H__ */
Index: code/trunk/src/network/GameStateClient.cc
===================================================================
--- code/trunk/src/network/GameStateClient.cc	(revision 790)
+++ code/trunk/src/network/GameStateClient.cc	(revision 790)
@@ -0,0 +1,184 @@
+/*
+*   ORXONOX - the hottest 3D action shooter ever to exist
+*
+*
+*   License notice:
+*
+*   This program is free software; you can redistribute it and/or
+*   modify it under the terms of the GNU General Public License
+*   as published by the Free Software Foundation; either version 2
+*   of the License, or (at your option) any later version.
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with this program; if not, write to the Free Software
+*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+*   Author:
+*      ...
+*   Co-authors:
+*      ...
+*
+*/
+#include <zlib.h>
+
+#include "core/CoreIncludes.h"
+#include "Synchronisable.h"
+#include "GameStateClient.h"
+
+namespace network
+{
+  GameStateClient::GameStateClient() {
+  }
+
+  GameStateClient::~GameStateClient() {
+  }
+
+  bool GameStateClient::pushGameState(GameStateCompressed *compstate) {
+    if(compstate->diffed)
+      return loadSnapshot(decode(reference, *compstate));
+    else
+      return loadSnapshot(decode(*compstate));
+  }
+
+  /**
+  * 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
+  */
+  void GameStateClient::removeObject(orxonox::Iterator<Synchronisable> &it) {
+    orxonox::Iterator<Synchronisable> temp=it;
+    ++it;
+    delete  *temp;
+  }
+
+  /**
+  * 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 GameStateClient::loadSnapshot(GameState state) {
+    unsigned char *data=state.data;
+    std::cout << "loadSnapshot: loading gs: " << state.id << std::endl;
+    // 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){
+          std::cout << "classid: " << sync.classID << ", name: " << ID(sync.classID)->getName() << std::endl;
+          Synchronisable *no = (Synchronisable*)(ID(sync.classID)->fabricate());
+          no->objectID=sync.objectID;
+          no->classID=sync.classID;
+          it=orxonox::ObjectList<Synchronisable>::end();
+          // update data and create object/entity...
+          if( !no->updateData(sync) && !no->create() )
+            COUT(0) << "We couldn't create/update the object: " << sync.objectID << std::endl;
+          ++it;
+        }
+      } else {
+        // we have our object
+        if(! it->updateData(sync))
+          std::cout << "We couldn't update objectID: " \
+          << sync.objectID << "; classID: " << sync.classID << std::endl;
+      }
+      ++it;
+    }
+
+    return true;
+  }
+
+  GameState GameStateClient::diff(GameState a, GameState b) {
+    unsigned char *ap = a.data, *bp = b.data;
+    int of=0; // pointers offset
+    int dest_length=0;
+    if(a.size>=b.size)
+      dest_length=a.size;
+    else
+      dest_length=b.size;
+    unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
+    while(of<a.size && of<b.size){
+      *(dp+of)=*(ap+of)^*(bp+of); // do the xor
+      ++of;
+    }
+    if(a.size!=b.size){ // do we have to fill up ?
+      unsigned char n=0;
+      if(a.size<b.size){
+        while(of<dest_length){
+          *(dp+of)=n^*(bp+of);
+          of++;
+        }
+      } else{
+        while(of<dest_length){
+          *(dp+of)=*(ap+of)^n;
+          of++;
+        }
+      }
+    }
+    // should be finished now
+    // FIXME: is it true or false now? (struct has changed, producing warnings)
+    GameState r = {b.id, dest_length, true, dp};
+    return r;
+  }
+
+  GameState GameStateClient::decompress(GameStateCompressed a) {
+    int normsize = a.normsize;
+    int compsize = a.compsize;
+    int bufsize;
+    if(normsize < compsize)
+      bufsize = compsize;
+    else
+      bufsize = normsize;
+    unsigned char* dest = (unsigned char*)malloc( bufsize );
+    int retval;
+    uLongf length=normsize;
+    //std::cout << "gamestateclient" << std::endl;
+    //std::cout << "normsize " << a.normsize << " compsize " << a.compsize << " " << bufsize << std::endl;
+    retval = uncompress( dest, &length, a.data, (uLong)compsize );
+    //std::cout << "length " << length << std::endl;
+    switch ( retval ) {
+      case Z_OK: std::cout << "successfully decompressed" << std::endl; break;
+      case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break;
+      case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break;
+      case Z_DATA_ERROR: std::cout << "data corrupted" << std::endl; break;
+    }
+
+    GameState gamestate;
+    gamestate.id = a.id;
+    gamestate.size = normsize;
+    gamestate.data = dest;
+    gamestate.diffed = a.diffed;
+
+    return gamestate;
+  }
+
+  GameState GameStateClient::decode(GameState a, GameStateCompressed x) {
+    GameState t = decompress(x);
+    return diff(a, t);
+  }
+
+  GameState GameStateClient::decode(GameStateCompressed x) {
+    GameState t = decompress(x);
+    return t;
+  }
+
+}
Index: code/trunk/src/network/GameStateClient.h
===================================================================
--- code/trunk/src/network/GameStateClient.h	(revision 790)
+++ code/trunk/src/network/GameStateClient.h	(revision 790)
@@ -0,0 +1,39 @@
+//
+// C++ Interface: GameStateClient
+//
+// Description:
+//
+//
+// Author:  <>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef _GameStateClient_H__
+#define _GameStateClient_H__
+
+#include "NetworkPrereqs.h"
+#include "GameStateManager.h"
+
+namespace network
+{
+  class GameStateClient
+  {
+  public:
+    GameStateClient();
+    ~GameStateClient();
+    bool pushGameState(GameStateCompressed *compstate);
+  private:
+    bool loadSnapshot(GameState state);
+    GameState diff(GameState a, GameState b);
+    GameState decompress(GameStateCompressed a);
+    GameState decode(GameState a, GameStateCompressed x);
+    GameState decode(GameStateCompressed x);
+    void removeObject(orxonox::Iterator<Synchronisable> &it);
+
+    GameState reference;
+  };
+
+}
+
+#endif /* _GameStateClient_H__ */
Index: code/trunk/src/network/GameStateManager.cc
===================================================================
--- code/trunk/src/network/GameStateManager.cc	(revision 790)
+++ code/trunk/src/network/GameStateManager.cc	(revision 790)
@@ -0,0 +1,243 @@
+/*
+*   ORXONOX - the hottest 3D action shooter ever to exist
+*
+*
+*   License notice:
+*
+*   This program is free software; you can redistribute it and/or
+*   modify it under the terms of the GNU General Public License
+*   as published by the Free Software Foundation; either version 2
+*   of the License, or (at your option) any later version.
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with this program; if not, write to the Free Software
+*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+*   Author:
+*      Oliver Scheuss, (C) 2007
+*   Co-authors:
+*      ...
+*
+*/
+
+//
+// C++ Implementation: GameStateManager
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include <utility>
+#include <iostream>
+#include <zlib.h>
+
+#include "core/CoreIncludes.h"
+#include "ClientInformation.h"
+#include "Synchronisable.h"
+#include "GameStateManager.h"
+
+namespace network
+{
+  GameStateManager::GameStateManager(ClientInformation *head) {
+    id=0;
+    head_=head;
+  }
+
+  GameStateManager::~GameStateManager() {
+  }
+
+  void GameStateManager::update(){
+    reference = getSnapshot(id);
+    gameStateMap.insert(std::pair<int, GameState*>(id, reference));
+    gameStateUsed[id]=0;
+    ++id;
+    return;
+  }
+
+  GameStateCompressed GameStateManager::popGameState(int clientID) {
+    int gID = head_->findClient(clientID)->getGamestateID();
+    std::cout << "popgamestate: sending gstate id: " << id << "diffed from: " << gID << std::endl;
+    if(gID!=GAMESTATEID_INITIAL){
+      GameState *client = gameStateMap[gID];
+      GameState *server = reference;
+      //head_->findClient(clientID)->setGamestateID(id);
+      return encode(client, server);
+    } else {
+      GameState *server = reference;
+      //head_->findClient(clientID)->setGamestateID(id);
+      return encode(server);
+      // return an undiffed gamestate and set appropriate flags
+    }
+  }
+
+  /**
+  * 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;
+    int memsize=1000;
+    //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=new GameState; //return value
+    retval->id=id++;
+    std::cout << "producing gamestate with id: " << retval->id << std::endl;
+    // reserve a little memory and increase it later on
+    //COUT(2) << "mallocing" << std::endl;
+    retval->data = (unsigned char*)malloc(memsize);
+    //COUT(2) << "malloced" << std::endl;
+
+    // offset of memory functions
+    int offset=0;
+    // go through all Synchronisables
+    for(it = orxonox::ObjectList<Synchronisable>::start(); it != 0; ++it){
+      //std::cout << "gamestatemanager: in for loop" << std::endl;
+      //get size of the synchronisable
+      tempsize=it->getSize();
+      //std::cout << "size of temp gamestate: " << tempsize << std::endl;
+      //COUT(2) << "size of synchronisable: " << tempsize << std::endl;
+      // add place for data and 3 ints (length,classid,objectid)
+      totalsize+=tempsize+3*sizeof(int);
+      //std::cout << "totalsize: " << totalsize << std::endl;
+      // allocate additional space
+      if(totalsize+tempsize>memsize){
+        if(tempsize<1000){
+          retval->data = (unsigned char *)realloc((void *)retval->data, totalsize+1000);
+          memsize+=1000;
+        } else {
+          retval->data = (unsigned char *)realloc((void *)retval->data, totalsize+1000);
+          memsize+=tempsize+1000;
+        }
+      }
+
+      // 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;
+  }
+
+  GameStateCompressed GameStateManager::encode(GameState *a, GameState *b) {
+    //GameState r = diff(a,b);
+    //r.diffed = true;
+    GameState r = *b;
+    r.diffed = false;
+    return compress_(&r);
+  }
+
+  GameStateCompressed GameStateManager::encode(GameState *a) {
+    a->diffed=false;
+    return compress_(a);
+  }
+
+  GameState GameStateManager::diff(GameState *a, GameState *b) {
+    unsigned char *ap = a->data, *bp = b->data;
+    int of=0; // pointers offset
+    int dest_length=0;
+    if(a->size>=b->size)
+      dest_length=a->size;
+    else
+      dest_length=b->size;
+    unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
+    while(of<a->size && of<b->size){
+      *(dp+of)=*(ap+of)^*(bp+of); // do the xor
+      ++of;
+    }
+    if(a->size!=b->size){ // do we have to fill up ?
+      unsigned char n=0;
+      if(a->size<b->size){
+        while(of<dest_length){
+          *(dp+of)=n^*(bp+of);
+          of++;
+        }
+      } else{
+        while(of<dest_length){
+          *(dp+of)=*(ap+of)^n;
+          of++;
+        }
+      }
+    }
+    // should be finished now
+    // FIXME: is it true or false now? (struct has changed, producing warnings)
+    GameState r = {b->id, dest_length, true, dp};
+    return r;
+  }
+
+  GameStateCompressed GameStateManager::compress_(GameState *a) {
+    //COUT(2) << "compressing gamestate" << std::endl;
+    int size = a->size;
+    uLongf buffer = (uLongf)((a->size + 12)*1.01)+1;
+    unsigned char* dest = (unsigned char*)malloc( buffer );
+    int retval;
+    //std::cout << "before ziped " << buffer << std::endl;
+    retval = compress( dest, &buffer, a->data, (uLong)size );
+    //std::cout << "after ziped " << buffer << std::endl;
+
+    switch ( retval ) {
+      case Z_OK: std::cout << "successfully compressed" << std::endl; break;
+      case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break;
+      case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break;
+      case Z_DATA_ERROR: std::cout << "decompress: data corrupted" << std::endl; break;
+    }
+
+    GameStateCompressed compressedGamestate;
+    compressedGamestate.compsize = buffer;
+    //std::cout << "compressedGamestate.compsize = buffer; " << buffer << std::endl;
+    compressedGamestate.normsize = size;
+    //std::cout << "compressedGamestate.normsize = size; " << size << std::endl;
+    compressedGamestate.id = a->id;
+    compressedGamestate.data = dest;
+    compressedGamestate.diffed = a->diffed;
+
+    return compressedGamestate;
+  }
+
+  void GameStateManager::ackGameState(int clientID, int gamestateID) {
+    ClientInformation *temp = head_->findClient(clientID);
+    int curid = temp->getID();
+    // decrease usage of gamestate and save it
+    deleteUnusedGameState(curid);
+    //increase gamestateused
+    ++gameStateUsed.find(gamestateID)->second;
+    temp->setGamestateID(gamestateID);
+    /*
+    GameState *old = clientGameState[clientID];
+    deleteUnusedGameState(old);
+    clientGameState[clientID]=idGameState[gamestateID];*/
+  }
+
+  bool GameStateManager::deleteUnusedGameState(int gamestateID) {
+    int used = --(gameStateUsed.find(gamestateID)->second);
+    if(id-gamestateID>KEEP_GAMESTATES && used==0){
+      // delete gamestate
+      delete gameStateMap.find(gamestateID)->second;
+      gameStateMap.erase(gamestateID);
+      return true;
+    }
+    return false;
+  }
+
+}
Index: code/trunk/src/network/GameStateManager.h
===================================================================
--- code/trunk/src/network/GameStateManager.h	(revision 790)
+++ code/trunk/src/network/GameStateManager.h	(revision 790)
@@ -0,0 +1,64 @@
+//
+// C++ Interface: GameStateManager
+//
+// Description: 
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef _GameStateManager_H__
+#define _GameStateManager_H__
+
+#include <map>
+
+#include "NetworkPrereqs.h"
+#include "PacketTypes.h"
+
+namespace network
+{
+
+#define KEEP_GAMESTATES 20
+
+  /**
+  * This Class implements a manager for gamestates:
+  * - creating snapshots of gamestates
+  * - writing gamestates to universe
+  * - diffing gamestates ?
+  * 
+  * EN/DECODATION:
+  * a: last Gamestate a client has received
+  * b: new Gamestate
+  * x: diffed and compressed gamestate
+  * x=(a^b)
+  * b=(a^x)
+  * diff(a,diff(a,x))=x (hope this is correct)
+  * @author Oliver Scheuss
+  */
+  class GameStateManager{
+  public:
+    GameStateManager(ClientInformation *head);
+    ~GameStateManager();
+    void update();
+    GameStateCompressed popGameState(int clientID);
+    void ackGameState(int clientID, int gamestateID);
+    int id;
+  private:
+    GameState *getSnapshot(int id);
+    GameStateCompressed encode(GameState *a, GameState *b);
+    GameStateCompressed encode(GameState *a);
+    GameState diff(GameState *a, GameState *b);
+    GameStateCompressed compress_(GameState *a);
+    bool deleteUnusedGameState(int gamestateID);
+
+    std::map<int, GameState*> gameStateMap; //map gsID to gamestate*
+    std::map<int, int> gameStateUsed; // save the number of clients, that use the specific gamestate
+    GameState *reference;
+    ClientInformation *head_;
+  };
+
+}
+
+#endif /* _GameStateManager_H__ */
Index: code/trunk/src/network/Makefile.norm
===================================================================
--- code/trunk/src/network/Makefile.norm	(revision 790)
+++ code/trunk/src/network/Makefile.norm	(revision 790)
@@ -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/trunk/src/network/Makefile.tardis
===================================================================
--- code/trunk/src/network/Makefile.tardis	(revision 790)
+++ code/trunk/src/network/Makefile.tardis	(revision 790)
@@ -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/trunk/src/network/Makefile.test
===================================================================
--- code/trunk/src/network/Makefile.test	(revision 790)
+++ code/trunk/src/network/Makefile.test	(revision 790)
@@ -0,0 +1,45 @@
+CC=g++
+MAIN_INC=..
+INC=-I ${MAIN_INC} -I..
+
+all: server client
+
+# Link command:
+server: PacketBuffer.o ConnectionManager.o dummyserver.o PacketDecoder.o PacketGenerator.o ClientInformation.o
+	${CC} PacketDecoder.o PacketGenerator.o ClientInformation.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}
+ClientInformation.o: ClientInformation.cc
+	${CC} -c ClientInformation.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}
+
+chatserver: Server.o ConnectionManager.o PacketGenerator.o PacketDecoder.o PacketBuffer.o ClientInformation.o GameStateManager.o
+	${CC} dummyserver3.cc Server.o ConnectionManager.o PacketGenerator.o PacketBuffer.o GameStateManager.o ClientInformation.o -o chatserver -lenet -lboost_thread -g ${INC}
Index: code/trunk/src/network/NetworkFrameListener.h
===================================================================
--- code/trunk/src/network/NetworkFrameListener.h	(revision 790)
+++ code/trunk/src/network/NetworkFrameListener.h	(revision 790)
@@ -0,0 +1,49 @@
+//
+// C++ Interface: NetworkFrameListener
+//
+// Description: 
+//
+//
+// Author:  <>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef _NetworkFrameListener_H__
+#define _NetworkFrameListener_H__
+
+#include <OgreFrameListener.h>
+
+#include "NetworkPrereqs.h"
+#include "Server.h"
+#include "Client.h"
+
+network::Server *server_g;
+network::Client *client_g;
+
+namespace network
+{
+  class ServerFrameListener : public Ogre::FrameListener{
+  private:
+    bool frameStarted(const Ogre::FrameEvent &evt){
+      server_g->tick(evt.timeSinceLastFrame);
+      return FrameListener::frameStarted(evt);
+    }
+  };
+
+  class ClientFrameListener : public Ogre::FrameListener{
+  private:
+    bool frameStarted(const Ogre::FrameEvent &evt){
+      //std::cout << "framelistener" << std::endl;
+      client_g->tick(evt.timeSinceLastFrame);
+      return FrameListener::frameStarted(evt);
+    }
+  };
+
+
+
+
+}
+
+#endif /* _NetworkFrameListener_H__ */
Index: code/trunk/src/network/NetworkPrereqs.h
===================================================================
--- code/trunk/src/network/NetworkPrereqs.h	(revision 790)
+++ code/trunk/src/network/NetworkPrereqs.h	(revision 790)
@@ -0,0 +1,90 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+ @file  NetworkPrereqs.h
+ @brief Contains all the necessary forward declarations for all classes, structs and enums.
+ */
+
+#ifndef _NetworkPrereqs_H__
+#define _NetworkPrereqs_H__
+
+#include "orxonox/OrxonoxPlatform.h"
+
+//-----------------------------------------------------------------------
+// Shared library settings
+//-----------------------------------------------------------------------
+#if (ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32) && !defined( NETWORK_STATIC_BUILD )
+#  ifdef NETWORK_SHARED_BUILD
+#    define _NetworkExport __declspec(dllexport)
+#  else
+#    if defined( __MINGW32__ )
+#      define _NetworkExport
+#    else
+#      define _NetworkExport __declspec(dllimport)
+#    endif
+#  endif
+#elif defined ( ORXONOX_GCC_VISIBILITY )
+#  define _NetworkExport  __attribute__ ((visibility("default")))
+#else
+#  define _NetworkExport
+#endif
+
+
+//-----------------------------------------------------------------------
+// Forward declarations
+//-----------------------------------------------------------------------
+namespace network
+{
+  class Client;
+  class ClientConnection;
+  class ClientFrameListener;
+  class ClientInformation;
+  class ConnectionManager;
+  class GameStateClient;
+  class GameStateManager;
+  class PacketBuffer;
+  class PacketDecoder;
+  class PacketGenerator;
+  class Server;
+  class ServerFrameListener;
+  class Synchronisable;
+  struct ack;
+  struct chat;
+  struct classid;
+  struct ClientList;
+  struct GameState;
+  struct GameStateCompressed;
+  struct keyboard;
+  struct mouse;
+  struct PacketEnvelope;
+  struct QueueItem;
+  struct synchData;
+  struct synchronisableVariable;
+}
+
+#endif /* _NetworkPrereqs_H__ */
Index: code/trunk/src/network/PacketBuffer.cc
===================================================================
--- code/trunk/src/network/PacketBuffer.cc	(revision 790)
+++ code/trunk/src/network/PacketBuffer.cc	(revision 790)
@@ -0,0 +1,136 @@
+/*
+*   ORXONOX - the hottest 3D action shooter ever to exist
+*
+*
+*   License notice:
+*
+*   This program is free software; you can redistribute it and/or
+*   modify it under the terms of the GNU General Public License
+*   as published by the Free Software Foundation; either version 2
+*   of the License, or (at your option) any later version.
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with this program; if not, write to the Free Software
+*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+*   Author:
+*      Oliver Scheuss, (C) 2007
+*   Co-authors:
+*      ...
+*
+*/
+
+// C++ PacketBuffer
+// d
+// Author Oliver Scheuss
+
+#include <iostream>
+#include <queue>
+#include <string>
+#include <boost/bind.hpp>
+#include <boost/thread/mutex.hpp>
+
+#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);
+    //std::cout << "event size inside packetbuffer " << ev->packet->dataLength << std::endl;
+    //   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);
+    //std::cout << "packetbuffer pop" << std::endl;
+    if(first!=NULL /*&& !closed*/){
+      QueueItem *temp = first;
+      // get packet
+      ENetPacket *pck=first->packet;
+      // remove first element
+      first = first->next;
+      delete temp;
+      //std::cout << "pop size of packet " << pck->dataLength << std::endl;
+      return pck;
+    } else{
+      //std::cout << "nothing to return" << std::endl;
+      return NULL;
+    }
+  }
+
+  ENetPacket *PacketBuffer::pop(ENetAddress &address) {
+    boost::mutex::scoped_lock lock(networkPacketBufferMutex);
+    //std::cout << "packetbuffer pop(address)" << std::endl;
+    if(first!=NULL /*&& !closed*/){
+      QueueItem *temp = first;
+      // get packet
+      ENetPacket *pck=first->packet;
+      address = first->address;
+      // remove first element
+      first = first->next;
+      delete temp;
+      //std::cout << "pop(address) size of packet " << pck->dataLength << std::endl;
+      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
Index: code/trunk/src/network/PacketBuffer.h
===================================================================
--- code/trunk/src/network/PacketBuffer.h	(revision 790)
+++ code/trunk/src/network/PacketBuffer.h	(revision 790)
@@ -0,0 +1,54 @@
+//
+// C++ Interface: PacketBuffer
+//
+// Description: 
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef _PacketBuffer_H__ 
+#define _PacketBuffer_H__
+
+#include <enet/enet.h>
+
+#include "NetworkPrereqs.h"
+
+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 /* _PacketBuffer_H__ */
Index: code/trunk/src/network/PacketBufferTestExt.cc
===================================================================
--- code/trunk/src/network/PacketBufferTestExt.cc	(revision 790)
+++ code/trunk/src/network/PacketBufferTestExt.cc	(revision 790)
@@ -0,0 +1,81 @@
+/*
+*   ORXONOX - the hottest 3D action shooter ever to exist
+*
+*
+*   License notice:
+*
+*   This program is free software; you can redistribute it and/or
+*   modify it under the terms of the GNU General Public License
+*   as published by the Free Software Foundation; either version 2
+*   of the License, or (at your option) any later version.
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with this program; if not, write to the Free Software
+*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+*   Author:
+*      ...
+*   Co-authors:
+*      ...
+*
+*/
+
+#include <string>
+#include <iostream>
+#include <enet/enet.h>
+#include <boost/thread/thread.hpp>
+
+#include "util/Sleep.h"
+#include "PacketBuffer.h"
+#include "PacketBuffer.cc"
+
+using namespace network;
+
+void write(PacketBuffer *test){
+  ENetEvent event;
+  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;
+    event.packet=packet;
+    test->push(&event);
+    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/trunk/src/network/PacketDecoder.cc
===================================================================
--- code/trunk/src/network/PacketDecoder.cc	(revision 790)
+++ code/trunk/src/network/PacketDecoder.cc	(revision 790)
@@ -0,0 +1,263 @@
+/*
+*   ORXONOX - the hottest 3D action shooter ever to exist
+*
+*
+*   License notice:
+*
+*   This program is free software; you can redistribute it and/or
+*   modify it under the terms of the GNU General Public License
+*   as published by the Free Software Foundation; either version 2
+*   of the License, or (at your option) any later version.
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with this program; if not, write to the Free Software
+*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+*   Author:
+*      Dumeni Manatschal, (C) 2007
+*   Co-authors:
+*      ...
+*
+*/
+
+/*
+* 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 <iostream>
+
+#include "PacketTypes.h"
+#include "PacketManager.h"
+
+namespace network
+{
+  using namespace std;
+
+  PacketDecoder::PacketDecoder(){}
+
+  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
+    std::cout << "packet id: " << id << std::endl;
+    std::cout << "packet size inside packetdecoder: " << packet->dataLength << std::endl;
+    switch( id ) {
+  case ACK:
+    acknowledgement( packet, clientId );
+    return true;
+    break;
+  case MOUSE:
+    mousem( packet, clientId );
+    return true;
+    break;
+  case KEYBOARD:
+    keystrike( packet, clientId );
+    return true;
+    break;
+  case CHAT:
+    chatMessage( packet, clientId );
+    return true;
+    break;
+  case GAMESTATE:
+    gstate( packet );
+    return true;
+    break;
+  case CLASSID:
+    clid(packet);
+    return true;
+    break;
+    }
+    return false;
+  }
+
+  //following are the decode functions for the data of the packets
+
+  void PacketDecoder::acknowledgement( ENetPacket* packet, int clientId )
+  {
+    ack* a = new ack;
+    *a = *(ack*)packet->data; //press pattern of ack on new data
+
+
+    std::cout << "got ack id: " << a->id << std::endl;
+    processAck( a, clientId ); //debug info
+
+    //clean memory
+    enet_packet_destroy( packet );
+  }
+
+  void PacketDecoder::mousem( ENetPacket* packet, int clientId )
+  {
+    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, int clientId )
+  {
+    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, int clientId )
+  {
+    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 );
+
+    processChat( chatting, clientId ); //debug info
+  }
+
+  void PacketDecoder::gstate( ENetPacket* packet )
+  {
+    GameStateCompressed* currentState = new GameStateCompressed;
+    //since it's not alowed to use void* for pointer arithmetic
+    unsigned char* data = (unsigned char*)packet->data;
+    //copy the GameStateCompressed id into the struct, which is located at second place data+sizeof( int )
+    //memcpy( (void*)&(currentState->id), (const void*)(data+sizeof( int )), sizeof( int ) );
+    currentState->id = (int)*(data+sizeof(int));
+    std::cout << "id: " << currentState->id << std::endl;
+    //copy the size of the GameStateCompressed compressed data into the new GameStateCompressed struct, located at 3th
+    //position of the data stream, data+2*sizeof( int )
+    memcpy( (void*)&(currentState->compsize), (const void*)(data+2*sizeof( int )), sizeof( int) );
+    //currentState->compsize = (int)*(data+2*sizeof(int));
+    std::cout << "compsize: " << currentState->compsize << std::endl;
+    //size of uncompressed data
+    memcpy( (void*)&(currentState->normsize), (const void*)(data+3*sizeof( int )), sizeof( int ) );
+    //currentState->normsize = (int)*(data+3*sizeof(int));
+    std::cout << "normsize. " << currentState->normsize << std::endl;
+    //since the packetgenerator was changed, due to a new parameter, change this function too
+    memcpy( (void*)&(currentState->diffed), (const void*)(data+4*sizeof(int)), sizeof(bool));
+    //currentState->diffed = (bool)*(data+4*sizeof(int));
+    std::cout << "diffed: " << currentState->diffed << std::endl;
+    //since data is not allocated, because it's just a pointer, allocate it with size of gamestatedatastream
+    currentState->data = (unsigned char*)(malloc( currentState->compsize ));
+    if(currentState->data==NULL)
+      std::cout << "memory leak" << std::endl;
+    //copy the GameStateCompressed data
+    //std::cout << "packet size (enet): " << packet->dataLength << std::endl;
+    //std::cout << "totallen: " << 4*sizeof(int)+sizeof(bool)+currentState->compsize << std::endl;
+    memcpy( (void*)(currentState->data), (const void*)(data+4*sizeof( int ) + sizeof(bool)), currentState->compsize );
+
+    //clean memory
+    enet_packet_destroy( packet );
+    //run processGameStateCompressed
+    //TODO: not yet implemented!
+    processGamestate(currentState);
+  }
+
+  void PacketDecoder::clid( ENetPacket *packet)
+  {
+    classid* cid = new classid;
+    cid->length = ((classid*)(packet->data))->length;
+    cid->id = ((classid *)(packet->data))->id;
+    cid->clid = ((classid *)(packet->data))->clid;
+    cid->message = (const char *)malloc(cid->length);
+    void *data  = (void *)cid->message;
+    memcpy(data, (const void*)(packet->data+3*sizeof(int)), cid->length);
+    std::cout << "classid: " << cid->clid << ", name: " << cid->message << std::endl;
+    enet_packet_destroy( packet );
+    processClassid(cid);
+  }
+
+
+  // now the data processing functions:
+
+  void PacketDecoder::processChat( chat *data, int clientId)
+  {
+    printChat(data, clientId);
+  }
+
+  void PacketDecoder::processGamestate( GameStateCompressed *state )
+  {
+  }
+
+  void PacketDecoder::processClassid( classid *cid)
+  {
+    printClassid(cid);
+    return;
+  }
+
+  void PacketDecoder::processAck( ack *data, int clientID)
+  {
+    printAck(data);
+    return;
+  }
+
+
+  //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, int clientId )
+  {
+    if(clientId!=CLIENTID_CLIENT)
+      cout << "client: " << clientId << endl;
+    cout << "data id: " << data->id << endl;
+    cout << "data:    " << data->message << endl;
+  }
+
+  void PacketDecoder::printGamestate( GameStateCompressed* data )
+  {
+    cout << "id of GameStateCompressed:   " << data->id << endl;
+    cout << "size of GameStateCompressed: " << data->compsize << endl;
+  }
+
+  void PacketDecoder::printClassid( classid *cid)
+  {
+    cout << "id of classid:    " << cid->id << endl;
+    cout << "size of classid:  " << cid->length << endl;
+    cout << "ID of classid:    " << cid->clid <<endl;
+    cout << "data of classid:  " << cid->message <<endl;
+  }
+
+}
Index: code/trunk/src/network/PacketGenerator.cc
===================================================================
--- code/trunk/src/network/PacketGenerator.cc	(revision 790)
+++ code/trunk/src/network/PacketGenerator.cc	(revision 790)
@@ -0,0 +1,144 @@
+/*
+*   ORXONOX - the hottest 3D action shooter ever to exist
+*
+*
+*   License notice:
+*
+*   This program is free software; you can redistribute it and/or
+*   modify it under the terms of the GNU General Public License
+*   as published by the Free Software Foundation; either version 2
+*   of the License, or (at your option) any later version.
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with this program; if not, write to the Free Software
+*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+*   Author:
+*      Dumeni Manatschal, (C) 2007
+*   Co-authors:
+*      ...
+*
+*/
+
+/*
+* 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 <iostream>
+#include <list>
+#include <string>
+#include <cstring>
+
+#include "PacketTypes.h"
+#include "PacketManager.h"
+
+namespace network
+{
+  PacketGenerator::PacketGenerator() { }
+
+  //following functions create a packet in form of bytestream
+
+  ENetPacket* PacketGenerator::acknowledgement( int state, int reliable )
+  {
+    std::cout << "generating new acknowledgement, id: " << state << std::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 )
+  {
+    std::cout << "generating new mouse" << std::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 )
+  {
+    std::cout << "generating new keyboard" << std::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( GameStateCompressed* states, int reliable )
+  {
+    //std::cout << "packetgenerator" << std::endl;
+    //std::cout << "states->normsize " << states->normsize << std::endl;
+    //std::cout << "states->compsize " << states->compsize << std::endl;
+    int gid = GAMESTATE; //first assign the correct enet id
+    int totalLen = 4*sizeof( int ) + sizeof(bool) + states->compsize; //calculate the total size of the datastream memory
+    //std::cout << "totalLen " << totalLen << std::endl;
+    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 GameStateCompressed id
+    memcpy( (void*)(data+2*sizeof(int)), (const void*)&(states->compsize), sizeof(int));
+    memcpy( (void*)(data+3*sizeof(int)), (const void*)&(states->normsize), sizeof(int));
+    memcpy( (void*)(data+4*sizeof(int)), (const void*)&(states->diffed), sizeof(bool));
+    /*(int)*(data) = gid;
+    (int)*(data+sizeof(int)) = states->id;
+    //this is the compressed size of the GameStateCompressed data, place at 3th position of the enet datastream
+    (int)*(data+2*sizeof(int)) = states->compsize;
+    //this is the uncompressed size of GameStateCompressed data
+    (int)*(data+3*sizeof(int)) = states->normsize;
+    //since there is a new parameter inside GameStateCompressed, change this function to create packet
+    (bool)*(data+4*sizeof(int)) = states->diffed;*/
+    //place the GameStateCompressed data at the end of the enet datastream
+    memcpy( (void*)(data+4*sizeof( int ) + sizeof(bool)), (const void*)states->data, states->compsize );
+    //create an enet packet with the generated bytestream
+    ENetPacket *packet = enet_packet_create( data , totalLen, reliable );
+    //delete data;
+    return packet;
+  }
+
+  ENetPacket* PacketGenerator::clid( int classid, std::string classname, int reliable )
+  {
+    unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1);
+    std::cout << "classid: " << classid << ", name: " << classname << std::endl;
+    *(int *)data = CLASSID;
+    *((int *)data+1) = classname.length()+1;
+    *((int *)data+2) = classid;
+    memcpy( (void *)(data+3*sizeof(int)), classname.c_str(), classname.length()+1);
+    ENetPacket *packet = enet_packet_create( data , 3*sizeof(int)+classname.length()+1, reliable );
+    return packet;
+  }
+
+}
Index: code/trunk/src/network/PacketManager.h
===================================================================
--- code/trunk/src/network/PacketManager.h	(revision 790)
+++ code/trunk/src/network/PacketManager.h	(revision 790)
@@ -0,0 +1,80 @@
+#ifndef _PacketManager_H__
+#define _PacketManager_H__
+
+#include <string>
+#include <enet/enet.h>
+
+#include "NetworkPrereqs.h"
+
+#define CLIENTID_CLIENT -1
+
+//enum netowk generally used to set the type ID of a packet
+namespace network
+{
+  /*
+  * 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( GameStateCompressed *states, int reliable = ENET_PACKET_FLAG_RELIABLE );
+    ENetPacket* clid( int classid, std::string classname, int reliable = ENET_PACKET_FLAG_RELIABLE );
+  private:
+  };
+
+  /*
+  * class used to decode incoming packets
+  * 
+  * @autor: Dumeni Manatschal
+  * 
+  */
+  class _NetworkExport PacketDecoder
+  {
+  public:
+    PacketDecoder();
+    virtual ~PacketDecoder();
+    //call this function to decode, it calls the right decoding function below
+    bool elaborate( ENetPacket* packet, int clientId );
+  protected:
+
+    virtual void processChat( chat *data, int clientId);
+
+
+  private:
+
+
+
+    void acknowledgement( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
+    void mousem( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
+    void keystrike( ENetPacket* packet, int clientId = CLIENTID_CLIENT );
+    void chatMessage( ENetPacket* packet, int clientId = CLIENTID_CLIENT);
+    void gstate( ENetPacket* packet );
+    void clid( ENetPacket *packet);
+
+    //process data
+    //two functions are note yet implemented!
+    virtual void processGamestate(GameStateCompressed *state);
+    virtual void processAck( ack *data, int clientID);
+    void processClassid( classid *cid);
+    //virtual void processAck( ack *data);
+
+    //print functions
+    void printAck( ack* data );
+    void printMouse( mouse* data );
+    void printKey( keyboard* data );
+    void printChat( chat* data, int clientId );
+    void printGamestate( GameStateCompressed *data );
+    void printClassid( classid *cid);
+  };
+}
+
+#endif /* _PacketManager_H__ */
Index: code/trunk/src/network/PacketTypes.h
===================================================================
--- code/trunk/src/network/PacketTypes.h	(revision 790)
+++ code/trunk/src/network/PacketTypes.h	(revision 790)
@@ -0,0 +1,90 @@
+//
+// C++ Interface: PacketTypes
+//
+// Description:
+//
+//
+// Author:  <>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef _PacketTypes_H__
+#define _PacketTypes_H__
+
+#include "NetworkPrereqs.h"
+
+namespace network
+{
+  enum packet_id {
+    ACK,
+    MOUSE,
+    KEYBOARD,
+    CHAT,
+    GAMESTATE ,
+    CLASSID
+  };
+
+
+  /**
+  * 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;                       //!< total size of data
+    // new ---- change functions
+    bool diffed;
+    unsigned char *data;            //!< pointer to data
+  };
+
+  /**
+  * this struct defines a gamestate:
+  * compsize is the size of the compressed data
+  * normsize is the size of the uncompressed data
+  * data are the gamestates
+  */
+  struct GameStateCompressed{
+    int id;
+    int compsize;                   //!< size of compressed data
+    int normsize;                   //!< size of uncompressed data
+    // new ----- change functions
+    bool diffed;
+    unsigned char *data;            //!< gamestate data
+  };
+
+  struct classid{
+    int id;
+    int length;
+    int clid;
+    const char *message;
+  };
+
+
+  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;
+  };
+
+}
+
+#endif /* _PacketTypes_H__ */
Index: code/trunk/src/network/Server.cc
===================================================================
--- code/trunk/src/network/Server.cc	(revision 790)
+++ code/trunk/src/network/Server.cc	(revision 790)
@@ -0,0 +1,178 @@
+//
+// C++ Implementation: Server
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include <iostream>
+
+#include "ConnectionManager.h"
+#include "PacketTypes.h"
+#include "GameStateManager.h"
+#include "ClientInformation.h"
+//#include "NetworkFrameListener.h"
+#include "Server.h"
+
+
+namespace network
+{
+  /**
+  * Constructor for default values (bindaddress is set to ENET_HOST_ANY
+  *
+  */
+  Server::Server() {
+    packet_gen = PacketGenerator();
+    clients = new ClientInformation(true);
+    connection = new ConnectionManager(clients);
+    gamestates = new GameStateManager(clients);
+  }
+
+  /**
+  * Constructor
+  * @param port Port to listen on
+  * @param bindAddress Address to listen on
+  */
+  Server::Server(int port, std::string bindAddress) {
+    packet_gen = PacketGenerator();
+    clients = new ClientInformation();
+    connection = new ConnectionManager(port, bindAddress, clients);
+    gamestates = new GameStateManager(clients);
+  }
+
+  /**
+  * Constructor
+  * @param port Port to listen on
+  * @param bindAddress Address to listen on
+  */
+  Server::Server(int port, const char *bindAddress) {
+    packet_gen = PacketGenerator();
+    clients = new ClientInformation();
+    connection = new ConnectionManager(port, bindAddress, clients);
+    gamestates = new GameStateManager(clients);
+  }
+
+  /**
+  * 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());
+    //std::cout <<"adding packets" << std::endl;
+    connection->addPacketAll(packet);
+    //std::cout <<"added packets" << std::endl;
+    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);
+    std::cout <<"adding Packets" << std::endl;
+    connection->addPacketAll(packet);
+    //std::cout <<"added packets" << std::endl;
+    if (connection->sendPackets()){
+      std::cout << "Sucessfully" << std::endl;
+      return true;
+    }
+    return false;
+  }
+
+  /**
+  * Run this function once every tick
+  * calls processQueue and updateGamestate
+  * @param time time since last tick
+  */
+  void Server::tick(float time) {
+    processQueue();
+    updateGamestate();
+    return;
+  }
+
+  /**
+  * processes all the packets waiting in the queue
+  */
+  void Server::processQueue() {
+    ENetPacket *packet;
+    int clientID=-1;
+    while(!connection->queueEmpty()){
+      //std::cout << "Client " << clientID << " sent: " << std::endl;
+      packet = connection->getPacket(clientID);
+      elaborate(packet, clientID);
+    }
+  }
+
+  /**
+  * takes a new snapshot of the gamestate and sends it to the clients
+  */
+  void Server::updateGamestate() {
+    gamestates->update();
+    //std::cout << "updated gamestate, sending it" << std::endl;
+    sendGameState();
+    //std::cout << "sent gamestate" << std::endl;
+  }
+
+  /**
+  * sends the gamestate
+  */
+  bool Server::sendGameState() {
+    std::cout << "starting gamestate" << std::endl;
+    ClientInformation *temp = clients;
+    bool added=false;
+    while(temp!=NULL){
+      if(temp->head){
+        temp=temp->next();
+        continue;
+      }
+      if( !(temp->getSynched()) ){
+        std::cout << "not sending gamestate" << std::endl;
+        temp=temp->next();
+        continue;
+      }
+      std::cout << "doing gamestate" << std::endl;
+      int gid = temp->getGamestateID();
+      int cid = temp->getID();
+      std::cout << "server, got acked ID: " << gid << std::endl;
+      GameStateCompressed *gs = &(gamestates->popGameState(cid)); // FIXME: taking address of temporary, check if correct
+      //std::cout << "adding gamestate" << std::endl;
+      connection->addPacket(packet_gen.gstate(gs), cid);
+      //std::cout << "added gamestate" << std::endl;
+      added=true;
+      temp=temp->next();
+    }
+    if(added)
+      return connection->sendPackets();
+    else
+      return false;
+  }
+
+  void Server::processAck( ack *data, int clientID) {
+    clients->findClient(clientID)->setGamestateID(data->a);
+  }
+
+}
Index: code/trunk/src/network/Server.h
===================================================================
--- code/trunk/src/network/Server.h	(revision 790)
+++ code/trunk/src/network/Server.h	(revision 790)
@@ -0,0 +1,55 @@
+//
+// C++ Interface: Server
+//
+// Description:
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef _Server_H__
+#define _Server_H__
+
+#include <string>
+
+#include "PacketManager.h"
+#include "NetworkPrereqs.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 _NetworkExport Server : public PacketDecoder{
+  public:
+    Server();
+    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(float time);
+  protected:
+    void processQueue();
+    void updateGamestate();
+  private:
+    bool sendGameState();
+    void processAck( ack *data, int clientID);
+    ConnectionManager *connection;
+    GameStateManager *gamestates;
+    PacketGenerator packet_gen;
+
+    ClientInformation *clients;
+  };
+
+
+
+
+}
+
+#endif /* _Server_H__ */
Index: code/trunk/src/network/Synchronisable.cc
===================================================================
--- code/trunk/src/network/Synchronisable.cc	(revision 790)
+++ code/trunk/src/network/Synchronisable.cc	(revision 790)
@@ -0,0 +1,183 @@
+//
+// C++ Implementation: synchronisable
+//
+// Description:
+//
+//
+// Author:  Dumeni, Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+
+#include <string>
+#include <iostream>
+
+#include "Synchronisable.h"
+
+namespace network
+{
+  /**
+  * Constructor:
+  * calls registarAllVariables, that has to be implemented by the inheriting classID
+  */
+  Synchronisable::Synchronisable(){
+    RegisterRootObject(Synchronisable);
+    static int idCounter=0;
+    datasize=0;
+    objectID=idCounter++;
+    //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, variableType t){
+    // create temporary synch.Var struct
+    synchronisableVariable temp={size, var, t};
+    // 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 ;)
+  //     if(i->type == STRING)
+  //       totalsize+=sizeof(int)+((std::string *)i->var)->length()+1;
+  //     else
+  //       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++){
+  //     std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int));
+  //     n+=sizeof(int);
+  //     switch(i->type){
+  //     case STRING:
+  //       std::memcpy(retVal.data+n, (const void *)(((std::string *)i->var)->c_str()), ((std::string *)i->var)->length()+1);
+  //       n+=((std::string *)i->var)->length()+1;
+  //       break;
+  //     case DATA:
+  //       std::memcpy(retVal.data+n, ((const void*)i->var), i->size);
+  //       n+=i->size;
+  //       break;
+  //     }
+  //   }
+  //   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=getSize();
+    retVal.data=mem;
+    // copy to location
+    int n=0;
+    for(i=syncList.begin(); n<datasize && i!=syncList.end(); ++i){
+      //COUT(2) << "size of variable: " << i->size << std::endl;
+      //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));
+      memcpy( (void *)(retVal.data+n), (const void*)&(i->size), sizeof(int) );
+      n+=sizeof(int);
+      switch(i->type){
+      case DATA:
+        std::memcpy( (void *)(retVal.data+n), (const void*)(i->var), i->size);
+        n+=i->size;
+        break;
+      case STRING:
+        std::memcpy( retVal.data+n, (const void*)( ( (std::string *) i->var)->c_str()), ( (std::string *)i->var )->length()+1);
+        n+=((std::string *) i->var)->length()+1;
+        break;
+      }
+    }
+    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 || i->type==STRING){
+        switch(i->type){
+      case DATA:
+        data+=sizeof(int);
+        memcpy((void*)i->var, data, i->size);
+        data+=i->size;
+        break;
+      case STRING:
+        i->size = (int)*data;
+        data+=sizeof(int);
+        *((std::string *)i->var) = std::string((const char*)data);
+        data += i->size;
+        break;
+        }
+      } else
+        return false; //there was some problem with registerVar
+    }
+    return true;
+  }
+
+  /**
+  * 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(){
+    int tsize=0;
+    std::list<synchronisableVariable>::iterator i;
+    for(i=syncList.begin(); i!=syncList.end(); i++){
+      switch(i->type){
+    case DATA:
+      tsize+=sizeof(int);
+      tsize+=i->size;
+      break;
+    case STRING:
+      tsize+=sizeof(int);
+      tsize+=((std::string *)i->var)->length()+1;
+      break;
+      }
+    }
+    return tsize;
+  }
+
+}
Index: code/trunk/src/network/Synchronisable.h
===================================================================
--- code/trunk/src/network/Synchronisable.h	(revision 790)
+++ code/trunk/src/network/Synchronisable.h	(revision 790)
@@ -0,0 +1,77 @@
+//
+// C++ Interface: synchronisable
+//
+// Description: 
+//
+//
+// Author:  Oliver Scheuss, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef _Synchronisable_H__
+#define _Synchronisable_H__
+
+#include <list>
+
+#include "NetworkPrereqs.h"
+#include "core/CoreIncludes.h"
+
+namespace network
+{
+  enum variableType{
+    DATA,
+    STRING,
+  };
+
+  struct syncData{
+    int length;
+    int objectID;
+    int classID;
+    unsigned char *data;
+  };
+
+  typedef struct synchronisableVariable{
+    int size;
+    const void *var;
+    variableType type;
+  }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 _NetworkExport Synchronisable : virtual public orxonox::OrxonoxClass{
+  public:
+
+    virtual ~Synchronisable();
+    int objectID;
+    int classID;
+
+    void registerVar(const void *var, int size, variableType t);
+    //  syncData getData();
+    syncData getData(unsigned char *mem);
+    int getSize();
+    bool updateData(syncData vars);
+    void registerAllVariables();
+    virtual bool create()=0;
+  protected:
+    Synchronisable();
+  private:
+    /*  bool removeObject(Iterator<Synchronisable> it);*/
+
+    std::list<SYNCVAR> syncList;
+    int datasize;
+  };
+
+}
+
+namespace orxonox
+{
+  template class _NetworkExport ClassIdentifier<network::Synchronisable>;
+  template class _NetworkExport ObjectList<network::Synchronisable>;
+}
+
+#endif /* _Synchronisable_H__ */
Index: code/trunk/src/network/TODO
===================================================================
--- code/trunk/src/network/TODO	(revision 790)
+++ code/trunk/src/network/TODO	(revision 790)
@@ -0,0 +1,15 @@
+TODO:
+
+- change ConnectionManager clientlist [done]
+- change gamestatemanager clientlist [done]
+- put them together into ClientInformation [done]
+
+- do better gamestate-update/snapshot-handling [partially done]
+- integrate ClientInformation into gamestatemanager [done]
+
+- write dummyserver and dummyclient (chat system) [done]
+
+- include GameStateClient into Client and write processGamestate (also packetdecoder (virtual))
+- create object with worldentity .....
+
+- try and error ;)
Index: code/trunk/src/network/dummyclient.cc
===================================================================
--- code/trunk/src/network/dummyclient.cc	(revision 790)
+++ code/trunk/src/network/dummyclient.cc	(revision 790)
@@ -0,0 +1,123 @@
+/*
+*   ORXONOX - the hottest 3D action shooter ever to exist
+*
+*
+*   License notice:
+*
+*   This program is free software; you can redistribute it and/or
+*   modify it under the terms of the GNU General Public License
+*   as published by the Free Software Foundation; either version 2
+*   of the License, or (at your option) any later version.
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with this program; if not, write to the Free Software
+*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+*   Author:
+*      Oliver Scheuss, (C) 2007
+*   Co-authors:
+*      ...
+*
+*/
+
+//o
+// Dummy client to test ConnectionManager and PacketBuffer classes
+//
+// Author: Oliver Scheuss
+
+#include <iostream>
+#include <string>
+#include <enet/enet.h>
+
+#include "util/Sleep.h"
+#include "PacketManager.h"
+#include "PacketTypes.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/trunk/src/network/dummyclient2.cc
===================================================================
--- code/trunk/src/network/dummyclient2.cc	(revision 790)
+++ code/trunk/src/network/dummyclient2.cc	(revision 790)
@@ -0,0 +1,91 @@
+/*
+*   ORXONOX - the hottest 3D action shooter ever to exist
+*
+*
+*   License notice:
+*
+*   This program is free software; you can redistribute it and/or
+*   modify it under the terms of the GNU General Public License
+*   as published by the Free Software Foundation; either version 2
+*   of the License, or (at your option) any later version.
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with this program; if not, write to the Free Software
+*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+*   Author:
+*      Oliver Scheuss, (C) 2007
+*   Co-authors:
+*      ...
+*
+*/
+
+//
+// Dummy client to test ConnectionManager, PacketBuffer, ClientConnection and other classes
+//
+// Author: Oliver Scheuss
+
+#include <iostream>
+#include <string>
+#include <enet/enet.h>
+
+#include "util/Sleep.h"
+#include "PacketManager.h"
+#include "PacketTypes.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;  //FIXME: unused var!
+  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(1000000);
+  }
+  usleep(1000000);
+  // 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/trunk/src/network/dummyclient3.cc
===================================================================
--- code/trunk/src/network/dummyclient3.cc	(revision 790)
+++ code/trunk/src/network/dummyclient3.cc	(revision 790)
@@ -0,0 +1,81 @@
+#include <iostream>
+#include <string>
+
+#include "util/Sleep.h"
+#include "PacketManager.h"
+#include "PacketTypes.h"
+#include "Client.h"
+
+using namespace network;
+
+void sender(){
+
+  network::PacketGenerator pck;
+  const int PORT = 55556;
+  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";
+
+  Client client( str, PORT );
+  if ( client.establishConnection() )
+    std::cout << "connection established" << std::endl;
+  else std::cout << "problems establishing connection" << std::endl;
+  char message[10000];
+  char signs[] = "abcdefghijklmnopqrstuvwxy";
+  while (true) {
+    client.tick(0);
+
+    std::cout << "your message2: ";
+    for ( int i=0; i<9999; i++ ) {
+      message[i] = signs[0];
+    }
+    message[9999] = 'z';
+    std::string str( message );
+    client.sendChat( str );
+    std::cout << str << std::endl;
+    std::cin.get(); std::cin.get();
+  }
+
+
+
+}
+
+void listener(){
+
+  const int PORT = 55556;
+  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";
+
+  Client client( str, PORT );
+  if ( client.establishConnection() )
+    std::cout << "connection established" << std::endl;
+  else std::cout << "problems establishing connection" << std::endl;
+
+  while (true) {
+    client.tick(0);
+    usleep(100);
+  }
+
+
+
+}
+
+
+int main(int argc, char **argv[]){
+  std::string in;
+  std::cout << "Please choose: sender(s) oder listener(l)" << std::endl;
+  std::getline(std::cin, in);
+  if(in.compare("l")==0)
+    listener();
+  else if(in.compare("s")==0)
+    sender();
+  else
+    std::cout << "wrong answer" << std::endl;
+}
Index: code/trunk/src/network/dummyserver.cc
===================================================================
--- code/trunk/src/network/dummyserver.cc	(revision 790)
+++ code/trunk/src/network/dummyserver.cc	(revision 790)
@@ -0,0 +1,73 @@
+/*
+*   ORXONOX - the hottest 3D action shooter ever to exist
+*
+*
+*   License notice:
+*
+*   This program is free software; you can redistribute it and/or
+*   modify it under the terms of the GNU General Public License
+*   as published by the Free Software Foundation; either version 2
+*   of the License, or (at your option) any later version.
+*
+*   This program is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with this program; if not, write to the Free Software
+*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+*
+*   Author:
+*      Oliver Scheuss, (C) 2007
+*   Co-authors:
+*      ...
+*
+*/
+
+//
+// Dummy server to test ConnectionManager and PacketBuffer classes
+//
+// Author: Oliver Scheuss
+
+#include <iostream>
+#include <enet/enet.h>
+
+#include "util/Sleep.h"
+#include "ConnectionManager.h"
+#include "PacketManager.h"
+#include "PacketTypes.h"
+#include "ClientInformation.h"
+
+using namespace network;
+
+int main(){
+  bool quit=false;
+  ENetPacket *packet;
+  ClientInformation clients;
+  ConnectionManager server = ConnectionManager(&clients);
+  server.createListener();
+
+  PacketDecoder dec;
+
+  while(!quit){
+    if(server.queueEmpty())
+      // Warning: usleep(100) is Sleep(100/1000) = Sleep(0), which is nothing!
+      usleep(1);
+    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;
+}
Index: code/trunk/src/network/dummyserver3.cc
===================================================================
--- code/trunk/src/network/dummyserver3.cc	(revision 790)
+++ code/trunk/src/network/dummyserver3.cc	(revision 790)
@@ -0,0 +1,52 @@
+#include <iostream>
+
+#include "util/Sleep.h"
+#include "PacketManager.h"
+#include "PacketTypes.h"
+#include "Server.h"
+
+namespace network
+{
+
+  class dummyserver3 : public Server
+  {
+  public:
+    dummyserver3();
+    ~dummyserver3();
+    void loop();
+  private:
+    void tick();
+    void processChat( chat *data, int clientId);
+
+
+  };
+
+  dummyserver3::dummyserver3(){
+  }
+  dummyserver3::~dummyserver3(){
+  }
+
+  void dummyserver3::loop(){
+    open();
+    while(true){
+      tick();
+      usleep(100);
+    }
+  }
+
+  void dummyserver3::processChat( chat *data, int clientId){
+    std::cout << "Client " << clientId << " sent: " << data->message << std::endl;
+    sendMSG(data->message);
+  }
+
+  void dummyserver3::tick(){
+    processQueue();
+  }
+
+}
+
+int main(int argc, char **argv[]){
+  network::dummyserver3 server;
+  server.loop();
+  return 0;  
+}
