From d999cc0d557232587b0ebbf0b70ba35aeb1b74d3 Mon Sep 17 00:00:00 2001 From: Koncord Date: Tue, 3 Jul 2018 02:06:52 +0800 Subject: [PATCH] [General] Add packetValid flag to packets --- apps/openmw-mp/Networking.cpp | 9 ++++++++- components/openmw-mp/Packets/BasePacket.cpp | 1 + components/openmw-mp/Packets/BasePacket.hpp | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 298e0010b..3eb1dc59d 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -217,7 +217,7 @@ void Networking::update(RakNet::Packet *packet) bsIn.IgnoreBytes((unsigned int) RakNet::RakNetGUID::size()); // Ignore GUID from received packet - if (player == 0) + if (player == nullptr) { if (packet->data[0] == ID_GAME_PREINIT) { @@ -229,6 +229,13 @@ void Networking::update(RakNet::Packet *packet) packetPreInit.setChecksums(&plugins); packetPreInit.Read(); + if (!packetPreInit.isPacketValid()) + { + LOG_APPEND(Log::LOG_ERROR, "Invalid packetPreInit"); + peer->CloseConnection(packet->systemAddress, false); // close connection without notification + return; + } + auto plugin = plugins.begin(); if (samples.size() == plugins.size()) { diff --git a/components/openmw-mp/Packets/BasePacket.cpp b/components/openmw-mp/Packets/BasePacket.cpp index 93de1762c..31513c5ac 100644 --- a/components/openmw-mp/Packets/BasePacket.cpp +++ b/components/openmw-mp/Packets/BasePacket.cpp @@ -17,6 +17,7 @@ BasePacket::BasePacket(RakNet::RakPeerInterface *peer) void BasePacket::Packet(RakNet::BitStream *bs, bool send) { this->bs = bs; + packetValid = true; if (send) { diff --git a/components/openmw-mp/Packets/BasePacket.hpp b/components/openmw-mp/Packets/BasePacket.hpp index bca5cc75d..0b6f2e2df 100644 --- a/components/openmw-mp/Packets/BasePacket.hpp +++ b/components/openmw-mp/Packets/BasePacket.hpp @@ -39,6 +39,11 @@ namespace mwmp return packetID; } + bool isPacketValid() const + { + return packetValid; + } + protected: template void RW(templateType &data, uint32_t size, bool write) @@ -112,6 +117,7 @@ namespace mwmp RakNet::BitStream *bsRead, *bsSend, *bs; RakNet::RakPeerInterface *peer; RakNet::RakNetGUID guid; + bool packetValid; }; }