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. 11
      Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/Win32/pnAceW32Dns.cpp
  4. 14
      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. 13
      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 * ,
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;
}

7
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;
}

11
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

14
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;

2
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; }

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) {
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));
}

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)
// - 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

9
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,

13
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
);
}

3
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"

Loading…
Cancel
Save