From 62d1213853277da00263daef7ca4b60d8f8e6e56 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 19 Feb 2012 12:27:50 -0800 Subject: [PATCH 01/37] Remove a bunch of unused pnUtils stuff. --- .../Plasma/NucleusLib/pnUtils/CMakeLists.txt | 8 - .../NucleusLib/pnUtils/Win32/pnUtW32Dll.cpp | 56 ------ .../Plasma/NucleusLib/pnUtils/pnUtBase64.cpp | 182 ----------------- .../Plasma/NucleusLib/pnUtils/pnUtBase64.h | 85 -------- Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h | 10 +- .../Plasma/NucleusLib/pnUtils/pnUtMath.cpp | 63 ------ Sources/Plasma/NucleusLib/pnUtils/pnUtMath.h | 102 ---------- .../Plasma/NucleusLib/pnUtils/pnUtRand.cpp | 184 ------------------ Sources/Plasma/NucleusLib/pnUtils/pnUtRand.h | 67 ------- .../NucleusLib/pnUtils/pnUtSpareList.cpp | 163 ---------------- .../Plasma/NucleusLib/pnUtils/pnUtSpareList.h | 148 -------------- 11 files changed, 8 insertions(+), 1060 deletions(-) delete mode 100644 Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Dll.cpp delete mode 100644 Sources/Plasma/NucleusLib/pnUtils/pnUtBase64.cpp delete mode 100644 Sources/Plasma/NucleusLib/pnUtils/pnUtBase64.h delete mode 100644 Sources/Plasma/NucleusLib/pnUtils/pnUtMath.cpp delete mode 100644 Sources/Plasma/NucleusLib/pnUtils/pnUtMath.h delete mode 100644 Sources/Plasma/NucleusLib/pnUtils/pnUtRand.cpp delete mode 100644 Sources/Plasma/NucleusLib/pnUtils/pnUtRand.h delete mode 100644 Sources/Plasma/NucleusLib/pnUtils/pnUtSpareList.cpp delete mode 100644 Sources/Plasma/NucleusLib/pnUtils/pnUtSpareList.h diff --git a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt index 2774f622..ddcc21ab 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt @@ -8,21 +8,17 @@ set(pnUtils_HEADERS pnUtAddr.h pnUtAllIncludes.h pnUtArray.h - pnUtBase64.h pnUtBigNum.h pnUtCmd.h pnUtCrypt.h pnUtHash.h pnUtList.h - pnUtMath.h pnUtMisc.h pnUtPath.h pnUtPragma.h pnUtPriQ.h - pnUtRand.h pnUtRef.h pnUtSort.h - pnUtSpareList.h pnUtStr.h pnUtSync.h pnUtTime.h @@ -33,16 +29,12 @@ set(pnUtils_HEADERS set(pnUtils_SOURCES pnUtAddr.cpp pnUtArray.cpp - pnUtBase64.cpp pnUtBigNum.cpp pnUtCmd.cpp pnUtHash.cpp pnUtList.cpp - pnUtMath.cpp pnUtMisc.cpp pnUtPath.cpp - pnUtRand.cpp - pnUtSpareList.cpp pnUtStr.cpp pnUtTime.cpp pnUtUuid.cpp diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Dll.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Dll.cpp deleted file mode 100644 index 9c32e117..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Dll.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Dll.cpp -* -***/ - -#include "../pnUtils.h" - - -/***************************************************************************** -* -* Private -* -***/ - diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtBase64.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtBase64.cpp deleted file mode 100644 index 09f10687..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtBase64.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtBase64.cpp -* -***/ - -#include "pnUtBase64.h" - - -/***************************************************************************** -* -* Private -* -***/ - -static const char kEncode64[] = { -// 0000000000111111111122222222223333333333444444444455555555556666 -// 0123456789012345678901234567890123456789012345678901234567890123 - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" -}; - -// Note that the decode table contains one special entry: -// The '-' character (0x2d) maps to 63 just like '/' (0x2f) -// so that URLs will work with Base64Decode when we implement them. -#define kTerminator 127 -#define xx kTerminator -static const char kDecode64[] = { -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 - xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx, - xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx, - xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,62,xx,63,xx,63, - 52,53,54,55,56,57,58,59,60,61,xx,xx,xx,xx,xx,xx, - xx, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, - 15,16,17,18,19,20,21,22,23,24,25,xx,xx,xx,xx,xx, - xx,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, - 41,42,43,44,45,46,47,48,49,50,51,xx,xx,xx,xx,xx, - xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx, - xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx, - xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx, - xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx, - xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx, - xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx, - xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx, - xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx, -}; -#undef xx - -static const char kFillchar = '='; - - -/***************************************************************************** -* -* Exports -* -***/ - -//============================================================================ -unsigned Base64Encode ( - unsigned srcChars, - const uint8_t srcData[], - unsigned dstChars, - char * dstData -) { - ASSERT(srcData); - ASSERT(dstChars >= Base64EncodeSize(srcChars)); - ASSERT(dstData); - - const char * dstBase = dstData; - const uint8_t * srcTerm = srcData + srcChars; - for (;;) switch (srcTerm - srcData) { - case 0: - *dstData++ = 0; - return dstData - dstBase; - - case 1: - *dstData++ = kEncode64[ ((srcData[0] >> 2) & 0x3f) ]; - *dstData++ = kEncode64[ ((srcData[0] << 4) & 0x30) ]; - *dstData++ = kFillchar; - *dstData++ = kFillchar; - *dstData++ = 0; - return dstData - dstBase; - - case 2: - *dstData++ = kEncode64[ ((srcData[0] >> 2) & 0x3f) ]; - *dstData++ = kEncode64[ ((srcData[0] << 4) & 0x30) + ((srcData[1] >> 4) & 0x0f) ]; - *dstData++ = kEncode64[ ((srcData[1] << 2) & 0x3c) ]; - *dstData++ = kFillchar; - *dstData++ = 0; - return dstData - dstBase; - - default: - *dstData++ = kEncode64[ ((srcData[0] >> 2) & 0x3f) ]; - *dstData++ = kEncode64[ ((srcData[0] << 4) & 0x30) + ((srcData[1] >> 4) & 0x0f) ]; - *dstData++ = kEncode64[ ((srcData[1] << 2) & 0x3c) + ((srcData[2] >> 6) & 0x03) ]; - *dstData++ = kEncode64[ (srcData[2] & 0x3f) ]; - srcData += 3; - break; - } -} - -//============================================================================ -unsigned Base64Decode ( - unsigned srcChars, - const char srcData[], - unsigned dstChars, - uint8_t * dstData -) { - ASSERT(srcData); - ASSERT(dstChars >= Base64DecodeSize(srcChars, srcData)); - ASSERT(dstData); - - const uint8_t * dstBase = dstData; - const char * srcTerm = srcData + srcChars; - while (srcTerm - srcData >= 4) { - - *dstData++ = (uint8_t) ( - (kDecode64[srcData[0]] << 2 & 0xfc) - +(kDecode64[srcData[1]] >> 4 & 0x03) - ); - - if (kDecode64[srcData[2]] == kTerminator) - break; - - *dstData++ = (uint8_t) ( - (kDecode64[srcData[1]] << 4 & 0xf0) - +(kDecode64[srcData[2]] >> 2 & 0x0f) - ); - - if (kDecode64[srcData[3]] == kTerminator) - break; - - *dstData++ = (uint8_t) ( - (kDecode64[srcData[2]] << 6 & 0xc0) - +(kDecode64[srcData[3]]) - ); - - srcData += 4; - } - - return dstData - dstBase; -} diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtBase64.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtBase64.h deleted file mode 100644 index f6635ebe..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtBase64.h +++ /dev/null @@ -1,85 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtBase64.h -* -***/ - -#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTBASE64_H -#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTBASE64_H - -#include "Pch.h" - - -/***************************************************************************** -* -* Base64 Codec API -* -***/ - -const unsigned kBase64EncodeBlock = 4; -const unsigned kBase64EncodeMultiple = 3; - -inline unsigned Base64EncodeSize (unsigned srcChars) { - return (srcChars + kBase64EncodeMultiple - 1) / kBase64EncodeMultiple - * kBase64EncodeBlock; -} -unsigned Base64Encode ( - unsigned srcChars, - const uint8_t srcData[], - unsigned dstChars, - char * dstData -); - -inline unsigned Base64DecodeSize (unsigned srcChars, const char srcData[]) { - return srcChars * kBase64EncodeMultiple / kBase64EncodeBlock - - ((srcChars >= 1 && srcData[srcChars - 1] == '=') ? 1 : 0) - - ((srcChars >= 2 && srcData[srcChars - 2] == '=') ? 1 : 0); -} -unsigned Base64Decode ( - unsigned srcChars, - const char srcData[], - unsigned dstChars, - uint8_t * dstData -); -#endif diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h index 6e6f12b2..638a0bb1 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h @@ -437,8 +437,14 @@ void TBaseHashTable::SetLinkOffset (int linkOffset, unsigned maxSize) { m_linkOffset = linkOffset; m_fullList.SetLinkOffset(m_linkOffset + offsetof(THashLink, m_linkToFull)); - if (!m_slotMask) - SetSlotCount(max(kSlotMinCount, MathNextPow2(maxSize))); + if (!m_slotMask) { + // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 + uint32_t v = maxSize - 1; + v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; + v++; + + SetSlotCount(max(kSlotMinCount, v)); + } } //=========================================================================== diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtMath.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtMath.cpp deleted file mode 100644 index 431ea740..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtMath.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtMath.cpp -* -***/ - -#include "pnUtMath.h" - - -/***************************************************************************** -* -* Exported bit manipulation functions -* -***/ - -//=========================================================================== - -unsigned MathHighBitPos (uint32_t val) { - ASSERT(val); - double f = (double)val; - return (*((uint32_t *)&f + 1) >> 20) - 1023; -} diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtMath.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtMath.h deleted file mode 100644 index 7080bb83..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtMath.h +++ /dev/null @@ -1,102 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtMath.h -* -***/ - -#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTMATH_H -#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTMATH_H - -#include "Pch.h" - -/***************************************************************************** -* -* Bit manipulation functions -* -***/ - -unsigned MathHighBitPos (uint32_t val); - -//=========================================================================== -inline unsigned MathBitCount (uint32_t val) { - val = val - ((val >> 1) & 033333333333) - ((val >> 2) & 011111111111); - val = ((val + (val >> 3)) & 030707070707); - val = val + (val >> 6); - val = (val + (val >> 12) + (val >> 24)) & 077; - return val; -} - -//=========================================================================== -inline unsigned MathBitMaskCreate (unsigned count) { - ASSERT(count <= 8 * sizeof(unsigned)); - return count ? ((2 << (count - 1)) - 1) : 0; -} - -//=========================================================================== -inline uint32_t MathHighBitValue (uint32_t val) { - return val ? 1 << MathHighBitPos(val) : 0; -} - -//=========================================================================== -inline bool MathIsPow2 (unsigned val) { - return !(val & (val - 1)); -} - -//=========================================================================== -inline unsigned MathLowBitValue (unsigned val) { - return val & ~(val - 1); -} - -//=========================================================================== -inline unsigned MathNextMultiplePow2 (unsigned val, unsigned multiple) { - ASSERT(multiple); - ASSERT(MathIsPow2(multiple)); - return (val + (multiple - 1)) & ~(multiple - 1); -} - -//=========================================================================== -inline uint32_t MathNextPow2 (uint32_t val) { - return MathIsPow2(val) ? val : 1 << (MathHighBitPos(val) + 1); -} -#endif diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtRand.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtRand.cpp deleted file mode 100644 index 4d30e7fe..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtRand.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtRand.cpp -* -***/ - -#include "pnUtRand.h" - - -/***************************************************************************** -* -* Private -* -***/ - -class RandomContext { - uint32_t m_seed; - uint32_t m_value; - - void UpdateValue (); - -public: - RandomContext (); - - void Reset (); - void SetSeed (unsigned seed); - float GetFloat (); - float GetFloat (float minVal, float maxVal); - unsigned GetUnsigned (); - unsigned GetUnsigned (unsigned minVal, unsigned maxVal); -}; - - -/***************************************************************************** -* -* Private data -* -***/ - -static const uint32_t kDefaultRandomSeed = 0x075bd924; - -static RandomContext s_random; - - -/***************************************************************************** -* -* RandomContext -* -***/ - -//============================================================================ -RandomContext::RandomContext () -: m_seed(kDefaultRandomSeed) -{ - Reset(); -} - -//============================================================================ -void RandomContext::UpdateValue () { - const uint32_t A = 0xbc8f; - const uint32_t Q = 0xadc8; - const uint32_t R = 0x0d47; - - uint32_t div = m_value / Q; - m_value = A * (m_value - Q * div) - R * div; - if (m_value > kRandomMax) - m_value -= kRandomMax + 1; - if (!m_value) - m_value = kDefaultRandomSeed; -} - -//============================================================================ -void RandomContext::Reset () { - m_value = m_seed; -} - -//============================================================================ -void RandomContext::SetSeed (unsigned seed) { - // Never allow a seed of zero - m_seed = seed ? seed : kDefaultRandomSeed; - Reset(); -} - -//============================================================================ -float RandomContext::GetFloat () { - UpdateValue(); - return m_value * (1.0f / kRandomMax); -} - -//============================================================================ -float RandomContext::GetFloat (float minVal, float maxVal) { - float value = GetFloat(); - return minVal + value * (maxVal - minVal); -} - -//============================================================================ -unsigned RandomContext::GetUnsigned () { - UpdateValue(); - return (unsigned)m_value; -} - -//============================================================================ -unsigned RandomContext::GetUnsigned (unsigned minVal, unsigned maxVal) { - unsigned value = GetUnsigned(); - return minVal + value % (maxVal - minVal + 1); -} - - -/***************************************************************************** -* -* Exports -* -***/ - -//============================================================================ -void RandReset () { - s_random.Reset(); -} - -//============================================================================ -void RandSetSeed (unsigned seed) { - s_random.SetSeed(seed); -} - -//============================================================================ -float RandFloat () { - return s_random.GetFloat(); -} - -//============================================================================ -float RandFloat (float minVal, float maxVal) { - return s_random.GetFloat(minVal, maxVal); -} - -//============================================================================ -unsigned RandUnsigned () { - return s_random.GetUnsigned(); -} - -//============================================================================ -unsigned RandUnsigned (unsigned minVal, unsigned maxVal) { - return s_random.GetUnsigned(minVal, maxVal); -} diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtRand.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtRand.h deleted file mode 100644 index 5383d49d..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtRand.h +++ /dev/null @@ -1,67 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtRand.h -* -***/ - -#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTRAND_H -#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTRAND_H - -#include "Pch.h" - -/***************************************************************************** -* -* Psuedo-random number generator -* -***/ - -const uint32_t kRandomMax = 0x7fffffff; - -void RandReset (); -void RandSetSeed (unsigned seed); -float RandFloat (); -float RandFloat (float minVal, float maxVal); -unsigned RandUnsigned (); -unsigned RandUnsigned (unsigned minVal, unsigned maxVal); -#endif diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtSpareList.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtSpareList.cpp deleted file mode 100644 index 8bc75878..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtSpareList.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtSpareList.cpp -* -***/ - -#include "pnUtSpareList.h" - - -/**************************************************************************** -* -* Exported functions -* -***/ - -//=========================================================================== -CBaseSpareList::CBaseSpareList () -: m_allocHead(nil), - m_spareHead(nil), - m_chunkSize(0) -{ - #ifdef SPARELIST_TRACK_MEMORY - m_unfreedObjects = 0; - #endif -} - -//=========================================================================== -void * CBaseSpareList::Alloc (unsigned objectSize, const char typeName[]) { - // if there aren't any spare nodes available then make more - if (!m_spareHead) - GrowSpareList(objectSize, typeName); - - // dequeue the head of the spare list - void * const object = m_spareHead; - m_spareHead = m_spareHead->spareNext; - #ifdef SPARELIST_TRACK_MEMORY - m_unfreedObjects++; - #endif - - // initialize memory to a freaky value in debug mode - #ifdef HS_DEBUGGING - memset(object, (uint8_t) ((unsigned) object >> 4), objectSize); - #endif - - return object; -} - -//=========================================================================== -void CBaseSpareList::Free (void * object, unsigned objectSize) { - // initialize memory to a freaky value in debug mode - #ifdef HS_DEBUGGING - memset(object, (uint8_t) ((unsigned) object >> 4), objectSize); - #endif - - // link memory block onto head of spare list - ((SpareNode *) object)->spareNext = m_spareHead; - m_spareHead = (SpareNode *) object; - #ifdef SPARELIST_TRACK_MEMORY - m_unfreedObjects--; - #endif -} - -//=========================================================================== -void CBaseSpareList::GrowSpareList (unsigned objectSize, const char typeName[]) { - // Grow the allocation by a substantial amount each time - // to reduce the time spent in memory managament - m_chunkSize *= 2; - const unsigned MIN_ALLOC = max(1, 256/objectSize); - const unsigned MAX_ALLOC = max(512, 32*1024/objectSize); - if (m_chunkSize < MIN_ALLOC) - m_chunkSize = MIN_ALLOC; - else if (m_chunkSize > MAX_ALLOC) - m_chunkSize = MAX_ALLOC; - - // allocate a block of memory to hold a bunch - // of T-objects, but allocate them as "raw" memory - AllocNode * allocNode = (AllocNode *) malloc( - sizeof(AllocNode) + objectSize * m_chunkSize - ); - - // link allocation onto head of allocation list - allocNode->allocNext = m_allocHead; - m_allocHead = allocNode; - - // chain newly created raw memory units together onto the spare list - SpareNode * spareCurr = (SpareNode *) (allocNode + 1); - SpareNode * spareEnd = (SpareNode *) ((uint8_t *) spareCurr + objectSize * m_chunkSize); - do { - spareCurr->spareNext = m_spareHead; - m_spareHead = spareCurr; - spareCurr = (SpareNode *) ((uint8_t *) spareCurr + objectSize); - } while (spareCurr < spareEnd); -} - -//=========================================================================== -void CBaseSpareList::CleanUp (const char typeName[]) { - // warn of resource leaks - #ifdef SPARELIST_TRACK_MEMORY - if (m_unfreedObjects) { - #ifdef CLIENT - { - char buffer[256]; - snprintf(buffer, arrsize(buffer), "Memory leak: %s", typeName); - FATAL(buffer); - } - #else - { - DEBUG_MSG("Memory leak: %s", typeName); - } - #endif - } - #endif - - // walk chain of AllocNodes and free each of them - while (m_allocHead) { - AllocNode * allocNext = m_allocHead->allocNext; - free(m_allocHead); - m_allocHead = allocNext; - } - - m_spareHead = nil; -} diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtSpareList.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtSpareList.h deleted file mode 100644 index ba660284..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtSpareList.h +++ /dev/null @@ -1,148 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtSpareList.h -* -***/ - -#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTSPARELIST_H -#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTSPARELIST_H - -#include "Pch.h" -#include - - -#ifdef HS_DEBUGGING -#define SPARELIST_TRACK_MEMORY -#endif - - -/**************************************************************************** -* -* CBaseSpareList -* -***/ - -class CBaseSpareList { -public: - CBaseSpareList (); - -protected: - struct SpareNode { - SpareNode * spareNext; - }; - SpareNode * m_spareHead; - - void * Alloc (unsigned objectSize, const char typeName[]); - void CleanUp (const char typeName[]); - void Free (void * object, unsigned objectSize); - -private: - union AllocNode { - AllocNode * allocNext; - uint64_t align; - }; - AllocNode * m_allocHead; - unsigned m_chunkSize; - - #ifdef SPARELIST_TRACK_MEMORY - unsigned m_unfreedObjects; - #endif - - void GrowSpareList (unsigned objectSize, const char typeName[]); -}; - - -/**************************************************************************** -* -* TSpareList -* -***/ - -template -class TSpareList : public CBaseSpareList { -private: - enum { OBJECT_SIZE = MAX(sizeof(T), sizeof(SpareNode)) }; - -public: - ~TSpareList () { CleanUp(); } - - void * Alloc (); - void CleanUp (); - void Delete (T * node); - void Free (T * node); - T * New (); -}; - - -//=========================================================================== -template -void * TSpareList::Alloc () { - return CBaseSpareList::Alloc(OBJECT_SIZE, typeid(T).name()); -} - -//=========================================================================== -template -void TSpareList::CleanUp () { - CBaseSpareList::CleanUp(typeid(T).name()); -} - -//=========================================================================== -template -void TSpareList::Delete (T * node) { - node->~T(); - CBaseSpareList::Free(node, OBJECT_SIZE); -} - -//=========================================================================== -template -void TSpareList::Free (T * node) { - CBaseSpareList::Free(node, OBJECT_SIZE); -} - -//=========================================================================== -template -T * TSpareList::New () { - return new(CBaseSpareList::Alloc(OBJECT_SIZE, typeid(T).name())) T; -} -#endif From 62249844c33fb0d476525ee813f5fb2bd728a316 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 19 Feb 2012 12:28:15 -0800 Subject: [PATCH 02/37] Remove some unused stuff from pnUtMisc. --- .../NucleusLib/pnUtils/Win32/pnUtW32Misc.cpp | 65 ------------------- Sources/Plasma/NucleusLib/pnUtils/pnUtMisc.h | 52 --------------- 2 files changed, 117 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Misc.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Misc.cpp index e6a9837b..452059f9 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Misc.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Misc.cpp @@ -47,13 +47,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "../pnUtils.h" -/***************************************************************************** -* -* Private -* -***/ -static MEMORYSTATUSEX s_memstatus; - /***************************************************************************** * * Exports @@ -65,70 +58,12 @@ const wchar_t * AppGetCommandLine () { return GetCommandLineW(); } -//============================================================================ -void MachineGetName (wchar_t *computerName, unsigned int length) { - DWORD len = length; - GetComputerNameW(computerName, &len); -} - /***************************************************************************** * * System status * ***/ -//============================================================================ -void MemoryGetStatus (MemoryStatus * status) { - MEMORYSTATUSEX mem; - mem.dwLength = sizeof(mem); - GlobalMemoryStatusEx(&mem); - - const uint64_t BYTES_PER_MB = 1024 * 1024; - status->totalPhysMB = unsigned(mem.ullTotalPhys / BYTES_PER_MB); - status->availPhysMB = unsigned(mem.ullAvailPhys / BYTES_PER_MB); - status->totalPageFileMB = unsigned(mem.ullTotalPageFile / BYTES_PER_MB); - status->availPageFileMB = unsigned(mem.ullAvailPageFile / BYTES_PER_MB); - status->totalVirtualMB = unsigned(mem.ullTotalVirtual / BYTES_PER_MB); - status->availVirtualMB = unsigned(mem.ullAvailVirtual / BYTES_PER_MB); - status->memoryLoad = mem.dwMemoryLoad; -} - -//============================================================================ -void DiskGetStatus (ARRAY(DiskStatus) * disks) { - DWORD length = GetLogicalDriveStrings(0, NULL); - if (!length || length > 2048) - return; - - wchar_t* buffer = (wchar_t*)malloc((length + 1) * sizeof(wchar_t)); - wchar_t* origbuf = buffer; - if (!GetLogicalDriveStringsW(length, buffer)) - { - free(buffer); - return; - } - - for (; *buffer; buffer += StrLen(buffer) + 1) { - UINT driveType = GetDriveTypeW(buffer); - if (driveType != DRIVE_FIXED) - continue; - - ULARGE_INTEGER freeBytes; - ULARGE_INTEGER totalBytes; - if (!GetDiskFreeSpaceExW(buffer, &freeBytes, &totalBytes, NULL)) - continue; - - DiskStatus status; - StrCopy(status.name, buffer, arrsize(status.name)); - - const uint64_t BYTES_PER_MB = 1024 * 1024; - status.totalSpaceMB = unsigned(totalBytes.QuadPart / BYTES_PER_MB); - status.freeSpaceMB = unsigned(freeBytes.QuadPart / BYTES_PER_MB); - - disks->Add(status); - } - free(origbuf); -} - //============================================================================ // Loosely taken from MS's cpuid code sample void CpuGetInfo ( diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtMisc.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtMisc.h index 5e400013..fb35ca46 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtMisc.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtMisc.h @@ -51,16 +51,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "Pch.h" #include "pnUtArray.h" -/***************************************************************************** -* -* Constants -* -***/ - -const wchar_t UNICODE_BOM = 0xfeff; // Unicode byte-order mark -const char UTF8_BOM[] = "\xef\xbb\xbf"; - - /***************************************************************************** * * Module instance functions @@ -80,14 +70,6 @@ void * ModuleGetInstance (); const wchar_t * AppGetCommandLine (); -/***************************************************************************** -* -* System info functions -* -***/ -void MachineGetName (wchar_t * computerName, unsigned length = 32); - - /***************************************************************************** * * Misc types @@ -101,46 +83,12 @@ typedef void (CDECL * FStateDump)( ... ); - -/***************************************************************************** -* -* Dll initialization -* -***/ - -#if HS_BUILD_FOR_WIN32 -#define SRV_MODULE_PRE_INIT() \ - extern BOOL WINAPI PreDllMain (HANDLE handle, DWORD reason, LPVOID); \ - extern "C" BOOL (WINAPI *_pRawDllMain)(HANDLE, DWORD, LPVOID) = PreDllMain -#endif - - /***************************************************************************** * * System status * ***/ -struct MemoryStatus { - unsigned totalPhysMB; // total physical memory - unsigned availPhysMB; // free physical memory - unsigned totalPageFileMB; // total page file size - unsigned availPageFileMB; // free page file size - unsigned totalVirtualMB; // total virtual address space for calling process - unsigned availVirtualMB; // available virtual address space for calling process - unsigned memoryLoad; // 0..100 -}; -void MemoryGetStatus (MemoryStatus * status); - -struct DiskStatus { - wchar_t name[16]; - unsigned totalSpaceMB; - unsigned freeSpaceMB; -}; - -void DiskGetStatus (ARRAY(DiskStatus) * disks); - - void CpuGetInfo ( uint16_t * cpuCaps, uint32_t * cpuVendor, From c1870f178bb7efbddd98345e674dda7b646a1151 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 4 Mar 2012 13:45:49 -0800 Subject: [PATCH 03/37] Remove some code that was never used anywhere. --- Sources/Plasma/NucleusLib/pnUtils/pnUtArray.h | 109 ------------------ Sources/Plasma/NucleusLib/pnUtils/pnUtCmd.cpp | 48 -------- Sources/Plasma/NucleusLib/pnUtils/pnUtCmd.h | 10 -- 3 files changed, 167 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtArray.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtArray.h index 38c32b8f..01346f99 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtArray.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtArray.h @@ -62,12 +62,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define FARRAY(type) TFArray< type, TArrayCopyBits< type > > #define FARRAYOBJ(type) TFArray< type, TArrayCopyObject< type > > -#define SORTARRAYFIELD(type, keyType, field) TSortArray< type, TArrayCopyBits< type >, keyType, offsetof(type, field)> -#define SORTARRAYFIELDOBJ(type, keyType, field) TSortArray< type, TArrayCopyObject< type >, keyType, offsetof(type, field)> -#define SORTARRAYTYPE(type) TSortArray< type, TArrayCopyBits< type >, type, 0> -#define SORTARRAYTYPEOBJ(type) TSortArray< type, TArrayCopyObject< type >, type, 0> - - /**************************************************************************** * * CBuffer @@ -978,107 +972,4 @@ template void TArray::Trim () { this->AdjustSize(this->m_count, this->m_count); } - - -/**************************************************************************** -* -* TSortArray -* -***/ - -template -class TSortArray : public TArray { -private: - inline static K & SortKey (T & rec) { return *(K *)((uint8_t *)&rec + OFFSET); } - inline static const K & SortKey (const T & rec) { return *(const K *)((const uint8_t *)&rec + OFFSET); } - -public: - inline bool Delete (K sortKey); - inline T * Find (K sortKey) { unsigned index; return Find(sortKey, &index); } - inline T * Find (K sortKey, unsigned * index); - inline const T * Find (K sortKey) const { unsigned index; return Find(sortKey, &index); } - inline const T * Find (K sortKey, unsigned * index) const; - inline T * Insert (K sortKey, unsigned index); - inline void Sort (); - -}; - -//=========================================================================== -template -bool TSortArray::Delete (K sortKey) { - - // Find the correct position for this key - unsigned index; - BSEARCH(T, this->Ptr(), this->Count(), (sortKey > SortKey(elem)), &index); - - // Verify that an entry exists for this key - unsigned count = this->Count(); - if ((index >= count) || (SortKey((*this)[index]) != sortKey)) - return false; - - // Delete the entry - this->DeleteOrdered(index); - - return true; -} - -//=========================================================================== -template -T * TSortArray::Find (K sortKey, unsigned * index) { - - // Find the correct position for this key - BSEARCH(T, this->Ptr(), this->Count(), (sortKey > SortKey(elem)), index); - if (*index >= this->Count()) - return nil; - - // Check whether the key is at that position - T & elem = (*this)[*index]; - return (SortKey(elem) == sortKey) ? &elem : nil; - -} - -//=========================================================================== -template -const T * TSortArray::Find (K sortKey, unsigned * index) const { - - // Find the correct position for this key - BSEARCH(T, this->Ptr(), this->Count(), (sortKey > SortKey(elem)), index); - if (*index >= this->Count()) - return nil; - - // Check whether the key is at that position - const T & elem = (*this)[*index]; - return (SortKey(elem) == sortKey) ? &elem : nil; - -} - -//=========================================================================== -template -T * TSortArray::Insert (K sortKey, unsigned index) { - - // Insert a new entry at this position - unsigned count = this->Count(); - this->SetCount(count + 1); - if (index < count) - this->Move(index + 1, index, count - index); - - // Fill in the new entry - T & elem = (*this)[index]; - SortKey(elem) = sortKey; - - return &elem; -} - -//=========================================================================== -template -void TSortArray::Sort () { - T * ptr = this->Ptr(); - unsigned count = this->Count(); - QSORT( - T, - ptr, - count, - SortKey(elem1) > SortKey(elem2) - ); -} #endif diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtCmd.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtCmd.cpp index 5f71810b..cea8367a 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtCmd.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtCmd.cpp @@ -648,51 +648,3 @@ bool CCmdParser::Parse (const wchar_t cmdLine[]) { return result; } - - -/**************************************************************************** -* -* CCmdParserSimple -* -***/ - - -//=========================================================================== -CCmdParserSimple::CCmdParserSimple ( - unsigned requiredStringCount, - unsigned optionalStringCount, - const wchar_t flaggedBoolNames[] // double null terminated if used -) { - - // Count the number of flagged arguments - unsigned flaggedBoolCount = 0; - const wchar_t * curr; - if (flaggedBoolNames) - for (curr = flaggedBoolNames; *curr; curr += StrLen(curr) + 1) - ++flaggedBoolCount; - - // Build the argument definition array - unsigned totalCount = requiredStringCount + optionalStringCount + flaggedBoolCount; - FARRAY(CmdArgDef) argDef(totalCount); - unsigned index = 0; - for (; index < requiredStringCount; ++index) { - argDef[index].flags = kCmdArgRequired | kCmdTypeString; - argDef[index].name = nil; - argDef[index].id = index + 1; - } - for (; index < requiredStringCount + optionalStringCount; ++index) { - argDef[index].flags = kCmdArgOptional | kCmdTypeString; - argDef[index].name = nil; - argDef[index].id = index + 1; - } - for (curr = flaggedBoolNames; index < totalCount; ++index) { - argDef[index].flags = kCmdArgFlagged | kCmdTypeBool; - argDef[index].name = curr; - argDef[index].id = 0; - curr += StrLen(curr) + 1; - } - - // Initialize the parser - Initialize(argDef.Ptr(), argDef.Count()); - -} diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtCmd.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtCmd.h index 08c83364..bed775d6 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtCmd.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtCmd.h @@ -133,14 +133,4 @@ public: bool Parse (const wchar_t cmdLine[] = nil); }; - -class CCmdParserSimple : public CCmdParser { -public: - CCmdParserSimple ( - unsigned requiredStringCount, - unsigned optionalStringCount, - const wchar_t flaggedBoolNames[] // double null terminated if used - ); - -}; #endif From dfee3034f04f8c41a0cc2ce84b67f69f9c25c05d Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 13:14:40 -0800 Subject: [PATCH 04/37] Clean up pnUtAddr of unused stuff. Still need to move ALL of this over to pnNetCommon's plNetAddress at some point. --- .../NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp | 186 ------------------ .../Plasma/NucleusLib/pnUtils/pnUtAddr.cpp | 47 ----- Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h | 50 ----- 3 files changed, 283 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp index b043a71f..54a82b10 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp @@ -48,92 +48,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "../pnUtils.h" -/***************************************************************************** -* -* Private -* -***/ - -// hardcoded uint8_t ordering -- Intel only -#ifdef _M_IX86 - - const unsigned kHostClassALoopbackAddr = 0x7f000001; // 127.0.0.1 - const unsigned kHostClassALoopbackMask = 0x00ffffff; - const unsigned kNetClassALoopbackAddr = 0x0100007f; // 127.0.0.1 - const unsigned kNetClassALoopbackMask = 0xffffff00; - - const unsigned kHostClassANatAddr = 0x000000a0; // 10.0.0.0 - 10.255.255.255 - const unsigned kHostClassANatMask = 0x000000ff; - const unsigned kNetClassANatAddr = 0x0a000000; // 10.0.0.0 - 10.255.255.255 - const unsigned kNetClassANatMask = 0xff000000; - - const unsigned kHostClassBNetAddr = 0x000010ac; // 172.16.0.0 - 172.31.255.255 - const unsigned kHostClassBNetMask = 0x0000f0ff; - const unsigned kNetClassBNetAddr = 0xac100000; // 172.16.0.0 - 172.31.255.255 - const unsigned kNetClassBNetMask = 0xfff00000; - - const unsigned kHostClassCNatAddr = 0x0000a8c0; // 192.168.0.0 - 192.168.255.255 - const unsigned kHostClassCNatMask = 0x0000ffff; - const unsigned kNetClassCNatAddr = 0xc0a80000; // 192.168.0.0 - 192.168.255.255 - const unsigned kNetClassCNatMask = 0xffff0000; - -#else - -#error "Must implement for this architecture" - -#endif // ifdef _M_IX86 - - /***************************************************************************** * * Internal functions * ***/ -//=========================================================================== -// Address sort order: -// (highest) -// externally visible address -// 10.0.0.0 - 10.255.255.255 -// 172.16.0.0 - 172.31.255.255 -// 192.168.0.0 - 192.168.255.255 -// 127.0.0.0 - 127.0.0.255 -// (lowest) -static int NetAddressNodeSortValueNetOrder (NetAddressNode addr) { - // Loopback addresses - if ((addr & kNetClassALoopbackMask) == (kNetClassALoopbackAddr & kNetClassALoopbackMask)) - return 4; - - // Private addresses - if ((addr & kNetClassCNatMask) == (kNetClassCNatAddr & kNetClassCNatMask)) - return 3; - if ((addr & kNetClassBNetMask) == (kNetClassBNetAddr & kNetClassBNetMask)) - return 2; - if ((addr & kNetClassANatMask) == (kNetClassANatAddr & kNetClassANatMask)) - return 1; - - // Public addresses - return 0; -} - -//=========================================================================== -static int NetAddressNodeSortValueHostOrder (NetAddressNode addr) { - // Loopback addresses - if ((addr & kHostClassALoopbackMask) == (kHostClassALoopbackAddr & kHostClassALoopbackMask)) - return 4; - - // Private addresses - if ((addr & kHostClassCNatMask) == (kHostClassCNatAddr & kHostClassCNatMask)) - return 3; - if ((addr & kHostClassBNetMask) == (kHostClassBNetAddr & kHostClassBNetMask)) - return 2; - if ((addr & kHostClassANatMask) == (kHostClassANatAddr & kHostClassANatMask)) - return 1; - - // Public addresses - return 0; -} - //=========================================================================== static NetAddressNode NodeFromString (const wchar_t * string[]) { // skip leading whitespace @@ -183,21 +103,6 @@ int NetAddressCompare (const NetAddress & a1, const NetAddress & a2) { return d ? d : i1.sin_port - i2.sin_port; } -//=========================================================================== -bool NetAddressSameSystem (const NetAddress & a1, const NetAddress & a2) { - const sockaddr_in & i1 = * (const sockaddr_in *) &a1; - const sockaddr_in & i2 = * (const sockaddr_in *) &a2; - return i1.sin_addr.S_un.S_addr == i2.sin_addr.S_un.S_addr; -} - -//=========================================================================== -unsigned NetAddressHash (const NetAddress & addr) { - // by using only the node number as the hash value, users can safely use - // hash value to find addresses by either using either "SameSystem" or "Equal" - const sockaddr_in & iAddr = * (const sockaddr_in *) &addr; - return iAddr.sin_addr.S_un.S_addr; -} - //=========================================================================== void NetAddressToString ( const NetAddress & addr, @@ -294,94 +199,3 @@ void NetAddressNodeToString ( addr.S_un.S_addr = htonl(node); StrPrintf(str, chars, L"%S", inet_ntoa(addr)); } - -//=========================================================================== -NetAddressNode NetAddressNodeFromString ( - const wchar_t string[], - const wchar_t * endPtr[] -) { - if (!endPtr) - endPtr = &string; - *endPtr = string; - return NodeFromString(endPtr); -} - -//=========================================================================== -void NetAddressGetLoopback ( - unsigned port, - NetAddress * addr -) { - NetAddressFromNode( - kHostClassALoopbackAddr, - port, - addr - ); -} - -//=========================================================================== -unsigned NetAddressGetLocal ( - unsigned count, - NetAddressNode addresses[] -) { - ASSERT(count); - ASSERT(addresses); - - for (;;) { - // Get local computer name - char name[MAX_COMPUTERNAME_LENGTH + 1]; - DWORD size = arrsize(name); - if (!GetComputerName(name, &size)) - StrCopy(name, "localhost", arrsize(name)); - - // Get IPv4 addresses for local system - const struct hostent * host = gethostbyname(name); - if (!host || !host->h_name) - break; - host = gethostbyname(host->h_name); - if (!host) - break; - if (host->h_length != sizeof(uint32_t)) - break; - - // Count total number of addresses - unsigned found = 0; - const uint32_t ** addr = (const uint32_t **) host->h_addr_list; - for (; *addr; ++addr) - ++found; - if (!found) - break; - - // Create a buffer to sort the addresses - NetAddressNode * dst; - if (found > count) - dst = (NetAddressNode*)_alloca(found * sizeof(NetAddressNode)); - else - dst = addresses; - - // Fill address buffer - const uint32_t * src = * (const uint32_t **) host->h_addr_list; - for (unsigned index = 0; index < found; ++index) - dst[index] = ntohl(src[index]); - - // Sort addresses by priority - QSORT( - NetAddressNode, - dst, - found, - NetAddressNodeSortValueHostOrder(elem1) - NetAddressNodeSortValueHostOrder(elem2) - ); - - // Return the number of addresses the user actually requested - if (found > count) { - for (unsigned index = 0; index < count; ++index) - addresses[index] = dst[index]; - return count; - } - - return found; - } - - // Initialize with a valid value - addresses[0] = kHostClassALoopbackAddr; - return 1; -} diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.cpp index cc798f76..cc3d36b0 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.cpp @@ -46,50 +46,3 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com ***/ #include "pnUtAddr.h" - - -/***************************************************************************** -* -* CNetAddressHash -* -***/ - -//============================================================================ -CNetAddressHash::CNetAddressHash ( - const NetAddress & addr -) : m_addr(addr) -, m_equals(nil) -{ } - -//============================================================================ -CNetAddressHash::CNetAddressHash ( - const NetAddress & addr, - FNetAddressEqualityProc equals -) : m_addr(addr) -, m_equals(equals) -{ } - -//============================================================================ -bool CNetAddressHash::operator== (const CNetAddressHash & rhs) const { - ASSERT(m_equals); - return m_equals(m_addr, rhs.m_addr); -} - -//============================================================================ -unsigned CNetAddressHash::GetHash () const { - return NetAddressHash(m_addr); -} - -//============================================================================ -const NetAddress & CNetAddressHash::GetAddr () const { - return m_addr; -} - - -/***************************************************************************** -* -* Exported data -* -***/ - -NetAddress kNilNetAddress; diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h index d0c28e9e..b13eb1a3 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h @@ -63,36 +63,6 @@ struct NetAddress { typedef unsigned NetAddressNode; - -extern NetAddress kNilNetAddress; - -typedef bool (*FNetAddressEqualityProc)( - const NetAddress & a1, - const NetAddress & a2 -); - - -class CNetAddressHash { - NetAddress m_addr; - FNetAddressEqualityProc m_equals; -public: - CNetAddressHash ( - const NetAddress & addr - ); - CNetAddressHash ( - const NetAddress & addr, - FNetAddressEqualityProc equals - // Useful values for 'equals': - // NetAddressEqual --> address node and port numbers match - // NetAddressSameSystem --> address node numbers match - ); - void operator= (const CNetAddressHash & rhs) const; // not impl. - bool operator== (const CNetAddressHash & rhs) const; - unsigned GetHash () const; - const NetAddress & GetAddr () const; -}; - - /***************************************************************************** * * Functions @@ -105,10 +75,7 @@ enum ENetAddressFormat { kNumNetAddressFormats }; -unsigned NetAddressHash (const NetAddress & addr); - int NetAddressCompare (const NetAddress & a1, const NetAddress & a2); -bool NetAddressSameSystem (const NetAddress & a1, const NetAddress & a2); inline bool NetAddressEqual (const NetAddress & a1, const NetAddress & a2) { return NetAddressCompare(a1, a2) == 0; } @@ -141,10 +108,6 @@ void NetAddressNodeToString ( wchar_t * str, unsigned chars ); -NetAddressNode NetAddressNodeFromString ( - const wchar_t string[], - const wchar_t * endPtr[] -); NetAddressNode NetAddressGetNode ( const NetAddress & addr @@ -154,17 +117,4 @@ void NetAddressFromNode ( unsigned port, NetAddress * addr ); - -void NetAddressGetLoopback ( - unsigned port, - NetAddress * addr -); - -// Returns number of addresses set, which is guaranteed to be non-zero. -// Furthermore, it sorts the addresses so that loopback and NAT addresses -// are at the end of the array, and "real" addresses are at the beginning. -unsigned NetAddressGetLocal ( - unsigned count, - NetAddressNode addresses[] -); #endif From 8c95dbe3a86dba5bd22a0e8d989977cc8bf3632d Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 13:16:36 -0800 Subject: [PATCH 05/37] We actually don't need pnUtAddr.cpp at all anymore --- .../Plasma/NucleusLib/pnUtils/CMakeLists.txt | 1 - .../Plasma/NucleusLib/pnUtils/pnUtAddr.cpp | 48 ------------------- 2 files changed, 49 deletions(-) delete mode 100644 Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.cpp diff --git a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt index ddcc21ab..8b988d1e 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt @@ -27,7 +27,6 @@ set(pnUtils_HEADERS ) set(pnUtils_SOURCES - pnUtAddr.cpp pnUtArray.cpp pnUtBigNum.cpp pnUtCmd.cpp diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.cpp deleted file mode 100644 index cc3d36b0..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtAddr.cpp -* -***/ - -#include "pnUtAddr.h" From 3b39393077ac9121fae47343a56d5b51d95f04d7 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 13:25:41 -0800 Subject: [PATCH 06/37] Kill the CpuGetInfo function. We're probably going to kill pnNetDiag at some point anyways. --- .../Plasma/NucleusLib/pnNetDiag/pnNetSys.cpp | 11 -- .../NucleusLib/pnUtils/Win32/pnUtW32Misc.cpp | 101 ------------------ Sources/Plasma/NucleusLib/pnUtils/pnUtMisc.h | 29 ----- 3 files changed, 141 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnNetDiag/pnNetSys.cpp b/Sources/Plasma/NucleusLib/pnNetDiag/pnNetSys.cpp index 938fca29..3949cf30 100644 --- a/Sources/Plasma/NucleusLib/pnNetDiag/pnNetSys.cpp +++ b/Sources/Plasma/NucleusLib/pnNetDiag/pnNetSys.cpp @@ -138,17 +138,6 @@ void NetDiagSys ( dump(L"[SYS] OS Patch: %u.%u (%S)", info.wServicePackMajor, info.wServicePackMinor, info.szCSDVersion); } - { // System - uint16_t cpuCaps; - uint32_t cpuVendor[3]; - uint16_t cpuSignature; - CpuGetInfo(&cpuCaps, cpuVendor, &cpuSignature); - SYSTEM_INFO info; - GetSystemInfo(&info); - dump(L"[SYS] CPU Count: %u", info.dwNumberOfProcessors); - dump(L"[SYS] CPU Vendor: %.*S", sizeof(cpuVendor), cpuVendor); - } - { // Adapters if (!getAdaptersInfo) { dump(L"[SYS] Failed to load IP helper API"); diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Misc.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Misc.cpp index 452059f9..645e4c1d 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Misc.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Misc.cpp @@ -58,104 +58,3 @@ const wchar_t * AppGetCommandLine () { return GetCommandLineW(); } -/***************************************************************************** -* -* System status -* -***/ - -//============================================================================ -// Loosely taken from MS's cpuid code sample -void CpuGetInfo ( - uint16_t * cpuCaps, - uint32_t * cpuVendor, - uint16_t * cpuSignature -) { - uint32_t signature = 0; - uint32_t extended = 0; - uint32_t flags[2] = { 0, 0 }; - cpuVendor[0] = 0; - -#ifdef _MSC_VER - _asm { - // Detect if cpuid instruction is supported by attempting - // to change the ID bit of EFLAGS - pushfd - pop eax // get EFLAGS - mov ecx, eax // store copy of original EFLAGS - xor eax, 0x200000 // flip ID bit - push eax - popfd // replace EFLAGS - pushfd // get EFLAGS - pop eax - xor eax, ecx - je DONE - - // Get processor id (GenuineIntel, AuthenticAMD, etc) - xor eax, eax - cpuid - mov edi, cpuVendor - mov [edi + 0], ebx - mov [edi + 4], edx - mov [edi + 8], ecx - - // Check if capability flags are supported - cmp eax, 1 - jl DONE - - // Get processor capability flags and signature - mov eax, 1 - cpuid - mov signature, eax - mov [flags + 0], edx - mov [flags + 4], ecx - - // Check for extended capabilities - mov eax, 0x80000000 - cpuid - cmp eax, 0x80000001 - jl DONE - - // Get extended capabilities - mov eax, 0x80000001 - cpuid - mov extended, edx - -DONE: - } -#endif - - // Decode capability flags - const static struct CpuCap { - uint16_t cpuFlag; - uint8_t field; - uint8_t bit; - } s_caps[] = { - // feature field bit - // ------- ----- --- - { kCpuCapCmov, 0, 15 }, - { kCpuCapEst, 1, 7 }, - { kCpuCapHtt, 0, 28 }, - { kCpuCapMmx, 0, 23 }, - { kCpuCapPsn, 0, 18 }, - { kCpuCapSse, 0, 25 }, - { kCpuCapSse2, 0, 26 }, - { kCpuCapSse3, 1, 0 }, - { kCpuCapTsc, 0, 4 }, - }; - for (unsigned i = 0; i < arrsize(s_caps); ++i) { - const CpuCap & cap = s_caps[i]; - if (flags[cap.field] & (1 << cap.bit)) - *cpuCaps |= cap.cpuFlag; - } - - // Copy signature - *cpuSignature = uint16_t(signature & 0xfff); - - // If this is an AMD CPU, check for 3DNow support - const char * vendorAmd = "AuthenticAMD"; - if (!memcmp(vendorAmd, cpuVendor, 12)) { - if (extended & (1 << 31)) - *cpuCaps |= kCpuCap3dNow; - } -} diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtMisc.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtMisc.h index fb35ca46..80c9f1b6 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtMisc.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtMisc.h @@ -83,33 +83,4 @@ typedef void (CDECL * FStateDump)( ... ); -/***************************************************************************** -* -* System status -* -***/ - -void CpuGetInfo ( - uint16_t * cpuCaps, - uint32_t * cpuVendor, - uint16_t * cpuSignature -); - -// CPU capability flags -const unsigned kCpuCap3dNow = 1<<0; -const unsigned kCpuCapCmov = 1<<1; // conditional move -const unsigned kCpuCapEst = 1<<2; // enhanced speed step -const unsigned kCpuCapHtt = 1<<3; // hyperthreading -const unsigned kCpuCapMmx = 1<<4; // multimedia extensions -const unsigned kCpuCapPsn = 1<<5; // processor serial number -const unsigned kCpuCapSse = 1<<6; // streaming SIMD extensions -const unsigned kCpuCapSse2 = 1<<7; -const unsigned kCpuCapSse3 = 1<<8; -const unsigned kCpuCapTsc = 1<<9; // time stamp counter - -// Macros for packing and unpacking CPU signature -#define CPU_SIGNATURE(family, model, stepping) ((stepping) | (model << 4) | (family << 8)) -#define CPU_SIGNATURE_FAMILY(sig) ((sig >> 8) & 0xf) -#define CPU_SIGNATURE_MODEL(sig) ((sig >> 4) & 0xf) -#define CPU_SIGNATURE_STEPPING(sig) (sig & 0xf) #endif From 44a43b298b57921693232a47a29be6d6f2f5a05c Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 14:16:01 -0800 Subject: [PATCH 07/37] Try replacing CEvent with hsSemaphore. This should work because we only ever call Wait() once. It doesn't fully behave like Win32's manual reset events though, so if we had a more complex usage that depended on the event remaining signalled, we'd have a problem. --- Sources/Plasma/Apps/plClient/winmain.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index 94bcdd5b..ba76e22c 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/winmain.cpp @@ -120,7 +120,7 @@ bool gPendingActivate = false; bool gPendingActivateFlag = false; static bool s_loginDlgRunning = false; -static CEvent s_statusEvent(kEventManualReset); +static hsSemaphore s_statusEvent(0); // Start non-signalled FILE *errFP = nil; HINSTANCE gHInst = NULL; // Instance of this app @@ -1135,7 +1135,7 @@ void StatusCallback(void *param) curl_easy_cleanup(hCurl); delete [] statusUrl; - s_statusEvent.Signal(); + s_statusEvent.Signal(); // Signal the semaphore } BOOL CALLBACK UruLoginDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) @@ -1185,7 +1185,7 @@ BOOL CALLBACK UruLoginDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM case WM_DESTROY: { s_loginDlgRunning = false; - s_statusEvent.Wait(kEventWaitForever); + s_statusEvent.Wait(); KillTimer(hwndDlg, AUTH_LOGIN_TIMER); return TRUE; } From 9e92b7743864e882135d42b69746c93e79de3bd9 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 16:07:59 -0800 Subject: [PATCH 08/37] Get rid of CEvent in plUruLauncher. --- Sources/Plasma/Apps/plUruLauncher/Main.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Plasma/Apps/plUruLauncher/Main.cpp b/Sources/Plasma/Apps/plUruLauncher/Main.cpp index 3b27e30b..8e2d15c6 100644 --- a/Sources/Plasma/Apps/plUruLauncher/Main.cpp +++ b/Sources/Plasma/Apps/plUruLauncher/Main.cpp @@ -147,12 +147,12 @@ static HANDLE s_thread; static HANDLE s_event; static HINSTANCE s_hInstance; static HWND s_dialog; -static CEvent s_dialogCreateEvent(kEventManualReset); +static hsSemaphore s_dialogCreateEvent(0); static CCritSect s_critsect; static LISTDECL(WndEvent, link) s_eventQ; -static CEvent s_shutdownEvent(kEventManualReset); +static hsSemaphore s_shutdownEvent(0); static wchar_t s_workingDir[MAX_PATH]; -static CEvent s_statusEvent(kEventManualReset); +static hsSemaphore s_statusEvent(0); static char s_curlError[CURL_ERROR_SIZE]; @@ -810,7 +810,7 @@ int __stdcall WinMain ( s_launcherInfo.buildId = cmdParser.GetInt(kArgBuildId); // Wait for the dialog to be created - s_dialogCreateEvent.Wait(kEventWaitForever); + s_dialogCreateEvent.Wait(); _beginthread(StatusCallback, 0, nil); // get status } @@ -950,10 +950,10 @@ int __stdcall WinMain ( } ShutdownAsyncCore(); - s_statusEvent.Wait(kEventWaitForever); + s_statusEvent.Wait(); PostMessage(s_dialog, WM_QUIT, 0, 0); // tell our window to shutdown - s_shutdownEvent.Wait(kEventWaitForever); // wait for our window to shutdown + s_shutdownEvent.Wait(); // wait for our window to shutdown SetConsoleCtrlHandler(CtrlHandler, FALSE); From 590eea770f085ab32dc43940037e393cf6c6be71 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 16:09:03 -0800 Subject: [PATCH 09/37] Remove CEvent entirely. --- .../NucleusLib/pnUtils/Win32/pnUtW32Sync.cpp | 41 ------------------- Sources/Plasma/NucleusLib/pnUtils/pnUtSync.h | 37 ----------------- 2 files changed, 78 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Sync.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Sync.cpp index e5100e52..dadc167b 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Sync.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Sync.cpp @@ -316,47 +316,6 @@ void CLock::LeaveWrite () { } -/***************************************************************************** -* -* CEvent -* -***/ - -//============================================================================ -CEvent::CEvent ( - ECEventResetBehavior resetType, - bool initialSet -) { - m_handle = CreateEvent( - nil, // security attributes - (resetType == kEventManualReset) ? true : false, - initialSet, - nil // name - ); -} - -//============================================================================ -CEvent::~CEvent () { - (void) CloseHandle(m_handle); -} - -//============================================================================ -void CEvent::Signal () { - SetEvent(m_handle); -} - -//============================================================================ -void CEvent::Reset () { - ResetEvent(m_handle); -} - -//============================================================================ -bool CEvent::Wait (unsigned waitMs) { - ThreadAssertCanBlock(__FILE__, __LINE__); - return WaitForSingleObject(m_handle, waitMs) == WAIT_OBJECT_0; -} - - /**************************************************************************** * * Exported functions diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtSync.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtSync.h index 750b5bb7..8a22497b 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtSync.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtSync.h @@ -95,41 +95,4 @@ public: void LeaveWrite (); }; - -/***************************************************************************** -* -* CEvent -* -***/ - -#ifdef HS_BUILD_FOR_WIN32 -typedef HANDLE EventHandle; -//#else -//# error "CEvent: Not implemented on this platform" -//#endif - -const unsigned kEventWaitForever = (unsigned)-1; - -enum ECEventResetBehavior { - kEventManualReset, - kEventAutoReset, -}; - -class CEvent { - EventHandle m_handle; -public: - CEvent ( - ECEventResetBehavior resetType, - bool initialSet = false - ); - ~CEvent (); - - void Signal (); - void Reset (); - bool Wait (unsigned waitMs); - - const EventHandle & Handle () const { return m_handle; } -}; -#endif // HS_BUILD_FOR_WIN32 - #endif From 26dc1fa1200ed39c98ad74a0175e107aca73f6da Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 17:47:25 -0800 Subject: [PATCH 10/37] Get rid of the PnUtils TLS stuff. --- .../Private/Nt/pnAceNtThread.cpp | 1 - .../NucleusLib/pnAsyncCoreExe/pnAceTimer.cpp | 3 - .../Plasma/NucleusLib/pnUtils/CMakeLists.txt | 2 - .../NucleusLib/pnUtils/pnUtAllIncludes.h | 5 - Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h | 1 - Sources/Plasma/NucleusLib/pnUtils/pnUtTls.cpp | 82 ------------- Sources/Plasma/NucleusLib/pnUtils/pnUtTls.h | 72 ------------ .../NucleusLib/pnUtilsExe/CMakeLists.txt | 1 - .../pnUtilsExe/Private/pnUteTls.cpp | 110 ------------------ 9 files changed, 277 deletions(-) delete mode 100644 Sources/Plasma/NucleusLib/pnUtils/pnUtTls.cpp delete mode 100644 Sources/Plasma/NucleusLib/pnUtils/pnUtTls.h delete mode 100644 Sources/Plasma/NucleusLib/pnUtilsExe/Private/pnUteTls.cpp diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtThread.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtThread.cpp index 56fc0ae2..32e808f1 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtThread.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtThread.cpp @@ -61,7 +61,6 @@ namespace Nt { //=========================================================================== void NtSleep (unsigned sleepMs) { - ThreadAssertCanBlock(__FILE__, __LINE__); Sleep(sleepMs); } diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceTimer.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceTimer.cpp index c3a168a4..64889003 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceTimer.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceTimer.cpp @@ -307,9 +307,6 @@ void AsyncTimerDelete ( // Wait until the timer procedure completes if (timerProc) { - // ensure that I/O worker threads don't call this function with waitComplete=true - // to prevent a possible deadlock of a timer callback waiting for itself to complete - ThreadAssertCanBlock(__FILE__, __LINE__); while (s_timerCurr == timerProc) Sleep(1); diff --git a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt index 8b988d1e..01000e98 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt @@ -22,7 +22,6 @@ set(pnUtils_HEADERS pnUtStr.h pnUtSync.h pnUtTime.h - pnUtTls.h pnUtUuid.h ) @@ -50,7 +49,6 @@ if(WIN32) Win32/pnUtW32Uuid.cpp pnUtCrypt.cpp - pnUtTls.cpp ) else() set(pnUtils_UNIX diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h index 96305333..6c9a8bdb 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h @@ -53,7 +53,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnUtPragma.h" #include "pnUtAddr.h" #include "pnUtUuid.h" -#include "pnUtMath.h" #include "pnUtSort.h" #include "pnUtArray.h" #include "pnUtList.h" @@ -61,7 +60,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnUtPriQ.h" #include "pnUtSync.h" #include "pnUtTime.h" -#include "pnUtTls.h" #include "pnUtStr.h" #include "pnUtRef.h" #include "pnUtPath.h" @@ -69,8 +67,5 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnUtCmd.h" #include "pnUtMisc.h" #include "pnUtCrypt.h" -#include "pnUtSpareList.h" -#include "pnUtRand.h" -#include "pnUtBase64.h" #endif // PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTALLINCLUDES_H diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h index 638a0bb1..c01b30cc 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h @@ -51,7 +51,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "Pch.h" #include "pnUtList.h" #include "pnUtArray.h" -#include "pnUtMath.h" #include "pnUtStr.h" /**************************************************************************** diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtTls.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtTls.cpp deleted file mode 100644 index 730af543..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtTls.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtTls.cpp -* -***/ - -#include "pnUtTls.h" - - -/***************************************************************************** -* -* Exports -* -***/ - -#ifdef HS_BUILD_FOR_WIN32 - -//============================================================================ -void ThreadLocalAlloc (unsigned * id) { - ASSERT(id); - *id = TlsAlloc(); -} - -//============================================================================ -void ThreadLocalFree (unsigned id) { - (void)TlsFree(id); -} - -//============================================================================ -void * ThreadLocalGetValue (unsigned id) { - return TlsGetValue(id); -} - -//============================================================================ -void ThreadLocalSetValue (unsigned id, void * value) { - TlsSetValue(id, value); -} - -#else -# error "TLS not implemented for this platform" -#endif diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtTls.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtTls.h deleted file mode 100644 index 815c22f6..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtTls.h +++ /dev/null @@ -1,72 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtTls.h -* -***/ - -#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTTLS_H -#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTTLS_H - -#include "Pch.h" - -/***************************************************************************** -* -* Thread local storage functions -* -***/ - -const unsigned kTlsInvalidValue = (unsigned) -1; - -void ThreadLocalAlloc (unsigned * id); -void ThreadLocalFree (unsigned id); -void * ThreadLocalGetValue (unsigned id); -void ThreadLocalSetValue (unsigned id, void * value); - - -// Thread capability functions - prevents deadlocks and performance -// bottlenecks by disallowing some threads certain operations. -void ThreadAllowBlock (); -void ThreadDenyBlock (); -void ThreadAssertCanBlock (const char file[], int line); -#endif diff --git a/Sources/Plasma/NucleusLib/pnUtilsExe/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnUtilsExe/CMakeLists.txt index 496de2d4..dbe63c74 100644 --- a/Sources/Plasma/NucleusLib/pnUtilsExe/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/pnUtilsExe/CMakeLists.txt @@ -8,7 +8,6 @@ set(pnUtilsExe_HEADERS set(pnUtilsExe_PRIVATE Private/pnUteTime.cpp - Private/pnUteTls.cpp ) if(WIN32) diff --git a/Sources/Plasma/NucleusLib/pnUtilsExe/Private/pnUteTls.cpp b/Sources/Plasma/NucleusLib/pnUtilsExe/Private/pnUteTls.cpp deleted file mode 100644 index 4001806b..00000000 --- a/Sources/Plasma/NucleusLib/pnUtilsExe/Private/pnUteTls.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtilsExe/Private/pnUteTls.cpp -* -***/ - -#include "../Pch.h" -#pragma hdrstop - -#if HS_BUILD_FOR_WIN32 - -/***************************************************************************** -* -* Private data -* -***/ - -static unsigned s_tlsNoBlock = kTlsInvalidValue; - - -/***************************************************************************** -* -* Local functions -* -***/ - -//============================================================================ -static void ThreadCapsInitialize () { - ThreadLocalAlloc(&s_tlsNoBlock); -} - -//============================================================================ -static void ThreadCapsDestroy () { - if (s_tlsNoBlock != kTlsInvalidValue) { - ThreadLocalFree(s_tlsNoBlock); - s_tlsNoBlock = kTlsInvalidValue; - } -} - -//============================================================================ -AUTO_INIT_FUNC(InitThreadCaps) { - ThreadCapsInitialize(); - atexit(ThreadCapsDestroy); -} - - -/***************************************************************************** -* -* Exports -* -***/ - -//============================================================================ -void ThreadAllowBlock () { - ThreadLocalSetValue(s_tlsNoBlock, (void *) false); -} - -//============================================================================ -void ThreadDenyBlock () { - ThreadLocalSetValue(s_tlsNoBlock, (void *) true); -} - -//============================================================================ -void ThreadAssertCanBlock (const char file[], int line) { - if (ThreadLocalGetValue(s_tlsNoBlock)) - ErrorAssert(line, file, "This thread may not block"); -} - -#endif From 251cf02bd71d62f60d33e0911ff2de5efa4e5222 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 17:49:22 -0800 Subject: [PATCH 11/37] Move AtomicAdd/AtomicSet to hsUtils. --- Sources/Plasma/CoreLib/hsUtils.h | 28 +++++++++++++++++++ .../NucleusLib/pnUtils/Win32/pnUtW32Sync.cpp | 17 ----------- Sources/Plasma/NucleusLib/pnUtils/pnUtSync.h | 20 ------------- 3 files changed, 28 insertions(+), 37 deletions(-) diff --git a/Sources/Plasma/CoreLib/hsUtils.h b/Sources/Plasma/CoreLib/hsUtils.h index 54e952f5..e42179af 100644 --- a/Sources/Plasma/CoreLib/hsUtils.h +++ b/Sources/Plasma/CoreLib/hsUtils.h @@ -250,3 +250,31 @@ void DebugMsg(const char fmt[], ...); #else #define DEFAULT_FATAL(var) default: FATAL("No valid case for switch variable '" #var "'"); break; #endif + +/***************************************************************************** +* +* Atomic Operations +* +***/ + +// *value += increment; return original value of *value; thread safe +long AtomicAdd(long* value, long increment) { +#ifdef HS_BUILD_FOR_WIN32 + return InterlockedExchangeAdd(value, increment); +#elif HS_BUILD_FOR_UNIX + return __sync_fetch_and_add(value, increment); +#else +#error "No Atomic Set support on this architecture" +#endif +} + +// *value = value; return original value of *value; thread safe +long AtomicSet(long* value, long set) { +#ifdef HS_BUILD_FOR_WIN32 + return InterlockedExchange(value, set); +#elif HS_BUILD_FOR_UNIX + return __sync_lock_test_and_set(value, set); +#else +#error "No Atomic Set support on this architecture" +#endif +} diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Sync.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Sync.cpp index dadc167b..1a75b30c 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Sync.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Sync.cpp @@ -314,20 +314,3 @@ void CLock::LeaveWrite () { LeaveSpinLock(&m_spinLock); } - - -/**************************************************************************** -* -* Exported functions -* -***/ - -//=========================================================================== -long AtomicAdd (long * value, long increment) { - return InterlockedExchangeAdd(value, increment); -} - -//=========================================================================== -long AtomicSet (long * value, long set) { - return InterlockedExchange(value, set); -} diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtSync.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtSync.h index 8a22497b..dda44786 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtSync.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtSync.h @@ -50,26 +50,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "Pch.h" -/**************************************************************************** -* -* Atomic operations -* -***/ - -// *value += increment; return original value of *value; thread safe -long AtomicAdd (long * value, long increment); - -// *value = value; return original value of *value; thread safe -long AtomicSet (long * value, long set); - - -#define ATOMIC_ONCE(code) { \ - static long s_count = 1; \ - if (AtomicSet(&s_count, 0)) \ - code; \ -} // - - /**************************************************************************** * * CLock From 3bf303885adc7644103804de61214262994e28d6 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 18:16:18 -0800 Subject: [PATCH 12/37] PnUtCrypt compiles on *nix now. --- Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt index 01000e98..6ca4b931 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt @@ -29,6 +29,7 @@ set(pnUtils_SOURCES pnUtArray.cpp pnUtBigNum.cpp pnUtCmd.cpp + pnUtCrypt.cpp pnUtHash.cpp pnUtList.cpp pnUtMisc.cpp @@ -47,8 +48,6 @@ if(WIN32) Win32/pnUtW32Sync.cpp Win32/pnUtW32Time.cpp Win32/pnUtW32Uuid.cpp - - pnUtCrypt.cpp ) else() set(pnUtils_UNIX From b7035a631efeeca9236ced2c38689e77f4f728e1 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 18:16:37 -0800 Subject: [PATCH 13/37] Try to replace a pnUtList with a std::queue. --- .../Plasma/Apps/plClientPatcher/UruPlayer.cpp | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp b/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp index c805a0cc..54d2430f 100644 --- a/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp +++ b/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp @@ -47,6 +47,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "Pch.h" #include "plStatusLog/plStatusLog.h" +#include #pragma hdrstop @@ -67,7 +68,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com struct ManifestFile { - LINK(ManifestFile) link; ManifestFile(const wchar_t clientName[], const wchar_t downloadName[], const wchar_t md5val[], int flags, plLauncherInfo *info) { StrCopy(filename, clientName, arrsize(filename)); @@ -142,13 +142,12 @@ static unsigned s_fileListRequests; static bool s_patchComplete; static PROCESS_INFORMATION s_pi; static long s_numFiles; -static CCritSect s_critsect; static char s_workingDir[MAX_PATH]; static bool s_patchError; static long s_asyncCoreInitCount; static long s_numConnectFailures; static bool s_running; -static LISTDECL(ManifestFile, link) s_manifestQueue; +static std::queue manifestQueue; //static AsyncThreadTaskList * s_taskList; // error strings @@ -347,10 +346,13 @@ void Shutdown(plLauncherInfo *info) { //============================================================================ static void RequestNextManifestFile () { bool success = true; - ManifestFile *nextfile = s_manifestQueue.Head(); - if(!nextfile) + + if (!manifestQueue.size()) return; - s_manifestQueue.Unlink(nextfile); + + ManifestFile* nextFile = manifestQueue.front(); + manifestQueue.pop(); + char path[MAX_PATH]; wchar_t basePath[MAX_PATH]; StrPrintf(path, arrsize(path), "%s%S", s_workingDir, nextfile->filename); @@ -614,14 +616,14 @@ static void ProcessManifest (void * param) { PathRemoveFilename(basePath, basePath, arrsize(basePath)); PathCreateDirectory(basePath, kPathCreateDirFlagEntireTree); - ManifestFile * mf = new ManifestFile( + ManifestFile* mf = new ManifestFile( manifest[index].clientName, manifest[index].downloadName, manifest[index].md5, manifest[index].flags, mr->info ); - + if (i < kMaxManifestFileRequests) { ProgressStream * stream; stream = NEWZERO(ProgressStream); @@ -645,7 +647,7 @@ static void ProcessManifest (void * param) { } else { // queue up this file download - s_manifestQueue.Link(mf); + manifestQueue.push(mf); } } } @@ -916,8 +918,10 @@ void UruPrepProc (void * param) { AsyncSleep(10); } while ((!s_patchComplete && !s_patchError && s_running) || s_perf[kPerfThreadTaskCount]); - while(ManifestFile *mf = s_manifestQueue.Head()) + while (manifestQueue.size()) { + ManifestFile* mf = manifestQueue.front() + manifestQueue.pop(); delete mf; } // If s_patchError, we don't wait around for s_numFiles From a28213806f9263b5181124be2a4835b0ff749b3b Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 19:16:52 -0800 Subject: [PATCH 14/37] Fix compiling. --- Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp | 4 ++-- Sources/Plasma/Apps/plUruLauncher/Main.cpp | 1 + Sources/Plasma/CoreLib/hsUtils.h | 4 ++-- .../Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNt.cpp | 2 -- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp b/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp index 54d2430f..b8beaf9b 100644 --- a/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp +++ b/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp @@ -350,7 +350,7 @@ static void RequestNextManifestFile () { if (!manifestQueue.size()) return; - ManifestFile* nextFile = manifestQueue.front(); + ManifestFile* nextfile = manifestQueue.front(); manifestQueue.pop(); char path[MAX_PATH]; @@ -920,7 +920,7 @@ void UruPrepProc (void * param) { while (manifestQueue.size()) { - ManifestFile* mf = manifestQueue.front() + ManifestFile* mf = manifestQueue.front(); manifestQueue.pop(); delete mf; } diff --git a/Sources/Plasma/Apps/plUruLauncher/Main.cpp b/Sources/Plasma/Apps/plUruLauncher/Main.cpp index 8e2d15c6..2c41a352 100644 --- a/Sources/Plasma/Apps/plUruLauncher/Main.cpp +++ b/Sources/Plasma/Apps/plUruLauncher/Main.cpp @@ -46,6 +46,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com ***/ #include "Pch.h" +#include "hsThread.h" #pragma hdrstop diff --git a/Sources/Plasma/CoreLib/hsUtils.h b/Sources/Plasma/CoreLib/hsUtils.h index e42179af..4768d57d 100644 --- a/Sources/Plasma/CoreLib/hsUtils.h +++ b/Sources/Plasma/CoreLib/hsUtils.h @@ -258,7 +258,7 @@ void DebugMsg(const char fmt[], ...); ***/ // *value += increment; return original value of *value; thread safe -long AtomicAdd(long* value, long increment) { +inline long AtomicAdd(long* value, long increment) { #ifdef HS_BUILD_FOR_WIN32 return InterlockedExchangeAdd(value, increment); #elif HS_BUILD_FOR_UNIX @@ -269,7 +269,7 @@ long AtomicAdd(long* value, long increment) { } // *value = value; return original value of *value; thread safe -long AtomicSet(long* value, long set) { +inline long AtomicSet(long* value, long set) { #ifdef HS_BUILD_FOR_WIN32 return InterlockedExchange(value, set); #elif HS_BUILD_FOR_UNIX diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNt.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNt.cpp index 8e9dbd18..1475ede2 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNt.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNt.cpp @@ -222,8 +222,6 @@ static void INtOpDispatch ( //=========================================================================== static unsigned THREADCALL NtWorkerThreadProc (AsyncThread * thread) { - ThreadDenyBlock(); - unsigned sleepMs = INFINITE; while (s_running) { From 833124c29759a551d5569a0ab122744b5e4436de Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 20:33:26 -0800 Subject: [PATCH 15/37] Get rid of CCritSect in the patcher stuff. --- Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp | 6 +++--- Sources/Plasma/Apps/plUruLauncher/Main.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp b/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp index b8beaf9b..c36cde8d 100644 --- a/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp +++ b/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp @@ -113,7 +113,7 @@ struct ManifestResult { long * indicator; plLauncherInfo * info; - CCritSect critsect; + hsMutex critsect; ARRAY(unsigned) indices; }; @@ -498,9 +498,9 @@ static void ProcessManifestEntry (void * param, ENetError error) { ); uint32_t start = (uint32_t)(TimeGetTime() / kTimeIntervalsPerMs); if(!MD5Check(path, p->mr->manifest[p->index].md5)) { - p->mr->critsect.Enter(); + p->mr->critsect.Lock(); p->mr->indices.Add(p->index); - p->mr->critsect.Leave(); + p->mr->critsect.Unlock(); AtomicAdd(&ProgressStream::totalBytes, p->mr->manifest[p->index].zipSize); } diff --git a/Sources/Plasma/Apps/plUruLauncher/Main.cpp b/Sources/Plasma/Apps/plUruLauncher/Main.cpp index 2c41a352..2e35b79e 100644 --- a/Sources/Plasma/Apps/plUruLauncher/Main.cpp +++ b/Sources/Plasma/Apps/plUruLauncher/Main.cpp @@ -149,7 +149,7 @@ static HANDLE s_event; static HINSTANCE s_hInstance; static HWND s_dialog; static hsSemaphore s_dialogCreateEvent(0); -static CCritSect s_critsect; +static hsMutex s_critsect; static LISTDECL(WndEvent, link) s_eventQ; static hsSemaphore s_shutdownEvent(0); static wchar_t s_workingDir[MAX_PATH]; @@ -197,9 +197,9 @@ static void Abort () { //============================================================================ static void PostEvent (WndEvent *event) { - s_critsect.Enter(); + s_critsect.Lock(); s_eventQ.Link(event); - s_critsect.Leave(); + s_critsect.Unlock(); } //============================================================================ @@ -394,11 +394,11 @@ static void Recv_SetBytesRemaining (HWND hwnd, const SetBytesRemainingEvent &eve static void DispatchEvents (HWND hwnd) { LISTDECL(WndEvent, link) eventQ; - s_critsect.Enter(); + s_critsect.Lock(); { eventQ.Link(&s_eventQ); } - s_critsect.Leave(); + s_critsect.Unlock(); #define DISPATCH(a) case kEvent##a: Recv_##a(hwnd, *(const a##Event *) event); break while (WndEvent *event = eventQ.Head()) { From f6f063a9ddfab0c4ce8d6ddc6bab87e9a276e983 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 20:34:03 -0800 Subject: [PATCH 16/37] Fix pnNetCli for *nix. Thanks to @zrax for breaking it originally :P Also switch another CCritSect over to hsMutex, and replace LIST with std::list. --- .../NucleusLib/pnNetCli/pnNcChannel.cpp | 65 ++++++++++--------- .../Plasma/NucleusLib/pnNetCli/pnNcCli.cpp | 8 +-- Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h | 10 +-- 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp b/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp index 0db62460..94086105 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp @@ -46,6 +46,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com ***/ #include "Pch.h" +#include "hsThread.h" +#include #pragma hdrstop @@ -60,34 +62,33 @@ namespace pnNetCli { struct ChannelCrit { ~ChannelCrit (); ChannelCrit (); - inline void Enter () { m_critsect.Enter(); } - inline void Leave () { m_critsect.Leave(); } - inline void EnterSafe () { if (m_init) m_critsect.Enter(); } - inline void LeaveSafe () { if (m_init) m_critsect.Leave(); } + inline void Enter () { m_critsect.Lock(); } + inline void Leave () { m_critsect.Unlock(); } + inline void EnterSafe () { if (m_init) m_critsect.Lock(); } + inline void LeaveSafe () { if (m_init) m_critsect.Unlock(); } private: bool m_init; - CCritSect m_critsect; + hsMutex m_critsect; }; struct NetMsgChannel : AtomicRef { - LINK(NetMsgChannel) m_link; - unsigned m_protocol; + uint32_t m_protocol; bool m_server; // Message definitions - unsigned m_largestRecv; + uint32_t m_largestRecv; ARRAY(NetMsgInitSend) m_sendMsgs; ARRAY(NetMsgInitRecv) m_recvMsgs; // Diffie-Hellman constants - unsigned m_dh_g; + uint32_t m_dh_g; BigNum m_dh_xa; // client: dh_x server: dh_a BigNum m_dh_n; }; -static ChannelCrit s_channelCrit; -static LIST(NetMsgChannel) * s_channels; +static ChannelCrit s_channelCrit; +static std::list* s_channels; /**************************************************************************** @@ -105,8 +106,9 @@ ChannelCrit::ChannelCrit () { ChannelCrit::~ChannelCrit () { EnterSafe(); if (s_channels) { - while (NetMsgChannel * const channel = s_channels->Head()) { - s_channels->Unlink(channel); + while (s_channels->size()) { + NetMsgChannel* const channel = s_channels->front(); + s_channels->remove(channel); channel->DecRef("ChannelLink"); } @@ -239,30 +241,29 @@ static void AddRecvMsgs_CS ( // copy the message handler *dst = *src; - const unsigned bytes = ValidateMsg(dst->msg); + const uint32_t bytes = ValidateMsg(dst->msg); channel->m_largestRecv = max(channel->m_largestRecv, bytes); } } //=========================================================================== -static NetMsgChannel * FindChannel_CS (unsigned protocol, bool server) { +static NetMsgChannel* FindChannel_CS (uint32_t protocol, bool server) { if (!s_channels) return nil; - NetMsgChannel * channel = s_channels->Head(); - for (; channel; channel = s_channels->Next(channel)) { - if ((channel->m_protocol == protocol) && (channel->m_server == server)) + std::list::iterator it = s_channels->begin(); + for (; it != s_channels->end(); ++it) { + if (((*it)->m_protocol == protocol) && ((*it)->m_server == server)) break; } - return channel; + return *it; } //=========================================================================== -static NetMsgChannel * FindOrCreateChannel_CS (unsigned protocol, bool server) { +static NetMsgChannel* FindOrCreateChannel_CS (uint32_t protocol, bool server) { if (!s_channels) { - s_channels = new LIST(NetMsgChannel); - s_channels->SetLinkOffset(offsetof(NetMsgChannel, m_link)); + s_channels = new std::list(); } // find or create protocol @@ -273,7 +274,7 @@ static NetMsgChannel * FindOrCreateChannel_CS (unsigned protocol, bool server) { channel->m_server = server; channel->m_largestRecv = 0; - s_channels->Link(channel); + s_channels->push_back(channel); channel->IncRef("ChannelLink"); } @@ -291,7 +292,7 @@ static NetMsgChannel * FindOrCreateChannel_CS (unsigned protocol, bool server) { NetMsgChannel * NetMsgChannelLock ( unsigned protocol, bool server, - unsigned * largestRecv + uint32_t * largestRecv ) { NetMsgChannel * channel; s_channelCrit.Enter(); @@ -353,7 +354,7 @@ const NetMsgInitSend * NetMsgChannelFindSendMessage ( //============================================================================ void NetMsgChannelGetDhConstants ( const NetMsgChannel * channel, - unsigned * dh_g, + uint32_t * dh_g, const BigNum ** dh_xa, const BigNum ** dh_n ) { @@ -374,13 +375,13 @@ void NetMsgChannelGetDhConstants ( //=========================================================================== void NetMsgProtocolRegister ( - unsigned protocol, + uint32_t protocol, bool server, const NetMsgInitSend sendMsgs[], - unsigned sendMsgCount, + uint32_t sendMsgCount, const NetMsgInitRecv recvMsgs[], - unsigned recvMsgCount, - unsigned dh_g, + uint32_t recvMsgCount, + uint32_t dh_g, const BigNum & dh_xa, // client: dh_x server: dh_a const BigNum & dh_n ) { @@ -406,10 +407,10 @@ void NetMsgProtocolRegister ( } //=========================================================================== -void NetMsgProtocolDestroy (unsigned protocol, bool server) { +void NetMsgProtocolDestroy (uint32_t protocol, bool server) { s_channelCrit.EnterSafe(); - if (NetMsgChannel * channel = FindChannel_CS(protocol, server)) { - s_channels->Unlink(channel); + if (NetMsgChannel* channel = FindChannel_CS(protocol, server)) { + s_channels->remove(channel); channel->DecRef("ChannelLink"); } s_channelCrit.LeaveSafe(); diff --git a/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp b/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp index 04501fd7..b8abb12c 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp @@ -58,7 +58,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com # define NCCLI_LOG LogMsg #endif -#ifndef PLASMA_EXTERNAL_RELEASE +#if !defined(PLASMA_EXTERNAL_RELEASE) && defined(HS_BUILD_FOR_WIN32) struct NetLogMessage_Header { @@ -173,7 +173,7 @@ static void PutBufferOnWire (NetCli * cli, void * data, unsigned bytes) { uint8_t * temp = NULL; -#ifndef PLASMA_EXTERNAL_RELEASE +#if !defined(PLASMA_EXTERNAL_RELEASE) && defined(HS_BUILD_FOR_WIN32) // Write to the netlog if (s_netlog) { NetLogMessage_Header header; @@ -919,7 +919,7 @@ static NetCli * ConnCreate ( cli->mode = mode; cli->SetValue(kNilGuid); -#ifndef PLASMA_EXTERNAL_RELEASE +#if !defined(PLASMA_EXTERNAL_RELEASE) && defined(HS_BUILD_FOR_WIN32) // Network debug pipe if (!s_netlog) { InitializeCriticalSection(&s_pipeCritical); @@ -1124,7 +1124,7 @@ bool NetCliDispatch ( cli->input.Add(bytes, data); bool result = DispatchData(cli, param); -#ifndef PLASMA_EXTERNAL_RELEASE +#if !defined(PLASMA_EXTERNAL_RELEASE) && defined(HS_BUILD_FOR_WIN32) // Write to the netlog if (s_netlog) { NetLogMessage_Header header; diff --git a/Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h b/Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h index 47b706f6..cc3ac7ba 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h +++ b/Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h @@ -318,20 +318,20 @@ struct NetMsgInitRecv { }; void NetMsgProtocolRegister ( - unsigned protocol, // from pnNetBase/pnNbProtocol.h + uint32_t protocol, // from pnNetBase/pnNbProtocol.h bool server, const NetMsgInitSend sendMsgs[], // messages this program can send - unsigned sendMsgCount, + uint32_t sendMsgCount, const NetMsgInitRecv recvMsgs[], // messages this program can receive - unsigned recvMsgCount, + uint32_t recvMsgCount, // Diffie-Hellman keys - unsigned dh_g, + uint32_t dh_g, const BigNum & dh_xa, // client: dh_x server: dh_a const BigNum & dh_n ); void NetMsgProtocolDestroy ( - unsigned protocol, + uint32_t protocol, bool server ); From 364ac730501cde2c786a0fc97c7cd4907a6f88d2 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 20:35:09 -0800 Subject: [PATCH 17/37] Replace NetLinkingMgr LIST with std::list. --- .../plNetClient/plNetLinkingMgr.cpp | 72 +++++++++---------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp index 03112b49..a6015300 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp @@ -44,6 +44,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plNetCliAgeJoiner.h" #include "plNetCliAgeLeaver.h" +#include + #include "plNetTransport/plNetTransportMember.h" // OfferLinkToPlayer() #include "plgDispatch.h" @@ -70,8 +72,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com * ***/ -struct NlmOpNode; - enum ENlmOp { kNlmOpNoOp, kNlmOpWaitOp, @@ -82,7 +82,6 @@ enum ENlmOp { struct NlmOp { ENlmOp opcode; - NlmOpNode * node; NlmOp (const ENlmOp & op) : opcode(op) { } @@ -114,12 +113,6 @@ struct NlmLeaveAgeOp : NlmOp { { } }; -struct NlmOpNode { - LINK(NlmOpNode) link; - NlmOp * op; - ~NlmOpNode () { delete op; } -}; - /***************************************************************************** * @@ -129,7 +122,7 @@ struct NlmOpNode { static plNCAgeJoiner * s_ageJoiner; static plNCAgeLeaver * s_ageLeaver; -static LISTDECL(NlmOpNode, link) s_oplist; +static std::list s_opqueue; /***************************************************************************** @@ -140,10 +133,11 @@ static LISTDECL(NlmOpNode, link) s_oplist; //============================================================================ static void QueueOp (NlmOp * op, bool front = false) { - NlmOpNode * node = NEWZERO(NlmOpNode); - node->op = op; - op->node = node; - s_oplist.Link(node, front ? kListHead : kListTail); + if (front) { + s_opqueue.push_front(op); + } else { + s_opqueue.push_back(op); + } } @@ -186,8 +180,10 @@ void plNetLinkingMgr::NCAgeJoinerCallback ( lm->SetEnabled(true); // Pull our wait op off exec queue - if (NlmOpWaitOp * waitOp = (NlmOpWaitOp *) userState) - delete waitOp->node; + if (NlmOpWaitOp * waitOp = (NlmOpWaitOp *) userState) { + s_opqueue.remove(waitOp); + delete waitOp; + } } break; @@ -208,8 +204,10 @@ void plNetLinkingMgr::NCAgeLeaverCallback ( s_ageLeaver = nil; // Pull our wait op off exec queue - if (NlmOpWaitOp * waitOp = (NlmOpWaitOp *) userState) - delete waitOp->node; + if (NlmOpWaitOp * waitOp = (NlmOpWaitOp *) userState) { + s_opqueue.remove(waitOp); + delete waitOp; + } } break; @@ -221,28 +219,27 @@ void plNetLinkingMgr::NCAgeLeaverCallback ( void plNetLinkingMgr::ExecNextOp () { plNetLinkingMgr * lm = plNetLinkingMgr::GetInstance(); - NlmOpNode * opNode = s_oplist.Head(); - if (!opNode) + if (!s_opqueue.size()) return; - - switch (opNode->op->opcode) { - case kNlmOpNoOp: { - } - break; - - case kNlmOpWaitOp: { - } - return; // don't allow wait op to be unlinked/deleted from list - + + NlmOp* op = s_opqueue.front(); + + switch (op->opcode) { + case kNlmOpNoOp: + break; + + case kNlmOpWaitOp: + return; // don't allow wait op to be unlinked/deleted from list + case kNlmOpJoinAgeOp: { ASSERT(!s_ageJoiner); ASSERT(!s_ageLeaver); - + // Insert a wait operation into the exec queue NlmOpWaitOp * waitOp = NEWZERO(NlmOpWaitOp); QueueOp(waitOp, true); - - NlmJoinAgeOp * joinAgeOp = (NlmJoinAgeOp *) opNode->op; + + NlmJoinAgeOp * joinAgeOp = (NlmJoinAgeOp *)op; NCAgeJoinerCreate( &s_ageJoiner, joinAgeOp->age, @@ -251,7 +248,7 @@ void plNetLinkingMgr::ExecNextOp () { ); } break; - + case kNlmOpLeaveAgeOp: { ASSERT(!s_ageJoiner); ASSERT(!s_ageLeaver); @@ -263,7 +260,7 @@ void plNetLinkingMgr::ExecNextOp () { lm->SetEnabled(false); lm->fLinkedIn = false; - NlmLeaveAgeOp * leaveAgeOp = (NlmLeaveAgeOp *) opNode->op; + NlmLeaveAgeOp * leaveAgeOp = (NlmLeaveAgeOp *)op; NCAgeLeaverCreate( &s_ageLeaver, leaveAgeOp->quitting, @@ -273,8 +270,9 @@ void plNetLinkingMgr::ExecNextOp () { } break; } - - delete opNode; + + s_opqueue.pop_front(); + delete op; } From 270e05738fac0c22ac2e46289fe8e3445fc7398d Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 10 Mar 2012 22:19:34 -0800 Subject: [PATCH 18/37] Clean up pnSimpleNet. Removes Pch.h. Removes a pnUtList. Removes a PnUtHash (and all the weird warnings from it). --- .../NucleusLib/pnSimpleNet/CMakeLists.txt | 1 - Sources/Plasma/NucleusLib/pnSimpleNet/Pch.h | 54 ---- .../NucleusLib/pnSimpleNet/pnSimpleNet.cpp | 252 +++++++++--------- 3 files changed, 132 insertions(+), 175 deletions(-) delete mode 100644 Sources/Plasma/NucleusLib/pnSimpleNet/Pch.h diff --git a/Sources/Plasma/NucleusLib/pnSimpleNet/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnSimpleNet/CMakeLists.txt index 96491f39..77d60d72 100644 --- a/Sources/Plasma/NucleusLib/pnSimpleNet/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/pnSimpleNet/CMakeLists.txt @@ -2,7 +2,6 @@ include_directories("../../CoreLib") include_directories("../../NucleusLib") set(pnSimpleNet_HEADERS - Pch.h pnSimpleNet.h ) diff --git a/Sources/Plasma/NucleusLib/pnSimpleNet/Pch.h b/Sources/Plasma/NucleusLib/pnSimpleNet/Pch.h deleted file mode 100644 index 762562b8..00000000 --- a/Sources/Plasma/NucleusLib/pnSimpleNet/Pch.h +++ /dev/null @@ -1,54 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnSimpleNet/Pch.h -* -***/ - -#ifdef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNSIMPLENET_PCH_H -#error "Header $/Plasma20/Sources/Plasma/NucleusLib/pnSimpleNet/Pch.h included more than once" -#endif -#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNSIMPLENET_PCH_H - - -#include "pnSimpleNet.h" diff --git a/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp b/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp index 0743b003..be0986c9 100644 --- a/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp +++ b/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp @@ -45,9 +45,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com * ***/ -#include "Pch.h" -#pragma hdrstop +#include "pnSimpleNet.h" +#include "hsThread.h" +#include +#include /***************************************************************************** * @@ -56,35 +58,25 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com ***/ struct SimpleNetConn : AtomicRef { - LINK(SimpleNetConn) link; AsyncSocket sock; AsyncCancelId cancelId; - unsigned channelId; + uint32_t channelId; bool abandoned; struct ConnectParam * connectParam; SimpleNet_MsgHeader * oversizeMsg; - ARRAY(uint8_t) oversizeBuffer; - - ~SimpleNetConn () { - ASSERT(!link.IsLinked()); - } + ARRAY(uint8_t) oversizeBuffer; }; -struct SimpleNetChannel : AtomicRef, THashKeyVal { - HASHLINK(SimpleNetChannel) link; - +struct SimpleNetChannel : AtomicRef { FSimpleNetOnMsg onMsg; FSimpleNetOnError onError; - - LISTDECL(SimpleNetConn, link) conns; + uint32_t channelId; + std::list conns; - SimpleNetChannel (unsigned channel) - : THashKeyVal(channel) - { } + SimpleNetChannel (uint32_t channel) : channelId(channel) { } ~SimpleNetChannel () { - ASSERT(!link.IsLinked()); - ASSERT(!conns.Head()); + ASSERT(!conns.size()); } }; @@ -92,7 +84,7 @@ struct ConnectParam { SimpleNetChannel * channel; FSimpleNetOnConnect callback; void * param; - + ~ConnectParam () { if (channel) channel->DecRef(); @@ -107,15 +99,10 @@ struct ConnectParam { ***/ static bool s_running; -static CCritSect s_critsect; +static hsMutex s_critsect; static FSimpleNetQueryAccept s_queryAccept; static void * s_queryAcceptParam; - -static HASHTABLEDECL( - SimpleNetChannel, - THashKeyVal, - link -) s_channels; +static std::map s_channels; /***************************************************************************** @@ -128,13 +115,13 @@ static HASHTABLEDECL( static void NotifyConnSocketConnect (SimpleNetConn * conn) { conn->TransferRef("Connecting", "Connected"); - + conn->connectParam->callback( conn->connectParam->param, conn, kNetSuccess ); - + delete conn->connectParam; conn->connectParam = nil; } @@ -142,18 +129,21 @@ static void NotifyConnSocketConnect (SimpleNetConn * conn) { //============================================================================ static void NotifyConnSocketConnectFailed (SimpleNetConn * conn) { - s_critsect.Enter(); + s_critsect.Lock(); { - conn->link.Unlink(); + std::map::iterator it; + if ((it = s_channels.find(conn->channelId)) != s_channels.end()) { + it->second->conns.remove(conn); + } } - s_critsect.Leave(); + s_critsect.Unlock(); conn->connectParam->callback( conn->connectParam->param, nil, kNetErrConnectFailed ); - + delete conn->connectParam; conn->connectParam = nil; @@ -165,38 +155,44 @@ static void NotifyConnSocketConnectFailed (SimpleNetConn * conn) { static void NotifyConnSocketDisconnect (SimpleNetConn * conn) { bool abandoned; - SimpleNetChannel * channel; - s_critsect.Enter(); + SimpleNetChannel* channel = nil; + s_critsect.Lock(); { abandoned = conn->abandoned; - if (nil != (channel = s_channels.Find(conn->channelId))) + std::map::iterator it; + if ((it = s_channels.find(conn->channelId)) != s_channels.end()) { + channel = it->second; channel->IncRef(); - conn->link.Unlink(); + channel->conns.remove(conn); + } } - s_critsect.Leave(); - + s_critsect.Unlock(); + if (channel && !abandoned) { channel->onError(conn, kNetErrDisconnected); channel->DecRef(); } - + conn->DecRef("Connected"); } //============================================================================ static bool NotifyConnSocketRead (SimpleNetConn * conn, AsyncNotifySocketRead * read) { - SimpleNetChannel * channel; - s_critsect.Enter(); + SimpleNetChannel* channel = nil; + s_critsect.Lock(); { - if (nil != (channel = s_channels.Find(conn->channelId))) + std::map::iterator it; + if ((it = s_channels.find(conn->channelId)) != s_channels.end()) { + channel = it->second; channel->IncRef(); + } } - s_critsect.Leave(); - + s_critsect.Unlock(); + if (!channel) return false; - + bool result = true; const uint8_t * curr = read->buffer; @@ -208,19 +204,19 @@ static bool NotifyConnSocketRead (SimpleNetConn * conn, AsyncNotifySocketRead * unsigned spaceLeft = conn->oversizeMsg->messageBytes - conn->oversizeBuffer.Count(); unsigned copyBytes = min(spaceLeft, term - curr); conn->oversizeBuffer.Add(curr, copyBytes); - + curr += copyBytes; // Wait until we have received the entire message if (copyBytes != spaceLeft) break; - + // Dispatch oversize msg if (!channel->onMsg(conn, conn->oversizeMsg)) { result = false; break; } - + conn->oversizeBuffer.SetCount(0); continue; } @@ -231,23 +227,23 @@ static bool NotifyConnSocketRead (SimpleNetConn * conn, AsyncNotifySocketRead * SimpleNet_MsgHeader * msg = (SimpleNet_MsgHeader *) read->buffer; - // Sanity check message size + // Sanity check message size if (msg->messageBytes < sizeof(*msg)) { result = false; break; } - + // Handle oversized messages if (msg->messageBytes > kAsyncSocketBufferSize) { - + conn->oversizeBuffer.SetCount(msg->messageBytes); conn->oversizeMsg = (SimpleNet_MsgHeader *) conn->oversizeBuffer.Ptr(); - *conn->oversizeMsg = *msg; - + *conn->oversizeMsg = *msg; + curr += sizeof(*msg); continue; } - + // Wait until we have received the entire message const uint8_t * msgTerm = (const uint8_t *) curr + msg->messageBytes; if (msgTerm > term) @@ -263,7 +259,7 @@ static bool NotifyConnSocketRead (SimpleNetConn * conn, AsyncNotifySocketRead * // Return count of bytes we processed read->bytesProcessed = curr - read->buffer; - + channel->DecRef(); return result; } @@ -286,59 +282,62 @@ static bool AsyncNotifySocketProc ( const SimpleNet_ConnData & connect = *(const SimpleNet_ConnData *) listen->buffer; listen->bytesProcessed += sizeof(connect); - SimpleNetChannel * channel; - s_critsect.Enter(); + SimpleNetChannel* channel = nil; + s_critsect.Lock(); { - if (nil != (channel = s_channels.Find(connect.channelId))) + std::map::iterator it; + if ((it = s_channels.find(conn->channelId)) != s_channels.end()) { + channel = it->second; channel->IncRef(); + } } - s_critsect.Leave(); - + s_critsect.Unlock(); + if (!channel) break; - + conn = NEWZERO(SimpleNetConn); - conn->channelId = channel->GetValue(); + conn->channelId = channel->channelId; conn->IncRef("Lifetime"); conn->IncRef("Connected"); conn->sock = sock; *userState = conn; - + bool accepted = s_queryAccept( s_queryAcceptParam, - channel->GetValue(), + channel->channelId, conn, listen->remoteAddr ); - + if (!accepted) { SimpleNetDisconnect(conn); } else { - s_critsect.Enter(); + s_critsect.Lock(); { - channel->conns.Link(conn); + channel->conns.push_back(conn); } - s_critsect.Leave(); + s_critsect.Unlock(); } - + channel->DecRef(); } break; - + case kNotifySocketConnectSuccess: { conn = (SimpleNetConn *) notify->param; *userState = conn; bool abandoned; - - s_critsect.Enter(); + + s_critsect.Lock(); { conn->sock = sock; conn->cancelId = 0; abandoned = conn->abandoned; } - s_critsect.Leave(); - + s_critsect.Unlock(); + if (abandoned) AsyncSocketDisconnect(sock, true); else @@ -349,17 +348,20 @@ static bool AsyncNotifySocketProc ( case kNotifySocketConnectFailed: conn = (SimpleNetConn *) notify->param; NotifyConnSocketConnectFailed(conn); - break; + break; case kNotifySocketDisconnect: conn = (SimpleNetConn *) *userState; NotifyConnSocketDisconnect(conn); - break; + break; case kNotifySocketRead: conn = (SimpleNetConn *) *userState; result = NotifyConnSocketRead(conn, (AsyncNotifySocketRead *) notify); - break; + break; + + default: + break; } return result; @@ -369,15 +371,15 @@ static bool AsyncNotifySocketProc ( static void Connect (const NetAddress & addr, ConnectParam * cp) { SimpleNetConn * conn = NEWZERO(SimpleNetConn); - conn->channelId = cp->channel->GetValue(); + conn->channelId = cp->channel->channelId; conn->connectParam = cp; conn->IncRef("Lifetime"); conn->IncRef("Connecting"); - s_critsect.Enter(); + s_critsect.Lock(); { - cp->channel->conns.Link(conn); - + cp->channel->conns.push_back(conn); + SimpleNet_Connect connect; connect.hdr.connType = kConnTypeSimpleNet; connect.hdr.hdrBytes = sizeof(connect.hdr); @@ -385,8 +387,8 @@ static void Connect (const NetAddress & addr, ConnectParam * cp) { connect.hdr.buildType = BUILD_TYPE_LIVE; connect.hdr.branchId = BranchId(); connect.hdr.productId = ProductId(); - connect.data.channelId = cp->channel->GetValue(); - + connect.data.channelId = cp->channel->channelId; + AsyncSocketConnect( &conn->cancelId, addr, @@ -395,12 +397,12 @@ static void Connect (const NetAddress & addr, ConnectParam * cp) { &connect, sizeof(connect) ); - - conn = nil; + + conn = nil; cp = nil; } - s_critsect.Leave(); - + s_critsect.Unlock(); + delete conn; delete cp; } @@ -447,8 +449,8 @@ void SimpleNetShutdown () { s_running = false; - ASSERT(!s_channels.Head()); - + ASSERT(!s_channels.size()); + AsyncSocketUnregisterNotifyProc( kConnTypeSimpleNet, AsyncNotifySocketProc @@ -460,7 +462,7 @@ void SimpleNetConnIncRef (SimpleNetConn * conn) { ASSERT(s_running); ASSERT(conn); - + conn->IncRef(); } @@ -469,7 +471,7 @@ void SimpleNetConnDecRef (SimpleNetConn * conn) { ASSERT(s_running); ASSERT(conn); - + conn->DecRef(); } @@ -481,10 +483,10 @@ bool SimpleNetStartListening ( ASSERT(s_running); ASSERT(queryAccept); ASSERT(!s_queryAccept); - + s_queryAccept = queryAccept; s_queryAcceptParam = param; - + NetAddress addr; NetAddressFromNode(0, kNetDefaultSimpleNetPort, &addr); return (0 != AsyncSocketStartListening(addr, nil)); @@ -514,22 +516,22 @@ void SimpleNetCreateChannel ( SimpleNetChannel * channel = NEWZERO(SimpleNetChannel)(channelId); channel->IncRef(); - s_critsect.Enter(); + s_critsect.Lock(); { #ifdef HS_DEBUGGING { - SimpleNetChannel * existing = s_channels.Find(channelId); - ASSERT(!existing); + std::map::iterator it = s_channels.find(channelId); + ASSERT(it == s_channels.end()); } #endif - + channel->onMsg = onMsg; channel->onError = onError; - s_channels.Add(channel); + s_channels[channelId] = channel; channel->IncRef(); } - s_critsect.Leave(); - + s_critsect.Unlock(); + channel->DecRef(); } @@ -539,20 +541,26 @@ void SimpleNetDestroyChannel (unsigned channelId) { ASSERT(s_running); SimpleNetChannel * channel; - s_critsect.Enter(); + s_critsect.Lock(); { - if (nil != (channel = s_channels.Find(channelId))) { - s_channels.Unlink(channel); - while (SimpleNetConn * conn = channel->conns.Head()) { + std::map::iterator it; + if ((it = s_channels.find(channelId)) != s_channels.end()) { + channel = it->second; + + while (channel->conns.size()) { + SimpleNetConn* conn = channel->conns.front(); SimpleNetDisconnect(conn); - channel->conns.Unlink(conn); + + channel->conns.pop_front(); } + + s_channels.erase(it); } } - s_critsect.Leave(); + s_critsect.Unlock(); if (channel) - channel->DecRef(); + channel->DecRef(); } //============================================================================ @@ -564,18 +572,22 @@ void SimpleNetStartConnecting ( ) { ASSERT(s_running); ASSERT(onConnect); - + ConnectParam * cp = new ConnectParam; cp->callback = onConnect; cp->param = param; - - s_critsect.Enter(); + cp->channel = nil; + + s_critsect.Lock(); { - if (nil != (cp->channel = s_channels.Find(channelId))) + std::map::iterator it; + if ((it = s_channels.find(channelId)) != s_channels.end()) { + cp->channel = it->second; cp->channel->IncRef(); + } } - s_critsect.Leave(); - + s_critsect.Unlock(); + ASSERT(cp->channel); // Do we need to lookup the address? @@ -608,8 +620,8 @@ void SimpleNetDisconnect ( ) { ASSERT(s_running); ASSERT(conn); - - s_critsect.Enter(); + + s_critsect.Lock(); { conn->abandoned = true; if (conn->sock) { @@ -621,7 +633,7 @@ void SimpleNetDisconnect ( conn->cancelId = nil; } } - s_critsect.Leave(); + s_critsect.Unlock(); conn->DecRef("Lifetime"); } @@ -635,11 +647,11 @@ void SimpleNetSend ( ASSERT(msg); ASSERT(msg->messageBytes != (uint32_t)-1); ASSERT(conn); - - s_critsect.Enter(); + + s_critsect.Lock(); { if (conn->sock) AsyncSocketSend(conn->sock, msg, msg->messageBytes); } - s_critsect.Leave(); + s_critsect.Unlock(); } From 87f050b55ef23ed979cd6f510e4a53e3831a39db Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 11 Mar 2012 00:02:20 -0800 Subject: [PATCH 19/37] Get rid of one hashtable in pfGameMgr. --- Sources/Plasma/FeatureLib/pfGameMgr/Intern.h | 6 +-- .../Plasma/FeatureLib/pfGameMgr/pfGameMgr.cpp | 54 ++++++++++--------- .../Plasma/FeatureLib/pfGameMgr/pfGameMgr.h | 12 ++--- 3 files changed, 38 insertions(+), 34 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfGameMgr/Intern.h b/Sources/Plasma/FeatureLib/pfGameMgr/Intern.h index d154dd2a..5a8f7a3e 100644 --- a/Sources/Plasma/FeatureLib/pfGameMgr/Intern.h +++ b/Sources/Plasma/FeatureLib/pfGameMgr/Intern.h @@ -64,9 +64,9 @@ typedef pfGameCli * (*FGameCliFactory)( ); struct GameTypeReg { - FGameCliFactory create; - Uuid typeId; - const wchar_t * name; + FGameCliFactory create; + plUUID typeId; + const wchar_t* name; }; void GameMgrRegisterGameType (const GameTypeReg & reg); diff --git a/Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.cpp b/Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.cpp index 27bf67d2..a4a7bfb1 100644 --- a/Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.cpp +++ b/Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.cpp @@ -58,10 +58,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com //============================================================================ // pfGameCli factory //============================================================================ -struct Factory : THashKeyVal { - - HASHLINK(Factory) link; - const GameTypeReg & reg; +struct Factory +{ + const GameTypeReg& reg; Factory (const GameTypeReg & reg); Factory& operator= (const Factory &); // not impl @@ -113,7 +112,7 @@ struct JoinTransState { //============================================================================ struct IGameMgr { - pfGameCli * CreateGameCli (const Uuid & gameTypeId, unsigned gameId, plKey receiver); + pfGameCli * CreateGameCli (const plUUID& gameTypeId, unsigned gameId, plKey receiver); void Recv (GameMsgHeader * msg); void RecvGameInstance (const Srv2Cli_GameMgr_GameInstance & msg, void * param); @@ -132,7 +131,7 @@ struct IGameMgr { static HASHTABLEDECL(TransState, THashKeyVal, link) s_trans; static HASHTABLEDECL(IGameCli, THashKeyVal, link) s_games; -static HASHTABLEDECL(Factory, THashKeyVal, link) s_factories; +static std::map s_factories; static long s_transId; static ARRAYOBJ(plKey) s_receivers; @@ -145,10 +144,14 @@ static ARRAYOBJ(plKey) s_receivers; ***/ //============================================================================ -static void ShutdownFactories () { - - while (Factory * factory = s_factories.Head()) +static void ShutdownFactories() +{ + std::map::iterator it; + for (it = s_factories.begin(); it != s_factories.end(); ++it) { + Factory* factory = it->second; delete factory; + } + s_factories.clear(); } //============================================================================ @@ -175,14 +178,15 @@ static inline unsigned INextTransId () { ***/ //============================================================================ -pfGameCli * IGameMgr::CreateGameCli (const Uuid & gameTypeId, unsigned gameId, plKey receiver) { - - if (Factory * factory = s_factories.Find(gameTypeId)) { - pfGameCli * gameCli = factory->reg.create(gameId, receiver); - gameCli->internal->factory = factory; +pfGameCli* IGameMgr::CreateGameCli(const plUUID& gameTypeId, unsigned gameId, plKey receiver) +{ + std::map::iterator it; + if ((it = s_factories.find(gameTypeId)) != s_factories.end()) { + pfGameCli* gameCli = it->second->reg.create(gameId, receiver); + gameCli->internal->factory = it->second; return gameCli; } - + return nil; } @@ -351,10 +355,12 @@ pfGameCli * pfGameMgr::GetGameCli (unsigned gameId) const { } //============================================================================ -const wchar_t * pfGameMgr::GetGameNameByTypeId (const Uuid & gameTypeId) const { - - if (Factory * factory = s_factories.Find(gameTypeId)) - return factory->reg.name; +const wchar_t* pfGameMgr::GetGameNameByTypeId(const plUUID& gameTypeId) const +{ + std::map::iterator it; + if ((it = s_factories.find(gameTypeId)) != s_factories.end()) { + return it->second->reg.name; + } return nil; } @@ -489,9 +495,9 @@ unsigned pfGameCli::GetGameId () const { } //============================================================================ -const Uuid & pfGameCli::GetGameTypeId () const { +const plUUID& pfGameCli::GetGameTypeId () const { - return internal->factory->GetValue(); + return internal->factory->reg.typeId; } //============================================================================ @@ -615,11 +621,9 @@ void IGameCli::RecvOwnerChange (const Srv2Cli_Game_OwnerChange & msg, void * par ***/ //============================================================================ -Factory::Factory (const GameTypeReg & reg) -: reg(reg) -, THashKeyVal(reg.typeId) +Factory::Factory(const GameTypeReg& reg) : reg(reg) { - s_factories.Add(this); + s_factories[reg.typeId] = this; } diff --git a/Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.h b/Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.h index c6a996c2..5f93ace7 100644 --- a/Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.h +++ b/Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.h @@ -156,7 +156,7 @@ public: // Return interface to the specified game pfGameCli * GetGameCli (unsigned gameId) const; // Get the name of a game by its typeid - const wchar_t * GetGameNameByTypeId (const Uuid & gameTypeId) const; + const wchar_t* GetGameNameByTypeId (const plUUID& gameTypeId) const; //======================================================================== //======================================================================== @@ -226,11 +226,11 @@ public: //======================================================================== // Game client properties //----------------------- - unsigned GetGameId () const; - const Uuid & GetGameTypeId () const; - const wchar_t * GetName () const; - plKey GetReceiver () const; - unsigned GetPlayerCount () const; + unsigned GetGameId () const; + const plUUID& GetGameTypeId () const; + const wchar_t* GetName () const; + plKey GetReceiver () const; + unsigned GetPlayerCount () const; //======================================================================== //======================================================================== From b8e4f00ad6ca1a0a9726158677d94b64ed117816 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 11 Mar 2012 00:02:40 -0800 Subject: [PATCH 20/37] Remove more unused pnUtils code. --- Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h | 34 -------------- Sources/Plasma/NucleusLib/pnUtils/pnUtPriQ.h | 48 -------------------- Sources/Plasma/NucleusLib/pnUtils/pnUtSort.h | 46 ------------------- 3 files changed, 128 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h index c01b30cc..e734697d 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtHash.h @@ -62,24 +62,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // Define a field inside an object that is used to link it into a hash table #define HASHLINK(object) THashLink< object > -// Define a POINTER to a hash table, not a hash table -#define HASHTABLE(object,key) THashTable< object, key > - // Define a hash table: // - starts with kSlotMinCount rows // - can grow to kDefaultSlotMaxCount rows // (hash table grows when a row contains more than kGrowOnListSize entries #define HASHTABLEDECL(object,key,link) THashTableDecl< object, key, offsetof(object,link), 0 > -// Define a hash table in situations when a forward reference prevents use of HASHTABLEDECL -// - Size characteristics are identical to HASHTABLEDECL -#define HASHTABLEDYN(object,key) THashTableDyn< object, key > - -// Define a hash table with: -// - starts with -// - row table never grows -#define HASHTABLEDECLSIZE(object,key,link,size) THashTableDecl - #if defined(_MSC_VER) #define forceinline __forceinline @@ -595,28 +583,6 @@ THashTableDecl::THashTableDecl () { } -/**************************************************************************** -* -* THashTableDyn -* -***/ - -template -class THashTableDyn : public THashTable { - -public: - void Initialize (int linkOffset, unsigned maxSize = 0); - -}; - -//=========================================================================== -template -void THashTableDyn::Initialize (int linkOffset, unsigned maxSize) { - this->SetLinkOffset(linkOffset, maxSize); - this->SetSlotMaxCount(maxSize); -} - - /**************************************************************************** * * THashKeyVal diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtPriQ.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtPriQ.h index 862970bd..3ca71606 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtPriQ.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtPriQ.h @@ -57,11 +57,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com ***/ #define PRIORITY_TIME(class) TPriorityTime< class > -#define PRIORITY_NUMERIC(class,type) TPriorityNumeric< class,type > #define PRIQ(class,priority) TPriorityQueue< class,priority > #define PRIQDECL(class,priority,field) TPriorityQueueDecl< class,priority,offsetof(class,field) > -#define PRIQDYN(class,priority) TPriorityQueueDyn< class,priority > /**************************************************************************** @@ -351,19 +349,6 @@ public: }; -/**************************************************************************** -* -* TPriorityQueueDyn -* -***/ - -template -class TPriorityQueueDyn : public TPriorityQueue { -public: - void Initialize (int linkOffset) { this->SetLinkOffset(linkOffset); } -}; - - /**************************************************************************** * * class TBasePriority @@ -419,39 +404,6 @@ void TBasePriority::Relink () { queue->Enqueue(object); } - -/**************************************************************************** -* -* class TPriorityNumeric -* -***/ - -template -class TPriorityNumeric : public TBasePriority< C, TPriorityNumeric > { - -public: - TPriorityNumeric () : m_value(0) { } - TPriorityNumeric (T value) : m_value(value) { } - void Set (T value) { - if (value == m_value) - return; - m_value = value; - this->Relink(); - } - T Get () const { - return m_value; - } - bool IsPriorityHigher (const TPriorityNumeric & source) { - return m_value > source.m_value; - } - bool IsPriorityHigher (T value) const { - return m_value > value; - } - -private: - T m_value; -}; - /**************************************************************************** * * class TPriorityTime diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtSort.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtSort.h index bd1752ec..dd20e76c 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtSort.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtSort.h @@ -191,50 +191,4 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com } \ } \ } - - -/**************************************************************************** -* -* BSEARCH -* -* This macro binary searches a sorted array to find an existing entry or -* the position where a new entry should be placed. It returns the index of -* the first entry for which the expression is false (zero or negative), or -* count if the expression is true (positive) for all entries. -* -* Typically the expression will return: -* > 0 if (sortKey > elem) -* <= 0 if (sortKey <= elem) -* -* The final parameter to the macro is the address of a variable which is -* filled with the resulting index. -* -***/ - -//=========================================================================== -#define BSEARCH(T, ptr, count, expr, addrOfIndex) { \ - \ - const T * low = (ptr); \ - const T * high = (ptr) + (count); /* first entry for which */ \ - /* expr is false */ \ - \ - if (low != high) \ - for (;;) { \ - const T & elem = *(low + (high - low) / 2); \ - int result = (expr); \ - if (result > 0) { \ - if (&elem == low) \ - break; \ - low = &elem; \ - } \ - else { \ - high = &elem; \ - if (&elem == low) \ - break; \ - } \ - } \ - \ - *(addrOfIndex) = high - (ptr); \ - \ -} #endif From 9479aadb3a962aad0fb274aa5e8fdd4097d97807 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 11 Mar 2012 20:04:10 -0700 Subject: [PATCH 21/37] Move pnUtBigNum to pnEncryption/plBigNum. --- .../NucleusLib/pnEncryption/CMakeLists.txt | 2 + .../plBigNum.cpp} | 57 ++++------- .../pnUtBigNum.h => pnEncryption/plBigNum.h} | 95 +++++++++---------- .../pnEncryption/plChallengeHash.cpp | 1 - Sources/Plasma/NucleusLib/pnNetCli/Intern.h | 18 ++-- Sources/Plasma/NucleusLib/pnNetCli/Pch.h | 1 + .../NucleusLib/pnNetCli/pnNcChannel.cpp | 12 +-- .../Plasma/NucleusLib/pnNetCli/pnNcCli.cpp | 8 +- .../NucleusLib/pnNetCli/pnNcEncrypt.cpp | 54 +++++------ Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h | 4 +- .../Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp | 4 +- .../Plasma/NucleusLib/pnUtils/CMakeLists.txt | 2 - .../NucleusLib/pnUtils/pnUtAllIncludes.h | 1 - Sources/Plasma/PubUtilLib/plNetGameLib/Pch.h | 1 + .../plNetGameLib/Private/plNglAuth.cpp | 4 +- .../plNetGameLib/Private/plNglCsr.cpp | 4 +- .../plNetGameLib/Private/plNglGame.cpp | 4 +- .../plNetGameLib/Private/plNglGateKeeper.cpp | 4 +- 18 files changed, 129 insertions(+), 147 deletions(-) rename Sources/Plasma/NucleusLib/{pnUtils/pnUtBigNum.cpp => pnEncryption/plBigNum.cpp} (63%) rename Sources/Plasma/NucleusLib/{pnUtils/pnUtBigNum.h => pnEncryption/plBigNum.h} (68%) diff --git a/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt index 349b3d42..0707beb5 100644 --- a/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt @@ -3,11 +3,13 @@ include_directories("../../NucleusLib") include_directories(${OPENSSL_INCLUDE_DIR}) set(pnEncryption_SOURCES + plBigNum.cpp plChallengeHash.cpp plChecksum.cpp ) set(pnEncryption_HEADERS + plBigNum.h plChallengeHash.h plChecksum.h plRandom.h diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtBigNum.cpp b/Sources/Plasma/NucleusLib/pnEncryption/plBigNum.cpp similarity index 63% rename from Sources/Plasma/NucleusLib/pnUtils/pnUtBigNum.cpp rename to Sources/Plasma/NucleusLib/pnEncryption/plBigNum.cpp index 1537c322..3bd26c09 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtBigNum.cpp +++ b/Sources/Plasma/NucleusLib/pnEncryption/plBigNum.cpp @@ -39,18 +39,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com Mead, WA 99021 *==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtBigNum.cpp -* -***/ - -#include "pnUtBigNum.h" +#include "plBigNum.h" #include #include -static inline void byteswap(size_t size, unsigned char * data) +static inline void byteswap(size_t size, uint8_t* data) { for (size_t i = 0; i < (size / 2); ++i) std::swap(data[i], data[size - i - 1]); @@ -58,32 +52,28 @@ static inline void byteswap(size_t size, unsigned char * data) /**************************************************************************** * -* BigNum public methods +* plBigNum public methods * ***/ -//=========================================================================== -BigNum::BigNum () : m_context(nil) +plBigNum::plBigNum () : m_context(nil) { BN_init(&m_number); } -//=========================================================================== -BigNum::BigNum (const BigNum & a) : m_context(nil) +plBigNum::plBigNum(const plBigNum& a) : m_context(nil) { BN_init(&m_number); BN_copy(&m_number, &a.m_number); } -//=========================================================================== -BigNum::BigNum (unsigned a) : m_context(nil) +plBigNum::plBigNum(unsigned a) : m_context(nil) { BN_init(&m_number); BN_set_word(&m_number, a); } -//=========================================================================== -BigNum::BigNum (unsigned bytes, const void * data, bool le) : m_context(nil) +plBigNum::plBigNum(unsigned bytes, const void* data, bool le) : m_context(nil) { BN_init(&m_number); if (le) @@ -92,16 +82,15 @@ BigNum::BigNum (unsigned bytes, const void * data, bool le) : m_context(nil) FromData_BE(bytes, data); } -//=========================================================================== -BigNum::~BigNum () +plBigNum::~plBigNum () { if (m_context) BN_CTX_free(m_context); BN_free(&m_number); } -//=========================================================================== -int BigNum::Compare (uint32_t a) const { +int plBigNum::Compare(uint32_t a) const +{ // -1 if (this < a) // 0 if (this == a) // 1 if (this > a) @@ -118,43 +107,39 @@ int BigNum::Compare (uint32_t a) const { return 1; } -//=========================================================================== -void BigNum::FromData_LE (unsigned bytes, const void * data) +void plBigNum::FromData_LE(uint32_t bytes, const void* data) { - unsigned char * buffer = new unsigned char[bytes]; + uint8_t* buffer = new uint8_t[bytes]; memcpy(buffer, data, bytes); byteswap(bytes, buffer); BN_bin2bn(buffer, bytes, &m_number); - delete [] buffer; + delete[] buffer; } -//=========================================================================== -unsigned char * BigNum::GetData_BE (unsigned * bytes) const +uint8_t* plBigNum::GetData_BE(uint32_t* bytes) const { *bytes = BN_num_bytes(&m_number); - unsigned char * data = new unsigned char[*bytes]; + uint8_t* data = new uint8_t[*bytes]; BN_bn2bin(&m_number, data); return data; } -//=========================================================================== -unsigned char * BigNum::GetData_LE (unsigned * bytes) const +uint8_t* plBigNum::GetData_LE(uint32_t* bytes) const { *bytes = BN_num_bytes(&m_number); - unsigned char * data = new unsigned char[*bytes]; + uint8_t* data = new uint8_t[*bytes]; BN_bn2bin(&m_number, data); byteswap(*bytes, data); return data; } -//=========================================================================== -void BigNum::Rand (unsigned bits, BigNum * seed) +void plBigNum::Rand(uint32_t bits, plBigNum* seed) { // this = random number with bits or fewer bits - unsigned seedbytes; - unsigned char * seedData = seed->GetData_BE(&seedbytes); + uint32_t seedbytes; + uint8_t* seedData = seed->GetData_BE(&seedbytes); RAND_seed(seedData, seedbytes); BN_rand(&m_number, bits, 0, 0); - delete [] seedData; + delete[] seedData; } diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtBigNum.h b/Sources/Plasma/NucleusLib/pnEncryption/plBigNum.h similarity index 68% rename from Sources/Plasma/NucleusLib/pnUtils/pnUtBigNum.h rename to Sources/Plasma/NucleusLib/pnEncryption/plBigNum.h index c6e6f94d..f9315372 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtBigNum.h +++ b/Sources/Plasma/NucleusLib/pnEncryption/plBigNum.h @@ -39,31 +39,26 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com Mead, WA 99021 *==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtBigNum.h -* -***/ -#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTBIGNUM_H -#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTBIGNUM_H - -#include "Pch.h" +#ifndef plBigNum_inc +#define plBigNum_inc /***************************************************************************** * -* BigNum class +* plBigNum class * ***/ +#include "HeadSpin.h" #include -class BigNum { +class plBigNum +{ private: BIGNUM m_number; - mutable BN_CTX * m_context; + mutable BN_CTX* m_context; - BN_CTX * GetContext () const + BN_CTX* GetContext() const { if (!m_context) m_context = BN_CTX_new(); @@ -71,13 +66,13 @@ private: } public: - BigNum (); - BigNum (const BigNum & a); - BigNum (unsigned a); - BigNum (unsigned bytess, const void * data, bool le=false); - ~BigNum (); + plBigNum(); + plBigNum(const plBigNum& a); + plBigNum(uint32_t a); + plBigNum(uint32_t bytess, const void* data, bool le=false); + ~plBigNum(); - BigNum & operator= (const BigNum & a) + plBigNum& operator=(const plBigNum& a) { BN_copy(&m_number, &a.m_number); return *this; @@ -86,37 +81,39 @@ public: // Constant parameters need not be distinct from the destination or from // each other - void Add (const BigNum & a, uint32_t b) + void Add(const plBigNum& a, uint32_t b) { // this = a + b BN_copy(&m_number, &a.m_number); BN_add_word(&m_number, b); } - void Add (const BigNum & a, const BigNum & b) + void Add(const plBigNum& a, const plBigNum& b) { // this = a + b BN_add(&m_number, &a.m_number, &b.m_number); } - int Compare (uint32_t a) const; - int Compare (const BigNum & a) const + int Compare(uint32_t a) const; + + int Compare(const plBigNum& a) const { return BN_cmp(&m_number, &a.m_number); } + bool isZero() const { return BN_is_zero(&m_number); } - void Div (const BigNum & a, uint32_t b, uint32_t * remainder) + void Div(const plBigNum& a, uint32_t b, uint32_t* remainder) { // this = a / b, remainder = a % b BN_copy(&m_number, &a.m_number); *remainder = (uint32_t)BN_div_word(&m_number, b); } - void Div (const BigNum & a, const BigNum & b, BigNum * remainder) + void Div(const plBigNum& a, const plBigNum& b, plBigNum* remainder) { // this = a / b, remainder = a % b // either this or remainder may be nil @@ -124,55 +121,55 @@ public: &a.m_number, &b.m_number, GetContext()); } - void FromData_BE (unsigned bytess, const void * data) + void FromData_BE(uint32_t bytess, const void* data) { - BN_bin2bn((const unsigned char *)data, bytess, &m_number); + BN_bin2bn((const uint8_t*)data, bytess, &m_number); } - void FromData_LE (unsigned bytess, const void * data); + void FromData_LE(uint32_t bytess, const void* data); - unsigned char * GetData_BE (unsigned * bytess) const; - unsigned char * GetData_LE (unsigned * bytess) const; + uint8_t* GetData_BE(uint32_t* bytess) const; + uint8_t* GetData_LE(uint32_t* bytess) const; - bool IsPrime () const + bool IsPrime() const { // Cyan's code uses 3 checks, so we'll follow suit. // This provides an accurate answer to p < 0.015625 return BN_is_prime_fasttest(&m_number, 3, nil, GetContext(), nil, 1) > 0; } - void Mod (const BigNum & a, const BigNum & b) + void Mod(const plBigNum& a, const plBigNum& b) { // this = a % b BN_div(nil, &m_number, &a.m_number, &b.m_number, GetContext()); } - void Mul (const BigNum & a, uint32_t b) + void Mul(const plBigNum& a, uint32_t b) { // this = a * b BN_copy(&m_number, &a.m_number); BN_mul_word(&m_number, b); } - void Mul (const BigNum & a, const BigNum & b) + void Mul(const plBigNum& a, const plBigNum& b) { // this = a * b BN_mul(&m_number, &a.m_number, &b.m_number, GetContext()); } - void PowMod (uint32_t a, const BigNum & b, const BigNum & c) + void PowMod(uint32_t a, const plBigNum& b, const plBigNum& c) { // this = a ^ b % c - PowMod(BigNum(a), b, c); + PowMod(plBigNum(a), b, c); } - void PowMod (const BigNum & a, const BigNum & b, const BigNum & c) + void PowMod(const plBigNum& a, const plBigNum& b, const plBigNum& c) { // this = a ^ b % c BN_mod_exp(&m_number, &a.m_number, &b.m_number, &c.m_number, GetContext()); } - void Rand (const BigNum & a, BigNum * seed) + void Rand(const plBigNum& a, plBigNum* seed) { // this = random number less than a int bits = BN_num_bits(&a.m_number); @@ -181,49 +178,49 @@ public: while (Compare(a) >= 0); } - void Rand (unsigned bits, BigNum * seed); + void Rand(uint32_t bits, plBigNum* seed); - void RandPrime (unsigned bits, BigNum * seed) + void RandPrime(uint32_t bits, plBigNum* seed) { BN_generate_prime(&m_number, bits, 1, nil, nil, nil, nil); } - void Set (const BigNum & a) + void Set(const plBigNum& a) { BN_copy(&m_number, &a.m_number); } - void Set (unsigned a) + void Set(uint32_t a) { BN_set_word(&m_number, a); } - void SetOne () { Set(1); } - void SetZero () { Set(0); } + void SetOne() { Set(1); } + void SetZero() { Set(0); } - void Shl (const BigNum & a, unsigned b) + void Shl(const plBigNum& a, uint32_t b) { // this = a << b BN_lshift(&m_number, &a.m_number, b); } - void Shr (const BigNum & a, unsigned b) + void Shr(const plBigNum& a, uint32_t b) { // this = a >> b BN_rshift(&m_number, &a.m_number, b); } - void Sub (const BigNum & a, uint32_t b) + void Sub(const plBigNum& a, uint32_t b) { // this = a - b BN_copy(&m_number, &a.m_number); BN_sub_word(&m_number, b); } - void Sub (const BigNum & a, const BigNum & b) + void Sub(const plBigNum& a, const plBigNum& b) { // this = a - b BN_sub(&m_number, &a.m_number, &b.m_number); } }; -#endif +#endif // plBigNum_inc diff --git a/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp b/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp index 4c88fd4c..92e72e59 100644 --- a/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp +++ b/Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp @@ -41,7 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "plChallengeHash.h" -#include "pnUtils/pnUtils.h" ShaDigest fSeed; diff --git a/Sources/Plasma/NucleusLib/pnNetCli/Intern.h b/Sources/Plasma/NucleusLib/pnNetCli/Intern.h index d18855af..f3ccc206 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/Intern.h +++ b/Sources/Plasma/NucleusLib/pnNetCli/Intern.h @@ -80,8 +80,8 @@ const NetMsgInitSend * NetMsgChannelFindSendMessage ( void NetMsgChannelGetDhConstants ( const NetMsgChannel * channel, unsigned * dh_g, - const BigNum ** dh_xa, // client: dh_x server: dh_a - const BigNum ** dh_n + const plBigNum** dh_xa, // client: dh_x server: dh_a + const plBigNum** dh_n ); @@ -92,18 +92,18 @@ void NetMsgChannelGetDhConstants ( ***/ void NetMsgCryptClientStart ( - NetMsgChannel * channel, + NetMsgChannel* channel, unsigned seedBytes, - const uint8_t seedData[], - BigNum * clientSeed, - BigNum * serverSeed + const uint8_t seedData[], + plBigNum* clientSeed, + plBigNum* serverSeed ); void NetMsgCryptServerConnect ( - NetMsgChannel * channel, + NetMsgChannel* channel, unsigned seedBytes, - const uint8_t seedData[], - BigNum * clientSeed + const uint8_t seedData[], + plBigNum* clientSeed ); diff --git a/Sources/Plasma/NucleusLib/pnNetCli/Pch.h b/Sources/Plasma/NucleusLib/pnNetCli/Pch.h index 068f5604..704e6a6c 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/Pch.h +++ b/Sources/Plasma/NucleusLib/pnNetCli/Pch.h @@ -54,6 +54,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnUtils/pnUtils.h" #include "pnNetBase/pnNetBase.h" #include "pnAsyncCore/pnAsyncCore.h" +#include "pnEncryption/plBigNum.h" #include "pnNetCli.h" #include "Intern.h" diff --git a/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp b/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp index 94086105..78d246c8 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp @@ -83,8 +83,8 @@ struct NetMsgChannel : AtomicRef { // Diffie-Hellman constants uint32_t m_dh_g; - BigNum m_dh_xa; // client: dh_x server: dh_a - BigNum m_dh_n; + plBigNum m_dh_xa; // client: dh_x server: dh_a + plBigNum m_dh_n; }; static ChannelCrit s_channelCrit; @@ -355,8 +355,8 @@ const NetMsgInitSend * NetMsgChannelFindSendMessage ( void NetMsgChannelGetDhConstants ( const NetMsgChannel * channel, uint32_t * dh_g, - const BigNum ** dh_xa, - const BigNum ** dh_n + const plBigNum** dh_xa, + const plBigNum** dh_n ) { if (dh_g) *dh_g = channel->m_dh_g; if (dh_xa) *dh_xa = &channel->m_dh_xa; @@ -382,8 +382,8 @@ void NetMsgProtocolRegister ( const NetMsgInitRecv recvMsgs[], uint32_t recvMsgCount, uint32_t dh_g, - const BigNum & dh_xa, // client: dh_x server: dh_a - const BigNum & dh_n + const plBigNum& dh_xa, // client: dh_x server: dh_a + const plBigNum& dh_n ) { s_channelCrit.EnterSafe(); { diff --git a/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp b/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp index b8abb12c..d573a733 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp @@ -652,8 +652,8 @@ static void CreateSymmetricKey ( static void ClientConnect (NetCli * cli) { // Initiate diffie-hellman for client - BigNum clientSeed; - BigNum serverSeed; + plBigNum clientSeed; + plBigNum serverSeed; NetMsgCryptClientStart( cli->channel, sizeof(cli->seed), @@ -717,7 +717,7 @@ static bool ServerRecvConnect ( else { // Compute client seed uint8_t clientSeed[kNetMaxSymmetricSeedBytes]; - BigNum clientSeedValue; + plBigNum clientSeedValue; { NetMsgCryptServerConnect( cli->channel, @@ -761,7 +761,7 @@ static bool ClientRecvEncrypt ( return false; // find out if we want encryption - const BigNum * DH_N; + const plBigNum* DH_N; NetMsgChannelGetDhConstants(cli->channel, nil, nil, &DH_N); bool encrypt = !DH_N->isZero(); diff --git a/Sources/Plasma/NucleusLib/pnNetCli/pnNcEncrypt.cpp b/Sources/Plasma/NucleusLib/pnNetCli/pnNcEncrypt.cpp index 12daec21..95563877 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/pnNcEncrypt.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCli/pnNcEncrypt.cpp @@ -58,23 +58,23 @@ namespace pnNetCli { // g and n are pregenerated and published // (built into both client and server software) - BigNum g(4); - BigNum n; n.RandPrime(kKeyBits, &seed); + plBigNum g(4); + plBigNum n; n.RandPrime(kKeyBits, &seed); // a and x are pregenerated; a is built into server software, and x is // built into client software - BigNum a; a.Rand(kKeyBits, &seed); - BigNum x; x.PowMod(g, a, n); + plBigNum a; a.Rand(kKeyBits, &seed); + plBigNum x; x.PowMod(g, a, n); // client chooses b and y on connect, and sends y to the server - BigNum b; b.Rand(kKeyBits, &seed); - BigNum y; y.PowMod(g, b, n); + plBigNum b; b.Rand(kKeyBits, &seed); + plBigNum y; y.PowMod(g, b, n); // server computes key: k = y^a mod n - BigNum ka; ka.PowMod(y, a, n); + plBigNum ka; ka.PowMod(y, a, n); // client computes key: k = x^b mod n - BigNum kb; kb.PowMod(x, b, n); + plBigNum kb; kb.PowMod(x, b, n); ***/ @@ -90,14 +90,14 @@ COMPILER_ASSERT(IS_POW2(kNetDiffieHellmanKeyBits)); //============================================================================ // TODO: Cache computed keys static void GetCachedServerKey ( - NetMsgChannel * channel, - BigNum * ka, - const BigNum & dh_y + NetMsgChannel* channel, + plBigNum* ka, + const plBigNum& dh_y ) { // Get diffie-hellman constants - unsigned DH_G; - const BigNum * DH_A; - const BigNum * DH_N; + unsigned DH_G; + const plBigNum* DH_A; + const plBigNum* DH_N; NetMsgChannelGetDhConstants(channel, &DH_G, &DH_A, &DH_N); hsAssert(!DH_N->isZero(), "DH_N must not be zero in encrypted mode"); @@ -114,15 +114,15 @@ static void GetCachedServerKey ( //============================================================================ void NetMsgCryptClientStart ( - NetMsgChannel * channel, + NetMsgChannel* channel, unsigned seedBytes, - const uint8_t seedData[], - BigNum * clientSeed, - BigNum * serverSeed + const uint8_t seedData[], + plBigNum* clientSeed, + plBigNum* serverSeed ) { unsigned DH_G; - const BigNum * DH_X; - const BigNum * DH_N; + const plBigNum* DH_X; + const plBigNum* DH_N; NetMsgChannelGetDhConstants(channel, &DH_G, &DH_X, &DH_N); if (DH_N->isZero()) { // no actual encryption, but the caller expects a seed clientSeed->SetZero(); @@ -130,9 +130,9 @@ void NetMsgCryptClientStart ( } else { // Client chooses b and y on connect - BigNum g(DH_G); - BigNum seed(seedBytes, seedData); - BigNum b; b.Rand(kNetDiffieHellmanKeyBits, &seed); + plBigNum g(DH_G); + plBigNum seed(seedBytes, seedData); + plBigNum b; b.Rand(kNetDiffieHellmanKeyBits, &seed); // Client computes key: kb = x^b mod n clientSeed->PowMod(*DH_X, b, *DH_N); @@ -144,13 +144,13 @@ void NetMsgCryptClientStart ( //============================================================================ void NetMsgCryptServerConnect ( - NetMsgChannel * channel, + NetMsgChannel* channel, unsigned seedBytes, - const uint8_t seedData[], - BigNum * clientSeed + const uint8_t seedData[], + plBigNum* clientSeed ) { // Server computes client key: ka = y^a mod n - const BigNum dh_y(seedBytes, seedData); + const plBigNum dh_y(seedBytes, seedData); GetCachedServerKey(channel, clientSeed, dh_y); } diff --git a/Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h b/Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h index cc3ac7ba..c2efb7c4 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h +++ b/Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h @@ -326,8 +326,8 @@ void NetMsgProtocolRegister ( uint32_t recvMsgCount, // Diffie-Hellman keys uint32_t dh_g, - const BigNum & dh_xa, // client: dh_x server: dh_a - const BigNum & dh_n + const plBigNum& dh_xa, // client: dh_x server: dh_a + const plBigNum& dh_n ); void NetMsgProtocolDestroy ( diff --git a/Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp b/Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp index 6b240b50..2cdb9639 100644 --- a/Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp +++ b/Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp @@ -616,8 +616,8 @@ static void StartAuthTcpTest ( s_send, arrsize(s_send), s_recv, arrsize(s_recv), kAuthDhGValue, - BigNum(sizeof(kAuthDhXData), kAuthDhXData), - BigNum(sizeof(kAuthDhNData), kAuthDhNData) + plBigNum(sizeof(kAuthDhXData), kAuthDhXData), + plBigNum(sizeof(kAuthDhNData), kAuthDhNData) ); } diff --git a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt index 6ca4b931..deec6ded 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt @@ -8,7 +8,6 @@ set(pnUtils_HEADERS pnUtAddr.h pnUtAllIncludes.h pnUtArray.h - pnUtBigNum.h pnUtCmd.h pnUtCrypt.h pnUtHash.h @@ -27,7 +26,6 @@ set(pnUtils_HEADERS set(pnUtils_SOURCES pnUtArray.cpp - pnUtBigNum.cpp pnUtCmd.cpp pnUtCrypt.cpp pnUtHash.cpp diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h index 6c9a8bdb..b21a5e9c 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h @@ -63,7 +63,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnUtStr.h" #include "pnUtRef.h" #include "pnUtPath.h" -#include "pnUtBigNum.h" #include "pnUtCmd.h" #include "pnUtMisc.h" #include "pnUtCrypt.h" diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Pch.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Pch.h index ebe3eee8..a3bfe83a 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Pch.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Pch.h @@ -51,6 +51,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PCH_H #include "pnUtils/pnUtils.h" +#include "pnEncryption/plBigNum.h" #include "pnNetBase/pnNetBase.h" #include "pnAsyncCore/pnAsyncCore.h" #include "pnNetCli/pnNetCli.h" diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index fe7a5a5f..85ac4488 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -5032,8 +5032,8 @@ void AuthInitialize () { s_send, arrsize(s_send), s_recv, arrsize(s_recv), kAuthDhGValue, - BigNum(sizeof(kAuthDhXData), kAuthDhXData), - BigNum(sizeof(kAuthDhNData), kAuthDhNData) + plBigNum(sizeof(kAuthDhXData), kAuthDhXData), + plBigNum(sizeof(kAuthDhNData), kAuthDhNData) ); } diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp index 7c84e206..86353d9a 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp @@ -758,8 +758,8 @@ void CsrInitialize () { s_send, arrsize(s_send), s_recv, arrsize(s_recv), kCsrDhGValue, - BigNum(sizeof(kCsrDhXData), kCsrDhXData), - BigNum(sizeof(kCsrDhNData), kCsrDhNData) + plBigNum(sizeof(kCsrDhXData), kCsrDhXData), + plBigNum(sizeof(kCsrDhNData), kCsrDhNData) ); } diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp index 3ec789de..febaed0c 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp @@ -711,8 +711,8 @@ void GameInitialize () { s_send, arrsize(s_send), s_recv, arrsize(s_recv), kGameDhGValue, - BigNum(sizeof(kGameDhXData), kGameDhXData), - BigNum(sizeof(kGameDhNData), kGameDhNData) + plBigNum(sizeof(kGameDhXData), kGameDhXData), + plBigNum(sizeof(kGameDhNData), kGameDhNData) ); } diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp index ee49e7cc..5794b063 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp @@ -984,8 +984,8 @@ void GateKeeperInitialize () { s_send, arrsize(s_send), s_recv, arrsize(s_recv), kGateKeeperDhGValue, - BigNum(sizeof(kGateKeeperDhXData), kGateKeeperDhXData), - BigNum(sizeof(kGateKeeperDhNData), kGateKeeperDhNData) + plBigNum(sizeof(kGateKeeperDhXData), kGateKeeperDhXData), + plBigNum(sizeof(kGateKeeperDhNData), kGateKeeperDhNData) ); } From e70cb420f3aa6b3ee77fce1b7cc3dd6f1e93a977 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 11 Mar 2012 20:54:03 -0700 Subject: [PATCH 22/37] Update plNetAddress to use plString. --- .../NucleusLib/pnNetCommon/plNetAddress.cpp | 52 ++++++++----------- .../NucleusLib/pnNetCommon/plNetAddress.h | 28 ++++++---- .../NucleusLib/pnNetCommon/pnNetCommon.cpp | 16 +++--- .../NucleusLib/pnNetCommon/pnNetCommon.h | 7 +-- 4 files changed, 50 insertions(+), 53 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp index b2af6ac6..60a3c541 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp @@ -50,47 +50,41 @@ plNetAddress::plNetAddress() Clear(); } - -plNetAddress::plNetAddress(uint32_t addr, int port) +plNetAddress::plNetAddress(uint32_t addr, uint16_t port) { Clear(); SetHost(addr); SetPort(port); } - -plNetAddress::plNetAddress(const char * addr, int port) +plNetAddress::plNetAddress(const char * addr, uint16_t port) { Clear(); SetHost(addr); SetPort(port); } - bool plNetAddress::SetAnyAddr() -{ +{ fAddr.sin_family = AF_INET; fAddr.sin_addr.s_addr = INADDR_ANY; return true; } - bool plNetAddress::SetAnyPort() -{ +{ fAddr.sin_family = AF_INET; fAddr.sin_port = htons(0); return true; } - -bool plNetAddress::SetPort(int port) -{ +bool plNetAddress::SetPort(uint16_t port) +{ fAddr.sin_family = AF_INET; fAddr.sin_port = htons(port); return true; } - void plNetAddress::Clear() { memset(&fAddr,0,sizeof(fAddr)); @@ -98,16 +92,14 @@ void plNetAddress::Clear() fAddr.sin_addr.s_addr = INADDR_ANY; } - -int plNetAddress::GetPort() const +uint16_t plNetAddress::GetPort() const { return ntohs(fAddr.sin_port); } - -std::string plNetAddress::GetHostString() const +plString plNetAddress::GetHostString() const { - return std::string(pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr)); + return pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr); } uint32_t plNetAddress::GetHost() const @@ -115,37 +107,35 @@ uint32_t plNetAddress::GetHost() const return fAddr.sin_addr.s_addr; } - -std::string plNetAddress::GetHostWithPort() const +plString plNetAddress::GetHostWithPort() const { - static const int buf_len = 1024; - char buf[buf_len]; - sprintf(buf,"%s:%d",pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr),GetPort()); - return std::string(buf); + plStringStream ss; + ss << pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr) << ":" << GetPort(); + return ss.GetString(); } - -bool plNetAddress::SetHost(const char * hostname) +bool plNetAddress::SetHost(const char* hostname) { fAddr.sin_addr.s_addr = pnNetCommon::GetBinAddr(hostname); fAddr.sin_family = AF_INET; return true; } -bool plNetAddress::SetHost(uint32_t addr) +bool plNetAddress::SetHost(uint32_t addr) { memcpy(&fAddr.sin_addr, &addr,sizeof(addr)); fAddr.sin_family = AF_INET; return true; } -std::string plNetAddress::AsString() const +plString plNetAddress::AsString() const { - char buf[100] = ""; - sprintf(buf,"IP:%s:%d",pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr),GetPort()); - return std::string(buf); -} + plStringStream ss; + ss << "IP:" << pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr); + ss << ":" << GetPort(); + return ss.GetString(); +} void plNetAddress::Read(hsStream * s) { diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h index dda04dc5..e238b8b9 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h @@ -44,6 +44,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #ifndef plNetAddress_h_inc #define plNetAddress_h_inc +#include "HeadSpin.h" +#include "plString.h" #include "hsStlUtils.h" #include "hsStream.h" @@ -73,24 +75,28 @@ class plNetAddress public: plNetAddress(); - plNetAddress(uint32_t addr, int port); - plNetAddress(const char * addr, int port); + plNetAddress(uint32_t addr, uint16_t port); + plNetAddress(const char* addr, uint16_t port); virtual ~plNetAddress(){} void Clear(); + bool SetAnyAddr(); bool SetAnyPort(); - bool SetPort(int port); - bool SetHost(const char * hostname); - bool SetHost(uint32_t ip4addr); - int GetPort() const; - std::string GetHostString() const; + + uint16_t GetPort() const; + bool SetPort(uint16_t port); + uint32_t GetHost() const; - std::string GetHostWithPort() const; - const AddressType & GetAddressInfo() const { return fAddr; } - AddressType & GetAddressInfo() { return fAddr; } + bool SetHost(const char* hostname); + bool SetHost(uint32_t ip4addr); + + const AddressType& GetAddressInfo() const { return fAddr; } + AddressType& GetAddressInfo() { return fAddr; } - std::string AsString() const; + plString GetHostString() const; + plString GetHostWithPort() const; + plString AsString() const; void Read(hsStream * stream); void Write(hsStream * stream); diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.cpp b/Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.cpp index 2ca67cb1..566c6f35 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.cpp @@ -57,23 +57,23 @@ namespace pnNetCommon #ifndef SERVER // NOTE: On Win32, WSAStartup() must be called before GetTextAddr() will work. -const char * GetTextAddr(uint32_t binAddr) +plString GetTextAddr(uint32_t binAddr) { in_addr in; - memcpy(&in,&binAddr,sizeof(binAddr)); - return inet_ntoa(in); + memcpy(&in, &binAddr, sizeof(binAddr)); + return plString::Format("%s", inet_ntoa(in)); } // NOTE: On Win32, WSAStartup() must be called before GetBinAddr() will work. uint32_t GetBinAddr(const char * textAddr) { uint32_t addr = 0; - + if (!textAddr) return addr; - - struct addrinfo * ai = NULL; - + + struct addrinfo* ai = NULL; + addr = inet_addr(textAddr); if(addr == INADDR_NONE) { @@ -82,7 +82,7 @@ uint32_t GetBinAddr(const char * textAddr) memcpy(&addr,(void*)(&(((sockaddr_in*)(ai->ai_addr))->sin_addr)),sizeof(addr)); pnAddrInfo::Free(ai); } - + return addr; } diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.h b/Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.h index a1c63f41..197046c2 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.h +++ b/Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.h @@ -43,6 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define pnNetCommon_h_inc #include "HeadSpin.h" +#include "plString.h" #include "hsStlUtils.h" #include "hsRefCnt.h" #include "hsStream.h" @@ -81,9 +82,9 @@ namespace pnNetCommon { #ifndef SERVER - uint32_t GetBinAddr(const char * textAddr); - const char * GetTextAddr(uint32_t binAddr); - + uint32_t GetBinAddr(const char* textAddr); + plString GetTextAddr(uint32_t binAddr); + #endif // SERVER } From cf802fcba0049fd95a6cf234d96e2a0830224bb2 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 11 Mar 2012 21:33:54 -0700 Subject: [PATCH 23/37] Remove a bunch of unused custom STL code. --- Sources/Plasma/CoreLib/hsStlUtils.h | 183 ---------------------------- 1 file changed, 183 deletions(-) diff --git a/Sources/Plasma/CoreLib/hsStlUtils.h b/Sources/Plasma/CoreLib/hsStlUtils.h index 94429bec..f419f997 100644 --- a/Sources/Plasma/CoreLib/hsStlUtils.h +++ b/Sources/Plasma/CoreLib/hsStlUtils.h @@ -53,184 +53,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include -/***************************************************************************** -* -* derived stl classes that use our heap manager -* -***/ - - // TEMPLATE CLASS cyallocator -template - class cyallocator - : public std::allocator<_Ty> - { // generic cyallocator for objects of class _Ty -public: - typedef std::allocator<_Ty> _Mybase; - typedef typename _Mybase::value_type value_type; - - - typedef value_type* pointer; - typedef value_type& reference; - typedef const value_type* const_pointer; - typedef const value_type& const_reference; - - typedef size_t size_type; - typedef ptrdiff_t difference_type; - - template - struct rebind - { // convert an cyallocator<_Ty> to an cyallocator <_Other> - typedef cyallocator<_Other> other; - }; - - pointer address(reference _Val) const - { // return address of mutable _Val - return (&_Val); - } - - const_pointer address(const_reference _Val) const - { // return address of nonmutable _Val - return (&_Val); - } - - cyallocator() - { // construct default cyallocator (do nothing) - } - - cyallocator(const cyallocator<_Ty>&) - { // construct by copying (do nothing) - } - - template - cyallocator(const cyallocator<_Other>&) - { // construct from a related cyallocator (do nothing) - } - - template - cyallocator<_Ty>& operator=(const cyallocator<_Other>&) - { // assign from a related cyallocator (do nothing) - return (*this); - } - - void deallocate(pointer _Ptr, size_type) - { // deallocate object at _Ptr, ignore size - free(_Ptr); - } - - pointer allocate(size_type _Count) - { // allocate array of _Count elements - return (pointer)malloc(_Count * sizeof(_Ty)); - } - - pointer allocate(size_type _Count, const void*) - { // allocate array of _Count elements, ignore hint - return (allocate(_Count)); - } - - void construct(pointer _Ptr, const _Ty& _Val) - { // construct object at _Ptr with value _Val - std::_Construct(_Ptr, _Val); - } - - void destroy(pointer _Ptr) - { // destroy object at _Ptr - std::_Destroy(_Ptr); - } - - size_t max_size() const - { // estimate maximum array size - size_t _Count = (size_t)(-1) / sizeof (_Ty); - return (0 < _Count ? _Count : 1); - } - }; - - // cyallocator TEMPLATE OPERATORS -template inline - bool operator==(const cyallocator<_Ty>&, const cyallocator<_Other>&) - { // test for cyallocator equality (always true) - return (true); - } - -template inline - bool operator!=(const cyallocator<_Ty>&, const cyallocator<_Other>&) - { // test for cyallocator inequality (always false) - return (false); - } - -#ifndef _CRTIMP2 -#define _CRTIMP2 -#endif - - // CLASS cyallocator -template<> class _CRTIMP2 cyallocator - { // generic cyallocator for type void -public: - typedef void _Ty; - typedef _Ty* pointer; - typedef const _Ty* const_pointer; - typedef _Ty value_type; - - template - struct rebind - { // convert an cyallocator to an cyallocator <_Other> - typedef cyallocator<_Other> other; - }; - - cyallocator() - { // construct default cyallocator (do nothing) - } - - cyallocator(const cyallocator<_Ty>&) - { // construct by copying (do nothing) - } - - template - cyallocator(const cyallocator<_Other>&) - { // construct from related cyallocator (do nothing) - } - - template - cyallocator<_Ty>& operator=(const cyallocator<_Other>&) - { // assign from a related cyallocator (do nothing) - return (*this); - } - }; - - -/***************************************************************************** -* -* Drop-in replacements for stl classes. Uses our allocator instead of the default one. -* -***/ - -typedef std::basic_string, cyallocator > cystring; -typedef std::basic_string, cyallocator > cywstring; -// cyistring and cyiwstring declared later in this file - - // TEMPLATE CLASS cyvector -template -class cyvector : public std::vector<_Ty, cyallocator<_Ty> > { -}; - - // TEMPLATE CLASS cymap -template > -class cymap : public std::map<_Kty, _Ty, _Pr, cyallocator > > { -}; - - // TEMPLATE CLASS cylist -template -class cylist : public std::list<_Ty, cyallocator<_Ty> > { -}; - - // TEMPLATE CLASS cyset -template > -class cyset : public std::set<_Kty, _Pr, cyallocator< _Kty > > { -}; - - - /***************************************************************************** * * stl extensions @@ -347,11 +169,6 @@ struct wstricmp_char_traits : public std::char_traits< wchar_t > typedef std::basic_string istring; typedef std::basic_string iwstring; -// cyallocator version of istring -typedef std::basic_string > cyistring; -typedef std::basic_string > cyiwstring; - - // std::string trim std::string & trimleft(std::string & s, const char * charset=" \t\n\r"); std::wstring & trimleft(std::wstring & s, const wchar_t * charset=L" \t\n\r"); From 72d92bc66eb32d675118f71107f191c4c3535220 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sun, 11 Mar 2012 23:12:03 -0700 Subject: [PATCH 24/37] Start killing off NetAddress. --- .../Private/Nt/pnAceNtSocket.cpp | 10 +++--- Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h | 1 + .../Plasma/NucleusLib/pnNetDiag/pnNdDns.cpp | 2 +- .../Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp | 11 +++---- .../NucleusLib/pnSimpleNet/pnSimpleNet.cpp | 20 ++++++----- .../NucleusLib/pnSimpleNet/pnSimpleNet.h | 3 +- .../NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp | 33 ------------------- Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h | 25 ++++---------- .../plNetGameLib/Private/plNglAuth.cpp | 17 +++------- .../plNetGameLib/Private/plNglGame.cpp | 3 +- 10 files changed, 38 insertions(+), 87 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp index 9d501063..506e03c0 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp @@ -540,8 +540,8 @@ static SOCKET ListenSocket (NetAddress * listenAddr) { ); */ - NetAddressNode node = NetAddressGetNode(*listenAddr); - unsigned port = NetAddressGetPort(*listenAddr); + NetAddressNode node = listenAddr->GetHost(); + unsigned port = listenAddr->GetPort(); // bind socket to port sockaddr_in addr; @@ -581,13 +581,13 @@ static SOCKET ListenSocket (NetAddress * listenAddr) { } // success! - NetAddressSetPort(port, listenAddr); + listenAddr->SetPort(port); return s; } while (false); // failure! closesocket(s); - NetAddressSetPort(0, listenAddr); + listenAddr->SetPort(0); return INVALID_SOCKET; } @@ -1152,7 +1152,7 @@ unsigned NtSocketStartListening ( } s_listenCrit.Leave(); - unsigned port = NetAddressGetPort(addr); + unsigned port = addr.GetPort(); if (port) SetEvent(s_listenEvent); diff --git a/Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h b/Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h index c2efb7c4..b15cb434 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h +++ b/Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h @@ -48,6 +48,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNNETCLI_PNNETCLI_H #define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNNETCLI_PNNETCLI_H +#include "pnEncryption/plBigNum.h" /***************************************************************************** * diff --git a/Sources/Plasma/NucleusLib/pnNetDiag/pnNdDns.cpp b/Sources/Plasma/NucleusLib/pnNetDiag/pnNdDns.cpp index ff5a10f3..1cf8dca5 100644 --- a/Sources/Plasma/NucleusLib/pnNetDiag/pnNdDns.cpp +++ b/Sources/Plasma/NucleusLib/pnNetDiag/pnNdDns.cpp @@ -80,7 +80,7 @@ static void LookupCallback ( ) { DNSParam * p = (DNSParam *)param; if (addrCount) { - unsigned node = NetAddressGetNode(addrs[0]); + unsigned node = addrs[0].GetHost(); p->diag->critsect.Enter(); { p->diag->nodes[p->srv] = node; diff --git a/Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp b/Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp index 2cdb9639..576acdc9 100644 --- a/Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp +++ b/Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp @@ -828,8 +828,7 @@ void NetDiagTcp ( return; } - unsigned node; - NetAddress addr; + unsigned node; diag->critsect.Enter(); { node = diag->nodes[srv]; @@ -842,17 +841,17 @@ void NetDiagTcp ( return; } - NetAddressFromNode(node, port, &addr); - + plNetAddress addr(node, port); + switch (protocol) { case kNetProtocolCli2Auth: StartAuthTcpTest(diag, addr, dump, callback, param); break; - + case kNetProtocolCli2File: StartFileTcpTest(diag, addr, dump, callback, param); break; - + DEFAULT_FATAL(protocol); } } diff --git a/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp b/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp index be0986c9..2ac85dfa 100644 --- a/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp +++ b/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp @@ -368,7 +368,7 @@ static bool AsyncNotifySocketProc ( } //============================================================================ -static void Connect (const NetAddress & addr, ConnectParam * cp) { +static void Connect(const plNetAddress& addr, ConnectParam * cp) { SimpleNetConn * conn = NEWZERO(SimpleNetConn); conn->channelId = cp->channel->channelId; @@ -410,9 +410,9 @@ static void Connect (const NetAddress & addr, ConnectParam * cp) { //============================================================================ static void AsyncLookupCallback ( void * param, - const wchar_t name[], + const wchar_t name[], unsigned addrCount, - const NetAddress addrs[] + const plNetAddress addrs[] ) { ConnectParam * cp = (ConnectParam *)param; @@ -487,8 +487,9 @@ bool SimpleNetStartListening ( s_queryAccept = queryAccept; s_queryAcceptParam = param; - NetAddress addr; - NetAddressFromNode(0, kNetDefaultSimpleNetPort, &addr); + plNetAddress addr; + addr.SetPort(kNetDefaultSimpleNetPort); + addr.SetAnyAddr(); return (0 != AsyncSocketStartListening(addr, nil)); } @@ -497,8 +498,9 @@ void SimpleNetStopListening () { ASSERT(s_running); - NetAddress addr; - NetAddressFromNode(0, kNetDefaultSimpleNetPort, &addr); + plNetAddress addr; + addr.SetPort(kNetDefaultSimpleNetPort); + addr.SetAnyAddr(); AsyncSocketStopListening(addr, nil); s_queryAccept = nil; @@ -608,8 +610,8 @@ void SimpleNetStartConnecting ( } } if (!name[0]) { - NetAddress netAddr; - NetAddressFromString(&netAddr, addr, kNetDefaultSimpleNetPort); + plString saddr = _TEMP_CONVERT_FROM_WCHAR_T(addr); + plNetAddress netAddr(saddr.c_str(), kNetDefaultSimpleNetPort); Connect(netAddr, cp); } } diff --git a/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.h b/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.h index b857e998..b4c60f40 100644 --- a/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.h +++ b/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.h @@ -53,6 +53,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnProduct/pnProduct.h" #include "pnNetBase/pnNetBase.h" #include "pnAsyncCore/pnAsyncCore.h" +#include "pnNetCommon/plNetAddress.h" /***************************************************************************** * @@ -148,7 +149,7 @@ typedef bool (*FSimpleNetQueryAccept) ( // return true to accept incoming connec void * param, unsigned channel, SimpleNetConn * conn, - const NetAddress & addr + const plNetAddress& addr ); void SimpleNetCreateChannel ( diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp index 54a82b10..c6bbd0f5 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp @@ -156,39 +156,6 @@ bool NetAddressFromString (NetAddress * addr, const wchar_t str[], unsigned defa return false; } -//=========================================================================== -unsigned NetAddressGetPort ( - const NetAddress & addr -) { - return ntohs(((sockaddr_in *) &addr)->sin_port); -} - -//=========================================================================== -void NetAddressSetPort ( - unsigned port, - NetAddress * addr -) { - ((sockaddr_in *) addr)->sin_port = htons((uint16_t) port); -} - -//============================================================================ -NetAddressNode NetAddressGetNode (const NetAddress & addr) { - return ntohl(((const sockaddr_in *) &addr)->sin_addr.S_un.S_addr); -} - -//=========================================================================== -void NetAddressFromNode ( - NetAddressNode node, - unsigned port, - NetAddress * addr -) { - memset(addr, 0, sizeof(*addr)); - sockaddr_in * inetaddr = (sockaddr_in *) addr; - inetaddr->sin_family = AF_INET; - inetaddr->sin_addr.S_un.S_addr = htonl(node); - inetaddr->sin_port = htons((uint16_t) port); -} - //=========================================================================== void NetAddressNodeToString ( NetAddressNode node, diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h index b13eb1a3..97574804 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h @@ -57,11 +57,16 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com ***/ -struct NetAddress { +/*struct NetAddress { uint8_t data[24]; }; -typedef unsigned NetAddressNode; +typedef unsigned NetAddressNode;*/ + +#include "pnNetCommon/plNetAddress.h" + +typedef plNetAddress NetAddress; +typedef uint32_t NetAddressNode; /***************************************************************************** * @@ -95,26 +100,10 @@ bool NetAddressFromString ( unsigned defaultPort ); -unsigned NetAddressGetPort ( - const NetAddress & addr -); -void NetAddressSetPort ( - unsigned port, - NetAddress * addr -); - void NetAddressNodeToString ( NetAddressNode node, wchar_t * str, unsigned chars ); -NetAddressNode NetAddressGetNode ( - const NetAddress & addr -); -void NetAddressFromNode ( - NetAddressNode node, - unsigned port, - NetAddress * addr -); #endif diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index 85ac4488..b91b11aa 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -2194,18 +2194,11 @@ static bool Recv_ServerAddr ( { if (s_active) { s_active->token = msg.token; - NetAddressFromNode( - msg.srvAddr, - NetAddressGetPort(s_active->addr), - &s_active->addr - ); - wchar_t addrStr[64]; - NetAddressNodeToString( - msg.srvAddr, - addrStr, - arrsize(addrStr) - ); - LogMsg(kLogPerf, L"SrvAuth addr: %s", addrStr); + s_active->addr.SetHost(msg.srvAddr); + + plString logmsg = _TEMP_CONVERT_FROM_LITERAL("SrvAuth addr: "); + logmsg += s_active->addr.GetHostString(); + LogMsg(kLogPerf, L"SrvAuth addr: %s", logmsg.c_str()); } } s_critsect.Leave(); diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp index febaed0c..2d36d31f 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp @@ -798,8 +798,7 @@ void GamePingEnable (bool enable) { void NetCliGameStartConnect ( const NetAddressNode & node ) { - NetAddress addr; - NetAddressFromNode(node, kNetDefaultClientPort, &addr); + plNetAddress addr(node, kNetDefaultClientPort); Connect(addr); } From e770beb73d2d594d1e4bf7cd1c96538e16ef1ccc Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 12 Mar 2012 21:03:58 -0700 Subject: [PATCH 25/37] Kill pnNetDiag. --- Sources/Plasma/NucleusLib/CMakeLists.txt | 1 - .../NucleusLib/pnNetDiag/CMakeLists.txt | 21 - Sources/Plasma/NucleusLib/pnNetDiag/Intern.h | 143 --- Sources/Plasma/NucleusLib/pnNetDiag/Pch.h | 68 -- .../Plasma/NucleusLib/pnNetDiag/pnNdDns.cpp | 194 ---- .../Plasma/NucleusLib/pnNetDiag/pnNdIcmp.cpp | 262 ------ .../Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp | 857 ------------------ .../Plasma/NucleusLib/pnNetDiag/pnNetDiag.cpp | 167 ---- .../Plasma/NucleusLib/pnNetDiag/pnNetDiag.h | 145 --- .../Plasma/NucleusLib/pnNetDiag/pnNetSys.cpp | 166 ---- 10 files changed, 2024 deletions(-) delete mode 100644 Sources/Plasma/NucleusLib/pnNetDiag/CMakeLists.txt delete mode 100644 Sources/Plasma/NucleusLib/pnNetDiag/Intern.h delete mode 100644 Sources/Plasma/NucleusLib/pnNetDiag/Pch.h delete mode 100644 Sources/Plasma/NucleusLib/pnNetDiag/pnNdDns.cpp delete mode 100644 Sources/Plasma/NucleusLib/pnNetDiag/pnNdIcmp.cpp delete mode 100644 Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp delete mode 100644 Sources/Plasma/NucleusLib/pnNetDiag/pnNetDiag.cpp delete mode 100644 Sources/Plasma/NucleusLib/pnNetDiag/pnNetDiag.h delete mode 100644 Sources/Plasma/NucleusLib/pnNetDiag/pnNetSys.cpp diff --git a/Sources/Plasma/NucleusLib/CMakeLists.txt b/Sources/Plasma/NucleusLib/CMakeLists.txt index 315f923f..bbaebdea 100644 --- a/Sources/Plasma/NucleusLib/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/CMakeLists.txt @@ -17,7 +17,6 @@ add_subdirectory(pnModifier) add_subdirectory(pnNetBase) add_subdirectory(pnNetCli) add_subdirectory(pnNetCommon) -add_subdirectory(pnNetDiag) add_subdirectory(pnNetProtocol) add_subdirectory(pnProduct) add_subdirectory(pnSceneObject) diff --git a/Sources/Plasma/NucleusLib/pnNetDiag/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnNetDiag/CMakeLists.txt deleted file mode 100644 index 476a185f..00000000 --- a/Sources/Plasma/NucleusLib/pnNetDiag/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -include_directories("../../CoreLib") -include_directories("../../NucleusLib") - -set(pnNetDiag_HEADERS - Intern.h - Pch.h - pnNetDiag.h -) - -set(pnNetDiag_SOURCES - pnNdDns.cpp - pnNdIcmp.cpp - pnNdTcp.cpp - pnNetDiag.cpp - pnNetSys.cpp -) - -add_library(pnNetDiag STATIC ${pnNetDiag_HEADERS} ${pnNetDiag_SOURCES}) - -source_group("Header Files" FILES ${pnNetDiag_HEADERS}) -source_group("Source Files" FILES ${pnNetDiag_SOURCES}) diff --git a/Sources/Plasma/NucleusLib/pnNetDiag/Intern.h b/Sources/Plasma/NucleusLib/pnNetDiag/Intern.h deleted file mode 100644 index f6b8fe36..00000000 --- a/Sources/Plasma/NucleusLib/pnNetDiag/Intern.h +++ /dev/null @@ -1,143 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnNetDiag/Intern.h -* -***/ - -#ifdef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNNETDIAG_INTERN_H -#error "Header $/Plasma20/Sources/Plasma/NucleusLib/pnNetDiag/Intern.h included more than once" -#endif -#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNNETDIAG_INTERN_H - - -namespace ND { - -extern HMODULE g_lib; -extern const wchar_t g_version[]; - - -//============================================================================ -enum { - kDiagSrvAuth, - kDiagSrvFile, - kNumDiagSrvs -}; - -//============================================================================ -inline unsigned NetProtocolToSrv (ENetProtocol protocol) { - - switch (protocol) { - case kNetProtocolCli2Auth: return kDiagSrvAuth; - case kNetProtocolCli2File: return kDiagSrvFile; - default: return kNumDiagSrvs; - } -} - -//============================================================================ -inline const wchar_t * SrvToString (unsigned srv) { - - switch (srv) { - case kDiagSrvAuth: return L"Auth"; - case kDiagSrvFile: return L"File"; - DEFAULT_FATAL(srv); - } -} - -} using namespace ND; - - -//============================================================================ -struct NetDiag : AtomicRef { - - bool destroyed; - CCritSect critsect; - wchar_t * hosts[kNumDiagSrvs]; - unsigned nodes[kNumDiagSrvs]; - - ~NetDiag (); - - void Destroy (); - void SetHost (unsigned srv, const wchar_t host[]); -}; - - -/***************************************************************************** -* -* SYS -* -***/ - -void SysStartup (); -void SysShutdown (); - - -/***************************************************************************** -* -* DNS -* -***/ - -void DnsStartup (); -void DnsShutdown (); - - -/***************************************************************************** -* -* ICMP -* -***/ - -void IcmpStartup (); -void IcmpShutdown (); - - -/***************************************************************************** -* -* TCP -* -***/ - -void TcpStartup (); -void TcpShutdown (); - diff --git a/Sources/Plasma/NucleusLib/pnNetDiag/Pch.h b/Sources/Plasma/NucleusLib/pnNetDiag/Pch.h deleted file mode 100644 index 21d1cb19..00000000 --- a/Sources/Plasma/NucleusLib/pnNetDiag/Pch.h +++ /dev/null @@ -1,68 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnNetDiag/Pch.h -* -***/ - -#ifdef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNNETDIAG_PCH_H -#error "Header $/Plasma20/Sources/Plasma/NucleusLib/pnNetDiag/Pch.h included more than once" -#endif -#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNNETDIAG_PCH_H - -#include "pnUtils/pnUtils.h" -#include "pnNetBase/pnNetBase.h" -#include "pnAsyncCore/pnAsyncCore.h" -#include "pnProduct/pnProduct.h" -#include "pnNetCli/pnNetCli.h" - -#define USES_PROTOCOL_CLI2AUTH -#define USES_PROTOCOL_CLI2FILE -#include "pnNetProtocol/pnNetProtocol.h" - -#include "pnNetDiag.h" -#include "Intern.h" - -#include -#include -#include diff --git a/Sources/Plasma/NucleusLib/pnNetDiag/pnNdDns.cpp b/Sources/Plasma/NucleusLib/pnNetDiag/pnNdDns.cpp deleted file mode 100644 index 1cf8dca5..00000000 --- a/Sources/Plasma/NucleusLib/pnNetDiag/pnNdDns.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnNetDiag/pnNdDns.cpp -* -***/ - -#include "Pch.h" -#pragma hdrstop - - -/***************************************************************************** -* -* Internal types -* -***/ - -struct DNSParam { - NetDiag * diag; - FNetDiagDumpProc dump; - FNetDiagTestCallback callback; - void * param; - ENetProtocol protocol; - unsigned srv; -}; - - -/***************************************************************************** -* -* Internal functions -* -***/ - -//============================================================================ -static void LookupCallback ( - void * param, - const wchar_t name[], - unsigned addrCount, - const NetAddress addrs[] -) { - DNSParam * p = (DNSParam *)param; - if (addrCount) { - unsigned node = addrs[0].GetHost(); - p->diag->critsect.Enter(); - { - p->diag->nodes[p->srv] = node; - } - p->diag->critsect.Leave(); - wchar_t nodeStr[64]; - NetAddressNodeToString(p->diag->nodes[p->srv], nodeStr, arrsize(nodeStr)); - p->dump(L"[DNS] Success. %s --> %s", name, nodeStr); - p->callback( - p->diag, - p->protocol, - kNetSuccess, - p->param - ); - } - else { - p->diag->critsect.Enter(); - { - // if the hostname still matches, then clear the node - if (p->diag->hosts[p->srv] && 0 == StrCmp(p->diag->hosts[p->srv], name)) - p->diag->nodes[p->srv] = 0; - } - p->diag->critsect.Leave(); - p->dump(L"[DNS] Failed to resolve hostname %s", name); - p->callback( - p->diag, - p->protocol, - kNetErrNameLookupFailed, - p->param - ); - } - p->diag->DecRef("DNS"); - delete p; -} - - -/***************************************************************************** -* -* Module functions -* -***/ - -//============================================================================ -void DnsStartup () { -} - -//============================================================================ -void DnsShutdown () { -} - - -/***************************************************************************** -* -* Exports -* -***/ - -//============================================================================ -void NetDiagDns ( - NetDiag * diag, - ENetProtocol protocol, - FNetDiagDumpProc dump, - FNetDiagTestCallback callback, - void * param -) { - ASSERT(diag); - ASSERT(dump); - ASSERT(callback); - - unsigned srv = NetProtocolToSrv(protocol); - if (srv == kNumDiagSrvs) { - dump(L"[DNS] Unsupported protocol: %s", NetProtocolToString(protocol)); - callback(diag, protocol, kNetErrNotSupported, param); - return; - } - - wchar_t * host = nil; - diag->critsect.Enter(); - { - if (diag->hosts[srv]) - host = StrDup(diag->hosts[srv]); - } - diag->critsect.Leave(); - - if (!host) { - dump(L"[DNS] No hostname set for protocol: %s", NetProtocolToString(protocol)); - callback(diag, protocol, kNetSuccess, param); - return; - } - - diag->IncRef("DNS"); - dump(L"[DNS] Looking up %s...", host); - - DNSParam * dnsParam = NEWZERO(DNSParam); - dnsParam->diag = diag; - dnsParam->srv = srv; - dnsParam->protocol = protocol; - dnsParam->dump = dump; - dnsParam->callback = callback; - dnsParam->param = param; - - AsyncCancelId cancelId; - AsyncAddressLookupName( - &cancelId, - LookupCallback, - host, - 0, - dnsParam - ); - free(host); -} diff --git a/Sources/Plasma/NucleusLib/pnNetDiag/pnNdIcmp.cpp b/Sources/Plasma/NucleusLib/pnNetDiag/pnNdIcmp.cpp deleted file mode 100644 index b3a5ba30..00000000 --- a/Sources/Plasma/NucleusLib/pnNetDiag/pnNdIcmp.cpp +++ /dev/null @@ -1,262 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnNetDiag/pnNdIcmp.cpp -* -***/ - -#include "Pch.h" -#pragma hdrstop - - -/***************************************************************************** -* -* Local types -* -***/ - -typedef HANDLE (PASCAL FAR * FIcmpCreateFile) (); -typedef DWORD (PASCAL FAR * FIcmpSendEcho) ( - HANDLE icmpHandle, - DWORD destinationAddress, - LPVOID requestData, - WORD requestSize, - PIP_OPTION_INFORMATION options, - LPVOID replyBuffer, - DWORD replySize, - DWORD timeoutMs -); - -struct PingParam { - NetDiag * diag; - FNetDiagDumpProc dump; - FNetDiagTestCallback callback; - void * param; - ENetProtocol protocol; - unsigned srv; -}; - - - -/***************************************************************************** -* -* Local data -* -***/ - -static const unsigned kPingCount = 5; -static const unsigned kPayloadBytes = 32; - -static FIcmpCreateFile IcmpCreateFile; -static FIcmpSendEcho IcmpSendEcho; - -static uint8_t s_payload[kPayloadBytes]; - - -/***************************************************************************** -* -* Local functions -* -***/ - -//============================================================================ -static const wchar_t * IpStatusToString (ULONG status) { - - switch (status) { - case IP_SUCCESS: return L"IP_SUCCESS"; - case IP_BUF_TOO_SMALL: return L"IP_BUF_TOO_SMALL"; - case IP_DEST_NET_UNREACHABLE: return L"IP_DEST_NET_UNREACHABLE"; - case IP_DEST_HOST_UNREACHABLE: return L"IP_DEST_HOST_UNREACHABLE"; - case IP_DEST_PROT_UNREACHABLE: return L"IP_DEST_PROT_UNREACHABLE"; - case IP_DEST_PORT_UNREACHABLE: return L"IP_DEST_PORT_UNREACHABLE"; - case IP_NO_RESOURCES: return L"IP_NO_RESOURCES"; - case IP_BAD_OPTION: return L"IP_BAD_OPTION"; - case IP_HW_ERROR: return L"IP_HW_ERROR"; - case IP_PACKET_TOO_BIG: return L"IP_PACKET_TOO_BIG"; - case IP_REQ_TIMED_OUT: return L"IP_REQ_TIMED_OUT"; - case IP_BAD_REQ: return L"IP_BAD_REQ"; - case IP_BAD_ROUTE: return L"IP_BAD_ROUTE"; - case IP_TTL_EXPIRED_TRANSIT: return L"IP_TTL_EXPIRED_TRANSIT"; - case IP_TTL_EXPIRED_REASSEM: return L"IP_TTL_EXPIRED_REASSEM"; - case IP_PARAM_PROBLEM: return L"IP_PARAM_PROBLEM"; - case IP_SOURCE_QUENCH: return L"IP_SOURCE_QUENCH"; - case IP_OPTION_TOO_BIG: return L"IP_OPTION_TOO_BIG"; - case IP_BAD_DESTINATION: return L"IP_BAD_DESTINATION"; - default: return L"Unknown error"; - } -} - - -//============================================================================ -static void __cdecl PingThreadProc (void * param) { - - PingParam * p = (PingParam *)param; - - HANDLE icmp = IcmpCreateFile(); - if (!icmp) { - p->dump(L"[ICMP] Failed to create ICMP handle"); - p->callback(p->diag, p->protocol, kNetErrFileNotFound, p->param); - return; - } - - char addr[64]; - wchar_t waddr[64]; - NetAddressNodeToString(p->diag->nodes[p->srv], waddr, arrsize(waddr)); - StrToAnsi(addr, waddr, arrsize(addr)); - - ENetError result = kNetSuccess; - - uint8_t reply[kPayloadBytes + sizeof(ICMP_ECHO_REPLY)]; - - for (unsigned i = 0; i < kPingCount; ++i) { - DWORD retval = IcmpSendEcho( - icmp, - inet_addr(addr), - s_payload, - sizeof(s_payload), - NULL, - reply, - sizeof(reply), - 4000 - ); - - PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)reply; - - if (retval) { - p->dump(L"[ICMP] Reply from %s. ms=%u", waddr, pEchoReply->RoundTripTime); - } - else { - result = kNetErrConnectFailed; - p->dump(L"[ICMP] No reply from %s. %s", waddr, IpStatusToString(pEchoReply->Status)); - } - } - - p->callback(p->diag, p->protocol, result, p->param); - p->diag->DecRef("ICMP"); - delete p; -} - - -/***************************************************************************** -* -* Module functions -* -***/ - -//============================================================================ -void IcmpStartup () { - - if (g_lib) { - IcmpCreateFile = (FIcmpCreateFile)GetProcAddress(g_lib, "IcmpCreateFile"); - IcmpSendEcho = (FIcmpSendEcho)GetProcAddress(g_lib, "IcmpSendEcho"); - } - memset(s_payload, (uint8_t)((uintptr_t)&s_payload >> 4), arrsize(s_payload)); -} - -//============================================================================ -void IcmpShutdown () { - - IcmpCreateFile = nil; - IcmpSendEcho = nil; -} - - -/***************************************************************************** -* -* Exports -* -***/ - -//============================================================================ -void NetDiagIcmp ( - NetDiag * diag, - ENetProtocol protocol, - FNetDiagDumpProc dump, - FNetDiagTestCallback callback, - void * param -) { - ASSERT(diag); - ASSERT(dump); - ASSERT(callback); - - if (!IcmpCreateFile || !IcmpSendEcho) { - dump(L"[ICMP] Failed to load IP helper API"); - callback(diag, protocol, kNetErrNotSupported, param); - return; - } - - unsigned srv = NetProtocolToSrv(protocol); - if (srv == kNumDiagSrvs) { - dump(L"[ICMP] Unsupported protocol: %s", NetProtocolToString(protocol)); - callback(diag, protocol, kNetErrNotSupported, param); - return; - } - - unsigned node = 0; - diag->critsect.Enter(); - { - node = diag->nodes[srv]; - } - diag->critsect.Leave(); - - if (!node) { - dump(L"[ICMP] No address set for protocol: %s", NetProtocolToString(protocol)); - callback(diag, protocol, kNetSuccess, param); - return; - } - - wchar_t nodeStr[64]; - NetAddressNodeToString(node, nodeStr, arrsize(nodeStr)); - dump(L"[ICMP] Pinging %s with %u bytes of data...", nodeStr, kPayloadBytes); - - PingParam * pingParam = NEWZERO(PingParam); - pingParam->diag = diag; - pingParam->srv = srv; - pingParam->protocol = protocol; - pingParam->dump = dump; - pingParam->callback = callback; - pingParam->param = param; - - diag->IncRef("ICMP"); - _beginthread(PingThreadProc, 0, pingParam); -} diff --git a/Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp b/Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp deleted file mode 100644 index 576acdc9..00000000 --- a/Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp +++ /dev/null @@ -1,857 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp -* -***/ - -#include "Pch.h" -#pragma hdrstop - -/***************************************************************************** -* -* Local types -* -***/ - -struct AuthConn : AtomicRef { - NetDiag * diag; - FNetDiagDumpProc dump; - FNetDiagTestCallback callback; - void * param; - AsyncSocket sock; - AsyncCancelId cancelId; - NetCli * cli; - long pingsInRoute; - long pingsCompleted; - bool done; - ENetError error; - - ~AuthConn (); -}; - -struct AuthTrans : THashKeyVal { - HASHLINK(AuthTrans) link; - AuthConn * conn; - unsigned pingAtMs; - - AuthTrans (AuthConn * conn); - ~AuthTrans (); -}; - -struct FileConn : AtomicRef { - NetDiag * diag; - FNetDiagDumpProc dump; - FNetDiagTestCallback callback; - void * param; - AsyncSocket sock; - AsyncCancelId cancelId; - ARRAY(uint8_t) recvBuffer; - long pingsInRoute; - long pingsCompleted; - bool done; - ENetError error; - - ~FileConn (); -}; - -struct FileTrans : THashKeyVal { - HASHLINK(FileTrans) link; - FileConn * conn; - unsigned pingAtMs; - - FileTrans (FileConn * conn); - ~FileTrans (); -}; - - - -/***************************************************************************** -* -* Local data -* -***/ - -static const unsigned kPingTimeoutMs = 5000; -static const unsigned kTimeoutCheckMs = 100; -static const unsigned kMaxPings = 15; - - -static long s_authProtocolRegistered; -static unsigned s_transId; -static CCritSect s_critsect; -static bool s_shutdown; -static uint8_t s_payload[32]; -static AsyncTimer * s_timer; - -static HASHTABLEDECL( - AuthTrans, - THashKeyVal, - link -) s_authTrans; - -static HASHTABLEDECL( - FileTrans, - THashKeyVal, - link -) s_fileTrans; - - -/***************************************************************************** -* -* Cli2Auth protocol -* -***/ - -//============================================================================ -static bool Recv_PingReply ( - const uint8_t msg[], - unsigned bytes, - void * -) { - const Auth2Cli_PingReply & reply = *(const Auth2Cli_PingReply *)msg; - - AuthTrans * trans; - s_critsect.Enter(); - { - if (bytes < sizeof(Auth2Cli_PingReply)) { - // beta6 compatibility - if (nil != (trans = s_authTrans.Tail())) - s_authTrans.Unlink(trans); - } - else if (nil != (trans = s_authTrans.Find(reply.transId))) - s_authTrans.Unlink(trans); - } - s_critsect.Leave(); - - if (trans) { - unsigned replyAtMs = TimeGetMs(); - trans->conn->dump(L"[TCP] Reply from SrvAuth. ms=%u", replyAtMs - trans->pingAtMs); - delete trans; - return true; - } - else { - return false; - } -} - -//============================================================================ -#define MSG(s) kNetMsg_Cli2Auth_##s -static NetMsgInitSend s_send[] = { - { MSG(PingRequest) }, -}; - -#undef MSG -#define MSG(s) kNetMsg_Auth2Cli_##s, Recv_##s -static NetMsgInitRecv s_recv[] = { - { MSG(PingReply) }, -}; -#undef MSG - - -/***************************************************************************** -* -* Local functions -* -***/ - -//============================================================================ -static unsigned TimerCallback (void *) { - - unsigned timeMs = TimeGetMs(); - s_critsect.Enter(); - { - ENetError error = kNetErrTimeout; - {for (AuthTrans * next, * curr = s_authTrans.Head(); curr; curr = next) { - next = s_authTrans.Next(curr); - unsigned diff = timeMs - curr->pingAtMs; - if (diff > kPingTimeoutMs) { - if (!curr->conn->error) - curr->conn->error = error; - curr->conn->dump(L"[TCP] No reply from SrvAuth: %u, %s (ms=%u)", error, NetErrorToString(error), diff); - delete curr; - } - }} - {for (FileTrans * next, * curr = s_fileTrans.Head(); curr; curr = next) { - next = s_fileTrans.Next(curr); - unsigned diff = timeMs - curr->pingAtMs; - if (diff > kPingTimeoutMs) { - if (!curr->conn->error) - curr->conn->error = error; - curr->conn->dump(L"[TCP] No reply from SrvFile: %u, %s (ms=%u)", error, NetErrorToString(error), diff); - delete curr; - } - }} - } - s_critsect.Leave(); - - return kTimeoutCheckMs; -} - -//============================================================================ -static void AuthPingProc (void * param) { - - AuthConn * conn = (AuthConn *)param; - - while (!conn->done && conn->pingsCompleted < kMaxPings) { - - if (!conn->pingsInRoute) { - - AuthTrans * trans = new AuthTrans(conn); - trans->pingAtMs = TimeGetMs(); - - s_critsect.Enter(); - for (;;) { - if (conn->done) { - conn->pingsCompleted = kMaxPings; - delete trans; - break; - } - while (++s_transId == 0) - NULL_STMT; - trans->SetValue(s_transId); - s_authTrans.Add(trans); - - const uintptr_t msg[] = { - kCli2Auth_PingRequest, - trans->pingAtMs, - trans->GetValue(), - sizeof(s_payload), - (uintptr_t) s_payload, - }; - - NetCliSend(conn->cli, msg, arrsize(msg)); - NetCliFlush(conn->cli); - break; - } - s_critsect.Leave(); - } - AsyncSleep(10); - } - - s_critsect.Enter(); - { - conn->done = true; - AsyncSocketDisconnect(conn->sock, true); - NetCliDelete(conn->cli, false); - conn->cli = nil; - } - s_critsect.Leave(); - - conn->DecRef("Pinging"); -} - -//============================================================================ -static bool AuthConnEncrypt (ENetError error, void * param) { - - AuthConn * conn = (AuthConn *)param; - - if (IS_NET_SUCCESS(error)) { - conn->dump(L"[TCP] SrvAuth stream encrypted."); - conn->dump(L"[TCP] Pinging SrvAuth with 32 bytes of data..."); - conn->IncRef("Pinging"); - _beginthread(AuthPingProc, 0, conn); - } - else { - conn->dump(L"[TCP] SrvAuth stream encryption failed: %u, %s", error, NetErrorToString(error)); - } - - return IS_NET_SUCCESS(error); -} - -//============================================================================ -static void NotifyAuthConnSocketConnect (AuthConn * conn) { - - conn->dump(L"[TCP] SrvAuth socket established, encrypting stream..."); - - conn->TransferRef("Connecting", "Connected"); - conn->cli = NetCliConnectAccept( - conn->sock, - kNetProtocolCli2Auth, - false, - AuthConnEncrypt, - 0, - nil, - conn - ); -} - -//============================================================================ -static void NotifyAuthConnSocketConnectFailed (AuthConn * conn) { - - conn->error = kNetErrConnectFailed; - - conn->cancelId = 0; - conn->dump(L"[TCP] SrvAuth socket connection failed %u, %s", conn->error, NetErrorToString(conn->error)); - - conn->DecRef("Connecting"); -} - -//============================================================================ -static void NotifyAuthConnSocketDisconnect (AuthConn * conn) { - - if (!conn->done && !conn->error) - conn->error = kNetErrDisconnected; - - conn->cancelId = 0; - conn->dump(L"[TCP] SrvAuth socket closed: %u, %s", conn->error, NetErrorToString(conn->error)); - - HASHTABLEDECL( - AuthTrans, - THashKeyVal, - link - ) authTrans; - - s_critsect.Enter(); - { - conn->done = true; - while (AuthTrans * trans = s_authTrans.Head()) - authTrans.Add(trans); - } - s_critsect.Leave(); - - while (AuthTrans * trans = authTrans.Head()) { - conn->dump(L"[TCP] No reply from SrvAuth: %u, %s", conn->error, NetErrorToString(conn->error)); - delete trans; - } - - conn->DecRef("Connected"); -} - -//============================================================================ -static bool NotifyAuthConnSocketRead (AuthConn * conn, AsyncNotifySocketRead * read) { - - NetCliDispatch(conn->cli, read->buffer, read->bytes, conn); - read->bytesProcessed += read->bytes; - - return true; -} - -//============================================================================ -static bool AuthSocketNotifyCallback ( - AsyncSocket sock, - EAsyncNotifySocket code, - AsyncNotifySocket * notify, - void ** userState -) { - bool result = true; - AuthConn * conn; - - switch (code) { - case kNotifySocketConnectSuccess: - conn = (AuthConn *) notify->param; - *userState = conn; - conn->sock = sock; - conn->cancelId = 0; - NotifyAuthConnSocketConnect(conn); - break; - - case kNotifySocketConnectFailed: - conn = (AuthConn *) notify->param; - NotifyAuthConnSocketConnectFailed(conn); - break; - - case kNotifySocketDisconnect: - conn = (AuthConn *) *userState; - NotifyAuthConnSocketDisconnect(conn); - break; - - case kNotifySocketRead: - conn = (AuthConn *) *userState; - result = NotifyAuthConnSocketRead(conn, (AsyncNotifySocketRead *) notify); - break; - } - - return result; -} - -//============================================================================ -static bool Recv_File2Cli_ManifestReply (FileConn * conn, const File2Cli_ManifestReply & msg) { - - FileTrans * trans; - s_critsect.Enter(); - { - if (nil != (trans = s_fileTrans.Find(msg.transId))) - s_fileTrans.Unlink(trans); - } - s_critsect.Leave(); - - if (trans) { - unsigned replyAtMs = TimeGetMs(); - trans->conn->dump(L"[TCP] Reply from SrvFile. ms=%u", replyAtMs - trans->pingAtMs); - delete trans; - return true; - } - else { - return false; - } -} - -//============================================================================ -static void FilePingProc (void * param) { - - FileConn * conn = (FileConn *)param; - - while (!conn->done && conn->pingsCompleted < kMaxPings) { - - if (!conn->pingsInRoute) { - - FileTrans * trans = new FileTrans(conn); - trans->pingAtMs = TimeGetMs(); - - s_critsect.Enter(); - for (;;) { - if (conn->done) { - conn->pingsCompleted = kMaxPings; - delete trans; - break; - } - while (++s_transId == 0) - NULL_STMT; - trans->SetValue(s_transId); - s_fileTrans.Add(trans); - - Cli2File_ManifestRequest msg; - StrCopy(msg.group, L"External", arrsize(msg.group)); - msg.messageId = kCli2File_ManifestRequest; - msg.transId = trans->GetValue(); - msg.messageBytes = sizeof(msg); - msg.buildId = 0; - - AsyncSocketSend(conn->sock, &msg, sizeof(msg)); - break; - } - s_critsect.Leave(); - } - AsyncSleep(10); - } - - s_critsect.Enter(); - { - conn->done = true; - AsyncSocketDisconnect(conn->sock, true); - } - s_critsect.Leave(); - - conn->DecRef("Pinging"); -} - -//============================================================================ -static void NotifyFileConnSocketConnect (FileConn * conn) { - - conn->TransferRef("Connecting", "Connected"); - - conn->dump(L"[TCP] SrvFile socket established"); - conn->dump(L"[TCP] Pinging SrvFile..."); - conn->IncRef("Pinging"); - _beginthread(FilePingProc, 0, conn); -} - -//============================================================================ -static void NotifyFileConnSocketConnectFailed (FileConn * conn) { - - conn->error = kNetErrConnectFailed; - - conn->cancelId = 0; - conn->dump(L"[TCP] SrvFile socket connection failed %u, %s", conn->error, NetErrorToString(conn->error)); - - conn->DecRef("Connecting"); -} - -//============================================================================ -static void NotifyFileConnSocketDisconnect (FileConn * conn) { - - if (!conn->done && !conn->error) - conn->error = kNetErrDisconnected; - - conn->cancelId = 0; - conn->dump(L"[TCP] SrvFile socket closed: %u, %s", conn->error, NetErrorToString(conn->error)); - - HASHTABLEDECL( - FileTrans, - THashKeyVal, - link - ) fileTrans; - - s_critsect.Enter(); - { - conn->done = true; - while (FileTrans * trans = s_fileTrans.Head()) - fileTrans.Add(trans); - } - s_critsect.Leave(); - - while (FileTrans * trans = fileTrans.Head()) { - conn->dump(L"[TCP] No reply from SrvFile: %u, %s", conn->error, NetErrorToString(conn->error)); - delete trans; - } - - conn->DecRef("Connected"); -} - -//============================================================================ -static bool NotifyFileConnSocketRead (FileConn * conn, AsyncNotifySocketRead * read) { - - conn->recvBuffer.Add(read->buffer, read->bytes); - read->bytesProcessed += read->bytes; - - for (;;) { - if (conn->recvBuffer.Count() < sizeof(uint32_t)) - return true; - - uint32_t msgSize = *(uint32_t *)conn->recvBuffer.Ptr(); - if (conn->recvBuffer.Count() < msgSize) - return true; - - const Cli2File_MsgHeader * msg = (const Cli2File_MsgHeader *) conn->recvBuffer.Ptr(); - - if (msg->messageId != kFile2Cli_ManifestReply) { - conn->dump(L"[TCP] SrvFile received unexpected message. id: %u", msg->messageId); - return false; - } - - if (!Recv_File2Cli_ManifestReply(conn, *(const File2Cli_ManifestReply *)msg)) - return false; - - conn->recvBuffer.Move(0, msgSize, conn->recvBuffer.Count() - msgSize); - conn->recvBuffer.ShrinkBy(msgSize); - } -} - -//============================================================================ -static bool FileSocketNotifyCallback ( - AsyncSocket sock, - EAsyncNotifySocket code, - AsyncNotifySocket * notify, - void ** userState -) { - bool result = true; - FileConn * conn; - - switch (code) { - case kNotifySocketConnectSuccess: - conn = (FileConn *) notify->param; - *userState = conn; - conn->sock = sock; - conn->cancelId = 0; - NotifyFileConnSocketConnect(conn); - break; - - case kNotifySocketConnectFailed: - conn = (FileConn *) notify->param; - NotifyFileConnSocketConnectFailed(conn); - break; - - case kNotifySocketDisconnect: - conn = (FileConn *) *userState; - NotifyFileConnSocketDisconnect(conn); - break; - - case kNotifySocketRead: - conn = (FileConn *) *userState; - result = NotifyFileConnSocketRead(conn, (AsyncNotifySocketRead *) notify); - break; - } - - return result; -} - -//============================================================================ -static void StartAuthTcpTest ( - NetDiag * diag, - const NetAddress & addr, - FNetDiagDumpProc dump, - FNetDiagTestCallback callback, - void * param -) { - if (0 == AtomicSet(&s_authProtocolRegistered, 1)) { - memset( - s_payload, - (uint8_t)((uintptr_t)&s_payload >> 4), - sizeof(s_payload) - ); - NetMsgProtocolRegister( - kNetProtocolCli2Auth, - false, - s_send, arrsize(s_send), - s_recv, arrsize(s_recv), - kAuthDhGValue, - plBigNum(sizeof(kAuthDhXData), kAuthDhXData), - plBigNum(sizeof(kAuthDhNData), kAuthDhNData) - ); - } - - wchar_t addrStr[128]; - NetAddressToString(addr, addrStr, arrsize(addrStr), kNetAddressFormatAll); - dump(L"[TCP] Connecting to SrvAuth at %s...", addrStr); - - diag->IncRef("TCP"); - - AuthConn * conn = NEWZERO(AuthConn); - conn->diag = diag; - conn->dump = dump; - conn->callback = callback; - conn->param = param; - conn->IncRef("Connecting"); - - Cli2Auth_Connect connect; - connect.hdr.connType = (uint8_t) kConnTypeCliToAuth; - connect.hdr.hdrBytes = sizeof(connect.hdr); - connect.hdr.buildId = BuildId(); - connect.hdr.buildType = BUILD_TYPE_LIVE; - connect.hdr.branchId = BranchId(); - connect.hdr.productId = ProductId(); - connect.data.token = kNilGuid; - connect.data.dataBytes = sizeof(connect.data); - - AsyncSocketConnect( - &conn->cancelId, - addr, - AuthSocketNotifyCallback, - conn, - &connect, - sizeof(connect), - 0, - 0 - ); -} - -//============================================================================ -static void StartFileTcpTest ( - NetDiag * diag, - const NetAddress & addr, - FNetDiagDumpProc dump, - FNetDiagTestCallback callback, - void * param -) { - wchar_t addrStr[128]; - NetAddressToString(addr, addrStr, arrsize(addrStr), kNetAddressFormatAll); - dump(L"[TCP] Connecting to SrvFile at %s...", addrStr); - - diag->IncRef("TCP"); - - FileConn * conn = NEWZERO(FileConn); - conn->diag = diag; - conn->dump = dump; - conn->callback = callback; - conn->param = param; - conn->IncRef("Connecting"); - - Cli2File_Connect connect; - connect.hdr.connType = kConnTypeCliToFile; - connect.hdr.hdrBytes = sizeof(connect.hdr); - connect.hdr.buildId = 0; - connect.hdr.buildType = BUILD_TYPE_LIVE; - connect.hdr.branchId = BranchId(); - connect.hdr.productId = ProductId(); - connect.data.buildId = BuildId(); - connect.data.serverType = kSrvTypeNone; - connect.data.dataBytes = sizeof(connect.data); - - AsyncSocketConnect( - &conn->cancelId, - addr, - FileSocketNotifyCallback, - conn, - &connect, - sizeof(connect), - 0, - 0 - ); - -} - - -/***************************************************************************** -* -* AuthConn -* -***/ - -//============================================================================ -AuthConn::~AuthConn () { - if (cli) - NetCliDelete(cli, false); - if (sock) - AsyncSocketDelete(sock); - callback(diag, kNetProtocolCli2Auth, error, param); - diag->DecRef("TCP"); -} - - -/***************************************************************************** -* -* AuthTrans -* -***/ - -//============================================================================ -AuthTrans::AuthTrans (AuthConn * conn) -: conn(conn) -{ - conn->IncRef("Ping"); - AtomicAdd(&conn->pingsInRoute, 1); -} - -//============================================================================ -AuthTrans::~AuthTrans () { - - AtomicAdd(&conn->pingsCompleted, 1); - AtomicAdd(&conn->pingsInRoute, -1); - conn->DecRef("Ping"); -} - - -/***************************************************************************** -* -* FileConn -* -***/ - -//============================================================================ -FileConn::~FileConn () { - if (sock) - AsyncSocketDelete(sock); - callback(diag, kNetProtocolCli2File, error, param); - diag->DecRef("TCP"); -} - - -/***************************************************************************** -* -* FileTrans -* -***/ - -//============================================================================ -FileTrans::FileTrans (FileConn * conn) -: conn(conn) -{ - conn->IncRef("Ping"); - AtomicAdd(&conn->pingsInRoute, 1); -} - -//============================================================================ -FileTrans::~FileTrans () { - - AtomicAdd(&conn->pingsCompleted, 1); - AtomicAdd(&conn->pingsInRoute, -1); - conn->DecRef("Ping"); -} - - -/***************************************************************************** -* -* Module functions -* -***/ - -//============================================================================ -void TcpStartup () { - - s_shutdown = false; - AsyncTimerCreate(&s_timer, TimerCallback, 0, nil); -} - -//============================================================================ -void TcpShutdown () { - - s_shutdown = true; - AsyncTimerDeleteCallback(s_timer, TimerCallback); - s_timer = nil; -} - - -/***************************************************************************** -* -* Exports -* -***/ - -//============================================================================ -void NetDiagTcp ( - NetDiag * diag, - ENetProtocol protocol, - unsigned port, - FNetDiagDumpProc dump, - FNetDiagTestCallback callback, - void * param -) { - ASSERT(diag); - ASSERT(dump); - ASSERT(callback); - - unsigned srv = NetProtocolToSrv(protocol); - if (srv == kNumDiagSrvs) { - dump(L"[TCP] Unsupported protocol: %s", NetProtocolToString(protocol)); - callback(diag, protocol, kNetErrNotSupported, param); - return; - } - - unsigned node; - diag->critsect.Enter(); - { - node = diag->nodes[srv]; - } - diag->critsect.Leave(); - - if (!node) { - dump(L"[TCP] No address set for protocol: %s", NetProtocolToString(protocol)); - callback(diag, protocol, kNetSuccess, param); - return; - } - - plNetAddress addr(node, port); - - switch (protocol) { - case kNetProtocolCli2Auth: - StartAuthTcpTest(diag, addr, dump, callback, param); - break; - - case kNetProtocolCli2File: - StartFileTcpTest(diag, addr, dump, callback, param); - break; - - DEFAULT_FATAL(protocol); - } -} diff --git a/Sources/Plasma/NucleusLib/pnNetDiag/pnNetDiag.cpp b/Sources/Plasma/NucleusLib/pnNetDiag/pnNetDiag.cpp deleted file mode 100644 index 14a77572..00000000 --- a/Sources/Plasma/NucleusLib/pnNetDiag/pnNetDiag.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnNetDiag/pnNetDiag.cpp -* -***/ - -#include "Pch.h" -#pragma hdrstop - - -namespace ND { - -/***************************************************************************** -* -* Local data -* -***/ - - -/***************************************************************************** -* -* Module data -* -***/ - -HMODULE g_lib; -//const wchar_t g_version[] = L"miasma"; -//const wchar_t g_version[] = L"ectomorph"; -const wchar_t g_version[] = L"solvent"; - -} // namespace ND - - -/***************************************************************************** -* -* NetDiag -* -***/ - -//============================================================================ -NetDiag::~NetDiag () { - - for (unsigned srv = 0; srv < kNumDiagSrvs; ++srv) - free(hosts[srv]); -} - -//============================================================================ -void NetDiag::SetHost (unsigned srv, const wchar_t host[]) { - - critsect.Enter(); - { - free(hosts[srv]); - - if (host) - hosts[srv] = StrDup(host); - else - hosts[srv] = nil; - - nodes[srv] = 0; - } - critsect.Leave(); -} - - -/***************************************************************************** -* -* Exports -* -***/ - -//============================================================================ -void NetDiagInitialize () { - - g_lib = LoadLibrary("Iphlpapi.dll"); - - SysStartup(); - DnsStartup(); - IcmpStartup(); - TcpStartup(); - -} - -//============================================================================ -void NetDiagDestroy () { - - TcpShutdown(); - IcmpShutdown(); - DnsShutdown(); - SysShutdown(); - - if (g_lib) { - FreeLibrary(g_lib); - g_lib = nil; - } -} - -//============================================================================ -NetDiag * NetDiagCreate () { - - NetDiag * diag = NEWZERO(NetDiag); - diag->IncRef("Lifetime"); - return diag; -} - -//============================================================================ -void NetDiagDelete (NetDiag * diag) { - - ASSERT(!diag->destroyed); - diag->destroyed = true; - diag->DecRef("Lifetime"); -} - -//============================================================================ -void NetDiagSetHost ( - NetDiag * diag, - ENetProtocol protocol, - const wchar_t host[] -) { - ASSERT(diag); - - unsigned srv = NetProtocolToSrv(protocol); - if (srv == kNumDiagSrvs) - return; - - diag->SetHost(srv, host); -} diff --git a/Sources/Plasma/NucleusLib/pnNetDiag/pnNetDiag.h b/Sources/Plasma/NucleusLib/pnNetDiag/pnNetDiag.h deleted file mode 100644 index 00f59ac2..00000000 --- a/Sources/Plasma/NucleusLib/pnNetDiag/pnNetDiag.h +++ /dev/null @@ -1,145 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnNetDiag/pnNetDiag.h -* -***/ - -#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNNETDIAG_PNNETDIAG_H -#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNNETDIAG_PNNETDIAG_H - -#define PNNETDIAG_INCLUDED - -#ifdef PLNETGAMELIB_INCLUDED -#error "pnNetDiag and plNetGameLib libraries may not be included in the same project because they invalidate each other's pnNetCli settings" -#endif - - -/***************************************************************************** -* -* Module -* -***/ - -void NetDiagInitialize (); -void NetDiagDestroy (); - - -/***************************************************************************** -* -* NetDiag -* -***/ - -struct NetDiag; - -NetDiag * NetDiagCreate (); -void NetDiagDelete (NetDiag * diag); -void NetDiagSetHost ( - NetDiag * diag, - ENetProtocol protocol, - const wchar_t name[] -); - -typedef void ( __cdecl * FNetDiagDumpProc)( - const wchar_t fmt[], - ... -); -typedef void (*FNetDiagTestCallback)( - NetDiag * diag, - ENetProtocol protocol, - ENetError result, - void * param -); - - -//============================================================================ -// Test: SYS -// Gather system information -//============================================================================ -void NetDiagSys ( - NetDiag * diag, - FNetDiagDumpProc dump, - FNetDiagTestCallback callback, - void * param -); - -//============================================================================ -// Test: DNS -// Lookup server address -//============================================================================ -void NetDiagDns ( - NetDiag * diag, - ENetProtocol protocol, - FNetDiagDumpProc dump, - FNetDiagTestCallback callback, - void * param -); - -//============================================================================ -// Test: ICMP -// Send out 5 sequential ICMP ping packets to the server -//============================================================================ -void NetDiagIcmp ( - NetDiag * diag, - ENetProtocol protocol, - FNetDiagDumpProc dump, - FNetDiagTestCallback callback, - void * param -); - -//============================================================================ -// Test: TCP -// Connect to server and measure bandwidth -//============================================================================ -void NetDiagTcp ( - NetDiag * diag, - ENetProtocol protocol, - unsigned port, // 0 --> use default client port - FNetDiagDumpProc dump, - FNetDiagTestCallback callback, - void * param -); - - -#endif // PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNNETDIAG_PNNETDIAG_H diff --git a/Sources/Plasma/NucleusLib/pnNetDiag/pnNetSys.cpp b/Sources/Plasma/NucleusLib/pnNetDiag/pnNetSys.cpp deleted file mode 100644 index 3949cf30..00000000 --- a/Sources/Plasma/NucleusLib/pnNetDiag/pnNetSys.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnNetDiag/pnNetSys.cpp -* -***/ - -#include "Pch.h" -#pragma hdrstop - - -/***************************************************************************** -* -* Local types -* -***/ - -typedef DWORD (PASCAL FAR * FGetAdaptersInfo)( - PIP_ADAPTER_INFO pAdapterInfo, - PULONG pOutBufLen -); - - - -/***************************************************************************** -* -* Local data -* -***/ - -static FGetAdaptersInfo getAdaptersInfo; - - -/***************************************************************************** -* -* Module functions -* -***/ - -//============================================================================ -void SysStartup () { - - if (g_lib) { - getAdaptersInfo = (FGetAdaptersInfo)GetProcAddress(g_lib, "GetAdaptersInfo"); - } -} - -//============================================================================ -void SysShutdown () { - - getAdaptersInfo = nil; -} - - -/***************************************************************************** -* -* Exports -* -***/ - -//============================================================================ -void NetDiagSys ( - NetDiag * diag, - FNetDiagDumpProc dump, - FNetDiagTestCallback callback, - void * param -) { - ASSERT(diag); - ASSERT(dump); - ASSERT(callback); - - { // Timestamp - wchar_t str[256]; - uint64_t time = TimeGetTime(); - TimePrettyPrint(time, arrsize(str), str); - dump(L"[SYS] Time: %s UTC", str); - } - - { // Command line - dump(L"[SYS] Cmdline: %s", AppGetCommandLine()); - } - - { // Product - wchar_t product[128]; - ProductString(product, arrsize(product)); - dump(L"[SYS] Product: %s", product); - } - - { // pnNetDiag version - dump(L"[SYS] Cognomen: '%s'", g_version); - } - - { // OS - OSVERSIONINFOEX info; - info.dwOSVersionInfoSize = sizeof(info); - GetVersionEx((OSVERSIONINFO*)&info); - dump(L"[SYS] OS Version: %u.%u", info.dwMajorVersion, info.dwMinorVersion); - dump(L"[SYS] OS Patch: %u.%u (%S)", info.wServicePackMajor, info.wServicePackMinor, info.szCSDVersion); - } - - { // Adapters - if (!getAdaptersInfo) { - dump(L"[SYS] Failed to load IP helper API"); - callback(diag, kNetProtocolNil, kNetErrNotSupported, param); - return; - } - - ULONG ulOutBufLen = 0; - getAdaptersInfo(nil, &ulOutBufLen); - PIP_ADAPTER_INFO pInfo = (PIP_ADAPTER_INFO)malloc(ulOutBufLen); - PIP_ADAPTER_INFO pAdapter; - if (getAdaptersInfo(pInfo, &ulOutBufLen) == NO_ERROR) { - pAdapter = pInfo; - while (pAdapter) { - dump(L"[SYS] NIC: %S", pAdapter->Description); - pAdapter = pAdapter->Next; - } - callback(diag, kNetProtocolNil, kNetSuccess, param); - } - else { - dump(L"[SYS] Error getting adaper list"); - callback(diag, kNetProtocolNil, kNetErrFileNotFound, param); - } - free(pInfo); - } -} From 4b3d4a0d8320315e73377b5a1dbe125014919ee1 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 12 Mar 2012 21:04:27 -0700 Subject: [PATCH 26/37] Add an operator== to plNetAddress. --- .../pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp | 2 +- Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h | 7 +++++++ Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp | 9 --------- Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h | 5 ----- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp index 506e03c0..f71854d2 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp @@ -177,7 +177,7 @@ static bool ListenPortIncrement ( ) { NtListener * listener; for (listener = s_listenList.Head(); listener; listener = s_listenList.Next(listener)) { - if (!NetAddressEqual(listener->addr, listenAddr)) + if (listener->addr != listenAddr) continue; if (listener->notifyProc != notifyProc) continue; diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h index e238b8b9..761fad44 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h @@ -79,6 +79,13 @@ public: plNetAddress(const char* addr, uint16_t port); virtual ~plNetAddress(){} + bool operator==(const plNetAddress& other) const { + return (GetHost() == other.GetHost()) && (GetPort() == other.GetPort()); + } + bool operator!=(const plNetAddress& other) const { + return !(*this == other); + } + void Clear(); bool SetAnyAddr(); diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp index c6bbd0f5..d52accf2 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp @@ -94,15 +94,6 @@ static NetAddressNode NodeFromString (const wchar_t * string[]) { * ***/ -//=========================================================================== -int NetAddressCompare (const NetAddress & a1, const NetAddress & a2) { - const sockaddr_in & i1 = * (const sockaddr_in *) &a1; - const sockaddr_in & i2 = * (const sockaddr_in *) &a2; - - int d = i1.sin_addr.S_un.S_addr - i2.sin_addr.S_un.S_addr; - return d ? d : i1.sin_port - i2.sin_port; -} - //=========================================================================== void NetAddressToString ( const NetAddress & addr, diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h index 97574804..2143fe53 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h @@ -80,11 +80,6 @@ enum ENetAddressFormat { kNumNetAddressFormats }; -int NetAddressCompare (const NetAddress & a1, const NetAddress & a2); -inline bool NetAddressEqual (const NetAddress & a1, const NetAddress & a2) { - return NetAddressCompare(a1, a2) == 0; -} - void NetAddressToString ( const NetAddress & addr, wchar_t * str, From 4737e791cb44760f0fca7607ce343e263e5e4855 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 12 Mar 2012 21:59:10 -0700 Subject: [PATCH 27/37] Remove almost all uses of NetAddress. This probably has a bunch of bugs because of Network Order/Host Order issues. If we intend to actually support BE architectures, these problems are going to get much much worse :( --- .../Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp | 5 ++- .../Private/Nt/pnAceNtSocket.cpp | 7 ++-- .../Private/Win32/pnAceW32Dns.cpp | 11 +++--- .../NucleusLib/pnNetCommon/plNetAddress.cpp | 14 +++++++- .../NucleusLib/pnNetCommon/plNetAddress.h | 2 ++ .../NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp | 35 ------------------- Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h | 19 ---------- .../plNetClientComm/plNetClientComm.cpp | 9 +++-- .../plNetGameLib/Private/plNglAuth.cpp | 13 ++++--- .../plNetGameLib/Private/plNglAuth.h | 3 +- 10 files changed, 38 insertions(+), 80 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp b/Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp index bf222139..01ead690 100644 --- a/Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp +++ b/Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp @@ -115,9 +115,8 @@ static bool QueryAccept ( SimpleNetConn * , const NetAddress & addr ) { - wchar_t str[64]; - NetAddressToString(addr, str, arrsize(str), kNetAddressFormatAll); - LogMsg(kLogPerf, L"pfCsrSrv: Accepted connection from %s", str); + plString str = addr.AsString(); + LogMsg(kLogPerf, L"pfCsrSrv: Accepted connection from %s", str.c_str()); return channel == kSimpleNetChannelCsr; } diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp index f71854d2..3f6a78e4 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp @@ -547,12 +547,11 @@ static SOCKET ListenSocket (NetAddress * listenAddr) { sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons((uint16_t)port); - addr.sin_addr.S_un.S_addr = htonl(node); + addr.sin_addr.S_un.S_addr = node; memset(addr.sin_zero, 0, sizeof(addr.sin_zero)); if (bind(s, (sockaddr *) &addr, sizeof(addr))) { - wchar_t str[32]; - NetAddressToString(*listenAddr, str, arrsize(str), kNetAddressFormatAll); - LogMsg(kLogError, "bind to addr %s failed (err %u)", str, WSAGetLastError()); + plString str = listenAddr->AsString(); + LogMsg(kLogError, "bind to addr %s failed (err %u)", str.c_str(), WSAGetLastError()); break; } diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp index 4b44f696..a88fb019 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp @@ -340,13 +340,10 @@ void AsyncAddressLookupAddr ( lookup->lookupProc = lookupProc; lookup->port = 1; lookup->param = param; - NetAddressToString( - address, - lookup->name, - arrsize(lookup->name), - kNetAddressFormatNodeNumber - ); - + + plString str = address.GetHostString(); + lookup->name = str.toUtf16().GetData(); + s_critsect.Enter(); { // Start the lookup thread if it wasn't started already diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp index 60a3c541..3012e62d 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp @@ -57,7 +57,7 @@ plNetAddress::plNetAddress(uint32_t addr, uint16_t port) SetPort(port); } -plNetAddress::plNetAddress(const char * addr, uint16_t port) +plNetAddress::plNetAddress(const char* addr, uint16_t port) { Clear(); SetHost(addr); @@ -103,6 +103,11 @@ plString plNetAddress::GetHostString() const } uint32_t plNetAddress::GetHost() const +{ + return ntohl(fAddr.sin_addr.s_addr); +} + +uint32_t plNetAddress::GetHostBE() const { return fAddr.sin_addr.s_addr; } @@ -122,6 +127,13 @@ bool plNetAddress::SetHost(const char* hostname) } bool plNetAddress::SetHost(uint32_t addr) +{ + fAddr.sin_addr.s_addr = htonl(addr); + fAddr.sin_family = AF_INET; + return true; +} + +bool plNetAddress::SetHostBE(uint32_t addr) { memcpy(&fAddr.sin_addr, &addr,sizeof(addr)); fAddr.sin_family = AF_INET; diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h index 761fad44..3841fc6b 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h @@ -95,8 +95,10 @@ public: bool SetPort(uint16_t port); uint32_t GetHost() const; + uint32_t GetHostBE() const; bool SetHost(const char* hostname); bool SetHost(uint32_t ip4addr); + bool SetHostBE(uint32_t addr); const AddressType& GetAddressInfo() const { return fAddr; } AddressType& GetAddressInfo() { return fAddr; } diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp index d52accf2..81e91089 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp @@ -94,30 +94,6 @@ static NetAddressNode NodeFromString (const wchar_t * string[]) { * ***/ -//=========================================================================== -void NetAddressToString ( - const NetAddress & addr, - wchar_t * str, - unsigned chars, - ENetAddressFormat format -) { - ASSERT(str); - - static const wchar_t * s_fmts[] = { - L"%S", // kNetAddressFormatNodeNumber - L"%S:%u", // kNetAddressFormatAll - }; - ASSERT(format < arrsize(s_fmts)); - const sockaddr_in & inetaddr = * (const sockaddr_in *) &addr; - StrPrintf( - str, - chars, - s_fmts[format], - inet_ntoa(inetaddr.sin_addr), - ntohs(inetaddr.sin_port) - ); -} - //=========================================================================== bool NetAddressFromString (NetAddress * addr, const wchar_t str[], unsigned defaultPort) { ASSERT(addr); @@ -146,14 +122,3 @@ bool NetAddressFromString (NetAddress * addr, const wchar_t str[], unsigned defa // address already zeroed return false; } - -//=========================================================================== -void NetAddressNodeToString ( - NetAddressNode node, - wchar_t * str, - unsigned chars -) { - in_addr addr; - addr.S_un.S_addr = htonl(node); - StrPrintf(str, chars, L"%S", inet_ntoa(addr)); -} diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h index 2143fe53..1a4cab8e 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h @@ -74,19 +74,6 @@ typedef uint32_t NetAddressNode; * ***/ -enum ENetAddressFormat { - kNetAddressFormatNodeNumber, - kNetAddressFormatAll, - kNumNetAddressFormats -}; - -void NetAddressToString ( - const NetAddress & addr, - wchar_t * str, - unsigned chars, - ENetAddressFormat format -); - // 'str' must be in the form of a dotted IP address (IPv4 or IPv6) // - names which require DNS lookup will cause the function to return false bool NetAddressFromString ( @@ -95,10 +82,4 @@ bool NetAddressFromString ( unsigned defaultPort ); -void NetAddressNodeToString ( - NetAddressNode node, - wchar_t * str, - unsigned chars -); - #endif diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp index fb403161..ac7dcf80 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp @@ -591,23 +591,22 @@ static void INetCliAuthAgeRequestCallback ( unsigned ageMcpId, unsigned ageVaultId, const Uuid & ageInstId, - NetAddressNode gameAddr + plNetAddress gameAddr ) { if (!IS_NET_ERROR(result) || result == kNetErrVaultNodeNotFound) { s_age.ageInstId = ageInstId; s_age.ageVaultId = ageVaultId; - wchar_t gameAddrStr[64]; wchar_t ageInstIdStr[64]; - NetAddressNodeToString(gameAddr, gameAddrStr, arrsize(gameAddrStr)); + plString gameAddrStr = gameAddr.GetHostString(); LogMsg( kLogPerf, L"Connecting to game server %s, ageInstId %s", - gameAddrStr, + gameAddrStr.c_str(), GuidToString(ageInstId, ageInstIdStr, arrsize(ageInstIdStr)) ); NetCliGameDisconnect(); - NetCliGameStartConnect(gameAddr); + NetCliGameStartConnect(gameAddr.GetHost()); NetCliGameJoinAgeRequest( ageMcpId, s_account.accountUuid, diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index b91b11aa..2b5e8513 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -90,8 +90,8 @@ struct CliAuConn : AtomicRef { LINK(CliAuConn) link; AsyncSocket sock; NetCli * cli; - wchar_t name[MAX_PATH]; - NetAddress addr; + wchar_t name[MAX_PATH]; + plNetAddress addr; Uuid token; unsigned seq; unsigned serverChallenge; @@ -1545,9 +1545,9 @@ static void Connect ( //============================================================================ static void AsyncLookupCallback ( void * param, - const wchar_t name[], + const wchar_t name[], unsigned addrCount, - const NetAddress addrs[] + const plNetAddress addrs[] ) { if (!addrCount) { ReportNetError(kNetProtocolCli2Auth, kNetErrNameLookupFailed); @@ -2753,13 +2753,16 @@ bool AgeRequestTrans::Send () { //============================================================================ void AgeRequestTrans::Post () { + plNetAddress addr; + addr.SetHost(m_gameSrvNode); + m_callback( m_result, m_param, m_ageMcpId, m_ageVaultId, m_ageInstId, - m_gameSrvNode + addr ); } diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h index 6637909f..f19b6944 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h @@ -50,6 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #endif #define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLAUTH_H +#include "pnNetCommon/plNetAddress.h" /***************************************************************************** * @@ -326,7 +327,7 @@ typedef void (*FNetCliAuthAgeRequestCallback)( unsigned ageMcpId, unsigned ageVaultId, const Uuid & ageInstId, - NetAddressNode gameAddr + plNetAddress gameAddr ); void NetCliAuthAgeRequest ( const wchar_t ageName[], // L"Teledahn" From fbc6e33f7dd3d2e72666b9db15cdce399db2a2b3 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 26 Mar 2012 16:14:17 -0700 Subject: [PATCH 28/37] Rename these to make more sense. --- .../Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp | 12 ++++++------ Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp index 3012e62d..52ad0ae0 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp @@ -104,12 +104,12 @@ plString plNetAddress::GetHostString() const uint32_t plNetAddress::GetHost() const { - return ntohl(fAddr.sin_addr.s_addr); + return fAddr.sin_addr.s_addr; } -uint32_t plNetAddress::GetHostBE() const +uint32_t plNetAddress::GetHostLE() const { - return fAddr.sin_addr.s_addr; + return ntohl(fAddr.sin_addr.s_addr); } plString plNetAddress::GetHostWithPort() const @@ -128,14 +128,14 @@ bool plNetAddress::SetHost(const char* hostname) bool plNetAddress::SetHost(uint32_t addr) { - fAddr.sin_addr.s_addr = htonl(addr); + memcpy(&fAddr.sin_addr, &addr,sizeof(addr)); fAddr.sin_family = AF_INET; return true; } -bool plNetAddress::SetHostBE(uint32_t addr) +bool plNetAddress::SetHostLE(uint32_t addr) { - memcpy(&fAddr.sin_addr, &addr,sizeof(addr)); + fAddr.sin_addr.s_addr = htonl(addr); fAddr.sin_family = AF_INET; return true; } diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h index 3841fc6b..645d7fe0 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h @@ -95,10 +95,10 @@ public: bool SetPort(uint16_t port); uint32_t GetHost() const; - uint32_t GetHostBE() const; + uint32_t GetHostLE() const; bool SetHost(const char* hostname); bool SetHost(uint32_t ip4addr); - bool SetHostBE(uint32_t addr); + bool SetHostLE(uint32_t addr); const AddressType& GetAddressInfo() const { return fAddr; } AddressType& GetAddressInfo() { return fAddr; } From 06a561fc85fd0be69d206241e6eec99dff6e230a Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 26 Mar 2012 19:03:43 -0700 Subject: [PATCH 29/37] Fix bugs with plNetAddress. This allows the patcher to successfully connect to both GateKeeper and FileSrv. --- .../pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp | 2 +- .../pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp | 2 +- Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp | 4 ++-- Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp | 4 ++-- .../Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp | 2 +- .../Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp | 13 +++---------- Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h | 2 +- 7 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp index 3f6a78e4..5e4fbdfe 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp @@ -638,7 +638,7 @@ static SOCKET ConnectSocket (unsigned localPort, const NetAddress & addr) { } } - if (connect(s, (const sockaddr *) &addr, sizeof(addr))) { + if (connect(s, (const sockaddr *) &addr.GetAddressInfo(), sizeof(AddressType))) { if (WSAGetLastError() != WSAEWOULDBLOCK) { LogMsg(kLogError, "sockegt connect failed"); break; diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp index a88fb019..f493cd8d 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp @@ -342,7 +342,7 @@ void AsyncAddressLookupAddr ( lookup->param = param; plString str = address.GetHostString(); - lookup->name = str.toUtf16().GetData(); + wcsncpy(lookup->name, (const wchar_t*)str.ToUtf16().GetData(), 127); s_critsect.Enter(); { diff --git a/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp b/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp index 78d246c8..37c468a7 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp @@ -254,10 +254,10 @@ static NetMsgChannel* FindChannel_CS (uint32_t protocol, bool server) { std::list::iterator it = s_channels->begin(); for (; it != s_channels->end(); ++it) { if (((*it)->m_protocol == protocol) && ((*it)->m_server == server)) - break; + return *it; } - return *it; + return nil; } //=========================================================================== diff --git a/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp b/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp index d573a733..a50f308c 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp @@ -309,7 +309,7 @@ static void BufferedSendData ( else { // Value arrays are passed in by ptr - for (int i = 0; i < count; i++) { + for (size_t i = 0; i < count; i++) { if (cmd->size == sizeof(uint8_t)) { ((uint8_t*)temp)[i] = ((uint8_t*)*msg)[i]; } else if (cmd->size == sizeof(uint16_t)) { @@ -449,7 +449,7 @@ static bool DispatchData (NetCli * cli, void * param) { // byte-swap integers // This is so screwed up >.< - for (int i = 0; i < count; i++) { + for (size_t i = 0; i < count; i++) { if (cli->recvField->size == sizeof(uint16_t)) { ((uint16_t*)data)[i] = hsToLE16(((uint16_t*)data)[i]); } else if (cli->recvField->size == sizeof(uint32_t)) { diff --git a/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp b/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp index 2ac85dfa..432ad367 100644 --- a/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp +++ b/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp @@ -286,7 +286,7 @@ static bool AsyncNotifySocketProc ( s_critsect.Lock(); { std::map::iterator it; - if ((it = s_channels.find(conn->channelId)) != s_channels.end()) { + if ((it = s_channels.find(connect.channelId)) != s_channels.end()) { channel = it->second; channel->IncRef(); } diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp index 81e91089..9daa3500 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp @@ -95,13 +95,10 @@ static NetAddressNode NodeFromString (const wchar_t * string[]) { ***/ //=========================================================================== -bool NetAddressFromString (NetAddress * addr, const wchar_t str[], unsigned defaultPort) { +bool NetAddressFromString (NetAddress * addr, const wchar_t str[], uint16_t defaultPort) { ASSERT(addr); ASSERT(str); - // NetAddress is bigger than sockaddr_in so start by zeroing the whole thing - memset(addr, 0, sizeof(*addr)); - for (;;) { NetAddressNode node = NodeFromString(&str); if (node == (unsigned)-1) @@ -110,12 +107,8 @@ bool NetAddressFromString (NetAddress * addr, const wchar_t str[], unsigned defa if (*str == L':') defaultPort = StrToUnsigned(str + 1, nil, 10); - sockaddr_in * inetaddr = (sockaddr_in *) addr; - inetaddr->sin_family = AF_INET; - inetaddr->sin_port = htons((uint16_t) defaultPort); - inetaddr->sin_addr.S_un.S_addr = htonl(node); - // inetaddr->sin_zero already zeroed - + addr->SetPort((uint16_t)defaultPort); + addr->SetHostLE(node); return true; } diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h index 1a4cab8e..f0d118e3 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h @@ -79,7 +79,7 @@ typedef uint32_t NetAddressNode; bool NetAddressFromString ( NetAddress * addr, const wchar_t str[], - unsigned defaultPort + uint16_t defaultPort ); #endif From 3ea3473d1397d54322bbff177ca8ae6a36e46856 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 26 Mar 2012 21:27:55 -0700 Subject: [PATCH 30/37] Get rid of pnUtW32Addr and make IP strings char*s. IP addresses don't need to be unicode. pnUtAddr is still around until we replace all NetAddress uses with plNetAddress (they are typedef'ed to each other right now). --- Sources/Plasma/Apps/plClient/winmain.cpp | 29 ++--- .../Plasma/Apps/plClientPatcher/UruPlayer.cpp | 6 +- Sources/Plasma/Apps/plUruLauncher/Main.cpp | 3 +- .../Plasma/Apps/plUruLauncher/SelfPatcher.cpp | 6 +- .../pfConsoleCore/pfConsoleCommandsCore.cpp | 28 ++--- .../NucleusLib/pnAsyncCore/Private/pnAcIo.h | 14 +-- .../Private/Nt/pnAceNtSocket.cpp | 6 +- .../Private/Win32/pnAceW32Dns.cpp | 17 ++- .../Plasma/NucleusLib/pnNetBase/pnNbSrvs.cpp | 64 +++++----- .../Plasma/NucleusLib/pnNetBase/pnNbSrvs.h | 28 ++--- .../Private/Protocols/Cli2Auth/pnNpCli2Auth.h | 18 +-- .../Private/Protocols/Srv2Mcp/pnNpSrv2Mcp.h | 6 +- .../NucleusLib/pnSimpleNet/pnSimpleNet.cpp | 9 +- .../Plasma/NucleusLib/pnUtils/CMakeLists.txt | 1 - .../NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp | 117 ------------------ Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h | 28 ----- .../plNetClientComm/plNetClientComm.cpp | 22 ++-- .../plNetGameLib/Private/plNglAuth.cpp | 19 ++- .../plNetGameLib/Private/plNglAuth.h | 4 +- .../plNetGameLib/Private/plNglCsr.cpp | 11 +- .../plNetGameLib/Private/plNglCsr.h | 4 +- .../plNetGameLib/Private/plNglFile.cpp | 26 ++-- .../plNetGameLib/Private/plNglFile.h | 4 +- .../plNetGameLib/Private/plNglGame.cpp | 2 +- .../plNetGameLib/Private/plNglGame.h | 2 +- .../plNetGameLib/Private/plNglGateKeeper.cpp | 17 ++- .../plNetGameLib/Private/plNglGateKeeper.h | 4 +- 27 files changed, 166 insertions(+), 329 deletions(-) delete mode 100644 Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index ba76e22c..f81a9cc9 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/winmain.cpp @@ -1109,7 +1109,7 @@ void StatusCallback(void *param) { HWND hwnd = (HWND)param; - char *statusUrl = hsWStringToString(GetServerStatusUrl()); + const char *statusUrl = GetServerStatusUrl(); CURL *hCurl = curl_easy_init(); // For reporting errors @@ -1133,7 +1133,6 @@ void StatusCallback(void *param) } curl_easy_cleanup(hCurl); - delete [] statusUrl; s_statusEvent.Signal(); // Signal the semaphore } @@ -1254,8 +1253,8 @@ BOOL CALLBACK UruLoginDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM } else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_URULOGIN_GAMETAPLINK) { - const wchar_t *signupurl = GetServerSignupUrl(); - ShellExecuteW(NULL, L"open", signupurl, NULL, NULL, SW_SHOWNORMAL); + const char* signupurl = GetServerSignupUrl(); + ShellExecuteA(NULL, "open", signupurl, NULL, NULL, SW_SHOWNORMAL); return TRUE; } @@ -1461,25 +1460,27 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC memset(&si, 0, sizeof(si)); memset(&pi, 0, sizeof(pi)); si.cb = sizeof(si); - wchar_t cmdLine[MAX_PATH]; - const wchar_t ** addrs; + + plStringStream cmdLine; + const char** addrs; if (!eventExists) // if it is missing, assume patcher wasn't launched { - StrCopy(cmdLine, s_patcherExeName, arrsize(cmdLine)); + cmdLine << _TEMP_CONVERT_FROM_WCHAR_T(s_patcherExeName); + GetAuthSrvHostnames(&addrs); - if(wcslen(addrs[0])) - StrPrintf(cmdLine, arrsize(cmdLine), L"%ws /AuthSrv=%ws", cmdLine, addrs[0]); + if(strlen(addrs[0])) + cmdLine << plString::Format(" /AuthSrv=%s", addrs[0]); GetFileSrvHostnames(&addrs); - if(wcslen(addrs[0])) - StrPrintf(cmdLine, arrsize(cmdLine), L"%ws /FileSrv=%ws", cmdLine, addrs[0]); + if(strlen(addrs[0])) + cmdLine << plString::Format(" /FileSrv=%s", addrs[0]); GetGateKeeperSrvHostnames(&addrs); - if(wcslen(addrs[0])) - StrPrintf(cmdLine, arrsize(cmdLine), L"%ws /GateKeeperSrv=%ws", cmdLine, addrs[0]); + if(strlen(addrs[0])) + cmdLine << plString::Format(" /GateKeeperSrv=%s", addrs[0]); - if(!CreateProcessW(NULL, cmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) + if(!CreateProcessW(NULL, (LPWSTR)cmdLine.GetString().ToUtf16().GetData(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { hsMessageBox("Failed to launch patcher", "Error", hsMessageBoxNormal); } diff --git a/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp b/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp index c36cde8d..205f8021 100644 --- a/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp +++ b/Sources/Plasma/Apps/plClientPatcher/UruPlayer.cpp @@ -840,7 +840,9 @@ static void FileSrvIpAddressCallback ( plLauncherInfo *info = (plLauncherInfo *) param; // Start connecting to the server - NetCliFileStartConnect(&addr, 1, true); + const char* caddr = hsWStringToString(addr); + NetCliFileStartConnect(&caddr, 1, true); + delete[] caddr; NetCliFileManifestRequest(ThinManifestCallback, info, s_thinmanifest, info->buildId); @@ -902,7 +904,7 @@ void UruPrepProc (void * param) { s_patchComplete = false; s_patchError = false; - const wchar_t ** addrs; + const char** addrs; unsigned count; count = GetGateKeeperSrvHostnames(&addrs); diff --git a/Sources/Plasma/Apps/plUruLauncher/Main.cpp b/Sources/Plasma/Apps/plUruLauncher/Main.cpp index 2e35b79e..7d59c579 100644 --- a/Sources/Plasma/Apps/plUruLauncher/Main.cpp +++ b/Sources/Plasma/Apps/plUruLauncher/Main.cpp @@ -609,7 +609,7 @@ static size_t CurlCallback(void *buffer, size_t size, size_t nmemb, void *) //============================================================================ static void StatusCallback(void *) { - char *serverUrl = hsWStringToString(GetServerStatusUrl()); + const char *serverUrl = GetServerStatusUrl(); CURL * hCurl = curl_easy_init(); curl_easy_setopt(hCurl, CURLOPT_ERRORBUFFER, s_curlError); @@ -631,7 +631,6 @@ static void StatusCallback(void *) } curl_easy_cleanup(hCurl); - delete [] serverUrl; s_statusEvent.Signal(); } diff --git a/Sources/Plasma/Apps/plUruLauncher/SelfPatcher.cpp b/Sources/Plasma/Apps/plUruLauncher/SelfPatcher.cpp index 0bbda6d2..172e4eba 100644 --- a/Sources/Plasma/Apps/plUruLauncher/SelfPatcher.cpp +++ b/Sources/Plasma/Apps/plUruLauncher/SelfPatcher.cpp @@ -226,7 +226,9 @@ static void FileSrvIpAddressCallback ( } // Start connecting to the server - NetCliFileStartConnect(&addr, 1, true); + const char* caddr = hsWStringToString(addr); + NetCliFileStartConnect(&caddr, 1, true); + delete[] caddr; PathGetProgramDirectory(s_newPatcherFile, arrsize(s_newPatcherFile)); GetTempFileNameW(s_newPatcherFile, kPatcherExeFilename, 0, s_newPatcherFile); @@ -245,7 +247,7 @@ static bool SelfPatcherProc (bool * abort, plLauncherInfo *info) { NetClientInitialize(); NetClientSetErrorHandler(NetErrorHandler); - const wchar_t ** addrs; + const char** addrs; unsigned count; count = GetGateKeeperSrvHostnames(&addrs); diff --git a/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCommandsCore.cpp b/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCommandsCore.cpp index 2f0bb915..3bdf7f76 100644 --- a/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCommandsCore.cpp +++ b/Sources/Plasma/FeatureLib/pfConsoleCore/pfConsoleCommandsCore.cpp @@ -89,9 +89,7 @@ PF_CONSOLE_CMD( "string url", "Set the server's status URL" ) { - wchar_t *wurl = hsStringToWString((const char *)params[0]); - SetServerStatusUrl(wurl); - delete [] wurl; + SetServerStatusUrl(params[0]); } //============================================================================ @@ -101,9 +99,7 @@ PF_CONSOLE_CMD( "string url", "Set the server's new user sign-up URL" ) { - wchar_t *wurl = hsStringToWString((const char *)params[0]); - SetServerSignupUrl(wurl); - delete [] wurl; + SetServerSignupUrl(params[0]); } //============================================================================ @@ -113,9 +109,7 @@ PF_CONSOLE_CMD( "string name", "Set the displayable server name" ) { - wchar_t *wname = hsStringToWString((const char *)params[0]); - SetServerDisplayName(wname); - delete [] wname; + SetServerDisplayName(params[0]); } @@ -130,9 +124,7 @@ PF_CONSOLE_CMD( "string address", "Set the File Server address" ) { - wchar_t *wHost = hsStringToWString((const char *)params[0]); - SetFileSrvHostname(wHost); - delete [] wHost; + SetFileSrvHostname(params[0]); } @@ -147,9 +139,7 @@ PF_CONSOLE_CMD( "string address", "Set the Auth Server address" ) { - wchar_t *wHost = hsStringToWString((const char *)params[0]); - SetAuthSrvHostname(wHost); - delete [] wHost; + SetAuthSrvHostname(params[0]); } //============================================================================ @@ -200,9 +190,7 @@ PF_CONSOLE_CMD( "string address", "Set the Csr Server address" ) { - wchar_t *wHost = hsStringToWString((const char *)params[0]); - SetCsrSrvHostname(wHost); - delete [] wHost; + SetCsrSrvHostname(params[0]); } //============================================================================ @@ -294,9 +282,7 @@ PF_CONSOLE_CMD( "string address", "Set the GateKeeper Server address" ) { - wchar_t *wHost = hsStringToWString((const char *)params[0]); - SetGateKeeperSrvHostname(wHost); - delete [] wHost; + SetGateKeeperSrvHostname(params[0]); } //============================================================================ diff --git a/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h b/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h index e789cb41..ddad5c46 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h +++ b/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h @@ -213,7 +213,7 @@ FAsyncNotifySocketProc AsyncSocketFindNotifyProc ( void AsyncSocketConnect ( AsyncCancelId * cancelId, - const NetAddress & netAddr, + const plNetAddress& netAddr, FAsyncNotifySocketProc notifyProc, void * param = nil, const void * sendData = nil, @@ -275,11 +275,11 @@ void AsyncSocketSetBacklogAlloc ( // for connections with hard-coded behavior, set the notifyProc here (e.g. for use // protocols like SNMP on port 25) unsigned AsyncSocketStartListening ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc = nil ); void AsyncSocketStopListening ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc = nil ); @@ -297,15 +297,15 @@ void AsyncSocketEnableNagling ( typedef void (* FAsyncLookupProc) ( void * param, - const wchar_t name[], + const char name[], unsigned addrCount, - const NetAddress addrs[] + const plNetAddress addrs[] ); void AsyncAddressLookupName ( AsyncCancelId * cancelId, FAsyncLookupProc lookupProc, - const wchar_t name[], + const char name[], unsigned port, void * param ); @@ -313,7 +313,7 @@ void AsyncAddressLookupName ( void AsyncAddressLookupAddr ( AsyncCancelId * cancelId, FAsyncLookupProc lookupProc, - const NetAddress & address, + const plNetAddress& address, void * param ); diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp index 5e4fbdfe..04ae6d76 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp @@ -540,13 +540,13 @@ static SOCKET ListenSocket (NetAddress * listenAddr) { ); */ - NetAddressNode node = listenAddr->GetHost(); - unsigned port = listenAddr->GetPort(); + uint32_t node = listenAddr->GetHost(); + uint16_t port = listenAddr->GetPort(); // bind socket to port sockaddr_in addr; addr.sin_family = AF_INET; - addr.sin_port = htons((uint16_t)port); + addr.sin_port = htons(port); addr.sin_addr.S_un.S_addr = node; memset(addr.sin_zero, 0, sizeof(addr.sin_zero)); if (bind(s, (sockaddr *) &addr, sizeof(addr))) { diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp index f493cd8d..9221e97d 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp @@ -69,7 +69,7 @@ struct Lookup { FAsyncLookupProc lookupProc; unsigned port; void * param; - wchar_t name[kMaxLookupName]; + char name[kMaxLookupName]; char buffer[MAXGETHOSTSTRUCT]; }; @@ -122,7 +122,7 @@ static void LookupProcess (Lookup * lookup, unsigned error) { } if (host.h_name && host.h_name[0]) - StrToUnicode(lookup->name, host.h_name, arrsize(lookup->name)); + strncpy(lookup->name, host.h_name, arrsize(lookup->name)); if (lookup->lookupProc) lookup->lookupProc(lookup->param, lookup->name, count, addrs); @@ -271,7 +271,7 @@ void DnsDestroy (unsigned exitThreadWaitMs) { void AsyncAddressLookupName ( AsyncCancelId * cancelId, // out FAsyncLookupProc lookupProc, - const wchar_t name[], + const char* name, unsigned port, void * param ) { @@ -282,9 +282,8 @@ void AsyncAddressLookupName ( PerfAddCounter(kAsyncPerfNameLookupAttemptsTotal, 1); // Get name/port - char ansiName[kMaxLookupName]; - StrToAnsi(ansiName, name, arrsize(ansiName)); - if (char * portStr = StrChr(ansiName, ':')) { + char* ansiName = strdup(name); + if (char* portStr = StrChr(ansiName, ':')) { if (unsigned newPort = StrToUnsigned(portStr + 1, nil, 10)) port = newPort; *portStr = 0; @@ -295,7 +294,7 @@ void AsyncAddressLookupName ( lookup->lookupProc = lookupProc; lookup->port = port; lookup->param = param; - StrCopy(lookup->name, name, arrsize(lookup->name)); + strncpy(lookup->name, name, arrsize(lookup->name)); s_critsect.Enter(); { @@ -312,7 +311,7 @@ void AsyncAddressLookupName ( lookup->cancelHandle = WSAAsyncGetHostByName( s_lookupWindow, WM_LOOKUP_FOUND_HOST, - ansiName, + name, &lookup->buffer[0], sizeof(lookup->buffer) ); @@ -342,7 +341,7 @@ void AsyncAddressLookupAddr ( lookup->param = param; plString str = address.GetHostString(); - wcsncpy(lookup->name, (const wchar_t*)str.ToUtf16().GetData(), 127); + strncpy(lookup->name, str.c_str(), arrsize(lookup->name)); s_critsect.Enter(); { diff --git a/Sources/Plasma/NucleusLib/pnNetBase/pnNbSrvs.cpp b/Sources/Plasma/NucleusLib/pnNetBase/pnNbSrvs.cpp index 6e624224..47dfa188 100644 --- a/Sources/Plasma/NucleusLib/pnNetBase/pnNbSrvs.cpp +++ b/Sources/Plasma/NucleusLib/pnNetBase/pnNbSrvs.cpp @@ -53,26 +53,26 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com * ***/ -static wchar_t s_authAddrConsole[64] = {0}; -static const wchar_t * s_authAddrs[] = { +static char s_authAddrConsole[64] = {0}; +static const char* s_authAddrs[] = { s_authAddrConsole }; -static wchar_t s_fileAddrConsole[64] = {0}; -static const wchar_t * s_fileAddrs[] = { +static char s_fileAddrConsole[64] = {0}; +static const char* s_fileAddrs[] = { s_fileAddrConsole }; -static wchar_t s_csrAddrConsole[64] = {0}; -static const wchar_t * s_csrAddrs[] = { +static char s_csrAddrConsole[64] = {0}; +static const char* s_csrAddrs[] = { s_csrAddrConsole }; -static wchar_t s_gateKeeperAddrConsole[64] = {0}; -static const wchar_t * s_gateKeeperAddrs[] = { +static char s_gateKeeperAddrConsole[64] = {0}; +static const char* s_gateKeeperAddrs[] = { s_gateKeeperAddrConsole }; @@ -86,97 +86,97 @@ static const wchar_t * s_gateKeeperAddrs[] = { //============================================================================ // Auth //============================================================================ -unsigned GetAuthSrvHostnames (const wchar_t *** addrs) { +unsigned GetAuthSrvHostnames (const char*** addrs) { *addrs = s_authAddrs; return arrsize(s_authAddrs); } //============================================================================ -void SetAuthSrvHostname (const wchar_t addr[]) { +void SetAuthSrvHostname (const char addr[]) { - wcsncpy(s_authAddrConsole, addr, arrsize(s_authAddrConsole)); + strncpy(s_authAddrConsole, addr, arrsize(s_authAddrConsole)); } //============================================================================ // File //============================================================================ -unsigned GetFileSrvHostnames (const wchar_t *** addrs) { +unsigned GetFileSrvHostnames (const char*** addrs) { *addrs = s_fileAddrs; return arrsize(s_fileAddrs); } //============================================================================ -void SetFileSrvHostname (const wchar_t addr[]) { +void SetFileSrvHostname (const char addr[]) { - wcsncpy(s_fileAddrConsole, addr, arrsize(s_fileAddrConsole)); + strncpy(s_fileAddrConsole, addr, arrsize(s_fileAddrConsole)); } //============================================================================ // Csr //============================================================================ -unsigned GetCsrSrvHostnames (const wchar_t *** addrs) { +unsigned GetCsrSrvHostnames (const char*** addrs) { *addrs = s_csrAddrs; return arrsize(s_csrAddrs); } //============================================================================ -void SetCsrSrvHostname (const wchar_t addr[]) { +void SetCsrSrvHostname (const char addr[]) { - wcsncpy(s_csrAddrConsole, addr, arrsize(s_csrAddrConsole)); + strncpy(s_csrAddrConsole, addr, arrsize(s_csrAddrConsole)); } //============================================================================ // GateKeeper //============================================================================ -unsigned GetGateKeeperSrvHostnames (const wchar_t *** addrs) { +unsigned GetGateKeeperSrvHostnames (const char*** addrs) { *addrs = s_gateKeeperAddrs; return arrsize(s_gateKeeperAddrs); } //============================================================================ -void SetGateKeeperSrvHostname (const wchar_t addr[]) { - wcsncpy(s_gateKeeperAddrConsole, addr, arrsize(s_gateKeeperAddrConsole)); +void SetGateKeeperSrvHostname (const char addr[]) { + strncpy(s_gateKeeperAddrConsole, addr, arrsize(s_gateKeeperAddrConsole)); } //============================================================================ // User-visible Server //============================================================================ -static wchar_t s_serverStatusUrl[256] = {0}; -static wchar_t s_serverSignupUrl[256] = {0}; -static wchar_t s_serverName[256] = {0}; +static char s_serverStatusUrl[256] = {0}; +static char s_serverSignupUrl[256] = {0}; +static char s_serverName[256] = {0}; //============================================================================ -const wchar_t *GetServerStatusUrl () { +const char* GetServerStatusUrl () { return s_serverStatusUrl; } //============================================================================ -void SetServerStatusUrl (const wchar_t url[]) { - wcsncpy(s_serverStatusUrl, url, arrsize(s_serverStatusUrl)); +void SetServerStatusUrl (const char url[]) { + strncpy(s_serverStatusUrl, url, arrsize(s_serverStatusUrl)); } //============================================================================ -const wchar_t *GetServerSignupUrl () { +const char* GetServerSignupUrl () { return s_serverSignupUrl; } //============================================================================ -void SetServerSignupUrl (const wchar_t url[]) { - wcsncpy(s_serverSignupUrl, url, arrsize(s_serverSignupUrl)); +void SetServerSignupUrl (const char url[]) { + strncpy(s_serverSignupUrl, url, arrsize(s_serverSignupUrl)); } //============================================================================ -const wchar_t *GetServerDisplayName () { +const char* GetServerDisplayName () { return s_serverName; } //============================================================================ -void SetServerDisplayName (const wchar_t name[]) { - wcsncpy(s_serverName, name, arrsize(s_serverName)); +void SetServerDisplayName (const char name[]) { + strncpy(s_serverName, name, arrsize(s_serverName)); } diff --git a/Sources/Plasma/NucleusLib/pnNetBase/pnNbSrvs.h b/Sources/Plasma/NucleusLib/pnNetBase/pnNbSrvs.h index 04ea2c9c..a7746e12 100644 --- a/Sources/Plasma/NucleusLib/pnNetBase/pnNbSrvs.h +++ b/Sources/Plasma/NucleusLib/pnNetBase/pnNbSrvs.h @@ -84,25 +84,25 @@ enum ESrvType { * ***/ -unsigned GetAuthSrvHostnames (const wchar_t *** addrs); // returns addrCount -void SetAuthSrvHostname (const wchar_t addr[]); +unsigned GetAuthSrvHostnames (const char*** addrs); // returns addrCount +void SetAuthSrvHostname (const char addr[]); -unsigned GetFileSrvHostnames (const wchar_t *** addrs); // returns addrCount -void SetFileSrvHostname (const wchar_t addr[]); +unsigned GetFileSrvHostnames (const char*** addrs); // returns addrCount +void SetFileSrvHostname (const char addr[]); -unsigned GetCsrSrvHostnames (const wchar_t *** addrs); // returns addrCount -void SetCsrSrvHostname (const wchar_t addr[]); +unsigned GetCsrSrvHostnames (const char*** addrs); // returns addrCount +void SetCsrSrvHostname (const char addr[]); -unsigned GetGateKeeperSrvHostnames (const wchar_t *** addrs); // returns addrCount -void SetGateKeeperSrvHostname (const wchar_t addr[]); +unsigned GetGateKeeperSrvHostnames (const char*** addrs); // returns addrCount +void SetGateKeeperSrvHostname (const char addr[]); -const wchar_t *GetServerStatusUrl (); -void SetServerStatusUrl (const wchar_t url[]); +const char *GetServerStatusUrl (); +void SetServerStatusUrl (const char url[]); -const wchar_t *GetServerSignupUrl (); -void SetServerSignupUrl (const wchar_t url[]); +const char *GetServerSignupUrl (); +void SetServerSignupUrl (const char url[]); -const wchar_t *GetServerDisplayName (); -void SetServerDisplayName (const wchar_t name[]); +const char *GetServerDisplayName (); +void SetServerDisplayName (const char name[]); #endif // pnNbSrvs_inc diff --git a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Auth/pnNpCli2Auth.h b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Auth/pnNpCli2Auth.h index 1aaef9cb..1b6a10b2 100644 --- a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Auth/pnNpCli2Auth.h +++ b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Auth/pnNpCli2Auth.h @@ -677,8 +677,8 @@ struct Auth2Cli_AccountExistsReply { // ServerAddr extern const NetMsg kNetMsg_Auth2Cli_ServerAddr; struct Auth2Cli_ServerAddr { - uint32_t messageId; - NetAddressNode srvAddr; + uint32_t messageId; + uint32_t srvAddr; Uuid token; }; @@ -713,13 +713,13 @@ struct Auth2Cli_AcctLoginReply { // AgeReply extern const NetMsg kNetMsg_Auth2Cli_AgeReply; struct Auth2Cli_AgeReply { - uint32_t messageId; - uint32_t transId; - ENetError result; - uint32_t ageMcpId; - Uuid ageInstId; - uint32_t ageVaultId; - NetAddressNode gameSrvNode; + uint32_t messageId; + uint32_t transId; + ENetError result; + uint32_t ageMcpId; + Uuid ageInstId; + uint32_t ageVaultId; + uint32_t gameSrvNode; }; // AcctCreateReply diff --git a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Srv2Mcp/pnNpSrv2Mcp.h b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Srv2Mcp/pnNpSrv2Mcp.h index 2296b069..87a00242 100644 --- a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Srv2Mcp/pnNpSrv2Mcp.h +++ b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Srv2Mcp/pnNpSrv2Mcp.h @@ -191,9 +191,9 @@ struct Srv2Mcp_KickPlayer : SrvMsgHeader { ***/ struct Mcp2Srv_AgeJoinReply : SrvMsgHeader { - uint32_t ageMcpId; - Uuid ageUuid; - NetAddressNode gameSrvNode; + uint32_t ageMcpId; + Uuid ageUuid; + uint32_t gameSrvNode; }; struct Mcp2Srv_AgeSpawnRequest : SrvMsgHeader { diff --git a/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp b/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp index 432ad367..865dae2e 100644 --- a/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp +++ b/Sources/Plasma/NucleusLib/pnSimpleNet/pnSimpleNet.cpp @@ -410,7 +410,7 @@ static void Connect(const plNetAddress& addr, ConnectParam * cp) { //============================================================================ static void AsyncLookupCallback ( void * param, - const wchar_t name[], + const char name[], unsigned addrCount, const plNetAddress addrs[] ) { @@ -568,7 +568,7 @@ void SimpleNetDestroyChannel (unsigned channelId) { //============================================================================ void SimpleNetStartConnecting ( unsigned channelId, - const wchar_t addr[], + const char addr[], FSimpleNetOnConnect onConnect, void * param ) { @@ -593,7 +593,7 @@ void SimpleNetStartConnecting ( ASSERT(cp->channel); // Do we need to lookup the address? - const wchar_t * name = addr; + const char* name = addr; while (unsigned ch = *name) { ++name; if (!(isdigit(ch) || ch == L'.' || ch == L':')) { @@ -610,8 +610,7 @@ void SimpleNetStartConnecting ( } } if (!name[0]) { - plString saddr = _TEMP_CONVERT_FROM_WCHAR_T(addr); - plNetAddress netAddr(saddr.c_str(), kNetDefaultSimpleNetPort); + plNetAddress netAddr(addr, kNetDefaultSimpleNetPort); Connect(netAddr, cp); } } diff --git a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt index deec6ded..035dbfcd 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt @@ -39,7 +39,6 @@ set(pnUtils_SOURCES if(WIN32) set(pnUtils_WIN32 - Win32/pnUtW32Addr.cpp Win32/pnUtW32Misc.cpp Win32/pnUtW32Path.cpp Win32/pnUtW32Str.cpp diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp deleted file mode 100644 index 9daa3500..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Addr.cpp -* -***/ - -#include "../pnUtils.h" - - -/***************************************************************************** -* -* Internal functions -* -***/ - -//=========================================================================== -static NetAddressNode NodeFromString (const wchar_t * string[]) { - // skip leading whitespace - const wchar_t * str = *string; - while (iswspace(*str)) - ++str; - - // This function handles partial ip addresses (61.33) - // as well as full dotted quads. The address can be - // terminated by whitespace or ':' as well as '\0' - uint8_t data[4]; - * (uint32_t *) data = 0; - for (unsigned i = sizeof(data); i--; ) { - if (!iswdigit(*str)) - return (unsigned)-1; - - unsigned value = StrToUnsigned(str, &str, 10); - if (value >= 256) - return (unsigned)-1; - data[i] = (uint8_t) value; - - if (!*str || (*str == ':') || iswspace(*str)) - break; - - static const wchar_t s_separator[] = L"\0..."; - if (*str++ != s_separator[i]) - return (unsigned)-1; - } - - *string = str; - return * (NetAddressNode *) &data[0]; -} - - -/***************************************************************************** -* -* Exports -* -***/ - -//=========================================================================== -bool NetAddressFromString (NetAddress * addr, const wchar_t str[], uint16_t defaultPort) { - ASSERT(addr); - ASSERT(str); - - for (;;) { - NetAddressNode node = NodeFromString(&str); - if (node == (unsigned)-1) - break; - - if (*str == L':') - defaultPort = StrToUnsigned(str + 1, nil, 10); - - addr->SetPort((uint16_t)defaultPort); - addr->SetHostLE(node); - return true; - } - - // address already zeroed - return false; -} diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h index f0d118e3..555d459b 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h @@ -50,36 +50,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "Pch.h" -/***************************************************************************** -* -* Types and constants -* -***/ - - -/*struct NetAddress { - uint8_t data[24]; -}; - -typedef unsigned NetAddressNode;*/ - #include "pnNetCommon/plNetAddress.h" typedef plNetAddress NetAddress; -typedef uint32_t NetAddressNode; - -/***************************************************************************** -* -* Functions -* -***/ - -// 'str' must be in the form of a dotted IP address (IPv4 or IPv6) -// - names which require DNS lookup will cause the function to return false -bool NetAddressFromString ( - NetAddress * addr, - const wchar_t str[], - uint16_t defaultPort -); #endif diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp index ac7dcf80..ecb1d550 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp @@ -110,11 +110,11 @@ static bool s_loginComplete = false; static bool s_hasAuthSrvIpAddress = false; static bool s_hasFileSrvIpAddress = false; static ENetError s_authResult = kNetErrAuthenticationFailed; -static wchar_t s_authSrvAddr[256]; -static wchar_t s_fileSrvAddr[256]; +static char s_authSrvAddr[256]; +static char s_fileSrvAddr[256]; -static wchar_t s_iniServerAddr[256]; -static wchar_t s_iniFileServerAddr[256]; +static char s_iniServerAddr[256]; +static char s_iniFileServerAddr[256]; static wchar_t s_iniAccountUsername[kMaxAccountNameLength]; static ShaDigest s_namePassHash; static wchar_t s_iniAuthToken[kMaxPublisherAuthKeyLength]; @@ -667,7 +667,7 @@ static void AuthSrvIpAddressCallback ( void * param, const wchar_t addr[] ) { - StrCopy(s_authSrvAddr, addr, arrsize(s_authSrvAddr)); + StrToAnsi(s_authSrvAddr, addr, arrsize(s_authSrvAddr)); s_hasAuthSrvIpAddress = true; } @@ -677,7 +677,7 @@ static void FileSrvIpAddressCallback ( void * param, const wchar_t addr[] ) { - StrCopy(s_fileSrvAddr, addr, arrsize(s_fileSrvAddr)); + StrToAnsi(s_fileSrvAddr, addr, arrsize(s_fileSrvAddr)); s_hasFileSrvIpAddress = true; } @@ -822,12 +822,12 @@ void NetCommUpdate () { //============================================================================ void NetCommConnect () { - const wchar_t ** addrs; + const char** addrs; unsigned count; hsBool connectedToKeeper = false; // if a console override was specified for a authserv, connect directly to the authserver rather than going through the gatekeeper - if((count = GetAuthSrvHostnames(&addrs)) && wcslen(addrs[0])) + if((count = GetAuthSrvHostnames(&addrs)) && strlen(addrs[0])) { NetCliAuthStartConnect(addrs, count); } @@ -845,7 +845,7 @@ void NetCommConnect () { AsyncSleep(10); } - const wchar_t * authSrv[] = { + const char* authSrv[] = { s_authSrvAddr }; NetCliAuthStartConnect(authSrv, 1); @@ -854,7 +854,7 @@ void NetCommConnect () { if (!gDataServerLocal) { // if a console override was specified for a filesrv, connect directly to the fileserver rather than going through the gatekeeper - if((count = GetFileSrvHostnames(&addrs)) && wcslen(addrs[0])) + if((count = GetFileSrvHostnames(&addrs)) && strlen(addrs[0])) { NetCliFileStartConnect(addrs, count); } @@ -874,7 +874,7 @@ void NetCommConnect () { AsyncSleep(10); } - const wchar_t * fileSrv[] = { + const char* fileSrv[] = { s_fileSrvAddr }; NetCliFileStartConnect(fileSrv, 1); diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index 2b5e8513..7f22b79a 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -90,7 +90,7 @@ struct CliAuConn : AtomicRef { LINK(CliAuConn) link; AsyncSocket sock; NetCli * cli; - wchar_t name[MAX_PATH]; + char name[MAX_PATH]; plNetAddress addr; Uuid token; unsigned seq; @@ -197,7 +197,7 @@ struct AgeRequestTrans : NetAuthTrans { unsigned m_ageMcpId; Uuid m_ageInstId; unsigned m_ageVaultId; - NetAddressNode m_gameSrvNode; + uint32_t m_gameSrvNode; AgeRequestTrans ( const wchar_t ageName[], @@ -1527,7 +1527,7 @@ static void Connect ( //============================================================================ static void Connect ( - const wchar_t name[], + const char name[], const NetAddress & addr ) { ASSERT(s_running); @@ -1536,7 +1536,7 @@ static void Connect ( conn->addr = addr; conn->seq = ConnNextSequence(); conn->lastHeardTimeMs = GetNonZeroTimeMs(); // used in connect timeout, and ping timeout - StrCopy(conn->name, name, arrsize(conn->name)); + strncpy(conn->name, name, arrsize(conn->name)); conn->IncRef("Lifetime"); conn->AutoReconnect(); @@ -1545,7 +1545,7 @@ static void Connect ( //============================================================================ static void AsyncLookupCallback ( void * param, - const wchar_t name[], + const char name[], unsigned addrCount, const plNetAddress addrs[] ) { @@ -5121,8 +5121,8 @@ void AuthPingEnable (bool enable) { //============================================================================ void NetCliAuthStartConnect ( - const wchar_t * authAddrList[], - unsigned authAddrCount + const char* authAddrList[], + uint32_t authAddrCount ) { // TEMP: Only connect to one auth server until we fill out this module // to choose the "best" auth connection. @@ -5130,7 +5130,7 @@ void NetCliAuthStartConnect ( for (unsigned i = 0; i < authAddrCount; ++i) { // Do we need to lookup the address? - const wchar_t * name = authAddrList[i]; + const char* name = authAddrList[i]; while (unsigned ch = *name) { ++name; if (!(isdigit(ch) || ch == L'.' || ch == L':')) { @@ -5146,8 +5146,7 @@ void NetCliAuthStartConnect ( } } if (!name[0]) { - NetAddress addr; - NetAddressFromString(&addr, authAddrList[i], kNetDefaultClientPort); + NetAddress addr(authAddrList[i], kNetDefaultClientPort); Connect(authAddrList[i], addr); } } diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h index f19b6944..5ebeb223 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h @@ -62,8 +62,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // Connect //============================================================================ void NetCliAuthStartConnect ( - const wchar_t * authAddrList[], - unsigned authAddrCount + const char* authAddrList[], + uint32_t authAddrCount ); bool NetCliAuthQueryConnected (); void NetCliAuthAutoReconnectEnable (bool enable); // is enabled by default diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp index 86353d9a..e7025948 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp @@ -413,7 +413,7 @@ static void Connect ( //============================================================================ static void AsyncLookupCallback ( void * param, - const wchar_t name[], + const char name[], unsigned addrCount, const NetAddress addrs[] ) { @@ -830,8 +830,8 @@ unsigned CsrGetConnId () { //============================================================================ void NetCliCsrStartConnect ( - const wchar_t * addrList[], - unsigned addrCount, + const char* addrList[], + uint32_t addrCount, FNetCliCsrConnectedCallback callback, void * param ) { @@ -840,7 +840,7 @@ void NetCliCsrStartConnect ( for (unsigned i = 0; i < addrCount; ++i) { // Do we need to lookup the address? - const wchar_t * name = addrList[i]; + const char* name = addrList[i]; while (unsigned ch = *name) { ++name; if (!(isdigit(ch) || ch == L'.' || ch == L':')) { @@ -860,8 +860,7 @@ void NetCliCsrStartConnect ( } } if (!name[0]) { - NetAddress addr; - NetAddressFromString(&addr, addrList[i], kNetDefaultClientPort); + NetAddress addr(addrList[i], kNetDefaultClientPort); ConnectParam * cp = new ConnectParam; cp->callback = callback; diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.h index 1cee1e57..2b4ab2c5 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.h @@ -62,8 +62,8 @@ typedef void (*FNetCliCsrConnectedCallback) ( unsigned latestBuildId ); void NetCliCsrStartConnect ( - const wchar_t * addrList[], - unsigned addrCount, + const char* addrList[], + uint32_t addrCount, FNetCliCsrConnectedCallback callback = nil, void * param = nil ); diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp index d22bb5f0..bb272328 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp @@ -64,7 +64,7 @@ struct CliFileConn : AtomicRef { LINK(CliFileConn) link; CLock sockLock; // to protect the socket pointer so we don't nuke it while using it AsyncSocket sock; - wchar_t name[MAX_PATH]; + char name[MAX_PATH]; NetAddress addr; unsigned seq; ARRAY(uint8_t) recvBuffer; @@ -539,13 +539,13 @@ static void Connect (CliFileConn * conn) { //============================================================================ static void Connect ( - const wchar_t name[], + const char name[], const NetAddress & addr ) { ASSERT(s_running); CliFileConn * conn = NEWZERO(CliFileConn); - StrCopy(conn->name, name, arrsize(conn->name)); + strncpy(conn->name, name, arrsize(conn->name)); conn->addr = addr; conn->buildId = s_connectBuildId; conn->serverType = s_serverType; @@ -559,7 +559,7 @@ static void Connect ( //============================================================================ static void AsyncLookupCallback ( void * param, - const wchar_t name[], + const char name[], unsigned addrCount, const NetAddress addrs[] ) { @@ -1334,8 +1334,8 @@ unsigned FileGetConnId () { //============================================================================ void NetCliFileStartConnect ( - const wchar_t * fileAddrList[], - unsigned fileAddrCount, + const char* fileAddrList[], + uint32_t fileAddrCount, bool isPatcher /* = false */ ) { // TEMP: Only connect to one file server until we fill out this module @@ -1346,7 +1346,7 @@ void NetCliFileStartConnect ( for (unsigned i = 0; i < fileAddrCount; ++i) { // Do we need to lookup the address? - const wchar_t * name = fileAddrList[i]; + const char* name = fileAddrList[i]; while (unsigned ch = *name) { ++name; if (!(isdigit(ch) || ch == L'.' || ch == L':')) { @@ -1362,8 +1362,7 @@ void NetCliFileStartConnect ( } } if (!name[0]) { - NetAddress addr; - NetAddressFromString(&addr, fileAddrList[i], kNetDefaultClientPort); + NetAddress addr(fileAddrList[i], kNetDefaultClientPort); Connect(fileAddrList[i], addr); } } @@ -1371,8 +1370,8 @@ void NetCliFileStartConnect ( //============================================================================ void NetCliFileStartConnectAsServer ( - const wchar_t * fileAddrList[], - unsigned fileAddrCount, + const char* fileAddrList[], + uint32_t fileAddrCount, unsigned serverType, unsigned serverBuildId ) { @@ -1384,7 +1383,7 @@ void NetCliFileStartConnectAsServer ( for (unsigned i = 0; i < fileAddrCount; ++i) { // Do we need to lookup the address? - const wchar_t * name = fileAddrList[i]; + const char* name = fileAddrList[i]; while (unsigned ch = *name) { ++name; if (!(isdigit(ch) || ch == L'.' || ch == L':')) { @@ -1400,8 +1399,7 @@ void NetCliFileStartConnectAsServer ( } } if (!name[0]) { - NetAddress addr; - NetAddressFromString(&addr, fileAddrList[i], kNetDefaultServerPort); + NetAddress addr(fileAddrList[i], kNetDefaultServerPort); Connect(fileAddrList[i], addr); } } diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h index 23d82b64..845e8dc6 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.h @@ -62,12 +62,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // Connect //============================================================================ void NetCliFileStartConnect ( - const wchar_t * fileAddrList[], + const char* fileAddrList[], unsigned fileAddrCount, bool isPatcher = false ); void NetCliFileStartConnectAsServer ( - const wchar_t * fileAddrList[], + const char* fileAddrList[], unsigned fileAddrCount, unsigned serverType, unsigned serverBuildId diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp index 2d36d31f..9210ca24 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp @@ -796,7 +796,7 @@ void GamePingEnable (bool enable) { //============================================================================ void NetCliGameStartConnect ( - const NetAddressNode & node + const uint32_t node ) { plNetAddress addr(node, kNetDefaultClientPort); Connect(addr); diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.h index c9642753..afca4c95 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.h @@ -61,7 +61,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // Connect //============================================================================ void NetCliGameStartConnect ( - const NetAddressNode & node + const uint32_t node ); //============================================================================ diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp index 5794b063..03f99cba 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp @@ -89,7 +89,7 @@ struct CliGkConn : AtomicRef { LINK(CliGkConn) link; AsyncSocket sock; NetCli * cli; - wchar_t name[MAX_PATH]; + char name[MAX_PATH]; NetAddress addr; Uuid token; unsigned seq; @@ -463,7 +463,7 @@ static void Connect ( //============================================================================ static void Connect ( - const wchar_t name[], + const char name[], const NetAddress & addr ) { ASSERT(s_running); @@ -472,7 +472,7 @@ static void Connect ( conn->addr = addr; conn->seq = ConnNextSequence(); conn->lastHeardTimeMs = GetNonZeroTimeMs(); // used in connect timeout, and ping timeout - StrCopy(conn->name, name, arrsize(conn->name)); + strncpy(conn->name, name, arrsize(conn->name)); conn->IncRef("Lifetime"); conn->AutoReconnect(); @@ -481,7 +481,7 @@ static void Connect ( //============================================================================ static void AsyncLookupCallback ( void * param, - const wchar_t name[], + const char name[], unsigned addrCount, const NetAddress addrs[] ) { @@ -1053,14 +1053,14 @@ unsigned GateKeeperGetConnId () { //============================================================================ void NetCliGateKeeperStartConnect ( - const wchar_t * gateKeeperAddrList[], - unsigned gateKeeperAddrCount + const char* gateKeeperAddrList[], + uint32_t gateKeeperAddrCount ) { gateKeeperAddrCount = min(gateKeeperAddrCount, 1); for (unsigned i = 0; i < gateKeeperAddrCount; ++i) { // Do we need to lookup the address? - const wchar_t * name = gateKeeperAddrList[i]; + const char* name = gateKeeperAddrList[i]; while (unsigned ch = *name) { ++name; if (!(isdigit(ch) || ch == L'.' || ch == L':')) { @@ -1076,8 +1076,7 @@ void NetCliGateKeeperStartConnect ( } } if (!name[0]) { - NetAddress addr; - NetAddressFromString(&addr, gateKeeperAddrList[i], kNetDefaultClientPort); + NetAddress addr(gateKeeperAddrList[i], kNetDefaultClientPort); Connect(gateKeeperAddrList[i], addr); } } diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.h index c7beb0c5..fd42bff2 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.h @@ -62,8 +62,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // Connect //============================================================================ void NetCliGateKeeperStartConnect ( - const wchar_t * gateKeeperAddrList[], - unsigned gateKeeperAddrCount + const char* gateKeeperAddrList[], + uint32_t gateKeeperAddrCount ); bool NetCliGateKeeperQueryConnected (); From 3ba721711e289f34ed87f4f22fe2d17a29e7cebb Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 26 Mar 2012 21:49:10 -0700 Subject: [PATCH 31/37] Completely kill pnUtAddr and NetAddress. --- .../Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp | 2 +- .../NucleusLib/pnAsyncCore/Private/pnAcIo.h | 6 +- .../pnAsyncCoreExe/Private/Nt/pnAceNtInt.h | 6 +- .../Private/Nt/pnAceNtSocket.cpp | 31 +++++----- .../pnAsyncCoreExe/Private/W9x/pnAceW9xInt.h | 6 +- .../Private/W9x/pnAceW9xSocket.cpp | 6 +- .../Private/Win32/pnAceW32Dns.cpp | 9 ++- .../pnAsyncCoreExe/Private/pnAceInt.h | 6 +- .../NucleusLib/pnAsyncCoreExe/pnAceIo.cpp | 6 +- .../Plasma/NucleusLib/pnUtils/CMakeLists.txt | 1 - Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h | 57 ------------------- .../NucleusLib/pnUtils/pnUtAllIncludes.h | 1 - .../plNetGameLib/Private/plNglAuth.cpp | 4 +- .../plNetGameLib/Private/plNglCsr.cpp | 10 ++-- .../plNetGameLib/Private/plNglFile.cpp | 10 ++-- .../plNetGameLib/Private/plNglGame.cpp | 4 +- .../plNetGameLib/Private/plNglGateKeeper.cpp | 8 +-- 17 files changed, 56 insertions(+), 117 deletions(-) delete mode 100644 Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h diff --git a/Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp b/Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp index 01ead690..3c4c5a14 100644 --- a/Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp +++ b/Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp @@ -113,7 +113,7 @@ static bool QueryAccept ( void * , unsigned channel, SimpleNetConn * , - const NetAddress & addr + const plNetAddress& addr ) { plString str = addr.AsString(); LogMsg(kLogPerf, L"pfCsrSrv: Accepted connection from %s", str.c_str()); diff --git a/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h b/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h index ddad5c46..a09be9af 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h +++ b/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h @@ -103,8 +103,8 @@ struct AsyncNotifySocket { }; struct AsyncNotifySocketConnect : AsyncNotifySocket { - NetAddress localAddr; - NetAddress remoteAddr; + plNetAddress localAddr; + plNetAddress remoteAddr; unsigned connType; }; @@ -113,7 +113,7 @@ struct AsyncNotifySocketListen : AsyncNotifySocketConnect { unsigned buildType; unsigned branchId; Uuid productId; - NetAddress addr; + plNetAddress addr; uint8_t * buffer; unsigned bytes; unsigned bytesProcessed; diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtInt.h b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtInt.h index 8f702287..60d5148e 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtInt.h +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtInt.h @@ -191,7 +191,7 @@ void NtWaitForShutdown (); void NtSleep (unsigned sleepMs); void NtSocketConnect ( AsyncCancelId * cancelId, - const NetAddress & netAddr, + const plNetAddress& netAddr, FAsyncNotifySocketProc notifyProc, void * param, const void * sendData, @@ -228,11 +228,11 @@ void NtSocketSetBacklogAlloc ( unsigned bufferSize ); unsigned NtSocketStartListening ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc ); void NtSocketStopListening ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc ); void NtSocketEnableNagling ( diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp index 04ae6d76..91490b37 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp @@ -77,7 +77,7 @@ static const unsigned kMinBacklogBytes = 4 * 1024; struct NtListener { LINK(NtListener) nextPort; SOCKET hSocket; - NetAddress addr; + plNetAddress addr; FAsyncNotifySocketProc notifyProc; int listenCount; @@ -91,7 +91,7 @@ struct NtOpConnAttempt : Operation { AsyncCancelId cancelId; bool canceled; unsigned localPort; - NetAddress remoteAddr; + plNetAddress remoteAddr; FAsyncNotifySocketProc notifyProc; void * param; SOCKET hSocket; @@ -113,7 +113,7 @@ struct NtOpSocketRead : Operation { struct NtSock : NtObject { LINK(NtSock) link; - NetAddress addr; + plNetAddress addr; unsigned closeTimeMs; unsigned connType; FAsyncNotifySocketProc notifyProc; @@ -171,7 +171,7 @@ NtSock::~NtSock () { //=========================================================================== // must be called inside s_listenCrit static bool ListenPortIncrement ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc, int count ) { @@ -192,12 +192,11 @@ static bool ListenPortIncrement ( //=========================================================================== static void SocketGetAddresses ( NtSock * sock, - NetAddress * localAddr, - NetAddress * remoteAddr + plNetAddress* localAddr, + plNetAddress* remoteAddr ) { - // NetAddress may be bigger than sockaddr_in so start by zeroing the whole thing - memset(localAddr, 0, sizeof(*localAddr)); - memset(remoteAddr, 0, sizeof(*remoteAddr)); + localAddr->Clear(); + remoteAddr->Clear(); // don't have to enter critsect or validate socket before referencing it // because this routine is called before the user has a chance to close it @@ -470,7 +469,7 @@ static bool SocketInitConnect ( //=========================================================================== static void SocketInitListen ( NtSock * const sock, - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc ) { for (;;) { @@ -509,7 +508,7 @@ static void SocketInitListen ( } //=========================================================================== -static SOCKET ListenSocket (NetAddress * listenAddr) { +static SOCKET ListenSocket(plNetAddress* listenAddr) { // create a new socket to listen SOCKET s; if (INVALID_SOCKET == (s = socket(AF_INET, SOCK_STREAM, 0))) { @@ -612,7 +611,7 @@ static void ListenPrepareListeners (fd_set * readfds) { } //=========================================================================== -static SOCKET ConnectSocket (unsigned localPort, const NetAddress & addr) { +static SOCKET ConnectSocket (unsigned localPort, const plNetAddress& addr) { SOCKET s; if (INVALID_SOCKET == (s = socket(AF_INET, SOCK_STREAM, 0))) { LogMsg(kLogError, "socket create failed"); @@ -1126,12 +1125,12 @@ bool INtSocketOpCompleteQueuedSocketWrite ( //=========================================================================== unsigned NtSocketStartListening ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc ) { s_listenCrit.Enter(); StartListenThread(); - NetAddress addr = listenAddr; + plNetAddress addr = listenAddr; for (;;) { // if the port is already open then just increment the reference count if (ListenPortIncrement(addr, notifyProc, 1)) @@ -1160,7 +1159,7 @@ unsigned NtSocketStartListening ( //=========================================================================== void NtSocketStopListening ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc ) { s_listenCrit.Enter(); @@ -1171,7 +1170,7 @@ void NtSocketStopListening ( //=========================================================================== void NtSocketConnect ( AsyncCancelId * cancelId, - const NetAddress & netAddr, + const plNetAddress& netAddr, FAsyncNotifySocketProc notifyProc, void * param, const void * sendData, diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xInt.h b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xInt.h index d518dbe1..5ca8974c 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xInt.h +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xInt.h @@ -88,7 +88,7 @@ bool W9xThreadWaitId ( ); void W9xSocketConnect ( AsyncCancelId * cancelId, - const NetAddress & netAddr, + const plNetAddress& netAddr, FAsyncNotifySocketProc notifyProc, void * param, const void * sendData, @@ -126,11 +126,11 @@ void W9xSocketSetBacklogAlloc ( unsigned bufferSize ); unsigned W9xSocketStartListening ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc ); void W9xSocketStopListening ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc ); void W9xSocketEnableNagling ( diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xSocket.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xSocket.cpp index e94bd60c..c7d63d53 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xSocket.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xSocket.cpp @@ -999,7 +999,7 @@ static LRESULT CALLBACK WndProc ( //=========================================================================== void W9xSocketConnect ( AsyncCancelId * cancelId, - const NetAddress & netAddr, + const plNetAddress& netAddr, FAsyncNotifySocketProc notifyProc, void * param, const void * sendData, @@ -1148,7 +1148,7 @@ void W9xSocketDisconnect ( //=========================================================================== unsigned W9xSocketStartListening ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc ) { return 0; @@ -1157,7 +1157,7 @@ unsigned W9xSocketStartListening ( //=========================================================================== void W9xSocketStopListening ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc ) { } diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp index 9221e97d..3aa557b3 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp @@ -89,7 +89,7 @@ static unsigned s_nextLookupCancelId = 1; //=========================================================================== static void LookupProcess (Lookup * lookup, unsigned error) { unsigned count = 0; - NetAddress * addrs = nil; + plNetAddress* addrs = nil; if (error) return; @@ -109,8 +109,7 @@ static void LookupProcess (Lookup * lookup, unsigned error) { ++count; // allocate a buffer large enough to hold all the addresses - addrs = (NetAddress *)malloc(sizeof(*addrs) * count); - memset(addrs, 0, sizeof(*addrs) * count); + addrs = new plNetAddress[count]; // fill in address data const uint16_t port = htons((uint16_t) lookup->port); @@ -134,7 +133,7 @@ static void LookupProcess (Lookup * lookup, unsigned error) { delete lookup; PerfSubCounter(kAsyncPerfNameLookupAttemptsCurr, 1); - free(addrs); + delete[] addrs; } //=========================================================================== @@ -326,7 +325,7 @@ void AsyncAddressLookupName ( void AsyncAddressLookupAddr ( AsyncCancelId * cancelId, // out FAsyncLookupProc lookupProc, - const NetAddress & address, + const plNetAddress& address, void * param ) { ASSERT(lookupProc); diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/pnAceInt.h b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/pnAceInt.h index 83270e82..9517e798 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/pnAceInt.h +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/pnAceInt.h @@ -106,7 +106,7 @@ typedef void (* FSleep) (unsigned sleepMs); // Sockets typedef void (* FAsyncSocketConnect) ( AsyncCancelId * cancelId, - const NetAddress & netAddr, + const plNetAddress& netAddr, FAsyncNotifySocketProc notifyProc, void * param, const void * sendData, @@ -151,12 +151,12 @@ typedef void (* FAsyncSocketSetBacklogAlloc) ( ); typedef unsigned (* FAsyncSocketStartListening) ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc ); typedef void (* FAsyncSocketStopListening) ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc ); diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceIo.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceIo.cpp index bd4ef8d1..a4b6bc6d 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceIo.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceIo.cpp @@ -206,7 +206,7 @@ static unsigned GetConnHash ( //=========================================================================== void AsyncSocketConnect ( AsyncCancelId * cancelId, - const NetAddress & netAddr, + const plNetAddress& netAddr, FAsyncNotifySocketProc notifyProc, void * param, const void * sendData, @@ -293,7 +293,7 @@ void AsyncSocketSetBacklogAlloc ( //=========================================================================== unsigned AsyncSocketStartListening ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc ) { ASSERT(g_api.socketStartListening); @@ -302,7 +302,7 @@ unsigned AsyncSocketStartListening ( //=========================================================================== void AsyncSocketStopListening ( - const NetAddress & listenAddr, + const plNetAddress& listenAddr, FAsyncNotifySocketProc notifyProc ) { ASSERT(g_api.socketStopListening); diff --git a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt index 035dbfcd..ce0441c4 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt +++ b/Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt @@ -5,7 +5,6 @@ set(pnUtils_HEADERS Pch.h pnUtils.h pnUtCoreLib.h - pnUtAddr.h pnUtAllIncludes.h pnUtArray.h pnUtCmd.h diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h deleted file mode 100644 index 555d459b..00000000 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h +++ /dev/null @@ -1,57 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -/***************************************************************************** -* -* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtAddr.h -* -***/ - -#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTADDR_H -#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTADDR_H - -#include "Pch.h" - -#include "pnNetCommon/plNetAddress.h" - -typedef plNetAddress NetAddress; - -#endif diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h index b21a5e9c..c252179c 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h @@ -51,7 +51,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnUtCoreLib.h" // must be first in list #include "pnUtPragma.h" -#include "pnUtAddr.h" #include "pnUtUuid.h" #include "pnUtSort.h" #include "pnUtArray.h" diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index 7f22b79a..4b8c51e7 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -1528,7 +1528,7 @@ static void Connect ( //============================================================================ static void Connect ( const char name[], - const NetAddress & addr + const plNetAddress& addr ) { ASSERT(s_running); @@ -5146,7 +5146,7 @@ void NetCliAuthStartConnect ( } } if (!name[0]) { - NetAddress addr(authAddrList[i], kNetDefaultClientPort); + plNetAddress addr(authAddrList[i], kNetDefaultClientPort); Connect(authAddrList[i], addr); } } diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp index e7025948..e3ed719b 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp @@ -73,7 +73,7 @@ struct CliCsConn : AtomicRef { AsyncSocket sock; AsyncCancelId cancelId; NetCli * cli; - NetAddress addr; + plNetAddress addr; unsigned seq; bool abandoned; unsigned serverChallenge; @@ -369,7 +369,7 @@ static bool SocketNotifyCallback ( //============================================================================ static void Connect ( - const NetAddress & addr, + const plNetAddress& addr, ConnectParam * cp ) { CliCsConn * conn = NEWZERO(CliCsConn); @@ -415,7 +415,7 @@ static void AsyncLookupCallback ( void * param, const char name[], unsigned addrCount, - const NetAddress addrs[] + const plNetAddress addrs[] ) { if (!addrCount) { ReportNetError(kNetProtocolCli2Auth, kNetErrNameLookupFailed); @@ -860,8 +860,8 @@ void NetCliCsrStartConnect ( } } if (!name[0]) { - NetAddress addr(addrList[i], kNetDefaultClientPort); - + plNetAddress addr(addrList[i], kNetDefaultClientPort); + ConnectParam * cp = new ConnectParam; cp->callback = callback; cp->param = param; diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp index bb272328..3243669b 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglFile.cpp @@ -65,7 +65,7 @@ struct CliFileConn : AtomicRef { CLock sockLock; // to protect the socket pointer so we don't nuke it while using it AsyncSocket sock; char name[MAX_PATH]; - NetAddress addr; + plNetAddress addr; unsigned seq; ARRAY(uint8_t) recvBuffer; AsyncCancelId cancelId; @@ -540,7 +540,7 @@ static void Connect (CliFileConn * conn) { //============================================================================ static void Connect ( const char name[], - const NetAddress & addr + const plNetAddress& addr ) { ASSERT(s_running); @@ -561,7 +561,7 @@ static void AsyncLookupCallback ( void * param, const char name[], unsigned addrCount, - const NetAddress addrs[] + const plNetAddress addrs[] ) { if (!addrCount) { ReportNetError(kNetProtocolCli2File, kNetErrNameLookupFailed); @@ -1362,7 +1362,7 @@ void NetCliFileStartConnect ( } } if (!name[0]) { - NetAddress addr(fileAddrList[i], kNetDefaultClientPort); + plNetAddress addr(fileAddrList[i], kNetDefaultClientPort); Connect(fileAddrList[i], addr); } } @@ -1399,7 +1399,7 @@ void NetCliFileStartConnectAsServer ( } } if (!name[0]) { - NetAddress addr(fileAddrList[i], kNetDefaultServerPort); + plNetAddress addr(fileAddrList[i], kNetDefaultServerPort); Connect(fileAddrList[i], addr); } } diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp index 9210ca24..a2d2ef7e 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp @@ -62,7 +62,7 @@ struct CliGmConn : AtomicRef { AsyncSocket sock; AsyncCancelId cancelId; NetCli * cli; - NetAddress addr; + plNetAddress addr; unsigned seq; bool abandoned; @@ -354,7 +354,7 @@ static bool SocketNotifyCallback ( //============================================================================ static void Connect ( - const NetAddress & addr + const plNetAddress& addr ) { CliGmConn * conn = NEWZERO(CliGmConn); conn->addr = addr; diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp index 03f99cba..5e7ca09d 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp @@ -90,7 +90,7 @@ struct CliGkConn : AtomicRef { AsyncSocket sock; NetCli * cli; char name[MAX_PATH]; - NetAddress addr; + plNetAddress addr; Uuid token; unsigned seq; unsigned serverChallenge; @@ -464,7 +464,7 @@ static void Connect ( //============================================================================ static void Connect ( const char name[], - const NetAddress & addr + const plNetAddress& addr ) { ASSERT(s_running); @@ -483,7 +483,7 @@ static void AsyncLookupCallback ( void * param, const char name[], unsigned addrCount, - const NetAddress addrs[] + const plNetAddress addrs[] ) { if (!addrCount) { ReportNetError(kNetProtocolCli2GateKeeper, kNetErrNameLookupFailed); @@ -1076,7 +1076,7 @@ void NetCliGateKeeperStartConnect ( } } if (!name[0]) { - NetAddress addr(gateKeeperAddrList[i], kNetDefaultClientPort); + plNetAddress addr(gateKeeperAddrList[i], kNetDefaultClientPort); Connect(gateKeeperAddrList[i], addr); } } From 883ce6fcbfe344859ddb41eefa043930067405dd Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Tue, 27 Mar 2012 21:32:02 -0700 Subject: [PATCH 32/37] Doxygen plNetAddress to make it less confusing. --- .../NucleusLib/pnNetCommon/plNetAddress.cpp | 12 -- .../NucleusLib/pnNetCommon/plNetAddress.h | 113 +++++++++++++++++- 2 files changed, 111 insertions(+), 14 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp index 52ad0ae0..6784dfe8 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp @@ -107,11 +107,6 @@ uint32_t plNetAddress::GetHost() const return fAddr.sin_addr.s_addr; } -uint32_t plNetAddress::GetHostLE() const -{ - return ntohl(fAddr.sin_addr.s_addr); -} - plString plNetAddress::GetHostWithPort() const { plStringStream ss; @@ -133,13 +128,6 @@ bool plNetAddress::SetHost(uint32_t addr) return true; } -bool plNetAddress::SetHostLE(uint32_t addr) -{ - fAddr.sin_addr.s_addr = htonl(addr); - fAddr.sin_family = AF_INET; - return true; -} - plString plNetAddress::AsString() const { plStringStream ss; diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h index 645d7fe0..bf699251 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h @@ -68,46 +68,155 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com typedef sockaddr_in AddressType; +/** + * A class representing a network address endpoint, as a pair of host address + * and port number. + * + * Internally, this class stores the network address using the sockaddr_in + * structure, but provides methods to transparently get and set the host + * address and port. + */ class plNetAddress { // fAddr must be first field AddressType fAddr; public: + /** + * Initializes an empty network address. + * All the fields of the sockaddr will be zeroed. + */ plNetAddress(); + + /** + * Initializes a new network address from the given IPv4 address and port + * number. + * + * @param addr The IPv4 address as a 32-bit network byte order integer. + * @param port The port number as a 16-bit host order integer. + */ plNetAddress(uint32_t addr, uint16_t port); + + /** + * Initializes a new network address from the given hostname and port + * number. + * + * @param addr The DNS hostname of the host. + * @param port The port number as a 16-bit host order integer. + */ plNetAddress(const char* addr, uint16_t port); + virtual ~plNetAddress(){} bool operator==(const plNetAddress& other) const { return (GetHost() == other.GetHost()) && (GetPort() == other.GetPort()); } + bool operator!=(const plNetAddress& other) const { return !(*this == other); } + /** + * Clears the address and zeros out the sockaddr fields. + */ void Clear(); + /** + * Sets the address to INADDR_ANY for binding to any host. + */ bool SetAnyAddr(); + + /** + * Sets the port number to 0 to allow binding to any port. + */ bool SetAnyPort(); + /** + * Gets the port number of the host. + * + * @return The host port number. + */ uint16_t GetPort() const; + + /** + * Sets the port number of the host. + * + * @param port The port number in host byte order. + */ bool SetPort(uint16_t port); + /** + * Gets the IPv4 address of the host as a 32-bit integer in network byte + * order (big endian). + * + * @return The IPv4 host address. + */ uint32_t GetHost() const; - uint32_t GetHostLE() const; + + /** + * Sets the IPv4 address of the host from a DNS name. + * + * @param hostname The DNS name of the host. + */ bool SetHost(const char* hostname); + + /** + * Sets the IPv4 address of the host from an unsigned 32-bit integer in + * network byte order (big endian). + * + * @param ip4addr The host IPv4 address in network byte order. + */ bool SetHost(uint32_t ip4addr); - bool SetHostLE(uint32_t addr); + /** + * Retrieves the internal address type. + * + * @return A constant sockaddr_in. + */ const AddressType& GetAddressInfo() const { return fAddr; } + + /** + * Retrieves the internal address type. + * + * @return A sockaddr_in. + */ AddressType& GetAddressInfo() { return fAddr; } + /** + * Returns the IPv4 address of the host as a string in 4-octet dotted + * notation. + * + * @return A string of the IPv4 host address. + */ plString GetHostString() const; + + /** + * Return the IPv4 address and port number of the host as a string in + * 4-octet dotted notation with a colon separated port. + * + * @return A string of the IPv4 host address and port number. + */ plString GetHostWithPort() const; + + /** + * Returns a string representation of the host address and port number. + * + * @return A string representation of the address. + */ plString AsString() const; + /** + * Reads and deserializes the address from a stream. + * + * @param stream The stream from which to read the address. + */ void Read(hsStream * stream); + + /** + * Serializes and writes the address to a stream. + * + * @param stream The stream to which to write the address. + */ void Write(hsStream * stream); }; From bb200c5b30db0d503034cf91d0459f1fafc45bf3 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Tue, 27 Mar 2012 23:10:54 -0700 Subject: [PATCH 33/37] Make sure plNetAddress is included correctly. --- Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h | 2 ++ Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/pnAceInt.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h b/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h index a09be9af..5fd04990 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h +++ b/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h @@ -50,6 +50,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #endif #define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNASYNCCORE_PRIVATE_PNACIO_H +#include "pnNetCommon/plNetAddress.h" + /**************************************************************************** * diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/pnAceInt.h b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/pnAceInt.h index 9517e798..4aa1274a 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/pnAceInt.h +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/pnAceInt.h @@ -50,6 +50,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #endif #define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNASYNCCOREEXE_PRIVATE_PNACEINT_H +#include "pnNetCommon/plNetAddress.h" + /***************************************************************************** * From 1fa981d09e6e391312f0b4aafe1c93898b800c59 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Fri, 30 Mar 2012 22:03:55 -0700 Subject: [PATCH 34/37] plUUID operator< should return a bool. --- Sources/Plasma/NucleusLib/pnUUID/pnUUID.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnUUID/pnUUID.h b/Sources/Plasma/NucleusLib/pnUUID/pnUUID.h index 10810071..567fd0b5 100644 --- a/Sources/Plasma/NucleusLib/pnUUID/pnUUID.h +++ b/Sources/Plasma/NucleusLib/pnUUID/pnUUID.h @@ -80,9 +80,16 @@ public: void Read( hsStream * s ); void Write( hsStream * s ); operator plString ( void ) const { return AsString();} - bool operator==( const plUUID & other ) const { return IsEqualTo( &other ); } - bool operator!=( const plUUID & other ) const { return !IsEqualTo( &other ); } - int operator <( const plUUID & other ) const { return CompareTo( &other ); } + + bool operator==(const plUUID& other) const { + return IsEqualTo(&other); + } + bool operator!=(const plUUID& other) const { + return !IsEqualTo(&other); + } + bool operator<(const plUUID& other) const { + return CompareTo(&other) == -1; + } operator Uuid () const; static plUUID Generate(); From 863247f0dd5c64e460b427989cff970cefddba02 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 7 Apr 2012 14:54:36 -0700 Subject: [PATCH 35/37] Another attempt to fix the std::list in NLM. --- Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp index a6015300..f2f08b61 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp @@ -271,7 +271,7 @@ void plNetLinkingMgr::ExecNextOp () { break; } - s_opqueue.pop_front(); + s_opqueue.remove(op); delete op; } From 60aa7e421e943ed955ea07d8ef64eeb7a5c50052 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 7 Apr 2012 16:01:30 -0700 Subject: [PATCH 36/37] Swap the IP address returned by AuthSrv. --- Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index 4b8c51e7..684b48c4 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -2754,7 +2754,7 @@ bool AgeRequestTrans::Send () { //============================================================================ void AgeRequestTrans::Post () { plNetAddress addr; - addr.SetHost(m_gameSrvNode); + addr.SetHost(htonl(m_gameSrvNode)); m_callback( m_result, From b1d65a194afef0d2c4dba09b815eec1976666673 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Sat, 14 Apr 2012 16:26:24 -0700 Subject: [PATCH 37/37] Fix memory corruption with DNS lookups. Thanks @Mystler for finding and reporting this, and thanks @Hoikas for investigating and confirming the fix. --- .../Private/Win32/pnAceW32Dns.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp index 3aa557b3..948727ab 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp @@ -88,9 +88,6 @@ static unsigned s_nextLookupCancelId = 1; //=========================================================================== static void LookupProcess (Lookup * lookup, unsigned error) { - unsigned count = 0; - plNetAddress* addrs = nil; - if (error) return; @@ -104,20 +101,14 @@ static void LookupProcess (Lookup * lookup, unsigned error) { in_addr const * const * const inAddr = (in_addr **) host.h_addr_list; - // count the number of addresses - while (inAddr[count]) - ++count; - // allocate a buffer large enough to hold all the addresses - addrs = new plNetAddress[count]; + size_t count = arrsize(inAddr); + plNetAddress* addrs = new plNetAddress[count]; // fill in address data - const uint16_t port = htons((uint16_t) lookup->port); - for (unsigned i = 0; i < count; ++i) { - sockaddr_in * inetaddr = (sockaddr_in *) &addrs[i]; - inetaddr->sin_family = AF_INET; - inetaddr->sin_addr = *inAddr[i]; - inetaddr->sin_port = port; + for (size_t i = 0; i < count; ++i) { + addrs[i].SetHost(inAddr[i]->S_un.S_addr); + addrs[i].SetPort(lookup->port); } if (host.h_name && host.h_name[0])