Adam Johnson
13 years ago
96 changed files with 890 additions and 5687 deletions
@ -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}) |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 (); |
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 <process.h> |
||||
#include <IPExport.h> |
||||
#include <IPTypes.h> |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 = NetAddressGetNode(addrs[0]); |
||||
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); |
||||
} |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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); |
||||
} |
@ -1,858 +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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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<unsigned> { |
||||
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<unsigned> { |
||||
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<unsigned>, |
||||
link |
||||
) s_authTrans; |
||||
|
||||
static HASHTABLEDECL( |
||||
FileTrans, |
||||
THashKeyVal<unsigned>, |
||||
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<unsigned>, |
||||
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<unsigned>, |
||||
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, |
||||
BigNum(sizeof(kAuthDhXData), kAuthDhXData), |
||||
BigNum(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;
|
||||
NetAddress addr; |
||||
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; |
||||
} |
||||
|
||||
NetAddressFromNode(node, port, &addr); |
||||
|
||||
switch (protocol) { |
||||
case kNetProtocolCli2Auth: |
||||
StartAuthTcpTest(diag, addr, dump, callback, param); |
||||
break; |
||||
|
||||
case kNetProtocolCli2File: |
||||
StartFileTcpTest(diag, addr, dump, callback, param); |
||||
break; |
||||
|
||||
DEFAULT_FATAL(protocol); |
||||
} |
||||
} |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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); |
||||
} |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
@ -1,177 +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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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); |
||||
} |
||||
|
||||
{ // 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"); |
||||
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); |
||||
} |
||||
} |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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" |
@ -1,387 +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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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" |
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* |
||||
* 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
|
||||
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 |
||||
* |
||||
***/ |
||||
|
||||
//===========================================================================
|
||||
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; |
||||
} |
||||
|
||||
//===========================================================================
|
||||
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,
|
||||
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); |
||||
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) |
||||
break; |
||||
|
||||
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
|
||||
|
||||
return true; |
||||
} |
||||
|
||||
// address already zeroed
|
||||
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, |
||||
wchar_t * str, |
||||
unsigned chars |
||||
) { |
||||
in_addr addr; |
||||
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; |
||||
} |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 |
||||
* |
||||
***/ |
||||
|
@ -1,95 +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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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" |
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* |
||||
* 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; |
@ -1,170 +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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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" |
||||
|
||||
/*****************************************************************************
|
||||
* |
||||
* Types and constants |
||||
* |
||||
***/ |
||||
|
||||
|
||||
struct NetAddress { |
||||
uint8_t data[24]; |
||||
}; |
||||
|
||||
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 |
||||
* |
||||
***/ |
||||
|
||||
enum ENetAddressFormat { |
||||
kNetAddressFormatNodeNumber, |
||||
kNetAddressFormatAll, |
||||
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; |
||||
} |
||||
|
||||
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 ( |
||||
NetAddress * addr, |
||||
const wchar_t str[], |
||||
unsigned defaultPort |
||||
); |
||||
|
||||
unsigned NetAddressGetPort ( |
||||
const NetAddress & addr |
||||
); |
||||
void NetAddressSetPort ( |
||||
unsigned port, |
||||
NetAddress * addr |
||||
); |
||||
|
||||
void NetAddressNodeToString ( |
||||
NetAddressNode node, |
||||
wchar_t * str, |
||||
unsigned chars |
||||
); |
||||
NetAddressNode NetAddressNodeFromString ( |
||||
const wchar_t string[], |
||||
const wchar_t * endPtr[] |
||||
); |
||||
|
||||
NetAddressNode NetAddressGetNode ( |
||||
const NetAddress & addr |
||||
); |
||||
void NetAddressFromNode ( |
||||
NetAddressNode node, |
||||
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 |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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; |
||||
} |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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; |
||||
} |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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); |
||||
} |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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; |
||||
} |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 <typeinfo> |
||||
|
||||
|
||||
#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 T> |
||||
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<class T> |
||||
void * TSpareList<T>::Alloc () { |
||||
return CBaseSpareList::Alloc(OBJECT_SIZE, typeid(T).name()); |
||||
} |
||||
|
||||
//===========================================================================
|
||||
template<class T> |
||||
void TSpareList<T>::CleanUp () { |
||||
CBaseSpareList::CleanUp(typeid(T).name()); |
||||
} |
||||
|
||||
//===========================================================================
|
||||
template<class T> |
||||
void TSpareList<T>::Delete (T * node) { |
||||
node->~T(); |
||||
CBaseSpareList::Free(node, OBJECT_SIZE); |
||||
} |
||||
|
||||
//===========================================================================
|
||||
template<class T> |
||||
void TSpareList<T>::Free (T * node) { |
||||
CBaseSpareList::Free(node, OBJECT_SIZE); |
||||
} |
||||
|
||||
//===========================================================================
|
||||
template<class T> |
||||
T * TSpareList<T>::New () { |
||||
return new(CBaseSpareList::Alloc(OBJECT_SIZE, typeid(T).name())) T; |
||||
} |
||||
#endif |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 |
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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 |
Loading…
Reference in new issue