From 64b59757322e29c331c0a75262baec4382673e6f Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 28 Jan 2011 01:38:16 +0200 Subject: Now texture handling is fast. Also now players are saved on disk. --- src/server.cpp | 194 +++++++++++++++++++++++---------------------------------- 1 file changed, 77 insertions(+), 117 deletions(-) (limited to 'src/server.cpp') diff --git a/src/server.cpp b/src/server.cpp index 541582b65..823a48b90 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1000,7 +1000,8 @@ Server::Server( m_time_of_day(9000), m_time_counter(0), m_time_of_day_send_timer(0), - m_uptime(0) + m_uptime(0), + m_mapsavedir(mapsavedir) { //m_flowwater_timer = 0.0; m_liquid_transform_timer = 0.0; @@ -1013,10 +1014,16 @@ Server::Server( m_con_mutex.Init(); m_step_dtime_mutex.Init(); m_step_dtime = 0.0; + + // Load players + m_env.deSerializePlayers(m_mapsavedir); } Server::~Server() { + // Save players + m_env.serializePlayers(m_mapsavedir); + // Stop threads stop(); @@ -1222,82 +1229,6 @@ void Server::AsyncRunStep() } } -#if 0 - /* - Update water - */ - if(g_settings.getBool("water_moves") == true) - { - float interval; - - if(g_settings.getBool("endless_water") == false) - interval = 1.0; - else - interval = 0.25; - - float &counter = m_flowwater_timer; - counter += dtime; - if(counter >= 0.25 && m_flow_active_nodes.size() > 0) - { - - counter = 0.0; - - core::map modified_blocks; - - { - - JMutexAutoLock envlock(m_env_mutex); - - MapVoxelManipulator v(&m_env.getMap()); - v.m_disable_water_climb = - g_settings.getBool("disable_water_climb"); - - if(g_settings.getBool("endless_water") == false) - v.flowWater(m_flow_active_nodes, 0, false, 250); - else - v.flowWater(m_flow_active_nodes, 0, false, 50); - - v.blitBack(modified_blocks); - - ServerMap &map = ((ServerMap&)m_env.getMap()); - - // Update lighting - core::map lighting_modified_blocks; - map.updateLighting(modified_blocks, lighting_modified_blocks); - - // Add blocks modified by lighting to modified_blocks - for(core::map::Iterator - i = lighting_modified_blocks.getIterator(); - i.atEnd() == false; i++) - { - MapBlock *block = i.getNode()->getValue(); - modified_blocks.insert(block->getPos(), block); - } - } // envlock - - /* - Set the modified blocks unsent for all the clients - */ - - JMutexAutoLock lock2(m_con_mutex); - - for(core::map::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); - } - } - - } // interval counter - } -#endif - // Periodically print some info { float &counter = m_print_info_timer; @@ -1476,6 +1407,9 @@ void Server::AsyncRunStep() dout_server<<"Server: Unloaded "<serialize(test_os); + dstream<<"Player serialization test: \""<deSerialize(test_is); + }*/ + // If failed, cancel if(player == NULL) { @@ -2950,7 +2894,7 @@ void Server::SendInventory(u16 peer_id) if(!found) { ItemSpec specs[9]; - specs[0] = ItemSpec(ITEM_CRAFT, "Coal"); + specs[0] = ItemSpec(ITEM_CRAFT, "lump_of_coal"); specs[3] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) { @@ -3147,6 +3091,50 @@ RemoteClient* Server::getClient(u16 peer_id) return n->getValue(); } +void setCreativeInventory(Player *player) +{ + player->resetInventory(); + + // 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; iinventory.addItem("main", item); + } + // Sign + { + InventoryItem *item = new MapBlockObjectItem("Sign Example text"); + void* r = player->inventory.addItem("main", item); + assert(r == NULL); + } +} + Player *Server::emergePlayer(const char *name, const char *password, u16 peer_id) { @@ -3162,8 +3150,16 @@ Player *Server::emergePlayer(const char *name, const char *password, dstream<<"emergePlayer(): Player already connected"<peer_id = peer_id; + + // Reset inventory to creative if in creative mode + if(g_settings.getBool("creative_mode")) + { + setCreativeInventory(player); + } + return player; } @@ -3271,51 +3267,15 @@ Player *Server::emergePlayer(const char *name, const char *password, 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; iinventory.addItem("main", item); - } - // Sign - { - InventoryItem *item = new MapBlockObjectItem("Sign Example text"); - void* r = player->inventory.addItem("main", item); - assert(r == NULL); - } + setCreativeInventory(player); } else { - { + /*{ InventoryItem *item = new ToolItem("WPick", 32000); void* r = player->inventory.addItem("main", item); assert(r == NULL); - } + }*/ /*{ InventoryItem *item = new MaterialItem(CONTENT_MESE, 6); void* r = player->inventory.addItem("main", item); -- cgit v1.2.3