]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/server.cpp
.
[dragonfireclient.git] / src / server.cpp
index 38c421e4119a708b70f4a84b7c87aee4f7d88d45..17004a803480cc853a96aaceeac46da1139d4803 100644 (file)
@@ -149,13 +149,40 @@ void * EmergeThread::Thread()
                        
                        if(optional)
                                only_from_disk = true;
-
-                       block = map.emergeBlock(
-                                       p,
-                                       only_from_disk,
-                                       changed_blocks,
-                                       lighting_invalidated_blocks);
                        
+                       // First check if the block already exists
+                       if(only_from_disk)
+                       {
+                               block = map.getBlockNoCreate(p);
+                       }
+
+                       if(block == NULL)
+                       {
+                               block = map.emergeBlock(
+                                               p,
+                                               only_from_disk,
+                                               changed_blocks,
+                                               lighting_invalidated_blocks);
+
+#if 0
+                               /*
+                                       EXPERIMENTAL: Create a few other blocks too
+                               */
+                               
+                               map.emergeBlock(
+                                               p + v3s16(0,1,0),
+                                               only_from_disk,
+                                               changed_blocks,
+                                               lighting_invalidated_blocks);
+
+                               map.emergeBlock(
+                                               p + v3s16(0,-1,0),
+                                               only_from_disk,
+                                               changed_blocks,
+                                               lighting_invalidated_blocks);
+#endif
+                       }
+
                        // If it is a dummy, block was not found on disk
                        if(block->isDummy())
                        {
@@ -185,6 +212,7 @@ void * EmergeThread::Thread()
                                dout_server<<std::endl;
                        }
 
+#if 0
                        /*
                                Update water pressure
                        */
@@ -199,6 +227,7 @@ void * EmergeThread::Thread()
                                //v3s16 p = i.getNode()->getKey();
                                //m_server->UpdateBlockWaterPressure(p, modified_blocks);
                        }
+#endif
 
                        /*
                                Collect a list of blocks that have been modified in
@@ -292,14 +321,25 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
                }
        }
 
+       bool haxmode = g_settings.getBool("haxmode");
+       
        Player *player = server->m_env.getPlayer(peer_id);
 
+       assert(player != NULL);
+
        v3f playerpos = player->getPosition();
        v3f playerspeed = player->getSpeed();
 
        v3s16 center_nodepos = floatToInt(playerpos);
 
        v3s16 center = getNodeBlockPos(center_nodepos);
+       
+       // Camera position and direction
+       v3f camera_pos =
+                       playerpos + v3f(0, BS+BS/2, 0);
+       v3f camera_dir = v3f(0,0,1);
+       camera_dir.rotateYZBy(player->getPitch());
+       camera_dir.rotateXZBy(player->getYaw());
 
        /*
                Get the starting value of the block finder radius.
@@ -455,10 +495,28 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
                                continue;
 
                        bool generate = d <= d_max_gen;
-               
-                       // Limit the generating area vertically to 2/3
-                       if(abs(p.Y - center.Y) > d_max_gen - d_max_gen / 3)
-                               generate = false;
+                       
+                       if(haxmode)
+                       {
+                               // Don't generate above player
+                               if(p.Y > center.Y)
+                                       generate = false;
+                       }
+                       else
+                       {
+                               // Limit the generating area vertically to 2/3
+                               if(abs(p.Y - center.Y) > d_max_gen - d_max_gen / 3)
+                                       generate = false;
+                       }
+
+                       /*
+                               Don't draw if not in sight
+                       */
+
+                       if(isBlockInSight(p, camera_pos, camera_dir, 10000*BS) == false)
+                       {
+                               continue;
+                       }
                        
                        /*
                                Don't send already sent blocks
@@ -470,6 +528,25 @@ void RemoteClient::GetNextBlocks(Server *server, float dtime,
                                        continue;
                        }
 
+                       if(haxmode)
+                       {
+                               /*
+                                       Ignore block if it is not at ground surface
+                                       but don't ignore water surface blocks
+                               */
+                               v2s16 p2d(p.X*MAP_BLOCKSIZE + MAP_BLOCKSIZE/2,
+                                               p.Z*MAP_BLOCKSIZE + MAP_BLOCKSIZE/2);
+                               f32 y = server->m_env.getMap().getGroundHeight(p2d);
+                               // The sector might not exist yet, thus no heightmap
+                               if(y > GROUNDHEIGHT_VALID_MINVALUE)
+                               {
+                                       f32 by = p.Y*MAP_BLOCKSIZE + MAP_BLOCKSIZE/2;
+                                       if(fabs(by - y) > MAP_BLOCKSIZE + MAP_BLOCKSIZE/3
+                                                       && fabs(by - WATER_LEVEL) >= MAP_BLOCKSIZE)
+                                               continue;
+                               }
+                       }
+
                        /*
                                Check if map has this block
                        */
@@ -604,8 +681,9 @@ void RemoteClient::SendObjectData(
        /*
                Get and write player data
        */
-
-       core::list<Player*> players = server->m_env.getPlayers();
+       
+       // Get connected players
+       core::list<Player*> players = server->m_env.getPlayers(true);
 
        // Write player count
        u16 playercount = players.size();
@@ -656,6 +734,8 @@ void RemoteClient::SendObjectData(
 
        Player *player = server->m_env.getPlayer(peer_id);
 
+       assert(player);
+
        v3f playerpos = player->getPosition();
        v3f playerspeed = player->getSpeed();
 
@@ -782,20 +862,23 @@ void RemoteClient::GotBlock(v3s16 p)
        if(m_blocks_sending.find(p) != NULL)
                m_blocks_sending.remove(p);
        else
-               dstream<<"RemoteClient::GotBlock(): Didn't find in"
-                               " m_blocks_sending"<<std::endl;
+       {
+               /*dstream<<"RemoteClient::GotBlock(): Didn't find in"
+                               " m_blocks_sending"<<std::endl;*/
+               m_excess_gotblocks++;
+       }
        m_blocks_sent.insert(p, true);
 }
 
 void RemoteClient::SentBlock(v3s16 p)
 {
        JMutexAutoLock lock(m_blocks_sending_mutex);
-       if(m_blocks_sending.size() > 15)
+       /*if(m_blocks_sending.size() > 15)
        {
                dstream<<"RemoteClient::SentBlock(): "
                                <<"m_blocks_sending.size()="
                                <<m_blocks_sending.size()<<std::endl;
-       }
+       }*/
        if(m_blocks_sending.find(p) == NULL)
                m_blocks_sending.insert(p, 0.0);
        else
@@ -847,7 +930,8 @@ PlayerInfo::PlayerInfo()
 
 void PlayerInfo::PrintLine(std::ostream *s)
 {
-       (*s)<<id<<": \""<<name<<"\" ("
+       (*s)<<id<<": ";
+       (*s)<<"\""<<name<<"\" ("
                        <<position.X<<","<<position.Y
                        <<","<<position.Z<<") ";
        address.print(s);
@@ -887,7 +971,8 @@ Server::Server(
        m_time_of_day_send_timer(0),
        m_uptime(0)
 {
-       m_flowwater_timer = 0.0;
+       //m_flowwater_timer = 0.0;
+       m_liquid_transform_timer = 0.0;
        m_print_info_timer = 0.0;
        m_objectdata_timer = 0.0;
        m_emergethread_trigger_timer = 0.0;
@@ -910,13 +995,13 @@ Server::~Server()
                i = m_clients.getIterator();
                i.atEnd() == false; i++)
        {
-               u16 peer_id = i.getNode()->getKey();
-
-               // Delete player
+               /*// Delete player
+               // NOTE: These are removed by env destructor
                {
+                       u16 peer_id = i.getNode()->getKey();
                        JMutexAutoLock envlock(m_env_mutex);
                        m_env.removePlayer(peer_id);
-               }
+               }*/
                
                // Delete client
                delete i.getNode()->getValue();
@@ -1056,10 +1141,61 @@ void Server::AsyncRunStep()
        /*
                Do background stuff
        */
+       
+       /*
+               Transform liquids
+       */
+       m_liquid_transform_timer += dtime;
+       if(m_liquid_transform_timer >= 1.00)
+       {
+               m_liquid_transform_timer -= 1.00;
+               
+               JMutexAutoLock lock(m_env_mutex);
+               
+               core::map<v3s16, MapBlock*> modified_blocks;
+               m_env.getMap().transformLiquids(modified_blocks);
+#if 0          
+               /*
+                       Update lighting
+               */
+               core::map<v3s16, MapBlock*> lighting_modified_blocks;
+               ServerMap &map = ((ServerMap&)m_env.getMap());
+               map.updateLighting(modified_blocks, lighting_modified_blocks);
+               
+               // Add blocks modified by lighting to modified_blocks
+               for(core::map<v3s16, MapBlock*>::Iterator
+                               i = lighting_modified_blocks.getIterator();
+                               i.atEnd() == false; i++)
+               {
+                       MapBlock *block = i.getNode()->getValue();
+                       modified_blocks.insert(block->getPos(), block);
+               }
+#endif
+               /*
+                       Set the modified blocks unsent for all the clients
+               */
+               
+               JMutexAutoLock lock2(m_con_mutex);
 
+               for(core::map<u16, RemoteClient*>::Iterator
+                               i = m_clients.getIterator();
+                               i.atEnd() == false; i++)
+               {
+                       RemoteClient *client = i.getNode()->getValue();
+                       
+                       if(modified_blocks.size() > 0)
+                       {
+                               // Remove block from sent history
+                               client->SetBlocksNotSent(modified_blocks);
+                       }
+               }
+       }
+
+#if 0
        /*
-               Flow water
+               Update water
        */
+       if(g_settings.getBool("water_moves") == true)
        {
                float interval;
                
@@ -1129,6 +1265,7 @@ void Server::AsyncRunStep()
 
                } // interval counter
        }
+#endif
        
        // Periodically print some info
        {
@@ -1419,20 +1556,44 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                /*
                        Set up player
                */
+               
+               // Get player name
+               const u32 playername_size = 20;
+               char playername[playername_size];
+               for(u32 i=0; i<playername_size-1; i++)
+               {
+                       playername[i] = data[3+i];
+               }
+               playername[playername_size-1] = 0;
+               
+               // Get player
+               Player *player = emergePlayer(playername, "");
+               //Player *player = m_env.getPlayer(peer_id);
+
+               // If a client is already connected to the player, cancel
+               if(player->peer_id != 0)
+               {
+                       derr_server<<DTIME<<"Server: peer_id="<<peer_id
+                                       <<" tried to connect to "
+                                       "an already connected player (peer_id="
+                                       <<player->peer_id<<")"<<std::endl;
+                       return;
+               }
 
-               Player *player = m_env.getPlayer(peer_id);
+               // Set client of player
+               player->peer_id = peer_id;
 
                // Check if player doesn't exist
                if(player == NULL)
                        throw con::InvalidIncomingDataException
                                ("Server::ProcessData(): INIT: Player doesn't exist");
 
-               // update name if it was supplied
+               /*// update name if it was supplied
                if(datasize >= 20+3)
                {
                        data[20+3-1] = 0;
                        player->updateName((const char*)&data[3]);
-               }
+               }*/
 
                // Now answer with a TOCLIENT_INIT
                
@@ -1488,9 +1649,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                                assert(client->peer_id == i.getNode()->getKey());
                                if(client->serialization_version == SER_FMT_VER_INVALID)
                                        continue;
+                               // Get player
+                               Player *player = m_env.getPlayer(client->peer_id);
                                // Get name of player
                                std::wstring name = L"unknown";
-                               Player *player = m_env.getPlayer(client->peer_id);
                                if(player != NULL)
                                        name = narrow_to_wide(player->getName());
                                // Add name to information string
@@ -1857,7 +2019,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                                (this takes some time so it is done after the quick stuff)
                        */
                        m_env.getMap().removeNodeAndUpdate(p_under, modified_blocks);
-                       
+
+#if 0
                        /*
                                Update water
                        */
@@ -1881,6 +2044,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                        }
                        
                        v.blitBack(modified_blocks);
+#endif
                }
                
                /*
@@ -2006,7 +2170,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                                        }
                                }
 #endif
-                               
+
+#if 0
                                /*
                                        Update water
                                */
@@ -2030,6 +2195,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
                                }
                                
                                v.blitBack(modified_blocks);
+#endif
                        }
                        /*
                                Handle other items
@@ -2394,15 +2560,17 @@ core::list<PlayerInfo> Server::getPlayerInfo()
                PlayerInfo info;
 
                Player *player = *i;
+
                try{
                        con::Peer *peer = m_con.GetPeer(player->peer_id);
+                       // Copy info from peer to info struct
                        info.id = peer->id;
                        info.address = peer->address;
                        info.avg_rtt = peer->avg_rtt;
                }
                catch(con::PeerNotFoundException &e)
                {
-                       // Outdated peer info
+                       // Set dummy peer info
                        info.id = 0;
                        info.address = Address(0,0,0,0,0);
                        info.avg_rtt = 0.0;
@@ -2470,7 +2638,8 @@ void Server::SendPlayerInfos()
 
        //JMutexAutoLock envlock(m_env_mutex);
        
-       core::list<Player*> players = m_env.getPlayers();
+       // Get connected players
+       core::list<Player*> players = m_env.getPlayers(true);
        
        u32 player_count = players.getSize();
        u32 datasize = 2+(2+PLAYERNAME_SIZE)*player_count;
@@ -2922,6 +3091,207 @@ RemoteClient* Server::getClient(u16 peer_id)
        return n->getValue();
 }
 
+Player *Server::emergePlayer(const char *name, const char *password)
+{
+       /*
+               Try to get an existing player
+       */
+       Player *player = m_env.getPlayer(name);
+       if(player != NULL)
+       {
+               // Got one.
+               return player;
+       }
+       
+       /*
+               Create a new player
+       */
+       {
+               player = new ServerRemotePlayer();
+               //player->peer_id = c.peer_id;
+               player->peer_id = PEER_ID_INEXISTENT;
+               player->updateName(name);
+
+               /*
+                       Set player position
+               */
+               
+               dstream<<"Server: Finding spawn place for player \""
+                               <<player->getName()<<"\""<<std::endl;
+
+#if 1
+               v2s16 nodepos;
+               f32 groundheight = 0;
+               // Try to find a good place a few times
+               for(s32 i=0; i<500; i++)
+               {
+                       s32 range = 1 + i;
+                       // We're going to try to throw the player to this position
+                       nodepos = v2s16(-range + (myrand()%(range*2)),
+                                       -range + (myrand()%(range*2)));
+                       v2s16 sectorpos = getNodeSectorPos(nodepos);
+                       // Get sector
+                       m_env.getMap().emergeSector(sectorpos);
+                       // Get ground height at point
+                       groundheight = m_env.getMap().getGroundHeight(nodepos, true);
+                       // The sector should have been generated -> groundheight exists
+                       assert(groundheight > GROUNDHEIGHT_VALID_MINVALUE);
+                       // Don't go underwater
+                       if(groundheight < WATER_LEVEL)
+                       {
+                               //dstream<<"-> Underwater"<<std::endl;
+                               continue;
+                       }
+#if 0 // Doesn't work, generating blocks is a bit too complicated for doing here
+                       // Get block at point
+                       v3s16 nodepos3d;
+                       nodepos3d = v3s16(nodepos.X, groundheight+1, nodepos.Y);
+                       v3s16 blockpos = getNodeBlockPos(nodepos3d);
+                       ((ServerMap*)(&m_env.getMap()))->emergeBlock(blockpos);
+                       // Don't go inside ground
+                       try{
+                               /*v3s16 footpos(nodepos.X, groundheight+1, nodepos.Y);
+                               v3s16 headpos(nodepos.X, groundheight+2, nodepos.Y);*/
+                               v3s16 footpos = nodepos3d + v3s16(0,0,0);
+                               v3s16 headpos = nodepos3d + v3s16(0,1,0);
+                               if(m_env.getMap().getNode(footpos).d != CONTENT_AIR
+                                       || m_env.getMap().getNode(headpos).d != CONTENT_AIR)
+                               {
+                                       dstream<<"-> Inside ground"<<std::endl;
+                                       // In ground
+                                       continue;
+                               }
+                       }catch(InvalidPositionException &e)
+                       {
+                               dstream<<"-> Invalid position"<<std::endl;
+                               // Ignore invalid position
+                               continue;
+                       }
+#endif
+                       // Found a good place
+                       dstream<<"Searched through "<<i<<" places."<<std::endl;
+                       break;
+               }
+#endif
+               
+               // If no suitable place was not found, go above water at least.
+               if(groundheight < WATER_LEVEL)
+                       groundheight = WATER_LEVEL;
+
+               player->setPosition(intToFloat(v3s16(
+                               nodepos.X,
+                               groundheight + 1,
+                               nodepos.Y
+               )));
+
+               /*
+                       Add player to environment
+               */
+
+               m_env.addPlayer(player);
+
+               /*
+                       Add stuff to inventory
+               */
+               
+               if(g_settings.getBool("creative_mode"))
+               {
+                       // Give some good picks
+                       {
+                               InventoryItem *item = new ToolItem("STPick", 0);
+                               void* r = player->inventory.addItem("main", item);
+                               assert(r == NULL);
+                       }
+                       {
+                               InventoryItem *item = new ToolItem("MesePick", 0);
+                               void* r = player->inventory.addItem("main", item);
+                               assert(r == NULL);
+                       }
+
+                       /*
+                               Give materials
+                       */
+                       assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE);
+                       
+                       // add torch first
+                       InventoryItem *item = new MaterialItem(CONTENT_TORCH, 1);
+                       player->inventory.addItem("main", item);
+                       
+                       // Then others
+                       for(u16 i=0; i<USEFUL_CONTENT_COUNT; i++)
+                       {
+                               // Skip some materials
+                               if(i == CONTENT_WATER || i == CONTENT_TORCH)
+                                       continue;
+
+                               InventoryItem *item = new MaterialItem(i, 1);
+                               player->inventory.addItem("main", item);
+                       }
+                       // Sign
+                       {
+                               InventoryItem *item = new MapBlockObjectItem("Sign Example text");
+                               void* r = player->inventory.addItem("main", item);
+                               assert(r == NULL);
+                       }
+               }
+               else
+               {
+                       /*{
+                               InventoryItem *item = new MaterialItem(CONTENT_MESE, 6);
+                               void* r = player->inventory.addItem("main", item);
+                               assert(r == NULL);
+                       }
+                       {
+                               InventoryItem *item = new MaterialItem(CONTENT_COALSTONE, 6);
+                               void* r = player->inventory.addItem("main", item);
+                               assert(r == NULL);
+                       }
+                       {
+                               InventoryItem *item = new MaterialItem(CONTENT_WOOD, 6);
+                               void* r = player->inventory.addItem("main", item);
+                               assert(r == NULL);
+                       }
+                       {
+                               InventoryItem *item = new CraftItem("Stick", 4);
+                               void* r = player->inventory.addItem("main", item);
+                               assert(r == NULL);
+                       }
+                       {
+                               InventoryItem *item = new ToolItem("WPick", 32000);
+                               void* r = player->inventory.addItem("main", item);
+                               assert(r == NULL);
+                       }
+                       {
+                               InventoryItem *item = new ToolItem("STPick", 32000);
+                               void* r = player->inventory.addItem("main", item);
+                               assert(r == NULL);
+                       }*/
+                       /*// Give some lights
+                       {
+                               InventoryItem *item = new MaterialItem(CONTENT_TORCH, 999);
+                               bool r = player->inventory.addItem("main", item);
+                               assert(r == true);
+                       }
+                       // and some signs
+                       for(u16 i=0; i<4; i++)
+                       {
+                               InventoryItem *item = new MapBlockObjectItem("Sign Example text");
+                               bool r = player->inventory.addItem("main", item);
+                               assert(r == true);
+                       }*/
+                       /*// Give some other stuff
+                       {
+                               InventoryItem *item = new MaterialItem(CONTENT_TREE, 999);
+                               bool r = player->inventory.addItem("main", item);
+                               assert(r == true);
+                       }*/
+               }
+
+               return player;
+       }
+}
+
+#if 0
 void Server::UpdateBlockWaterPressure(MapBlock *block,
                        core::map<v3s16, MapBlock*> &modified_blocks)
 {
@@ -2943,6 +3313,7 @@ void Server::UpdateBlockWaterPressure(MapBlock *block,
        
        v.blitBack(modified_blocks);
 }
+#endif
 
 void Server::handlePeerChange(PeerChange &c)
 {
@@ -2966,145 +3337,6 @@ void Server::handlePeerChange(PeerChange &c)
                client->peer_id = c.peer_id;
                m_clients.insert(client->peer_id, client);
 
-               // Create player
-               {
-                       Player *player = m_env.getPlayer(c.peer_id);
-                       
-                       // The player shouldn't already exist
-                       assert(player == NULL);
-
-                       player = new ServerRemotePlayer(true);
-                       player->peer_id = c.peer_id;
-
-                       /*
-                               Set player position
-                       */
-                       
-                       // We're going to throw the player to this position
-                       //v2s16 nodepos(29990,29990);
-                       //v2s16 nodepos(9990,9990);
-                       v2s16 nodepos(0,0);
-                       v2s16 sectorpos = getNodeSectorPos(nodepos);
-                       // Get zero sector (it could have been unloaded to disk)
-                       m_env.getMap().emergeSector(sectorpos);
-                       // Get ground height at origin
-                       f32 groundheight = m_env.getMap().getGroundHeight(nodepos, true);
-                       // The sector should have been generated -> groundheight exists
-                       assert(groundheight > GROUNDHEIGHT_VALID_MINVALUE);
-                       // Don't go underwater
-                       if(groundheight < WATER_LEVEL)
-                               groundheight = WATER_LEVEL;
-
-                       player->setPosition(intToFloat(v3s16(
-                                       nodepos.X,
-                                       groundheight + 1,
-                                       nodepos.Y
-                       )));
-
-                       /*
-                               Add player to environment
-                       */
-
-                       m_env.addPlayer(player);
-
-                       /*
-                               Add stuff to inventory
-                       */
-                       
-                       if(g_settings.getBool("creative_mode"))
-                       {
-                               // Give some good picks
-                               {
-                                       InventoryItem *item = new ToolItem("STPick", 0);
-                                       void* r = player->inventory.addItem("main", item);
-                                       assert(r == NULL);
-                               }
-                               {
-                                       InventoryItem *item = new ToolItem("MesePick", 0);
-                                       void* r = player->inventory.addItem("main", item);
-                                       assert(r == NULL);
-                               }
-
-                               /*
-                                       Give materials
-                               */
-                               assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE);
-                               
-                               // add torch first
-                               InventoryItem *item = new MaterialItem(CONTENT_TORCH, 1);
-                               player->inventory.addItem("main", item);
-                               
-                               // Then others
-                               for(u16 i=0; i<USEFUL_CONTENT_COUNT; i++)
-                               {
-                                       // Skip some materials
-                                       if(i == CONTENT_OCEAN || i == CONTENT_TORCH)
-                                               continue;
-
-                                       InventoryItem *item = new MaterialItem(i, 1);
-                                       player->inventory.addItem("main", item);
-                               }
-                               // Sign
-                               {
-                                       InventoryItem *item = new MapBlockObjectItem("Sign Example text");
-                                       void* r = player->inventory.addItem("main", item);
-                                       assert(r == NULL);
-                               }
-                       }
-                       else
-                       {
-                               /*{
-                                       InventoryItem *item = new MaterialItem(CONTENT_MESE, 6);
-                                       void* r = player->inventory.addItem("main", item);
-                                       assert(r == NULL);
-                               }
-                               {
-                                       InventoryItem *item = new MaterialItem(CONTENT_COALSTONE, 6);
-                                       void* r = player->inventory.addItem("main", item);
-                                       assert(r == NULL);
-                               }
-                               {
-                                       InventoryItem *item = new MaterialItem(CONTENT_WOOD, 6);
-                                       void* r = player->inventory.addItem("main", item);
-                                       assert(r == NULL);
-                               }
-                               {
-                                       InventoryItem *item = new CraftItem("Stick", 4);
-                                       void* r = player->inventory.addItem("main", item);
-                                       assert(r == NULL);
-                               }
-                               {
-                                       InventoryItem *item = new ToolItem("WPick", 32000);
-                                       void* r = player->inventory.addItem("main", item);
-                                       assert(r == NULL);
-                               }
-                               {
-                                       InventoryItem *item = new ToolItem("STPick", 32000);
-                                       void* r = player->inventory.addItem("main", item);
-                                       assert(r == NULL);
-                               }*/
-                               /*// Give some lights
-                               {
-                                       InventoryItem *item = new MaterialItem(CONTENT_TORCH, 999);
-                                       bool r = player->inventory.addItem("main", item);
-                                       assert(r == true);
-                               }
-                               // and some signs
-                               for(u16 i=0; i<4; i++)
-                               {
-                                       InventoryItem *item = new MapBlockObjectItem("Sign Example text");
-                                       bool r = player->inventory.addItem("main", item);
-                                       assert(r == true);
-                               }*/
-                               /*// Give some other stuff
-                               {
-                                       InventoryItem *item = new MaterialItem(CONTENT_TREE, 999);
-                                       bool r = player->inventory.addItem("main", item);
-                                       assert(r == true);
-                               }*/
-                       }
-               }
-
        } // PEER_ADDED
        else if(c.type == PEER_REMOVED)
        {
@@ -3133,9 +3365,15 @@ void Server::handlePeerChange(PeerChange &c)
                                message += L" (timed out)";
                }
 
-               // Delete player
+               /*// Delete player
                {
                        m_env.removePlayer(c.peer_id);
+               }*/
+
+               // Set player client disconnected
+               {
+                       Player *player = m_env.getPlayer(c.peer_id);
+                       player->peer_id = 0;
                }
                
                // Delete client