1
0

Compare commits

...

8 Commits

Author SHA1 Message Date
3567eb2c01 Merge branch 'main' of https://github.com/MultiCraft/MultiCraft to sync upstream 2023-09-25 10:35:57 -04:00
4a9327f195 Revert "Drop support for connecting to MT 0.4 servers" for our finalminetest
* This reverts commit f2ca6a6ca5e9dfe7bda3630a1ae41a94f7d02125.
* now all clients can connect to older servers or server
2023-09-25 10:03:14 -04:00
Deve
5b9ca22c57
Free loaded data after alBufferData() (#147)
https://github.com/kcat/openal-soft/blob/master/examples/alplay.c#L266
2023-09-22 00:14:00 +03:00
Maksym H
6cc875cc32 MainMenu: minor cleanup 2023-09-21 01:57:52 +03:00
Maksym H
8a93f5492e Apple: Xcode 15 support 2023-09-21 01:50:55 +03:00
Maksym H
3d80a69b47 Drop only 1 item if sneak is pressed 2023-09-18 17:18:26 +03:00
Deve
52228db808
Mobile: improve the chat experience (#146)
* Some chat input dialog fixes.

- If getAndroidChatOpen() is true then input dialog is created by chat.
- Hide touchscreengui when chat input dialog is open.

* Check input dialog owner in config registration, just in case

* Make sure there is no menu active before showing touchscreengui

* Reset input dialog owner when reading value
2023-09-17 19:18:40 +03:00
Maksym H
2c244aa28c Fix background image scaling in MainMenu 2023-09-17 19:02:24 +03:00
44 changed files with 892 additions and 491 deletions

View File

@ -259,6 +259,9 @@ class GameActivity : SDLActivity() {
} }
} }
@Suppress("unused")
fun isDialogActive() = isInputActive
@Suppress("unused") @Suppress("unused")
fun getDialogState() = messageReturnCode fun getDialogState() = messageReturnCode

View File

@ -2215,6 +2215,7 @@
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
GCC_PREPROCESSOR_DEFINITIONS = ( GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)", "$(inherited)",
_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION,
"RUN_IN_PLACE=0", "RUN_IN_PLACE=0",
"USE_GETTEXT=1", "USE_GETTEXT=1",
"USE_CURL=1", "USE_CURL=1",
@ -2283,8 +2284,8 @@
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
GCC_PREPROCESSOR_DEFINITIONS = ( GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)", "$(inherited)",
"COCOAPODS=1",
"NDEBUG=1", "NDEBUG=1",
_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION,
"RUN_IN_PLACE=0", "RUN_IN_PLACE=0",
"USE_GETTEXT=1", "USE_GETTEXT=1",
"USE_CURL=1", "USE_CURL=1",

View File

@ -1,6 +1,6 @@
#!/bin/bash -e #!/bin/bash -e
SDL2_VERSION=release-2.28.2 SDL2_VERSION=release-2.28.3
. scripts/sdk.sh . scripts/sdk.sh
mkdir -p deps; cd deps mkdir -p deps; cd deps

View File

@ -1,6 +1,6 @@
#!/bin/bash -e #!/bin/bash -e
FREETYPE_VERSION=2.13.1 FREETYPE_VERSION=2.13.2
. scripts/sdk.sh . scripts/sdk.sh
mkdir -p deps; cd deps mkdir -p deps; cd deps

View File

@ -29,6 +29,7 @@ rm templib_*.a
mkdir -p ../luajit/include mkdir -p ../luajit/include
cp -v src/*.h ../luajit/include cp -v src/*.h ../luajit/include
cp -v ../luajit/include/luajit_rolling.h ../luajit/include/luajit.h
cp -v libluajit.a ../luajit cp -v libluajit.a ../luajit
echo "LuaJIT build successful" echo "LuaJIT build successful"

View File

@ -6,6 +6,7 @@ local abs, atan2, cos, floor, max, sin, random =
math.abs, math.atan2, math.cos, math.floor, math.max, math.sin, math.random math.abs, math.atan2, math.cos, math.floor, math.max, math.sin, math.random
local vadd, vnew, vmultiply, vnormalize, vsubtract = local vadd, vnew, vmultiply, vnormalize, vsubtract =
vector.add, vector.new, vector.multiply, vector.normalize, vector.subtract vector.add, vector.new, vector.multiply, vector.normalize, vector.subtract
local tcopy = table.copy
local creative_mode = core.settings:get_bool("creative_mode") local creative_mode = core.settings:get_bool("creative_mode")
local node_drop = core.settings:get_bool("node_drop") local node_drop = core.settings:get_bool("node_drop")
@ -529,14 +530,15 @@ end
function core.item_drop(itemstack, dropper, pos) function core.item_drop(itemstack, dropper, pos)
local dropper_is_player = dropper and dropper:is_player() local dropper_is_player = dropper and dropper:is_player()
local p = table.copy(pos) local p = tcopy(pos)
local cnt = itemstack:get_count()
if not core.is_valid_pos(p) then if not core.is_valid_pos(p) then
return return
end end
if dropper_is_player then if dropper_is_player then
p.y = p.y + 1.2 p.y = p.y + 1.2
end end
local sneak = dropper_is_player and dropper:get_player_control().sneak
local cnt = sneak and 1 or itemstack:get_count()
local item = itemstack:take_item(cnt) local item = itemstack:take_item(cnt)
local obj = core.add_item(p, item) local obj = core.add_item(p, item)
if obj then if obj then

View File

@ -0,0 +1,71 @@
--MultiCraft
--Copyright (C) 2022 MultiCraft Development Team
--
--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 3.0 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.
local function outdated_server_formspec(this)
return ([[
style_type[image_button;content_offset=0]
image[4.9,0.3;2.5,2.5;%sattention.png]
style[msg;content_offset=0]
image_button[1,2.5;10,0.8;;msg;%s;false;false]
image_button[1,3.2;10,0.8;;msg;%s;false;false]
%s
button[2,4.5;4,0.8;cancel;%s]
%s
button[6,4.5;4,0.8;continue;%s]
]]):format(
defaulttexturedir_esc,
fgettext("The server you are trying to connect to is outdated!"),
fgettext("Support for older servers may be removed at any time."),
btn_style("cancel"),
fgettext("Cancel"),
btn_style("continue", "yellow"),
fgettext("Join anyway")
)
end
local function outdated_server_buttonhandler(this, fields)
if fields.cancel then
this:delete()
return true
end
if fields.continue then
serverlistmgr.add_favorite(this.server)
gamedata.servername = this.server.name
gamedata.serverdescription = this.server.description
core.settings:set_bool("auto_connect", false)
core.settings:set("connect_time", os.time())
core.settings:set("maintab_LAST", "online")
core.settings:set("address", gamedata.address)
core.settings:set("remote_port", gamedata.port)
core.start()
end
end
function create_outdated_server_dlg(server)
local retval = dialog_create("outdated_server_dlg",
outdated_server_formspec,
outdated_server_buttonhandler,
nil, true)
retval.server = server
return retval
end

View File

@ -23,7 +23,6 @@ mt_color_orange = "#FF8800"
local menupath = core.get_mainmenu_path() local menupath = core.get_mainmenu_path()
local basepath = core.get_builtin_path() local basepath = core.get_builtin_path()
local mobile = PLATFORM == "Android" or PLATFORM == "iOS"
defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" .. defaulttexturedir = core.get_texturepath_share() .. DIR_DELIM .. "base" ..
DIR_DELIM .. "pack" .. DIR_DELIM DIR_DELIM .. "pack" .. DIR_DELIM
defaulttexturedir_esc = core.formspec_escape(defaulttexturedir) defaulttexturedir_esc = core.formspec_escape(defaulttexturedir)
@ -42,11 +41,13 @@ dofile(menupath .. DIR_DELIM .. "serverlistmgr.lua")
dofile(menupath .. DIR_DELIM .. "textures.lua") dofile(menupath .. DIR_DELIM .. "textures.lua")
dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua") dofile(menupath .. DIR_DELIM .. "dlg_config_world.lua")
dofile(menupath .. DIR_DELIM .. "dlg_settings_advanced.lua")
dofile(menupath .. DIR_DELIM .. "dlg_contentstore.lua") dofile(menupath .. DIR_DELIM .. "dlg_contentstore.lua")
dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua") dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua")
dofile(menupath .. DIR_DELIM .. "dlg_delete_content.lua") dofile(menupath .. DIR_DELIM .. "dlg_delete_content.lua")
dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua") dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua")
dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua") dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
dofile(menupath .. DIR_DELIM .. "dlg_outdated_server.lua")
if not mobile then if not mobile then
dofile(menupath .. DIR_DELIM .. "dlg_settings_advanced.lua") dofile(menupath .. DIR_DELIM .. "dlg_settings_advanced.lua")
@ -56,12 +57,7 @@ dofile(menupath .. DIR_DELIM .. "dlg_version_info.lua")
local tabs = {} local tabs = {}
if not mobile then tabs.settings = dofile(menupath .. DIR_DELIM .. "tab_settings.lua")
tabs.settings = dofile(menupath .. DIR_DELIM .. "tab_settings.lua")
else
tabs.settings = dofile(menupath .. DIR_DELIM .. "tab_settings_simple.lua")
end
tabs.content = dofile(menupath .. DIR_DELIM .. "tab_content.lua") tabs.content = dofile(menupath .. DIR_DELIM .. "tab_content.lua")
tabs.credits = dofile(menupath .. DIR_DELIM .. "tab_credits.lua") tabs.credits = dofile(menupath .. DIR_DELIM .. "tab_credits.lua")
tabs.local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua") tabs.local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua")
@ -135,6 +131,7 @@ function menudata.init_tabs()
texture_prefix = "authors" texture_prefix = "authors"
}) })
tv_main:set_autosave_tab(true)
tv_main:add(tabs.local_game) tv_main:add(tabs.local_game)
if func then if func then
func(tv_main) func(tv_main)
@ -145,7 +142,6 @@ function menudata.init_tabs()
tv_main:add(tabs.settings) tv_main:add(tabs.settings)
tv_main:add(tabs.credits) tv_main:add(tabs.credits)
tv_main:set_autosave_tab(true)
tv_main:set_global_event_handler(main_event_handler) tv_main:set_global_event_handler(main_event_handler)
tv_main:set_fixed_size(false) tv_main:set_fixed_size(false)
@ -172,7 +168,10 @@ function menudata.init_tabs()
check_new_version() check_new_version()
tv_main:show() tv_main:show()
ui.update() ui.update()
-- core.sound_play("main_menu", true)
end end
menudata.init_tabs() menudata.init_tabs()

View File

@ -165,6 +165,17 @@ local function get_formspec(tabview, name, tabdata)
return retval return retval
end end
local function is_favorite(server)
local favs = serverlistmgr.get_favorites()
for fav_id = 1, #favs do
if server.address == favs[fav_id].address and
server.port == favs[fav_id].port then
return true
end
end
return false
end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local function main_button_handler(tabview, fields, name, tabdata) local function main_button_handler(tabview, fields, name, tabdata)
local serverlist = menudata.search_result or serverlistmgr.servers local serverlist = menudata.search_result or serverlistmgr.servers
@ -374,6 +385,12 @@ local function main_button_handler(tabview, fields, name, tabdata)
if not is_server_protocol_compat_or_error( if not is_server_protocol_compat_or_error(
fav.proto_min, fav.proto_max) then fav.proto_min, fav.proto_max) then
return true return true
elseif fav.proto_max and fav.proto_max < 37 and not is_favorite(fav) then
local dlg = create_outdated_server_dlg(fav)
dlg:set_parent(tabview)
tabview:hide()
dlg:show()
return true
end end
serverlistmgr.add_favorite(fav) serverlistmgr.add_favorite(fav)

View File

@ -1,286 +0,0 @@
--Minetest
--Copyright (C) 2020-2022 MultiCraft Development Team
--Copyright (C) 2013 sapier
--
--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 3.0 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.
local function create_confirm_reset_dlg()
return dialog_create("reset_all_settings",
function()
return table.concat({
"real_coordinates[true]",
"image[6.5,0.8;2.5,2.5;", defaulttexturedir_esc, "attention.png]",
"style[msg;content_offset=0]",
"image_button[1,3.5;13.5,0.8;;msg;",
fgettext("Reset all settings?"), ";false;false]",
btn_style("reset_confirm", "red"),
"image_button[4.1,5.3;3.5,0.8;;reset_confirm;",
fgettext("Reset"), ";true;false]",
btn_style("reset_cancel"),
"image_button[7.9,5.3;3.5,0.8;;reset_cancel;",
fgettext("Cancel"), ";true;false]",
})
end,
function(this, fields)
if fields["reset_confirm"] then
for _, setting_name in ipairs(core.settings:get_names()) do
if not setting_name:find(".", 1, true) and
setting_name ~= "maintab_LAST" then
core.settings:remove(setting_name)
end
end
-- Reload the entire main menu
dofile(core.get_builtin_path() .. "init.lua")
return true
end
if fields["reset_cancel"] then
this:delete()
return true
end
end,
nil, true)
end
--------------------------------------------------------------------------------
local languages, lang_idx, language_labels = get_language_list()
local node_highlighting_labels = {
fgettext("Node Outlining"),
fgettext("Node Highlighting"),
fgettext("None")
}
local fps_max_labels = {"30", "60", "90", [-1] = "45"}
local dd_options = {
-- "30 FPS" actually sets 35 FPS for some reason
fps_max = {"35", "60", "90"},
language = languages,
node_highlighting = {"box", "halo", "none"},
viewing_range = {"30", "40", "60", "80", "100", "125", "150", "175", "200"},
}
local getSettingIndex = {
NodeHighlighting = function()
local style = core.settings:get("node_highlighting")
for idx, name in pairs(dd_options.node_highlighting) do
if style == name then return idx end
end
return 1
end
}
local function setting_cb(x, y, setting, label)
return checkbox(x, y, "cb_" .. setting, label, core.settings:get_bool(setting), true)
end
local function disabled_cb(x, y, _, label)
return ("label[%s,%s;%s]"):format(x + 0.6, y, core.colorize("#888", label))
end
local open_dropdown
local guitexturedir = defaulttexturedir_esc .. "gui" .. DIR_DELIM_esc
local function formspec(tabview, name, tabdata)
local fps = tonumber(core.settings:get("fps_max"))
local range = tonumber(core.settings:get("viewing_range"))
local sensitivity = tonumber(core.settings:get("touch_sensitivity") or 0) * 2000
local touchtarget = core.settings:get_bool("touchtarget", false)
local fancy_leaves = core.settings:get("leaves_style") == "fancy"
local sound = tonumber(core.settings:get("sound_volume")) ~= 0
local video_driver = core.settings:get("video_driver")
local shaders_enabled = video_driver == "opengl" or video_driver == "ogles2"
core.settings:set_bool("enable_shaders", shaders_enabled)
local open_dropdown_fs
local function dropdown(x, y, w, name, items, selected_idx, max_items, container_pos)
local dd = get_dropdown(x, y, w, name, items, selected_idx, open_dropdown == name, max_items)
if open_dropdown == name then
open_dropdown_fs = dd
-- Items positioned inside scroll containers are very slightly
-- offset from the same item in a regular container
if container_pos then
open_dropdown_fs = "scroll_container[" .. container_pos .. ";" .. w + x + 1 .. ",10;;vertical;0]" ..
open_dropdown_fs ..
"scroll_container_end[]"
end
return ""
end
return dd
end
local shader_cb = shaders_enabled and setting_cb or disabled_cb
local fs = {
"formspec_version[4]",
"real_coordinates[true]",
"background9[0.5,0.5;4.8,6.4;", defaulttexturedir_esc, "desc_bg.png;false;32]",
-- A scroll container is used so that long labels are clipped
"scroll_container[0.5,0.5;4.8,6.4;;vertical;0]",
setting_cb(0.3, 0.5, "smooth_lighting", fgettext("Smooth Lighting")),
setting_cb(0.3, 1.175, "enable_particles", fgettext("Particles")),
setting_cb(0.3, 1.85, "enable_3d_clouds", fgettext("3D Clouds")),
-- setting_cb(0.3, y, "opaque_water", fgettext("Opaque Water")),
-- setting_cb(0.3, y, "connected_glass", fgettext("Connected Glass")),
setting_cb(0.3, 2.525, "enable_fog", fgettext("Fog")),
setting_cb(0.3, 3.2, "inventory_items_animations", fgettext("Inv. animations")),
-- Some checkboxes don't directly have a boolean setting so they need
-- to be handled separately
checkbox(0.3, 3.875, "fancy_leaves", fgettext("Fancy Leaves"), fancy_leaves, true),
checkbox(0.3, 4.55, "crosshair", fgettext("Crosshair"), not touchtarget, true),
setting_cb(0.3, 5.225, "arm_inertia", fgettext("Arm inertia")),
checkbox(0.3, 5.9, "sound", fgettext("Sound"), sound, true),
"scroll_container_end[]",
-- Middle column
"background9[5.6,0.5;4.8,6.4;", defaulttexturedir_esc, "desc_bg.png;false;32]",
"scroll_container[5.6,0.5;4.8,6.4;;vertical;0]",
"label[0.3,0.5;", fgettext("Maximum FPS"), ":]",
dropdown(0.3, 0.8, 4.2, "dd_fps_max", fps_max_labels,
fps <= 35 and 1 or fps == 45 and -1 or fps == 60 and 2 or 3, nil, "5.6,0.5"),
"label[0.3,2;", fgettext("Viewing range"), ":]",
dropdown(0.3, 2.3, 4.2, "dd_viewing_range", dd_options.viewing_range,
range <= 30 and 1 or range == 40 and 2 or range == 60 and 3 or
range == 80 and 4 or range == 100 and 5 or range == 125 and 6 or
range == 150 and 7 or range == 175 and 8 or 9, 4.5, "5.6,0.5"),
"label[0.3,3.5;", fgettext("Node highlighting"), ":]",
dropdown(0.3, 3.8, 4.2, "dd_node_highlighting", node_highlighting_labels,
getSettingIndex.NodeHighlighting(), nil, "5.6,0.5"),
"label[0.3,5;", fgettext("Mouse sensitivity"), ":]",
"scrollbar[0.3,5.3;4.2,0.8;horizontal;sb_sensitivity;", tostring(sensitivity), ";",
guitexturedir, "scrollbar_horiz_bg.png,", guitexturedir, "scrollbar_slider.png,",
guitexturedir, "scrollbar_minus.png,", guitexturedir, "scrollbar_plus.png]",
"scroll_container_end[]",
-- Right column
"background9[10.7,0.5;4.8,1.9;", defaulttexturedir_esc, "desc_bg.png;false;32]",
"label[11,1;", fgettext("Language"), ":]",
dropdown(11, 1.3, 4.2, "dd_language", language_labels, lang_idx, 6.4),
"background9[10.7,2.6;4.8,4.3;", defaulttexturedir_esc, "desc_bg.png;false;32]",
"scroll_container[10.7,2.6;4.8,4.3;;vertical;0]",
"label[0.3,0.5;", shaders_enabled and fgettext("Shaders") or
core.colorize("#888888", fgettext("Shaders (unavailable)")), "]",
shader_cb(0.3, 1, "tone_mapping", fgettext("Tone Mapping")),
shader_cb(0.3, 1.6, "enable_waving_water", fgettext("Waving liquids")),
shader_cb(0.3, 2.2, "enable_waving_leaves", fgettext("Waving leaves")),
shader_cb(0.3, 2.8, "enable_waving_plants", fgettext("Waving plants")),
"scroll_container_end[]",
btn_style("btn_reset"),
"button[11,5.8;4.2,0.8;btn_reset;", fgettext("Reset all settings"), "]",
}
-- Show the open dropdown (if any) last
fs[#fs + 1] = open_dropdown_fs
fs[#fs + 1] = "real_coordinates[false]"
return table.concat(fs)
end
--------------------------------------------------------------------------------
local function handle_settings_buttons(this, fields, tabname, tabdata)
--[[if fields["btn_advanced_settings"] ~= nil then
local adv_settings_dlg = create_adv_settings_dlg()
adv_settings_dlg:set_parent(this)
this:hide()
adv_settings_dlg:show()
return true
end]]
for field in pairs(fields) do
if field:sub(1, 3) == "cb_" then
-- Checkboxes
local setting_name = field:sub(4)
core.settings:set_bool(setting_name, not core.settings:get_bool(setting_name))
return true
elseif field:sub(1, 3) == "dd_" then
-- Dropdown buttons
open_dropdown = field
return true
elseif open_dropdown and field:sub(1, 9) == "dropdown_" then
-- Dropdown fields
local i = tonumber(field:sub(10))
local setting = open_dropdown:sub(4)
if i and dd_options[setting] then
core.settings:set(setting, dd_options[setting][i])
-- Reload the main menu so that everything uses the new language
if setting == "language" then
dofile(core.get_builtin_path() .. "init.lua")
end
end
open_dropdown = nil
return true
end
end
-- Special checkboxes
if fields["fancy_leaves"] then
core.settings:set("leaves_style", core.settings:get("leaves_style") == "fancy" and "opaque" or "fancy")
return true
end
if fields["crosshair"] then
core.settings:set_bool("touchtarget", not core.settings:get_bool("touchtarget"))
return true
end
if fields["sound"] then
core.settings:set("sound_volume", tonumber(core.settings:get("sound_volume")) == 0 and "1.0" or "0.0")
return true
end
--[[if fields["btn_change_keys"] then
core.show_keys_menu()
return true
end]]
if fields["btn_reset"] then
local reset_dlg = create_confirm_reset_dlg()
reset_dlg:set_parent(this)
this:hide()
reset_dlg:show()
return true
end
if fields["sb_sensitivity"] then
-- reset old setting
core.settings:remove("touchscreen_threshold")
local event = core.explode_scrollbar_event(fields["sb_sensitivity"])
if event.type == "CHG" then
core.settings:set("touch_sensitivity", event.value / 2000)
end
end
end
return {
name = "settings",
caption = "", -- fgettext("Settings"),
cbf_formspec = formspec,
cbf_button_handler = handle_settings_buttons
}

View File

@ -467,6 +467,10 @@ void Client::step(float dtime)
event->type = CE_PLAYER_DAMAGE; event->type = CE_PLAYER_DAMAGE;
event->player_damage.amount = damage; event->player_damage.amount = damage;
m_client_event_queue.push(event); m_client_event_queue.push(event);
} else if (envEvent.type == CEE_PLAYER_BREATH && m_proto_ver < 29) {
// Protocol v29 or greater obsoleted this event
u16 breath = envEvent.player_breath.amount;
sendBreath(breath);
} }
} }
@ -850,6 +854,7 @@ void Client::ReceiveAll()
inline void Client::handleCommand(NetworkPacket* pkt) inline void Client::handleCommand(NetworkPacket* pkt)
{ {
pkt->setProtocolVersion(m_proto_ver);
const ToClientCommandHandler& opHandle = toClientCommandTable[pkt->getCommand()]; const ToClientCommandHandler& opHandle = toClientCommandTable[pkt->getCommand()];
(this->*opHandle.handler)(pkt); (this->*opHandle.handler)(pkt);
} }
@ -968,7 +973,7 @@ void Client::interact(InteractAction action, const PointedThing& pointed)
[9 + plen] player position information [9 + plen] player position information
*/ */
NetworkPacket pkt(TOSERVER_INTERACT, 1 + 2 + 0); NetworkPacket pkt(TOSERVER_INTERACT, 1 + 2 + 0, 0, m_proto_ver);
pkt << (u8)action; pkt << (u8)action;
pkt << myplayer->getWieldIndex(); pkt << myplayer->getWieldIndex();
@ -1019,14 +1024,14 @@ AuthMechanism Client::choseAuthMech(const u32 mechs)
void Client::sendInit(const std::string &playerName) void Client::sendInit(const std::string &playerName)
{ {
NetworkPacket pkt(TOSERVER_INIT, 1 + 2 + 2 + (1 + playerName.size()) + 1); NetworkPacket pkt(TOSERVER_INIT, 1 + 2 + 2 + (1 + playerName.size()));
// we don't support network compression yet // we don't support network compression yet
u16 supp_comp_modes = NETPROTO_COMPRESSION_NONE; u16 supp_comp_modes = NETPROTO_COMPRESSION_NONE;
pkt << (u8) SER_FMT_VER_HIGHEST_READ << (u16) supp_comp_modes; pkt << (u8) SER_FMT_VER_HIGHEST_READ << (u16) supp_comp_modes;
pkt << (u16) CLIENT_PROTOCOL_VERSION_MIN << (u16) CLIENT_PROTOCOL_VERSION_MAX; pkt << (u16) CLIENT_PROTOCOL_VERSION_MIN << (u16) CLIENT_PROTOCOL_VERSION_MAX;
pkt << playerName << (u8) 1; pkt << playerName;
Send(&pkt); Send(&pkt);
} }
@ -1263,9 +1268,28 @@ void Client::sendChangePassword(const std::string &oldpassword,
void Client::sendDamage(u16 damage) void Client::sendDamage(u16 damage)
{ {
// Minetest 0.4 uses uint8s instead of uint16s in TOSERVER_DAMAGE.
if (m_proto_ver >= 37) {
NetworkPacket pkt(TOSERVER_DAMAGE, sizeof(u16)); NetworkPacket pkt(TOSERVER_DAMAGE, sizeof(u16));
pkt << damage; pkt << damage;
Send(&pkt); Send(&pkt);
} else {
u8 raw_damage = damage & 0xFF;
NetworkPacket pkt(TOSERVER_DAMAGE, sizeof(u8));
pkt << raw_damage;
Send(&pkt);
}
}
void Client::sendBreath(u16 breath)
{
// Protocol v29 (Minetest 0.4.16) made this obsolete
if (m_proto_ver >= 29)
return;
NetworkPacket pkt(TOSERVER_BREATH, sizeof(u16));
pkt << breath;
Send(&pkt);
} }
void Client::sendRespawn() void Client::sendRespawn()
@ -1328,7 +1352,8 @@ void Client::sendPlayerPos()
player->last_camera_fov = camera_fov; player->last_camera_fov = camera_fov;
player->last_wanted_range = wanted_range; player->last_wanted_range = wanted_range;
NetworkPacket pkt(TOSERVER_PLAYERPOS, 12 + 12 + 4 + 4 + 4 + 1 + 1); NetworkPacket pkt(TOSERVER_PLAYERPOS, 12 + 12 + 4 + 4 + 4 + 1 + 1, 0,
m_proto_ver);
writePlayerPos(player, &map, &pkt); writePlayerPos(player, &map, &pkt);
@ -1593,6 +1618,24 @@ void Client::typeChatMessage(const std::wstring &message)
// Send to others // Send to others
sendChatMessage(message); sendChatMessage(message);
// Show locally
if (message[0] == L'/') {
if (!m_mods_loaded) {
ChatMessage *chatMessage = new ChatMessage(L"issued command: " +
message);
m_chat_queue.push(chatMessage);
}
} else if (m_proto_ver < 29) {
// Backwards compatibility
LocalPlayer *player = m_env.getLocalPlayer();
if (!player)
return;
std::wstring name = utf8_to_wide(player->getName());
ChatMessage *chatMessage = new ChatMessage(CHATMESSAGE_TYPE_NORMAL,
message, name);
m_chat_queue.push(chatMessage);
}
} }
void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent) void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent)

View File

@ -179,6 +179,7 @@ public:
void handleCommand_BlockData(NetworkPacket* pkt); void handleCommand_BlockData(NetworkPacket* pkt);
void handleCommand_Inventory(NetworkPacket* pkt); void handleCommand_Inventory(NetworkPacket* pkt);
void handleCommand_TimeOfDay(NetworkPacket* pkt); void handleCommand_TimeOfDay(NetworkPacket* pkt);
void handleCommand_ChatMessageOld(NetworkPacket *pkt);
void handleCommand_ChatMessage(NetworkPacket *pkt); void handleCommand_ChatMessage(NetworkPacket *pkt);
void handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt); void handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt);
void handleCommand_ActiveObjectMessages(NetworkPacket* pkt); void handleCommand_ActiveObjectMessages(NetworkPacket* pkt);
@ -241,6 +242,7 @@ public:
void sendChangePassword(const std::string &oldpassword, void sendChangePassword(const std::string &oldpassword,
const std::string &newpassword, const bool close_form = false); const std::string &newpassword, const bool close_form = false);
void sendDamage(u16 damage); void sendDamage(u16 damage);
void sendBreath(u16 breath);
void sendRespawn(); void sendRespawn();
void sendReady(); void sendReady();

View File

@ -271,6 +271,75 @@ void ClientEnvironment::step(float dtime)
if (m_client->modsLoaded()) if (m_client->modsLoaded())
m_script->environment_step(dtime); m_script->environment_step(dtime);
// Protocol v29 make this behaviour obsolete
if (getGameDef()->getProtoVersion() < 29) {
if (m_lava_hurt_interval.step(dtime, 1.0)) {
v3f pf = lplayer->getPosition();
// Feet, middle and head
v3s16 p1 = floatToInt(pf + v3f(0, BS * 0.1, 0), BS);
MapNode n1 = m_map->getNode(p1);
v3s16 p2 = floatToInt(pf + v3f(0, BS * 0.8, 0), BS);
MapNode n2 = m_map->getNode(p2);
v3s16 p3 = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
MapNode n3 = m_map->getNode(p3);
u32 damage_per_second = 0;
damage_per_second = MYMAX(damage_per_second,
m_client->ndef()->get(n1).damage_per_second);
damage_per_second = MYMAX(damage_per_second,
m_client->ndef()->get(n2).damage_per_second);
damage_per_second = MYMAX(damage_per_second,
m_client->ndef()->get(n3).damage_per_second);
if (damage_per_second != 0)
damageLocalPlayer(damage_per_second, true);
}
/*
Drowning
*/
if (m_drowning_interval.step(dtime, 2.0)) {
v3f pf = lplayer->getPosition();
// head
v3s16 p = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
MapNode n = m_map->getNode(p);
const ContentFeatures &c = m_client->ndef()->get(n);
u8 drowning_damage = c.drowning;
if (drowning_damage > 0 && lplayer->hp > 0) {
u16 breath = lplayer->getBreath();
if (breath > 10)
breath = 11;
if (breath > 0)
breath -= 1;
lplayer->setBreath(breath);
updateLocalPlayerBreath(breath);
}
if (lplayer->getBreath() == 0 && drowning_damage > 0)
damageLocalPlayer(drowning_damage, true);
}
if (m_breathing_interval.step(dtime, 0.5)) {
v3f pf = lplayer->getPosition();
// head
v3s16 p = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
MapNode n = m_map->getNode(p);
const ContentFeatures &c = m_client->ndef()->get(n);
if (!lplayer->hp) {
lplayer->setBreath(11);
} else if (c.drowning == 0) {
u16 breath = lplayer->getBreath();
if (breath <= 10) {
breath += 1;
lplayer->setBreath(breath);
updateLocalPlayerBreath(breath);
}
}
}
}
// Update lighting on local player (used for wield item) // Update lighting on local player (used for wield item)
u32 day_night_ratio = getDayNightRatio(); u32 day_night_ratio = getDayNightRatio();
{ {
@ -449,6 +518,14 @@ void ClientEnvironment::damageLocalPlayer(u16 damage, bool handle_hp)
m_client_event_queue.push(event); m_client_event_queue.push(event);
} }
void ClientEnvironment::updateLocalPlayerBreath(u16 breath)
{
ClientEnvEvent event;
event.type = CEE_PLAYER_BREATH;
event.player_breath.amount = breath;
m_client_event_queue.push(event);
}
/* /*
Client likes to call these Client likes to call these
*/ */

View File

@ -43,7 +43,8 @@ class LocalPlayer;
enum ClientEnvEventType enum ClientEnvEventType
{ {
CEE_NONE, CEE_NONE,
CEE_PLAYER_DAMAGE CEE_PLAYER_DAMAGE,
CEE_PLAYER_BREATH
}; };
struct ClientEnvEvent struct ClientEnvEvent
@ -56,6 +57,9 @@ struct ClientEnvEvent
u16 amount; u16 amount;
bool send_to_server; bool send_to_server;
} player_damage; } player_damage;
struct{
u16 amount;
} player_breath;
}; };
}; };
@ -113,6 +117,7 @@ public:
*/ */
void damageLocalPlayer(u16 damage, bool handle_hp=true); void damageLocalPlayer(u16 damage, bool handle_hp=true);
void updateLocalPlayerBreath(u16 breath);
/* /*
Client likes to call these Client likes to call these
@ -151,6 +156,9 @@ private:
std::vector<ClientSimpleObject*> m_simple_objects; std::vector<ClientSimpleObject*> m_simple_objects;
std::queue<ClientEnvEvent> m_client_event_queue; std::queue<ClientEnvEvent> m_client_event_queue;
IntervalLimiter m_active_object_light_update_interval; IntervalLimiter m_active_object_light_update_interval;
IntervalLimiter m_lava_hurt_interval;
IntervalLimiter m_drowning_interval;
IntervalLimiter m_breathing_interval;
std::list<std::string> m_player_names; std::list<std::string> m_player_names;
v3s16 m_camera_offset; v3s16 m_camera_offset;
}; };

View File

@ -357,6 +357,8 @@ void GenericCAO::initialize(const std::string &data)
m_prop.show_on_minimap = false; m_prop.show_on_minimap = false;
} }
if (m_client->getProtoVersion() < 33)
m_env->addPlayerName(m_name.c_str());
} }
m_enable_shaders = g_settings->getBool("enable_shaders"); m_enable_shaders = g_settings->getBool("enable_shaders");
@ -365,21 +367,25 @@ void GenericCAO::initialize(const std::string &data)
void GenericCAO::processInitData(const std::string &data) void GenericCAO::processInitData(const std::string &data)
{ {
std::istringstream is(data, std::ios::binary); std::istringstream is(data, std::ios::binary);
const u8 version = readU8(is); const u8 version = readU8(is);
const u16 protocol_version = m_client->getProtoVersion();
if (version < 1) { // PROTOCOL_VERSION >= 14
errorstream << "GenericCAO: Unsupported init data version"
<< std::endl;
return;
}
// PROTOCOL_VERSION >= 37
m_name = deSerializeString16(is); m_name = deSerializeString16(is);
m_is_player = readU8(is); m_is_player = readU8(is);
if (protocol_version >= 37) {
m_id = readU16(is); m_id = readU16(is);
m_position = readV3F32(is); m_position = readV3F32(is);
m_rotation = readV3F32(is); m_rotation = readV3F32(is);
m_hp = readU16(is); m_hp = readU16(is);
} else {
if (version >= 1)
m_id = readS16(is);
m_position = readV3F1000(is);
m_rotation = v3f(0.0, readF1000(is), 0.0);
m_hp = readS16(is);
}
const u8 num_messages = readU8(is); const u8 num_messages = readU8(is);
@ -396,6 +402,8 @@ void GenericCAO::processInitData(const std::string &data)
GenericCAO::~GenericCAO() GenericCAO::~GenericCAO()
{ {
if (m_is_player && m_client->getProtoVersion() < 33)
m_env->removePlayerName(m_name.c_str());
removeFromScene(true); removeFromScene(true);
} }
@ -675,8 +683,9 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
video::S3DVertex( dx, dy, 0, 0,0,1, c, 0,0), video::S3DVertex( dx, dy, 0, 0,0,1, c, 0,0),
video::S3DVertex(-dx, dy, 0, 0,0,1, c, 1,0), video::S3DVertex(-dx, dy, 0, 0,0,1, c, 1,0),
}; };
if (m_is_player) { if (m_is_player && m_client->getProtoVersion() >= 36) {
// Move minimal Y position to 0 (feet position) // Move minimal Y position to 0 (feet position)
// This should not be done on Minetest 0.4 servers
for (video::S3DVertex &vertex : vertices) for (video::S3DVertex &vertex : vertices)
vertex.Pos.Y += dy; vertex.Pos.Y += dy;
} }
@ -706,8 +715,9 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
video::S3DVertex(-dx, dy, 0, 0,0,-1, c, 0,0), video::S3DVertex(-dx, dy, 0, 0,0,-1, c, 0,0),
video::S3DVertex( dx, dy, 0, 0,0,-1, c, 1,0), video::S3DVertex( dx, dy, 0, 0,0,-1, c, 1,0),
}; };
if (m_is_player) { if (m_is_player && m_client->getProtoVersion() >= 36) {
// Move minimal Y position to 0 (feet position) // Move minimal Y position to 0 (feet position)
// This should not be done on Minetest 0.4 servers
for (video::S3DVertex &vertex : vertices) for (video::S3DVertex &vertex : vertices)
vertex.Pos.Y += dy; vertex.Pos.Y += dy;
} }
@ -776,7 +786,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
setSceneNodeMaterial(m_animated_meshnode); setSceneNodeMaterial(m_animated_meshnode);
m_animated_meshnode->setMaterialFlag(video::EMF_BACK_FACE_CULLING, m_animated_meshnode->setMaterialFlag(video::EMF_BACK_FACE_CULLING,
m_prop.backface_culling); !m_is_player && m_prop.backface_culling);
} else } else
errorstream<<"GenericCAO::addToScene(): Could not load mesh "<<m_prop.mesh<<std::endl; errorstream<<"GenericCAO::addToScene(): Could not load mesh "<<m_prop.mesh<<std::endl;
} else if (m_prop.visual == "wielditem" || m_prop.visual == "item") { } else if (m_prop.visual == "wielditem" || m_prop.visual == "item") {
@ -987,6 +997,8 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
if (m_is_local_player) { if (m_is_local_player) {
LocalPlayer *player = m_env->getLocalPlayer(); LocalPlayer *player = m_env->getLocalPlayer();
m_position = player->getPosition(); m_position = player->getPosition();
if (m_client->getProtoVersion() < 36)
m_position += v3f(0,BS,0);
pos_translator.val_current = m_position; pos_translator.val_current = m_position;
m_rotation.Y = wrapDegrees_0_360(player->getYaw()); m_rotation.Y = wrapDegrees_0_360(player->getYaw());
rot_translator.val_current = m_rotation; rot_translator.val_current = m_rotation;
@ -1626,6 +1638,7 @@ void GenericCAO::processMessage(const std::string &data)
std::istringstream is(data, std::ios::binary); std::istringstream is(data, std::ios::binary);
// command // command
u8 cmd = readU8(is); u8 cmd = readU8(is);
const u16 protocol_version = m_client->getProtoVersion();
if (cmd == AO_CMD_SET_PROPERTIES) { if (cmd == AO_CMD_SET_PROPERTIES) {
ObjectProperties newprops; ObjectProperties newprops;
newprops.show_on_minimap = m_is_player; // default newprops.show_on_minimap = m_is_player; // default
@ -1653,10 +1666,14 @@ void GenericCAO::processMessage(const std::string &data)
if (m_is_local_player) { if (m_is_local_player) {
LocalPlayer *player = m_env->getLocalPlayer(); LocalPlayer *player = m_env->getLocalPlayer();
player->makes_footstep_sound = m_prop.makes_footstep_sound; player->makes_footstep_sound = m_prop.makes_footstep_sound;
// Only set the collision box on Minetest 5.0.0+ to ensure
// compatibility with 0.4.
if (protocol_version >= 36) {
aabb3f collision_box = m_prop.collisionbox; aabb3f collision_box = m_prop.collisionbox;
collision_box.MinEdge *= BS; collision_box.MinEdge *= BS;
collision_box.MaxEdge *= BS; collision_box.MaxEdge *= BS;
player->setCollisionbox(collision_box); player->setCollisionbox(collision_box);
}
player->setEyeHeight(m_prop.eye_height); player->setEyeHeight(m_prop.eye_height);
player->setZoomFOV(m_prop.zoom_fov); player->setZoomFOV(m_prop.zoom_fov);
} }
@ -1682,15 +1699,19 @@ void GenericCAO::processMessage(const std::string &data)
} else if (cmd == AO_CMD_UPDATE_POSITION) { } else if (cmd == AO_CMD_UPDATE_POSITION) {
// Not sent by the server if this object is an attachment. // Not sent by the server if this object is an attachment.
// We might however get here if the server notices the object being detached before the client. // We might however get here if the server notices the object being detached before the client.
m_position = readV3F32(is); m_position = readV3F(is, protocol_version);
m_velocity = readV3F32(is); m_velocity = readV3F(is, protocol_version);
m_acceleration = readV3F32(is); m_acceleration = readV3F(is, protocol_version);
if (protocol_version >= 37)
m_rotation = readV3F32(is); m_rotation = readV3F32(is);
else
m_rotation = v3f(0.0, readF1000(is), 0.0);
m_rotation = wrapDegrees_0_360_v3f(m_rotation); m_rotation = wrapDegrees_0_360_v3f(m_rotation);
bool do_interpolate = readU8(is); bool do_interpolate = readU8(is);
bool is_end_position = readU8(is); bool is_end_position = readU8(is);
float update_interval = readF32(is); float update_interval = readF(is, protocol_version);
// Place us a bit higher if we're physical, to not sink into // Place us a bit higher if we're physical, to not sink into
// the ground due to sucky collision detection... // the ground due to sucky collision detection...
@ -1721,7 +1742,7 @@ void GenericCAO::processMessage(const std::string &data)
} else if (cmd == AO_CMD_SET_SPRITE) { } else if (cmd == AO_CMD_SET_SPRITE) {
v2s16 p = readV2S16(is); v2s16 p = readV2S16(is);
int num_frames = readU16(is); int num_frames = readU16(is);
float framelength = readF32(is); float framelength = readF(is, protocol_version);
bool select_horiz_by_yawpitch = readU8(is); bool select_horiz_by_yawpitch = readU8(is);
m_tx_basepos = p; m_tx_basepos = p;
@ -1731,9 +1752,9 @@ void GenericCAO::processMessage(const std::string &data)
updateTexturePos(); updateTexturePos();
} else if (cmd == AO_CMD_SET_PHYSICS_OVERRIDE) { } else if (cmd == AO_CMD_SET_PHYSICS_OVERRIDE) {
float override_speed = readF32(is); float override_speed = readF(is, protocol_version);
float override_jump = readF32(is); float override_jump = readF(is, protocol_version);
float override_gravity = readF32(is); float override_gravity = readF(is, protocol_version);
// these are sent inverted so we get true when the server sends nothing // these are sent inverted so we get true when the server sends nothing
bool sneak = !readU8(is); bool sneak = !readU8(is);
bool sneak_glitch = !readU8(is); bool sneak_glitch = !readU8(is);
@ -1752,11 +1773,11 @@ void GenericCAO::processMessage(const std::string &data)
} }
} else if (cmd == AO_CMD_SET_ANIMATION) { } else if (cmd == AO_CMD_SET_ANIMATION) {
// TODO: change frames send as v2s32 value // TODO: change frames send as v2s32 value
v2f range = readV2F32(is); v2f range = readV2F(is, protocol_version);
if (!m_is_local_player) { if (!m_is_local_player) {
m_animation_range = v2s32((s32)range.X, (s32)range.Y); m_animation_range = v2s32((s32)range.X, (s32)range.Y);
m_animation_speed = readF32(is); m_animation_speed = readF(is, protocol_version);
m_animation_blend = readF32(is); m_animation_blend = readF(is, protocol_version);
// these are sent inverted so we get true when the server sends nothing // these are sent inverted so we get true when the server sends nothing
m_animation_loop = !readU8(is); m_animation_loop = !readU8(is);
updateAnimation(); updateAnimation();
@ -1765,8 +1786,8 @@ void GenericCAO::processMessage(const std::string &data)
if(player->last_animation == NO_ANIM) if(player->last_animation == NO_ANIM)
{ {
m_animation_range = v2s32((s32)range.X, (s32)range.Y); m_animation_range = v2s32((s32)range.X, (s32)range.Y);
m_animation_speed = readF32(is); m_animation_speed = readF(is, protocol_version);
m_animation_blend = readF32(is); m_animation_blend = readF(is, protocol_version);
// these are sent inverted so we get true when the server sends nothing // these are sent inverted so we get true when the server sends nothing
m_animation_loop = !readU8(is); m_animation_loop = !readU8(is);
} }
@ -1785,25 +1806,30 @@ void GenericCAO::processMessage(const std::string &data)
} }
} }
} else if (cmd == AO_CMD_SET_ANIMATION_SPEED) { } else if (cmd == AO_CMD_SET_ANIMATION_SPEED) {
m_animation_speed = readF32(is); m_animation_speed = readF(is, protocol_version);
updateAnimationSpeed(); updateAnimationSpeed();
} else if (cmd == AO_CMD_SET_BONE_POSITION) { } else if (cmd == AO_CMD_SET_BONE_POSITION) {
std::string bone = deSerializeString16(is); std::string bone = deSerializeString16(is);
v3f position = readV3F32(is); v3f position = readV3F(is, protocol_version);
v3f rotation = readV3F32(is); v3f rotation = readV3F(is, protocol_version);
m_bone_position[bone] = core::vector2d<v3f>(position, rotation); m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
// updateBonePosition(); now called every step // updateBonePosition(); now called every step
} else if (cmd == AO_CMD_ATTACH_TO) { } else if (cmd == AO_CMD_ATTACH_TO) {
u16 parent_id = readS16(is); u16 parent_id = readS16(is);
std::string bone = deSerializeString16(is); std::string bone = deSerializeString16(is);
v3f position = readV3F32(is); v3f position = readV3F(is, protocol_version);
v3f rotation = readV3F32(is); v3f rotation = readV3F(is, protocol_version);
bool force_visible = readU8(is); // Returns false for EOF bool force_visible = readU8(is); // Returns false for EOF
setAttachment(parent_id, bone, position, rotation, force_visible); setAttachment(parent_id, bone, position, rotation, force_visible);
} else if (cmd == AO_CMD_PUNCHED) { } else if (cmd == AO_CMD_PUNCHED) {
u16 result_hp = readU16(is); u16 result_hp = readU16(is);
if (protocol_version < 37) {
// This is not a bug, the above readU16() is intentionally executed
// on older protocols as there used to be a damage value sent.
result_hp = readS16(is);
}
// Use this instead of the send damage to not interfere with prediction // Use this instead of the send damage to not interfere with prediction
s32 damage = (s32)m_hp - (s32)result_hp; s32 damage = (s32)m_hp - (s32)result_hp;

View File

@ -819,7 +819,7 @@ protected:
} }
#if defined(__ANDROID__) || defined(__IOS__) #if defined(__ANDROID__) || defined(__IOS__)
void handleAndroidChatInput(); void handleTouchChatInput();
#endif #endif
private: private:
@ -1873,6 +1873,14 @@ void Game::processUserInput(f32 dtime)
g_touchscreengui->hide(); g_touchscreengui->hide();
#endif #endif
} }
#if defined(__ANDROID__) || defined(__IOS__)
if (porting::isInputDialogActive() && porting::getInputDialogOwner() == "chat") {
input->clear();
g_touchscreengui->hide();
}
#endif
#ifdef HAVE_TOUCHSCREENGUI #ifdef HAVE_TOUCHSCREENGUI
else if (g_touchscreengui) { else if (g_touchscreengui) {
/* on touchscreengui step may generate own input events which ain't /* on touchscreengui step may generate own input events which ain't
@ -1889,13 +1897,11 @@ void Game::processUserInput(f32 dtime)
input->step(dtime); input->step(dtime);
#if defined(__ANDROID__) || defined(__IOS__) #if defined(__ANDROID__) || defined(__IOS__)
if (!porting::hasRealKeyboard()) { handleTouchChatInput();
auto formspec = m_game_ui->getFormspecGUI(); auto formspec = m_game_ui->getFormspecGUI();
if (formspec) if (formspec)
formspec->getAndroidUIInput(); formspec->getTouchUIInput();
else
handleAndroidChatInput();
}
#endif #endif
bool doubletap_jump = m_cache_doubletap_jump; bool doubletap_jump = m_cache_doubletap_jump;
@ -1923,9 +1929,6 @@ void Game::processKeyInput()
} else if (wasKeyDown(KeyType::INVENTORY)) { } else if (wasKeyDown(KeyType::INVENTORY)) {
openInventory(); openInventory();
} else if (input->cancelPressed()) { } else if (input->cancelPressed()) {
#if defined(__ANDROID__) || defined(__IOS__)
gui_chat_console->setAndroidChatOpen(false);
#endif
if (!gui_chat_console->isOpenInhibited()) { if (!gui_chat_console->isOpenInhibited()) {
showPauseMenu(); showPauseMenu();
} }
@ -2137,21 +2140,21 @@ void Game::openConsole(float scale, const wchar_t *line)
{ {
assert(scale > 0.0f && scale <= 1.0f); assert(scale > 0.0f && scale <= 1.0f);
if (gui_chat_console->getAndroidChatOpen()) if (gui_chat_console->isOpenInhibited())
return; return;
#if defined(__ANDROID__) || defined(__IOS__) #if defined(__ANDROID__) || defined(__IOS__)
if (porting::isInputDialogActive())
return;
if (!porting::hasRealKeyboard()) { if (!porting::hasRealKeyboard()) {
porting::showInputDialog("", "", 2); porting::showInputDialog("", "", 2, "chat");
gui_chat_console->setAndroidChatOpen(true);
} }
if (!RenderingEngine::isTablet()) if (!RenderingEngine::isTablet())
return; return;
#endif #endif
if (gui_chat_console->isOpenInhibited())
return;
gui_chat_console->openConsole(scale); gui_chat_console->openConsole(scale);
if (line) { if (line) {
gui_chat_console->setCloseOnEnter(true); gui_chat_console->setCloseOnEnter(true);
@ -2160,16 +2163,21 @@ void Game::openConsole(float scale, const wchar_t *line)
} }
#if defined(__ANDROID__) || defined(__IOS__) #if defined(__ANDROID__) || defined(__IOS__)
void Game::handleAndroidChatInput() void Game::handleTouchChatInput()
{ {
if (gui_chat_console->getAndroidChatOpen() && if (porting::getInputDialogOwner() == "chat" &&
porting::getInputDialogState() == 0) { porting::getInputDialogState() == 0) {
std::string text = porting::getInputDialogValue(); std::string text = porting::getInputDialogValue();
client->typeChatMessage(utf8_to_wide(text)); client->typeChatMessage(utf8_to_wide(text));
gui_chat_console->setAndroidChatOpen(false);
if (!text.empty() && gui_chat_console->isOpen()) { if (!text.empty() && gui_chat_console->isOpen()) {
gui_chat_console->closeConsole(); gui_chat_console->closeConsole();
} }
#ifdef HAVE_TOUCHSCREENGUI
if (!gui_chat_console->isOpen() && !isMenuActive()) {
if (g_touchscreengui && g_touchscreengui->isActive())
g_touchscreengui->show();
}
#endif
} }
} }
#endif #endif
@ -2640,6 +2648,11 @@ void Game::handleClientEvent_None(ClientEvent *event, CameraOrientation *cam)
void Game::handleClientEvent_PlayerDamage(ClientEvent *event, CameraOrientation *cam) void Game::handleClientEvent_PlayerDamage(ClientEvent *event, CameraOrientation *cam)
{ {
// Don't do anything if proto_ver < 36 and the player is dead.
// This reverts the change introduced in dcd1a15 for old servers.
if (client->getProtoVersion() < 36 && client->getHP() == 0)
return;
if (client->modsLoaded()) if (client->modsLoaded())
client->getScript()->on_damage_taken(event->player_damage.amount); client->getScript()->on_damage_taken(event->player_damage.amount);

View File

@ -743,6 +743,14 @@ ClientActiveObject *LocalPlayer::getParent() const
return m_cao ? m_cao->getParent() : nullptr; return m_cao ? m_cao->getParent() : nullptr;
} }
float LocalPlayer::getZoomFOV() const
{
// OH nO, The ZOOm FoV IS nOt COnFIguRABLE On oLDER ServErS.
if (m_client && m_client->getProtoVersion() < 36)
return m_client->checkPrivilege("zoom") ? 15.0f : 0.0f;
return m_zoom_fov;
}
bool LocalPlayer::isDead() const bool LocalPlayer::isDead() const
{ {
FATAL_ERROR_IF(!getCAO(), "LocalPlayer's CAO isn't initialized"); FATAL_ERROR_IF(!getCAO(), "LocalPlayer's CAO isn't initialized");

View File

@ -146,7 +146,7 @@ public:
const aabb3f& getCollisionbox() const { return m_collisionbox; } const aabb3f& getCollisionbox() const { return m_collisionbox; }
float getZoomFOV() const { return m_zoom_fov; } float getZoomFOV() const;
void setZoomFOV(float zoom_fov) { m_zoom_fov = zoom_fov; } void setZoomFOV(float zoom_fov) { m_zoom_fov = zoom_fov; }
bool getAutojump() const { return m_autojump; } bool getAutojump() const { return m_autojump; }

View File

@ -109,7 +109,6 @@ struct SoundBuffer
ALenum format; ALenum format;
ALsizei freq; ALsizei freq;
ALuint buffer_id; ALuint buffer_id;
std::vector<char> buffer;
}; };
SoundBuffer *load_opened_ogg_file(OggVorbis_File *oggFile, SoundBuffer *load_opened_ogg_file(OggVorbis_File *oggFile,
@ -120,6 +119,7 @@ SoundBuffer *load_opened_ogg_file(OggVorbis_File *oggFile,
long bytes; long bytes;
char array[BUFFER_SIZE]; // Local fixed size array char array[BUFFER_SIZE]; // Local fixed size array
vorbis_info *pInfo; vorbis_info *pInfo;
std::vector<char> buffer;
SoundBuffer *snd = new SoundBuffer; SoundBuffer *snd = new SoundBuffer;
@ -151,12 +151,12 @@ SoundBuffer *load_opened_ogg_file(OggVorbis_File *oggFile,
} }
// Append to end of buffer // Append to end of buffer
snd->buffer.insert(snd->buffer.end(), array, array + bytes); buffer.insert(buffer.end(), array, array + bytes);
} while (bytes > 0); } while (bytes > 0);
alGenBuffers(1, &snd->buffer_id); alGenBuffers(1, &snd->buffer_id);
alBufferData(snd->buffer_id, snd->format, alBufferData(snd->buffer_id, snd->format,
&(snd->buffer[0]), snd->buffer.size(), &buffer[0], buffer.size(),
snd->freq); snd->freq);
ALenum error = alGetError(); ALenum error = alGetError();
@ -170,6 +170,7 @@ SoundBuffer *load_opened_ogg_file(OggVorbis_File *oggFile,
// << filename_for_logging << " loaded" << std::endl; // << filename_for_logging << " loaded" << std::endl;
// Clean up! // Clean up!
buffer.clear();
ov_clear(oggFile); ov_clear(oggFile);
return snd; return snd;

View File

@ -1589,10 +1589,9 @@ bool GUIChatConsole::preprocessEvent(SEvent event)
event.TouchInput.Y >= prompt_y && event.TouchInput.Y >= prompt_y &&
event.TouchInput.Y <= m_height) { event.TouchInput.Y <= m_height) {
if (event.TouchInput.Event == ETIE_PRESSED_DOWN && if (event.TouchInput.Event == ETIE_PRESSED_DOWN &&
!m_android_chat_open) { !porting::isInputDialogActive()) {
ChatPrompt& prompt = m_chat_backend->getPrompt(); ChatPrompt& prompt = m_chat_backend->getPrompt();
porting::showInputDialog("", "", 2); porting::showInputDialog("", "", 2, "chat");
m_android_chat_open = true;
} }
} }
#endif #endif

View File

@ -170,9 +170,6 @@ public:
bool preprocessEvent(SEvent event); bool preprocessEvent(SEvent event);
bool getAndroidChatOpen() { return m_android_chat_open; }
void setAndroidChatOpen(bool value) { m_android_chat_open = value; }
void onLinesModified(); void onLinesModified();
void onPromptModified(); void onPromptModified();
@ -253,6 +250,4 @@ private:
u32 m_scrollbar_width = 0; u32 m_scrollbar_width = 0;
GUIScrollBar *m_vscrollbar = nullptr; GUIScrollBar *m_vscrollbar = nullptr;
s32 m_bottom_scroll_pos = 0; s32 m_bottom_scroll_pos = 0;
bool m_android_chat_open = false;
}; };

View File

@ -220,7 +220,7 @@ void GUIConfirmRegistration::drawMenu()
gui::IGUIElement::draw(); gui::IGUIElement::draw();
#if defined(__ANDROID__) || defined(__IOS__) #if defined(__ANDROID__) || defined(__IOS__)
getAndroidUIInput(); getTouchUIInput();
#endif #endif
} }
@ -308,11 +308,14 @@ bool GUIConfirmRegistration::OnEvent(const SEvent &event)
} }
#if defined(__ANDROID__) || defined(__IOS__) #if defined(__ANDROID__) || defined(__IOS__)
bool GUIConfirmRegistration::getAndroidUIInput() bool GUIConfirmRegistration::getTouchUIInput()
{ {
if (m_jni_field_name.empty() || m_jni_field_name != "password") if (m_jni_field_name.empty() || m_jni_field_name != "password")
return false; return false;
if (porting::getInputDialogOwner() != "modalmenu")
return false;
// still waiting // still waiting
if (porting::getInputDialogState() == -1) if (porting::getInputDialogState() == -1)
return true; return true;

View File

@ -52,7 +52,7 @@ public:
bool OnEvent(const SEvent &event); bool OnEvent(const SEvent &event);
#if defined(__ANDROID__) || defined(__IOS__) #if defined(__ANDROID__) || defined(__IOS__)
bool getAndroidUIInput(); bool getTouchUIInput();
#endif #endif
private: private:

View File

@ -348,7 +348,7 @@ void GUIEngine::run()
m_script->step(); m_script->step();
#if defined(__ANDROID__) || defined(__IOS__) #if defined(__ANDROID__) || defined(__IOS__)
m_menu->getAndroidUIInput(); m_menu->getTouchUIInput();
#endif #endif
} }
} }
@ -474,9 +474,15 @@ void GUIEngine::drawBackground(video::IVideoDriver *driver)
} }
/* Draw background texture */ /* Draw background texture */
float aspectRatioScreen = (float) screensize.X / screensize.Y;
float aspectRatioSource = (float) sourcesize.X / sourcesize.Y;
int sourceX = aspectRatioSource > aspectRatioScreen ? (sourcesize.X - sourcesize.Y * aspectRatioScreen) / 2 : 0;
int sourceY = aspectRatioSource < aspectRatioScreen ? (sourcesize.Y - sourcesize.X / aspectRatioScreen) / 2 : 0;
draw2DImageFilterScaled(driver, texture, draw2DImageFilterScaled(driver, texture,
core::rect<s32>(0, 0, screensize.X, screensize.Y), core::rect<s32>(0, 0, screensize.X, screensize.Y),
core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y), core::rect<s32>(sourceX, sourceY, sourcesize.X - sourceX, sourcesize.Y - sourceY),
NULL, NULL, true); NULL, NULL, true);
} }

View File

@ -3602,11 +3602,14 @@ void GUIFormSpecMenu::legacySortElements(core::list<IGUIElement *>::Iterator fro
} }
#if defined(__ANDROID__) || defined(__IOS__) #if defined(__ANDROID__) || defined(__IOS__)
bool GUIFormSpecMenu::getAndroidUIInput() bool GUIFormSpecMenu::getTouchUIInput()
{ {
if (m_jni_field_name.empty()) if (m_jni_field_name.empty())
return false; return false;
if (porting::getInputDialogOwner() != "modalmenu")
return false;
// still waiting // still waiting
if (porting::getInputDialogState() == -1) if (porting::getInputDialogState() == -1)
return true; return true;

View File

@ -266,7 +266,7 @@ public:
std::vector<std::string>* getDropDownValues(const std::string &name); std::vector<std::string>* getDropDownValues(const std::string &name);
#if defined(__ANDROID__) || defined(__IOS__) #if defined(__ANDROID__) || defined(__IOS__)
bool getAndroidUIInput(); bool getTouchUIInput();
#endif #endif
protected: protected:

View File

@ -346,6 +346,9 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
if (field_name.empty() || porting::hasRealKeyboard()) if (field_name.empty() || porting::hasRealKeyboard())
return retval; return retval;
if (porting::isInputDialogActive())
return retval;
m_jni_field_name = field_name; m_jni_field_name = field_name;
// single line text input // single line text input
@ -360,7 +363,8 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
type = 3; type = 3;
porting::showInputDialog(wide_to_utf8(getLabelByID(hovered->getID())), porting::showInputDialog(wide_to_utf8(getLabelByID(hovered->getID())),
wide_to_utf8(((gui::IGUIEditBox *)hovered)->getText()), type); wide_to_utf8(((gui::IGUIEditBox *)hovered)->getText()), type,
"modalmenu");
return retval; return retval;
} }
} }

View File

@ -58,7 +58,7 @@ public:
virtual bool OnEvent(const SEvent &event) { return false; }; virtual bool OnEvent(const SEvent &event) { return false; };
virtual bool pausesGame() { return false; } // Used for pause menu virtual bool pausesGame() { return false; } // Used for pause menu
#if defined(__ANDROID__) || defined(__IOS__) #if defined(__ANDROID__) || defined(__IOS__)
virtual bool getAndroidUIInput() { return false; } virtual bool getTouchUIInput() { return false; }
#endif #endif
protected: protected:

View File

@ -192,7 +192,7 @@ void ItemDefinition::deSerialize(std::istream &is)
// Deserialize // Deserialize
int version = readU8(is); int version = readU8(is);
if (version < 6) if (version < 1 || (version > 3 && version < 6))
throw SerializationError("unsupported ItemDefinition version"); throw SerializationError("unsupported ItemDefinition version");
type = (enum ItemType)readU8(is); type = (enum ItemType)readU8(is);
@ -200,7 +200,10 @@ void ItemDefinition::deSerialize(std::istream &is)
description = deSerializeString16(is); description = deSerializeString16(is);
inventory_image = deSerializeString16(is); inventory_image = deSerializeString16(is);
wield_image = deSerializeString16(is); wield_image = deSerializeString16(is);
if (version >= 6)
wield_scale = readV3F32(is); wield_scale = readV3F32(is);
else
wield_scale = readV3F1000(is);
stack_max = readS16(is); stack_max = readS16(is);
usable = readU8(is); usable = readU8(is);
liquids_pointable = readU8(is); liquids_pointable = readU8(is);
@ -220,21 +223,37 @@ void ItemDefinition::deSerialize(std::istream &is)
groups[name] = value; groups[name] = value;
} }
if (version < 2) {
// We can't be sure that node_placement_prediction is sent in version 1.
try {
node_placement_prediction = deSerializeString16(is);
} catch (SerializationError &e) {};
sound_place.name = "default_place_node";
sound_place.gain = 0.5;
return;
}
node_placement_prediction = deSerializeString16(is); node_placement_prediction = deSerializeString16(is);
// Version from ContentFeatures::serialize to keep in sync // Version from ContentFeatures::serialize to keep in sync
sound_place.deSerialize(is, CONTENTFEATURES_VERSION); const u8 cf_version = version >= 6 ? CONTENTFEATURES_VERSION : 9;
sound_place_failed.deSerialize(is, CONTENTFEATURES_VERSION); sound_place.deSerialize(is, cf_version);
range = readF32(is);
palette_image = deSerializeString16(is);
color = readARGB8(is);
inventory_overlay = deSerializeString16(is);
wield_overlay = deSerializeString16(is);
// If you add anything here, insert it primarily inside the try-catch // If you add anything here, insert it primarily inside the try-catch
// block to not need to increase the version. // block to not need to increase the version.
try { try {
if (version >= 6) {
sound_place_failed.deSerialize(is, cf_version);
range = readF32(is);
} else {
if (version >= 3)
range = readF1000(is);
sound_place_failed.deSerialize(is, cf_version);
}
palette_image = deSerializeString16(is);
color = readARGB8(is);
inventory_overlay = deSerializeString16(is);
wield_overlay = deSerializeString16(is);
short_description = deSerializeString16(is); short_description = deSerializeString16(is);
} catch(SerializationError &e) {}; } catch(SerializationError &e) {};
} }

View File

@ -72,7 +72,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
null_command_handler, null_command_handler,
null_command_handler, null_command_handler,
{ "TOCLIENT_CHAT_MESSAGE", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ChatMessage }, // 0x2F { "TOCLIENT_CHAT_MESSAGE", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ChatMessage }, // 0x2F
null_command_handler, // 0x30 { "TOCLIENT_CHAT_MESSAGE_OLD", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ChatMessageOld }, // 0x30
{ "TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ActiveObjectRemoveAdd }, // 0x31 { "TOCLIENT_ACTIVE_OBJECT_REMOVE_ADD", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ActiveObjectRemoveAdd }, // 0x31
{ "TOCLIENT_ACTIVE_OBJECT_MESSAGES", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ActiveObjectMessages }, // 0x32 { "TOCLIENT_ACTIVE_OBJECT_MESSAGES", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ActiveObjectMessages }, // 0x32
{ "TOCLIENT_HP", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HP }, // 0x33 { "TOCLIENT_HP", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HP }, // 0x33

View File

@ -397,6 +397,35 @@ void Client::handleCommand_TimeOfDay(NetworkPacket* pkt)
// << " dr=" << dr << std::endl; // << " dr=" << dr << std::endl;
} }
void Client::handleCommand_ChatMessageOld(NetworkPacket* pkt)
{
/*
u16 command
u16 length
wstring message
*/
u16 len, read_wchar;
*pkt >> len;
std::wstring message;
for (u32 i = 0; i < len; i++) {
*pkt >> read_wchar;
message += (wchar_t)read_wchar;
}
ChatMessage *chatMessage = new ChatMessage(message);
// @TODO send this to CSM using ChatMessage object
if (modsLoaded() && m_script->on_receiving_message(
wide_to_utf8(chatMessage->message))) {
// Message was consumed by CSM and should not be handled by client
delete chatMessage;
} else {
pushToChatQueue(chatMessage);
}
}
void Client::handleCommand_ChatMessage(NetworkPacket *pkt) void Client::handleCommand_ChatMessage(NetworkPacket *pkt)
{ {
/* /*
@ -560,7 +589,13 @@ void Client::handleCommand_HP(NetworkPacket *pkt)
u16 oldhp = player->hp; u16 oldhp = player->hp;
u16 hp; u16 hp;
if (m_proto_ver >= 37) {
*pkt >> hp; *pkt >> hp;
} else {
u8 raw_hp;
*pkt >> raw_hp;
hp = raw_hp;
}
player->hp = hp; player->hp = hp;
@ -916,6 +951,27 @@ void Client::handleCommand_InventoryFormSpec(NetworkPacket* pkt)
void Client::handleCommand_DetachedInventory(NetworkPacket* pkt) void Client::handleCommand_DetachedInventory(NetworkPacket* pkt)
{ {
// TODO: Unify this legacy code with the new code.
if (m_proto_ver < 37) {
std::string datastring(pkt->getString(0), pkt->getSize());
std::istringstream is(datastring, std::ios_base::binary);
std::string name = deSerializeString16(is);
infostream << "Client: Detached inventory update: \"" << name
<< "\"" << std::endl;
Inventory *inv = nullptr;
if (m_detached_inventories.count(name) > 0)
inv = m_detached_inventories[name];
else {
inv = new Inventory(m_itemdef);
m_detached_inventories[name] = inv;
}
inv->deSerialize(is);
return;
}
std::string name; std::string name;
bool keep_inv = true; bool keep_inv = true;
*pkt >> name >> keep_inv; *pkt >> name >> keep_inv;
@ -988,17 +1044,17 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
u16 attached_id = 0; u16 attached_id = 0;
p.amount = readU16(is); p.amount = readU16(is);
p.time = readF32(is); p.time = readF(is, m_proto_ver);
p.minpos = readV3F32(is); p.minpos = readV3F(is, m_proto_ver);
p.maxpos = readV3F32(is); p.maxpos = readV3F(is, m_proto_ver);
p.minvel = readV3F32(is); p.minvel = readV3F(is, m_proto_ver);
p.maxvel = readV3F32(is); p.maxvel = readV3F(is, m_proto_ver);
p.minacc = readV3F32(is); p.minacc = readV3F(is, m_proto_ver);
p.maxacc = readV3F32(is); p.maxacc = readV3F(is, m_proto_ver);
p.minexptime = readF32(is); p.minexptime = readF(is, m_proto_ver);
p.maxexptime = readF32(is); p.maxexptime = readF(is, m_proto_ver);
p.minsize = readF32(is); p.minsize = readF(is, m_proto_ver);
p.maxsize = readF32(is); p.maxsize = readF(is, m_proto_ver);
p.collisiondetection = readU8(is); p.collisiondetection = readU8(is);
p.texture = deSerializeString32(is); p.texture = deSerializeString32(is);
@ -1009,7 +1065,7 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
attached_id = readU16(is); attached_id = readU16(is);
p.animation.deSerialize(is, m_proto_ver); p.animation.deSerializeWithProtoVer(is, m_proto_ver);
p.glow = readU8(is); p.glow = readU8(is);
p.object_collision = readU8(is); p.object_collision = readU8(is);

View File

@ -177,6 +177,7 @@ controltype and data description:
#define CONTROLTYPE_SET_PEER_ID 1 #define CONTROLTYPE_SET_PEER_ID 1
#define CONTROLTYPE_PING 2 #define CONTROLTYPE_PING 2
#define CONTROLTYPE_DISCO 3 #define CONTROLTYPE_DISCO 3
#define CONTROLTYPE_ENABLE_BIG_SEND_WINDOW 4
/* /*
ORIGINAL: This is a plain packet with no control and no error ORIGINAL: This is a plain packet with no control and no error
@ -313,7 +314,8 @@ enum ConnectionCommandType{
CONNCMD_SEND, CONNCMD_SEND,
CONNCMD_SEND_TO_ALL, CONNCMD_SEND_TO_ALL,
CONCMD_ACK, CONCMD_ACK,
CONCMD_CREATE_PEER CONCMD_CREATE_PEER,
CONCMD_DISABLE_LEGACY
}; };
struct ConnectionCommand struct ConnectionCommand
@ -368,6 +370,16 @@ struct ConnectionCommand
reliable = true; reliable = true;
raw = true; raw = true;
} }
void disableLegacy(session_t peer_id_, const SharedBuffer<u8> &data_)
{
type = CONCMD_DISABLE_LEGACY;
peer_id = peer_id_;
data = data_;
channelnum = 0;
reliable = true;
raw = true;
}
}; };
/* maximum window size to use, 0xFFFF is theoretical maximum. don't think about /* maximum window size to use, 0xFFFF is theoretical maximum. don't think about

View File

@ -405,6 +405,15 @@ void ConnectionSendThread::processReliableCommand(ConnectionCommand &c)
} }
return; return;
case CONCMD_DISABLE_LEGACY:
LOG(dout_con << m_connection->getDesc()
<< "UDP processing reliable CONCMD_DISABLE_LEGACY" << std::endl);
if (!rawSendAsPacket(c.peer_id, c.channelnum, c.data, c.reliable)) {
/* put to queue if we couldn't send it immediately */
sendReliable(c);
}
return;
case CONNCMD_SERVE: case CONNCMD_SERVE:
case CONNCMD_CONNECT: case CONNCMD_CONNECT:
case CONNCMD_DISCONNECT: case CONNCMD_DISCONNECT:
@ -1185,6 +1194,17 @@ SharedBuffer<u8> ConnectionReceiveThread::handlePacketType_Control(Channel *chan
m_connection->SetPeerID(peer_id_new); m_connection->SetPeerID(peer_id_new);
} }
// Request the server disables "legacy peer mode" (0.4.X servers
// throttle outgoing packets if this does not happen).
// Minetest 5.X servers *should* ignore this.
ConnectionCommand cmd;
SharedBuffer<u8> reply(2);
writeU8(&reply[0], PACKET_TYPE_CONTROL);
writeU8(&reply[1], CONTROLTYPE_ENABLE_BIG_SEND_WINDOW);
cmd.disableLegacy(PEER_ID_SERVER, reply);
m_connection->putCommand(cmd);
throw ProcessedSilentlyException("Got a SET_PEER_ID"); throw ProcessedSilentlyException("Got a SET_PEER_ID");
} else if (controltype == CONTROLTYPE_PING) { } else if (controltype == CONTROLTYPE_PING) {
// Just ignore it, the incoming data already reset // Just ignore it, the incoming data already reset

View File

@ -218,7 +218,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// Client's supported network protocol range // Client's supported network protocol range
// The minimal version depends on whether // The minimal version depends on whether
// send_pre_v25_init is enabled or not // send_pre_v25_init is enabled or not
#define CLIENT_PROTOCOL_VERSION_MIN 37 #define CLIENT_PROTOCOL_VERSION_MIN 25
#define CLIENT_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION #define CLIENT_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION
// Constant that differentiates the protocol from random data and other protocols // Constant that differentiates the protocol from random data and other protocols

View File

@ -152,32 +152,34 @@ void NodeBox::serialize(std::ostream &os, u16 protocol_version) const
void NodeBox::deSerialize(std::istream &is) void NodeBox::deSerialize(std::istream &is)
{ {
int version = readU8(is); int version = readU8(is);
if (version < 6) if (version < 1 || (version > 3 && version < 6))
throw SerializationError("unsupported NodeBox version"); throw SerializationError("unsupported NodeBox version");
reset(); reset();
type = (enum NodeBoxType)readU8(is); type = (enum NodeBoxType)readU8(is);
// An approximate protocol version.
const u16 protocol_version = version > 3 ? 37 : 32;
if(type == NODEBOX_FIXED || type == NODEBOX_LEVELED) if(type == NODEBOX_FIXED || type == NODEBOX_LEVELED)
{ {
u16 fixed_count = readU16(is); u16 fixed_count = readU16(is);
while(fixed_count--) while(fixed_count--)
{ {
aabb3f box; aabb3f box;
box.MinEdge = readV3F32(is); box.MinEdge = readV3F(is, protocol_version);
box.MaxEdge = readV3F32(is); box.MaxEdge = readV3F(is, protocol_version);
fixed.push_back(box); fixed.push_back(box);
} }
} }
else if(type == NODEBOX_WALLMOUNTED) else if(type == NODEBOX_WALLMOUNTED)
{ {
wall_top.MinEdge = readV3F32(is); wall_top.MinEdge = readV3F(is, protocol_version);
wall_top.MaxEdge = readV3F32(is); wall_top.MaxEdge = readV3F(is, protocol_version);
wall_bottom.MinEdge = readV3F32(is); wall_bottom.MinEdge = readV3F(is, protocol_version);
wall_bottom.MaxEdge = readV3F32(is); wall_bottom.MaxEdge = readV3F(is, protocol_version);
wall_side.MinEdge = readV3F32(is); wall_side.MinEdge = readV3F(is, protocol_version);
wall_side.MaxEdge = readV3F32(is); wall_side.MaxEdge = readV3F(is, protocol_version);
} }
else if (type == NODEBOX_CONNECTED) else if (type == NODEBOX_CONNECTED)
{ {
@ -185,8 +187,8 @@ void NodeBox::deSerialize(std::istream &is)
count = readU16(is); \ count = readU16(is); \
(box).reserve(count); \ (box).reserve(count); \
while (count--) { \ while (count--) { \
v3f min = readV3F32(is); \ v3f min = readV3F(is, protocol_version); \
v3f max = readV3F32(is); \ v3f max = readV3F(is, protocol_version); \
(box).emplace_back(min, max); }; } (box).emplace_back(min, max); }; }
u16 count; u16 count;
@ -198,6 +200,8 @@ void NodeBox::deSerialize(std::istream &is)
READBOXES(connect_left); READBOXES(connect_left);
READBOXES(connect_back); READBOXES(connect_back);
READBOXES(connect_right); READBOXES(connect_right);
if (version <= 3)
return;
READBOXES(disconnected_top); READBOXES(disconnected_top);
READBOXES(disconnected_bottom); READBOXES(disconnected_bottom);
READBOXES(disconnected_front); READBOXES(disconnected_front);
@ -287,17 +291,37 @@ void TileDef::deSerialize(std::istream &is, u8 contentfeatures_version,
NodeDrawType drawtype) NodeDrawType drawtype)
{ {
int version = readU8(is); int version = readU8(is);
if (version < 6)
throw SerializationError("unsupported TileDef version");
name = deSerializeString16(is); name = deSerializeString16(is);
animation.deSerialize(is, version); animation.deSerialize(is, version);
bool has_scale = false;
bool has_align_style = false;
if (version >= 6) {
u16 flags = readU16(is); u16 flags = readU16(is);
backface_culling = flags & TILE_FLAG_BACKFACE_CULLING; backface_culling = flags & TILE_FLAG_BACKFACE_CULLING;
tileable_horizontal = flags & TILE_FLAG_TILEABLE_HORIZONTAL; tileable_horizontal = flags & TILE_FLAG_TILEABLE_HORIZONTAL;
tileable_vertical = flags & TILE_FLAG_TILEABLE_VERTICAL; tileable_vertical = flags & TILE_FLAG_TILEABLE_VERTICAL;
has_color = flags & TILE_FLAG_HAS_COLOR; has_color = flags & TILE_FLAG_HAS_COLOR;
bool has_scale = flags & TILE_FLAG_HAS_SCALE; has_scale = flags & TILE_FLAG_HAS_SCALE;
bool has_align_style = flags & TILE_FLAG_HAS_ALIGN_STYLE; has_align_style = flags & TILE_FLAG_HAS_ALIGN_STYLE;
} else {
if (version >= 1)
backface_culling = readU8(is);
if (version >= 2) {
tileable_horizontal = readU8(is);
tileable_vertical = readU8(is);
}
if (version >= 4)
has_color = readU8(is);
if ((contentfeatures_version < 8) &&
((drawtype == NDT_MESH) ||
(drawtype == NDT_FIRELIKE) ||
(drawtype == NDT_LIQUID) ||
(drawtype == NDT_PLANTLIKE)))
backface_culling = false;
}
if (has_color) { if (has_color) {
color.setRed(readU8(is)); color.setRed(readU8(is));
color.setGreen(readU8(is)); color.setGreen(readU8(is));
@ -572,12 +596,192 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const
writeU8(os, alpha); writeU8(os, alpha);
} }
void ContentFeatures::deSerializeOld(std::istream &is, int version)
{
if (version == 5) // In PROTOCOL_VERSION 13
{
name = deSerializeString16(is);
groups.clear();
u32 groups_size = readU16(is);
for(u32 i=0; i<groups_size; i++){
std::string name = deSerializeString16(is);
int value = readS16(is);
groups[name] = value;
}
drawtype = (enum NodeDrawType)readU8(is);
visual_scale = readF1000(is);
if (readU8(is) != 6)
throw SerializationError("unsupported tile count");
for (u32 i = 0; i < 6; i++)
tiledef[i].deSerialize(is, version, drawtype);
if (readU8(is) != CF_SPECIAL_COUNT)
throw SerializationError("unsupported CF_SPECIAL_COUNT");
for (u32 i = 0; i < CF_SPECIAL_COUNT; i++)
tiledef_special[i].deSerialize(is, version, drawtype);
setAlphaFromLegacy(readU8(is));
post_effect_color.setAlpha(readU8(is));
post_effect_color.setRed(readU8(is));
post_effect_color.setGreen(readU8(is));
post_effect_color.setBlue(readU8(is));
param_type = (enum ContentParamType)readU8(is);
param_type_2 = (enum ContentParamType2)readU8(is);
is_ground_content = readU8(is);
light_propagates = readU8(is);
sunlight_propagates = readU8(is);
walkable = readU8(is);
pointable = readU8(is);
diggable = readU8(is);
climbable = readU8(is);
buildable_to = readU8(is);
deSerializeString16(is); // legacy: used to be metadata_name
liquid_type = (enum LiquidType)readU8(is);
liquid_alternative_flowing = deSerializeString16(is);
liquid_alternative_source = deSerializeString16(is);
liquid_viscosity = readU8(is);
light_source = readU8(is);
light_source = MYMIN(light_source, LIGHT_MAX);
damage_per_second = readU32(is);
node_box.deSerialize(is);
selection_box.deSerialize(is);
legacy_facedir_simple = readU8(is);
legacy_wallmounted = readU8(is);
sound_footstep.deSerialize(is, version);
sound_dig.deSerialize(is, version);
sound_dug.deSerialize(is, version);
} else if (version == 6) {
name = deSerializeString16(is);
groups.clear();
u32 groups_size = readU16(is);
for (u32 i = 0; i < groups_size; i++) {
std::string name = deSerializeString16(is);
int value = readS16(is);
groups[name] = value;
}
drawtype = (enum NodeDrawType)readU8(is);
visual_scale = readF1000(is);
if (readU8(is) != 6)
throw SerializationError("unsupported tile count");
for (u32 i = 0; i < 6; i++)
tiledef[i].deSerialize(is, version, drawtype);
// CF_SPECIAL_COUNT in version 6 = 2
if (readU8(is) != 2)
throw SerializationError("unsupported CF_SPECIAL_COUNT");
for (u32 i = 0; i < 2; i++)
tiledef_special[i].deSerialize(is, version, drawtype);
setAlphaFromLegacy(readU8(is));
post_effect_color.setAlpha(readU8(is));
post_effect_color.setRed(readU8(is));
post_effect_color.setGreen(readU8(is));
post_effect_color.setBlue(readU8(is));
param_type = (enum ContentParamType)readU8(is);
param_type_2 = (enum ContentParamType2)readU8(is);
is_ground_content = readU8(is);
light_propagates = readU8(is);
sunlight_propagates = readU8(is);
walkable = readU8(is);
pointable = readU8(is);
diggable = readU8(is);
climbable = readU8(is);
buildable_to = readU8(is);
deSerializeString16(is); // legacy: used to be metadata_name
liquid_type = (enum LiquidType)readU8(is);
liquid_alternative_flowing = deSerializeString16(is);
liquid_alternative_source = deSerializeString16(is);
liquid_viscosity = readU8(is);
liquid_renewable = readU8(is);
light_source = readU8(is);
damage_per_second = readU32(is);
node_box.deSerialize(is);
selection_box.deSerialize(is);
legacy_facedir_simple = readU8(is);
legacy_wallmounted = readU8(is);
sound_footstep.deSerialize(is, version);
sound_dig.deSerialize(is, version);
sound_dug.deSerialize(is, version);
rightclickable = readU8(is);
drowning = readU8(is);
leveled = readU8(is);
liquid_range = readU8(is);
} else if (version == 7 || version == 8){
name = deSerializeString16(is);
groups.clear();
u32 groups_size = readU16(is);
for (u32 i = 0; i < groups_size; i++) {
std::string name = deSerializeString16(is);
int value = readS16(is);
groups[name] = value;
}
drawtype = (enum NodeDrawType) readU8(is);
visual_scale = readF1000(is);
if (readU8(is) != 6)
throw SerializationError("unsupported tile count");
for (u32 i = 0; i < 6; i++)
tiledef[i].deSerialize(is, version, drawtype);
if (readU8(is) != CF_SPECIAL_COUNT)
throw SerializationError("unsupported CF_SPECIAL_COUNT");
for (u32 i = 0; i < CF_SPECIAL_COUNT; i++)
tiledef_special[i].deSerialize(is, version, drawtype);
setAlphaFromLegacy(readU8(is));
post_effect_color.setAlpha(readU8(is));
post_effect_color.setRed(readU8(is));
post_effect_color.setGreen(readU8(is));
post_effect_color.setBlue(readU8(is));
param_type = (enum ContentParamType) readU8(is);
param_type_2 = (enum ContentParamType2) readU8(is);
is_ground_content = readU8(is);
light_propagates = readU8(is);
sunlight_propagates = readU8(is);
walkable = readU8(is);
pointable = readU8(is);
diggable = readU8(is);
climbable = readU8(is);
buildable_to = readU8(is);
deSerializeString16(is); // legacy: used to be metadata_name
liquid_type = (enum LiquidType) readU8(is);
liquid_alternative_flowing = deSerializeString16(is);
liquid_alternative_source = deSerializeString16(is);
liquid_viscosity = readU8(is);
liquid_renewable = readU8(is);
light_source = readU8(is);
light_source = MYMIN(light_source, LIGHT_MAX);
damage_per_second = readU32(is);
node_box.deSerialize(is);
selection_box.deSerialize(is);
legacy_facedir_simple = readU8(is);
legacy_wallmounted = readU8(is);
sound_footstep.deSerialize(is, version);
sound_dig.deSerialize(is, version);
sound_dug.deSerialize(is, version);
rightclickable = readU8(is);
drowning = readU8(is);
leveled = readU8(is);
liquid_range = readU8(is);
waving = readU8(is);
try {
mesh = deSerializeString16(is);
collision_box.deSerialize(is);
floodable = readU8(is);
u16 connects_to_size = readU16(is);
connects_to_ids.clear();
for (u16 i = 0; i < connects_to_size; i++)
connects_to_ids.push_back(readU16(is));
connect_sides = readU8(is);
} catch (SerializationError &e) {};
}else{
throw SerializationError("unsupported ContentFeatures version");
}
}
void ContentFeatures::deSerialize(std::istream &is) void ContentFeatures::deSerialize(std::istream &is)
{ {
// version detection // version detection
const u8 version = readU8(is); const u8 version = readU8(is);
if (version < CONTENTFEATURES_VERSION) if (version < 9) {
throw SerializationError("unsupported ContentFeatures version"); deSerializeOld(is, version);
return;
}
// general // general
name = deSerializeString16(is); name = deSerializeString16(is);
@ -594,7 +798,10 @@ void ContentFeatures::deSerialize(std::istream &is)
// visual // visual
drawtype = (enum NodeDrawType) readU8(is); drawtype = (enum NodeDrawType) readU8(is);
mesh = deSerializeString16(is); mesh = deSerializeString16(is);
if (version > 12)
visual_scale = readF32(is); visual_scale = readF32(is);
else
visual_scale = readF1000(is);
if (readU8(is) != 6) if (readU8(is) != 6)
throw SerializationError("unsupported tile count"); throw SerializationError("unsupported tile count");
for (TileDef &td : tiledef) for (TileDef &td : tiledef)

View File

@ -423,6 +423,7 @@ struct ContentFeatures
void reset(); void reset();
void serialize(std::ostream &os, u16 protocol_version) const; void serialize(std::ostream &os, u16 protocol_version) const;
void deSerialize(std::istream &is); void deSerialize(std::istream &is);
void deSerializeOld(std::istream &is, int version);
void serializeOld(std::ostream &os, u16 protocol_version) const; void serializeOld(std::ostream &os, u16 protocol_version) const;
/* /*

View File

@ -222,19 +222,34 @@ void ObjectProperties::serialize(std::ostream &os, u16 protocol_version) const
void ObjectProperties::deSerialize(std::istream &is) void ObjectProperties::deSerialize(std::istream &is)
{ {
int version = readU8(is); int version = readU8(is);
if (version != 4) if (version != 1 && version != 4)
throw SerializationError("unsupported ObjectProperties version"); throw SerializationError("unsupported ObjectProperties version");
// Another approximate protocol version.
const u16 protocol_version = version == 1 ? 32 : 37;
try {
hp_max = readU16(is); hp_max = readU16(is);
physical = readU8(is); physical = readU8(is);
readU32(is); // removed property (weight) readU32(is); // removed property (weight)
collisionbox.MinEdge = readV3F32(is); collisionbox.MinEdge = readV3F(is, protocol_version);
collisionbox.MaxEdge = readV3F32(is); collisionbox.MaxEdge = readV3F(is, protocol_version);
if (version >= 4) {
selectionbox.MinEdge = readV3F32(is); selectionbox.MinEdge = readV3F32(is);
selectionbox.MaxEdge = readV3F32(is); selectionbox.MaxEdge = readV3F32(is);
pointable = readU8(is); pointable = readU8(is);
} else {
selectionbox.MinEdge = collisionbox.MinEdge;
selectionbox.MaxEdge = collisionbox.MaxEdge;
pointable = true;
}
visual = deSerializeString16(is); visual = deSerializeString16(is);
if (version == 1) {
v2f size = readV2F1000(is);
visual_size = v3f(size.X, size.Y, size.X);
} else {
visual_size = readV3F32(is); visual_size = readV3F32(is);
}
textures.clear(); textures.clear();
u32 texture_count = readU16(is); u32 texture_count = readU16(is);
for (u32 i = 0; i < texture_count; i++){ for (u32 i = 0; i < texture_count; i++){
@ -244,7 +259,7 @@ void ObjectProperties::deSerialize(std::istream &is)
initial_sprite_basepos = readV2S16(is); initial_sprite_basepos = readV2S16(is);
is_visible = readU8(is); is_visible = readU8(is);
makes_footstep_sound = readU8(is); makes_footstep_sound = readU8(is);
automatic_rotate = readF32(is); automatic_rotate = readF(is, protocol_version);
mesh = deSerializeString16(is); mesh = deSerializeString16(is);
colors.clear(); colors.clear();
u32 color_count = readU16(is); u32 color_count = readU16(is);
@ -252,21 +267,27 @@ void ObjectProperties::deSerialize(std::istream &is)
colors.push_back(readARGB8(is)); colors.push_back(readARGB8(is));
} }
collideWithObjects = readU8(is); collideWithObjects = readU8(is);
stepheight = readF32(is); stepheight = readF(is, protocol_version);
automatic_face_movement_dir = readU8(is); automatic_face_movement_dir = readU8(is);
automatic_face_movement_dir_offset = readF32(is); automatic_face_movement_dir_offset = readF(is, protocol_version);
backface_culling = readU8(is); backface_culling = readU8(is);
nametag = deSerializeString16(is); nametag = deSerializeString16(is);
nametag_color = readARGB8(is); nametag_color = readARGB8(is);
automatic_face_movement_max_rotation_per_sec = readF32(is); automatic_face_movement_max_rotation_per_sec = readF(is,
protocol_version);
infotext = deSerializeString16(is); infotext = deSerializeString16(is);
wield_item = deSerializeString16(is); wield_item = deSerializeString16(is);
// The "glow" property exists in MultiCraft 1.
glow = readS8(is); glow = readS8(is);
if (version == 1)
return;
breath_max = readU16(is); breath_max = readU16(is);
eye_height = readF32(is); eye_height = readF32(is);
zoom_fov = readF32(is); zoom_fov = readF32(is);
use_texture_alpha = readU8(is); use_texture_alpha = readU8(is);
try {
damage_texture_modifier = deSerializeString16(is); damage_texture_modifier = deSerializeString16(is);
u8 tmp = readU8(is); u8 tmp = readU8(is);
if (is.eof()) if (is.eof())

View File

@ -41,16 +41,18 @@ void ParticleParameters::serialize(std::ostream &os, u16 protocol_ver) const
void ParticleParameters::deSerialize(std::istream &is, u16 protocol_ver) void ParticleParameters::deSerialize(std::istream &is, u16 protocol_ver)
{ {
pos = readV3F32(is); pos = readV3F(is, protocol_ver);
vel = readV3F32(is); vel = readV3F(is, protocol_ver);
acc = readV3F32(is); acc = readV3F(is, protocol_ver);
expirationtime = readF32(is); expirationtime = readF(is, protocol_ver);
size = readF32(is); size = readF(is, protocol_ver);
collisiondetection = readU8(is); collisiondetection = readU8(is);
texture = deSerializeString32(is); texture = deSerializeString32(is);
vertical = readU8(is); vertical = readU8(is);
collision_removal = readU8(is); collision_removal = readU8(is);
animation.deSerialize(is, 6); /* NOT the protocol ver */ animation.deSerializeWithProtoVer(is, protocol_ver);
// TODO: Ensure this doesn't error
glow = readU8(is); glow = readU8(is);
object_collision = readU8(is); object_collision = readU8(is);
// This is kinda awful // This is kinda awful

View File

@ -95,6 +95,7 @@ namespace porting {
JNIEnv *jnienv; JNIEnv *jnienv;
jclass activityClass; jclass activityClass;
jobject activityObj; jobject activityObj;
std::string input_dialog_owner;
jclass findClass(const std::string &classname) jclass findClass(const std::string &classname)
{ {
@ -209,8 +210,10 @@ void initializePaths()
activityObj, mt_getAbsPath, "getCacheDir"); activityObj, mt_getAbsPath, "getCacheDir");
} }
void showInputDialog(const std::string &hint, const std::string &current, int editType) void showInputDialog(const std::string &hint, const std::string &current, int editType, std::string owner)
{ {
input_dialog_owner = owner;
jmethodID showdialog = jnienv->GetMethodID(activityClass, "showDialog", jmethodID showdialog = jnienv->GetMethodID(activityClass, "showDialog",
"(Ljava/lang/String;Ljava/lang/String;I)V"); "(Ljava/lang/String;Ljava/lang/String;I)V");
@ -236,6 +239,22 @@ void openURIAndroid(const std::string &url)
jnienv->CallVoidMethod(activityObj, url_open, jurl); jnienv->CallVoidMethod(activityObj, url_open, jurl);
} }
std::string getInputDialogOwner()
{
return input_dialog_owner;
}
bool isInputDialogActive()
{
jmethodID dialog_active = jnienv->GetMethodID(activityClass,
"isDialogActive", "()Z");
FATAL_ERROR_IF(dialog_active == nullptr,
"porting::isInputDialogActive unable to find Java dialog state method");
return jnienv->CallBooleanMethod(activityObj, dialog_active);
}
int getInputDialogState() int getInputDialogState()
{ {
jmethodID dialogstate = jnienv->GetMethodID(activityClass, jmethodID dialogstate = jnienv->GetMethodID(activityClass,
@ -249,6 +268,8 @@ int getInputDialogState()
std::string getInputDialogValue() std::string getInputDialogValue()
{ {
input_dialog_owner = "";
jmethodID dialogvalue = jnienv->GetMethodID(activityClass, jmethodID dialogvalue = jnienv->GetMethodID(activityClass,
"getDialogValue", "()Ljava/lang/String;"); "getDialogValue", "()Ljava/lang/String;");

View File

@ -34,6 +34,8 @@ namespace porting {
// java <-> c++ interaction interface // java <-> c++ interaction interface
extern JNIEnv *jnienv; extern JNIEnv *jnienv;
extern std::string input_dialog_owner;
// do initialization required on android only // do initialization required on android only
void initAndroid(); void initAndroid();
@ -51,7 +53,11 @@ void initializePaths();
* @param editType type of texfield * @param editType type of texfield
* (1 == multiline text input; 2 == single line text input; 3 == password field) * (1 == multiline text input; 2 == single line text input; 3 == password field)
*/ */
void showInputDialog(const std::string &hint, const std::string &current, int editType); void showInputDialog(const std::string &hint, const std::string &current, int editType, std::string owner = "");
std::string getInputDialogOwner();
bool isInputDialogActive();
void openURIAndroid(const std::string &url); void openURIAndroid(const std::string &url);

View File

@ -56,9 +56,16 @@ struct SimpleSoundSpec
void deSerialize(std::istream &is, u8 cf_version) void deSerialize(std::istream &is, u8 cf_version)
{ {
name = deSerializeString16(is); name = deSerializeString16(is);
if (cf_version > 12) {
gain = readF32(is); gain = readF32(is);
pitch = readF32(is); pitch = readF32(is);
fade = readF32(is); fade = readF32(is);
} else {
// Minetest 0.4 compatibility
gain = readF1000(is);
pitch = 1.0f;
fade = 0.0f;
}
} }
std::string name; std::string name;

View File

@ -49,17 +49,42 @@ void TileAnimationParams::deSerialize(std::istream &is, u8 tiledef_version)
{ {
type = (TileAnimationType) readU8(is); type = (TileAnimationType) readU8(is);
if (type == TAT_VERTICAL_FRAMES) { FATAL_ERROR_IF(tiledef_version >= 25, "TileAnimationParams::deSerialize "
"called with what is probably a protocol version.");
// Approximate protocol version
u16 protocol_version = tiledef_version >= 6 ? 37 : 32;
if (type == TAT_VERTICAL_FRAMES || tiledef_version <= 2) {
vertical_frames.aspect_w = readU16(is); vertical_frames.aspect_w = readU16(is);
vertical_frames.aspect_h = readU16(is); vertical_frames.aspect_h = readU16(is);
vertical_frames.length = fabs(readF32(is)); // Don't hang if a negative length is sent
vertical_frames.length = fabs(readF(is, protocol_version));
} else if (type == TAT_SHEET_2D) { } else if (type == TAT_SHEET_2D) {
sheet_2d.frames_w = readU8(is); sheet_2d.frames_w = readU8(is);
sheet_2d.frames_h = readU8(is); sheet_2d.frames_h = readU8(is);
sheet_2d.frame_length = fabs(readF32(is)); sheet_2d.frame_length = fabs(readF(is, protocol_version));
} }
} }
void TileAnimationParams::deSerializeWithProtoVer(std::istream &is,
u16 protocol_version)
{
u8 tiledef_version;
if (protocol_version >= 37)
tiledef_version = 6;
else if (protocol_version >= 30)
tiledef_version = 4;
else if (protocol_version >= 29)
tiledef_version = 3;
else if (protocol_version >= 26)
tiledef_version = 2;
else
tiledef_version = 1;
deSerialize(is, tiledef_version);
}
void TileAnimationParams::determineParams(v2u32 texture_size, int *frame_count, void TileAnimationParams::determineParams(v2u32 texture_size, int *frame_count,
int *frame_length_ms, v2u32 *frame_size) const int *frame_length_ms, v2u32 *frame_size) const
{ {

View File

@ -52,6 +52,7 @@ struct TileAnimationParams
void serialize(std::ostream &os, u8 tiledef_version) const; void serialize(std::ostream &os, u8 tiledef_version) const;
void deSerialize(std::istream &is, u8 tiledef_version); void deSerialize(std::istream &is, u8 tiledef_version);
void deSerializeWithProtoVer(std::istream &is, u16 protocol_version);
void determineParams(v2u32 texture_size, int *frame_count, int *frame_length_ms, void determineParams(v2u32 texture_size, int *frame_count, int *frame_length_ms,
v2u32 *frame_size) const; v2u32 *frame_size) const;
void getTextureModifer(std::ostream &os, v2u32 texture_size, int frame) const; void getTextureModifer(std::ostream &os, v2u32 texture_size, int frame) const;

View File

@ -92,10 +92,13 @@ void ToolCapabilities::serialize(std::ostream &os, u16 protocol_version) const
void ToolCapabilities::deSerialize(std::istream &is) void ToolCapabilities::deSerialize(std::istream &is)
{ {
int version = readU8(is); int version = readU8(is);
if (version < 4) if (version != 1 && version != 2 && version < 4)
throw SerializationError("unsupported ToolCapabilities version"); throw SerializationError("unsupported ToolCapabilities version");
if (version > 3)
full_punch_interval = readF32(is); full_punch_interval = readF32(is);
else
full_punch_interval = readF1000(is);
max_drop_level = readS16(is); max_drop_level = readS16(is);
groupcaps.clear(); groupcaps.clear();
u32 groupcaps_size = readU32(is); u32 groupcaps_size = readU32(is);
@ -107,7 +110,11 @@ void ToolCapabilities::deSerialize(std::istream &is)
u32 times_size = readU32(is); u32 times_size = readU32(is);
for(u32 i = 0; i < times_size; i++) { for(u32 i = 0; i < times_size; i++) {
int level = readS16(is); int level = readS16(is);
float time = readF32(is); float time;
if (version > 3)
time = readF32(is);
else
time = readF1000(is);
cap.times[level] = time; cap.times[level] = time;
} }
groupcaps[name] = cap; groupcaps[name] = cap;