From 416499f9787e48549a344f19eeac7ecfec517ecf Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 25 Jul 2011 23:31:02 +0300 Subject: [PATCH 01/14] fix server build --- src/mapblock.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mapblock.cpp b/src/mapblock.cpp index b7981348c..44ca75ff0 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -909,10 +909,12 @@ std::string analyze_block(MapBlock *block) else desc<<"is_ug [ ], "; +#ifndef SERVER if(block->getMeshExpired()) desc<<"mesh_exp [X], "; else desc<<"mesh_exp [ ], "; +#endif if(block->getLightingExpired()) desc<<"lighting_exp [X], "; From a653cf4944b9d5c9b1ecafc2ebdf244854189c79 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 29 Jul 2011 12:59:37 +0300 Subject: [PATCH 02/14] removed delta README --- README | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 README diff --git a/README b/README deleted file mode 100644 index 82fcdd331..000000000 --- a/README +++ /dev/null @@ -1,41 +0,0 @@ -Minetest Δ (“Minetest Delta”) is a fork of Minetest-c55 , incorporating experimental features that are not (yet) included in Minetest-c55. - -New features: -* Submenu for key assignment -* configurable far mesh tree display (boolean) -* configurable far mesh rendering distance -* volumetric clouds (using fake shading) -* translation support (including questionable translation into german) -* build system uses local jthread & sqlite libraries if available - -New bricks: -* Sandstone (crafted from 4 sand, yields sand) -* Cactus (plant that grows on sand) -* Clay (found in sand at sea level, yields 4 lumps of clay) -* Brick (made from 4 clay bricks, yields 4 clay bricks) -* Papyrus (plant that grows in shallow water) -* Book shelf (made from 6 wood and 3 books, sandwhiched) -* Rail (made from 6 iron ingots and 3 sticks, vertically sandwhiched) - -New materials: -* Lump of clay -* Clay brick (made from lumps of clay in the furnace) -* Paper (made from 3 papyrus horizontally) -* Book (made from 3 paper vertically) - -Alternate graphics: -* Player -* Omsk birds (instead of Oerkki ghosts) -* Rat -* Glass -* Heart - -Building on GNU/Linux or OS X: - cmake . -DRUN_IN_PLACE=1 - make -j2 - -The “upstream” branch contains vanilla minetest-c55, created using: - hg-fast-export -r ~/share/src/games/minetest -o upstream - git push origin upstream/master:upstream -f - -All new/replaced graphics done by erlehmann are dual-licensed under GPL (version 2 or, at your option, any later version) and CC-BY-SA (version 3.0 or, at your option, any later version). From 1de45cc8a7e191dedd8c2d9ca10c71eff88dc9ef Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 30 Jul 2011 14:02:11 +0300 Subject: [PATCH 03/14] Removed remaining -delta references --- CMakeLists.txt | 2 +- src/game.cpp | 2 +- src/guiKeyChangeMenu.cpp | 2 +- src/guiKeyChangeMenu.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4a5bb02e..860bbba00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ project(minetest) set(VERSION_MAJOR 0) set(VERSION_MINOR 2) -set(VERSION_PATCH 20110720_0) +set(VERSION_PATCH 20110730_rc1) set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") # Configuration options diff --git a/src/game.cpp b/src/game.cpp index b3069d6f9..0afb351d1 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2021,7 +2021,7 @@ void the_game( endscenetime_avg = endscenetime_avg * 0.95 + (float)endscenetime*0.05; char temptext[300]; - snprintf(temptext, 300, "Minetest-delta %s (" + snprintf(temptext, 300, "Minetest-c55 %s (" "R: range_all=%i" ")" " drawtime=%.0f, beginscenetime=%.0f" diff --git a/src/guiKeyChangeMenu.cpp b/src/guiKeyChangeMenu.cpp index 4a11cf93c..98d6f8086 100644 --- a/src/guiKeyChangeMenu.cpp +++ b/src/guiKeyChangeMenu.cpp @@ -1,5 +1,5 @@ /* - Minetest-delta + Minetest-c55 Copyright (C) 2010-11 celeron55, Perttu Ahola Copyright (C) 2011 Ciaran Gultnieks Copyright (C) 2011 teddydestodes diff --git a/src/guiKeyChangeMenu.h b/src/guiKeyChangeMenu.h index 389ce7aee..e9e359c3c 100644 --- a/src/guiKeyChangeMenu.h +++ b/src/guiKeyChangeMenu.h @@ -1,5 +1,5 @@ /* - Minetest-delta + Minetest-c55 Copyright (C) 2010-11 celeron55, Perttu Ahola Copyright (C) 2011 Ciaran Gultnieks Copyright (C) 2011 teddydestodes From df27b854325c1fe96b7bc9f8a1cc227b55896f57 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 30 Jul 2011 14:38:41 +0300 Subject: [PATCH 04/14] quick fix to it not building with gettext on my visual studio environment --- src/gettext.h | 2 -- src/main.cpp | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gettext.h b/src/gettext.h index 8ddb95346..73b9f8986 100644 --- a/src/gettext.h +++ b/src/gettext.h @@ -2,8 +2,6 @@ #include #else #define gettext(String) String -#define bindtextdomain(domain, dir) /* */ -#define textdomain(domain) /* */ #endif #define _(String) gettext(String) diff --git a/src/main.cpp b/src/main.cpp index 09c299004..9a9b22f87 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1161,9 +1161,11 @@ int main(int argc, char *argv[]) // Create user data directory fs::CreateDir(porting::path_userdata); +#ifdef USE_GETTEXT setlocale(LC_MESSAGES, ""); bindtextdomain("minetest", (porting::path_userdata+"/locale").c_str()); textdomain("minetest"); +#endif // Initialize debug streams #ifdef RUN_IN_PLACE From 8ceb0586b29d66ad0b4c073420590625a4b63769 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 30 Jul 2011 14:57:43 +0300 Subject: [PATCH 05/14] made more things burnable in furnace --- src/content_nodemeta.cpp | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/content_nodemeta.cpp b/src/content_nodemeta.cpp index 681e2b925..6b8bf05ef 100644 --- a/src/content_nodemeta.cpp +++ b/src/content_nodemeta.cpp @@ -277,6 +277,20 @@ bool FurnaceNodeMetadata::step(float dtime) fuel_list->decrementMaterials(1); changed = true; } + else if(ItemSpec(ITEM_MATERIAL, CONTENT_JUNGLETREE).checkItem(fuel_item)) + { + m_fuel_totaltime = 30; + m_fuel_time = 0; + fuel_list->decrementMaterials(1); + changed = true; + } + else if(ItemSpec(ITEM_MATERIAL, CONTENT_FENCE).checkItem(fuel_item)) + { + m_fuel_totaltime = 30/2; + m_fuel_time = 0; + fuel_list->decrementMaterials(1); + changed = true; + } else if(ItemSpec(ITEM_MATERIAL, CONTENT_WOOD).checkItem(fuel_item)) { m_fuel_totaltime = 30/4; @@ -284,6 +298,41 @@ bool FurnaceNodeMetadata::step(float dtime) fuel_list->decrementMaterials(1); changed = true; } + else if(ItemSpec(ITEM_MATERIAL, CONTENT_BOOKSHELF).checkItem(fuel_item)) + { + m_fuel_totaltime = 30/4; + m_fuel_time = 0; + fuel_list->decrementMaterials(1); + changed = true; + } + else if(ItemSpec(ITEM_MATERIAL, CONTENT_LEAVES).checkItem(fuel_item)) + { + m_fuel_totaltime = 30/16; + m_fuel_time = 0; + fuel_list->decrementMaterials(1); + changed = true; + } + else if(ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS).checkItem(fuel_item)) + { + m_fuel_totaltime = 30/32; + m_fuel_time = 0; + fuel_list->decrementMaterials(1); + changed = true; + } + else if(ItemSpec(ITEM_MATERIAL, CONTENT_JUNGLEGRASS).checkItem(fuel_item)) + { + m_fuel_totaltime = 30/32; + m_fuel_time = 0; + fuel_list->decrementMaterials(1); + changed = true; + } + else if(ItemSpec(ITEM_MATERIAL, CONTENT_CACTUS).checkItem(fuel_item)) + { + m_fuel_totaltime = 30/4; + m_fuel_time = 0; + fuel_list->decrementMaterials(1); + changed = true; + } else if(ItemSpec(ITEM_CRAFT, "Stick").checkItem(fuel_item)) { m_fuel_totaltime = 30/4/4; From 4556c212dba726271352b05a9299564e05abb218 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 30 Jul 2011 17:51:21 +0300 Subject: [PATCH 06/14] Made rats cookable and made them spawn near trees --- src/content_inventory.cpp | 10 +++++++++- src/content_sao.cpp | 2 +- src/defaultsettings.cpp | 2 +- src/environment.cpp | 42 ++++++++++++++++++++++++++++++++++++--- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/content_inventory.cpp b/src/content_inventory.cpp index 322250606..24840d6af 100644 --- a/src/content_inventory.cpp +++ b/src/content_inventory.cpp @@ -65,6 +65,10 @@ std::string item_craft_get_image_name(const std::string &subname) return "clay_brick.png"; else if(subname == "rat") return "rat.png"; + else if(subname == "cooked_rat") + return "cooked_rat.png"; + else if(subname == "scorched_stuff") + return "scorched_stuff.png"; else if(subname == "firefly") return "firefly.png"; else @@ -98,7 +102,7 @@ s16 item_craft_get_drop_count(const std::string &subname) bool item_craft_is_cookable(const std::string &subname) { - if(subname == "lump_of_iron" || subname == "lump_of_clay") + if(subname == "lump_of_iron" || subname == "lump_of_clay" || subname == "rat" || subname == "cooked_rat") return true; return false; @@ -110,6 +114,10 @@ InventoryItem* item_craft_create_cook_result(const std::string &subname) return new CraftItem("steel_ingot", 1); else if(subname == "lump_of_clay") return new CraftItem("clay_brick", 1); + else if(subname == "rat") + return new CraftItem("cooked_rat", 1); + else if(subname == "cooked_rat") + return new CraftItem("scorched_stuff", 1); return NULL; } diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 0b81855c1..eadaa6e5f 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -232,7 +232,7 @@ RatSAO::RatSAO(ServerEnvironment *env, u16 id, v3f pos): m_oldpos = v3f(0,0,0); m_last_sent_position = v3f(0,0,0); - m_yaw = 0; + m_yaw = myrand_range(0,PI*2); m_counter1 = 0; m_counter2 = 0; m_age = 0; diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 8326a0f0d..947892d12 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -79,7 +79,7 @@ void set_default_settings() // Server stuff g_settings.setDefault("enable_experimental", "false"); g_settings.setDefault("creative_mode", "false"); - g_settings.setDefault("enable_damage", "false"); //TODO: Set to true when healing is possible + g_settings.setDefault("enable_damage", "true"); g_settings.setDefault("give_initial_stuff", "false"); g_settings.setDefault("default_password", ""); g_settings.setDefault("default_privs", "build, shout"); diff --git a/src/environment.cpp b/src/environment.cpp index d72369620..e9b94f3fa 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -816,7 +816,7 @@ void ServerEnvironment::step(float dtime) if(m_active_blocks_test_interval.step(dtime, 10.0)) { //float dtime = 10.0; - + for(core::map::Iterator i = m_active_blocks.m_list.getIterator(); i.atEnd()==false; i++) @@ -846,6 +846,21 @@ void ServerEnvironment::step(float dtime) searching loop to keep things fast. */ // TODO: Implement usage of ActiveBlockModifier + + // Find out how many objects the block contains + u32 active_object_count = block->m_static_objects.m_active.size(); + // Find out how many objects this and all the neighbors contain + u32 active_object_count_wider = 0; + for(s16 x=-1; x<=1; x++) + for(s16 y=-1; y<=1; y++) + for(s16 z=-1; z<=1; z++) + { + MapBlock *block = m_map->getBlockNoCreateNoEx(p+v3s16(x,y,z)); + if(block==NULL) + continue; + active_object_count_wider += + block->m_static_objects.m_active.size(); + } v3s16 p0; for(p0.X=0; p0.XgetNodeNoEx(p+v3s16(0,1,0)); - if(content_features(n_top).air_equivalent == false) + if(content_features(n_top).air_equivalent == false) { n.setContent(CONTENT_MUD); m_map->addNodeWithEvent(p, n); } } } + /* + Rats spawn around regular trees + */ + if(n.getContent() == CONTENT_TREE || + n.getContent() == CONTENT_JUNGLETREE) + { + if(myrand()%200 == 0 && active_object_count_wider == 0) + { + v3s16 p1 = p + v3s16(myrand_range(-2, 2), + 0, myrand_range(-2, 2)); + MapNode n1 = m_map->getNodeNoEx(p1); + MapNode n1b = m_map->getNodeNoEx(p1+v3s16(0,-1,0)); + if(n1b.getContent() == CONTENT_GRASS && + n1.getContent() == CONTENT_AIR) + { + v3f pos = intToFloat(p1, BS); + ServerActiveObject *obj = new RatSAO(this, 0, pos); + addActiveObject(obj); + } + } + } } } } From d62ae0e18bc570033ada07454b1642f696fe17b1 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 30 Jul 2011 18:51:15 +0300 Subject: [PATCH 07/14] Rats are now eatable. Also made their selection box move smoothly. --- src/content_cao.h | 3 +- src/content_inventory.cpp | 15 +++++ src/content_inventory.h | 2 + src/content_sao.cpp | 12 ++++ src/content_sao.h | 1 + src/game.cpp | 2 + src/inventory.cpp | 15 +++++ src/inventory.h | 15 ++++- src/server.cpp | 127 +++++++++++++++++++++----------------- src/serverobject.h | 5 ++ 10 files changed, 140 insertions(+), 57 deletions(-) diff --git a/src/content_cao.h b/src/content_cao.h index b984be136..319f90380 100644 --- a/src/content_cao.h +++ b/src/content_cao.h @@ -187,7 +187,8 @@ public: core::aabbox3d* getSelectionBox() {return &m_selection_box;} v3f getPosition() - {return m_position;} + {return pos_translator.vect_show;} + //{return m_position;} private: core::aabbox3d m_selection_box; diff --git a/src/content_inventory.cpp b/src/content_inventory.cpp index 24840d6af..de8f8e397 100644 --- a/src/content_inventory.cpp +++ b/src/content_inventory.cpp @@ -122,3 +122,18 @@ InventoryItem* item_craft_create_cook_result(const std::string &subname) return NULL; } +bool item_craft_is_eatable(const std::string &subname) +{ + if(subname == "cooked_rat") + return true; + return false; +} + +s16 item_craft_eat_hp_change(const std::string &subname) +{ + if(subname == "cooked_rat") + return 6; // 3 hearts + return 0; +} + + diff --git a/src/content_inventory.h b/src/content_inventory.h index 0f410128b..91550bb9a 100644 --- a/src/content_inventory.h +++ b/src/content_inventory.h @@ -37,6 +37,8 @@ ServerActiveObject* item_craft_create_object(const std::string &subname, s16 item_craft_get_drop_count(const std::string &subname); bool item_craft_is_cookable(const std::string &subname); InventoryItem* item_craft_create_cook_result(const std::string &subname); +bool item_craft_is_eatable(const std::string &subname); +s16 item_craft_eat_hp_change(const std::string &subname); #endif diff --git a/src/content_sao.cpp b/src/content_sao.cpp index eadaa6e5f..638f50c9d 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -215,6 +215,18 @@ InventoryItem * ItemSAO::createInventoryItem() } } +void ItemSAO::rightClick(Player *player) +{ + dstream<<__FUNCTION_NAME<use(m_env, player); + + if(to_be_deleted) + m_removed = true; +} /* RatSAO diff --git a/src/content_sao.h b/src/content_sao.h index e5b1223d4..060c18341 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -51,6 +51,7 @@ public: std::string getStaticData(); InventoryItem* createInventoryItem(); InventoryItem* createPickedUpItem(){return createInventoryItem();} + void rightClick(Player *player); private: std::string m_inventorystring; v3f m_speed_f; diff --git a/src/game.cpp b/src/game.cpp index 0afb351d1..74b8e5029 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1656,6 +1656,8 @@ void the_game( else if(input->getRightClicked()) { std::cout<getId(), g_selected_item); } } else // selected_object == NULL diff --git a/src/inventory.cpp b/src/inventory.cpp index 7ef7f0138..ca050614f 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content_mapnode.h" #include "content_inventory.h" #include "content_sao.h" +#include "player.h" /* InventoryItem @@ -168,6 +169,20 @@ InventoryItem *CraftItem::createCookResult() return item_craft_create_cook_result(m_subname); } +bool CraftItem::use(ServerEnvironment *env, Player *player) +{ + if(item_craft_is_eatable(m_subname)) + { + s16 hp_change = item_craft_eat_hp_change(m_subname); + if(player->hp + hp_change > 20) + player->hp = 20; + else + player->hp += hp_change; + return true; + } + return false; +} + /* MapBlockObjectItem DEPRECATED TODO: Remove diff --git a/src/inventory.h b/src/inventory.h index 5c64f89bb..66b1cd1f0 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -37,6 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc., class ServerActiveObject; class ServerEnvironment; +class Player; class InventoryItem { @@ -99,12 +100,19 @@ public: /* Other properties */ + // Whether it can be cooked virtual bool isCookable(){return false;} // Time of cooking virtual float getCookTime(){return 3.0;} - // Result of cooking + // Result of cooking (can randomize) virtual InventoryItem *createCookResult(){return NULL;} + + // Eat, press, activate, whatever. + // Called when item is right-clicked when lying on ground. + // If returns true, item shall be deleted. + virtual bool use(ServerEnvironment *env, + Player *player){return false;} protected: u16 m_count; @@ -298,11 +306,16 @@ public: return 0; return QUANTITY_ITEM_MAX_COUNT - m_count; } + /* Other properties */ + bool isCookable(); InventoryItem *createCookResult(); + + bool use(ServerEnvironment *env, Player *player); + /* Special methods */ diff --git a/src/server.cpp b/src/server.cpp index e2e6ce46b..ab60be5cc 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2368,76 +2368,93 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) return; } + // Skip if object has been removed + if(obj->m_removed) + return; + //TODO: Check that object is reasonably close // Left click, pick object up (usually) if(button == 0) { - InventoryList *ilist = player->inventory.getList("main"); - if(g_settings.getBool("creative_mode") == false && ilist != NULL) - { + /* + Try creating inventory item + */ + InventoryItem *item = obj->createPickedUpItem(); - // Skip if inventory has no free space - if(ilist->getUsedSlots() == ilist->getSize()) + if(item) + { + if(g_settings.getBool("creative_mode") == false) { - dout_server<<"Player inventory has no free space"<m_removed) - return; - - /* - Create the inventory item - */ - InventoryItem *item = obj->createPickedUpItem(); - - if(item) - { - // Add to inventory and send inventory - ilist->addItem(item); - UpdateCrafting(player->peer_id); - SendInventory(player->peer_id); - - // Remove object from environment - obj->m_removed = true; - } - else - { - /* - Item cannot be picked up. Punch it instead. - */ - - ToolItem *titem = NULL; - std::string toolname = ""; - - InventoryList *mlist = player->inventory.getList("main"); - if(mlist != NULL) + InventoryList *ilist = player->inventory.getList("main"); + if(ilist != NULL) { - InventoryItem *item = mlist->getItem(item_i); - if(item && (std::string)item->getName() == "ToolItem") + // Skip if inventory has no free space + if(ilist->getUsedSlots() == ilist->getSize()) { - titem = (ToolItem*)item; - toolname = titem->getToolName(); + dout_server<<"Player inventory has no free space"<getPosition(); - v3f objpos = obj->getBasePosition(); - v3f dir = (objpos - playerpos).normalize(); - - u16 wear = obj->punch(toolname, dir); - - if(titem) - { - bool weared_out = titem->addWear(wear); - if(weared_out) - mlist->deleteItem(item_i); + // Add to inventory and send inventory + ilist->addItem(item); + UpdateCrafting(player->peer_id); SendInventory(player->peer_id); + + // Remove object from environment + obj->m_removed = true; } } } + else + { + /* + Item cannot be picked up. Punch it instead. + */ + + ToolItem *titem = NULL; + std::string toolname = ""; + + InventoryList *mlist = player->inventory.getList("main"); + if(mlist != NULL) + { + InventoryItem *item = mlist->getItem(item_i); + if(item && (std::string)item->getName() == "ToolItem") + { + titem = (ToolItem*)item; + toolname = titem->getToolName(); + } + } + + v3f playerpos = player->getPosition(); + v3f objpos = obj->getBasePosition(); + v3f dir = (objpos - playerpos).normalize(); + + u16 wear = obj->punch(toolname, dir); + + if(titem) + { + bool weared_out = titem->addWear(wear); + if(weared_out) + mlist->deleteItem(item_i); + SendInventory(player->peer_id); + } + } + } + // Right click, do something with object + if(button == 1) + { + // Track hp changes super-crappily + u16 oldhp = player->hp; + + // Do stuff + obj->rightClick(player); + + // Send back stuff + if(player->hp != oldhp) + { + SendPlayerHP(player); + } } } else if(command == TOSERVER_GROUND_ACTION) diff --git a/src/serverobject.h b/src/serverobject.h index c008bf93e..01f199a4b 100644 --- a/src/serverobject.h +++ b/src/serverobject.h @@ -42,6 +42,7 @@ Some planning class ServerEnvironment; class InventoryItem; +class Player; class ServerActiveObject : public ActiveObject { @@ -105,6 +106,10 @@ public: */ virtual u16 punch(const std::string &toolname, v3f dir) {return 0;} + + /* + */ + virtual void rightClick(Player *player){} /* Number of players which know about this object. Object won't be From cae422076bc921ab5bc4c8168651534418767c12 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 30 Jul 2011 18:54:02 +0300 Subject: [PATCH 08/14] updated pause menu text a bit --- src/guiPauseMenu.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/guiPauseMenu.cpp b/src/guiPauseMenu.cpp index c10bcf039..7745b8dd2 100644 --- a/src/guiPauseMenu.cpp +++ b/src/guiPauseMenu.cpp @@ -135,10 +135,10 @@ void GUIPauseMenu::regenerateGui(v2u32 screensize) core::rect rect(0, 0, 180, 240); rect = rect + v2s32(size.X/2 + 90, size.Y/2-rect.getHeight()/2); Environment->addStaticText(chartowchar_t(gettext( - "Keys:\n" + "Default Controls:\n" "- WASD: Walk\n" - "- Mouse left: dig blocks\n" - "- Mouse right: place blocks\n" + "- Mouse left: dig/hit\n" + "- Mouse right: place/use\n" "- Mouse wheel: select item\n" "- 0...9: select item\n" "- Shift: sneak\n" From 4b0c3e435715479ce13df7319298884b1589be22 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 30 Jul 2011 19:05:25 +0300 Subject: [PATCH 09/14] Made picking items up in creative mode delete them (because they usually are in the inventory already anyway) --- src/server.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index ab60be5cc..b0c087d09 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2384,10 +2384,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) if(item) { - if(g_settings.getBool("creative_mode") == false) + InventoryList *ilist = player->inventory.getList("main"); + if(ilist != NULL) { - InventoryList *ilist = player->inventory.getList("main"); - if(ilist != NULL) + if(g_settings.getBool("creative_mode") == false) { // Skip if inventory has no free space if(ilist->getUsedSlots() == ilist->getSize()) @@ -2400,10 +2400,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) ilist->addItem(item); UpdateCrafting(player->peer_id); SendInventory(player->peer_id); - - // Remove object from environment - obj->m_removed = true; } + + // Remove object from environment + obj->m_removed = true; } } else From 9b294ffa7a1f3cf7ee19111b7e5f4882f130dd21 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 30 Jul 2011 19:31:33 +0300 Subject: [PATCH 10/14] Added message of the day and made it properly configurable using /#setting (not saved to config file yet) --- src/defaultsettings.cpp | 1 + src/server.cpp | 9 +++++++- src/servercommand.cpp | 3 ++- src/servercommand.h | 5 ++++- src/strfnd.h | 50 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 947892d12..c1104eff0 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -77,6 +77,7 @@ void set_default_settings() g_settings.setDefault("screenshot_path", "."); // Server stuff + g_settings.setDefault("motd", ""); g_settings.setDefault("enable_experimental", "false"); g_settings.setDefault("creative_mode", "false"); g_settings.setDefault("enable_damage", "true"); diff --git a/src/server.cpp b/src/server.cpp index b0c087d09..0b312fbc3 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3196,9 +3196,14 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) line += L"Server: "; message = message.substr(commandprefix.size()); + + WStrfnd f1(message); + f1.next(L" "); + std::wstring paramstring = f1.next(L""); ServerCommandContext *ctx = new ServerCommandContext( str_split(message, L' '), + paramstring, this, &m_env, player, @@ -4018,7 +4023,9 @@ std::wstring Server::getStatusString() } os<isSavingEnabled() == false) - os<<" WARNING: Map saving is disabled."<parms[1] + L" = " + ctx->parms[2]); + std::string confline = wide_to_narrow( + ctx->parms[1] + L" = " + ctx->paramstring); g_settings.parseConfigLine(confline); os<< L"-!- Setting changed."; } diff --git a/src/servercommand.h b/src/servercommand.h index 9013bc2a6..cee4976b1 100644 --- a/src/servercommand.h +++ b/src/servercommand.h @@ -29,6 +29,7 @@ struct ServerCommandContext { std::vector parms; + std::wstring paramstring; Server* server; ServerEnvironment *env; Player* player; @@ -39,11 +40,13 @@ struct ServerCommandContext ServerCommandContext( std::vector parms, + std::wstring paramstring, Server* server, ServerEnvironment *env, Player* player, u64 privs) - : parms(parms), server(server), env(env), player(player), privs(privs) + : parms(parms), paramstring(paramstring), + server(server), env(env), player(player), privs(privs) { } diff --git a/src/strfnd.h b/src/strfnd.h index 2be92d43b..e3d380e37 100644 --- a/src/strfnd.h +++ b/src/strfnd.h @@ -74,6 +74,56 @@ public: } }; +class WStrfnd{ + std::wstring tek; + unsigned int p; +public: + void start(std::wstring niinq){ + tek = niinq; + p=0; + } + unsigned int where(){ + return p; + } + void to(unsigned int i){ + p = i; + } + std::wstring what(){ + return tek; + } + std::wstring next(std::wstring plop){ + //std::cout<<"tek=\""<=tek.size()"<=tek.size()) return true; + return false; + } + WStrfnd(std::wstring s){ + start(s); + } +}; + inline std::string trim(const std::string &s) { std::string str = s; From cdadbdbd17d624dd45cca67f41309cbe776dc348 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 30 Jul 2011 19:49:42 +0300 Subject: [PATCH 11/14] Server configuration is now written when "/#setting whatever = whatever" is issued. --- src/game.cpp | 5 +++-- src/game.h | 3 ++- src/main.cpp | 5 +++-- src/server.cpp | 10 ++++++---- src/server.h | 13 ++++++++++++- src/servercommand.cpp | 12 +++++++++--- src/servermain.cpp | 2 +- 7 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 74b8e5029..6c0474ee7 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -715,7 +715,8 @@ void the_game( std::string password, std::string address, u16 port, - std::wstring &error_message + std::wstring &error_message, + std::string configpath ) { video::IVideoDriver* driver = device->getVideoDriver(); @@ -755,7 +756,7 @@ void the_game( if(address == ""){ draw_load_screen(L"Creating server...", driver, font); std::cout<start(port); } diff --git a/src/game.h b/src/game.h index eb289b8f2..95623316a 100644 --- a/src/game.h +++ b/src/game.h @@ -70,7 +70,8 @@ void the_game( std::string password, std::string address, u16 port, - std::wstring &error_message + std::wstring &error_message, + std::string configpath ); #endif diff --git a/src/main.cpp b/src/main.cpp index 9a9b22f87..3cc748954 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1302,7 +1302,7 @@ int main(int argc, char *argv[]) g_timegetter = new SimpleTimeGetter(); // Create server - Server server(map_dir.c_str()); + Server server(map_dir.c_str(), configpath); server.start(port); // Run server @@ -1641,7 +1641,8 @@ int main(int argc, char *argv[]) password, address, port, - error_message + error_message, + configpath ); } //try diff --git a/src/server.cpp b/src/server.cpp index 0b312fbc3..96e64b314 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1058,7 +1058,8 @@ u32 PIChecksum(core::list &l) */ Server::Server( - std::string mapsavedir + std::string mapsavedir, + std::string configpath ): m_env(new ServerMap(mapsavedir), this), m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this), @@ -1069,6 +1070,7 @@ Server::Server( m_time_of_day_send_timer(0), m_uptime(0), m_mapsavedir(mapsavedir), + m_configpath(configpath), m_shutdown_requested(false), m_ignore_map_edit_events(false), m_ignore_map_edit_events_peer_id(0) @@ -3198,7 +3200,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) message = message.substr(commandprefix.size()); WStrfnd f1(message); - f1.next(L" "); + f1.next(L" "); // Skip over /#whatever std::wstring paramstring = f1.next(L""); ServerCommandContext *ctx = new ServerCommandContext( @@ -4023,9 +4025,9 @@ std::wstring Server::getStatusString() } os<isSavingEnabled() == false) - os<parms[1] + L" = " + ctx->paramstring); + /*std::string confline = wide_to_narrow( + ctx->parms[1] + L" = " + ctx->params[2]);*/ + + std::string confline = wide_to_narrow(ctx->paramstring); + g_settings.parseConfigLine(confline); - os<< L"-!- Setting changed."; + + ctx->server->saveConfig(); + + os<< L"-!- Setting changed and configuration saved."; } void cmd_teleport(std::wostringstream &os, diff --git a/src/servermain.cpp b/src/servermain.cpp index 146c548c5..91fd1d3a5 100644 --- a/src/servermain.cpp +++ b/src/servermain.cpp @@ -323,7 +323,7 @@ int main(int argc, char *argv[]) map_dir = g_settings.get("map-dir"); // Create server - Server server(map_dir.c_str()); + Server server(map_dir.c_str(), configpath); server.start(port); // Run server From 24a662705cb73f8a5630114654c38a0e1328b9ec Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 30 Jul 2011 20:02:17 +0300 Subject: [PATCH 12/14] Added network protocol version number in protocol --- src/client.cpp | 8 ++++++-- src/clientserver.h | 3 ++- src/server.cpp | 19 ++++++++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 7ebb30fba..5f299890a 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -415,8 +415,9 @@ void Client::step(float dtime) // [0] u16 TOSERVER_INIT // [2] u8 SER_FMT_VER_HIGHEST // [3] u8[20] player_name - // [23] u8[28] password - SharedBuffer data(2+1+PLAYERNAME_SIZE+PASSWORD_SIZE); + // [23] u8[28] password (new in some version) + // [51] u16 client network protocol version (new in some version) + SharedBuffer data(2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2); writeU16(&data[0], TOSERVER_INIT); writeU8(&data[2], SER_FMT_VER_HIGHEST); @@ -428,6 +429,9 @@ void Client::step(float dtime) memset((char*)&data[23], 0, PASSWORD_SIZE); snprintf((char*)&data[23], PASSWORD_SIZE, "%s", m_password.c_str()); + + // This should be incremented in each version + writeU16(&data[51], 1); // Send as unreliable Send(0, data, false); diff --git a/src/clientserver.h b/src/clientserver.h index 35484fe76..4981b7ea8 100644 --- a/src/clientserver.h +++ b/src/clientserver.h @@ -171,7 +171,8 @@ enum ToServerCommand [0] u16 TOSERVER_INIT [2] u8 SER_FMT_VER_HIGHEST [3] u8[20] player_name - [23] u8[28] password + [23] u8[28] password (new in some version) + [51] u16 client network protocol version (new in some version) */ TOSERVER_INIT2 = 0x11, diff --git a/src/server.cpp b/src/server.cpp index 96e64b314..ca166eaef 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1966,6 +1966,23 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) derr_server<= 2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2) + { + net_proto_version = readU16(&data[2+1+PLAYERNAME_SIZE+PASSWORD_SIZE]); + } + if(net_proto_version == 0) + { + SendAccessDenied(m_con, peer_id, + L"Your client is too old (network protocol)"); return; } @@ -1999,7 +2016,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) // Get password char password[PASSWORD_SIZE]; - if(datasize == 2+1+PLAYERNAME_SIZE) + if(datasize >= 2+1+PLAYERNAME_SIZE) { // old version - assume blank password password[0] = 0; From f8fca8ca5e1e5cc72ea4a8c46cbf3d4f9a64ad0a Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 30 Jul 2011 20:06:30 +0300 Subject: [PATCH 13/14] easier notice on old version --- src/server.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index ca166eaef..368f0acbf 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1981,9 +1981,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) } if(net_proto_version == 0) { - SendAccessDenied(m_con, peer_id, + /*SendAccessDenied(m_con, peer_id, L"Your client is too old (network protocol)"); - return; + return;*/ + SendChatMessage(peer_id, L"# Server: NOTE: YOUR CLIENT IS OLD AND DOES NOT WORK PROPERLY WITH THIS SERVER"); } /* From f2051c98223d087c8ba3d7e4514935781c93ed1c Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 30 Jul 2011 20:10:16 +0300 Subject: [PATCH 14/14] fix to the former --- src/server.cpp | 15 ++++++++++----- src/server.h | 3 +++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 368f0acbf..07f9875c4 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1979,13 +1979,13 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) { net_proto_version = readU16(&data[2+1+PLAYERNAME_SIZE+PASSWORD_SIZE]); } - if(net_proto_version == 0) + getClient(peer->id)->net_proto_version = net_proto_version; + /*if(net_proto_version == 0) { - /*SendAccessDenied(m_con, peer_id, + SendAccessDenied(m_con, peer_id, L"Your client is too old (network protocol)"); - return;*/ - SendChatMessage(peer_id, L"# Server: NOTE: YOUR CLIENT IS OLD AND DOES NOT WORK PROPERLY WITH THIS SERVER"); - } + return; + }*/ /* Set up player @@ -2182,6 +2182,11 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) BroadcastChatMessage(message); } + if(getClient(peer->id)->net_proto_version == 0) + { + SendChatMessage(peer_id, L"# Server: NOTE: YOUR CLIENT IS OLD AND DOES NOT WORK PROPERLY WITH THIS SERVER"); + } + return; } diff --git a/src/server.h b/src/server.h index c300d40e6..4a2d667a8 100644 --- a/src/server.h +++ b/src/server.h @@ -235,6 +235,8 @@ public: u16 peer_id; // The serialization version to use with the client u8 serialization_version; + // + u16 net_proto_version; // Version is stored in here after INIT before INIT2 u8 pending_serialization_version; @@ -244,6 +246,7 @@ public: { peer_id = 0; serialization_version = SER_FMT_VER_INVALID; + net_proto_version = 0; pending_serialization_version = SER_FMT_VER_INVALID; m_nearest_unsent_d = 0; m_nearest_unsent_reset_timer = 0.0;