summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/address.cpp8
-rw-r--r--src/network/address.h2
-rw-r--r--src/network/clientopcodes.cpp1
-rw-r--r--src/network/clientpackethandler.cpp175
-rw-r--r--src/network/connection.cpp17
-rw-r--r--src/network/connection.h6
-rw-r--r--src/network/connectionthreads.cpp10
-rw-r--r--src/network/networkprotocol.h128
-rw-r--r--src/network/serveropcodes.cpp2
-rw-r--r--src/network/serverpackethandler.cpp29
-rw-r--r--src/network/socket.cpp8
11 files changed, 261 insertions, 125 deletions
diff --git a/src/network/address.cpp b/src/network/address.cpp
index 90e561802..cf2e6208d 100644
--- a/src/network/address.cpp
+++ b/src/network/address.cpp
@@ -230,14 +230,14 @@ void Address::setPort(u16 port)
m_port = port;
}
-void Address::print(std::ostream *s) const
+void Address::print(std::ostream& s) const
{
if (m_addr_family == AF_INET6)
- *s << "[" << serializeString() << "]:" << m_port;
+ s << "[" << serializeString() << "]:" << m_port;
else if (m_addr_family == AF_INET)
- *s << serializeString() << ":" << m_port;
+ s << serializeString() << ":" << m_port;
else
- *s << "(undefined)";
+ s << "(undefined)";
}
bool Address::isLocalhost() const
diff --git a/src/network/address.h b/src/network/address.h
index c2f5f2eef..692bf82c5 100644
--- a/src/network/address.h
+++ b/src/network/address.h
@@ -59,7 +59,7 @@ public:
int getFamily() const { return m_addr_family; }
bool isIPv6() const { return m_addr_family == AF_INET6; }
bool isZero() const;
- void print(std::ostream *s) const;
+ void print(std::ostream &s) const;
std::string serializeString() const;
bool isLocalhost() const;
diff --git a/src/network/clientopcodes.cpp b/src/network/clientopcodes.cpp
index a98a5e7d1..6a78b4652 100644
--- a/src/network/clientopcodes.cpp
+++ b/src/network/clientopcodes.cpp
@@ -123,6 +123,7 @@ const ToClientCommandHandler toClientCommandTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_SRP_BYTES_S_B", TOCLIENT_STATE_NOT_CONNECTED, &Client::handleCommand_SrpBytesSandB }, // 0x60
{ "TOCLIENT_FORMSPEC_PREPEND", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_FormspecPrepend }, // 0x61,
{ "TOCLIENT_MINIMAP_MODES", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_MinimapModes }, // 0x62,
+ { "TOCLIENT_SET_LIGHTING", TOCLIENT_STATE_CONNECTED, &Client::handleCommand_SetLighting }, // 0x63,
};
const static ServerCommandFactory null_command_factory = { "TOSERVER_NULL", 0, false };
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index 48ad60ac6..25c1d2690 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -101,11 +101,20 @@ void Client::handleCommand_Hello(NetworkPacket* pkt)
// Authenticate using that method, or abort if there wasn't any method found
if (chosen_auth_mechanism != AUTH_MECHANISM_NONE) {
- if (chosen_auth_mechanism == AUTH_MECHANISM_FIRST_SRP &&
- !m_simple_singleplayer_mode &&
- !getServerAddress().isLocalhost() &&
- g_settings->getBool("enable_register_confirmation")) {
- promptConfirmRegistration(chosen_auth_mechanism);
+ bool is_register = chosen_auth_mechanism == AUTH_MECHANISM_FIRST_SRP;
+ ELoginRegister mode = is_register ? ELoginRegister::Register : ELoginRegister::Login;
+ if (m_allow_login_or_register != ELoginRegister::Any &&
+ m_allow_login_or_register != mode) {
+ m_chosen_auth_mech = AUTH_MECHANISM_NONE;
+ m_access_denied = true;
+ if (m_allow_login_or_register == ELoginRegister::Login) {
+ m_access_denied_reason =
+ gettext("Name is not registered. To create an account on this server, click 'Register'");
+ } else {
+ m_access_denied_reason =
+ gettext("Name is taken. Please choose another name");
+ }
+ m_con->Disconnect();
} else {
startAuth(chosen_auth_mechanism);
}
@@ -183,7 +192,7 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
m_access_denied_reason = "Unknown";
if (pkt->getCommand() != TOCLIENT_ACCESS_DENIED) {
- // 13/03/15 Legacy code from 0.4.12 and lesser but is still used
+ // Legacy code from 0.4.12 and older but is still used
// in some places of the server code
if (pkt->getSize() >= 2) {
std::wstring wide_reason;
@@ -196,14 +205,14 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
if (pkt->getSize() < 1)
return;
- u8 denyCode = SERVER_ACCESSDENIED_UNEXPECTED_DATA;
+ u8 denyCode;
*pkt >> denyCode;
+
if (denyCode == SERVER_ACCESSDENIED_SHUTDOWN ||
denyCode == SERVER_ACCESSDENIED_CRASH) {
*pkt >> m_access_denied_reason;
- if (m_access_denied_reason.empty()) {
+ if (m_access_denied_reason.empty())
m_access_denied_reason = accessDeniedStrings[denyCode];
- }
u8 reconnect;
*pkt >> reconnect;
m_access_denied_reconnect = reconnect & 1;
@@ -220,9 +229,8 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
// Until then (which may be never), this is outside
// of the defined protocol.
*pkt >> m_access_denied_reason;
- if (m_access_denied_reason.empty()) {
+ if (m_access_denied_reason.empty())
m_access_denied_reason = "Unknown";
- }
}
}
@@ -562,6 +570,10 @@ void Client::handleCommand_HP(NetworkPacket *pkt)
u16 hp;
*pkt >> hp;
+ bool damage_effect = true;
+ try {
+ *pkt >> damage_effect;
+ } catch (PacketError &e) {};
player->hp = hp;
@@ -573,6 +585,7 @@ void Client::handleCommand_HP(NetworkPacket *pkt)
ClientEvent *event = new ClientEvent();
event->type = CE_PLAYER_DAMAGE;
event->player_damage.amount = oldhp - hp;
+ event->player_damage.effect = damage_effect;
m_client_event_queue.push(event);
}
}
@@ -765,7 +778,7 @@ void Client::handleCommand_NodeDef(NetworkPacket* pkt)
decompressZlib(tmp_is, tmp_os);
// Deserialize node definitions
- m_nodedef->deSerialize(tmp_os);
+ m_nodedef->deSerialize(tmp_os, m_proto_ver);
m_nodedef_received = true;
}
@@ -784,7 +797,7 @@ void Client::handleCommand_ItemDef(NetworkPacket* pkt)
decompressZlib(tmp_is, tmp_os);
// Deserialize node definitions
- m_itemdef->deSerialize(tmp_os);
+ m_itemdef->deSerialize(tmp_os, m_proto_ver);
m_itemdef_received = true;
}
@@ -805,44 +818,38 @@ void Client::handleCommand_PlaySound(NetworkPacket* pkt)
*/
s32 server_id;
- std::string name;
- float gain;
- u8 type; // 0=local, 1=positional, 2=object
+ SimpleSoundSpec spec;
+ SoundLocation type; // 0=local, 1=positional, 2=object
v3f pos;
u16 object_id;
- bool loop;
- float fade = 0.0f;
- float pitch = 1.0f;
bool ephemeral = false;
- *pkt >> server_id >> name >> gain >> type >> pos >> object_id >> loop;
+ *pkt >> server_id >> spec.name >> spec.gain >> (u8 &)type >> pos >> object_id >> spec.loop;
try {
- *pkt >> fade;
- *pkt >> pitch;
+ *pkt >> spec.fade;
+ *pkt >> spec.pitch;
*pkt >> ephemeral;
} catch (PacketError &e) {};
// Start playing
int client_id = -1;
switch(type) {
- case 0: // local
- client_id = m_sound->playSound(name, loop, gain, fade, pitch);
- break;
- case 1: // positional
- client_id = m_sound->playSoundAt(name, loop, gain, pos, pitch);
- break;
- case 2:
- { // object
+ case SoundLocation::Local:
+ client_id = m_sound->playSound(spec);
+ break;
+ case SoundLocation::Position:
+ client_id = m_sound->playSoundAt(spec, pos);
+ break;
+ case SoundLocation::Object:
+ {
ClientActiveObject *cao = m_env.getActiveObject(object_id);
if (cao)
pos = cao->getPosition();
- client_id = m_sound->playSoundAt(name, loop, gain, pos, pitch);
+ client_id = m_sound->playSoundAt(spec, pos);
break;
}
- default:
- break;
}
if (client_id != -1) {
@@ -987,18 +994,18 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
p.amount = readU16(is);
p.time = readF32(is);
- p.minpos = readV3F32(is);
- p.maxpos = readV3F32(is);
- p.minvel = readV3F32(is);
- p.maxvel = readV3F32(is);
- p.minacc = readV3F32(is);
- p.maxacc = readV3F32(is);
- p.minexptime = readF32(is);
- p.maxexptime = readF32(is);
- p.minsize = readF32(is);
- p.maxsize = readF32(is);
+
+ // older protocols do not support tweening, and send only
+ // static ranges, so we can't just use the normal serialization
+ // functions for the older values.
+ p.pos.start.legacyDeSerialize(is);
+ p.vel.start.legacyDeSerialize(is);
+ p.acc.start.legacyDeSerialize(is);
+ p.exptime.start.legacyDeSerialize(is);
+ p.size.start.legacyDeSerialize(is);
+
p.collisiondetection = readU8(is);
- p.texture = deSerializeString32(is);
+ p.texture.string = deSerializeString32(is);
server_id = readU32(is);
@@ -1011,6 +1018,8 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
p.glow = readU8(is);
p.object_collision = readU8(is);
+ bool legacy_format = true;
+
// This is kinda awful
do {
u16 tmp_param0 = readU16(is);
@@ -1019,7 +1028,70 @@ void Client::handleCommand_AddParticleSpawner(NetworkPacket* pkt)
p.node.param0 = tmp_param0;
p.node.param2 = readU8(is);
p.node_tile = readU8(is);
- } while (0);
+
+ // v >= 5.6.0
+ f32 tmp_sbias = readF32(is);
+ if (is.eof())
+ break;
+
+ // initial bias must be stored separately in the stream to preserve
+ // backwards compatibility with older clients, which do not support
+ // a bias field in their range "format"
+ p.pos.start.bias = tmp_sbias;
+ p.vel.start.bias = readF32(is);
+ p.acc.start.bias = readF32(is);
+ p.exptime.start.bias = readF32(is);
+ p.size.start.bias = readF32(is);
+
+ p.pos.end.deSerialize(is);
+ p.vel.end.deSerialize(is);
+ p.acc.end.deSerialize(is);
+ p.exptime.end.deSerialize(is);
+ p.size.end.deSerialize(is);
+
+ // properties for legacy texture field
+ p.texture.deSerialize(is, m_proto_ver, true);
+
+ p.drag.deSerialize(is);
+ p.jitter.deSerialize(is);
+ p.bounce.deSerialize(is);
+ ParticleParamTypes::deSerializeParameterValue(is, p.attractor_kind);
+ using ParticleParamTypes::AttractorKind;
+ if (p.attractor_kind != AttractorKind::none) {
+ p.attract.deSerialize(is);
+ p.attractor_origin.deSerialize(is);
+ p.attractor_attachment = readU16(is);
+ /* we only check the first bit, in order to allow this value
+ * to be turned into a bit flag field later if needed */
+ p.attractor_kill = !!(readU8(is) & 1);
+ if (p.attractor_kind != AttractorKind::point) {
+ p.attractor_direction.deSerialize(is);
+ p.attractor_direction_attachment = readU16(is);
+ }
+ }
+ p.radius.deSerialize(is);
+
+ u16 texpoolsz = readU16(is);
+ p.texpool.reserve(texpoolsz);
+ for (u16 i = 0; i < texpoolsz; ++i) {
+ ServerParticleTexture newtex;
+ newtex.deSerialize(is, m_proto_ver);
+ p.texpool.push_back(newtex);
+ }
+
+ legacy_format = false;
+ } while(0);
+
+ if (legacy_format) {
+ // there's no tweening data to be had, so we need to set the
+ // legacy params to constant values, otherwise everything old
+ // will tween to zero
+ p.pos.end = p.pos.start;
+ p.vel.end = p.vel.start;
+ p.acc.end = p.acc.start;
+ p.exptime.end = p.exptime.start;
+ p.size.end = p.size.start;
+ }
auto event = new ClientEvent();
event->type = CE_ADD_PARTICLESPAWNER;
@@ -1331,10 +1403,13 @@ void Client::handleCommand_HudSetMoon(NetworkPacket *pkt)
void Client::handleCommand_HudSetStars(NetworkPacket *pkt)
{
- StarParams stars;
+ StarParams stars = SkyboxDefaults::getStarDefaults();
*pkt >> stars.visible >> stars.count
>> stars.starcolor >> stars.scale;
+ try {
+ *pkt >> stars.day_opacity;
+ } catch (PacketError &e) {};
ClientEvent *event = new ClientEvent();
event->type = CE_SET_STARS;
@@ -1682,3 +1757,11 @@ void Client::handleCommand_MinimapModes(NetworkPacket *pkt)
if (m_minimap)
m_minimap->setModeIndex(mode);
}
+
+void Client::handleCommand_SetLighting(NetworkPacket *pkt)
+{
+ Lighting& lighting = m_env.getLocalPlayer()->getLighting();
+
+ if (pkt->getRemainingBytes() >= 4)
+ *pkt >> lighting.shadow_intensity;
+}
diff --git a/src/network/connection.cpp b/src/network/connection.cpp
index 2d3cf6e88..6fb676f25 100644
--- a/src/network/connection.cpp
+++ b/src/network/connection.cpp
@@ -41,25 +41,14 @@ namespace con
/* defines used for debugging and profiling */
/******************************************************************************/
#ifdef NDEBUG
- #define LOG(a) a
#define PROFILE(a)
#else
- #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
+// TODO: Clean this up.
+#define LOG(a) a
+
#define PING_TIMEOUT 5.0
u16 BufferedPacket::getSeqnum() const
diff --git a/src/network/connection.h b/src/network/connection.h
index 1afb4ae84..b5ae24882 100644
--- a/src/network/connection.h
+++ b/src/network/connection.h
@@ -194,7 +194,7 @@ struct BufferedPacket {
u16 getSeqnum() const;
- inline const size_t size() const { return m_data.size(); }
+ inline size_t size() const { return m_data.size(); }
u8 *data; // Direct memory access
float time = 0.0f; // Seconds from buffering the packet or re-sending
@@ -752,8 +752,8 @@ protected:
void putEvent(ConnectionEventPtr e);
void TriggerSend();
-
- bool ConnectedToServer()
+
+ bool ConnectedToServer()
{
return getPeerNoEx(PEER_ID_SERVER) != nullptr;
}
diff --git a/src/network/connectionthreads.cpp b/src/network/connectionthreads.cpp
index dca065ae1..90936b43d 100644
--- a/src/network/connectionthreads.cpp
+++ b/src/network/connectionthreads.cpp
@@ -32,22 +32,18 @@ namespace con
/* defines used for debugging and profiling */
/******************************************************************************/
#ifdef NDEBUG
-#define LOG(a) a
#define PROFILE(a)
#undef DEBUG_CONNECTION_KBPS
#else
/* this mutex is used to achieve log message consistency */
-std::mutex log_conthread_mutex;
-#define LOG(a) \
- { \
- MutexAutoLock loglock(log_conthread_mutex); \
- a; \
- }
#define PROFILE(a) a
//#define DEBUG_CONNECTION_KBPS
#undef DEBUG_CONNECTION_KBPS
#endif
+// TODO: Clean this up.
+#define LOG(a) a
+
#define WINDOW_SIZE 5
static session_t readPeerId(const u8 *packetdata)
diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h
index a5ff53216..3ab839f8d 100644
--- a/src/network/networkprotocol.h
+++ b/src/network/networkprotocol.h
@@ -207,9 +207,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Minimap modes
PROTOCOL VERSION 40:
TOCLIENT_MEDIA_PUSH changed, TOSERVER_HAVE_MEDIA added
+ Added new particlespawner parameters
+ [scheduled bump for 5.6.0]
*/
-#define LATEST_PROTOCOL_VERSION 40
+#define LATEST_PROTOCOL_VERSION 41
#define LATEST_PROTOCOL_VERSION_STRING TOSTRING(LATEST_PROTOCOL_VERSION)
// Server's supported network protocol range
@@ -228,8 +230,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define PASSWORD_SIZE 28 // Maximum password length. Allows for
// base64-encoded SHA-1 (27+\0).
-// See also: Formspec Version History in doc/lua_api.txt
-#define FORMSPEC_API_VERSION 5
+// See also formspec [Version History] in doc/lua_api.txt
+#define FORMSPEC_API_VERSION 6
#define TEXTURENAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-"
@@ -511,11 +513,12 @@ enum ToClientCommand
TOCLIENT_SPAWN_PARTICLE = 0x46,
/*
- v3f1000 pos
- v3f1000 velocity
- v3f1000 acceleration
- f1000 expirationtime
- f1000 size
+ -- struct range<T> { T min, T max, f32 bias };
+ v3f pos
+ v3f velocity
+ v3f acceleration
+ f32 expirationtime
+ f32 size
u8 bool collisiondetection
u32 len
u8[len] texture
@@ -524,22 +527,26 @@ enum ToClientCommand
TileAnimation animation
u8 glow
u8 object_collision
+ v3f drag
+ range<v3f> bounce
*/
TOCLIENT_ADD_PARTICLESPAWNER = 0x47,
/*
+ -- struct range<T> { T min, T max, f32 bias };
+ -- struct tween<T> { T start, T end };
u16 amount
- f1000 spawntime
- v3f1000 minpos
- v3f1000 maxpos
- v3f1000 minvel
- v3f1000 maxvel
- v3f1000 minacc
- v3f1000 maxacc
- f1000 minexptime
- f1000 maxexptime
- f1000 minsize
- f1000 maxsize
+ f32 spawntime
+ v3f minpos
+ v3f maxpos
+ v3f minvel
+ v3f maxvel
+ v3f minacc
+ v3f maxacc
+ f32 minexptime
+ f32 maxexptime
+ f32 minsize
+ f32 maxsize
u8 bool collisiondetection
u32 len
u8[len] texture
@@ -549,6 +556,63 @@ enum ToClientCommand
TileAnimation animation
u8 glow
u8 object_collision
+
+ f32 pos_start_bias
+ f32 vel_start_bias
+ f32 acc_start_bias
+ f32 exptime_start_bias
+ f32 size_start_bias
+
+ range<v3f> pos_end
+ -- i.e v3f pos_end_min
+ -- v3f pos_end_max
+ -- f32 pos_end_bias
+ range<v3f> vel_end
+ range<v3f> acc_end
+
+ tween<range<v3f>> drag
+ -- i.e. v3f drag_start_min
+ -- v3f drag_start_max
+ -- f32 drag_start_bias
+ -- v3f drag_end_min
+ -- v3f drag_end_max
+ -- f32 drag_end_bias
+ tween<range<v3f>> jitter
+ tween<range<f32>> bounce
+
+ u8 attraction_kind
+ none = 0
+ point = 1
+ line = 2
+ plane = 3
+
+ if attraction_kind > none {
+ tween<range<f32>> attract_strength
+ tween<v3f> attractor_origin
+ u16 attractor_origin_attachment_object_id
+ u8 spawner_flags
+ bit 1: attractor_kill (particles dies on contact)
+ if attraction_mode > point {
+ tween<v3f> attractor_angle
+ u16 attractor_origin_attachment_object_id
+ }
+ }
+
+ tween<range<v3f>> radius
+ tween<range<v3f>> drag
+
+ u16 texpool_sz
+ texpool_sz.times {
+ u8 flags
+ -- bit 0: animated
+ -- other bits free & ignored as of proto v40
+ tween<f32> alpha
+ tween<v2f> scale
+ if flags.animated {
+ TileAnimation animation
+ }
+ }
+
*/
TOCLIENT_DELETE_PARTICLESPAWNER_LEGACY = 0x48, // Obsolete
@@ -735,6 +799,7 @@ enum ToClientCommand
u32 count
u8[4] starcolor (ARGB)
f32 scale
+ f32 day_opacity
*/
TOCLIENT_SRP_BYTES_S_B = 0x60,
@@ -762,7 +827,12 @@ enum ToClientCommand
std::string extra
*/
- TOCLIENT_NUM_MSG_TYPES = 0x63,
+ TOCLIENT_SET_LIGHTING = 0x63,
+ /*
+ f32 shadow_intensity
+ */
+
+ TOCLIENT_NUM_MSG_TYPES = 0x64,
};
enum ToServerCommand
@@ -1001,7 +1071,7 @@ enum AuthMechanism
AUTH_MECHANISM_FIRST_SRP = 1 << 2,
};
-enum AccessDeniedCode {
+enum AccessDeniedCode : u8 {
SERVER_ACCESSDENIED_WRONG_PASSWORD,
SERVER_ACCESSDENIED_UNEXPECTED_DATA,
SERVER_ACCESSDENIED_SINGLEPLAYER,
@@ -1024,18 +1094,18 @@ enum NetProtoCompressionMode {
const static std::string accessDeniedStrings[SERVER_ACCESSDENIED_MAX] = {
"Invalid password",
- "Your client sent something the server didn't expect. Try reconnecting or updating your client",
+ "Your client sent something the server didn't expect. Try reconnecting or updating your client.",
"The server is running in simple singleplayer mode. You cannot connect.",
- "Your client's version is not supported.\nPlease contact server administrator.",
- "Player name contains disallowed characters.",
- "Player name not allowed.",
- "Too many users.",
+ "Your client's version is not supported.\nPlease contact the server administrator.",
+ "Player name contains disallowed characters",
+ "Player name not allowed",
+ "Too many users",
"Empty passwords are disallowed. Set a password and try again.",
"Another client is connected with this name. If your client closed unexpectedly, try again in a minute.",
- "Server authentication failed. This is likely a server error.",
+ "Internal server error",
"",
- "Server shutting down.",
- "This server has experienced an internal error. You will now be disconnected."
+ "Server shutting down",
+ "The server has experienced an internal error. You will now be disconnected."
};
enum PlayerListModifer : u8
diff --git a/src/network/serveropcodes.cpp b/src/network/serveropcodes.cpp
index 44b65e8da..12665e7f1 100644
--- a/src/network/serveropcodes.cpp
+++ b/src/network/serveropcodes.cpp
@@ -176,7 +176,7 @@ const ClientCommandFactory clientCommandFactoryTable[TOCLIENT_NUM_MSG_TYPES] =
{ "TOCLIENT_ACTIVE_OBJECT_MESSAGES", 0, true }, // 0x32 (may be sent as unrel over channel 1 too)
{ "TOCLIENT_HP", 0, true }, // 0x33
{ "TOCLIENT_MOVE_PLAYER", 0, true }, // 0x34
- { "TOCLIENT_ACCESS_DENIED_LEGACY", 0, true }, // 0x35
+ null_command_factory, // 0x35
{ "TOCLIENT_FOV", 0, true }, // 0x36
{ "TOCLIENT_DEATHSCREEN", 0, true }, // 0x37
{ "TOCLIENT_MEDIA", 2, true }, // 0x38
diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp
index 6f60b8172..a5ee81a9c 100644
--- a/src/network/serverpackethandler.cpp
+++ b/src/network/serverpackethandler.cpp
@@ -108,8 +108,10 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
// Use the highest version supported by both
u8 depl_serial_v = std::min(client_max, our_max);
// If it's lower than the lowest supported, give up.
+#if SER_FMT_VER_LOWEST_READ > 0
if (depl_serial_v < SER_FMT_VER_LOWEST_READ)
depl_serial_v = SER_FMT_VER_INVALID;
+#endif
if (depl_serial_v == SER_FMT_VER_INVALID) {
actionstream << "Server: A mismatched client tried to connect from " <<
@@ -227,7 +229,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt)
Compose auth methods for answer
*/
std::string encpwd; // encrypted Password field for the user
- bool has_auth = m_script->getAuth(playername, &encpwd, NULL);
+ bool has_auth = m_script->getAuth(playername, &encpwd, nullptr);
u32 auth_mechs = 0;
client->chosen_mech = AUTH_MECHANISM_NONE;
@@ -444,7 +446,7 @@ void Server::handleCommand_GotBlocks(NetworkPacket* pkt)
("GOTBLOCKS length is too short");
}
- m_clients.lock();
+ ClientInterface::AutoLock lock(m_clients);
RemoteClient *client = m_clients.lockedGetClientNoEx(pkt->getPeerId());
for (u16 i = 0; i < count; i++) {
@@ -452,7 +454,6 @@ void Server::handleCommand_GotBlocks(NetworkPacket* pkt)
*pkt >> p;
client->GotBlock(p);
}
- m_clients.unlock();
}
void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
@@ -1462,11 +1463,9 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt)
session_t peer_id = pkt->getPeerId();
RemoteClient *client = getClient(peer_id, CS_Invalid);
ClientState cstate = client->getState();
+ const std::string playername = client->getName();
- std::string playername = client->getName();
-
- std::string salt;
- std::string verification_key;
+ std::string salt, verification_key;
std::string addr_s = getPeerAddress(peer_id).serializeString();
u8 is_empty;
@@ -1552,8 +1551,6 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt)
RemoteClient *client = getClient(peer_id, CS_Invalid);
ClientState cstate = client->getState();
- bool wantSudo = (cstate == CS_Active);
-
if (!((cstate == CS_HelloSent) || (cstate == CS_Active))) {
actionstream << "Server: got SRP _A packet in wrong state " << cstate <<
" from " << getPeerAddress(peer_id).serializeString() <<
@@ -1561,6 +1558,8 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt)
return;
}
+ const bool wantSudo = (cstate == CS_Active);
+
if (client->chosen_mech != AUTH_MECHANISM_NONE) {
actionstream << "Server: got SRP _A packet, while auth is already "
"going on with mech " << client->chosen_mech << " from " <<
@@ -1607,8 +1606,7 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt)
client->chosen_mech = chosen;
- std::string salt;
- std::string verifier;
+ std::string salt, verifier;
if (based_on == 0) {
@@ -1658,10 +1656,10 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt)
session_t peer_id = pkt->getPeerId();
RemoteClient *client = getClient(peer_id, CS_Invalid);
ClientState cstate = client->getState();
- std::string addr_s = getPeerAddress(pkt->getPeerId()).serializeString();
- std::string playername = client->getName();
+ const std::string addr_s = client->getAddress().serializeString();
+ const std::string playername = client->getName();
- bool wantSudo = (cstate == CS_Active);
+ const bool wantSudo = (cstate == CS_Active);
verbosestream << "Server: Received TOSERVER_SRP_BYTES_M." << std::endl;
@@ -1721,8 +1719,7 @@ void Server::handleCommand_SrpBytesM(NetworkPacket* pkt)
if (client->create_player_on_auth_success) {
m_script->createAuth(playername, client->enc_pwd);
- std::string checkpwd; // not used, but needed for passing something
- if (!m_script->getAuth(playername, &checkpwd, NULL)) {
+ if (!m_script->getAuth(playername, nullptr, nullptr)) {
errorstream << "Server: " << playername <<
" cannot be authenticated (auth handler does not work?)" <<
std::endl;
diff --git a/src/network/socket.cpp b/src/network/socket.cpp
index 0bb7ea234..df15c89ba 100644
--- a/src/network/socket.cpp
+++ b/src/network/socket.cpp
@@ -198,7 +198,7 @@ void UDPSocket::Send(const Address &destination, const void *data, int size)
if (socket_enable_debug_output) {
// Print packet destination and size
dstream << (int)m_handle << " -> ";
- destination.print(&dstream);
+ destination.print(dstream);
dstream << ", size=" << size;
// Print packet contents
@@ -231,7 +231,7 @@ void UDPSocket::Send(const Address &destination, const void *data, int size)
int sent;
if (m_addr_family == AF_INET6) {
- struct sockaddr_in6 address = {0};
+ struct sockaddr_in6 address = {};
address.sin6_family = AF_INET6;
address.sin6_addr = destination.getAddress6();
address.sin6_port = htons(destination.getPort());
@@ -239,7 +239,7 @@ void UDPSocket::Send(const Address &destination, const void *data, int size)
sent = sendto(m_handle, (const char *)data, size, 0,
(struct sockaddr *)&address, sizeof(struct sockaddr_in6));
} else {
- struct sockaddr_in address = {0};
+ struct sockaddr_in address = {};
address.sin_family = AF_INET;
address.sin_addr = destination.getAddress();
address.sin_port = htons(destination.getPort());
@@ -295,7 +295,7 @@ int UDPSocket::Receive(Address &sender, void *data, int size)
if (socket_enable_debug_output) {
// Print packet sender and size
dstream << (int)m_handle << " <- ";
- sender.print(&dstream);
+ sender.print(dstream);
dstream << ", size=" << received;
// Print packet contents