Browse Source

Merge branch 'plNetAddress' into kill_utils

Darryl Pogue 13 years ago
parent
commit
7bd51c923f
  1. 52
      Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.cpp
  2. 28
      Sources/Plasma/NucleusLib/pnNetCommon/plNetAddress.h
  3. 16
      Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.cpp
  4. 7
      Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.h
  5. 12
      Sources/Plasma/PubUtilLib/plAvatar/plAvBrainGeneric.cpp

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

@ -50,47 +50,41 @@ plNetAddress::plNetAddress()
Clear();
}
plNetAddress::plNetAddress(uint32_t addr, int port)
plNetAddress::plNetAddress(uint32_t addr, uint16_t port)
{
Clear();
SetHost(addr);
SetPort(port);
}
plNetAddress::plNetAddress(const char * addr, int port)
plNetAddress::plNetAddress(const char * addr, uint16_t port)
{
Clear();
SetHost(addr);
SetPort(port);
}
bool plNetAddress::SetAnyAddr()
{
{
fAddr.sin_family = AF_INET;
fAddr.sin_addr.s_addr = INADDR_ANY;
return true;
}
bool plNetAddress::SetAnyPort()
{
{
fAddr.sin_family = AF_INET;
fAddr.sin_port = htons(0);
return true;
}
bool plNetAddress::SetPort(int port)
{
bool plNetAddress::SetPort(uint16_t port)
{
fAddr.sin_family = AF_INET;
fAddr.sin_port = htons(port);
return true;
}
void plNetAddress::Clear()
{
memset(&fAddr,0,sizeof(fAddr));
@ -98,16 +92,14 @@ void plNetAddress::Clear()
fAddr.sin_addr.s_addr = INADDR_ANY;
}
int plNetAddress::GetPort() const
uint16_t plNetAddress::GetPort() const
{
return ntohs(fAddr.sin_port);
}
std::string plNetAddress::GetHostString() const
plString plNetAddress::GetHostString() const
{
return std::string(pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr));
return pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr);
}
uint32_t plNetAddress::GetHost() const
@ -115,37 +107,35 @@ uint32_t plNetAddress::GetHost() const
return fAddr.sin_addr.s_addr;
}
std::string plNetAddress::GetHostWithPort() const
plString plNetAddress::GetHostWithPort() const
{
static const int buf_len = 1024;
char buf[buf_len];
sprintf(buf,"%s:%d",pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr),GetPort());
return std::string(buf);
plStringStream ss;
ss << pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr) << ":" << GetPort();
return ss.GetString();
}
bool plNetAddress::SetHost(const char * hostname)
bool plNetAddress::SetHost(const char* hostname)
{
fAddr.sin_addr.s_addr = pnNetCommon::GetBinAddr(hostname);
fAddr.sin_family = AF_INET;
return true;
}
bool plNetAddress::SetHost(uint32_t addr)
bool plNetAddress::SetHost(uint32_t addr)
{
memcpy(&fAddr.sin_addr, &addr,sizeof(addr));
fAddr.sin_family = AF_INET;
return true;
}
std::string plNetAddress::AsString() const
plString plNetAddress::AsString() const
{
char buf[100] = "";
sprintf(buf,"IP:%s:%d",pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr),GetPort());
return std::string(buf);
}
plStringStream ss;
ss << "IP:" << pnNetCommon::GetTextAddr(fAddr.sin_addr.s_addr);
ss << ":" << GetPort();
return ss.GetString();
}
void plNetAddress::Read(hsStream * s)
{

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

@ -44,6 +44,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef plNetAddress_h_inc
#define plNetAddress_h_inc
#include "HeadSpin.h"
#include "plString.h"
#include "hsStlUtils.h"
#include "hsStream.h"
@ -73,24 +75,28 @@ class plNetAddress
public:
plNetAddress();
plNetAddress(uint32_t addr, int port);
plNetAddress(const char * addr, int port);
plNetAddress(uint32_t addr, uint16_t port);
plNetAddress(const char* addr, uint16_t port);
virtual ~plNetAddress(){}
void Clear();
bool SetAnyAddr();
bool SetAnyPort();
bool SetPort(int port);
bool SetHost(const char * hostname);
bool SetHost(uint32_t ip4addr);
int GetPort() const;
std::string GetHostString() const;
uint16_t GetPort() const;
bool SetPort(uint16_t port);
uint32_t GetHost() const;
std::string GetHostWithPort() const;
const AddressType & GetAddressInfo() const { return fAddr; }
AddressType & GetAddressInfo() { return fAddr; }
bool SetHost(const char* hostname);
bool SetHost(uint32_t ip4addr);
const AddressType& GetAddressInfo() const { return fAddr; }
AddressType& GetAddressInfo() { return fAddr; }
std::string AsString() const;
plString GetHostString() const;
plString GetHostWithPort() const;
plString AsString() const;
void Read(hsStream * stream);
void Write(hsStream * stream);

16
Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.cpp

@ -57,23 +57,23 @@ namespace pnNetCommon
#ifndef SERVER
// NOTE: On Win32, WSAStartup() must be called before GetTextAddr() will work.
const char * GetTextAddr(uint32_t binAddr)
plString GetTextAddr(uint32_t binAddr)
{
in_addr in;
memcpy(&in,&binAddr,sizeof(binAddr));
return inet_ntoa(in);
memcpy(&in, &binAddr, sizeof(binAddr));
return plString::Format("%s", inet_ntoa(in));
}
// NOTE: On Win32, WSAStartup() must be called before GetBinAddr() will work.
uint32_t GetBinAddr(const char * textAddr)
{
uint32_t addr = 0;
if (!textAddr)
return addr;
struct addrinfo * ai = NULL;
struct addrinfo* ai = NULL;
addr = inet_addr(textAddr);
if(addr == INADDR_NONE)
{
@ -82,7 +82,7 @@ uint32_t GetBinAddr(const char * textAddr)
memcpy(&addr,(void*)(&(((sockaddr_in*)(ai->ai_addr))->sin_addr)),sizeof(addr));
pnAddrInfo::Free(ai);
}
return addr;
}

7
Sources/Plasma/NucleusLib/pnNetCommon/pnNetCommon.h

@ -43,6 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define pnNetCommon_h_inc
#include "HeadSpin.h"
#include "plString.h"
#include "hsStlUtils.h"
#include "hsRefCnt.h"
#include "hsStream.h"
@ -81,9 +82,9 @@ namespace pnNetCommon
{
#ifndef SERVER
uint32_t GetBinAddr(const char * textAddr);
const char * GetTextAddr(uint32_t binAddr);
uint32_t GetBinAddr(const char* textAddr);
plString GetTextAddr(uint32_t binAddr);
#endif // SERVER
}

12
Sources/Plasma/PubUtilLib/plAvatar/plAvBrainGeneric.cpp

@ -170,12 +170,6 @@ void plAvBrainGeneric::Activate(plArmatureModBase *avMod)
{
plArmatureBrain::Activate(avMod);
if ((GetType() == kEmote || GetType() == kAFK || GetType() == kSitOnGround) && fAvMod->IsLocalAvatar())
{
plInputIfaceMgrMsg* msg = new plInputIfaceMgrMsg(plInputIfaceMgrMsg::kDisableClickables );
plgDispatch::MsgSend(msg);
}
int numStages = fStages->size();
if (!numStages)
return;
@ -315,12 +309,6 @@ void plAvBrainGeneric::Deactivate()
}
plArmatureBrain::Deactivate();
if ((GetType() == kEmote || GetType() == kAFK || GetType() == kSitOnGround) && fAvMod->IsLocalAvatar())
{
plInputIfaceMgrMsg* msg = new plInputIfaceMgrMsg(plInputIfaceMgrMsg::kEnableClickables );
plgDispatch::MsgSend(msg);
}
}
// GETRECIPIENT

Loading…
Cancel
Save