diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2063c9c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +# Changelog +All notable changes to this project will be documented here. This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +## Unreleased +- Added attribute to SInPacket to track decryption/decompression failures with incoming packets. + +## 2.1.1 - 2018-03-14 +- Fixed getPeerCount() returning the maximum number of peers instead of the current peer count. +- Fixed clients not sending disconnect message on program exit. +- Changed example clients from looping infintely. +- Renamed tutorial/examples. +- Restructed project directory. + +## 2.1.0 - 2018-03-10 +Initial commit of original code. diff --git a/README.md b/README.md index 837f3b3..8fbf8eb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ ## Irrnet -An updated version of the [irrNetLite](http://irrlicht.sourceforge.net/forum/viewtopic.php?f=6&t=22658) networking library compiled against recent versions of [enet](https://github.com/lsalzman/enet) and [zlib](https://github.com/madler/zlib). +An updated version of the [irrNetLite](http://irrlicht.sourceforge.net/forum/viewtopic.php?f=6&t=22658) networking library compiled against recent versions of [enet](https://github.com/lsalzman/enet) and [zlib](https://github.com/madler/zlib). + +Changelog can be viewed [here](https://github.com/rna88/irrnet/blob/master/CHANGELOG.md). ## Compiling for Linux @@ -27,4 +29,4 @@ The compiled binaries will be found in `examples/bin/`. ## License -Refer to `source/ReadMe.txt`. +Refer to [source/ReadMe.txt](https://github.com/rna88/irrnet/blob/master/source/ReadMe.txt). diff --git a/include/SPacket.h b/include/SPacket.h index 6d9d1e9..b6a2548 100644 --- a/include/SPacket.h +++ b/include/SPacket.h @@ -154,10 +154,14 @@ class SInPacket /// Returns the size in bytes of the packet. u32 getSize(); + /// Returns true if the packet decompresses/decrypts successfully. + bool isValid(); + private: u32 pos; core::array buff; u16 playerid; + bool valid; }; } // Close Net Namespace diff --git a/source/SPacket.cpp b/source/SPacket.cpp index 55bd1c0..9d46a5a 100644 --- a/source/SPacket.cpp +++ b/source/SPacket.cpp @@ -225,7 +225,7 @@ void SOutPacket::decryptPacket(const c8 key[16]) buff = tmpbuff; } -SInPacket::SInPacket(const c8* buff, const u32 size) : pos(0), playerid(0) +SInPacket::SInPacket(const c8* buff, const u32 size) : pos(0), playerid(0), valid(true) { SInPacket::buff.set_used(size); memcpy(SInPacket::buff.pointer(), buff, size); @@ -435,10 +435,19 @@ void SInPacket::deCompressPacket() newBuff.set_used(newSize); uLongf destLen = newSize; - uncompress((Bytef*)newBuff.pointer(), &destLen, (Bytef*)buff.pointer() + 4, buff.size() - 4); - newBuff.set_used(destLen); - - buff = newBuff; + int ret = uncompress((Bytef*)newBuff.pointer(), &destLen, (Bytef*)buff.pointer() + 4, buff.size() - 4); + + if (ret != Z_OK) + { + valid = false; + newBuff.set_used(0); + newBuff.clear(); + } + else + { + newBuff.set_used(destLen); + buff = newBuff; + } } void SInPacket::encryptPacket(const c8 key[16]) @@ -457,6 +466,12 @@ void SInPacket::encryptPacket(const c8 key[16]) void SInPacket::decryptPacket(const c8 key[16]) { + if (buff.size() % 16 != 0) + { + valid = false; + return; + } + CEncryption::SetEncryptionKey((u8*)&key[0]); const u32 newSize = buff.size(); core::array tmpbuff; @@ -473,5 +488,10 @@ u32 SInPacket::getSize() return buff.size(); } +bool SInPacket::isValid() +{ + return valid; +} + } // Close Net Namespace } // Close Irr namespace