aboutsummaryrefslogtreecommitdiff
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.cpp139
-rw-r--r--src/network/networkprotocol.h51
-rw-r--r--src/network/serveropcodes.cpp12
4 files changed, 180 insertions, 28 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 b887c0282..f6de9cd8b 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)
{
@@ -1233,28 +1234,132 @@ void Client::handleCommand_HudSetParam(NetworkPacket* pkt)
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);
+ std::vector<std::string>* params = new std::vector<std::string>;
+
+ for (size_t i = 0; i < count; i++)
+ skybox.textures.emplace_back(deSerializeString(is));
+
+ bool 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_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_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_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/networkprotocol.h b/src/network/networkprotocol.h
index 3be4110ee..d3799868b 100644
--- a/src/network/networkprotocol.h
+++ b/src/network/networkprotocol.h
@@ -201,9 +201,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
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
@@ -605,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
@@ -613,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,
@@ -688,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
};