Index: /branches/proxy/src/lib/network/message_manager.cc
===================================================================
--- /branches/proxy/src/lib/network/message_manager.cc	(revision 9503)
+++ /branches/proxy/src/lib/network/message_manager.cc	(revision 9504)
@@ -141,4 +141,5 @@
   int nAcks;
 
+
   assert( i + INTSIZE <= length );
   n = Converter::byteArrayToInt( data + i, &nAcks );
@@ -248,4 +249,6 @@
   return i;
 }
+
+
 
 /**
Index: /branches/proxy/src/lib/network/player_stats.cc
===================================================================
--- /branches/proxy/src/lib/network/player_stats.cc	(revision 9503)
+++ /branches/proxy/src/lib/network/player_stats.cc	(revision 9504)
@@ -105,7 +105,33 @@
   {
     PRINTF(0)("user %s is now known as %s\n", oldNickName.c_str(), nickName.c_str());
-    oldNickName = nickName;
-  }
-}
+    this->oldNickName = nickName;
+  }
+
+  if ( std::find( id.begin(), id.end(), teamId_handle ) != id.end() )
+  {
+    PRINTF(0)("user %s joins team %i\n", this->nickName.c_str(), this->teamId);
+    this->setPreferedTeamIdHandler( this->teamId);
+  }
+
+}
+
+
+/**
+ * handler for setting the prefered team id
+ * @param newTeamId: the new team id
+ */
+void PlayerStats::setPreferedTeamIdHandler( int newTeamId)
+{
+
+  if( this->playable == NULL)
+  {
+    PRINTF(0)("could not set prefered team, since the playable is not yet set\n");
+    return;
+  }
+
+  this->playable->setTeam(newTeamId);
+}
+
+
 
 /**
Index: /branches/proxy/src/lib/network/player_stats.h
===================================================================
--- /branches/proxy/src/lib/network/player_stats.h	(revision 9503)
+++ /branches/proxy/src/lib/network/player_stats.h	(revision 9504)
@@ -30,5 +30,5 @@
 
 //! A class for storing player information
-class PlayerStats : public Synchronizeable 
+class PlayerStats : public Synchronizeable
 {
 
@@ -37,38 +37,39 @@
     PlayerStats( int userId );
     virtual ~PlayerStats();
-    
+
     virtual void varChangeHandler( std::list<int> & id );
-    
+
     static PlayerStats * getStats( int userId );
-    
+
     inline int getUserId(){ return userId; }
-    
+
     inline int getTeamId(){ return teamId; }
     inline void setTeamId( int teamId ){ this->teamId = teamId; }
-    
+
+    void setPreferedTeamIdHandler( int newTeamId);
     inline int getPreferedTeamId(){ return preferedTeamId; }
-    inline void setPreferedTeamId( int preferedTeamId ){ this->preferedTeamId = preferedTeamId; }
-    
+    inline void setPreferedTeamId( int preferedTeamId ) { this->preferedTeamId = preferedTeamId; }
+
     inline int getScore(){ return score; }
     inline void setScore( int score ){ this->score = score; }
-    
+
     inline int getPlayableClassId(){ return playableClassId; }
     void setPlayableClassId( int classId ){ this->playableClassId = classId; };
-    
+
     inline int getPlayableUniqueId(){ return playableUniqueId; }
     void setPlayableUniqueId( int uniqueId );
-    
+
     inline std::string getModelFileName(){ return modelFileName; }
     inline void setModelFileName( std::string filename ){ modelFileName = filename; }
-    
+
     Playable * getPlayable();
-    
+
     inline std::string getNickName(){ return this->nickName; }
     void setNickName( std::string nick );
     static bool changeNickHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
     void shellNick( const std::string&  newNick );
-    
+
     static void deleteAllPlayerStats();
-    
+
     static ScoreList getScoreList();
 
@@ -97,5 +98,5 @@
     int modelFileName_handle;
     int nickName_handler;
-    
+
     void init();
 };
Index: /branches/proxy/src/util/multiplayer_team_deathmatch.cc
===================================================================
--- /branches/proxy/src/util/multiplayer_team_deathmatch.cc	(revision 9503)
+++ /branches/proxy/src/util/multiplayer_team_deathmatch.cc	(revision 9504)
@@ -503,13 +503,15 @@
   playable.loadMD2Texture( playableTexture );
   playable.loadModel( playableModel, playableScale );
-  playable.setTeam(stats.getPreferedTeamId());
   playable.setOwner( userId );
   playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
   playable.setSynchronized( true );
 
-  stats.setTeamId( stats.getPreferedTeamId() );
   stats.setPlayableClassId( playableClassId );
   stats.setPlayableUniqueId( playable.getUniqueID() );
   stats.setModelFileName( playableModel );
+  stats.setTeamId( stats.getPreferedTeamId() );
+
+  playable.setTeam(stats.getPreferedTeamId());
+
 
   this->respawnPlayable( &playable, stats.getPreferedTeamId(), 0.0f );
