From d67004a3be64bfe3e1df5d0771f340ebb0eebabe Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 26 Nov 2012 00:56:47 +0200 Subject: [PATCH 01/30] Bump version to 0.4.4 as this isn't compatible with 0.4.3 --- CMakeLists.txt | 2 +- doc/lua_api.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e7c1f761..23c64541d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string") # Also remember to set PROTOCOL_VERSION in clientserver.h when releasing set(VERSION_MAJOR 0) set(VERSION_MINOR 4) -set(VERSION_PATCH 3) +set(VERSION_PATCH 4) if(VERSION_EXTRA) set(VERSION_PATCH ${VERSION_PATCH}-${VERSION_EXTRA}) endif() diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 0c093b7ee..550716cef 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1,4 +1,4 @@ -Minetest Lua Modding API Reference 0.4.3 +Minetest Lua Modding API Reference 0.4.4 ========================================== More information at http://c55.me/minetest/ From ab507f83e2e0b1f442341724bc47a8480667628e Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 26 Nov 2012 09:10:27 +0200 Subject: [PATCH 02/30] Fix LuaEntitySAO::getClientInitializationData() and bump the related version --- src/content_cao.cpp | 2 +- src/content_sao.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 339c9f248..ce41c8312 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -650,7 +650,7 @@ public: // version u8 version = readU8(is); // check version - if(version != 0){ + if(version != 1){ errorstream<<"GenericCAO: Unsupported init data version" <getName()); // name writeU8(os, 1); // is_player writeS16(os, getId()); //id From 197542c7ec19b41e865be1e84c6c6898de8514d1 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 26 Nov 2012 09:49:07 +0200 Subject: [PATCH 03/30] New PROTOCOL_VERSION scheme (allow client to support a range of versions) --- src/client.cpp | 9 +++++---- src/clientserver.h | 11 +++++++++-- src/server.cpp | 25 ++++++++++++++++++------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index f72c4b654..f6e97c52e 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -499,8 +499,9 @@ void Client::step(float dtime) // [2] u8 SER_FMT_VER_HIGHEST // [3] u8[20] player_name // [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); + // [51] u16 minimum supported network protocol version (added sometime) + // [53] u16 maximum supported network protocol version (added later than the previous one) + SharedBuffer data(2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2+2); writeU16(&data[0], TOSERVER_INIT); writeU8(&data[2], SER_FMT_VER_HIGHEST); @@ -513,8 +514,8 @@ 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], PROTOCOL_VERSION); + writeU16(&data[51], CLIENT_PROTOCOL_VERSION_MIN); + writeU16(&data[53], CLIENT_PROTOCOL_VERSION_MAX); // Send as unreliable Send(0, data, false); diff --git a/src/clientserver.h b/src/clientserver.h index ba535a66b..b7e64d295 100644 --- a/src/clientserver.h +++ b/src/clientserver.h @@ -75,8 +75,14 @@ with this program; if not, write to the Free Software Foundation, Inc., GENERIC_CMD_SET_ATTACHMENT */ -#define PROTOCOL_VERSION 14 +// Server always only supports one version +#define SERVER_PROTOCOL_VERSION 14 +// Client can support older versions too +#define CLIENT_PROTOCOL_VERSION_MIN 13 +#define CLIENT_PROTOCOL_VERSION_MAX SERVER_PROTOCOL_VERSION + +// Constant that differentiates the protocol from random data and other protocols #define PROTOCOL_ID 0x4f457403 #define PASSWORD_SIZE 28 // Maximum password length. Allows for @@ -350,7 +356,8 @@ enum ToServerCommand [2] u8 SER_FMT_VER_HIGHEST [3] u8[20] player_name [23] u8[28] password (new in some version) - [51] u16 client network protocol version (new in some version) + [51] u16 minimum supported network protocol version (added sometime) + [53] u16 maximum supported network protocol version (added later than the previous one) */ TOSERVER_INIT2 = 0x11, diff --git a/src/server.cpp b/src/server.cpp index ac243a29c..f4da73fa5 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2037,11 +2037,22 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) Read and check network protocol version */ - u16 net_proto_version = 0; + u16 min_net_proto_version = 0; if(datasize >= 2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2) - { - net_proto_version = readU16(&data[2+1+PLAYERNAME_SIZE+PASSWORD_SIZE]); - } + min_net_proto_version = readU16(&data[2+1+PLAYERNAME_SIZE+PASSWORD_SIZE]); + + // Use min if version field doesn't exist (backwards compatibility) + u16 max_net_proto_version = min_net_proto_version; + if(datasize >= 2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2+2) + max_net_proto_version = readU16(&data[2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2]); + + u16 net_proto_version = max_net_proto_version; + if(max_net_proto_version != SERVER_PROTOCOL_VERSION && min_net_proto_version <= SERVER_PROTOCOL_VERSION) + net_proto_version = SERVER_PROTOCOL_VERSION; + + verbosestream<<"Server: "<net_proto_version = net_proto_version; @@ -2059,7 +2070,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) if(g_settings->getBool("strict_protocol_version_checking")) { - if(net_proto_version != PROTOCOL_VERSION) + if(net_proto_version != SERVER_PROTOCOL_VERSION) { actionstream<<"Server: A mismatched client tried to connect" <<" from "<net_proto_version < PROTOCOL_VERSION) + if(getClient(peer_id)->net_proto_version < SERVER_PROTOCOL_VERSION) { SendChatMessage(peer_id, L"# Server: WARNING: YOUR CLIENT IS OLD AND MAY WORK PROPERLY WITH THIS SERVER!"); } From 4fa4340b95165bb4cdc88ee6d7cf2d0609d6df13 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 26 Nov 2012 09:49:31 +0200 Subject: [PATCH 04/30] Proper versioning of new network-serialized stuff --- src/content_cao.cpp | 32 +++++--- src/environment.cpp | 5 +- src/nodedef.cpp | 165 +++++++++++++++++++++++++------------- src/object_properties.cpp | 86 +++++++++++++------- 4 files changed, 195 insertions(+), 93 deletions(-) diff --git a/src/content_cao.cpp b/src/content_cao.cpp index ce41c8312..c7d21d278 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -647,22 +647,36 @@ public: { infostream<<"GenericCAO: Got init data"< Date: Mon, 26 Nov 2012 10:20:57 +0200 Subject: [PATCH 05/30] Move a function from clientserver.h to clientserver.cpp --- src/CMakeLists.txt | 1 + src/clientserver.cpp | 31 +++++++++++++++++++++++++++++++ src/clientserver.h | 15 ++++----------- 3 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 src/clientserver.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8cdaa510d..eb42b7d3c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -202,6 +202,7 @@ set(common_SRCS sha1.cpp base64.cpp ban.cpp + clientserver.cpp util/serialize.cpp util/directiontables.cpp util/numeric.cpp diff --git a/src/clientserver.cpp b/src/clientserver.cpp new file mode 100644 index 000000000..bd0a8ede0 --- /dev/null +++ b/src/clientserver.cpp @@ -0,0 +1,31 @@ +/* +Minetest-c55 +Copyright (C) 2010-2012 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "clientserver.h" +#include "util/serialize.h" + +SharedBuffer makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed) +{ + SharedBuffer data(2+2+4); + writeU16(&data[0], TOCLIENT_TIME_OF_DAY); + writeU16(&data[2], time); + writeF1000(&data[4], time_speed); + return data; +} + diff --git a/src/clientserver.h b/src/clientserver.h index b7e64d295..65a14ab38 100644 --- a/src/clientserver.h +++ b/src/clientserver.h @@ -1,6 +1,6 @@ /* Minetest-c55 -Copyright (C) 2010 celeron55, Perttu Ahola +Copyright (C) 2010-2012 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -20,7 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #ifndef CLIENTSERVER_HEADER #define CLIENTSERVER_HEADER -#include "util/serialize.h" +#include "util/pointer.h" + +SharedBuffer makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed); /* changes by PROTOCOL_VERSION: @@ -565,14 +567,5 @@ enum ToServerCommand }; -inline SharedBuffer makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed) -{ - SharedBuffer data(2+2+4); - writeU16(&data[0], TOCLIENT_TIME_OF_DAY); - writeU16(&data[2], time); - writeF1000(&data[4], time_speed); - return data; -} - #endif From eca1c964126cc7f6ae62ab274f7f1a83f03fedfd Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 26 Nov 2012 11:18:34 +0200 Subject: [PATCH 06/30] Move util/serialize.h out from staticobject.h for smaller header dependencies --- src/CMakeLists.txt | 1 + src/client.cpp | 1 + src/environment.cpp | 1 + src/mapblock.cpp | 1 + src/server.cpp | 1 + src/staticobject.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++++ src/staticobject.h | 74 +++-------------------------------- 7 files changed, 102 insertions(+), 69 deletions(-) create mode 100644 src/staticobject.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eb42b7d3c..e1639b46f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -203,6 +203,7 @@ set(common_SRCS base64.cpp ban.cpp clientserver.cpp + staticobject.cpp util/serialize.cpp util/directiontables.cpp util/numeric.cpp diff --git a/src/client.cpp b/src/client.cpp index f6e97c52e..1936c2ce9 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -42,6 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/string.h" #include "hex.h" #include "IMeshCache.h" +#include "util/serialize.h" static std::string getMediaCacheDir() { diff --git a/src/environment.cpp b/src/environment.cpp index 889990ca5..b8e037376 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -43,6 +43,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #endif #include "daynightratio.h" #include "map.h" +#include "util/serialize.h" #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 2ae6e9bd7..e9c8fadff 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapblock_mesh.h" #endif #include "util/string.h" +#include "util/serialize.h" #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" diff --git a/src/server.cpp b/src/server.cpp index f4da73fa5..6f80c82f7 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -54,6 +54,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/pointedthing.h" #include "util/mathconstants.h" #include "rollback.h" +#include "util/serialize.h" #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" diff --git a/src/staticobject.cpp b/src/staticobject.cpp new file mode 100644 index 000000000..2183f2ffe --- /dev/null +++ b/src/staticobject.cpp @@ -0,0 +1,92 @@ +/* +Minetest-c55 +Copyright (C) 2010-2012 celeron55, Perttu Ahola + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "staticobject.h" +#include "util/serialize.h" + +void StaticObject::serialize(std::ostream &os) +{ + char buf[12]; + // type + buf[0] = type; + os.write(buf, 1); + // pos + writeV3S32((u8*)buf, v3s32(pos.X*1000,pos.Y*1000,pos.Z*1000)); + os.write(buf, 12); + // data + os<::Iterator + i = m_stored.begin(); + i != m_stored.end(); i++) + { + StaticObject &s_obj = *i; + s_obj.serialize(os); + } + for(core::map::Iterator + i = m_active.getIterator(); + i.atEnd()==false; i++) + { + StaticObject s_obj = i.getNode()->getValue(); + s_obj.serialize(os); + } +} +void StaticObjectList::deSerialize(std::istream &is) +{ + char buf[12]; + // version + is.read(buf, 1); + u8 version = buf[0]; + // count + is.read(buf, 2); + u16 count = readU16((u8*)buf); + for(u16 i=0; i #include -#include "util/serialize.h" +#include "debug.h" struct StaticObject { @@ -43,33 +43,8 @@ struct StaticObject { } - void serialize(std::ostream &os) - { - char buf[12]; - // type - buf[0] = type; - os.write(buf, 1); - // pos - writeV3S32((u8*)buf, v3s32(pos.X*1000,pos.Y*1000,pos.Z*1000)); - os.write(buf, 12); - // data - os<::Iterator - i = m_stored.begin(); - i != m_stored.end(); i++) - { - StaticObject &s_obj = *i; - s_obj.serialize(os); - } - for(core::map::Iterator - i = m_active.getIterator(); - i.atEnd()==false; i++) - { - StaticObject s_obj = i.getNode()->getValue(); - s_obj.serialize(os); - } - } - void deSerialize(std::istream &is) - { - char buf[12]; - // version - is.read(buf, 1); - u8 version = buf[0]; - // count - is.read(buf, 2); - u16 count = readU16((u8*)buf); - for(u16 i=0; i Date: Mon, 26 Nov 2012 11:39:52 +0200 Subject: [PATCH 07/30] Const-correct SharedBuffer::SharedBuffer(const T *t, unsigned int size) --- src/util/pointer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/pointer.h b/src/util/pointer.h index 766cc2328..775f0a336 100644 --- a/src/util/pointer.h +++ b/src/util/pointer.h @@ -222,7 +222,7 @@ public: /* Copies whole buffer */ - SharedBuffer(T *t, unsigned int size) + SharedBuffer(const T *t, unsigned int size) { m_size = size; if(m_size != 0) From e0eaed5fdbdad79b47c2c6fba15a21dbea03fe96 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 26 Nov 2012 11:56:18 +0200 Subject: [PATCH 08/30] Remove unnecessary util/serialize.h from content_mapblock.cpp --- src/content_mapblock.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/content_mapblock.cpp b/src/content_mapblock.cpp index ff8ef5276..68895c396 100644 --- a/src/content_mapblock.cpp +++ b/src/content_mapblock.cpp @@ -26,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "tile.h" #include "gamedef.h" #include "util/numeric.h" -#include "util/serialize.h" #include "util/directiontables.h" // Create a cuboid. From ffad18e42442fed10c312adc989fc62b74e05896 Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Sat, 24 Nov 2012 19:02:16 +0100 Subject: [PATCH 09/30] Use wielditem drawtype for all nodes in item_entity --- builtin/item_entity.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/item_entity.lua b/builtin/item_entity.lua index 2b12764f1..8657e64af 100644 --- a/builtin/item_entity.lua +++ b/builtin/item_entity.lua @@ -41,17 +41,17 @@ minetest.register_entity("__builtin:item", { prop = { is_visible = true, visual = "sprite", - textures = {"unknown_item.png"} + textures = {"unknown_item.png"}, + visual_size = {x=0.50, y=0.50} } - if item_texture and item_texture ~= "" then - prop.visual = "sprite" - prop.textures = {item_texture} - prop.visual_size = {x=0.50, y=0.50} - else + if item_type == "node" then prop.visual = "wielditem" prop.textures = {itemname} prop.visual_size = {x=0.20, y=0.20} prop.automatic_rotate = math.pi * 0.25 + elseif item_texture and item_texture ~= "" then + prop.visual = "sprite" + prop.textures = {item_texture} end self.object:set_properties(prop) end, From 6b927229f5f9cb9a8163ecec482160975199fa0f Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 26 Nov 2012 22:31:21 +0200 Subject: [PATCH 10/30] Default server step to 0.1s and sync object/player update intervals to it --- minetest.conf.example | 4 ++-- src/client.cpp | 11 ++++++++++- src/client.h | 3 +++ src/clientserver.h | 1 + src/defaultsettings.cpp | 2 +- src/environment.cpp | 8 +++++++- src/environment.h | 6 +++--- src/server.cpp | 3 ++- 8 files changed, 29 insertions(+), 9 deletions(-) diff --git a/minetest.conf.example b/minetest.conf.example index 3f292c01e..aebab825c 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -194,7 +194,7 @@ # To reduce lag, block transfers are slowed down when a player is building something. # This determines how long they are slowed down after placing or removing a node. #full_block_send_enable_min_time_from_building = 2.0 -# Length of a server tick in dedicated server -#dedicated_server_step = 0.05 +# Length of a server tick and the interval at which objects are generally updated over network +#dedicated_server_step = 0.1 # Can be set to true to disable shutting down on invalid world data #ignore_world_load_errors = false diff --git a/src/client.cpp b/src/client.cpp index 1936c2ce9..4117a9130 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -267,6 +267,7 @@ Client::Client( m_time_of_day_set(false), m_last_time_of_day_f(-1), m_time_of_day_update_timer(0), + m_recommended_send_interval(0.1), m_removed_sounds_check_timer(0) { m_packetcounter_timer = 0.0; @@ -658,7 +659,7 @@ void Client::step(float dtime) { float &counter = m_playerpos_send_timer; counter += dtime; - if(counter >= 0.2) + if(counter >= m_recommended_send_interval) { counter = 0.0; sendPlayerPos(); @@ -1022,6 +1023,14 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) m_map_seed = readU64(&data[2+1+6]); infostream<<"Client: received map seed: "<= 2+1+6+8+4) + { + // Get map seed + m_recommended_send_interval = readF1000(&data[2+1+6+8]); + infostream<<"Client: received recommended send interval " + <setDefault("server_unload_unused_data_timeout", "29"); settings->setDefault("server_map_save_interval", "5.3"); settings->setDefault("full_block_send_enable_min_time_from_building", "2.0"); - settings->setDefault("dedicated_server_step", "0.05"); + settings->setDefault("dedicated_server_step", "0.1"); settings->setDefault("ignore_world_load_errors", "false"); settings->setDefault("mip_map", "false"); settings->setDefault("anisotropic_filter", "false"); diff --git a/src/environment.cpp b/src/environment.cpp index b8e037376..e70cb39b7 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -329,7 +329,8 @@ ServerEnvironment::ServerEnvironment(ServerMap *map, lua_State *L, m_send_recommended_timer(0), m_active_block_interval_overload_skip(0), m_game_time(0), - m_game_time_fraction_counter(0) + m_game_time_fraction_counter(0), + m_recommended_send_interval(0.1) { } @@ -940,6 +941,11 @@ void ServerEnvironment::step(float dtime) /* Step time of day */ stepTimeOfDay(dtime); + // Update this one + // NOTE: This is kind of funny on a singleplayer game, but doesn't + // really matter that much. + m_recommended_send_interval = g_settings->getFloat("dedicated_server_step"); + /* Increment game time */ diff --git a/src/environment.h b/src/environment.h index e2028d614..0cc53f9a6 100644 --- a/src/environment.h +++ b/src/environment.h @@ -205,9 +205,7 @@ public: { return m_gamedef; } float getSendRecommendedInterval() - { - return 0.10; - } + { return m_recommended_send_interval; } /* Save players @@ -367,6 +365,8 @@ private: // A helper variable for incrementing the latter float m_game_time_fraction_counter; core::list m_abms; + // An interval for generally sending object positions and stuff + float m_recommended_send_interval; }; #ifndef SERVER diff --git a/src/server.cpp b/src/server.cpp index 6f80c82f7..cb5447605 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2224,11 +2224,12 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) Answer with a TOCLIENT_INIT */ { - SharedBuffer reply(2+1+6+8); + SharedBuffer reply(2+1+6+8+4); writeU16(&reply[0], TOCLIENT_INIT); writeU8(&reply[2], deployed); writeV3S16(&reply[2+1], floatToInt(playersao->getPlayer()->getPosition()+v3f(0,BS/2,0), BS)); writeU64(&reply[2+1+6], m_env->getServerMap().getSeed()); + writeF1000(&reply[2+1+6+8], g_settings->getFloat("dedicated_server_step")); // Send as reliable m_con.Send(peer_id, 0, reply, true); From 5f798d944ee03beca205b107dda58bdc72dd2bf8 Mon Sep 17 00:00:00 2001 From: MirceaKitsune Date: Tue, 27 Nov 2012 01:35:18 +0200 Subject: [PATCH 11/30] Fix forgotten material properties for meshes (also seems to have been forgotten for cubes previously). This allows transparent png images to work properly --- src/content_cao.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/content_cao.cpp b/src/content_cao.cpp index c7d21d278..8229ded62 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -923,6 +923,11 @@ public: m_prop.visual_size.X)); u8 li = m_last_light; setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li)); + + m_meshnode->setMaterialFlag(video::EMF_LIGHTING, false); + m_meshnode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false); + m_meshnode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF); + m_meshnode->setMaterialFlag(video::EMF_FOG_ENABLE, true); } else if(m_prop.visual == "mesh"){ infostream<<"GenericCAO::addToScene(): mesh"<getMesh(), video::SColor(255,li,li,li)); + + m_animated_meshnode->setMaterialFlag(video::EMF_LIGHTING, false); + m_animated_meshnode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false); + m_animated_meshnode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF); + m_animated_meshnode->setMaterialFlag(video::EMF_FOG_ENABLE, true); } else errorstream<<"GenericCAO::addToScene(): Could not load mesh "< Date: Tue, 27 Nov 2012 17:32:58 +0200 Subject: [PATCH 12/30] Revert "Use wielditem drawtype for all nodes in item_entity" This reverts commit ffad18e42442fed10c312adc989fc62b74e05896. --- builtin/item_entity.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/item_entity.lua b/builtin/item_entity.lua index 8657e64af..2b12764f1 100644 --- a/builtin/item_entity.lua +++ b/builtin/item_entity.lua @@ -41,17 +41,17 @@ minetest.register_entity("__builtin:item", { prop = { is_visible = true, visual = "sprite", - textures = {"unknown_item.png"}, - visual_size = {x=0.50, y=0.50} + textures = {"unknown_item.png"} } - if item_type == "node" then + if item_texture and item_texture ~= "" then + prop.visual = "sprite" + prop.textures = {item_texture} + prop.visual_size = {x=0.50, y=0.50} + else prop.visual = "wielditem" prop.textures = {itemname} prop.visual_size = {x=0.20, y=0.20} prop.automatic_rotate = math.pi * 0.25 - elseif item_texture and item_texture ~= "" then - prop.visual = "sprite" - prop.textures = {item_texture} end self.object:set_properties(prop) end, From 5c26972cddb78f3f93d5d6e0428a6b282fde4bfe Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 27 Nov 2012 19:00:09 +0200 Subject: [PATCH 13/30] Fix mesh glitches on MapBlock boundaries --- src/mapblock_mesh.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp index 9ae9b21c0..fdeb31f4d 100644 --- a/src/mapblock_mesh.cpp +++ b/src/mapblock_mesh.cpp @@ -77,9 +77,9 @@ void MeshMakeData::fill(MapBlock *block) // Get map Map *map = block->getParent(); - for(u16 i=0; i<6; i++) + for(u16 i=0; i<26; i++) { - const v3s16 &dir = g_6dirs[i]; + const v3s16 &dir = g_26dirs[i]; v3s16 bp = m_blockpos + dir; MapBlock *b = map->getBlockNoCreateNoEx(bp); if(b) From 655bb526f48a147808eefe47fde38adae88e1915 Mon Sep 17 00:00:00 2001 From: Calinou Date: Wed, 28 Nov 2012 11:59:19 +0100 Subject: [PATCH 14/30] Fix head shifting downards in glass, nodeboxes... --- src/localplayer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 63400cc29..17c4cdeb9 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -323,7 +323,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d, v3s16 camera_np = floatToInt(getEyePosition(), BS); MapNode n = map.getNodeNoEx(camera_np); if(n.getContent() != CONTENT_IGNORE){ - if(nodemgr->get(n).walkable){ + if(nodemgr->get(n).walkable && nodemgr->get(n).solidness == 2){ camera_barely_in_ceiling = true; } } From f720c67f3e3a3be4e7cc8cedb536515e9053641d Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 29 Nov 2012 19:49:44 +0200 Subject: [PATCH 15/30] Change version to 0.4.4-dev because... ehm... why it wasn't that already? --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23c64541d..0bce897bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ set(VERSION_EXTRA "" CACHE STRING "Stuff to append to version string") # Also remember to set PROTOCOL_VERSION in clientserver.h when releasing set(VERSION_MAJOR 0) set(VERSION_MINOR 4) -set(VERSION_PATCH 4) +set(VERSION_PATCH 4-dev) if(VERSION_EXTRA) set(VERSION_PATCH ${VERSION_PATCH}-${VERSION_EXTRA}) endif() From 30ec69c7d393f09bc683ef9894da2ddbae15fc6f Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 29 Nov 2012 19:22:07 +0200 Subject: [PATCH 16/30] Fix Taoki's messed up generic object command ids --- src/genericobject.cpp | 51 +++++++++++++++++++++---------------------- src/genericobject.h | 20 ++++++++--------- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/genericobject.cpp b/src/genericobject.cpp index 654548fa1..398b07feb 100644 --- a/src/genericobject.cpp +++ b/src/genericobject.cpp @@ -92,6 +92,31 @@ std::string gob_cmd_set_sprite( return os.str(); } +std::string gob_cmd_punched(s16 damage, s16 result_hp) +{ + std::ostringstream os(std::ios::binary); + // command + writeU8(os, GENERIC_CMD_PUNCHED); + // damage + writeS16(os, damage); + // result_hp + writeS16(os, result_hp); + return os.str(); +} + +std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups) +{ + std::ostringstream os(std::ios::binary); + writeU8(os, GENERIC_CMD_UPDATE_ARMOR_GROUPS); + writeU16(os, armor_groups.size()); + for(ItemGroupList::const_iterator i = armor_groups.begin(); + i != armor_groups.end(); i++){ + os<first); + writeS16(os, i->second); + } + return os.str(); +} + std::string gob_cmd_update_animation(v2f frames, float frame_speed, float frame_blend) { std::ostringstream os(std::ios::binary); @@ -129,29 +154,3 @@ std::string gob_cmd_update_attachment(int parent_id, std::string bone, v3f posit return os.str(); } -std::string gob_cmd_punched(s16 damage, s16 result_hp) -{ - std::ostringstream os(std::ios::binary); - // command - writeU8(os, GENERIC_CMD_PUNCHED); - // damage - writeS16(os, damage); - // result_hp - writeS16(os, result_hp); - return os.str(); -} - -std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups) -{ - std::ostringstream os(std::ios::binary); - writeU8(os, GENERIC_CMD_UPDATE_ARMOR_GROUPS); - writeU16(os, armor_groups.size()); - for(ItemGroupList::const_iterator i = armor_groups.begin(); - i != armor_groups.end(); i++){ - os<first); - writeS16(os, i->second); - } - return os.str(); -} - - diff --git a/src/genericobject.h b/src/genericobject.h index a46a9474f..b69c24b48 100644 --- a/src/genericobject.h +++ b/src/genericobject.h @@ -28,11 +28,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #define GENERIC_CMD_UPDATE_POSITION 1 #define GENERIC_CMD_SET_TEXTURE_MOD 2 #define GENERIC_CMD_SET_SPRITE 3 -#define GENERIC_CMD_SET_ANIMATION 4 -#define GENERIC_CMD_SET_BONE_POSITION 5 -#define GENERIC_CMD_SET_ATTACHMENT 6 -#define GENERIC_CMD_PUNCHED 7 -#define GENERIC_CMD_UPDATE_ARMOR_GROUPS 8 +#define GENERIC_CMD_PUNCHED 4 +#define GENERIC_CMD_UPDATE_ARMOR_GROUPS 5 +#define GENERIC_CMD_SET_ANIMATION 6 +#define GENERIC_CMD_SET_BONE_POSITION 7 +#define GENERIC_CMD_SET_ATTACHMENT 8 #include "object_properties.h" std::string gob_cmd_set_properties(const ObjectProperties &prop); @@ -57,16 +57,16 @@ std::string gob_cmd_set_sprite( bool select_horiz_by_yawpitch ); +std::string gob_cmd_punched(s16 damage, s16 result_hp); + +#include "itemgroup.h" +std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups); + std::string gob_cmd_update_animation(v2f frames, float frame_speed, float frame_blend); std::string gob_cmd_update_bone_position(std::string bone, v3f position, v3f rotation); std::string gob_cmd_update_attachment(int parent_id, std::string bone, v3f position, v3f rotation); -std::string gob_cmd_punched(s16 damage, s16 result_hp); - -#include "itemgroup.h" -std::string gob_cmd_update_armor_groups(const ItemGroupList &armor_groups); - #endif From 69cdcea9fc30b9522da3f994e77ec54c5c7547af Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 29 Nov 2012 19:44:58 +0200 Subject: [PATCH 17/30] Modify new ObjectProperties format to such that 0.4.3 will eat it --- src/object_properties.cpp | 87 ++++++++++++++------------------------- 1 file changed, 31 insertions(+), 56 deletions(-) diff --git a/src/object_properties.cpp b/src/object_properties.cpp index 3368a5883..ec988a37d 100644 --- a/src/object_properties.cpp +++ b/src/object_properties.cpp @@ -74,86 +74,61 @@ std::string ObjectProperties::dump() void ObjectProperties::serialize(std::ostream &os) const { - writeU8(os, 2); // version + writeU8(os, 1); // version writeS16(os, hp_max); writeU8(os, physical); writeF1000(os, weight); writeV3F1000(os, collisionbox.MinEdge); writeV3F1000(os, collisionbox.MaxEdge); os< Date: Mon, 26 Nov 2012 21:40:39 +0200 Subject: [PATCH 18/30] unit test: TestNodedefSerialization --- src/test.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test.cpp b/src/test.cpp index f81f2910c..52782fa36 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -314,6 +314,26 @@ struct TestSerialization: public TestBase } }; +struct TestNodedefSerialization: public TestBase +{ + void Run() + { + ContentFeatures f; + f.name = "default:stone"; + for(int i = 0; i < 6; i++) + f.tiledef[i].name = "default_stone.png"; + f.is_ground_content = true; + std::ostringstream os(std::ios::binary); + f.serialize(os); + verbosestream<<"Test ContentFeatures size: "< Date: Mon, 26 Nov 2012 23:59:03 +0200 Subject: [PATCH 19/30] Support serialization of protocol 13 ContentFeatures --- src/nodedef.cpp | 296 ++++++++++++++++++++++++++++++------------------ src/nodedef.h | 8 +- src/server.cpp | 11 +- 3 files changed, 195 insertions(+), 120 deletions(-) diff --git a/src/nodedef.cpp b/src/nodedef.cpp index c51b3e6ff..c48e2ff97 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -215,8 +215,13 @@ void ContentFeatures::reset() sound_dug = SimpleSoundSpec(); } -void ContentFeatures::serialize(std::ostream &os) +void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) { + if(protocol_version < 14){ + serializeOld(os, protocol_version); + return; + } + writeU8(os, 6); // version os<serialize(wrapper_os); + f->serialize(wrapper_os, protocol_version); os2<first); + writeS16(os, i->second); + } + writeU8(os, drawtype); + writeF1000(os, visual_scale); + writeU8(os, 6); + for(u32 i=0; i<6; i++) + tiledef[i].serialize(os); + writeU8(os, CF_SPECIAL_COUNT); + for(u32 i=0; iserialization_version - = getClient(peer_id)->pending_serialization_version; + RemoteClient *client = getClient(peer_id); + client->serialization_version = + getClient(peer_id)->pending_serialization_version; /* Send some initialization data @@ -2269,7 +2270,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) SendItemDef(m_con, peer_id, m_itemdef); // Send node definitions - SendNodeDef(m_con, peer_id, m_nodedef); + SendNodeDef(m_con, peer_id, m_nodedef, client->net_proto_version); // Send media announcement sendMediaAnnouncement(peer_id); @@ -3521,7 +3522,7 @@ void Server::SendItemDef(con::Connection &con, u16 peer_id, } void Server::SendNodeDef(con::Connection &con, u16 peer_id, - INodeDefManager *nodedef) + INodeDefManager *nodedef, u16 protocol_version) { DSTACK(__FUNCTION_NAME); std::ostringstream os(std::ios_base::binary); @@ -3533,7 +3534,7 @@ void Server::SendNodeDef(con::Connection &con, u16 peer_id, */ writeU16(os, TOCLIENT_NODEDEF); std::ostringstream tmp_os(std::ios::binary); - nodedef->serialize(tmp_os); + nodedef->serialize(tmp_os, protocol_version); std::ostringstream tmp_os2(std::ios::binary); compressZlib(tmp_os.str(), tmp_os2); os< Date: Mon, 26 Nov 2012 23:58:27 +0200 Subject: [PATCH 20/30] Ranged support of protocol version on server side --- src/clientserver.h | 13 +++++++++---- src/server.cpp | 34 ++++++++++++++++++++++++++-------- src/server.h | 2 +- src/test.cpp | 3 ++- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/clientserver.h b/src/clientserver.h index 6d4998550..d77772416 100644 --- a/src/clientserver.h +++ b/src/clientserver.h @@ -75,14 +75,19 @@ SharedBuffer makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed); GENERIC_CMD_SET_ANIMATION GENERIC_CMD_SET_BONE_POSITION GENERIC_CMD_SET_ATTACHMENT + PROTOCOL_VERSION 15: + Serialization format changes */ -// Server always only supports one version -#define SERVER_PROTOCOL_VERSION 14 +#define LATEST_PROTOCOL_VERSION 15 -// Client can support older versions too +// Server's supported network protocol range +#define SERVER_PROTOCOL_VERSION_MIN 14 +#define SERVER_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION + +// Client's supported network protocol range #define CLIENT_PROTOCOL_VERSION_MIN 13 -#define CLIENT_PROTOCOL_VERSION_MAX SERVER_PROTOCOL_VERSION +#define CLIENT_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION // Constant that differentiates the protocol from random data and other protocols #define PROTOCOL_ID 0x4f457403 diff --git a/src/server.cpp b/src/server.cpp index f29155ba0..41765ed19 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2042,14 +2042,26 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) if(datasize >= 2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2) min_net_proto_version = readU16(&data[2+1+PLAYERNAME_SIZE+PASSWORD_SIZE]); - // Use min if version field doesn't exist (backwards compatibility) + // Use same version as minimum and maximum if maximum version field + // doesn't exist (backwards compatibility) u16 max_net_proto_version = min_net_proto_version; if(datasize >= 2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2+2) max_net_proto_version = readU16(&data[2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2]); + // Start with client's maximum version u16 net_proto_version = max_net_proto_version; - if(max_net_proto_version != SERVER_PROTOCOL_VERSION && min_net_proto_version <= SERVER_PROTOCOL_VERSION) - net_proto_version = SERVER_PROTOCOL_VERSION; + + // Figure out a working version if it is possible at all + if(max_net_proto_version >= SERVER_PROTOCOL_VERSION_MIN || + min_net_proto_version <= SERVER_PROTOCOL_VERSION_MAX) + { + // If maximum is larger than our maximum, go with our maximum + if(max_net_proto_version > SERVER_PROTOCOL_VERSION_MAX) + net_proto_version = SERVER_PROTOCOL_VERSION_MAX; + // Else go with client's maximum + else + net_proto_version = max_net_proto_version; + } verbosestream<<"Server: "<getBool("strict_protocol_version_checking")) { - if(net_proto_version != SERVER_PROTOCOL_VERSION) + if(net_proto_version < SERVER_PROTOCOL_VERSION_MIN || + net_proto_version > SERVER_PROTOCOL_VERSION_MAX) { actionstream<<"Server: A mismatched client tried to connect" <<" from "<net_proto_version < SERVER_PROTOCOL_VERSION) + if(getClient(peer_id)->net_proto_version < LATEST_PROTOCOL_VERSION) { - SendChatMessage(peer_id, L"# Server: WARNING: YOUR CLIENT IS OLD AND MAY WORK PROPERLY WITH THIS SERVER!"); + SendChatMessage(peer_id, L"# Server: WARNING: YOUR CLIENT IS OLD " + L"AND MAY NOT FULLY WORK WITH THIS SERVER!"); } /* diff --git a/src/server.h b/src/server.h index 223c1b0ff..f770fa3d4 100644 --- a/src/server.h +++ b/src/server.h @@ -602,7 +602,7 @@ private: static void SendItemDef(con::Connection &con, u16 peer_id, IItemDefManager *itemdef); static void SendNodeDef(con::Connection &con, u16 peer_id, - INodeDefManager *nodedef); + INodeDefManager *nodedef, u16 protocol_version); /* Non-static send methods. diff --git a/src/test.cpp b/src/test.cpp index 52782fa36..bc0692a78 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -41,6 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/numeric.h" #include "util/serialize.h" #include "noise.h" // PseudoRandom used for random data for compression +#include "clientserver.h" // LATEST_PROTOCOL_VERSION /* Asserts that the exception occurs @@ -324,7 +325,7 @@ struct TestNodedefSerialization: public TestBase f.tiledef[i].name = "default_stone.png"; f.is_ground_content = true; std::ostringstream os(std::ios::binary); - f.serialize(os); + f.serialize(os, LATEST_PROTOCOL_VERSION); verbosestream<<"Test ContentFeatures size: "< Date: Tue, 27 Nov 2012 00:15:17 +0200 Subject: [PATCH 21/30] Allow server to accept protocol 13 clients altough they don't work too well --- src/clientserver.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clientserver.h b/src/clientserver.h index d77772416..6f9396c02 100644 --- a/src/clientserver.h +++ b/src/clientserver.h @@ -82,7 +82,7 @@ SharedBuffer makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed); #define LATEST_PROTOCOL_VERSION 15 // Server's supported network protocol range -#define SERVER_PROTOCOL_VERSION_MIN 14 +#define SERVER_PROTOCOL_VERSION_MIN 13 #define SERVER_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION // Client's supported network protocol range From 96a286dcf501e1a749767e20327613c02bb1ff63 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 27 Nov 2012 00:26:19 +0200 Subject: [PATCH 22/30] Make strict and non-strict protocol version checking to work more like expected --- minetest.conf.example | 4 ++-- src/defaultsettings.cpp | 2 +- src/server.cpp | 32 +++++++++++++++++++------------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/minetest.conf.example b/minetest.conf.example index aebab825c..64cb87727 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -139,8 +139,8 @@ #motd = Welcome to this awesome Minetest server! # Maximum number of players connected simultaneously #max_users = 100 -# Set to false to allow old clients to connect -#strict_protocol_version_checking = true +# Set to true to disallow old clients from connecting +#strict_protocol_version_checking = false # Set to true to enable creative mode (unlimited inventory) #creative_mode = false # Enable players getting damage and dying diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index e9c2ba3b8..8ce9cb1fb 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -111,7 +111,7 @@ void set_default_settings(Settings *settings) settings->setDefault("default_game", "minetest"); settings->setDefault("motd", ""); settings->setDefault("max_users", "100"); - settings->setDefault("strict_protocol_version_checking", "true"); + settings->setDefault("strict_protocol_version_checking", "false"); settings->setDefault("creative_mode", "false"); settings->setDefault("enable_damage", "true"); settings->setDefault("only_peaceful_mobs", "false"); diff --git a/src/server.cpp b/src/server.cpp index 41765ed19..684e3bb08 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2069,33 +2069,39 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) getClient(peer_id)->net_proto_version = net_proto_version; - if(net_proto_version == 0) + if(net_proto_version < SERVER_PROTOCOL_VERSION_MIN || + net_proto_version > SERVER_PROTOCOL_VERSION_MAX) { - actionstream<<"Server: An old tried to connect from "<getBool("strict_protocol_version_checking")) { - if(net_proto_version < SERVER_PROTOCOL_VERSION_MIN || - net_proto_version > SERVER_PROTOCOL_VERSION_MAX) + if(net_proto_version != LATEST_PROTOCOL_VERSION) { - actionstream<<"Server: A mismatched client tried to connect" - <<" from "<net_proto_version < LATEST_PROTOCOL_VERSION) { - SendChatMessage(peer_id, L"# Server: WARNING: YOUR CLIENT IS OLD " - L"AND MAY NOT FULLY WORK WITH THIS SERVER!"); + SendChatMessage(peer_id, L"# Server: WARNING: YOUR CLIENT'S " + L"VERSION MAY NOT BE FULLY COMPATIBLE WITH THIS SERVER!"); } /* From 7b6d6423004343c73fd37726fbbb9f981a50f271 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 27 Nov 2012 00:47:03 +0200 Subject: [PATCH 23/30] Full protocol 13 compatibility on server side --- src/content_sao.cpp | 94 ++++++++++++++++++++++++++++++--------------- src/content_sao.h | 4 +- src/server.cpp | 8 ++-- src/serverobject.h | 2 +- 4 files changed, 71 insertions(+), 37 deletions(-) diff --git a/src/content_sao.cpp b/src/content_sao.cpp index efc14570a..8916b4926 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -245,7 +245,7 @@ public: } } - std::string getClientInitializationData() + std::string getClientInitializationData(u16 protocol_version) { std::ostringstream os(std::ios::binary); // version @@ -564,25 +564,41 @@ void LuaEntitySAO::step(float dtime, bool send_recommended) } } -std::string LuaEntitySAO::getClientInitializationData() +std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version) { std::ostringstream os(std::ios::binary); - writeU8(os, 1); // version - os< >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){ - os<= 14) + { + writeU8(os, 1); // version + os< >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){ + os<getBool("unlimited_player_transfer_distance"); } -std::string PlayerSAO::getClientInitializationData() +std::string PlayerSAO::getClientInitializationData(u16 protocol_version) { std::ostringstream os(std::ios::binary); - writeU8(os, 1); // version - os<getName()); // name - writeU8(os, 1); // is_player - writeS16(os, getId()); //id - writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0)); - writeF1000(os, m_player->getYaw()); - writeS16(os, getHP()); - writeU8(os, 4 + m_bone_position.size()); // number of messages stuffed in here - os< >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){ - os<= 15) + { + writeU8(os, 1); // version + os<getName()); // name + writeU8(os, 1); // is_player + writeS16(os, getId()); //id + writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0)); + writeF1000(os, m_player->getYaw()); + writeS16(os, getHP()); + + writeU8(os, 4 + m_bone_position.size()); // number of messages stuffed in here + os< >::const_iterator ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii){ + os<getName()); // name + writeU8(os, 1); // is_player + writeV3F1000(os, m_player->getPosition() + v3f(0,BS*1,0)); + writeF1000(os, m_player->getYaw()); + writeS16(os, getHP()); + writeU8(os, 2); // number of messages stuffed in here + os<getClientInitializationData())); + obj->getClientInitializationData(client->net_proto_version))); else data_buffer.append(serializeLongString("")); @@ -2407,7 +2407,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) if(command == TOSERVER_PLAYERPOS) { - if(datasize < 2+12+12+4+4+4) + if(datasize < 2+12+12+4+4) return; u32 start = 0; @@ -2415,7 +2415,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) v3s32 ss = readV3S32(&data[start+2+12]); f32 pitch = (f32)readS32(&data[2+12+12]) / 100.0; f32 yaw = (f32)readS32(&data[2+12+12+4]) / 100.0; - u32 keyPressed = (u32)readU32(&data[2+12+12+4+4]); + u32 keyPressed = 0; + if(datasize >= 2+12+12+4+4+4) + keyPressed = (u32)readU32(&data[2+12+12+4+4]); v3f position((f32)ps.X/100., (f32)ps.Y/100., (f32)ps.Z/100.); v3f speed((f32)ss.X/100., (f32)ss.Y/100., (f32)ss.Z/100.); pitch = wrapDegrees(pitch); diff --git a/src/serverobject.h b/src/serverobject.h index 1bbd3e4e8..14752878f 100644 --- a/src/serverobject.h +++ b/src/serverobject.h @@ -118,7 +118,7 @@ public: The return value of this is passed to the client-side object when it is created */ - virtual std::string getClientInitializationData(){return "";} + virtual std::string getClientInitializationData(u16 protocol_version){return "";} /* The return value of this is passed to the server-side object From ab45133ab4826359ca9a5ed50b68150eb462c8ef Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 27 Nov 2012 09:38:21 +0200 Subject: [PATCH 24/30] Add congestion control settings to minetest.conf --- minetest.conf.example | 5 +++++ src/connection.cpp | 28 ++++++++++++++++++++++------ src/connection.h | 6 +++++- src/defaultsettings.cpp | 13 ++++++++----- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/minetest.conf.example b/minetest.conf.example index 64cb87727..071b97c65 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -198,3 +198,8 @@ #dedicated_server_step = 0.1 # Can be set to true to disable shutting down on invalid world data #ignore_world_load_errors = false +# Congestion control parameters +# time in seconds, rate in ~500B packets +#congestion_control_aim_rtt = 0.2 +#congestion_control_max_rate = 400 +#congestion_control_min_rate = 10 diff --git a/src/connection.cpp b/src/connection.cpp index 4f5d095e5..ed5a752be 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/serialize.h" #include "util/numeric.h" #include "util/string.h" +#include "settings.h" namespace con { @@ -466,7 +467,10 @@ Peer::Peer(u16 a_id, Address a_address): m_sendtime_accu(0), m_max_packets_per_second(10), m_num_sent(0), - m_max_num_sent(0) + m_max_num_sent(0), + congestion_control_aim_rtt(0.2), + congestion_control_max_rate(400), + congestion_control_min_rate(10) { } Peer::~Peer() @@ -477,15 +481,15 @@ void Peer::reportRTT(float rtt) { if(rtt >= 0.0){ if(rtt < 0.01){ - if(m_max_packets_per_second < 400) + if(m_max_packets_per_second < congestion_control_max_rate) m_max_packets_per_second += 10; - } else if(rtt < 0.2){ - if(m_max_packets_per_second < 100) + } else if(rtt < congestion_control_aim_rtt){ + if(m_max_packets_per_second < congestion_control_max_rate) m_max_packets_per_second += 2; } else { m_max_packets_per_second *= 0.8; - if(m_max_packets_per_second < 10) - m_max_packets_per_second = 10; + if(m_max_packets_per_second < congestion_control_min_rate) + m_max_packets_per_second = congestion_control_min_rate; } } @@ -891,12 +895,24 @@ void Connection::receive() void Connection::runTimeouts(float dtime) { + float congestion_control_aim_rtt + = g_settings->getFloat("congestion_control_aim_rtt"); + float congestion_control_max_rate + = g_settings->getFloat("congestion_control_max_rate"); + float congestion_control_min_rate + = g_settings->getFloat("congestion_control_min_rate"); + core::list timeouted_peers; core::map::Iterator j; j = m_peers.getIterator(); for(; j.atEnd() == false; j++) { Peer *peer = j.getNode()->getValue(); + + // Update congestion control values + peer->congestion_control_aim_rtt = congestion_control_aim_rtt; + peer->congestion_control_max_rate = congestion_control_max_rate; + peer->congestion_control_min_rate = congestion_control_min_rate; /* Check peer timeout diff --git a/src/connection.h b/src/connection.h index f88e813a3..f99cd1bf9 100644 --- a/src/connection.h +++ b/src/connection.h @@ -394,7 +394,11 @@ public: float m_max_packets_per_second; int m_num_sent; int m_max_num_sent; - + + // Updated from configuration by Connection + float congestion_control_aim_rtt; + float congestion_control_max_rate; + float congestion_control_min_rate; private: }; diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 8ce9cb1fb..d186427e7 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -106,6 +106,11 @@ void set_default_settings(Settings *settings) settings->setDefault("sound_volume", "0.8"); settings->setDefault("desynchronize_mapblock_texture_animation", "true"); + settings->setDefault("mip_map", "false"); + settings->setDefault("anisotropic_filter", "false"); + settings->setDefault("bilinear_filter", "false"); + settings->setDefault("trilinear_filter", "false"); + // Server stuff // "map-dir" doesn't exist by default. settings->setDefault("default_game", "minetest"); @@ -142,10 +147,8 @@ void set_default_settings(Settings *settings) settings->setDefault("full_block_send_enable_min_time_from_building", "2.0"); settings->setDefault("dedicated_server_step", "0.1"); settings->setDefault("ignore_world_load_errors", "false"); - settings->setDefault("mip_map", "false"); - settings->setDefault("anisotropic_filter", "false"); - settings->setDefault("bilinear_filter", "false"); - settings->setDefault("trilinear_filter", "false"); - + settings->setDefault("congestion_control_aim_rtt", "0.2"); + settings->setDefault("congestion_control_max_rate", "400"); + settings->setDefault("congestion_control_min_rate", "10"); } From 6c8fa83ecd3f40a8e2fec890caaaa955f9d4255c Mon Sep 17 00:00:00 2001 From: Matthew I Date: Sat, 8 Sep 2012 14:44:26 -0400 Subject: [PATCH 25/30] Add shutdown hook interface to Lua API Scripts can call minetest.register_on_shutdown() to register a shutdown hook. Document that minetest.register_on_shutdown() callbacks may not be run If the server crashes, it is unlikely that callbacks registered using minetest.register_on_shutdown() will be called. --- builtin/misc_register.lua | 1 + doc/lua_api.txt | 5 +++++ src/scriptapi.cpp | 13 +++++++++++++ src/scriptapi.h | 3 +++ src/server.cpp | 5 +++++ 5 files changed, 27 insertions(+) diff --git a/builtin/misc_register.lua b/builtin/misc_register.lua index 77c594de2..f9c06a02a 100644 --- a/builtin/misc_register.lua +++ b/builtin/misc_register.lua @@ -303,6 +303,7 @@ end minetest.registered_on_chat_messages, minetest.register_on_chat_message = make_registration() minetest.registered_globalsteps, minetest.register_globalstep = make_registration() +minetest.registered_on_shutdown, minetest.register_on_shutdown = make_registration() minetest.registered_on_punchnodes, minetest.register_on_punchnode = make_registration() minetest.registered_on_placenodes, minetest.register_on_placenode = make_registration() minetest.registered_on_dignodes, minetest.register_on_dignode = make_registration() diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 550716cef..e32efc6df 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -792,6 +792,11 @@ minetest.register_craft(recipe) Global callback registration functions: (Call these only at load time) minetest.register_globalstep(func(dtime)) ^ Called every server step, usually interval of 0.05s +minetest.register_on_shutdown(func()) +^ Called before server shutdown +^ WARNING: If the server terminates abnormally (i.e. crashes), the registered + callbacks WILL LIKELY NOT BE RUN. Data should be saved at + semi-frequent intervals as well as on server shutdown. minetest.register_on_placenode(func(pos, newnode, placer, oldnode)) ^ Called when a node has been placed ^ Deprecated: Use on_construct or after_place_node in node definition instead diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 91100d311..e5815c462 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -5576,6 +5576,19 @@ bool scriptapi_on_chat_message(lua_State *L, const std::string &name, return ate; } +void scriptapi_on_shutdown(lua_State *L) +{ + realitycheck(L); + assert(lua_checkstack(L, 20)); + StackUnroller stack_unroller(L); + + // Get registered shutdown hooks + lua_getglobal(L, "minetest"); + lua_getfield(L, -1, "registered_on_shutdown"); + // Call callbacks + scriptapi_run_callbacks(L, 0, RUN_CALLBACKS_MODE_FIRST); +} + void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player) { realitycheck(L); diff --git a/src/scriptapi.h b/src/scriptapi.h index 144cb3bc6..d71b8fe41 100644 --- a/src/scriptapi.h +++ b/src/scriptapi.h @@ -55,6 +55,9 @@ void scriptapi_environment_step(lua_State *L, float dtime); void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp, u32 blockseed); +/* server */ +void scriptapi_on_shutdown(lua_State *L); + /* misc */ void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player); void scriptapi_on_dieplayer(lua_State *L, ServerActiveObject *player); diff --git a/src/server.cpp b/src/server.cpp index 961bdeaf9..67c1ce927 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1112,6 +1112,11 @@ Server::~Server() {} } } + + /* + Execute script shutdown hooks + */ + scriptapi_on_shutdown(m_lua); { JMutexAutoLock envlock(m_env_mutex); From 8a93581c8ab457819a258286aca4ef4359d80877 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 30 Nov 2012 19:41:13 +0200 Subject: [PATCH 26/30] Run scriptapi_on_shutdown() thread-safely and remove some old crap --- src/server.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 67c1ce927..a793c6e2a 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1113,11 +1113,16 @@ Server::~Server() } } - /* - Execute script shutdown hooks - */ - scriptapi_on_shutdown(m_lua); - + { + JMutexAutoLock envlock(m_env_mutex); + JMutexAutoLock conlock(m_con_mutex); + + /* + Execute script shutdown hooks + */ + scriptapi_on_shutdown(m_lua); + } + { JMutexAutoLock envlock(m_env_mutex); @@ -1149,14 +1154,6 @@ Server::~Server() i = m_clients.getIterator(); i.atEnd() == false; i++) { - /*// 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(); } From 6cf87e1d23d829cc0d5c07160e8135ff5887d90d Mon Sep 17 00:00:00 2001 From: Matthew I Date: Sun, 7 Oct 2012 10:03:22 -0400 Subject: [PATCH 27/30] Ignore directories beginning with a "." when searching for mods This is not a problem on POSIX systems (these directories are ignored by the POSIX implementation of fs::GetDirListing() in filesys.cpp), but these directories still are reported on Windows systems. This becomes a problem when mod authors use version control systems that create directories like ".git" or ".svn" and collectMods() picks up on them. It has also been suggested that ignoring such directories would allow for the easily disabling mods by inserting a "." in front of their name. This quick fix simply makes collectMods() ignore directories beginning with a ".". --- src/mods.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mods.cpp b/src/mods.cpp index c2bb907c2..08e8e276f 100644 --- a/src/mods.cpp +++ b/src/mods.cpp @@ -39,6 +39,10 @@ static void collectMods(const std::string &modspath, if(!dirlist[j].dir) continue; std::string modname = dirlist[j].name; + // Ignore all directories beginning with a ".", especially + // VCS directories like ".git" or ".svn" + if(modname[0] == '.') + continue; std::string modpath = modspath + DIR_DELIM + modname; TRACESTREAM(< Date: Wed, 28 Nov 2012 18:39:58 +0100 Subject: [PATCH 28/30] Make dragged itemstack following the mouse cursor much smoother by using the cursor coordinates directly, instead of updating them only when a mouse event is seen. --- src/game.cpp | 4 ++-- src/guiFormSpecMenu.cpp | 18 ++++++------------ src/guiFormSpecMenu.h | 3 ++- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 5ce214cb8..edc3ce741 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1513,7 +1513,7 @@ void the_game( <<"Launching inventory"<setFormSpec(meta->getString("formspec"), diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp index 4db020c11..618141d24 100644 --- a/src/guiFormSpecMenu.cpp +++ b/src/guiFormSpecMenu.cpp @@ -125,13 +125,14 @@ void drawItemStack(video::IVideoDriver *driver, GUIFormSpecMenu */ -GUIFormSpecMenu::GUIFormSpecMenu(gui::IGUIEnvironment* env, +GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, InventoryManager *invmgr, IGameDef *gamedef ): - GUIModalMenu(env, parent, id, menumgr), + GUIModalMenu(dev->getGUIEnvironment(), parent, id, menumgr), + m_device(dev), m_invmgr(invmgr), m_gamedef(gamedef), m_form_src(NULL), @@ -698,6 +699,8 @@ void GUIFormSpecMenu::drawMenu() } } + m_pointer = m_device->getCursorControl()->getPosition(); + updateSelectedItem(); gui::IGUISkin* skin = Environment->getSkin(); @@ -937,24 +940,15 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) return true; } } - if(event.EventType==EET_MOUSE_INPUT_EVENT - && event.MouseInput.Event == EMIE_MOUSE_MOVED) - { - // Mouse moved - m_pointer = v2s32(event.MouseInput.X, event.MouseInput.Y); - } if(event.EventType==EET_MOUSE_INPUT_EVENT && event.MouseInput.Event != EMIE_MOUSE_MOVED) { // Mouse event other than movement - v2s32 p(event.MouseInput.X, event.MouseInput.Y); - m_pointer = p; - // Get selected item and hovered/clicked item (s) updateSelectedItem(); - ItemSpec s = getItemAtPos(p); + ItemSpec s = getItemAtPos(m_pointer); Inventory *inv_selected = NULL; Inventory *inv_s = NULL; diff --git a/src/guiFormSpecMenu.h b/src/guiFormSpecMenu.h index 890b54d61..e6a2efe42 100644 --- a/src/guiFormSpecMenu.h +++ b/src/guiFormSpecMenu.h @@ -144,7 +144,7 @@ class GUIFormSpecMenu : public GUIModalMenu }; public: - GUIFormSpecMenu(gui::IGUIEnvironment* env, + GUIFormSpecMenu(irr::IrrlichtDevice* dev, gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, InventoryManager *invmgr, @@ -197,6 +197,7 @@ protected: v2s32 spacing; v2s32 imgsize; + irr::IrrlichtDevice* m_device; InventoryManager *m_invmgr; IGameDef *m_gamedef; From 84ace278729a965c8eecc6ee1b6bbedaa27705f0 Mon Sep 17 00:00:00 2001 From: DannyDark Date: Thu, 29 Nov 2012 19:00:33 +0000 Subject: [PATCH 29/30] Log /grant and /revoke command usage --- builtin/chatcommands.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/chatcommands.lua b/builtin/chatcommands.lua index f25a276ea..f41f9afe4 100644 --- a/builtin/chatcommands.lua +++ b/builtin/chatcommands.lua @@ -138,6 +138,7 @@ minetest.register_chatcommand("grant", { return end minetest.set_player_privs(grantname, privs) + minetest.log(name..' granted ('..minetest.privs_to_string(grantprivs, ', ')..') privileges to '..grantname) minetest.chat_send_player(name, "Privileges of "..grantname..": "..minetest.privs_to_string(minetest.get_player_privs(grantname), ' ')) if grantname ~= name then minetest.chat_send_player(grantname, name.." granted you privileges: "..minetest.privs_to_string(grantprivs, ' ')) @@ -175,6 +176,7 @@ minetest.register_chatcommand("revoke", { end end minetest.set_player_privs(revokename, privs) + minetest.log(name..' revoked ('..minetest.privs_to_string(revokeprivs, ', ')..') privileges from '..revokename) minetest.chat_send_player(name, "Privileges of "..revokename..": "..minetest.privs_to_string(minetest.get_player_privs(revokename), ' ')) if revokename ~= name then minetest.chat_send_player(revokename, name.." revoked privileges from you: "..minetest.privs_to_string(revokeprivs, ' ')) From 778d9b0cd609ee24a86e88dbd1fe396d809683d9 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Fri, 30 Nov 2012 22:19:50 +0200 Subject: [PATCH 30/30] Add the ability for client to check if image exists --- src/tile.cpp | 16 ++++++++++++++++ src/tile.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/tile.cpp b/src/tile.cpp index f7f1779ca..7cad1b836 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -372,6 +372,18 @@ public: // Update new texture pointer and texture coordinates to an // AtlasPointer based on it's texture id void updateAP(AtlasPointer &ap); + + bool isKnownSourceImage(const std::string &name) + { + bool is_known = false; + bool cache_found = m_source_image_existence.get(name, &is_known); + if(cache_found) + return is_known; + // Not found in cache; find out if a local file exists + is_known = (getTexturePath(name) != ""); + m_source_image_existence.set(name, is_known); + return is_known; + } // Processes queued texture requests from other threads. // Shall be called from the main thread. @@ -400,6 +412,9 @@ private: // This should be only accessed from the main thread SourceImageCache m_sourcecache; + // Thread-safe cache of what source images are known (true = known) + MutexedMap m_source_image_existence; + // A texture id is index in this array. // The first position contains a NULL texture. core::array m_atlaspointer_cache; @@ -781,6 +796,7 @@ void TextureSource::insertSourceImage(const std::string &name, video::IImage *im assert(get_current_thread_id() == m_main_thread); m_sourcecache.insert(name, img, true, m_device->getVideoDriver()); + m_source_image_existence.set(name, true); } void TextureSource::rebuildImagesAndTextures() diff --git a/src/tile.h b/src/tile.h index ae986e797..12c40c833 100644 --- a/src/tile.h +++ b/src/tile.h @@ -131,6 +131,7 @@ public: virtual IrrlichtDevice* getDevice() {return NULL;} virtual void updateAP(AtlasPointer &ap){}; + virtual bool isKnownSourceImage(const std::string &name)=0; }; class IWritableTextureSource : public ITextureSource @@ -149,6 +150,7 @@ public: virtual IrrlichtDevice* getDevice() {return NULL;} virtual void updateAP(AtlasPointer &ap){}; + virtual bool isKnownSourceImage(const std::string &name)=0; virtual void processQueue()=0; virtual void insertSourceImage(const std::string &name, video::IImage *img)=0;