Index: branches/network/src/lib/network/network_stream.cc
===================================================================
--- branches/network/src/lib/network/network_stream.cc	(revision 8185)
+++ branches/network/src/lib/network/network_stream.cc	(revision 8187)
@@ -105,4 +105,5 @@
     serverSocket->close();
     delete serverSocket;
+    serverSocket = NULL;
   }
 
@@ -123,10 +124,6 @@
   }
   
-  if ( serverSocket )
-  {
-    delete serverSocket;
-    serverSocket = NULL;
-  }
-
+  for ( SynchronizeableList::const_iterator it = getSyncBegin(); it != getSyncEnd(); it ++ )
+    (*it)->setNetworkStream( NULL );
 }
 
Index: branches/network/src/lib/network/player_stats.cc
===================================================================
--- branches/network/src/lib/network/player_stats.cc	(revision 8185)
+++ branches/network/src/lib/network/player_stats.cc	(revision 8187)
@@ -62,7 +62,4 @@
   playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );
   modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
-  playerName_handle = registerVarId( new SynchronizeableString( &playerName, &playerName, "playerName" ) );
-  
-  MessageManager::getInstance()->registerMessageHandler( MSGID_CHANGEPLAYERNAME, changePlayernameHandler, NULL );
   
   PRINTF(0)("PlayerStats created\n");
@@ -167,41 +164,3 @@
 }
 
-bool PlayerStats::changePlayernameHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
-{
-  if ( !SharedNetworkData::getInstance()->isGameServer() )
-    return true;
-  
-  if ( Converter::byteArrayToString( data, getStats(userId)->playerName, dataLength ) != dataLength );
-  {
-    PRINTF(1)("recieved invalid message from user %d\n", userId);
-    // TODO give user a name
-    getStats( userId )->playerName = "invalid name";
-  }
-  
-  return true;
-}
 
-std::string PlayerStats::setPlayerName( std::string name )
-{
-  if ( isServer() )
-  {
-    this->playerName = name;
-  }
-  else
-  {
-    if ( userId == getHostID() )
-    {
-      byte * data = new byte[INTSIZE+playerName.length()];
-      
-      assert( Converter::stringToByteArray( playerName, data, INTSIZE+playerName.length() ) == INTSIZE+playerName.length() );
-      
-      MessageManager::getInstance()->sendMessage( MSGID_CHANGEPLAYERNAME, data, INTSIZE+playerName.length(), RT_SERVER, 0, MP_HIGHBANDWIDTH );
-    }
-    else
-    {
-      PRINTF(1)("Clients cannot set PlayerNames of other hosts!\n");
-    }
-  }
-}
-
-
Index: branches/network/src/lib/network/player_stats.h
===================================================================
--- branches/network/src/lib/network/player_stats.h	(revision 8185)
+++ branches/network/src/lib/network/player_stats.h	(revision 8187)
@@ -1,91 +1,166 @@
-/*!
- * @file player_stats.h
- * @brief Definition of PlayerStats
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   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, or (at your option)
+   any later version.
+
+### File Specific:
+   main-programmer: Christoph Renner
+   co-programmer: ...
+*/
+
+#include "player_stats.h"
+
+#include "class_list.h"
+#include "src/lib/util/loading/factory.h"
+
+#include "player.h"
+#include "state.h"
+#include "shared_network_data.h"
+
+
+CREATE_FACTORY(PlayerStats, CL_PLAYER_STATS);
+
+/**
+ * constructor
  */
+PlayerStats::PlayerStats( int userId )
+{
+  init();
+  
+  this->userId = userId;
+}
 
-#ifndef _PLAYER_STATS_H
-#define _PLAYER_STATS_H
+/**
+ * constructor
+ */
+PlayerStats::PlayerStats( const TiXmlElement* root )
+{
+  init();
+}
 
-#include "synchronizeable.h"
-#include "playable.h"
-#include "message_manager.h"
+void PlayerStats::init( )
+{
+  this->setClassID( CL_PLAYER_STATS, "PlayerStats" );
 
-#include <string>
-#include <list>
+  this->userId = 0;
+  this->teamId = TEAM_NOTEAM;
+  this->preferedTeamId = TEAM_NOTEAM;
+  this->score = 0;
+  this->playableClassId = 0;
+  this->modelFileName = "";
+  
+  userId_handle = registerVarId( new SynchronizeableInt( &userId, &userId, "userId" ) );
+  teamId_handle = registerVarId( new SynchronizeableInt( &teamId, &teamId, "teamId" ) );
+  preferedTeamId_handle = registerVarId( new SynchronizeableInt( &preferedTeamId, &preferedTeamId, "preferedUserId" ) );
+  score_handle = registerVarId( new SynchronizeableInt( &score, &score, "score" ) );
+  playableClassId_handle = registerVarId( new SynchronizeableInt( &playableClassId, &playableClassId, "playableClassId") );
+  playableUniqueId_handle = registerVarId( new SynchronizeableInt( &playableUniqueId, &playableUniqueId, "playableUniqueId" ) );
+  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
+  
+  PRINTF(0)("PlayerStats created\n");
+}
 
-enum
+
+/**
+ * standard deconstructor
+ */
+PlayerStats::~PlayerStats()
 {
-  TEAM_NOTEAM = -3,
-  TEAM_RANDOM = -2,
-  TEAM_SPECTATOR = -1
-};
+}
 
-//! A class for storing player information
-class PlayerStats : public Synchronizeable 
+
+ /**
+ * override this function to be notified on change
+ * of your registred variables.
+ * @param id id's which have changed
+  */
+void PlayerStats::varChangeHandler( std::list< int > & id )
 {
+  if ( std::find( id.begin(), id.end(), playableUniqueId_handle ) != id.end() )
+  {
+    this->setPlayableUniqueId( this->playableUniqueId );
+    
+    PRINTF(0)("uniqueID changed %d %d %d\n", userId, getHostID(), getUniqueID());
+  }
+}
 
-  public:
-    PlayerStats( const TiXmlElement* root = NULL );
-    PlayerStats( int userId );
-    virtual ~PlayerStats();
-    
-    virtual void varChangeHandler( std::list<int> & id );
-    
-    static PlayerStats * getStats( int userId );
-    
-    inline int getUserId(){ return userId; }
-    
-    inline std::string getPlayerName(){ return playerName; }
-    inline std::string setPlayerName( std::string name );
-    
-    inline int getTeamId(){ return teamId; }
-    inline void setTeamId( int teamId ){ this->teamId = teamId; }
-    
-    inline int getPreferedTeamId(){ return 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();
-    
-    static bool changePlayernameHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId );
+/**
+ * get stats for user userId
+ * @param userId user's id
+ * @return stats assigned to user
+ */
+PlayerStats * PlayerStats::getStats( int userId )
+{
+  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++ )
+  {
+    if ( dynamic_cast<PlayerStats*>(*it)->getUserId() == userId )
+    {
+      return dynamic_cast<PlayerStats*>(*it);
+    }
+  }
+  
+  return NULL;
+}
 
-  private:
-    int userId;                //!< userId
+/**
+ * set playable class id and set playable
+ */
+void PlayerStats::setPlayableUniqueId( int uniqueId )
+{
+  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++ )
+  {
+    if ( dynamic_cast<Playable*>(*it)->getUniqueID() == uniqueId )
+    {
+      this->playable = dynamic_cast<Playable*>(*it);
+      break;
+    }
+  }
+  
+  if ( this->playable && userId == getHostID() )
+  {
+    State::getPlayer()->setPlayable( this->playable );
+  }
+  
+  this->playableUniqueId = uniqueId;
+}
 
-    std::string playerName;    //!< playername
+/**
+ * get playable associated to player
+ * @return playable associated to player
+ */
+Playable * PlayerStats::getPlayable()
+{
+  if ( playable )
+    return playable;
+  
+  assert( playableUniqueId > 0 );
+  
+  setPlayableUniqueId( playableUniqueId );
+  
+  assert( playable );
+  
+  return playable;
+}
 
-    int teamId;                //!< teamId
-    int preferedTeamId;        //!< preferedTeamId
 
-    int score;                 //!< users score points
-    int playableClassId;       //!< players playable class id
-    int playableUniqueId;      //!< playable's uniqueId
-    std::string modelFileName; //!< model filename
-
-    Playable * playable;       //!< pointer to players playable
-
-    // handles for SynchronizeableVars
-    int userId_handle;
-    int playerName_handle;
-    int teamId_handle;
-    int preferedTeamId_handle;
-    int score_handle;
-    int playableClassId_handle;
-    int playableUniqueId_handle;
-    int modelFileName_handle;
-    
-    void init();
-};
-
-#endif /* _PLAYER_STATS_H */
Index: branches/network/src/lib/network/udp_socket.cc
===================================================================
--- branches/network/src/lib/network/udp_socket.cc	(revision 8185)
+++ branches/network/src/lib/network/udp_socket.cc	(revision 8187)
@@ -135,5 +135,5 @@
 void UdpSocket::disconnectServer( )
 {
-  PRINTF(0)("disconnect from server\n");
+  PRINTF(0)("disconnect\n");
   writePacket( NULL, 0 );
   SDLNet_UDP_Unbind( socket, -1 );
@@ -171,5 +171,5 @@
     packet->len = length;
     
-    if ( SDLNet_UDP_Send( socket, 1, packet) == 0 )
+    if ( socket && SDLNet_UDP_Send( socket, 1, packet) == 0 )
     {
       PRINTF(1)("SDLNet_UDP_Send: %s\n", SDLNet_GetError());
Index: branches/network/src/story_entities/multi_player_world.cc
===================================================================
--- branches/network/src/story_entities/multi_player_world.cc	(revision 8185)
+++ branches/network/src/story_entities/multi_player_world.cc	(revision 8187)
@@ -127,7 +127,9 @@
 ErrorMessage MultiPlayerWorld::unloadData( )
 {
+    
   GameWorld::unloadData();
   
   delete NetworkManager::getInstance();
   delete NetworkGameManager::getInstance();
+
 }
