Browse Source

Remove almost all uses of NetAddress.

This probably has a bunch of bugs because of Network Order/Host Order
issues. If we intend to actually support BE architectures, these
problems are going to get much much worse :(
Darryl Pogue 13 years ago
parent
commit
4737e791cb
  1. 5
      Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp
  2. 7
      Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp
  3. 9
      Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp
  4. 12
      Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp
  5. 2
      Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h
  6. 35
      Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Addr.cpp
  7. 19
      Sources/Plasma/NucleusLib/pnUtils/pnUtAddr.h
  8. 9
      Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp
  9. 9
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp
  10. 3
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h

5
Sources/Plasma/FeatureLib/pfCsrSrv/pfCsrSrv.cpp

@ -115,9 +115,8 @@ static bool QueryAccept (
SimpleNetConn * , SimpleNetConn * ,
const NetAddress & addr const NetAddress & addr
) { ) {
wchar_t str[64]; plString str = addr.AsString();
NetAddressToString(addr, str, arrsize(str), kNetAddressFormatAll); LogMsg(kLogPerf, L"pfCsrSrv: Accepted connection from %s", str.c_str());
LogMsg(kLogPerf, L"pfCsrSrv: Accepted connection from %s", str);
return channel == kSimpleNetChannelCsr; return channel == kSimpleNetChannelCsr;
} }

7
Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Nt/pnAceNtSocket.cpp

@ -547,12 +547,11 @@ static SOCKET ListenSocket (NetAddress * listenAddr) {
sockaddr_in addr; sockaddr_in addr;
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_port = htons((uint16_t)port); 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)); memset(addr.sin_zero, 0, sizeof(addr.sin_zero));
if (bind(s, (sockaddr *) &addr, sizeof(addr))) { if (bind(s, (sockaddr *) &addr, sizeof(addr))) {
wchar_t str[32]; plString str = listenAddr->AsString();
NetAddressToString(*listenAddr, str, arrsize(str), kNetAddressFormatAll); LogMsg(kLogError, "bind to addr %s failed (err %u)", str.c_str(), WSAGetLastError());
LogMsg(kLogError, "bind to addr %s failed (err %u)", str, WSAGetLastError());
break; break;
} }

9
Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp

@ -340,12 +340,9 @@ void AsyncAddressLookupAddr (
lookup->lookupProc = lookupProc; lookup->lookupProc = lookupProc;
lookup->port = 1; lookup->port = 1;
lookup->param = param; lookup->param = param;
NetAddressToString(
address, plString str = address.GetHostString();
lookup->name, lookup->name = str.toUtf16().GetData();
arrsize(lookup->name),
kNetAddressFormatNodeNumber
);
s_critsect.Enter(); s_critsect.Enter();
{ {

12
Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp

@ -103,6 +103,11 @@ plString plNetAddress::GetHostString() const
} }
uint32_t plNetAddress::GetHost() const uint32_t plNetAddress::GetHost() const
{
return ntohl(fAddr.sin_addr.s_addr);
}
uint32_t plNetAddress::GetHostBE() const
{ {
return fAddr.sin_addr.s_addr; return fAddr.sin_addr.s_addr;
} }
@ -122,6 +127,13 @@ bool plNetAddress::SetHost(const char* hostname)
} }
bool plNetAddress::SetHost(uint32_t addr) 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)); memcpy(&fAddr.sin_addr, &addr,sizeof(addr));
fAddr.sin_family = AF_INET; fAddr.sin_family = AF_INET;

2
Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h

@ -95,8 +95,10 @@ public:
bool SetPort(uint16_t port); bool SetPort(uint16_t port);
uint32_t GetHost() const; uint32_t GetHost() const;
uint32_t GetHostBE() const;
bool SetHost(const char* hostname); bool SetHost(const char* hostname);
bool SetHost(uint32_t ip4addr); bool SetHost(uint32_t ip4addr);
bool SetHostBE(uint32_t addr);
const AddressType& GetAddressInfo() const { return fAddr; } const AddressType& GetAddressInfo() const { return fAddr; }
AddressType& GetAddressInfo() { return fAddr; } AddressType& GetAddressInfo() { return fAddr; }

35
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) { bool NetAddressFromString (NetAddress * addr, const wchar_t str[], unsigned defaultPort) {
ASSERT(addr); ASSERT(addr);
@ -146,14 +122,3 @@ bool NetAddressFromString (NetAddress * addr, const wchar_t str[], unsigned defa
// address already zeroed // address already zeroed
return false; 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));
}

19
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) // '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 // - names which require DNS lookup will cause the function to return false
bool NetAddressFromString ( bool NetAddressFromString (
@ -95,10 +82,4 @@ bool NetAddressFromString (
unsigned defaultPort unsigned defaultPort
); );
void NetAddressNodeToString (
NetAddressNode node,
wchar_t * str,
unsigned chars
);
#endif #endif

9
Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp

@ -591,23 +591,22 @@ static void INetCliAuthAgeRequestCallback (
unsigned ageMcpId, unsigned ageMcpId,
unsigned ageVaultId, unsigned ageVaultId,
const Uuid & ageInstId, const Uuid & ageInstId,
NetAddressNode gameAddr plNetAddress gameAddr
) { ) {
if (!IS_NET_ERROR(result) || result == kNetErrVaultNodeNotFound) { if (!IS_NET_ERROR(result) || result == kNetErrVaultNodeNotFound) {
s_age.ageInstId = ageInstId; s_age.ageInstId = ageInstId;
s_age.ageVaultId = ageVaultId; s_age.ageVaultId = ageVaultId;
wchar_t gameAddrStr[64];
wchar_t ageInstIdStr[64]; wchar_t ageInstIdStr[64];
NetAddressNodeToString(gameAddr, gameAddrStr, arrsize(gameAddrStr)); plString gameAddrStr = gameAddr.GetHostString();
LogMsg( LogMsg(
kLogPerf, kLogPerf,
L"Connecting to game server %s, ageInstId %s", L"Connecting to game server %s, ageInstId %s",
gameAddrStr, gameAddrStr.c_str(),
GuidToString(ageInstId, ageInstIdStr, arrsize(ageInstIdStr)) GuidToString(ageInstId, ageInstIdStr, arrsize(ageInstIdStr))
); );
NetCliGameDisconnect(); NetCliGameDisconnect();
NetCliGameStartConnect(gameAddr); NetCliGameStartConnect(gameAddr.GetHost());
NetCliGameJoinAgeRequest( NetCliGameJoinAgeRequest(
ageMcpId, ageMcpId,
s_account.accountUuid, s_account.accountUuid,

9
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp

@ -91,7 +91,7 @@ struct CliAuConn : AtomicRef {
AsyncSocket sock; AsyncSocket sock;
NetCli * cli; NetCli * cli;
wchar_t name[MAX_PATH]; wchar_t name[MAX_PATH];
NetAddress addr; plNetAddress addr;
Uuid token; Uuid token;
unsigned seq; unsigned seq;
unsigned serverChallenge; unsigned serverChallenge;
@ -1547,7 +1547,7 @@ static void AsyncLookupCallback (
void * param, void * param,
const wchar_t name[], const wchar_t name[],
unsigned addrCount, unsigned addrCount,
const NetAddress addrs[] const plNetAddress addrs[]
) { ) {
if (!addrCount) { if (!addrCount) {
ReportNetError(kNetProtocolCli2Auth, kNetErrNameLookupFailed); ReportNetError(kNetProtocolCli2Auth, kNetErrNameLookupFailed);
@ -2753,13 +2753,16 @@ bool AgeRequestTrans::Send () {
//============================================================================ //============================================================================
void AgeRequestTrans::Post () { void AgeRequestTrans::Post () {
plNetAddress addr;
addr.SetHost(m_gameSrvNode);
m_callback( m_callback(
m_result, m_result,
m_param, m_param,
m_ageMcpId, m_ageMcpId,
m_ageVaultId, m_ageVaultId,
m_ageInstId, m_ageInstId,
m_gameSrvNode addr
); );
} }

3
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h

@ -50,6 +50,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#endif #endif
#define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLAUTH_H #define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PRIVATE_PLNGLAUTH_H
#include "pnNetCommon/plNetAddress.h"
/***************************************************************************** /*****************************************************************************
* *
@ -326,7 +327,7 @@ typedef void (*FNetCliAuthAgeRequestCallback)(
unsigned ageMcpId, unsigned ageMcpId,
unsigned ageVaultId, unsigned ageVaultId,
const Uuid & ageInstId, const Uuid & ageInstId,
NetAddressNode gameAddr plNetAddress gameAddr
); );
void NetCliAuthAgeRequest ( void NetCliAuthAgeRequest (
const wchar_t ageName[], // L"Teledahn" const wchar_t ageName[], // L"Teledahn"

Loading…
Cancel
Save