mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
Fix pnNetCli for *nix.
Thanks to @zrax for breaking it originally :P Also switch another CCritSect over to hsMutex, and replace LIST with std::list.
This commit is contained in:
@ -46,6 +46,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
***/
|
***/
|
||||||
|
|
||||||
#include "Pch.h"
|
#include "Pch.h"
|
||||||
|
#include "hsThread.h"
|
||||||
|
#include <list>
|
||||||
#pragma hdrstop
|
#pragma hdrstop
|
||||||
|
|
||||||
|
|
||||||
@ -60,34 +62,33 @@ namespace pnNetCli {
|
|||||||
struct ChannelCrit {
|
struct ChannelCrit {
|
||||||
~ChannelCrit ();
|
~ChannelCrit ();
|
||||||
ChannelCrit ();
|
ChannelCrit ();
|
||||||
inline void Enter () { m_critsect.Enter(); }
|
inline void Enter () { m_critsect.Lock(); }
|
||||||
inline void Leave () { m_critsect.Leave(); }
|
inline void Leave () { m_critsect.Unlock(); }
|
||||||
inline void EnterSafe () { if (m_init) m_critsect.Enter(); }
|
inline void EnterSafe () { if (m_init) m_critsect.Lock(); }
|
||||||
inline void LeaveSafe () { if (m_init) m_critsect.Leave(); }
|
inline void LeaveSafe () { if (m_init) m_critsect.Unlock(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_init;
|
bool m_init;
|
||||||
CCritSect m_critsect;
|
hsMutex m_critsect;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NetMsgChannel : AtomicRef {
|
struct NetMsgChannel : AtomicRef {
|
||||||
LINK(NetMsgChannel) m_link;
|
uint32_t m_protocol;
|
||||||
unsigned m_protocol;
|
|
||||||
bool m_server;
|
bool m_server;
|
||||||
|
|
||||||
// Message definitions
|
// Message definitions
|
||||||
unsigned m_largestRecv;
|
uint32_t m_largestRecv;
|
||||||
ARRAY(NetMsgInitSend) m_sendMsgs;
|
ARRAY(NetMsgInitSend) m_sendMsgs;
|
||||||
ARRAY(NetMsgInitRecv) m_recvMsgs;
|
ARRAY(NetMsgInitRecv) m_recvMsgs;
|
||||||
|
|
||||||
// Diffie-Hellman constants
|
// Diffie-Hellman constants
|
||||||
unsigned m_dh_g;
|
uint32_t m_dh_g;
|
||||||
BigNum m_dh_xa; // client: dh_x server: dh_a
|
BigNum m_dh_xa; // client: dh_x server: dh_a
|
||||||
BigNum m_dh_n;
|
BigNum m_dh_n;
|
||||||
};
|
};
|
||||||
|
|
||||||
static ChannelCrit s_channelCrit;
|
static ChannelCrit s_channelCrit;
|
||||||
static LIST(NetMsgChannel) * s_channels;
|
static std::list<NetMsgChannel*>* s_channels;
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -105,8 +106,9 @@ ChannelCrit::ChannelCrit () {
|
|||||||
ChannelCrit::~ChannelCrit () {
|
ChannelCrit::~ChannelCrit () {
|
||||||
EnterSafe();
|
EnterSafe();
|
||||||
if (s_channels) {
|
if (s_channels) {
|
||||||
while (NetMsgChannel * const channel = s_channels->Head()) {
|
while (s_channels->size()) {
|
||||||
s_channels->Unlink(channel);
|
NetMsgChannel* const channel = s_channels->front();
|
||||||
|
s_channels->remove(channel);
|
||||||
channel->DecRef("ChannelLink");
|
channel->DecRef("ChannelLink");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,30 +241,29 @@ static void AddRecvMsgs_CS (
|
|||||||
// copy the message handler
|
// copy the message handler
|
||||||
*dst = *src;
|
*dst = *src;
|
||||||
|
|
||||||
const unsigned bytes = ValidateMsg(dst->msg);
|
const uint32_t bytes = ValidateMsg(dst->msg);
|
||||||
channel->m_largestRecv = max(channel->m_largestRecv, bytes);
|
channel->m_largestRecv = max(channel->m_largestRecv, bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
static NetMsgChannel * FindChannel_CS (unsigned protocol, bool server) {
|
static NetMsgChannel* FindChannel_CS (uint32_t protocol, bool server) {
|
||||||
if (!s_channels)
|
if (!s_channels)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
NetMsgChannel * channel = s_channels->Head();
|
std::list<NetMsgChannel*>::iterator it = s_channels->begin();
|
||||||
for (; channel; channel = s_channels->Next(channel)) {
|
for (; it != s_channels->end(); ++it) {
|
||||||
if ((channel->m_protocol == protocol) && (channel->m_server == server))
|
if (((*it)->m_protocol == protocol) && ((*it)->m_server == server))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return channel;
|
return *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
static NetMsgChannel * FindOrCreateChannel_CS (unsigned protocol, bool server) {
|
static NetMsgChannel* FindOrCreateChannel_CS (uint32_t protocol, bool server) {
|
||||||
if (!s_channels) {
|
if (!s_channels) {
|
||||||
s_channels = new LIST(NetMsgChannel);
|
s_channels = new std::list<NetMsgChannel*>();
|
||||||
s_channels->SetLinkOffset(offsetof(NetMsgChannel, m_link));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// find or create protocol
|
// find or create protocol
|
||||||
@ -273,7 +274,7 @@ static NetMsgChannel * FindOrCreateChannel_CS (unsigned protocol, bool server) {
|
|||||||
channel->m_server = server;
|
channel->m_server = server;
|
||||||
channel->m_largestRecv = 0;
|
channel->m_largestRecv = 0;
|
||||||
|
|
||||||
s_channels->Link(channel);
|
s_channels->push_back(channel);
|
||||||
channel->IncRef("ChannelLink");
|
channel->IncRef("ChannelLink");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,7 +292,7 @@ static NetMsgChannel * FindOrCreateChannel_CS (unsigned protocol, bool server) {
|
|||||||
NetMsgChannel * NetMsgChannelLock (
|
NetMsgChannel * NetMsgChannelLock (
|
||||||
unsigned protocol,
|
unsigned protocol,
|
||||||
bool server,
|
bool server,
|
||||||
unsigned * largestRecv
|
uint32_t * largestRecv
|
||||||
) {
|
) {
|
||||||
NetMsgChannel * channel;
|
NetMsgChannel * channel;
|
||||||
s_channelCrit.Enter();
|
s_channelCrit.Enter();
|
||||||
@ -353,7 +354,7 @@ const NetMsgInitSend * NetMsgChannelFindSendMessage (
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
void NetMsgChannelGetDhConstants (
|
void NetMsgChannelGetDhConstants (
|
||||||
const NetMsgChannel * channel,
|
const NetMsgChannel * channel,
|
||||||
unsigned * dh_g,
|
uint32_t * dh_g,
|
||||||
const BigNum ** dh_xa,
|
const BigNum ** dh_xa,
|
||||||
const BigNum ** dh_n
|
const BigNum ** dh_n
|
||||||
) {
|
) {
|
||||||
@ -374,13 +375,13 @@ void NetMsgChannelGetDhConstants (
|
|||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
void NetMsgProtocolRegister (
|
void NetMsgProtocolRegister (
|
||||||
unsigned protocol,
|
uint32_t protocol,
|
||||||
bool server,
|
bool server,
|
||||||
const NetMsgInitSend sendMsgs[],
|
const NetMsgInitSend sendMsgs[],
|
||||||
unsigned sendMsgCount,
|
uint32_t sendMsgCount,
|
||||||
const NetMsgInitRecv recvMsgs[],
|
const NetMsgInitRecv recvMsgs[],
|
||||||
unsigned recvMsgCount,
|
uint32_t recvMsgCount,
|
||||||
unsigned dh_g,
|
uint32_t dh_g,
|
||||||
const BigNum & dh_xa, // client: dh_x server: dh_a
|
const BigNum & dh_xa, // client: dh_x server: dh_a
|
||||||
const BigNum & dh_n
|
const BigNum & dh_n
|
||||||
) {
|
) {
|
||||||
@ -406,10 +407,10 @@ void NetMsgProtocolRegister (
|
|||||||
}
|
}
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
void NetMsgProtocolDestroy (unsigned protocol, bool server) {
|
void NetMsgProtocolDestroy (uint32_t protocol, bool server) {
|
||||||
s_channelCrit.EnterSafe();
|
s_channelCrit.EnterSafe();
|
||||||
if (NetMsgChannel * channel = FindChannel_CS(protocol, server)) {
|
if (NetMsgChannel* channel = FindChannel_CS(protocol, server)) {
|
||||||
s_channels->Unlink(channel);
|
s_channels->remove(channel);
|
||||||
channel->DecRef("ChannelLink");
|
channel->DecRef("ChannelLink");
|
||||||
}
|
}
|
||||||
s_channelCrit.LeaveSafe();
|
s_channelCrit.LeaveSafe();
|
||||||
|
@ -58,7 +58,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
# define NCCLI_LOG LogMsg
|
# define NCCLI_LOG LogMsg
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
#if !defined(PLASMA_EXTERNAL_RELEASE) && defined(HS_BUILD_FOR_WIN32)
|
||||||
|
|
||||||
struct NetLogMessage_Header
|
struct NetLogMessage_Header
|
||||||
{
|
{
|
||||||
@ -173,7 +173,7 @@ static void PutBufferOnWire (NetCli * cli, void * data, unsigned bytes) {
|
|||||||
|
|
||||||
uint8_t * temp = NULL;
|
uint8_t * temp = NULL;
|
||||||
|
|
||||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
#if !defined(PLASMA_EXTERNAL_RELEASE) && defined(HS_BUILD_FOR_WIN32)
|
||||||
// Write to the netlog
|
// Write to the netlog
|
||||||
if (s_netlog) {
|
if (s_netlog) {
|
||||||
NetLogMessage_Header header;
|
NetLogMessage_Header header;
|
||||||
@ -919,7 +919,7 @@ static NetCli * ConnCreate (
|
|||||||
cli->mode = mode;
|
cli->mode = mode;
|
||||||
cli->SetValue(kNilGuid);
|
cli->SetValue(kNilGuid);
|
||||||
|
|
||||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
#if !defined(PLASMA_EXTERNAL_RELEASE) && defined(HS_BUILD_FOR_WIN32)
|
||||||
// Network debug pipe
|
// Network debug pipe
|
||||||
if (!s_netlog) {
|
if (!s_netlog) {
|
||||||
InitializeCriticalSection(&s_pipeCritical);
|
InitializeCriticalSection(&s_pipeCritical);
|
||||||
@ -1124,7 +1124,7 @@ bool NetCliDispatch (
|
|||||||
cli->input.Add(bytes, data);
|
cli->input.Add(bytes, data);
|
||||||
bool result = DispatchData(cli, param);
|
bool result = DispatchData(cli, param);
|
||||||
|
|
||||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
#if !defined(PLASMA_EXTERNAL_RELEASE) && defined(HS_BUILD_FOR_WIN32)
|
||||||
// Write to the netlog
|
// Write to the netlog
|
||||||
if (s_netlog) {
|
if (s_netlog) {
|
||||||
NetLogMessage_Header header;
|
NetLogMessage_Header header;
|
||||||
|
@ -318,20 +318,20 @@ struct NetMsgInitRecv {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void NetMsgProtocolRegister (
|
void NetMsgProtocolRegister (
|
||||||
unsigned protocol, // from pnNetBase/pnNbProtocol.h
|
uint32_t protocol, // from pnNetBase/pnNbProtocol.h
|
||||||
bool server,
|
bool server,
|
||||||
const NetMsgInitSend sendMsgs[], // messages this program can send
|
const NetMsgInitSend sendMsgs[], // messages this program can send
|
||||||
unsigned sendMsgCount,
|
uint32_t sendMsgCount,
|
||||||
const NetMsgInitRecv recvMsgs[], // messages this program can receive
|
const NetMsgInitRecv recvMsgs[], // messages this program can receive
|
||||||
unsigned recvMsgCount,
|
uint32_t recvMsgCount,
|
||||||
// Diffie-Hellman keys
|
// Diffie-Hellman keys
|
||||||
unsigned dh_g,
|
uint32_t dh_g,
|
||||||
const BigNum & dh_xa, // client: dh_x server: dh_a
|
const BigNum & dh_xa, // client: dh_x server: dh_a
|
||||||
const BigNum & dh_n
|
const BigNum & dh_n
|
||||||
);
|
);
|
||||||
|
|
||||||
void NetMsgProtocolDestroy (
|
void NetMsgProtocolDestroy (
|
||||||
unsigned protocol,
|
uint32_t protocol,
|
||||||
bool server
|
bool server
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user