Index: branches/network/src/defs/class_id.h
===================================================================
--- branches/network/src/defs/class_id.h	(revision 7983)
+++ branches/network/src/defs/class_id.h	(revision 7984)
@@ -134,5 +134,6 @@
   CL_GAME_WORLD_DATA            =    0x00102000,
   CL_GAME_RULES                 =    0x00104000,
-  CL_MISSION_GOAL               =    0x00105000,
+  CL_NETWORK_GAME_RULES         =    0x00108000,
+  CL_MISSION_GOAL               =    0x00110000,
 
   CL_CAMPAIGN                   =    0x00000101,
@@ -146,6 +147,6 @@
   CL_MOVIE_LOADER               =    0x00000109,
 
-  CL_MULTIPLAYER_TEAM_DEATHMATCH=    0x00104001,
-  CL_SINGLEPLAYER_SHOOTEMUP     =    0x00104002,
+  CL_MULTIPLAYER_TEAM_DEATHMATCH=    0x00000121,
+  CL_SINGLEPLAYER_SHOOTEMUP     =    0x00000122,
 
   CL_KILL_TARGET                =    0x00105001,
Index: branches/network/src/lib/network/message_manager.h
===================================================================
--- branches/network/src/lib/network/message_manager.h	(revision 7983)
+++ branches/network/src/lib/network/message_manager.h	(revision 7984)
@@ -28,6 +28,5 @@
 enum MessageId 
 {
-  TESTMESSAGEID = 1,
-  MSGID_YOU_ARE
+  TESTMESSAGEID = 1
 };
 
Index: branches/network/src/lib/network/network_game_manager.cc
===================================================================
--- branches/network/src/lib/network/network_game_manager.cc	(revision 7983)
+++ branches/network/src/lib/network/network_game_manager.cc	(revision 7984)
@@ -34,4 +34,7 @@
 #include "game_world.h"
 
+#include "game_rules.h"
+#include "network_game_rules.h"
+
 #include "network_game_manager.h"
 
@@ -54,6 +57,4 @@
 
   this->setSynchronized(true);
-  
-  MessageManager::getInstance()->registerMessageHandler( MSGID_YOU_ARE, youAreHandler, NULL );
 }
 
@@ -63,930 +64,52 @@
 NetworkGameManager::~NetworkGameManager()
 {
-#if 0
-  for ( int i = 0; i<outBuffer.size(); i++)
-  {
-    if ( outBuffer[i].buffer )
-      delete outBuffer[i].buffer;
-  }
-#endif
-
-}
-
-#if 0
-int NetworkGameManager::writeBytes(const byte* data, int length, int sender)
-{
-  int i = 0;
-  byte b;
-
-  while ( i<length )
-  {
-    b = data[i++];
-
-    /**************** Commands only processed by servers ****************/
-    if ( isServer() )
-    {
-      if ( b == NET_REQUEST_CREATE )
-      {
-        if ( !handleRequestCreate( i, data, length, sender ) )
-          return i;
-        continue;
-      }
-      else if ( b == NET_REQUEST_REMOVE )
-      {
-        if ( !handleRequestRemove( i, data, length, sender ) )
-          return i;
-        continue;
-      }
-      else if ( b == NET_REQUEST_PNODE_PATH )
-      {
-        if ( !handleRequestPNodePath( i, data, length, sender ) )
-          return i;
-        continue;
-      }
-    }
-    else
-    {
-      /**************** Commands only processed by clients ****************/
-      if ( b == NET_CREATE_ENTITY )
-      {
-        PRINTF(0)("CREATE_ENTITY\n");
-        if ( !handleCreateEntity( i, data, length, sender ) )
-          return i;
-        continue;
-      }
-      else if ( b == NET_REMOVE_ENTITY )
-      {
-        if ( !handleRemoveEntity( i, data, length, sender ) )
-          return i;
-        continue;
-      }
-      else if ( b == NET_CREATE_ENTITY_LIST )
-      {
-        if ( !handleCreateEntityList( i, data, length, sender ) )
-          return i;
-        continue;
-      }
-      else if ( b == NET_REMOVE_ENTITY_LIST )
-      {
-        if ( !handleRemoveEntityList( i, data, length, sender ) )
-          return i;
-        continue;
-      }
-      else if ( b == NET_YOU_ARE_ENTITY )
-      {
-        if ( !handleYouAreEntity( i, data, length, sender ) )
-          return i;
-        continue;
-      }
-    }
-
-    /**************** Commands processed by servers and clients ****************/
-    if ( b == NET_REQUEST_ENTITY_LIST )
-    {
-      sendEntityList( sender );
-      continue;
-    }
-
-
-    PRINTF(1)("Network is asynchronous: couldn't decode the command sent by %i\n", sender);
-    PRINTF(1)("Probably this is because the network protocol has different \n");
-    PRINTF(1)("versions or there occured an error in the sending algorithm\n");
-    PRINTF(1)("Data is not in the right format! i=%d\n", i);
-    return i;
-  }
-
-  return i;
-}
-#endif
-
-#if 0
-int NetworkGameManager::readBytes(byte* data, int maxLength, int * reciever)
-{
-  if ( !isServer() && !hasRequestedWorld )
-  {
-    assert( maxLength >= 1 );
-    data[0] = NET_REQUEST_ENTITY_LIST;
-    hasRequestedWorld = true;
-    return 1;
-  }
-
-  for ( int i = 0; i<outBuffer.size(); i++ )
-  {
-    *reciever = i;
-    if ( outBuffer[i].length>0 )
-    {
-      int nbytes = outBuffer[i].length;
-      outBuffer[i].length = 0;
-
-      if ( nbytes > maxLength )
-      {
-        PRINTF(1)("OutBuffer.length (%d) > (%d) networkStreamBuffer.maxLength\n", nbytes, maxLength);
-        return 0;
-      }
-
-      memcpy(data, outBuffer[i].buffer, nbytes);
-      return nbytes;
-    }
-  }
-
-  return 0;
-}
-#endif
-
-#if 0
-void NetworkGameManager::writeDebug() const
-{
-}
-
-void NetworkGameManager::readDebug() const
-{
-}
-#endif
-
-
-/*!
- * Checks whether this is connected to a server or a client
- * and afterwards creates the needed entity
- * @param classID: The ID of the class of which an entity should be created
- */
-int NetworkGameManager::createEntity( ClassID classID, int owner )
-{
-  if ( this->isServer())
-  {
-    int res = this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner );
-    
-    if ( res < 0 )
-    {
-      PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");
-      return -1;
-    }
-    
-    return res;
-  }
-  else
-  {
-#if 0
-    this->requestCreateEntity( classID );
-#endif
-    return -1;
-  }
 }
 
 
-/*!
- * Checks whether this is connected to a server or a client
- * and afterwards creates the needed entity
- * @param classID: The ID of the class of which an entity should be created
+/**
+ * insert new player into game
+ * @param userId 
+ * @return 
  */
-BaseObject* NetworkGameManager::createEntity(const TiXmlElement* element)
+bool NetworkGameManager::signalNewPlayer( int userId )
 {
-  if ( this->isServer() )
-  {
-    if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 )
-    {
-      PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n");
-      return NULL;
-    }
-
-    BaseObject * b = Factory::fabricate( element );
-
-    if ( !b )
-    {
-      PRINTF(1)("Could not fabricate Object with className %s\n", element->Value() );
-      return NULL;
-    }
-
-
-    if ( b->isA(CL_SYNCHRONIZEABLE) )
-    {
-      Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);
-      s->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
-      s->setOwner( 0 );
-      // all entities created via this function are added automaticaly to the synchronizeable list
-      s->setSynchronized(true);
-      return b;
-    }
-    else
-    {
-      PRINTF(1)("Class %s is not a synchronizeable!\n", b->getClassName() );
-      delete b;
-    }
-
-  }
-  else
-
-  {
-    PRINTF(1)("This node is not a server and cannot create id %x\n", element->Value());
-  }
-  return NULL;
+  assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) );
+  
+  NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules()));
+  
+  int team = rules.getTeamForNewUser();
+  ClassID playableClassId = rules.getPlayableClassId( team );
+  std::string playableModel = rules.getPlayableModelFileName( team, playableClassId );
+  
+  BaseObject * bo = Factory::fabricate( playableClassId );
+  
+  assert( bo->isA( CL_PLAYABLE ) );
+  
+  Playable & playable = *(dynamic_cast<Playable*>(bo));
+  
+  playable.loadModel( playableModel );
+  
+  PlayerStats * stats = rules.getNewPlayerStats( userId );
+  
+  stats->setTeamId( team );
+  stats->setPlayableClassId( playableClassId );
+  stats->setPlayableUniqueId( playable.getUniqueID() );
+  stats->setModelFileName( playableModel );
 }
 
 
-/*!
- * Checks whether this is connected to a server or a client
- * and afterwards removes the specified entity
- * @param uniqueID: The ID of the entity object which should be removed
+/**
+ * remove player from game
+ * @param userID 
+ * @return 
  */
-void NetworkGameManager::removeEntity(int uniqueID)
+bool NetworkGameManager::signalLeftPlayer(int userID)
 {
-  if ( this->isServer() )
-  {
-    this->executeRemoveEntity( uniqueID );
-  }
-  else
-  {
-#if 0
-    this->requestRemoveEntity( uniqueID );
-#endif
-  }
-}
-
-
-#if 0
-/*!
- * Creates the needed entity on the server if possible
- * @param classID: The ID of the class of which an entity should be created
- */
-void NetworkGameManager::requestCreateEntity(ClassID classID)
-{
-  for ( int i = 0; i<outBuffer.size(); i++)
-  {
-    if ( !this->networkStream->isUserIdActive( i ) )
-      continue;
-
-    if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REQUEST_CREATE ) )
-      return;
-    if ( !writeToClientBuffer( outBuffer[i], (int)classID ) )
-      return;
-  }
-}
-#endif
-
-#if 0
-/*!
- * Removes the specified entity on the server
- * @param uniqueID: The ID of the entity object which should be removed
- */
-void NetworkGameManager::requestRemoveEntity(int uniqueID)
-{
-  for ( int i = 0; i<outBuffer.size(); i++)
-  {
-    if ( !this->networkStream->isUserIdActive( i ) )
-      continue;
-
-    if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REQUEST_REMOVE ) )
-      return;
-    if ( !writeToClientBuffer( outBuffer[i], uniqueID ) )
-      return;
-  }
-}
-#endif
-
-/*!
- * Creates the needed entity if possible
- * This function is called if this is a server
- * @param classID: The ID of the class of which an entity should be created
- */
-int NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner)
-{
-#if 0
-  for ( int i = 0; i<outBuffer.size(); i++)
-  {
-    if ( !this->networkStream->isUserIdActive( i ) )
-      continue;
-
-    if ( !writeToClientBuffer( outBuffer[i], (byte)NET_CREATE_ENTITY ) )
-      return -1;
-    if ( !writeToClientBuffer( outBuffer[i], (int)classID ) )
-      return -1;
-    if ( !writeToClientBuffer( outBuffer[i], uniqueID ) )
-      return -1;
-    if ( !writeToClientBuffer( outBuffer[i], owner ) )
-      return -1;
-  }
-#endif
-  PRINTF(0)("ExecuteCreateEntity: server side: classID: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner);
-  doCreateEntity( classID, uniqueID, owner );
-
-  return uniqueID;
-}
-
-/*!
- * Removes the specified entity
- * This function is called if this is a server
- * @param uniqueID: The ID of the entity object which should be removed
- */
-void NetworkGameManager::executeRemoveEntity(int uniqueID)
-{
-#if 0
-  for ( int i = 0; i<outBuffer.size(); i++)
-  {
-    if ( !this->networkStream->isUserIdActive( i ) )
-      continue;
-
-    if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REMOVE_ENTITY ) )
-      return;
-    if ( !writeToClientBuffer( outBuffer[i], uniqueID ) )
-      return;
-  }
-#endif
-
-  doRemoveEntity(uniqueID);
-}
-
-/*!
- * Checks whether it is possible to create an entity of a given class
- * @return: true if the entity can be created, false otherwise
- */
-bool NetworkGameManager::canCreateEntity(ClassID classID)
-{
-  return true;
-}
-
-#if 0
-/*!
- * Sends the Entities to the new connected client
- * @param userID: The ID of the user
- */
-void NetworkGameManager::sendEntityList( int userID )
-{
-  if ( !isServer() )
-    return;
-
-  if ( userID >= outBuffer.size() )
-    resizeBufferVector( userID );
-
-  SynchronizeableList::const_iterator it, e;
-
-  it = this->networkStream->getSyncBegin();
-  e = this->networkStream->getSyncEnd();
-
-  // send the packet header
-  if ( !writeToClientBuffer( outBuffer[userID], (byte)NET_CREATE_ENTITY_LIST ) )
-    return;
-
-  // send the number of entities: -2 because you must not send network_game_manager and handshake
-  if ( !writeToClientBuffer( outBuffer[userID], networkStream->getSyncCount() ) )
-    return;
-
-  //PRINTF(0)("SendEntityList: n = %d\n", networkStream->getSyncCount()-2 );
-
-  // first send the NullParent
-  if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getLeafClassID()) )
-    return;
-  if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getUniqueID()) )
-    return;
-  if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getOwner()) )
-    return;
-
-  // now send the rest of the entities
-  while ( it != e )
-  {
-    if( (*it)->beSynchronized() && (*it) != PNode::getNullParent())
-    {
-      PRINTF(0)("SENDING ENTITY %s classid: %x, uniqueid %d\n", (*it)->getClassName(), (*it)->getLeafClassID(), (*it)->getUniqueID() );
-      if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) )
-        return;
-
-      if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getUniqueID()) ) )
-        return;
-
-      if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getOwner()) ) )
-        return;
-    }
-    it++;
-  }
-
-  signalNewPlayer( userID );
-}
-#endif
-
-
-
-bool NetworkGameManager::signalNewPlayer(int userId)
-{
-  /* create new playable for Player*/
-  PRINTF(0)("Request for creation: %i\n", userId);
-  int uniqueId = this->createEntity(CL_SPACE_SHIP, userId);
-  PRINTF(0)("Request for creation: userid: %i, uniqueid: %i\n", userId, uniqueId);
-  this->sendYouAre(uniqueId, userId);
 }
 
 
 
-bool NetworkGameManager::signalLeftPlayer(int userID)
-{
-  const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE);
-  
-  if ( !playableList )
-    return false;
-  
-  std::list<BaseObject*>::const_iterator it = playableList->begin();
-
-  for(; it != playableList->end(); it++)
-  {
-    if( dynamic_cast<Synchronizeable*>(*it)->getOwner() == userID )
-    {
-      PRINTF(0)("remove playable from %i\n", userID);
-      this->removeEntity(dynamic_cast<Synchronizeable*>(*it)->getUniqueID());
-      return true;
-    }
-  }
-  return false;
-}
-
-#if 0
-/**
- * Creates a buffer for user n
- * @param n The ID of the user
- */
-void NetworkGameManager::resizeBufferVector( int n )
-{
-  for ( int i = outBuffer.size(); i<=n; i++)
-  {
-    clientBuffer outBuf;
-
-    outBuf.length = 0;
-
-    outBuf.maxLength = 5*1024;
-
-    outBuf.buffer = new byte[5*1014];
-
-    outBuffer.push_back(outBuf);
-  }
-}
-#endif
-
-/**
- * Creates the entity on this host
- * @param classID: ClassID of the entity to create
- * @param uniqueID: Unique ID to assign to the synchronizeable
- * @param owner: owner of this synchronizealbe
- */
-BaseObject* NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner )
-{
-  PRINTF(0)("Creating Entity via Factory: classid: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner);
-
-  BaseObject * b;
-  /* These are some small exeptions in creation: Not all objects can/should be created via Factory */
-  /* Exception 1: NullParent */
-  if( classID == CL_NULL_PARENT)
-  {
-    b = (BaseObject*)PNode::getNullParent();
-  }
-  else
-    b = Factory::fabricate( classID );
-
-  if ( !b )
-  {
-    PRINTF(1)("Could not fabricate Object with classID %x\n", classID);
-    return NULL;
-  }
-
-  if ( b->isA(CL_SYNCHRONIZEABLE) )
-  {
-    Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);
-    s->setUniqueID( uniqueID );
-    s->setOwner( owner );
-    s->setSynchronized(true);
-    //this->networkStream->connectSynchronizeable( *s );
-
-    PRINTF(0)("Fabricated %s with id %d\n", s->getClassName(), s->getUniqueID());
-
-    //TODO HACK: hack to prevent collision
-    if ( b->isA(CL_WORLD_ENTITY) && !b->isA(CL_PLAYABLE) )
-    {
-      if ( SharedNetworkData::getInstance()->getHostID()!=0 )
-      {
-        static Vector pos = Vector(1000.0, 1000.0, 1000.0);
-        PNode *p = dynamic_cast<PNode*>(b);
-        p->setAbsCoor(pos);
-        p->updateNode(0);
-        pos += Vector(1000.0, 1000.0, 1000.0);
-      }
-    }
-    ///TODO HACK this is only for network multiplayer games.
-    if( b->isA(CL_PLAYABLE))
-    {
-      Playable* ss = dynamic_cast<Playable*>(b);
-      if( owner%2 == 0)
-      {
-
-        ss->loadModel("models/ships/reap_0.obj");
-        ss->toList(OM_GROUP_00);
-        ss->setAbsCoor(213.37, 57.71, -47.98);
-        ss->setAbsDir(Quaternion(0.16, 0.98, -0.10));
-      }
-      else
-      {
-        ss->loadModel( "models/ships/fighter.obj" );
-        ss->toList(OM_GROUP_01);
-        ss->setAbsCoor(-314.450, 40.701, 83.554);
-      }
-    }
-
-    return b;
-  }
-  else
-  {
-    PRINTF(1)("Class with ID %x is not a synchronizeable!", (int)classID);
-    delete b;
-  }
-  return NULL;
-}
-
-/**
- * Removes a entity on this host
- * @param uniqueID: unique ID assigned with the entity to remove
- */
-void NetworkGameManager::doRemoveEntity( int uniqueID )
-{
-  SynchronizeableList::const_iterator it,e;
-  it = this->networkStream->getSyncBegin();
-  e = this->networkStream->getSyncEnd();
-
-  while ( it != e )
-  {
-    if ( (*it)->getUniqueID() == uniqueID )
-    {
-      assert((*it)->isA(CL_WORLD_ENTITY));
-      dynamic_cast<WorldEntity*>(*it)->leaveWorld();
-      dynamic_cast<WorldEntity*>(*it)->toList(OM_DEAD);
-      break;
-    }
-    it++;
-  }
-}
-
-#if 0
-/**
- * Copies length bytes to the clientBuffer with error checking
- * @param clientBuffer: the clientBuffer to write to
- * @param data: buffer to the data
- * @param length: length of data
- * @return false on error true else
- */
-bool NetworkGameManager::writeToClientBuffer( clientBuffer &cb, byte * data, int length )
-{
-  if ( length > cb.maxLength-cb.length )
-  {
-    PRINTF(1)("No space left in clientBuffer\n");
-    return false;
-  }
-
-  memcpy( cb.buffer+cb.length, data, length );
-  return true;
-}
-#endif
-
-#if 0
-/**
- * Reads data from clientBuffer with error checking
- * @param clientBuffer: the clientBuffer to read from
- * @param data: pointer to the buffer
- * @param length:
- * @return
- */
-bool NetworkGameManager::readFromClientBuffer( clientBuffer &cb, byte * data, int length )
-{
-  if ( cb.length < length )
-  {
-    PRINTF(0)("There is not enough data in clientBuffer\n");
-    return 0;
-  }
-
-  memcpy( data, cb.buffer+cb.length-length, length );
-  return true;
-}
-#endif
-
-/**
- * Tells this client that he has to control this entity
- * @param uniqueID: the entity's uniqeID
- */
-void NetworkGameManager::doYouAre( int uniqueID )
-{
-
-  SynchronizeableList::const_iterator it = this->networkStream->getSyncBegin();
-
-  Playable *p = NULL;
-  Synchronizeable *s = NULL;
-
-  for ( ; it !=networkStream->getSyncEnd(); it++ )
-  {
-    if ( (*it)->getUniqueID()==uniqueID )
-    {
-      if ( (*it)->isA( CL_SYNCHRONIZEABLE ) )
-      {
-        s = dynamic_cast<Synchronizeable*>(*it);
-      }
-      if ( (*it)->isA( CL_PLAYABLE ) )
-      {
-        p = dynamic_cast<Playable*>(*it);
-        break;
-      } else
-      {
-        PRINTF(1)("UniqueID %d is not a Playable\n", uniqueID);
-      }
-    }
-  }
-
-  Player* player = State::getPlayer();
-  assert(p != NULL);
-  assert(s != NULL);
-  assert(player != NULL);
-
-  PRINTF(0)("uniqueID = %d\n", s->getUniqueID());
-
-  player->setPlayable(p);
 
 
-}
-
-/**
- * Tells a remote client that he has to control this entity
- * @param uniqueID: the entity's uniqeID
- * @param userID: the users ID
- */
-void NetworkGameManager::sendYouAre( int uniqueID, int userID )
-{
-  if ( !isServer() )
-    return;
-  
-  byte buf[INTSIZE];
-  
-  Converter::intToByteArray( uniqueID, buf, INTSIZE );
-  
-  MessageManager::getInstance()->sendMessage( MSGID_YOU_ARE, buf, INTSIZE, RT_USER, userID, MP_HIGHBANDWIDTH);
-}
-
-bool NetworkGameManager::handleRequestCreate( int & i, const byte * data, int length, int sender )
-{
-  if ( INTSIZE > length-i )
-  {
-    PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n");
-    return false;
-  }
-  int classID;
-  i += Converter::byteArrayToInt( &data[i], &classID );
-
-  createEntity( (ClassID)classID );
-
-  return true;
-}
-
-bool NetworkGameManager::handleRequestRemove( int & i, const byte * data, int length, int sender )
-{
-  if ( INTSIZE > length-i )
-  {
-    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
-    return false;
-  }
-  int uniqueID;
-  i += Converter::byteArrayToInt( &data[i], &uniqueID );
-
-  removeEntity( uniqueID );
-
-  return true;
-}
-
-bool NetworkGameManager::handleCreateEntity( int & i, const byte * data, int length, int sender )
-{
-  if ( INTSIZE > length-i )
-  {
-    PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n");
-    return false;
-  }
-  int classID;
-  i += Converter::byteArrayToInt( &data[i], &classID );
-
-  if ( INTSIZE > length-i )
-  {
-    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
-    return false;
-  }
-  int uniqueID;
-  i += Converter::byteArrayToInt( &data[i], &uniqueID );
-
-  if ( INTSIZE > length-i )
-  {
-    PRINTF(1)("Cannot read owner from buffer! Not enough data left!\n");
-    return false;
-  }
-  int owner;
-  i += Converter::byteArrayToInt( &data[i], &owner );
-
-  PRINTF(0)("handleCreateEntity: client side: classID: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner);
-  doCreateEntity( (ClassID)classID, uniqueID, owner );
-
-  return true;
-}
-
-bool NetworkGameManager::handleRemoveEntity( int & i, const byte * data, int length, int sender )
-{
-  if ( INTSIZE > length-i )
-  {
-    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
-    return false;
-  }
-  int uniqueID;
-  i += Converter::byteArrayToInt( &data[i], &uniqueID );
-
-  doRemoveEntity( uniqueID );
-
-  return true;
-}
-
-bool NetworkGameManager::handleCreateEntityList( int & i, const byte * data, int length, int sender )
-{
-  if ( INTSIZE > length-i )
-  {
-    PRINTF(1)("Cannot read n from buffer! Not enough data left!\n");
-    return false;
-  }
-
-  PRINTF(0)("HandleCreateEntityList:  data[i..i+3] = %d %d %d %d\n", data[i], data[i+1], data[i+2], data[i+3]);
-
-  int n;
-  i += Converter::byteArrayToInt( &data[i], &n );
 
 
-  PRINTF(0)("HandleCreateEntityList: n = %d\n", n);
-
-  int classID, uniqueID, owner;
-
-  for ( int j = 0; j<n; j++ )
-  {
-
-    if ( INTSIZE > length-i )
-    {
-      PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n");
-      return false;
-    }
-    i += Converter::byteArrayToInt( &data[i], &classID );
-
-    if ( INTSIZE > length-i )
-    {
-      PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
-      return false;
-    }
-    i += Converter::byteArrayToInt( &data[i], &uniqueID );
-
-    if ( INTSIZE > length-i )
-    {
-      PRINTF(1)("Cannot read owner from buffer! Not enough data left!\n");
-      return false;
-    }
-    i += Converter::byteArrayToInt( &data[i], &owner );
-
-    if ( classID != CL_NETWORK_GAME_MANAGER && classID != CL_HANDSHAKE )
-    {
-      BaseObject* b = doCreateEntity( (ClassID)classID, uniqueID, owner );
-    }
-
-  }
-
-  return true;
-}
-
-bool NetworkGameManager::handleRemoveEntityList( int & i, const byte * data, int length, int sender )
-{
-  if ( INTSIZE > length-i )
-  {
-    PRINTF(1)("Cannot read n from buffer! Not enough data left!\n");
-    return false;
-  }
-  int n;
-  i += Converter::byteArrayToInt( &data[i], &n );
-
-  int uniqueID;
-
-  for ( int j = 0; j<n; j++ )
-  {
-
-    if ( INTSIZE > length-i )
-    {
-      PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
-      return false;
-    }
-    i += Converter::byteArrayToInt( &data[i], &uniqueID );
-
-    doRemoveEntity( uniqueID );
-  }
-
-  return true;
-}
-
-bool NetworkGameManager::handleYouAreEntity( int & i, const byte * data, int length, int sender )
-{
-  if ( INTSIZE > length-i )
-  {
-    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
-    return false;
-  }
-
-  int uniqueID;
-  i += Converter::byteArrayToInt( &data[i], &uniqueID );
-
-  doYouAre( uniqueID );
-
-  return true;
-}
-
-/**
- *  handles the network signal NET_REQUEST_PNODE_PATH
- * @param i byte offset in the buffer
- * @param data data array
- * @param length length of the data arary
- * @param sender the sender id
- * @return true if process terminated sucessfully
- */
-bool NetworkGameManager::handleRequestPNodePath(int& i, const byte* data, int length, int sender)
-{
-  if( INTSIZE > length-i )
-  {
-    PRINTF(1)("Cannot read n from buffer! Not enough data left!\n");
-    return false;
-  }
-  PRINTF(0)("HandleRequestPNodePath:  data[i..i+3] = %d %d %d %d\n", data[i], data[i+1], data[i+2], data[i+3]);
-
-  int uniqueID1, uniqueID2;
-  if( INTSIZE > length-i )
-  {
-    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
-    return false;
-  }
-  i += Converter::byteArrayToInt( &data[i], &uniqueID1 );
-
-  if( INTSIZE > length-i )
-  {
-    PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n");
-    return false;
-  }
-  i += Converter::byteArrayToInt( &data[i], &uniqueID2 );
-
-
-  PRINTF(0)("HandleRequestPNodePath: got a request for path from uid %i to uid %i\n", uniqueID1, uniqueID2);
-
-  return true;
-}
-
-bool NetworkGameManager::youAreHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
-{
-  assert( dataLength == INTSIZE );
-  int uniqueId;
-  
-  Converter::byteArrayToInt( data, &uniqueId );
-  
-  SynchronizeableList::const_iterator it = NetworkGameManager::getInstance()->networkStream->getSyncBegin();
-
-  Playable *p = NULL;
-  Synchronizeable *s = NULL;
-
-  for ( ; it !=NetworkGameManager::getInstance()->networkStream->getSyncEnd(); it++ )
-  {
-    if ( (*it)->getUniqueID()==uniqueId )
-    {
-      break;
-    }
-  }
-  
-  if ( it == NetworkGameManager::getInstance()->networkStream->getSyncEnd() )
-    return false;
-  
-  NetworkGameManager::getInstance()->doYouAre( uniqueId );
-  
-  return true;
-}
-
-#if 0
-bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, byte b )
-{
-  if ( cb.maxLength-cb.length < 1 )
-  {
-    PRINTF(1)("Cannot write to clientBuffer! Not enough space for 1 byte\n");
-    return false;
-  }
-
-  cb.buffer[cb.length++] = b;
-
-  return true;
-}
-
-
-bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, int i )
-{
-  int n = Converter::intToByteArray( i, cb.buffer+cb.length, cb.maxLength-cb.length );
-  cb.length += n;
-
-  if ( n <= 0 )
-  {
-    PRINTF(1)("Cannot write to clientBuffer! Not enough space for 1 int\n");
-    return false;
-  }
-
-  return true;
-}
-#endif
-
-
Index: branches/network/src/lib/network/network_game_manager.h
===================================================================
--- branches/network/src/lib/network/network_game_manager.h	(revision 7983)
+++ branches/network/src/lib/network/network_game_manager.h	(revision 7984)
@@ -51,19 +51,4 @@
     { if (!NetworkGameManager::singletonRef) NetworkGameManager::singletonRef = new NetworkGameManager(); return NetworkGameManager::singletonRef; }
 
-#if 0
-    virtual int writeBytes(const byte* data, int length, int sender);
-    virtual int readBytes(byte* data, int maxLength, int * reciever);
-    virtual void writeDebug() const;
-    virtual void readDebug() const;
-#endif
-
-    int createEntity( ClassID classID, int owner = 0 );
-    BaseObject* createEntity(const TiXmlElement* element);
-    void removeEntity( int uniqueID );
-    void sendYouAre( int uniqueID, int userID );
-
-#if 0
-    void sendEntityList(int userID);
-#endif
 
     bool signalNewPlayer(int userId);
@@ -76,48 +61,4 @@
     static bool youAreHandler(MessageId messageId, byte * data, int dataLength, void * someData, int userId );
 
-
-    /* some network signal handlers */
-    bool handleRequestCreate( int& i, const byte* data, int length, int sender );
-    bool handleRequestRemove( int& i, const byte* data, int length, int sender );
-    bool handleCreateEntity( int& i, const byte* data, int length, int sender );
-    bool handleRemoveEntity( int& i, const byte* data, int length, int sender );
-    bool handleCreateEntityList( int& i, const byte* data, int length, int sender );
-    bool handleRemoveEntityList( int& i, const byte* data, int length, int sender );
-    bool handleYouAreEntity( int& i, const byte* data, int length, int sender );
-    bool handleRequestPNodePath(int& i, const byte* data, int length, int sender);
-    bool handleSendPNodePath(int& i, const byte* data, int length, int sender);
-
-
-    /* some network handlers helper functions */
-//    void requestCreateEntity(ClassID classID);
-    int executeCreateEntity(ClassID classID, int uniqueID = 0, int owner = 0);
-    BaseObject* doCreateEntity(ClassID classID, int uniqueID, int owner);
-
-//    void requestRemoveEntity(int uniqueID);
-    void executeRemoveEntity(int uniqueID);
-    void doRemoveEntity(int uniqueID);
-
-    void doYouAre( int uniqueID );
-
-//    void requestPNodePath(const PNode* node1, const PNode* node2);
-    void executeRequestPNodePath(const PNode* node2, const PNode* node2);
-    void doRequestPNodePath(const PNode* node1, const PNode* node2);
-
-    bool canCreateEntity(ClassID classID);
-#if 0
-    void resizeBufferVector(int n);
-
-
-    bool writeToClientBuffer( clientBuffer &cb, byte*data, int length );
-    bool writeToClientBuffer( clientBuffer &cb, byte b );
-    bool writeToClientBuffer( clientBuffer &cb, int i );
-    bool readFromClientBuffer( clientBuffer &cb, byte*data, int length );
-#endif
-
-  private:
-#if 0
-    std::vector<clientBuffer>     outBuffer;
-    //clientBuffer                  allOutBuffer;
-#endif
     static NetworkGameManager*    singletonRef;
 };
Index: branches/network/src/lib/network/network_stream.cc
===================================================================
--- branches/network/src/lib/network/network_stream.cc	(revision 7983)
+++ branches/network/src/lib/network/network_stream.cc	(revision 7984)
@@ -279,5 +279,5 @@
       PRINTF(0)("Client is gone: %d (%s)\n", it->second.userId, reason.c_str());
       
-      assert(false);
+      //assert(false);
 
       it->second.socket->disconnectServer();
Index: branches/network/src/lib/network/player_stats.cc
===================================================================
--- branches/network/src/lib/network/player_stats.cc	(revision 7983)
+++ branches/network/src/lib/network/player_stats.cc	(revision 7984)
@@ -18,4 +18,7 @@
 #include "class_list.h"
 #include "src/lib/util/loading/factory.h"
+
+#include "player.h"
+#include "state.h"
 
 
@@ -45,5 +48,5 @@
 
   this->userId = 0;
-  this->groupId = 0;
+  this->teamId = 0;
   this->score = 0;
   this->playableClassId = 0;
@@ -51,5 +54,5 @@
   
   userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) );
-  groupId_handle = registerVarId( new SynchronizeableInt( &groupId, &groupId, "groupId" ) );
+  groupId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
   score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score" ) );
   playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId") );
@@ -77,4 +80,7 @@
   {
     this->setPlayableUniqueId( this->playableUniqueId );
+    
+    if ( userId == getHostID() )
+      State::getPlayer()->setPlayable( getPlayable() );
   }
 }
Index: branches/network/src/lib/network/player_stats.h
===================================================================
--- branches/network/src/lib/network/player_stats.h	(revision 7983)
+++ branches/network/src/lib/network/player_stats.h	(revision 7984)
@@ -28,6 +28,6 @@
     inline int getUserId(){ return userId; }
     
-    inline int getGroupId(){ return groupId; }
-    inline void setGroupId( int groupId ){ this->groupId = groupId; }
+    inline int getTeamId(){ return teamId; }
+    inline void setTeamId( int teamId ){ this->teamId = teamId; }
     
     inline int getScore(){ return score; }
@@ -47,5 +47,5 @@
   private:
     int userId;                //!< userId
-    int groupId;               //!< groupId
+    int teamId;                //!< teamId
 
     int score;                 //!< users score points
Index: branches/network/src/story_entities/multi_player_world_data.cc
===================================================================
--- branches/network/src/story_entities/multi_player_world_data.cc	(revision 7983)
+++ branches/network/src/story_entities/multi_player_world_data.cc	(revision 7984)
@@ -146,5 +146,5 @@
       {
         /* pass the entity to the NetworkGameManager to be created */
-        BaseObject* created = NetworkGameManager::getInstance()->createEntity(element);
+        BaseObject* created = Factory::fabricate(element);
         if( created != NULL )
           PRINTF(1)("Created a %s: %s (0x%8x) from %s\n", created->getClassName(), created->getName(), created->getLeafClassID(), element->Value());
Index: branches/network/src/util/Makefile.am
===================================================================
--- branches/network/src/util/Makefile.am	(revision 7983)
+++ branches/network/src/util/Makefile.am	(revision 7984)
@@ -10,4 +10,5 @@
 			\
 			game_rules.cc \
+			network_game_rules.cc \
 			multiplayer_team_deathmatch.cc \
 			singleplayer_shootemup.cc \
@@ -34,4 +35,5 @@
 			\
 			game_rules.h \
+			network_game_rules.h \
 			multiplayer_team_deathmatch.h \
 			singleplayer_shootemup.h \
Index: branches/network/src/util/multiplayer_team_deathmatch.cc
===================================================================
--- branches/network/src/util/multiplayer_team_deathmatch.cc	(revision 7983)
+++ branches/network/src/util/multiplayer_team_deathmatch.cc	(revision 7984)
@@ -45,5 +45,5 @@
  */
 MultiplayerTeamDeathmatch::MultiplayerTeamDeathmatch(const TiXmlElement* root)
-  : GameRules(root)
+  : NetworkGameRules(root)
 {
   this->setClassID(CL_MULTIPLAYER_TEAM_DEATHMATCH, "MultiplayerTeamDeathmatch");
Index: branches/network/src/util/multiplayer_team_deathmatch.h
===================================================================
--- branches/network/src/util/multiplayer_team_deathmatch.h	(revision 7983)
+++ branches/network/src/util/multiplayer_team_deathmatch.h	(revision 7984)
@@ -10,5 +10,5 @@
 #define _MULTIPLAYER_TEAM_DEATHMATCH_H
 
-#include "game_rules.h"
+#include "network_game_rules.h"
 
 
@@ -19,5 +19,5 @@
 
 
-class MultiplayerTeamDeathmatch : public GameRules
+class MultiplayerTeamDeathmatch : public NetworkGameRules
 {
 
