Index: branches/network/src/lib/network/message_manager.h
===================================================================
--- branches/network/src/lib/network/message_manager.h	(revision 8070)
+++ branches/network/src/lib/network/message_manager.h	(revision 8096)
@@ -29,5 +29,6 @@
 {
   TESTMESSAGEID = 1,
-  MSGID_DELETESYNCHRONIZEABLE
+  MSGID_DELETESYNCHRONIZEABLE,
+  MSGID_PREFEREDTEAM
 };
 
Index: branches/network/src/lib/network/network_game_manager.cc
===================================================================
--- branches/network/src/lib/network/network_game_manager.cc	(revision 8070)
+++ branches/network/src/lib/network/network_game_manager.cc	(revision 8096)
@@ -59,4 +59,5 @@
   
   MessageManager::getInstance()->registerMessageHandler( MSGID_DELETESYNCHRONIZEABLE, delSynchronizeableHandler, NULL );
+  MessageManager::getInstance()->registerMessageHandler( MSGID_PREFEREDTEAM, preferedTeamHandler, NULL );
   
   this->gameState = 0;
@@ -86,6 +87,6 @@
   
   int team = rules.getTeamForNewUser();
-  ClassID playableClassId = rules.getPlayableClassId( team );
-  std::string playableModel = rules.getPlayableModelFileName( team, playableClassId );
+  ClassID playableClassId = rules.getPlayableClassId( userId, team );
+  std::string playableModel = rules.getPlayableModelFileName( userId, team, playableClassId );
   
   BaseObject * bo = Factory::fabricate( playableClassId );
@@ -180,5 +181,59 @@
 
 
-
-
-
+/**
+ * handler for MSGID_PREFEREDTEAM message
+ * @param messageId 
+ * @param data 
+ * @param dataLength 
+ * @param someData 
+ * @param userId 
+ * @return 
+ */
+bool NetworkGameManager::preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
+{
+  assert( NetworkGameManager::getInstance()->isServer() );
+  
+  int teamId = 0;
+  int len = Converter::byteArrayToInt( data, &teamId );
+  
+  if ( len != dataLength )
+  {
+    PRINTF(2)("Recieved DeleteSynchronizeable message with incorrect size (%d) from client %d!\n", dataLength, userId);
+    return true;
+  }
+  
+  NetworkGameManager::getInstance()->setPreferedTeam( userId, teamId );
+}
+
+void NetworkGameManager::setPreferedTeam( int userId, int teamId )
+{
+  if ( !PlayerStats::getStats( userId ) )
+    return;
+  
+  PlayerStats & stats = *(PlayerStats::getStats( userId ));
+  
+  stats.setPreferedTeamId( teamId );
+  
+}
+
+/**
+ * set prefered team for this host
+ * @param teamId 
+ */
+void NetworkGameManager::prefereTeam( int teamId )
+{
+  if ( isServer() )
+    setPreferedTeam( getHostID(), teamId );
+  else
+  {
+    byte buf[INTSIZE];
+    
+    assert( Converter::intToByteArray( teamId, buf, INTSIZE) == INTSIZE );
+    
+    MessageManager::getInstance()->sendMessage( MSGID_PREFEREDTEAM, buf, INTSIZE, RT_USER, 0, MP_HIGHBANDWIDTH );
+  }
+}
+
+
+
+
Index: branches/network/src/lib/network/network_game_manager.h
===================================================================
--- branches/network/src/lib/network/network_game_manager.h	(revision 8070)
+++ branches/network/src/lib/network/network_game_manager.h	(revision 8096)
@@ -56,4 +56,6 @@
     
     void removeSynchronizeable( int uniqueId );
+    
+    void prefereTeam( int teamId );
 
     inline void setGameState( int gameState ){ this->gameState = gameState; }
@@ -64,4 +66,7 @@
     
     static bool delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
+    static bool preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
+    
+    void setPreferedTeam( int userId, int teamId );
 
     static NetworkGameManager*    singletonRef;
Index: branches/network/src/lib/network/player_stats.cc
===================================================================
--- branches/network/src/lib/network/player_stats.cc	(revision 8070)
+++ branches/network/src/lib/network/player_stats.cc	(revision 8096)
@@ -86,7 +86,4 @@
     
     PRINTF(0)("uniqueID changed %d %d\n", userId, getHostID());
-    
-    if ( userId == getHostID() )
-      State::getPlayer()->setPlayable( getPlayable() );
   }
 }
@@ -100,4 +97,7 @@
 {
   const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS );
+  
+  if ( !list )
+    return NULL;
   
   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
@@ -121,4 +121,10 @@
   const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
   
+  if ( !list )
+  {
+    this->playableUniqueId = uniqueId;
+    return;
+  }
+  
   this->playable = NULL;
   for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
@@ -130,4 +136,7 @@
     }
   }
+  
+  if ( /*this->playable &&*/ userId == getHostID() )
+    State::getPlayer()->setPlayable( this->playable );
   
   this->playableUniqueId = uniqueId;
Index: branches/network/src/lib/network/synchronizeable.cc
===================================================================
--- branches/network/src/lib/network/synchronizeable.cc	(revision 8070)
+++ branches/network/src/lib/network/synchronizeable.cc	(revision 8096)
@@ -108,5 +108,8 @@
 
   for ( SyncVarList::iterator it = syncVarList.begin(); it != syncVarList.end(); it++ )
+  {
+    //PRINTF(0)("SIZE = %d %s\n", (*it)->getSize(), (*it)->getName().c_str());
     neededSize += (*it)->getSize();
+  }
 
   if ( !( neededSize <= maxLength ) )
@@ -183,5 +186,5 @@
                     );
     
-    if ( ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeIter == stateFrom->sizeList.end() )
+    if ( ( sizeIter != stateFrom->sizeList.end() && *sizeIter != (*it)->getSize() ) || ( hasPermission && (*it)->getPriority() >= priorityTH ) || sizeIter == stateFrom->sizeList.end() )
     {
       n = (*it)->writeToBuf( stateTo->data+i, stateTo->dataLength - i );
@@ -209,5 +212,9 @@
   sentStates[userId].push_back( stateTo );
   
-  assert( i == neededSize );
+  if ( i != neededSize )
+  {
+    PRINTF(0)("strange error: (%s) %d != %d\n", this->getClassName(), i, neededSize);
+    assert(false);
+  }
 
   //write diff to data
Index: branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.cc
===================================================================
--- branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.cc	(revision 8070)
+++ branches/network/src/lib/network/synchronizeable_var/synchronizeable_string.cc	(revision 8096)
@@ -48,4 +48,5 @@
   
   assert( res > 0 );
+  assert( res == vPtrIn->length()+INTSIZE );
   
   return res;
