summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/clientopcodes.cpp6
-rw-r--r--src/network/clientpackethandler.cpp171
-rw-r--r--src/network/connection.cpp32
-rw-r--r--src/network/connection.h6
-rw-r--r--src/network/networkprotocol.h62
-rw-r--r--src/network/serveropcodes.cpp12
-rw-r--r--src/network/serverpackethandler.cpp13
7 files changed, 242 insertions, 60 deletions
diff --git a/src/network/clientopcodes.cpp b/src/network/clientopcodes.cpp
index 498583df9..431455b76 100644
--- a/src/network/clientopcodes.cpp
+++ b/src/network/clientopcodes.cpp
@@ -114,9 +114,9 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_MODCHANNEL_MSG", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ModChannelMsg }, // 0x57
{ "TOCLIENT_MODCHANNEL_SIGNAL", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_ModChannelSignal }, // 0x58
{ "TOCLIENT_NODEMETA_CHANGED", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_NodemetaChanged }, // 0x59
- null_command_handler,
- null_command_handler,
- null_command_handler,
+ { "TOCLIENT_SET_SUN", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudSetSun }, // 0x5a
+ { "TOCLIENT_SET_MOON", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudSetMoon }, // 0x5b
+ { "TOCLIENT_SET_STARS", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_HudSetStars }, // 0x5c
null_command_handler,
null_command_handler,
null_command_handler,
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index b6e9defb0..432fb415e 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -40,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/srp.h"
#include "tileanimation.h"
#include "gettext.h"
+#include "skyparams.h"
void Client::handleCommand_Deprecated(NetworkPacket* pkt)
{
@@ -134,6 +135,9 @@ void Client::handleCommand_AuthAccept(NetworkPacket* pkt)
<< m_recommended_send_interval<<std::endl;
// Reply to server
+ /*~ DO NOT TRANSLATE THIS LITERALLY!
+ This is a special string which needs to contain the translation's
+ language code (e.g. "de" for German). */
std::string lang = gettext("LANG_CODE");
if (lang == "LANG_CODE")
lang = "";
@@ -778,6 +782,7 @@ void Client::handleCommand_PlaySound(NetworkPacket* pkt)
[25 + len] bool loop
[26 + len] f32 fade
[30 + len] f32 pitch
+ [34 + len] bool ephemeral
*/
s32 server_id;
@@ -790,12 +795,14 @@ void Client::handleCommand_PlaySound(NetworkPacket* pkt)
bool loop;
float fade = 0.0f;
float pitch = 1.0f;
+ bool ephemeral = false;
*pkt >> server_id >> name >> gain >> type >> pos >> object_id >> loop;
try {
*pkt >> fade;
*pkt >> pitch;
+ *pkt >> ephemeral;
} catch (PacketError &e) {};
// Start playing
@@ -813,7 +820,6 @@ void Client::handleCommand_PlaySound(NetworkPacket* pkt)
if (cao)
pos = cao->getPosition();
client_id = m_sound->playSoundAt(name, loop, gain, pos, pitch);
- // TODO: Set up sound to move with object
break;
}
default:
@@ -821,8 +827,11 @@ void Client::handleCommand_PlaySound(NetworkPacket* pkt)
}
if (client_id != -1) {
- m_sounds_server_to_client[server_id] = client_id;
- m_sounds_client_to_server[client_id] = server_id;
+ // for ephemeral sounds, server_id is not meaningful
+ if (!ephemeral) {
+ m_sounds_server_to_client[server_id] = client_id;
+ m_sounds_client_to_server[client_id] = server_id;
+ }
if (object_id != 0)
m_sounds_to_objects[client_id] = object_id;
}
@@ -1081,6 +1090,7 @@ void Client::handleCommand_HudAdd(NetworkPacket* pkt)
v2f offset;
v3f world_pos;
v2s32 size;
+ s16 z_index = 0;
*pkt >> server_id >> type >> pos >> name >> scale >> text >> number >> item
>> dir >> align >> offset;
@@ -1093,6 +1103,11 @@ void Client::handleCommand_HudAdd(NetworkPacket* pkt)
*pkt >> size;
} catch(SerializationError &e) {};
+ try {
+ *pkt >> z_index;
+ }
+ catch(PacketError &e) {}
+
ClientEvent *event = new ClientEvent();
event->type = CE_HUDADD;
event->hudadd.server_id = server_id;
@@ -1108,6 +1123,7 @@ void Client::handleCommand_HudAdd(NetworkPacket* pkt)
event->hudadd.offset = new v2f(offset);
event->hudadd.world_pos = new v3f(world_pos);
event->hudadd.size = new v2s32(size);
+ event->hudadd.z_index = z_index;
m_client_event_queue.push(event);
}
@@ -1212,49 +1228,140 @@ void Client::handleCommand_HudSetParam(NetworkPacket* pkt)
player->hud_hotbar_itemcount = hotbar_itemcount;
}
else if (param == HUD_PARAM_HOTBAR_IMAGE) {
- // If value not empty verify image exists in texture source
- if (!value.empty() && !getTextureSource()->isKnownSourceImage(value)) {
- errorstream << "Server sent wrong Hud hotbar image (sent value: '"
- << value << "')" << std::endl;
- return;
- }
player->hotbar_image = value;
}
else if (param == HUD_PARAM_HOTBAR_SELECTED_IMAGE) {
- // If value not empty verify image exists in texture source
- if (!value.empty() && !getTextureSource()->isKnownSourceImage(value)) {
- errorstream << "Server sent wrong Hud hotbar selected image (sent value: '"
- << value << "')" << std::endl;
- return;
- }
player->hotbar_selected_image = value;
}
}
void Client::handleCommand_HudSetSky(NetworkPacket* pkt)
{
- std::string datastring(pkt->getString(0), pkt->getSize());
- std::istringstream is(datastring, std::ios_base::binary);
+ if (m_proto_ver < 39) {
+ // Handle Protocol 38 and below servers with old set_sky,
+ // ensuring the classic look is kept.
+ std::string datastring(pkt->getString(0), pkt->getSize());
+ std::istringstream is(datastring, std::ios_base::binary);
- video::SColor *bgcolor = new video::SColor(readARGB8(is));
- std::string *type = new std::string(deSerializeString(is));
- u16 count = readU16(is);
- std::vector<std::string> *params = new std::vector<std::string>;
+ SkyboxParams skybox;
+ skybox.bgcolor = video::SColor(readARGB8(is));
+ skybox.type = std::string(deSerializeString(is));
+ u16 count = readU16(is);
+
+ for (size_t i = 0; i < count; i++)
+ skybox.textures.emplace_back(deSerializeString(is));
+
+ skybox.clouds = true;
+ try {
+ skybox.clouds = readU8(is);
+ } catch (...) {}
+
+ // Use default skybox settings:
+ SkyboxDefaults sky_defaults;
+ SunParams sun = sky_defaults.getSunDefaults();
+ MoonParams moon = sky_defaults.getMoonDefaults();
+ StarParams stars = sky_defaults.getStarDefaults();
+
+ // Fix for "regular" skies, as color isn't kept:
+ if (skybox.type == "regular") {
+ skybox.sky_color = sky_defaults.getSkyColorDefaults();
+ skybox.tint_type = "default";
+ skybox.moon_tint = video::SColor(255, 255, 255, 255);
+ skybox.sun_tint = video::SColor(255, 255, 255, 255);
+ }
+ else {
+ sun.visible = false;
+ sun.sunrise_visible = false;
+ moon.visible = false;
+ stars.visible = false;
+ }
- for (size_t i = 0; i < count; i++)
- params->push_back(deSerializeString(is));
+ // Skybox, sun, moon and stars ClientEvents:
+ ClientEvent *sky_event = new ClientEvent();
+ sky_event->type = CE_SET_SKY;
+ sky_event->set_sky = new SkyboxParams(skybox);
+ m_client_event_queue.push(sky_event);
+
+ ClientEvent *sun_event = new ClientEvent();
+ sun_event->type = CE_SET_SUN;
+ sun_event->sun_params = new SunParams(sun);
+ m_client_event_queue.push(sun_event);
+
+ ClientEvent *moon_event = new ClientEvent();
+ moon_event->type = CE_SET_MOON;
+ moon_event->moon_params = new MoonParams(moon);
+ m_client_event_queue.push(moon_event);
+
+ ClientEvent *star_event = new ClientEvent();
+ star_event->type = CE_SET_STARS;
+ star_event->star_params = new StarParams(stars);
+ m_client_event_queue.push(star_event);
+ } else {
+ SkyboxParams skybox;
+ u16 texture_count;
+ std::string texture;
+
+ *pkt >> skybox.bgcolor >> skybox.type >> skybox.clouds >>
+ skybox.sun_tint >> skybox.moon_tint >> skybox.tint_type;
+
+ if (skybox.type == "skybox") {
+ *pkt >> texture_count;
+ for (int i = 0; i < texture_count; i++) {
+ *pkt >> texture;
+ skybox.textures.emplace_back(texture);
+ }
+ }
+ else if (skybox.type == "regular") {
+ *pkt >> skybox.sky_color.day_sky >> skybox.sky_color.day_horizon
+ >> skybox.sky_color.dawn_sky >> skybox.sky_color.dawn_horizon
+ >> skybox.sky_color.night_sky >> skybox.sky_color.night_horizon
+ >> skybox.sky_color.indoors;
+ }
- bool clouds = true;
- try {
- clouds = readU8(is);
- } catch (...) {}
+ ClientEvent *event = new ClientEvent();
+ event->type = CE_SET_SKY;
+ event->set_sky = new SkyboxParams(skybox);
+ m_client_event_queue.push(event);
+ }
+}
+
+void Client::handleCommand_HudSetSun(NetworkPacket *pkt)
+{
+ SunParams sun;
+
+ *pkt >> sun.visible >> sun.texture>> sun.tonemap
+ >> sun.sunrise >> sun.sunrise_visible >> sun.scale;
ClientEvent *event = new ClientEvent();
- event->type = CE_SET_SKY;
- event->set_sky.bgcolor = bgcolor;
- event->set_sky.type = type;
- event->set_sky.params = params;
- event->set_sky.clouds = clouds;
+ event->type = CE_SET_SUN;
+ event->sun_params = new SunParams(sun);
+ m_client_event_queue.push(event);
+}
+
+void Client::handleCommand_HudSetMoon(NetworkPacket *pkt)
+{
+ MoonParams moon;
+
+ *pkt >> moon.visible >> moon.texture
+ >> moon.tonemap >> moon.scale;
+
+ ClientEvent *event = new ClientEvent();
+ event->type = CE_SET_MOON;
+ event->moon_params = new MoonParams(moon);
+ m_client_event_queue.push(event);
+}
+
+void Client::handleCommand_HudSetStars(NetworkPacket *pkt)
+{
+ StarParams stars;
+
+ *pkt >> stars.visible >> stars.count
+ >> stars.starcolor >> stars.scale;
+
+ ClientEvent *event = new ClientEvent();
+ event->type = CE_SET_STARS;
+ event->star_params = new StarParams(stars);
+
m_client_event_queue.push(event);
}
diff --git a/src/network/connection.cpp b/src/network/connection.cpp
index a99e5b145..36124ce3c 100644
--- a/src/network/connection.cpp
+++ b/src/network/connection.cpp
@@ -41,17 +41,23 @@ namespace con
/* defines used for debugging and profiling */
/******************************************************************************/
#ifdef NDEBUG
-#define LOG(a) a
-#define PROFILE(a)
+ #define LOG(a) a
+ #define PROFILE(a)
#else
-/* this mutex is used to achieve log message consistency */
-std::mutex log_message_mutex;
-#define LOG(a) \
- { \
- MutexAutoLock loglock(log_message_mutex); \
- a; \
- }
-#define PROFILE(a) a
+ #if 0
+ /* this mutex is used to achieve log message consistency */
+ std::mutex log_message_mutex;
+ #define LOG(a) \
+ { \
+ MutexAutoLock loglock(log_message_mutex); \
+ a; \
+ }
+ #else
+ // Prevent deadlocks until a solution is found after 5.2.0 (TODO)
+ #define LOG(a) a
+ #endif
+
+ #define PROFILE(a) a
#endif
#define PING_TIMEOUT 5.0
@@ -1073,6 +1079,10 @@ bool UDPPeer::processReliableSendCommand(
FATAL_ERROR_IF(!successfully_put_back_sequence_number, "error");
}
+ // DO NOT REMOVE n_queued! It avoids a deadlock of async locked
+ // 'log_message_mutex' and 'm_list_mutex'.
+ u32 n_queued = channels[c.channelnum].outgoing_reliables_sent.size();
+
LOG(dout_con<<m_connection->getDesc()
<< " Windowsize exceeded on reliable sending "
<< c.data.getSize() << " bytes"
@@ -1081,7 +1091,7 @@ bool UDPPeer::processReliableSendCommand(
<< std::endl << "\t\tgot at most : "
<< packets_available << " packets"
<< std::endl << "\t\tpackets queued : "
- << channels[c.channelnum].outgoing_reliables_sent.size()
+ << n_queued
<< std::endl);
return false;
diff --git a/src/network/connection.h b/src/network/connection.h
index d7f1e0fe8..0b12bf701 100644
--- a/src/network/connection.h
+++ b/src/network/connection.h
@@ -612,16 +612,16 @@ class Peer {
struct rttstats {
float jitter_min = FLT_MAX;
float jitter_max = 0.0f;
- float jitter_avg = -1.0f;
+ float jitter_avg = -2.0f;
float min_rtt = FLT_MAX;
float max_rtt = 0.0f;
- float avg_rtt = -1.0f;
+ float avg_rtt = -2.0f;
rttstats() = default;
};
rttstats m_rtt;
- float m_last_rtt = -1.0f;
+ float m_last_rtt = -2.0f;
// current usage count
unsigned int m_usage = 0;
diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h
index 5a13c1353..d3799868b 100644
--- a/src/network/networkprotocol.h
+++ b/src/network/networkprotocol.h
@@ -200,9 +200,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Unknown inventory serialization fields no longer throw an error
Mod-specific formspec version
Player FOV override API
+ "ephemeral" added to TOCLIENT_PLAY_SOUND
+ PROTOCOL VERSION 39:
+ Updated set_sky packet
+ Adds new sun, moon and stars packets
*/
-#define LATEST_PROTOCOL_VERSION 38
+#define LATEST_PROTOCOL_VERSION 39
#define LATEST_PROTOCOL_VERSION_STRING TOSTRING(LATEST_PROTOCOL_VERSION)
// Server's supported network protocol range
@@ -228,9 +232,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
(too much)
FORMSPEC VERSION 2:
Forced real coordinates
- background[]: 9-slice scaling parameters
+ background9[]: 9-slice scaling parameters
+ FORMSPEC VERSION 3:
+ Formspec elements are drawn in the order of definition
+ bgcolor[]: use 3 parameters (bgcolor, formspec (now an enum), fbgcolor)
+ box[] and image[] elements enable clipping by default
*/
-#define FORMSPEC_API_VERSION 2
+#define FORMSPEC_API_VERSION 3
#define TEXTURENAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-"
@@ -446,6 +454,7 @@ enum ToClientCommand
s32[3] pos_nodes*10000
u16 object_id
u8 loop (bool)
+ u8 ephemeral (bool)
*/
TOCLIENT_STOP_SOUND = 0x40,
@@ -561,6 +570,7 @@ enum ToClientCommand
v2f1000 offset
v3f1000 world_pos
v2s32 size
+ s16 z_index
*/
TOCLIENT_HUDRM = 0x4a,
@@ -598,7 +608,8 @@ enum ToClientCommand
TOCLIENT_SET_SKY = 0x4f,
/*
- u8[4] color (ARGB)
+ Protocol 38:
+ u8[4] base_color (ARGB)
u8 len
u8[len] type
u16 count
@@ -606,6 +617,24 @@ enum ToClientCommand
u8 len
u8[len] param
u8 clouds (boolean)
+
+ Protocol 39:
+ u8[4] bgcolor (ARGB)
+ std::string type
+ int texture_count
+ std::string[6] param
+ bool clouds
+ bool bgcolor_fog
+ u8[4] day_sky (ARGB)
+ u8[4] day_horizon (ARGB)
+ u8[4] dawn_sky (ARGB)
+ u8[4] dawn_horizon (ARGB)
+ u8[4] night_sky (ARGB)
+ u8[4] night_horizon (ARGB)
+ u8[4] indoors (ARGB)
+ u8[4] sun_tint (ARGB)
+ u8[4] moon_tint (ARGB)
+ std::string tint_type
*/
TOCLIENT_OVERRIDE_DAY_NIGHT_RATIO = 0x50,
@@ -681,6 +710,31 @@ enum ToClientCommand
serialized and compressed node metadata
*/
+ TOCLIENT_SET_SUN = 0x5a,
+ /*
+ bool visible
+ std::string texture
+ std::string tonemap
+ std::string sunrise
+ f32 scale
+ */
+
+ TOCLIENT_SET_MOON = 0x5b,
+ /*
+ bool visible
+ std::string texture
+ std::string tonemap
+ f32 scale
+ */
+
+ TOCLIENT_SET_STARS = 0x5c,
+ /*
+ bool visible
+ u32 count
+ u8[4] starcolor (ARGB)
+ f32 scale
+ */
+
TOCLIENT_SRP_BYTES_S_B = 0x60,
/*
Belonging to AUTH_MECHANISM_SRP.
diff --git a/src/network/serveropcodes.cpp b/src/network/serveropcodes.cpp
index 8c8d49955..cca2e56ea 100644
--- a/src/network/serveropcodes.cpp
+++ b/src/network/serveropcodes.cpp
@@ -203,12 +203,12 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_MODCHANNEL_MSG", 0, true }, // 0x57
{ "TOCLIENT_MODCHANNEL_SIGNAL", 0, true }, // 0x58
{ "TOCLIENT_NODEMETA_CHANGED", 0, true }, // 0x59
- null_command_factory, // 0x5A
- null_command_factory, // 0x5B
- null_command_factory, // 0x5C
- null_command_factory, // 0x5D
- null_command_factory, // 0x5E
- null_command_factory, // 0x5F
+ { "TOCLIENT_SET_SUN", 0, true }, // 0x5a
+ { "TOCLIENT_SET_MOON", 0, true }, // 0x5b
+ { "TOCLIENT_SET_STARS", 0, true }, // 0x5c
+ null_command_factory, // 0x5d
+ null_command_factory, // 0x5e
+ null_command_factory, // 0x5f
{ "TOSERVER_SRP_BYTES_S_B", 0, true }, // 0x60
{ "TOCLIENT_FORMSPEC_PREPEND", 0, true }, // 0x61
};
diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp
index d8fbeebd5..23bcc867f 100644
--- a/src/network/serverpackethandler.cpp
+++ b/src/network/serverpackethandler.cpp
@@ -1166,6 +1166,8 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
u16 wear = pointed_object->punch(dir, &toolcap, playersao,
time_from_last_punch);
+ // Callback may have changed item, so get it again
+ playersao->getWieldedItem(&selected_item);
bool changed = selected_item.addWear(wear, m_itemdef);
if (changed)
playersao->setWieldedItem(selected_item);
@@ -1316,6 +1318,13 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
<< pointed_object->getDescription() << std::endl;
// Do stuff
+ if (m_script->item_OnSecondaryUse(
+ selected_item, playersao, pointed)) {
+ if (playersao->setWieldedItem(selected_item)) {
+ SendInventory(playersao, true);
+ }
+ }
+
pointed_object->rightClick(playersao);
} else if (m_script->item_OnPlace(
selected_item, playersao, pointed)) {
@@ -1376,8 +1385,10 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
actionstream << player->getName() << " activates "
<< selected_item.name << std::endl;
+ pointed.type = POINTEDTHING_NOTHING; // can only ever be NOTHING
+
if (m_script->item_OnSecondaryUse(
- selected_item, playersao)) {
+ selected_item, playersao, pointed)) {
if (playersao->setWieldedItem(selected_item)) {
SendInventory(playersao, true);
}