merge fix for windows cmake cfg
This commit is contained in:
commit
43d8801e71
|
@ -1,6 +1,9 @@
|
|||
# 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.
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
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)
|
||||
|
||||
|
@ -10,7 +12,6 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/lib")
|
|||
set(LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
|
||||
|
||||
#irrnet stuff
|
||||
add_definitions(-DCOMPILE_WITH_IRRLICHT)
|
||||
set(IRRNET_TARGET irrnet)
|
||||
set(IRRNET_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/source")
|
||||
set(IRRNET_INC_DIR "${CMAKE_CURRENT_LIST_DIR}/include")
|
||||
|
@ -24,18 +25,38 @@ 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}/include)
|
||||
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)
|
||||
|
||||
include_directories(/usr/include/irrlicht)
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
target_include_directories(${IRRNET_TARGET} PUBLIC ${IRRNET_INC_DIR} ${ENET_INC_DIR} ${ZLIB_INC_DIR})
|
||||
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})
|
||||
|
||||
|
|
|
@ -49,8 +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.
|
||||
|
@ -116,8 +118,10 @@ class SInPacket
|
|||
void operator >> (f64& data);
|
||||
/// Gets the next item in the packet based on the size of the variable.
|
||||
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.
|
||||
|
@ -157,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
|
||||
|
|
|
@ -106,13 +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)
|
||||
{
|
||||
|
@ -232,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);
|
||||
|
@ -304,12 +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)
|
||||
{
|
||||
|
@ -448,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);
|
||||
int ret = uncompress((Bytef*)newBuff.pointer(), &destLen, (Bytef*)buff.pointer() + 4, buff.size() - 4);
|
||||
|
||||
buff = newBuff;
|
||||
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])
|
||||
|
@ -470,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;
|
||||
|
@ -486,5 +503,10 @@ u32 SInPacket::getSize()
|
|||
return buff.size();
|
||||
}
|
||||
|
||||
bool SInPacket::isValid()
|
||||
{
|
||||
return valid;
|
||||
}
|
||||
|
||||
} // Close Net Namespace
|
||||
} // Close Irr namespace
|
||||
|
|
Loading…
Reference in New Issue