[General] Add packetValid flag to packets

0.6.3
Koncord 7 years ago
parent 695fb7d4a7
commit d999cc0d55

@ -217,7 +217,7 @@ void Networking::update(RakNet::Packet *packet)
bsIn.IgnoreBytes((unsigned int) RakNet::RakNetGUID::size()); // Ignore GUID from received 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) if (packet->data[0] == ID_GAME_PREINIT)
{ {
@ -229,6 +229,13 @@ void Networking::update(RakNet::Packet *packet)
packetPreInit.setChecksums(&plugins); packetPreInit.setChecksums(&plugins);
packetPreInit.Read(); 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(); auto plugin = plugins.begin();
if (samples.size() == plugins.size()) if (samples.size() == plugins.size())
{ {

@ -17,6 +17,7 @@ BasePacket::BasePacket(RakNet::RakPeerInterface *peer)
void BasePacket::Packet(RakNet::BitStream *bs, bool send) void BasePacket::Packet(RakNet::BitStream *bs, bool send)
{ {
this->bs = bs; this->bs = bs;
packetValid = true;
if (send) if (send)
{ {

@ -39,6 +39,11 @@ namespace mwmp
return packetID; return packetID;
} }
bool isPacketValid() const
{
return packetValid;
}
protected: protected:
template<class templateType> template<class templateType>
void RW(templateType &data, uint32_t size, bool write) void RW(templateType &data, uint32_t size, bool write)
@ -112,6 +117,7 @@ namespace mwmp
RakNet::BitStream *bsRead, *bsSend, *bs; RakNet::BitStream *bsRead, *bsSend, *bs;
RakNet::RakPeerInterface *peer; RakNet::RakPeerInterface *peer;
RakNet::RakNetGUID guid; RakNet::RakNetGUID guid;
bool packetValid;
}; };
} }

Loading…
Cancel
Save