Index: /code/branches/network/TODO
===================================================================
--- /code/branches/network/TODO	(revision 1792)
+++ /code/branches/network/TODO	(revision 1793)
@@ -1,5 +1,6 @@
 todo: 
 	!!! check that enet does not cause a packet traffic jam when a reliable packet gets missed !!!
-	spaceship of client vanishes on server
-	new gamestate concept
+	[implemented] new gamestate concept
+	check Projectiles
+	check that we dont have to much registervar because of virtual function calls
 
Index: /code/branches/network/src/network/Client.cc
===================================================================
--- /code/branches/network/src/network/Client.cc	(revision 1792)
+++ /code/branches/network/src/network/Client.cc	(revision 1793)
@@ -43,5 +43,4 @@
 #include "Synchronisable.h"
 #include "core/CoreIncludes.h"
-#include "core/ConsoleCommand.h"
 #include "packet/Packet.h"
 // #include "packet/Acknowledgement.h"
@@ -118,32 +117,24 @@
   }
 
-  bool Client::processChat(packet::Chat *message, unsigned int clientID){
-    return message->process();
+  bool Client::processChat(std::string message, unsigned int playerID){
+    COUT(1) << "Player " << playerID << ": " << message << std::endl;
+    return true;
   }
-
-  /*bool Client::sendChat(packet::Chat *chat){
-    chat->process();
-    packet::Packet *p = new packet::Packet(chat);
-    return p->send();
-  }*/
+  
+  /**
+   * This function implements the method of sending a chat message to the server
+   * @param message message to be sent 
+   * @return result(true/false)
+   */
+  bool Client::chat(std::string message){
+    packet::Chat *m = new packet::Chat(message, Host::getPlayerID());
+    return m->send();
+  }
 
 
   /**
-  * 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;
-    packet::Chat chat(message, 0);
-    return chat.send();
-    // send packets
-  }
-
-  /**
-  * Performs a GameState update
-  */
+   * Processes incoming packets, sends a gamestate to the server and does the cleanup
+   * @param time 
+   */
   void Client::tick(float time){
 //     COUT(3) << ".";
Index: /code/branches/network/src/network/Client.h
===================================================================
--- /code/branches/network/src/network/Client.h	(revision 1792)
+++ /code/branches/network/src/network/Client.h	(revision 1793)
@@ -73,11 +73,10 @@
     bool closeConnection();
     bool queuePacket(ENetPacket *packet, int clientID);
-    bool processChat(packet::Chat *message, unsigned int clientID);
+    bool processChat(std::string message, unsigned int playerID);
+    virtual bool chat(std::string message);
     //bool sendChat(packet::Chat *chat);
     
 //    static void Chat( std::string message );
     
-    unsigned int shipID(){return shipID_;}
-    int playerID(){return clientID_;}
     //static void setShipID( unsigned int shipID){ dynamic_cast<Client *>(instance_)->shipID_=shipID; }
     static void setClientID( unsigned int clientID){ dynamic_cast<Client *>(instance_)->clientID_=clientID; }
@@ -91,11 +90,5 @@
     bool isConnected;
     bool isSynched_;
-
-    bool sendChat( std::string message );
     
-    // implement data processing functions of PacketDecoder
-//     void processChat( chat *data, int clientId );
-    int clientID_;     // this is the id the server gave to us
-    int shipID_;
     bool gameStateFailure_;
   };
Index: /code/branches/network/src/network/Host.cc
===================================================================
--- /code/branches/network/src/network/Host.cc	(revision 1792)
+++ /code/branches/network/src/network/Host.cc	(revision 1793)
@@ -30,12 +30,19 @@
 
 #include "Host.h"
+#include "core/ConsoleCommand.h"
 #include "packet/Packet.h"
 
 namespace network {
 
+SetConsoleCommandShortcut(Host, Chat);
+
 Host *Host::instance_=0;
   
+/**
+ * @brief Constructor: assures that only one reference will be created and sets the pointer
+ */
 Host::Host()
 {
+  clientID_=0;
   assert(instance_==0);
   instance_=this;
@@ -43,4 +50,7 @@
 
 
+/**
+ * @brief Destructor: resets the instance pointer to 0
+ */
 Host::~Host()
 {
@@ -48,4 +58,10 @@
 }
 
+/**
+ * This function is used to add an enetpacket to be sent to another peer
+ * @param packet Packet to be added
+ * @param clientID ID of the client the packet should be sent to
+ * @return success?
+ */
 bool Host::addPacket(ENetPacket *packet, int clientID){
   if(instance_)
@@ -70,15 +86,23 @@
 // }
 
-int Host::getPlayerID(){ 
+/**
+ * This function returns the ID of the player
+ * @return playerID
+ */
+unsigned int Host::getPlayerID(){ 
   if(!instance_)
     return 0;
-  return instance_->playerID();
+  return instance_->clientID_;
 }
 
-// unsigned int Host::getShipID(){ 
-//   if(!instance_)
-//     assert(0);
-//   return instance_->shipID();
-// }
+bool Host::Chat(std::string message){
+  if(!instance_)
+    return false;
+  return instance_->chat(message);
+}
+
+bool Host::incomingChat(std::string message, unsigned int playerID){
+  return instance_->processChat(message, playerID);
+}
 
 }//namespace network
Index: /code/branches/network/src/network/Host.h
===================================================================
--- /code/branches/network/src/network/Host.h	(revision 1792)
+++ /code/branches/network/src/network/Host.h	(revision 1793)
@@ -37,5 +37,10 @@
 
 /**
-	@author Oliver Scheuss
+*       @brief Base class of Server and Client
+*       This is the Base class of the Server and Client classes
+*       - Makes server and client a singleton
+*       - defines static functions available on both server and client
+*       - is the interface to be used when communicating with the network
+*	@author Oliver Scheuss
 */
 class Host{
@@ -45,6 +50,6 @@
     //virtual bool sendChat(packet::Chat *chat)=0;
     virtual bool queuePacket(ENetPacket *packet, int clientID)=0;
-    virtual unsigned int shipID()=0;
-    virtual int playerID()=0;
+    virtual bool chat(std::string message)=0;
+    virtual bool processChat(std::string message, unsigned int playerID)=0;
 
 
@@ -55,4 +60,6 @@
     static Host *instance_;
     bool isServer_;	
+    unsigned int clientID_;
+    unsigned int shipID_;
 
   public:
@@ -61,12 +68,12 @@
     //static bool chat(std::string& message);
 //     static bool receiveChat(packet::Chat *message, unsigned int clientID);
-    static int getPlayerID();
+    static unsigned int getPlayerID();
     static unsigned int getShipID(){return instance_->shipID_;}
     static void setClientID(unsigned int id){ instance_->clientID_ = id; }
     static void setShipID(unsigned int id){ instance_->shipID_ = id; }
     static bool isServer(){ return instance_->isServer_; }		
+    static bool Chat(std::string message);
+    static bool incomingChat(std::string message, unsigned int playerID);
   private:
-    unsigned int clientID_;
-    unsigned int shipID_;
 };
 
Index: /code/branches/network/src/network/Server.cc
===================================================================
--- /code/branches/network/src/network/Server.cc	(revision 1792)
+++ /code/branches/network/src/network/Server.cc	(revision 1793)
@@ -122,45 +122,18 @@
   }
 
-  bool Server::processChat(packet::Chat *message, unsigned int clientID){
+  bool Server::processChat(std::string message, unsigned int playerID){
     ClientInformation *temp = ClientInformation::getBegin();
+    packet::Chat *chat;
     while(temp){
-      message->setClientID(temp->getID());
-      if(!message->send())
-        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
-      temp = temp->next();
-    }
-    return message->process();
-  }
-
-  /**
-  * This function sends out a message to all clients
-  * @param msg message
-  * @return true/false
-  */
-  bool Server::sendChat(packet::Chat *chat) {
-    //TODO: change this (no informations about who wrote a message)
-    assert(0);
-    ClientInformation *temp = ClientInformation::getBegin();
-    while(temp){
+      chat = new packet::Chat(message, playerID);
       chat->setClientID(temp->getID());
       if(!chat->send())
         COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
-    }
-    return chat->process();;
-  }
-
-  /**
-  * This function sends out a message to all clients
-  * @param msg message
-  * @return true/false
-  */
-//   bool Server::sendChat(const char *msg) {
-//     char *message = new char [strlen(msg)+10+1];
-//     sprintf(message, "Player %d: %s", CLIENTID_SERVER, msg);
-//     COUT(1) << message << std::endl;
-//     ENetPacket *packet = packet_gen.chatMessage(message);
-//     COUT(5) <<"Server: adding Packets" << std::endl;
-//     return connection->addPacketAll(packet);
-//   }
+      temp = temp->next();
+    }
+    COUT(1) << "Player " << playerID << ": " << message << std::endl;
+    return true;
+  }
+
 
   /**
@@ -175,12 +148,7 @@
     if(timeSinceLastUpdate_>=(1./NETWORK_FREQUENCY)){
       timeSinceLastUpdate_=(float)((int)(timeSinceLastUpdate_*NETWORK_FREQUENCY))/timeSinceLastUpdate_;
-//      timeSinceLastUpdate_-=1./NETWORK_FREQUENCY;
       gamestates_->processGamestates();
       updateGamestate();
     }
-    /*while(timeSinceLastUpdate_>1./NETWORK_FREQUENCY)
-      timeSinceLastUpdate_-=1./NETWORK_FREQUENCY;*/
-//     usleep(5000); // TODO remove
-    return;
   }
 
@@ -303,14 +271,5 @@
     return true;
   }
-  
-//   void Server::processChat( chat *data, int clientId){
-//     char *message = new char [strlen(data->message)+10+1];
-//     sprintf(message, "Player %d: %s", clientId, data->message);
-//     COUT(1) << message << std::endl;
-//     ENetPacket *pck = packet_gen.chatMessage(message);
-//     connection->addPacketAll(pck);
-//     delete[] data->message;
-//     delete data;
-//   }
+
 
   bool Server::addClient(ENetEvent *event){
@@ -417,4 +376,18 @@
     gamestates_->removeClient(client);
   }
+  
+  bool Server::chat(std::string message){
+    ClientInformation *temp = ClientInformation::getBegin();
+    packet::Chat *chat;
+    while(temp){
+      chat = new packet::Chat(message, Host::getPlayerID());
+      chat->setClientID(temp->getID());
+      if(!chat->send())
+        COUT(3) << "could not send Chat message to client ID: " << temp->getID() << std::endl;
+      temp = temp->next();
+    }
+    COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl;
+    return true;
+  }
 
 }
Index: /code/branches/network/src/network/Server.h
===================================================================
--- /code/branches/network/src/network/Server.h	(revision 1792)
+++ /code/branches/network/src/network/Server.h	(revision 1793)
@@ -66,6 +66,5 @@
     void open();
     void close();
-    bool processChat(packet::Chat *message, unsigned int clientID);
-    bool sendChat(packet::Chat *chat);
+    bool processChat(std::string message, unsigned int playerID);
     bool queuePacket(ENetPacket *packet, int clientID);
     void tick(float time);
@@ -75,5 +74,5 @@
   private:
     unsigned int shipID(){return 0;}
-    int playerID(){return 0;}
+    unsigned int playerID(){return 0;}
     
     bool addClient(ENetEvent *event);
@@ -86,4 +85,5 @@
     bool sendGameState();
     bool sendObjectDeletes();
+    virtual bool chat(std::string message);
     
     //void processChat( chat *data, int clientId);
Index: /code/branches/network/src/network/Synchronisable.cc
===================================================================
--- /code/branches/network/src/network/Synchronisable.cc	(revision 1792)
+++ /code/branches/network/src/network/Synchronisable.cc	(revision 1793)
@@ -51,4 +51,5 @@
 namespace network
 {
+  
 
   std::map<unsigned int, Synchronisable *> Synchronisable::objectMap_;
@@ -59,5 +60,5 @@
   /**
   * Constructor:
-  * calls registarAllVariables, that has to be implemented by the inheriting classID
+  * Initializes all Variables and sets the right objectID
   */
   Synchronisable::Synchronisable(){
@@ -71,4 +72,8 @@
   }
 
+  /**
+   * Destructor: 
+   * Delete all callback objects and remove objectID from the objectMap_
+   */
   Synchronisable::~Synchronisable(){
     // delete callback function objects
@@ -81,4 +86,9 @@
   }
 
+  /**
+   * This function gets called after all neccessary data has been passed to the object
+   * Overload this function and recall the create function of the parent class
+   * @return true/false
+   */
   bool Synchronisable::create(){
     objectMap_[objectID]=this;
@@ -90,4 +100,8 @@
 
   
+  /**
+   * This function sets the internal mode for synchronisation
+   * @param b true if this object is located on a client or on a server
+   */
   void Synchronisable::setClient(bool b){
     if(b) // client
@@ -97,4 +111,11 @@
   }
   
+  /**
+   * This function fabricated a new synchrnisable (and children of it), sets calls updateData and create
+   * After calling this function the mem pointer will be increased by the size of the needed data
+   * @param mem pointer to where the appropriate data is located
+   * @param mode defines the mode, how the data should be loaded
+   * @return pointer to the newly created synchronisable
+   */
   Synchronisable *Synchronisable::fabricate(unsigned char*& mem, int mode)
   {
@@ -119,4 +140,9 @@
 
   
+  /**
+   * Finds and deletes the Synchronisable with the appropriate objectID
+   * @param objectID objectID of the Synchronisable
+   * @return true/false
+   */
   bool Synchronisable::deleteObject(unsigned int objectID){
     assert(getSynchronisable(objectID));
@@ -126,4 +152,9 @@
   }
   
+  /**
+   * This function looks up the objectID in the objectMap_ and returns a pointer to the right Synchronisable
+   * @param objectID objectID of the Synchronisable
+   * @return pointer to the Synchronisable with the objectID
+   */
   Synchronisable* Synchronisable::getSynchronisable(unsigned int objectID){
     std::map<unsigned int, Synchronisable *>::iterator i = objectMap_.find(objectID);
@@ -140,4 +171,7 @@
   * @param var pointer to the variable
   * @param size size of the datatype the variable consists of
+  * @param t the type of the variable (network::DATA or network::STRING
+  * @param mode same as in getData
+  * @param cb callback object that should get called, if the value of the variable changes
   */
   void Synchronisable::registerVar(void *var, int size, variableType t, int mode, NetworkCallbackBase *cb){
@@ -158,12 +192,16 @@
   
   /**
-   * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct
-   * Difference to the above function:
+   * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID and classID to the given memory
    * 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
+   * |totalsize,objectID,classID,var1,var2,string1_length,string1,var3,...|
+   * length of varx: size saved int syncvarlist
+   * @param mem pointer to allocated memory with enough size
+   * @param id gamestateid of the gamestate to be saved (important for priorities)
+   * @param mode defines the direction in which the data will be send/received
+   *             0x1: server->client
+   *             0x2: client->server (not recommended)
+   *             0x3: bidirectional
+   * @return true: if !isMyTick or if everything was successfully saved
    */
   bool Synchronisable::getData(unsigned char*& mem, unsigned int id, int mode){
@@ -224,6 +262,7 @@
   
   /**
-   * This function takes a syncData struct and takes it to update the variables
-   * @param vars data of the variables
+   * This function takes a bytestream and loads the data into the registered variables
+   * @param mem pointer to the bytestream
+   * @param mode same as in getData
    * @return true/false
    */
@@ -288,4 +327,6 @@
   /**
   * This function returns the total amount of bytes needed by getData to save the whole content of the variables
+  * @param id id of the gamestate
+  * @param mode same as getData
   * @return amount of bytes
   */
@@ -316,7 +357,7 @@
 
   /**
-   * 
-   * @param id 
-   * @return 
+   * This function determines, wheter the object should be saved to the bytestream (according to its syncfrequency)
+   * @param id gamestate id
+   * @return true/false
    */
   bool Synchronisable::isMyTick(unsigned int id){
@@ -325,4 +366,8 @@
   }
   
+  /**
+   * This function looks at the header located in the bytestream and checks wheter objectID and classID match with the Synchronisables ones
+   * @param mem pointer to the bytestream
+   */
   bool Synchronisable::isMyData(unsigned char* mem)
   {
@@ -339,4 +384,11 @@
   }
   
+  /**
+   * This function sets the synchronisation mode of the object
+   * If set to 0x1 variables will only be synchronised to the client
+   * If set to 0x2 variables will only be synchronised to the server
+   * If set to 0x3 variables will be synchronised bidirectionally (only if set so in registerVar)
+   * @param mode same as in registerVar
+   */
   void Synchronisable::setObjectMode(int mode){
     assert(mode==0x1 || mode==0x2 || mode==0x3);
Index: /code/branches/network/src/network/Synchronisable.h
===================================================================
--- /code/branches/network/src/network/Synchronisable.h	(revision 1792)
+++ /code/branches/network/src/network/Synchronisable.h	(revision 1793)
@@ -39,6 +39,20 @@
 #include "NetworkCallback.h"
 
+#define REGISTERDATA(varname) registerVar(&varname, sizeof(varname), network::DATA)
+#define REGISTERDATA_WITHDIR(varname, mode) registerVar(&varname, sizeof(varname), network::DATA, mode)
+#define REGISTERSTRING(stringname) registerVar(&stringname, stringname.length()+1, network::STRING)
+#define REGISTERSTRING_WITHDIR(stringname, mode) registerVar(&stringname, stringname.length()+1, network::STRING, mode)
+
 namespace network
 {
+  namespace direction{
+    enum syncdirection{
+      toclient=0x1,
+      toserver=0x2,
+      bidirectional=0x3
+    };
+    
+  }
+  
   enum variableType{
     DATA,
@@ -63,6 +77,5 @@
   /**
   * This class is the base class of all the Objects in the universe that need to be synchronised over the network
-   * Every class, t
-  int mode;hat 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.
+   * Every class, that inherits from this class has to link the DATA THAT NEEDS TO BE SYNCHRONISED into the linked list.
   * @author Oliver Scheuss
   */
@@ -74,5 +87,4 @@
     unsigned int classID;
 
-    void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);
     bool getData(unsigned char*& men, unsigned int id, int mode=0x0);
     int getSize(unsigned int id, int mode=0x0);
@@ -95,4 +107,5 @@
   protected:
     Synchronisable();
+    void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);
   private:
     bool isMyTick(unsigned int id);
Index: /code/branches/network/src/network/packet/Chat.cc
===================================================================
--- /code/branches/network/src/network/packet/Chat.cc	(revision 1792)
+++ /code/branches/network/src/network/packet/Chat.cc	(revision 1793)
@@ -29,14 +29,16 @@
 #include "Chat.h"
 #include <assert.h>
+#include "network/Host.h"
 
 namespace network {
 namespace packet {
   
-#define PACKET_FLAGS_CHAT ENET_PACKET_FLAG_RELIABLE
-#define _PACKETID         0
-#define _MESSAGELENGTH    _PACKETID + sizeof(ENUM::Type)
-#define _MESSAGE          _MESSAGELENGTH + sizeof(unsigned int)
+#define   PACKET_FLAGS_CHAT ENET_PACKET_FLAG_RELIABLE
+#define   _PACKETID         0
+const int _PLAYERID     =   _PACKETID + sizeof(ENUM::Type);
+#define   _MESSAGELENGTH    _PLAYERID + sizeof(unsigned int)
+#define   _MESSAGE          _MESSAGELENGTH + sizeof(unsigned int)
 
-Chat::Chat( std::string& message, int clientID )
+Chat::Chat( std::string message, unsigned int playerID )
  : Packet()
 {
@@ -44,8 +46,8 @@
   messageLength_ = message.length()+1;
   data_=new unsigned char[ getSize() ];
-  *(ENUM::Type *)&data_[ _PACKETID ] = ENUM::Chat;
-  *(unsigned int *)&data_[ _MESSAGELENGTH ] = messageLength_;
-  memcpy( &data_[ _MESSAGE ], (void *)message.c_str(), messageLength_ );
-  clientID_=clientID;
+  *(ENUM::Type *)(data_ + _PACKETID ) = ENUM::Chat;
+  *(unsigned int *)(data_ + _PLAYERID ) = playerID;
+  *(unsigned int *)(data_ + _MESSAGELENGTH ) = messageLength_;
+  memcpy( data_+_MESSAGE, (void *)message.c_str(), messageLength_ );
 }
 
@@ -65,12 +67,11 @@
 
 bool Chat::process(){
-  //TODO: change this !!!
-  assert(0);
+  bool b = Host::incomingChat(std::string((const char*)data_+_MESSAGE), *(unsigned int *)(data_+_PLAYERID));
   delete this;
-  return true;
+  return b;
 }
 
 unsigned char *Chat::getMessage(){
-  return &data_[ _MESSAGE ];
+  return data_ + _MESSAGE;
 }
 
Index: /code/branches/network/src/network/packet/Chat.h
===================================================================
--- /code/branches/network/src/network/packet/Chat.h	(revision 1792)
+++ /code/branches/network/src/network/packet/Chat.h	(revision 1793)
@@ -15,5 +15,5 @@
 {
 public:
-  Chat( std::string& message, int clientID );
+  Chat( std::string message, unsigned int playerID );
   Chat( unsigned char* data, int clientID );
   ~Chat();
Index: /code/branches/network/src/orxonox/objects/Model.cc
===================================================================
--- /code/branches/network/src/orxonox/objects/Model.cc	(revision 1792)
+++ /code/branches/network/src/orxonox/objects/Model.cc	(revision 1793)
@@ -86,5 +86,5 @@
       }
       if(this->isExactlyA(Class(Model)))
-        setObjectFrequency(1); //sync all 10 seconds (this only applies to asteroids and other isExactlyA(Model)
+        setObjectFrequency(300); //sync all 10 seconds (this only applies to asteroids and other isExactlyA(Model)'s
       return true;
     }
