diff --git a/Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp b/Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp index bf222139..01ead690 100644 --- a/Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp +++ b/Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp @@ -115,9 +115,8 @@ static bool QueryAccept ( SimpleNetConn * , const NetAddress & addr ) { - wchar_t str[64]; - NetAddressToString(addr, str, arrsize(str), kNetAddressFormatAll); - LogMsg(kLogPerf, L"pfCsrSrv: Accepted connection from %s", str); + plString str = addr.AsString(); + LogMsg(kLogPerf, L"pfCsrSrv: Accepted connection from %s", str.c_str()); return channel == kSimpleNetChannelCsr; } diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp index f71854d2..3f6a78e4 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp @@ -547,12 +547,11 @@ static SOCKET ListenSocket (NetAddress * listenAddr) { sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons((uint16_t)port); - addr.sin_addr.S_un.S_addr = htonl(node); + addr.sin_addr.S_un.S_addr = node; memset(addr.sin_zero, 0, sizeof(addr.sin_zero)); if (bind(s, (sockaddr *) &addr, sizeof(addr))) { - wchar_t str[32]; - NetAddressToString(*listenAddr, str, arrsize(str), kNetAddressFormatAll); - LogMsg(kLogError, "bind to addr %s failed (err %u)", str, WSAGetLastError()); + plString str = listenAddr->AsString(); + LogMsg(kLogError, "bind to addr %s failed (err %u)", str.c_str(), WSAGetLastError()); break; } diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp index 4b44f696..a88fb019 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp @@ -340,13 +340,10 @@ void AsyncAddressLookupAddr ( lookup->lookupProc = lookupProc; lookup->port = 1; lookup->param = param; - NetAddressToString( - address, - lookup->name, - arrsize(lookup->name), - kNetAddressFormatNodeNumber - ); - + + plString str = address.GetHostString(); + lookup->name = str.toUtf16().GetData(); + s_critsect.Enter(); { // Start the lookup thread if it wasn't started already diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp index 60a3c541..3012e62d 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp @@ -57,7 +57,7 @@ plNetAddress::plNetAddress(uint32_t addr, uint16_t port) SetPort(port); } -plNetAddress::plNetAddress(const char * addr, uint16_t port) +plNetAddress::plNetAddress(const char* addr, uint16_t port) { Clear(); SetHost(addr); @@ -103,6 +103,11 @@ plString plNetAddress::GetHostString() const } uint32_t plNetAddress::GetHost() const +{ + return ntohl(fAddr.sin_addr.s_addr); +} + +uint32_t plNetAddress::GetHostBE() const { return fAddr.sin_addr.s_addr; } @@ -122,6 +127,13 @@ bool plNetAddress::SetHost(const char* hostname) } bool plNetAddress::SetHost(uint32_t addr) +{ + fAddr.sin_addr.s_addr = htonl(addr); + fAddr.sin_family = AF_INET; + return true; +} + +bool plNetAddress::SetHostBE(uint32_t addr) { memcpy(&fAddr.sin_addr, &addr,sizeof(addr)); fAddr.sin_family = AF_INET; diff --git a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h index 761fad44..3841fc6b 100644 --- a/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h +++ b/Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h @@ -95,8 +95,10 @@ public: bool SetPort(uint16_t port); uint32_t GetHost() const; + uint32_t GetHostBE() const; bool SetHost(const char* hostname); bool SetHost(uint32_t ip4addr); + bool SetHostBE(uint32_t addr); const AddressType& GetAddressInfo() const { return fAddr; } AddressType& GetAddressInfo() { return fAddr; } diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp index d52accf2..81e91089 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp @@ -94,30 +94,6 @@ static NetAddressNode NodeFromString (const wchar_t * string[]) { * ***/ -//=========================================================================== -void NetAddressToString ( - const NetAddress & addr, - wchar_t * str, - unsigned chars, - ENetAddressFormat format -) { - ASSERT(str); - - static const wchar_t * s_fmts[] = { - L"%S", // kNetAddressFormatNodeNumber - L"%S:%u", // kNetAddressFormatAll - }; - ASSERT(format < arrsize(s_fmts)); - const sockaddr_in & inetaddr = * (const sockaddr_in *) &addr; - StrPrintf( - str, - chars, - s_fmts[format], - inet_ntoa(inetaddr.sin_addr), - ntohs(inetaddr.sin_port) - ); -} - //=========================================================================== bool NetAddressFromString (NetAddress * addr, const wchar_t str[], unsigned defaultPort) { ASSERT(addr); @@ -146,14 +122,3 @@ bool NetAddressFromString (NetAddress * addr, const wchar_t str[], unsigned defa // address already zeroed return false; } - -//=========================================================================== -void NetAddressNodeToString ( - NetAddressNode node, - wchar_t * str, - unsigned chars -) { - in_addr addr; - addr.S_un.S_addr = htonl(node); - StrPrintf(str, chars, L"%S", inet_ntoa(addr)); -} diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h index 2143fe53..1a4cab8e 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h @@ -74,19 +74,6 @@ typedef uint32_t NetAddressNode; * ***/ -enum ENetAddressFormat { - kNetAddressFormatNodeNumber, - kNetAddressFormatAll, - kNumNetAddressFormats -}; - -void NetAddressToString ( - const NetAddress & addr, - wchar_t * str, - unsigned chars, - ENetAddressFormat format -); - // 'str' must be in the form of a dotted IP address (IPv4 or IPv6) // - names which require DNS lookup will cause the function to return false bool NetAddressFromString ( @@ -95,10 +82,4 @@ bool NetAddressFromString ( unsigned defaultPort ); -void NetAddressNodeToString ( - NetAddressNode node, - wchar_t * str, - unsigned chars -); - #endif diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp index fb403161..ac7dcf80 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp @@ -591,23 +591,22 @@ static void INetCliAuthAgeRequestCallback ( unsigned ageMcpId, unsigned ageVaultId, const Uuid & ageInstId, - NetAddressNode gameAddr + plNetAddress gameAddr ) { if (!IS_NET_ERROR(result) || result == kNetErrVaultNodeNotFound) { s_age.ageInstId = ageInstId; s_age.ageVaultId = ageVaultId; - wchar_t gameAddrStr[64]; wchar_t ageInstIdStr[64]; - NetAddressNodeToString(gameAddr, gameAddrStr, arrsize(gameAddrStr)); + plString gameAddrStr = gameAddr.GetHostString(); LogMsg( kLogPerf, L"Connecting to game server %s, ageInstId %s", - gameAddrStr, + gameAddrStr.c_str(), GuidToString(ageInstId, ageInstIdStr, arrsize(ageInstIdStr)) ); NetCliGameDisconnect(); - NetCliGameStartConnect(gameAddr); + NetCliGameStartConnect(gameAddr.GetHost()); NetCliGameJoinAgeRequest( ageMcpId, s_account.accountUuid, diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index b91b11aa..2b5e8513 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -90,8 +90,8 @@ struct CliAuConn : AtomicRef { LINK(CliAuConn) link; AsyncSocket sock; NetCli * cli; - wchar_t name[MAX_PATH]; - NetAddress addr; + wchar_t name[MAX_PATH]; + plNetAddress addr; Uuid token; unsigned seq; unsigned serverChallenge; @@ -1545,9 +1545,9 @@ static void Connect ( //============================================================================ static void AsyncLookupCallback ( void * param, - const wchar_t name[], + const wchar_t name[], unsigned addrCount, - const NetAddress addrs[] + const plNetAddress addrs[] ) { if (!addrCount) { ReportNetError(kNetProtocolCli2Auth, kNetErrNameLookupFailed); @@ -2753,13 +2753,16 @@ bool AgeRequestTrans::Send () { //============================================================================ void AgeRequestTrans::Post () { + plNetAddress addr; + addr.SetHost(m_gameSrvNode); + m_callback( m_result, m_param, m_ageMcpId, m_ageVaultId, m_ageInstId, - m_gameSrvNode + addr ); } diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h index 6637909f..f19b6944 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h @@ -50,6 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #endif #define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLAUTH_H +#include "pnNetCommon/plNetAddress.h" /***************************************************************************** * @@ -326,7 +327,7 @@ typedef void (*FNetCliAuthAgeRequestCallback)( unsigned ageMcpId, unsigned ageVaultId, const Uuid & ageInstId, - NetAddressNode gameAddr + plNetAddress gameAddr ); void NetCliAuthAgeRequest ( const wchar_t ageName[], // L"Teledahn"