Compare commits

...

16 Commits

Author SHA1 Message Date
ottona 168f605620 merge readme update 2022-12-13 01:48:40 +01:00
ottona 2e938af096 updated readme 2022-12-13 01:32:47 +01:00
Otto Naderer 43d8801e71 merge fix for windows cmake cfg 2022-06-08 01:30:10 +02:00
Otto Naderer 0a39403f8d fixes to cmake cfg windows 2022-06-08 00:38:01 +02:00
Otto Naderer 8e5d81f913 cmake op for native irrlicht 2022-06-07 22:01:26 +02:00
Otto Naderer fb0b8cee79 Merge branch 'master' into dev 2022-06-07 17:52:34 +02:00
Otto Naderer ed8345550f added quaternions to packet structures 2022-06-05 14:31:52 +02:00
Otto Naderer 1887c702c4 init cmake 2022-04-28 00:14:10 +02:00
rna88 ca1e18cf3c Merge with dev for 2.1.1 version
* Added changelog.
2018-03-20 00:48:19 -07:00
rna88 540d682cfc SInPacket now tracks decryption/decompression failure.
Previously there was no way to tell if an incoming packet was
incorrectly formatted. The new function SInPacket.isValid()
can be called after decryption/decompression to determine if
the packet wasn't decrypted and/or decompressed properly.

* Added "valid" attribute to SInPacket.
* Decryption routine unsets "valid" if input buffer is not divisible by 16.
* Decompression routine unsets "valid" on receiving zlib error.
2018-03-18 19:00:16 -07:00
rna88 967378ae98 SInPacket now tracks decryption/decompression failure.
Previously there was no way to tell if an incoming packet was
incorrectly formatted. The new function SInPacket.isValid()
can be called after decryption/decompression to determine if
the packet wasn't decrypted and/or decompressed properly.

* Added "valid" attribute to SInPacket.
* Decryption routine unsets "valid" if buffer is not divisible by 16.
* Decompression routine unsets "valid" on receiving zlib error code.
2018-03-15 20:12:33 -07:00
rna88 bcdf5b317c Cleaned up some minor details with examples. Added port specification in server/client creation. 2018-03-14 00:38:54 -07:00
rna88 f9b49365c0 Fixed issues with CNetManager::getPeerCount() returning incorrect number of peers. 2018-03-13 17:11:08 -07:00
rna88 fe00af35d2 Fixed issue with clients not properly ending their connection after being destroyed. Removed git tracking of compiled binaries/library. 2018-03-12 23:53:10 -07:00
rna88 73c54c580d Reorganizing examples. 2018-03-11 05:05:43 -07:00
rna88 4e5b5abd6f Fixed links in readme. 2018-03-10 20:10:07 -08:00
6 changed files with 140 additions and 31 deletions

15
CHANGELOG.md Normal file
View File

@ -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.

62
CMakeLists.txt Executable file
View File

@ -0,0 +1,62 @@
# cmake for irrnet, ottona, 2022-04-27
cmake_minimum_required(VERSION 3.10)
option(OP_COMPILE_WITH_IRRLICHT "compile irrnet with native irrlicht datatypes" ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/lib")
set(LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
#irrnet stuff
set(IRRNET_TARGET irrnet)
set(IRRNET_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/source")
set(IRRNET_INC_DIR "${CMAKE_CURRENT_LIST_DIR}/include")
#enet stuff
set(ENET_TARGET enet)
set(ENET_DIR "${CMAKE_CURRENT_LIST_DIR}/enet")
set(ENET_INC_DIR ${ENET_DIR}/include)
add_subdirectory(${ENET_DIR} EXCLUDE_FROM_ALL)
#zlib stuff
set(ZLIB_TARGET zlibstatic)
set(ZLIB_DIR "${CMAKE_CURRENT_LIST_DIR}/zlib")
set(ZLIB_INC_DIR ${ZLIB_DIR})
set(ZLIB_CONF_DIR ${CMAKE_CURRENT_BINARY_DIR}/zlib)
add_subdirectory(${ZLIB_DIR} EXCLUDE_FROM_ALL)
#irrlicht stuff
if (NOT IRRLICHT_INC_DIR)
set(IRRLICHT_INC_DIR /usr/include/irrlicht)
endif()
project(irrnet)
add_library(${IRRNET_TARGET} STATIC
${IRRNET_INC_DIR}/CEncryption.h
${IRRNET_INC_DIR}/CNetManager.h
${IRRNET_INC_DIR}/INetManager.h
${IRRNET_INC_DIR}/irrNet.h
${IRRNET_INC_DIR}/SPacket.h
${IRRNET_SRC_DIR}/CNetManager.cpp
${IRRNET_SRC_DIR}/SPacket.cpp
)
if (OP_COMPILE_WITH_IRRLICHT)
message(STATUS "compile with native irrlicht")
add_definitions(-DCOMPILE_WITH_IRRLICHT)
message(STATUS "irrlicht dir: " ${IRRLICHT_INC_DIR})
target_include_directories(${IRRNET_TARGET} PUBLIC ${IRRLICHT_INC_DIR})
endif()
target_link_libraries(${IRRNET_TARGET} ${ZLIB_TARGET} ${ENET_TARGET})
target_include_directories(${IRRNET_TARGET} PUBLIC ${IRRNET_INC_DIR} ${ENET_INC_DIR} ${ZLIB_INC_DIR})
message(STATUS "conf dir" ${ZLIB_CONF_DIR})
target_include_directories(${IRRNET_TARGET} PRIVATE ${ZLIB_CONF_DIR})

View File

@ -1,30 +1,16 @@
## Irrnet
# 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).
## Compiling for Linux
## building irrnet
When cloning use the `--recurse-submodules` flag to retrieve the enet and zlib libraries needed by the project:
irrnet now uses an easy to use cmake configuration. use it to either build the lib or rather integrate it into your project's cmake setup (recommended).
`git clone --recurse-submodules https://github.com/rna88/irrnet.git`
quick steps:
Then run `make` in the `source/` directory to build the library, which will be placed in `lib/`.
1. clone the repository and pull the submodules: `git clone --recurse-submodules <path to repo>`
1. use `cmake` or `cmake-gui` to generate makefiles or projects for your favorite ide. as for the first just do `cmake -B build`
1. on successful generation, cd into the just created `build` folder
1. `make` irrnet
## Building examples
Navigate to `examples/` and run:
`./linux_buildAllExamples.sh`
or to build them with optimizations:
`./linux_buildAllExamples.sh release`
The compiled binaries will be found in `examples/bin/`.
## License
Refer to `source/ReadMe.txt`.

View File

@ -49,6 +49,10 @@ class SOutPacket
SOutPacket& operator << (const f64 data);
/// Adds data to the packet.
SOutPacket& operator << (const core::vector3df& data);
#ifdef COMPILE_WITH_IRRLICHT
/// Adds a quaternion to the packet
SOutPacket& operator << (const core::quaternion&);
#endif
/// Adds data to the packet.
SOutPacket& operator << (const c8* string);
/// Adds data to the packet.
@ -57,7 +61,6 @@ class SOutPacket
SOutPacket& operator << (const std::string& string);
/// Adds data to the packet.
SOutPacket& operator << (const core::stringw& string);
/// Appends another SOutPacket to the packet.
SOutPacket& operator << (const SOutPacket& other);
@ -114,7 +117,11 @@ class SInPacket
/// Gets the next item in the packet based on the size of the variable.
void operator >> (f64& data);
/// Gets the next item in the packet based on the size of the variable.
void operator >> (core::vector3df& data);
void operator >> (core::vector3df& data);
#ifdef COMPILE_WITH_IRRLICHT
/// Gets the next item in the packet based on the size of the variable.
void operator >> (core::quaternion& data);
#endif
/// Gets the next item in the packet based on the size of the variable.
void operator >> (char* string);
/// Gets the next item in the packet based on the size of the variable.
@ -154,10 +161,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<c8> buff;
u16 playerid;
bool valid;
};
} // Close Net Namespace

View File

@ -106,6 +106,14 @@ SOutPacket& SOutPacket::operator << (const core::vector3df& data)
memcpy(buff.pointer() + buff.size() - 12, &data.X, 12);
return *this;
}
#ifdef COMPILE_WITH_IRRLICHT
SOutPacket& SOutPacket::operator << (const core::quaternion& data)
{
enlargeBuffer(16);
memcpy(buff.pointer() + buff.size() - 16, &data.X, 16);
return *this;
}
#endif
SOutPacket& SOutPacket::operator << (const c8* string)
{
@ -225,7 +233,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);
@ -297,6 +305,13 @@ void SInPacket::operator >> (core::vector3df &data)
memcpy(&data.X,getData()+pos,12);
pos+=12;
}
#ifdef COMPILE_WITH_IRRLICHT
void SInPacket::operator >> (core::quaternion &data)
{
memcpy(&data.X,getData()+pos,16);
pos+=16;
}
#endif
void SInPacket::operator >> (char *string)
{
@ -435,10 +450,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 +481,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<c8> tmpbuff;
@ -473,5 +503,10 @@ u32 SInPacket::getSize()
return buff.size();
}
bool SInPacket::isValid()
{
return valid;
}
} // Close Net Namespace
} // Close Irr namespace

2
zlib

@ -1 +1 @@
Subproject commit cacf7f1d4e3d44d871b605da3b647f07d718623f
Subproject commit 21767c654d31d2dccdde4330529775c6c5fd5389