From b87b8ceb127c9a0119cdba0e0f0d54cc3021f879 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Fri, 16 Jun 2023 20:55:19 +0200 Subject: [PATCH 01/13] Remove empty "validation" methods of plNetMessage --- .../Plasma/PubUtilLib/plNetMessage/plNetMessage.cpp | 13 ------------- .../Plasma/PubUtilLib/plNetMessage/plNetMessage.h | 2 -- 2 files changed, 15 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.cpp b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.cpp index 0870a1c787..2cba93a8e8 100644 --- a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.cpp +++ b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.cpp @@ -168,7 +168,6 @@ int plNetMessage::PokeBuffer(char* bufIn, int bufLen, uint32_t peekOptions) if (! (peekOptions & kDontClearBuffer)) memset(bufIn, 0, bufLen); - ValidatePoke(); hsWriteOnlyStream writeStream(bufLen, bufIn); int ret; if (peekOptions & kBaseClassOnly) @@ -202,12 +201,10 @@ int plNetMessage::PeekBuffer(const char* bufIn, int bufLen, uint32_t peekOptions if (peekOptions & kBaseClassOnly) { ret=plNetMessage::IPeekBuffer(&readStream, peekOptions); - plNetMessage::ValidatePeek(); } else { ret=IPeekBuffer(&readStream, peekOptions); - ValidatePeek(); } return ret; @@ -380,16 +377,6 @@ uint32_t plNetMessage::GetNetCoreMsgLen() const return fNetCoreMsg ? fNetCoreMsg->GetLen() : 0; } -void plNetMessage::ValidatePeek() const -{ - -} - -void plNetMessage::ValidatePoke() const -{ - -} - ST::string plNetMessage::AsString() const { const char* delim = ""; diff --git a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h index 79f0dc4ced..4d4d0de8e7 100644 --- a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h +++ b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h @@ -193,8 +193,6 @@ class plNetMessage : public plCreatable int PeekBuffer(const char* buf, int bufLen, uint32_t peekOptions=0, bool forcePeek=false); // get msg out of buffer bool NeedsReliableSend() const { return IsBitSet(kNeedsReliableSend); } bool IsSystemMessage() const { return IsBitSet(kIsSystemMessage); } - virtual void ValidatePoke() const; - virtual void ValidatePeek() const; virtual bool NeedsBroadcast() const { return false; } // should game server broadcast this message to other clients? virtual int ValidationSchemeID() const { return 1; } From 7ad55becdcf635d42462d07e8fd5a8aa3abfdde8 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Fri, 16 Jun 2023 21:55:20 +0200 Subject: [PATCH 02/13] Remove plNetCommonMessage stuff that's not actually used Yes, all the plNetClientMsgHandler::PeekMsg calls really did nothing, because plNetMessage::fNetCoreMsg was never set anywhere. --- .../plNetClient/plNetClientMsgHandler.cpp | 48 ++------- .../plNetClient/plNetClientMsgHandler.h | 1 - .../PubUtilLib/plNetMessage/CMakeLists.txt | 1 - .../plNetMessage/plNetCommonMessage.h | 99 ------------------- .../PubUtilLib/plNetMessage/plNetMessage.cpp | 49 --------- .../PubUtilLib/plNetMessage/plNetMessage.h | 10 +- 6 files changed, 10 insertions(+), 198 deletions(-) delete mode 100644 Sources/Plasma/PubUtilLib/plNetMessage/plNetCommonMessage.h diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.cpp index b25df54314..2ecaa19e2b 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.cpp @@ -63,7 +63,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plMessage/plLoadCloneMsg.h" #include "plMessage/plMemberUpdateMsg.h" #include "plMessage/plNetOwnershipMsg.h" -#include "plNetMessage/plNetCommonMessage.h" #include "plNetMessage/plNetMessage.h" #include "plNetTransport/plNetTransportMember.h" #include "plSDL/plSDL.h" @@ -87,18 +86,6 @@ plNetClientMgr * plNetClientMsgHandler::IGetNetClientMgr() return plNetClientMgr::ConvertNoRef(GetNetApp()); } -int plNetClientMsgHandler::PeekMsg(plNetMessage * netMsg) -{ - plNetClientMgr * nc = IGetNetClientMgr(); - int cnt = -1; - if (netMsg->GetNetCoreMsg()) // && !netMsg->Peeked()) // not needed - { - cnt = netMsg->PeekBuffer(netMsg->GetNetCoreMsg()->GetData(), netMsg->GetNetCoreMsg()->GetLen()); - hsAssert(cnt,"0 length message"); - } - return cnt; -} - void plNetClientMsgHandler::IFillInTransportMember(const plNetMsgMemberInfoHelper* mbi, plNetTransportMember* mbr) { const plNetClientMgr* nc=IGetNetClientMgr(); @@ -160,11 +147,9 @@ MSG_HANDLER_DEFN(plNetClientMsgHandler,plNetMsgGroupOwner) { plNetClientMgr* nc = IGetNetClientMgr(); plNetMsgGroupOwner* m = plNetMsgGroupOwner::ConvertNoRef(netMsg); - PeekMsg(m); /* !!! THIS LOG MSG CRASHES THE CLIENT SOMETIMES! -eap - hsLogEntry( nc->DebugMsg(" {}, {}, sz={}", - m->ClassName(), m->AsStdString(), m->GetNetCoreMsgLen()) ); + hsLogEntry( nc->DebugMsg(" {}, {}", m->ClassName(), m->AsStdString())); */ /* @@ -200,11 +185,9 @@ MSG_HANDLER_DEFN(plNetClientMsgHandler,plNetMsgSDLState) { plNetClientMgr* nc = IGetNetClientMgr(); plNetMsgSDLState* m = plNetMsgSDLState::ConvertNoRef(netMsg); - PeekMsg(m); /* !!! THIS LOG MSG CRASHES THE CLIENT SOMETIMES! -eap - hsLogEntry( nc->DebugMsg(" {}, {}, sz={}", - m->ClassName(), m->AsStdString(), m->GetNetCoreMsgLen()) ); + hsLogEntry(nc->DebugMsg(" {}, {}, sz={}", m->ClassName(), m->AsStdString())); */ uint32_t rwFlags = 0; @@ -297,8 +280,6 @@ MSG_HANDLER_DEFN(plNetClientMsgHandler,plNetMsgGameMessage) plNetMsgGameMessage* m = plNetMsgGameMessage::ConvertNoRef(netMsg); if (m) { - PeekMsg(m); - plNetMsgLoadClone * lcMsg = plNetMsgLoadClone::ConvertNoRef( m ); if ( lcMsg ) { @@ -315,11 +296,10 @@ MSG_HANDLER_DEFN(plNetClientMsgHandler,plNetMsgGameMessage) if (gameMsg) { /* !!! THIS LOG MSG CRASHES THE CLIENT SOMETIMES!!! -eap - hsLogEntry( nc->DebugMsg(" {}, {}, sndr {} rcvr {} sz={}", + hsLogEntry( nc->DebugMsg(" {}, {}, sndr {} rcvr {}", m->ClassName(), m->AsStdString(), gameMsg->GetSender() ? gameMsg->GetSender()->GetName() : "?", - gameMsg->GetNumReceivers() ? gameMsg->GetReceiver(0)->GetName() : "?", - m->GetNetCoreMsgLen()) ); + gameMsg->GetNumReceivers() ? gameMsg->GetReceiver(0)->GetName() : "?")); */ if (lcMsg) @@ -386,11 +366,9 @@ MSG_HANDLER_DEFN(plNetClientMsgHandler,plNetMsgVoice) { plNetClientMgr* nc = IGetNetClientMgr(); plNetMsgVoice* m = plNetMsgVoice::ConvertNoRef(netMsg); - PeekMsg(m); /* !!! THIS LOG MSG CRASHES THE CLIENT SOMETIMES! -eap - hsLogEntry( nc->DebugMsg(" {}, {}, sz={}", - m->ClassName(), m->AsStdString(), m->GetNetCoreMsgLen()) ); + hsLogEntry(nc->DebugMsg(" {}, {}", m->ClassName(), m->AsStdString())); */ size_t bufLen = m->GetVoiceDataLen(); @@ -441,11 +419,9 @@ MSG_HANDLER_DEFN(plNetClientMsgHandler,plNetMsgMembersList) { plNetClientMgr* nc = IGetNetClientMgr(); plNetMsgMembersList* m = plNetMsgMembersList::ConvertNoRef(netMsg); - PeekMsg(m); /* !!! THIS LOG MSG CRASHES THE CLIENT SOMETIMES! -eap - hsLogEntry( nc->DebugMsg(" {}, {}, sz={}", - m->ClassName(), m->AsStdString(), m->GetNetCoreMsgLen()) ); + hsLogEntry(nc->DebugMsg(" {}, {}", m->ClassName(), m->AsStdString())); */ // remove existing members, except server @@ -480,11 +456,9 @@ MSG_HANDLER_DEFN(plNetClientMsgHandler,plNetMsgMemberUpdate) { plNetClientMgr* nc = IGetNetClientMgr(); plNetMsgMemberUpdate* m = plNetMsgMemberUpdate::ConvertNoRef(netMsg); - PeekMsg(m); /* !!! THIS LOG MSG CRASHES THE CLIENT SOMETIMES! -eap - hsLogEntry( nc->DebugMsg(" {}, {}, sz={}", - m->ClassName(), m->AsStdString(), m->GetNetCoreMsgLen()) ); + hsLogEntry(nc->DebugMsg(" {}, {}", m->ClassName(), m->AsStdString())); */ if (m->AddingMember()) @@ -528,11 +502,9 @@ MSG_HANDLER_DEFN(plNetClientMsgHandler,plNetMsgListenListUpdate) { plNetClientMgr* nc = IGetNetClientMgr(); plNetMsgListenListUpdate* m = plNetMsgListenListUpdate::ConvertNoRef(netMsg); - PeekMsg(m); /* !!! THIS LOG MSG CRASHES THE CLIENT SOMETIMES! -eap - hsLogEntry( nc->DebugMsg(" {}, {}, sz={}", - m->ClassName(), m->AsStdString(), m->GetNetCoreMsgLen()) ); + hsLogEntry(nc->DebugMsg(" {}, {}", m->ClassName(), m->AsStdString())); */ plNetTransportMember* tm = nc->fTransport.GetMemberByID(m->GetPlayerID()); @@ -566,11 +538,9 @@ MSG_HANDLER_DEFN(plNetClientMsgHandler,plNetMsgInitialAgeStateSent) { plNetClientMgr * nc = IGetNetClientMgr(); plNetMsgInitialAgeStateSent* msg = plNetMsgInitialAgeStateSent::ConvertNoRef(netMsg); - PeekMsg(msg); /* !!! THIS LOG MSG CRASHES THE CLIENT SOMETIMES! -eap - hsLogEntry( nc->DebugMsg(" {}, {}, sz={}", - netMsg->ClassName(), netMsg->AsStdString(), netMsg->GetNetCoreMsgLen()) ); + hsLogEntry(nc->DebugMsg(" {}, {}", netMsg->ClassName(), netMsg->AsStdString())); */ nc->DebugMsg( "Initial age SDL count: {}", msg->GetNumInitialSDLStates( ) ); diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.h b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.h index 0bfcf52e56..0bd9d7363e 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.h +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.h @@ -71,7 +71,6 @@ class plNetClientMsgHandler : public plNetMsgHandler ~plNetClientMsgHandler(); plNetMsgHandler::Status ReceiveMsg(plNetMessage *& netMsg) override; - int PeekMsg(plNetMessage * netMsg); // return msgsize on success. -1 on error. MSG_HANDLER_DECL(plNetMsgTerminated) MSG_HANDLER_DECL(plNetMsgGroupOwner) diff --git a/Sources/Plasma/PubUtilLib/plNetMessage/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plNetMessage/CMakeLists.txt index 54b7ff85f0..a84624aab6 100644 --- a/Sources/Plasma/PubUtilLib/plNetMessage/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plNetMessage/CMakeLists.txt @@ -4,7 +4,6 @@ set(plNetMessage_SOURCES ) set(plNetMessage_HEADERS - plNetCommonMessage.h plNetMessage.h plNetMessageCreatable.h plNetMsgHelpers.h diff --git a/Sources/Plasma/PubUtilLib/plNetMessage/plNetCommonMessage.h b/Sources/Plasma/PubUtilLib/plNetMessage/plNetCommonMessage.h deleted file mode 100644 index 155bd229c5..0000000000 --- a/Sources/Plasma/PubUtilLib/plNetMessage/plNetCommonMessage.h +++ /dev/null @@ -1,99 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#ifndef plNetCommonMessage_inc -#define plNetCommonMessage_inc - -#include "HeadSpin.h" -#include "hsRefCnt.h" - -// -// refcntable data -// -class plNetCommonMessageData : public hsRefCnt -{ -private: - char *fData; // sent -public: - plNetCommonMessageData(char* d) : fData(d) {} - ~plNetCommonMessageData() - { - hsAssert(RefCnt()==1, "illegal refcnt"); - delete [] fData; - } - - char* GetData() const { return fData; } -}; - -// -// basic msg payload w/ refcntable data -// -class plNetCommonMessage -{ - plNetCommonMessage(const plNetCommonMessage & other); -private: - plNetCommonMessageData* fMsgData; -protected: - uint32_t fLen; // sent -public: - plNetCommonMessage() : fLen(), fMsgData() { } - virtual ~plNetCommonMessage() { hsRefCnt_SafeUnRef(fMsgData); } - - // setters - void SetData(char *d) - { - plNetCommonMessageData* n = d ? new plNetCommonMessageData(d) : nullptr; - hsRefCnt_SafeAssign(fMsgData, n); - hsRefCnt_SafeUnRef(n); - } - void SetMsgData(plNetCommonMessageData* d) - { - hsRefCnt_SafeAssign(fMsgData, d); - } - void SetLen(uint32_t l) { fLen=l; } - - // getters - char* GetData() const { return fMsgData ? fMsgData->GetData() : nullptr; } - virtual uint32_t GetDataLen() { return fLen; } - uint32_t GetLen() const { return fLen; } - plNetCommonMessageData* GetMsgData() const { return fMsgData; } -}; -#endif // plNetCommonMessage_inc diff --git a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.cpp b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.cpp index 2cba93a8e8..488a3f1ca1 100644 --- a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.cpp +++ b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.cpp @@ -46,7 +46,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsResMgr.h" #include "hsStream.h" -#include "plNetCommonMessage.h" #include "plNetMsgVersion.h" #include "pnFactory/plFactory.h" @@ -115,49 +114,6 @@ void plNetMessage::InitReplyFieldsFrom(plNetMessage * msg) #endif } -// -// STATIC -// create and READ from lowlevel net buffer -// -plNetMessage* plNetMessage::CreateAndRead(const plNetCommonMessage* msg) -{ - // create - plNetMessage* pHdr = Create(msg); - if (!pHdr) - return nullptr; - - // read - pHdr->PeekBuffer(msg->GetData(), msg->GetLen(), 0, false); - return pHdr; -} - -// -// STATIC -// create from lowlevel net buffer -// -plNetMessage* plNetMessage::Create(const plNetCommonMessage* msg) -{ - if (msg) - { - ClassIndexType classIndex; - hsReadOnlyStream readStream(sizeof(classIndex), msg->GetData()); - readStream.ReadLE16(&classIndex); - if (!plFactory::IsValidClassIndex(classIndex)) - return nullptr; - plNetMessage* pnm = plNetMessage::ConvertNoRef(plFactory::Create(classIndex)); - if (pnm) - pnm->SetNetCoreMsg(msg); - else - { - char str[256]; - sprintf(str, "Factory create failed, class index=%d, garbage msg?", classIndex); - hsAssert(false, str); - } - return pnm; - } - return nullptr; -} - int plNetMessage::PokeBuffer(char* bufIn, int bufLen, uint32_t peekOptions) { fPeekStatus = 0; @@ -372,11 +328,6 @@ int plNetMessage::GetPackSize() return IPokeBuffer(&nullStream); } -uint32_t plNetMessage::GetNetCoreMsgLen() const -{ - return fNetCoreMsg ? fNetCoreMsg->GetLen() : 0; -} - ST::string plNetMessage::AsString() const { const char* delim = ""; diff --git a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h index 4d4d0de8e7..8040c58063 100644 --- a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h +++ b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h @@ -65,9 +65,7 @@ class plUUID; // // Base class for application network messages. -// These become the data in a plNetCommonMessage when sent over the network. // -class plNetCommonMessage; class plKey; class plNetMessage : public plCreatable @@ -82,7 +80,6 @@ class plNetMessage : public plCreatable uint32_t fTransactionID; // set by originator, included in reply. Only written if kHasTransactionID flag set uint32_t fPlayerID; // set by originator. Only written if kHasPlayerID flag set plUUID fAcctUUID; // set by sender (app level). Only written if kHasAcctUUID flag set - const plNetCommonMessage* fNetCoreMsg; // not sent, set by the receiver uint32_t fPeekStatus; // not sent. set on PeekBuffer, cleared on PokeBuffer uint8_t fProtocolVerMajor; // conditionally sent uint8_t fProtocolVerMinor; // conditionally sent @@ -181,14 +178,12 @@ class plNetMessage : public plCreatable // ctor plNetMessage() - : fTimeRecvd(), fBytesRead(), fNetCoreMsg(), fContext(), + : fTimeRecvd(), fBytesRead(), fContext(), fPeekStatus(), fTransactionID(), fPlayerID(kInvalidPlayerID), fNetProtocol(), fProtocolVerMajor(), fProtocolVerMinor(), fFlags(0) { } - static plNetMessage* CreateAndRead(const plNetCommonMessage*); - static plNetMessage* Create(const plNetCommonMessage*); int PokeBuffer(char* buf, int bufLen, uint32_t peekOptions=0); // put msg in buffer int PeekBuffer(const char* buf, int bufLen, uint32_t peekOptions=0, bool forcePeek=false); // get msg out of buffer bool NeedsReliableSend() const { return IsBitSet(kNeedsReliableSend); } @@ -202,8 +197,6 @@ class plNetMessage : public plCreatable bool GetHasTimeSent() const { return IsBitSet(kHasTimeSent); } double GetTimeReceived() const { return fTimeRecvd; } bool IsBitSet(int b) const { return (fFlags & b) != 0; } - const plNetCommonMessage* GetNetCoreMsg() const { return fNetCoreMsg; } - uint32_t GetNetCoreMsgLen() const; bool GetHasContext() const { return IsBitSet(kHasContext);} uint32_t GetContext() const { return fContext;} bool GetHasTransactionID() const { return IsBitSet(kHasTransactionID);} @@ -222,7 +215,6 @@ class plNetMessage : public plCreatable void SetHasTimeSent(bool value) { SetBit( kHasTimeSent, value ); } void SetTimeReceived(double t) { fTimeRecvd=t; } void SetBit(int b, bool on=true) { if (on) fFlags |= b; else fFlags &= ~b; } - void SetNetCoreMsg(const plNetCommonMessage* ncmsg) { fNetCoreMsg=ncmsg; } void SetHasContext(bool value) { SetBit(kHasContext,value);} void SetContext(uint32_t value) { fContext=value; SetHasContext(true);} void SetHasTransactionID(bool value) { SetBit(kHasTransactionID,value);} From 57ed0b495a19820cf81f92e829d942e6420e3804 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sat, 17 Jun 2023 00:41:11 +0200 Subject: [PATCH 03/13] Read/write plNetMessages from/to hsStreams instead of memory buffers This simplifies the writing process especially, where the previous implementation actually had to write the message twice: first to calculate the required buffer size, then another time to actually fill in the buffer. Now the message is written directly into a hsRAMStream. --- .../plNetClientComm/plNetClientComm.cpp | 12 +++---- .../PubUtilLib/plNetMessage/plNetMessage.cpp | 32 ++++++------------- .../PubUtilLib/plNetMessage/plNetMessage.h | 4 +-- 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp index e462c5f189..f85daa3801 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp @@ -220,7 +220,8 @@ static void INetBufferCallback ( return; } - if (!msg->PeekBuffer((const char *)buffer, bytes)) { + hsReadOnlyStream stream(bytes, buffer); + if (!msg->PeekBuffer(&stream)) { LogMsg(kLogError, "NetComm: plNetMessage %u failed to peek buffer", type); return; } @@ -872,9 +873,10 @@ void NetCommSendMsg ( ) { msg->SetPlayerID(NetCommGetPlayer()->playerInt); - unsigned msgSize = msg->GetPackSize(); - uint8_t * buf = (uint8_t *)malloc(msgSize); - msg->PokeBuffer((char *)buf, msgSize); + hsRAMStream stream; + msg->PokeBuffer(&stream); + size_t msgSize = stream.GetEOF(); + auto buf = static_cast(stream.GetData()); switch (msg->GetNetProtocol()) { case kNetProtocolCli2Auth: @@ -895,8 +897,6 @@ void NetCommSendMsg ( DEFAULT_FATAL(msg->GetNetProtocol()); } - - free(buf); } //============================================================================ diff --git a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.cpp b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.cpp index 488a3f1ca1..639b1d556b 100644 --- a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.cpp +++ b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.cpp @@ -114,53 +114,39 @@ void plNetMessage::InitReplyFieldsFrom(plNetMessage * msg) #endif } -int plNetMessage::PokeBuffer(char* bufIn, int bufLen, uint32_t peekOptions) +int plNetMessage::PokeBuffer(hsStream* s, uint32_t peekOptions) { fPeekStatus = 0; - - if (!bufIn) - return 0; - - if (! (peekOptions & kDontClearBuffer)) - memset(bufIn, 0, bufLen); - - hsWriteOnlyStream writeStream(bufLen, bufIn); + int ret; if (peekOptions & kBaseClassOnly) { - ret=plNetMessage::IPokeBuffer(&writeStream, peekOptions); + ret=plNetMessage::IPokeBuffer(s, peekOptions); } else { - ret=IPokeBuffer(&writeStream, peekOptions); + ret=IPokeBuffer(s, peekOptions); } return ret; } -int plNetMessage::PeekBuffer(const char* bufIn, int bufLen, uint32_t peekOptions, bool forcePeek) +int plNetMessage::PeekBuffer(hsStream* s, uint32_t peekOptions, bool forcePeek) { - if(!bufLen || bufLen < 1) - return 0; - uint32_t partialPeekOptions = (peekOptions & kPartialPeekMask); if (!forcePeek && (fPeekStatus & partialPeekOptions) ) return 0; // already peeked, fully or partially - - if (!bufIn) - return 0; - + // set peek status based on peekOptions fPeekStatus = partialPeekOptions ? partialPeekOptions : kFullyPeeked; - - hsReadOnlyStream readStream(bufLen, bufIn); + int ret; if (peekOptions & kBaseClassOnly) { - ret=plNetMessage::IPeekBuffer(&readStream, peekOptions); + ret=plNetMessage::IPeekBuffer(s, peekOptions); } else { - ret=IPeekBuffer(&readStream, peekOptions); + ret=IPeekBuffer(s, peekOptions); } return ret; diff --git a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h index 8040c58063..fee672983d 100644 --- a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h +++ b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h @@ -184,8 +184,8 @@ class plNetMessage : public plCreatable fFlags(0) { } - int PokeBuffer(char* buf, int bufLen, uint32_t peekOptions=0); // put msg in buffer - int PeekBuffer(const char* buf, int bufLen, uint32_t peekOptions=0, bool forcePeek=false); // get msg out of buffer + int PokeBuffer(hsStream* s, uint32_t peekOptions = 0); // put msg in stream + int PeekBuffer(hsStream* s, uint32_t peekOptions = 0, bool forcePeek = false); // get msg out of stream bool NeedsReliableSend() const { return IsBitSet(kNeedsReliableSend); } bool IsSystemMessage() const { return IsBitSet(kIsSystemMessage); } virtual bool NeedsBroadcast() const { return false; } // should game server broadcast this message to other clients? From 3a00ca610f67a9c21ebb3c28f5952fc8de8ef983 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sat, 17 Jun 2023 12:38:04 +0200 Subject: [PATCH 04/13] Remove dead plNetTransport channel stuff The channel number was ignored when sending messages to the server. The plNetTransportMember subscription lists were updated in various places, but also never actually used for anything. --- .../PubUtilLib/plNetClient/plNetClientMgr.cpp | 38 +------ .../PubUtilLib/plNetClient/plNetClientMgr.h | 12 +-- .../plNetClient/plNetClientMgrSend.cpp | 4 +- .../PubUtilLib/plNetClient/plNetVoiceList.cpp | 26 ----- .../PubUtilLib/plNetClient/plNetVoiceList.h | 12 --- .../plNetTransport/plNetTransport.cpp | 100 +----------------- .../plNetTransport/plNetTransport.h | 11 +- .../plNetTransport/plNetTransportMember.cpp | 33 ------ .../plNetTransport/plNetTransportMember.h | 12 --- 9 files changed, 9 insertions(+), 239 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp index 54603d5329..5e6e589846 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp @@ -115,7 +115,6 @@ plNetClientMgr::plNetClientMgr() SetFlagsBit(kAllowAuthTimeOut); // fPlayerVault.SetPlayerName("SinglePlayer"); // in a MP game, this will be replaced with a player name like 'Atrus' - fTransport.SetNumChannels(kNetNumChannels); } // @@ -326,21 +325,13 @@ void plNetClientMgr::Init() // // Prepare to send. -// Update p2p transport groups and rcvrs list in some msgs -// Returns channel. +// Update rcvrs list in some msgs // -int plNetClientMgr::IPrepMsg(plNetMessage* msg) +void plNetClientMgr::IPrepMsg(plNetMessage* msg) { - // pick channel, prepare msg - int channel=kNetChanDefault; plNetMsgVoice* v=plNetMsgVoice::ConvertNoRef(msg); if (v) { // VOICE MSG - channel=kNetChanVoice; - - // compute new transport group (from talkList) if necessary - GetTalkList()->UpdateTransportGroup(this); - // update receivers list in voice msg based on talk list v->Receivers()->Clear(); int i; @@ -352,31 +343,6 @@ int plNetClientMgr::IPrepMsg(plNetMessage* msg) if (msg->IsBitSet(plNetMessage::kEchoBackToSender)) v->Receivers()->AddReceiverPlayerID(GetPlayerID()); } - else if (plNetMsgListenListUpdate::ConvertNoRef(msg)) - { // LISTEN LIST UPDATE MSG - channel=kNetChanListenListUpdate; - - // update transport group from rcvrs list, add p2p mbrs to trasnport group - fTransport.ClearChannelGrp(kNetChanListenListUpdate); - if (IsPeerToPeer()) - { - plNetMsgReceiversListHelper* rl = plNetMsgReceiversListHelper::ConvertNoRef(msg); - hsAssert(rl, "error converting msg to rcvrs list?"); - int i; - for(i=0;iGetNumReceivers();i++) - { - plNetTransportMember* tm = fTransport.GetMemberByID(rl->GetReceiverPlayerID(i)); - hsAssert(tm, "error finding transport mbr"); - if (tm->IsPeerToPeer()) - fTransport.SubscribeToChannelGrp(tm, kNetChanListenListUpdate); - } - } - } - else if( plNetMsgGameMessageDirected::ConvertNoRef( msg ) ) - { - channel = kNetChanDirectedMsg; - } - return channel; } // diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h index 63ec58f560..e16d7e69b7 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h @@ -90,16 +90,6 @@ class plNetClientMgr : public plNetClientApp private: typedef std::vector plKeyVec; public: - - enum NetChannels - { - kNetChanDefault, - kNetChanVoice, - kNetChanListenListUpdate, - kNetChanDirectedMsg, - kNetNumChannels - }; - enum DirectedSendFlags { kInterAgeMsg = 0x1 @@ -211,7 +201,7 @@ class plNetClientMgr : public plNetClientApp bool IUpdateListenList(double secs); void IHandleNetVoiceListMsg(plNetVoiceListMsg* msg); bool IApplyNewListenList(std::vector& newListenList, bool forceSynch); - int IPrepMsg(plNetMessage* msg); + void IPrepMsg(plNetMessage* msg); void IPlayerChangeAge(bool exiting, int32_t spawnPt); void IAddCloneRoom(); diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp index 5ec2b71933..1a6b3afa6d 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp @@ -412,11 +412,11 @@ void plNetClientMgr::SendMsg(plNetMessage* msg) } msg->SetTimeSent(plUnifiedTime::GetCurrent()); - int channel = IPrepMsg(msg); + IPrepMsg(msg); // hsLogEntry( DebugMsg( " {} {}", msg->ClassName(), msg->AsStdString()) ); - fTransport.SendMsg(channel, msg); + fTransport.SendMsg(msg); // Debug if (plNetMsgVoice::ConvertNoRef(msg)) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetVoiceList.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetVoiceList.cpp index b9b8713802..e8802a619c 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetVoiceList.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetVoiceList.cpp @@ -71,24 +71,6 @@ int plNetVoiceList::FindMember(plNetTransportMember* e) * ***/ -void plNetTalkList::UpdateTransportGroup(plNetClientMgr* nc) -{ - if (fFlags & kDirty) - { - nc->fTransport.ClearChannelGrp(plNetClientMgr::kNetChanVoice); - if (nc->IsPeerToPeer()) - { - int i; - for(i=0;iIsPeerToPeer()) - nc->fTransport.SubscribeToChannelGrp(GetMember(i), plNetClientMgr::kNetChanVoice); - } - } - fFlags &= ~kDirty; - } -} - void plNetTalkList::AddMember(plNetTransportMember* e) { if (FindMember(e)==-1) @@ -96,7 +78,6 @@ void plNetTalkList::AddMember(plNetTransportMember* e) plStatusLog::AddLineSF("voice.log", "Adding {} to talk list", e->AsString()); fMembers.push_back(e); } - fFlags |= kDirty; } void plNetTalkList::RemoveMember(plNetTransportMember* e) @@ -107,13 +88,6 @@ void plNetTalkList::RemoveMember(plNetTransportMember* e) plStatusLog::AddLineSF("voice.log", "Removing {} from talklist", e->AsString()); fMembers.erase(fMembers.begin()+idx); } - fFlags |= kDirty; -} - -void plNetTalkList::Clear() -{ - plNetVoiceList::Clear(); - fFlags |= kDirty; } diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetVoiceList.h b/Sources/Plasma/PubUtilLib/plNetClient/plNetVoiceList.h index a906a55bbe..4406e0c53e 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetVoiceList.h +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetVoiceList.h @@ -104,21 +104,9 @@ class plNetListenList : public plNetVoiceList // class plNetTalkList : public plNetVoiceList { -private: - enum - { - kDirty = 0x1 - }; - uint32_t fFlags; public: - plNetTalkList() : fFlags(0) {} - ~plNetTalkList() {} - - void UpdateTransportGroup(plNetClientMgr* nc); - void AddMember(plNetTransportMember* e) override; void RemoveMember(plNetTransportMember* e) override; - void Clear() override; }; #endif // plNetVoiceList_h diff --git a/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransport.cpp b/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransport.cpp index 5ec4d91424..e78e68b966 100644 --- a/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransport.cpp +++ b/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransport.cpp @@ -75,17 +75,6 @@ hsSsize_t plNetTransport::AddMember(plNetTransportMember* mbr) return -1; } -void plNetTransport::IUnSubscribeToAllChannelGrps(plNetTransportMember* mbr) -{ - int i; - for( i=mbr->GetNumSubscriptions()-1; i>=0 ; i-- ) - { - int chan=mbr->GetSubscription(i); - bool ok=UnSubscribeToChannelGrp(mbr, chan); - hsAssert(ok, "can't find supposed subscription to remove"); - } // for -} - void plNetTransport::IRemoveMember(plNetTransportMember* mbr) { if (!mbr) @@ -97,9 +86,6 @@ void plNetTransport::IRemoveMember(plNetTransportMember* mbr) plNetClientMgr::GetInstance()->GetTalkList()->RemoveMember(mbr); plNetClientMgr::GetInstance()->GetListenList()->RemoveMember(mbr); - // remove member from subscription lists - IUnSubscribeToAllChannelGrps(mbr); - auto it = std::find(fMembers.cbegin(), fMembers.cend(), mbr); // remove member from master list @@ -153,50 +139,9 @@ hsSsize_t plNetTransport::FindMember(const plNetTransportMember* mbr) // -// add this member to the given channel grp -// -void plNetTransport::SubscribeToChannelGrp(plNetTransportMember* mbr, int channel) -{ -// hsAssert(FindMember(mbr) != -1, "must add member before subscribing to channel"); - if (mbr->AddSubscription(channel)) - { - hsAssert(channel=0 && chancbegin(), mList->cend(), mbr); - if (it != mList->cend()) - { - mList->erase(it); - bool ret=mbr->RemoveSubscription(chan); - hsAssert(ret, "error removing subscription"); - return true; - } - return false; -} - -// -// copy list of members channelGrp subscriptions +// Send Msg to the server. // -void plNetTransport::GetSubscriptions(plNetTransportMember* mbr, std::vector* channels) const -{ - mbr->CopySubscriptions(channels); -} - - -// -// Send Msg to all members in the given channelGrp. -// Here's where multicasting would be used. -// -void plNetTransport::SendMsg(int chan, plNetMessage* netMsg) const +void plNetTransport::SendMsg(plNetMessage* netMsg) const { NetCommSendMsg(netMsg); } @@ -207,7 +152,6 @@ void plNetTransport::ClearMembers() for (plNetTransportMember* mbr : fMembers) { hsAssert(mbr, "nil member?"); - IUnSubscribeToAllChannelGrps(mbr); delete mbr; } // for @@ -243,59 +187,21 @@ hsSsize_t plNetTransport::FindMember(const plKey& avKey) const return -1; } -// -// clear channel and unsubscribe all members to that channel -// -void plNetTransport::ClearChannelGrp(int channel) -{ - const MembersList* mList = &fChannelGroups[channel]; - for (plNetTransportMember* tm : *mList) - { - bool ok=tm->RemoveSubscription(channel); - hsAssert(ok, "error removing subscription"); - } - - fChannelGroups[channel].clear(); -} - void plNetTransport::DumpState() { plNetClientMgr* nc=plNetClientMgr::GetInstance(); hsLogEntry( nc->DebugMsg("-------------------\n") ); - hsLogEntry( nc->DebugMsg("Num Channels={}\n", fChannelGroups.size()) ); - - for (size_t i = 0; i < fChannelGroups.size(); i++) - { - MembersList* mList = &fChannelGroups[i]; - hsLogEntry( nc->DebugMsg("\tChannel {}, num mbrs={}\n", i, mList->size()) ); - for (plNetTransportMember* mbr : *mList) - { - hsLogEntry(nc->DebugMsg("\t\tMbr {}\n", mbr->AsString())); - } - } nc->DebugMsg("Num Mbrs={}\n", GetNumMembers()); for (size_t i = 0; i < GetNumMembers(); i++) { plNetTransportMember * mbr = GetMember(i); - hsLogEntry (nc->DebugMsg("\tMbr {}, name={}, plyrID={}, subs={}", - i,mbr->AsString(),mbr->GetPlayerID(),mbr->GetNumSubscriptions()) ); - int j; - for(j=0;jGetNumSubscriptions();j++) - { - hsLogEntry( nc->DebugMsg("\t\tSub {}, chan={}\n", j, mbr->GetSubscription(j)) ); - } + hsLogEntry(nc->DebugMsg("\tMbr {}, name={}, plyrID={}", i, mbr->AsString(), mbr->GetPlayerID())); } hsLogEntry( nc->DebugMsg("\n") ); } -void plNetTransport::SetNumChannels(int n) -{ - if (n>fChannelGroups.size()) - fChannelGroups.resize(n); -} - // // create a members list sorted by dist. // diff --git a/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransport.h b/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransport.h index c0e72f1b3a..e2089471ab 100644 --- a/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransport.h +++ b/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransport.h @@ -61,9 +61,7 @@ class plNetTransport private: typedef std::vector MembersList; MembersList fMembers; // master list of all members in the game, server is member[0] - std::vector fChannelGroups; // members grouped by channel - void IUnSubscribeToAllChannelGrps(plNetTransportMember* mbr); void IRemoveMember(plNetTransportMember* mbr); public: plNetTransport() {} @@ -86,14 +84,7 @@ class plNetTransport const std::vector& GetMemberList() const { return fMembers; } void ClearMembers(); - // channel group ops - void SubscribeToChannelGrp(plNetTransportMember* mbr, int channel); - bool UnSubscribeToChannelGrp(plNetTransportMember* mbr, int channel); - void GetSubscriptions(plNetTransportMember* mbr, std::vector* channels) const; - void ClearChannelGrp(int channel); - void SetNumChannels(int n); - - void SendMsg(int channel, plNetMessage* msg) const; + void SendMsg(plNetMessage* msg) const; }; #endif // plNetTransport_h diff --git a/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransportMember.cpp b/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransportMember.cpp index e13b9e375b..a92f329e72 100644 --- a/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransportMember.cpp +++ b/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransportMember.cpp @@ -42,39 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plNetTransportMember.h" -#include - -// -// add a channel subscription if it's not already there -// returns true if added -// -bool plNetTransportMember::AddSubscription(int chan) -{ - if (FindSubscription(chan)==-1) - { - fSubscriptions.push_back(chan); - return true; - } - return false; -} - -bool plNetTransportMember::RemoveSubscription(int chan) -{ - int idx=FindSubscription(chan); - if (idx>=0) - { - fSubscriptions.erase(fSubscriptions.begin()+idx); - return true; - } - return false; -} - -int plNetTransportMember::FindSubscription(int chan) -{ - std::vector::iterator it=std::find(fSubscriptions.begin(), fSubscriptions.end(), chan); - return (it==fSubscriptions.end()) ? -1 : (int)(it-fSubscriptions.begin()); -} - ST::string plNetTransportMember::AsString() const { if (IsServer()) diff --git a/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransportMember.h b/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransportMember.h index 13d608393d..04b7218d97 100644 --- a/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransportMember.h +++ b/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransportMember.h @@ -47,12 +47,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnKeyedObject/plKey.h" #include -#include // // This represents a participant in the game, ie. another // remote user. -// It is a basic net member with a list of channels that it subscribes to. // class plKey; @@ -68,7 +66,6 @@ class plNetTransportMember : public plNetMember plKey fAvatarKey; ST::string fPlayerName; uint32_t fPlayerID; - std::vector fSubscriptions; // list of channelGrp subscriptions uint32_t fTransportFlags; float fDistSq; // from local player, temp uint8_t fCCRLevel; @@ -97,15 +94,6 @@ class plNetTransportMember : public plNetMember void SetIsServer(bool value) { (value)?SetFlags(GetFlags()|kIsServer):SetFlags(GetFlags()&~kIsServer);} bool IsServer() const { return (GetFlags()&kIsServer)?true:false;} - bool AddSubscription(int chan); - bool RemoveSubscription(int chan); // return true on success - int FindSubscription(int chan); // return index into subscription array or -1 - - int GetNumSubscriptions() { return fSubscriptions.size(); } - int GetSubscription(int i) { return fSubscriptions[i]; } - - void CopySubscriptions(std::vector* channels) { *channels = fSubscriptions; } - void SetTransportFlags(uint32_t f) { fTransportFlags=f; } uint32_t GetTransportFlags() const { return fTransportFlags; } From 97638c17b8a22a37088aeb605ca0a438fec42be7 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sat, 17 Jun 2023 12:49:03 +0200 Subject: [PATCH 05/13] Remove more bits of dead peer-to-peer code --- Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h | 3 --- .../Plasma/PubUtilLib/plNetClient/plNetClientMgrShow.cpp | 9 ++++----- .../PubUtilLib/plNetClient/plNetClientMgrVoice.cpp | 5 ----- .../PubUtilLib/plNetClient/plNetClientMsgHandler.cpp | 2 +- .../PubUtilLib/plNetTransport/plNetTransportMember.h | 1 - 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h index e16d7e69b7..2cc7f3e1bf 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h @@ -279,9 +279,6 @@ class plNetClientMgr : public plNetClientApp plKey GetLocalPlayerKey() const override { return fLocalPlayerKey; } plSynchedObject* GetLocalPlayer(bool forceLoad=false) const override; - - bool IsPeerToPeer() const { return false; } - bool IsConnected() const { return true; } void IncNumInitialSDLStates(); void ResetNumInitialSDLStates() { fNumInitialSDLStates=0; } diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrShow.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrShow.cpp index 7bac3edebd..4fe03169f9 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrShow.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrShow.cpp @@ -74,11 +74,11 @@ void plNetClientMgr::IShowLists() y=startY; plSceneObject *player = plSceneObject::ConvertNoRef(GetLocalPlayer()); hsPoint3 pos = (player ? player->GetLocalToWorld() * hsPoint3(0, 0, 0) : hsPoint3(0, 0, 0)); - sprintf(str, "%s%s PlyrName=%s PlyrID=%d AcctID=%d P2P=%d Join#=%d Peers=%d %.1f,%.1f,%.1f", + sprintf(str, "%s%s PlyrName=%s PlyrID=%d Join#=%d %.1f,%.1f,%.1f", GetFlagsBit(kSendingVoice) ? "V" : " ", GetFlagsBit(kSendingActions) ? "A" : " ", - GetPlayerName().c_str(), GetPlayerID(), 0, - IsPeerToPeer(), GetJoinOrder(), 0, + GetPlayerName().c_str(), GetPlayerID(), + GetJoinOrder(), pos.fX, pos.fY, pos.fZ); txt.DrawString(x,y,str,255,255,255,255); SetFlagsBit(kSendingVoice, 0); @@ -101,11 +101,10 @@ void plNetClientMgr::IShowLists() if (mbr->IsServer()) continue; player = (mbr->GetAvatarKey() ? plSceneObject::ConvertNoRef(mbr->GetAvatarKey()->ObjectIsLoaded()) : nullptr); - sprintf(str, "%s%s %s p2p=%d dist=%.1f", + sprintf(str, "%s%s %s dist=%.1f", mbr->GetTransportFlags() & plNetTransportMember::kSendingVoice ? "V" : " ", mbr->GetTransportFlags() & plNetTransportMember::kSendingActions ? "A" : " ", mbr->AsString().c_str(), - mbr->IsPeerToPeer(), mbr->GetDistSq() != FLT_MAX ? sqrt(mbr->GetDistSq()) :-1.f); txt.DrawString(x,y,str); y+=yOff; diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrVoice.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrVoice.cpp index 40cd6d1965..241cd93d54 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrVoice.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrVoice.cpp @@ -275,11 +275,6 @@ bool plNetClientMgr::IUpdateListenList(double secs) // I can't listen to players that are more than 50 ft away if (distSq>plNetListenList::kMaxListenDistSq) continue; - // if we are p2p and member isn't, skip them. - if ( IsPeerToPeer() && !fTransport.GetMember(i)->IsPeerToPeer() ) - continue; - // otherwise, we aren't p2p so just update the listen list - // normally so it will update in the gui as distance changes. #else float distSq=1; #endif diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.cpp index 2ecaa19e2b..c20f2d991a 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.cpp @@ -439,7 +439,7 @@ MSG_HANDLER_DEFN(plNetClientMsgHandler,plNetMsgMembersList) { plNetTransportMember* mbr = new plNetTransportMember(nc); IFillInTransportMember(m->MemberListInfo()->GetMember(i), mbr); - hsLogEntry(nc->DebugMsg("\tAdding transport member, name={}, p2p={}, plrID={}\n", mbr->AsString(), mbr->IsPeerToPeer(), mbr->GetPlayerID())); + hsLogEntry(nc->DebugMsg("\tAdding transport member, name={}, plrID={}\n", mbr->AsString(), mbr->GetPlayerID())); hsSsize_t idx = nc->fTransport.AddMember(mbr); hsAssert(idx>=0, "Failed adding member?"); diff --git a/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransportMember.h b/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransportMember.h index 04b7218d97..dfa042dde4 100644 --- a/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransportMember.h +++ b/Sources/Plasma/PubUtilLib/plNetTransport/plNetTransportMember.h @@ -97,7 +97,6 @@ class plNetTransportMember : public plNetMember void SetTransportFlags(uint32_t f) { fTransportFlags=f; } uint32_t GetTransportFlags() const { return fTransportFlags; } - bool IsPeerToPeer() const { return hsCheckBits(fFlags, kRequestP2P); } ST::string AsString() const override; bool IsEqualTo(const plNetMember * other) const override { From a47f5927ee9b6857f574e24eedf6d62affec2970 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sun, 18 Jun 2023 03:13:45 +0200 Subject: [PATCH 06/13] Remove unused plNetClientComm PreHandler --- .../plNetClientComm/plNetClientComm.cpp | 25 ------------------- .../plNetClientComm/plNetClientComm.h | 11 -------- 2 files changed, 36 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp index f85daa3801..85c0ebc549 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp @@ -154,7 +154,6 @@ static HASHTABLEDECL( ) s_handlers; static NetCommMsgHandler s_defaultHandler(0, nullptr, nullptr); -static NetCommMsgHandler s_preHandler(0, nullptr, nullptr); //============================================================================ @@ -741,7 +740,6 @@ void NetCommShutdown () { s_shutdown = true; NetCommSetDefaultMsgHandler(nullptr, nullptr); - NetCommSetMsgPreHandler(nullptr, nullptr); NetCommRemoveMsgHandler( kNetCommAllMsgClasses, kNetCommAllMsgHandlers, @@ -904,9 +902,6 @@ void NetCommRecvMsg ( plNetMessage * msg ) { for (;;) { - if (s_preHandler.proc && s_preHandler.proc(msg, s_preHandler.state) == plNetMsgHandler::Status::kConsumed) - break; - unsigned msgClassIdx = msg->ClassIndex(); NetCommMsgHandler * handler = s_handlers.Find(msgClassIdx); @@ -984,15 +979,6 @@ void NetCommSetDefaultMsgHandler ( s_defaultHandler.state = state; } -//============================================================================ -void NetCommSetMsgPreHandler ( - FNetCommMsgHandler * proc, - void * state -) { - s_preHandler.proc = proc; - s_preHandler.state = state; -} - //============================================================================ void NetCommSetAccountUsernamePassword ( const ST::string& username, @@ -1307,17 +1293,6 @@ void NetCommLogStackDump(const ST::string& stackDump) //////////////////////////////////////////////////////////////////// -// plNetClientComm ---------------------------------------------- -plNetClientComm::plNetClientComm() -{ -} - -// ~plNetClientComm ---------------------------------------------- -plNetClientComm::~plNetClientComm() -{ - NetCommSetMsgPreHandler(nullptr, nullptr); -} - // AddMsgHandlerForType ---------------------------------------------- void plNetClientComm::AddMsgHandlerForType( uint16_t msgClassIdx, MsgHandler* handler ) { diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h index b0d84113ba..6b4f5bd68d 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h @@ -179,10 +179,6 @@ void NetCommSetDefaultMsgHandler ( FNetCommMsgHandler * handler, void * userState ); -void NetCommSetMsgPreHandler ( - FNetCommMsgHandler * handler, - void * userState -); /***************************************************************************** * @@ -326,13 +322,6 @@ class plNetClientComm virtual plNetMsgHandler::Status HandleMessage(plNetMessage* msg) = 0; }; - //////////////////////////////////////////////////////////////// - - plNetClientComm(); - ~plNetClientComm(); - - //////////////////////////////////////////////////////////////// - // Adds a msg handler for a msg that is convertable to specified type. void AddMsgHandlerForType( uint16_t msgClassIdx, MsgHandler* handler ); From 4b5fe8890e9d16f21321fc8c423abe0c56db782c Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sun, 18 Jun 2023 12:25:11 +0200 Subject: [PATCH 07/13] Remove never used plNetMsgHandler kConsumed status --- Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp | 3 +-- Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgHandler.h | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp index 85c0ebc549..061dc4a9e0 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp @@ -910,8 +910,7 @@ void NetCommRecvMsg ( break; } while (handler) { - if (handler->proc(msg, handler->state) == plNetMsgHandler::Status::kConsumed) - break; + handler->proc(msg, handler->state); handler = s_handlers.FindNext(msgClassIdx, handler); } break; diff --git a/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgHandler.h b/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgHandler.h index 2ea5e3475a..a08675a313 100644 --- a/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgHandler.h +++ b/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgHandler.h @@ -60,9 +60,6 @@ class plNetMsgHandler { kError, kHandled, - // Return this value from your registered msg handler - // to stop further dispatching of incoming msg. - kConsumed, }; plNetMsgHandler() : fNetApp() { } From b6b380a103550dcd372dbb72c18511e722db58c8 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sun, 18 Jun 2023 16:48:36 +0200 Subject: [PATCH 08/13] Remove dynamic type-based plNetClientComm message handlers Now there's only one single message handler, previously called the "default handler", which takes care of all message dispatching. The previous type-based message handling was already completely unused. --- .../plNetClient/plNetClientCommInterface.cpp | 2 +- .../plNetClientComm/plNetClientComm.cpp | 145 ++---------------- .../plNetClientComm/plNetClientComm.h | 38 +---- 3 files changed, 14 insertions(+), 171 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientCommInterface.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientCommInterface.cpp index 56e9a68d6f..074edcb806 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientCommInterface.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientCommInterface.cpp @@ -68,7 +68,7 @@ void plNetClientMgr::IInitNetClientComm() NetCommActivateMsgDispatchers(); ASSERT(!GetFlagsBit(kNetClientCommInited)); - fNetClientComm.SetDefaultHandler(&fNetClientCommMsgHandler); + fNetClientComm.SetMsgHandler(&fNetClientCommMsgHandler); SetFlagsBit(kNetClientCommInited); } diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp index 061dc4a9e0..158003d0b1 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp @@ -78,16 +78,6 @@ using namespace std::literals::string_view_literals; extern bool gDataServerLocal; -/***************************************************************************** -* -* Exported data -* -***/ - -const unsigned kNetCommAllMsgClasses = (unsigned)-1; -FNetCommMsgHandler * kNetCommAllMsgHandlers = (FNetCommMsgHandler*)-1; -const void * kNetCommAllUserStates = (void*)-1; - struct NetCommParam { void * param; plNetCommReplyMsg::EParamType type; @@ -131,29 +121,8 @@ static plUUID s_iniStartupAgeInstId; static unsigned s_iniStartupPlayerId = 0; static bool s_netError = false; - -struct NetCommMsgHandler : THashKeyVal { - HASHLINK(NetCommMsgHandler) link; - FNetCommMsgHandler * proc; - void * state; - - NetCommMsgHandler ( - unsigned msgId, - FNetCommMsgHandler * proc, - void * state - ) : THashKeyVal(msgId) - , proc(proc) - , state(state) - { } -}; - -static HASHTABLEDECL( - NetCommMsgHandler, - THashKeyVal, - link -) s_handlers; - -static NetCommMsgHandler s_defaultHandler(0, nullptr, nullptr); +static FNetCommMsgHandler* s_msgHandlerProc = nullptr; +static void* s_msgHandlerState = nullptr; //============================================================================ @@ -739,13 +708,8 @@ void NetCommStartup () { void NetCommShutdown () { s_shutdown = true; - NetCommSetDefaultMsgHandler(nullptr, nullptr); - NetCommRemoveMsgHandler( - kNetCommAllMsgClasses, - kNetCommAllMsgHandlers, - kNetCommAllUserStates - ); - + NetCommSetMsgHandler(nullptr, nullptr); + NetCliGameDisconnect(); NetCliAuthDisconnect(); if (!gDataServerLocal) @@ -901,81 +865,18 @@ void NetCommSendMsg ( void NetCommRecvMsg ( plNetMessage * msg ) { - for (;;) { - unsigned msgClassIdx = msg->ClassIndex(); - NetCommMsgHandler * handler = s_handlers.Find(msgClassIdx); - - if (!handler && s_defaultHandler.proc) { - s_defaultHandler.proc(msg, s_defaultHandler.state); - break; - } - while (handler) { - handler->proc(msg, handler->state); - handler = s_handlers.FindNext(msgClassIdx, handler); - } - break; - } -} - -//============================================================================ -void NetCommAddMsgHandlerForType ( - unsigned msgClassIdx, - FNetCommMsgHandler * proc, - void * state -) { - for (unsigned i = 0; i < plFactory::GetNumClasses(); ++i) { - if (plFactory::DerivesFrom(msgClassIdx, i)) - NetCommAddMsgHandlerForExactType(i, proc, state); - } -} - -//============================================================================ -void NetCommAddMsgHandlerForExactType ( - unsigned msgClassIdx, - FNetCommMsgHandler * proc, - void * state -) { - ASSERT(msgClassIdx != kNetCommAllMsgClasses); - ASSERT(proc && proc != kNetCommAllMsgHandlers); - ASSERT(!state || (state && state != kNetCommAllUserStates)); - - NetCommRemoveMsgHandler(msgClassIdx, proc, state); - NetCommMsgHandler * handler = new NetCommMsgHandler(msgClassIdx, proc, state); - - s_handlers.Add(handler); -} - -//============================================================================ -void NetCommRemoveMsgHandler ( - unsigned msgClassIdx, - FNetCommMsgHandler * proc, - const void * state -) { - NetCommMsgHandler * next, * handler = s_handlers.Head(); - for (; handler; handler = next) { - next = handler->link.Next(); - if (handler->GetValue() != msgClassIdx) - if (msgClassIdx != kNetCommAllMsgClasses) - continue; - if (handler->proc != proc) - if (proc != kNetCommAllMsgHandlers) - continue; - if (handler->state != state) - if (state != kNetCommAllUserStates) - continue; - - // We found a matching handler, delete it - delete handler; + if (s_msgHandlerProc != nullptr) { + s_msgHandlerProc(msg, s_msgHandlerState); } } //============================================================================ -void NetCommSetDefaultMsgHandler ( +void NetCommSetMsgHandler( FNetCommMsgHandler * proc, void * state ) { - s_defaultHandler.proc = proc; - s_defaultHandler.state = state; + s_msgHandlerProc = proc; + s_msgHandlerState = state; } //============================================================================ @@ -1292,33 +1193,9 @@ void NetCommLogStackDump(const ST::string& stackDump) //////////////////////////////////////////////////////////////////// -// AddMsgHandlerForType ---------------------------------------------- -void plNetClientComm::AddMsgHandlerForType( uint16_t msgClassIdx, MsgHandler* handler ) -{ - int i; - for( i = 0; i < plFactory::GetNumClasses(); i++ ) - { - if ( plFactory::DerivesFrom( msgClassIdx, i ) ) - AddMsgHandlerForExactType( i, handler ); - } -} - -// AddMsgHandlerForExactType ---------------------------------------------- -void plNetClientComm::AddMsgHandlerForExactType( uint16_t msgClassIdx, MsgHandler* handler ) -{ - NetCommAddMsgHandlerForExactType(msgClassIdx, MsgHandler::StaticMsgHandler, handler); -} - -// RemoveMsgHandler ---------------------------------------------- -bool plNetClientComm::RemoveMsgHandler( MsgHandler* handler ) -{ - NetCommRemoveMsgHandler(kNetCommAllMsgClasses, kNetCommAllMsgHandlers, handler); - return true; -} - // SetDefaultHandler ---------------------------------------------- -void plNetClientComm::SetDefaultHandler( MsgHandler* handler) { - NetCommSetDefaultMsgHandler(MsgHandler::StaticMsgHandler, handler); +void plNetClientComm::SetMsgHandler(MsgHandler* msgHandler) { + NetCommSetMsgHandler(MsgHandler::StaticMsgHandler, msgHandler); } // MsgHandler::StaticMsgHandler ---------------------------------------------- diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h index 6b4f5bd68d..a9febe31e2 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h @@ -152,30 +152,7 @@ typedef plNetMsgHandler::Status (FNetCommMsgHandler)( void * userState ); -// Adds a msg handler for a msg that is convertable to specified type. -void NetCommAddMsgHandlerForType ( - unsigned msgClassIdx, - FNetCommMsgHandler * handler, - void * userState -); -// Adds a msg handler for a specific msg type. -void NetCommAddMsgHandlerForExactType ( - unsigned msgClassIdx, - FNetCommMsgHandler * handler, - void * userState -); - -extern const unsigned kNetCommAllMsgClasses; -extern FNetCommMsgHandler * kNetCommAllMsgHandlers; -extern const void * kNetCommAllUserStates; - -void NetCommRemoveMsgHandler ( - unsigned msgClassIdx, - FNetCommMsgHandler * handler, - const void * userState -); - -void NetCommSetDefaultMsgHandler ( +void NetCommSetMsgHandler( FNetCommMsgHandler * handler, void * userState ); @@ -322,18 +299,7 @@ class plNetClientComm virtual plNetMsgHandler::Status HandleMessage(plNetMessage* msg) = 0; }; - // Adds a msg handler for a msg that is convertable to specified type. - void AddMsgHandlerForType( uint16_t msgClassIdx, MsgHandler* handler ); - - // Adds a msg handler for a specific msg type. - void AddMsgHandlerForExactType( uint16_t msgClassIdx, MsgHandler* handler ); - - bool RemoveMsgHandler( MsgHandler* handler ); - - // Msgs not part of a task controlled by this - // object, and doesn't have a handler set for its type - // are sent to this handler (if set). - void SetDefaultHandler( MsgHandler* msgHandler ); + void SetMsgHandler(MsgHandler* msgHandler); }; //////////////////////////////////////////////////////////////////// From e2150d1c15a0c7f17625ae7d6db67465daf5de9d Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sun, 18 Jun 2023 16:56:16 +0200 Subject: [PATCH 09/13] Remove unimplemented and empty plNetClientComm functions --- .../plNetClientComm/plNetClientComm.cpp | 62 ------------------- .../plNetClientComm/plNetClientComm.h | 50 --------------- 2 files changed, 112 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp index 158003d0b1..367ca36f35 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp @@ -1045,68 +1045,6 @@ void NetCommSetAgePublic ( // --> no msg ); } -//============================================================================ -void NetCommCreatePublicAge (// --> plNetCommPublicAgeMsg - const char ageName[], - const plUUID& ageInstId, - void * param -) { -} - -//============================================================================ -void NetCommRemovePublicAge(// --> plNetCommPublicAgeMsg - const plUUID& ageInstId, - void * param -) { -} - -//============================================================================ -void NetCommRegisterOwnedAge ( - const NetCommAge & age, - const char ageInstDesc[], - unsigned playerInt, - void * param -) { -} - -//============================================================================ -void NetCommUnregisterOwnedAge ( - const char ageName[], - unsigned playerInt, - void * param -) { -} - -//============================================================================ -void NetCommRegisterVisitAge ( - const NetCommAge & age, - const char ageInstDesc[], - unsigned playerInt, - void * param -) { -} - -//============================================================================ -void NetCommUnregisterVisitAge ( - const plUUID& ageInstId, - unsigned playerInt, - void * param -) { -} - -//============================================================================ -void NetCommConnectPlayerVault ( - void * param -) { -} - -//============================================================================ -void NetCommConnectAgeVault ( - const plUUID& ageInstId, - void * param -) { -} - //============================================================================ void NetCommUpgradeVisitorToExplorer ( unsigned playerInt, diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h index a9febe31e2..f394066982 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h @@ -167,16 +167,6 @@ void NetCommSetMsgHandler( void NetCommAuthenticate ( // --> plNetCommAuthMsg void * param ); -void NetCommGetFileList ( // --> plNetCommFileListMsg - const char16_t dir[], - const char16_t ext[], - void * param -); -void NetCommGetFile ( // --> plNetCommFileDownloadMsg - const char16_t filename[], - hsStream * writer, - void * param -); void NetCommLinkToAge ( // --> plNetCommLinkToAgeMsg const NetCommAge & age, void * param @@ -205,46 +195,6 @@ void NetCommSetAgePublic ( // --> no msg unsigned ageInfoId, bool makePublic ); -void NetCommCreatePublicAge (// --> plNetCommPublicAgeMsg - const char ageName[], - const plUUID& ageInstId, - void * param -); -void NetCommRemovePublicAge(// --> plNetCommPublicAgeMsg - const plUUID& ageInstId, - void * param -); -void NetCommRegisterOwnedAge ( - const NetCommAge & age, - const char ageInstDesc[], - unsigned playerInt, - void * param -); -void NetCommUnregisterOwnedAge ( - const char ageName[], - unsigned playerInt, - void * param -); -void NetCommRegisterVisitAge ( - const NetCommAge & age, - const char ageInstDesc[], - unsigned playerInt, - void * param -); -void NetCommUnregisterVisitAge ( - const plUUID& ageInstId, - unsigned playerInt, - void * param -); -void NetCommConnectPlayerVault ( - void * param -); -void NetCommDisconnectPlayerVault (); -void NetCommConnectAgeVault ( - const plUUID& ageInstId, - void * param -); -void NetCommDisconnectAgeVault (); void NetCommUpgradeVisitorToExplorer ( unsigned playerInt, void * param From 48e1d3762e3f6836a7ed90d620e0382fdb97ef08 Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sun, 18 Jun 2023 23:21:47 +0200 Subject: [PATCH 10/13] Hardcode that all plNetMessages are sent via the game server Nothing used the option to send a plNetMessage to the auth server. DIRTSAND and MOSS don't support handling such messages either. --- .../pfConsole/pfConsoleCommands.cpp | 1 - .../pfConsole/pfConsoleCommandsNet.cpp | 1 - .../plAgeLoader/plAgeLoaderPaging.cpp | 2 -- .../Plasma/PubUtilLib/plAudio/plVoiceChat.cpp | 2 -- .../PubUtilLib/plAvatar/plArmatureMod.cpp | 1 - .../PubUtilLib/plModifier/plLogicModifier.cpp | 1 - .../PubUtilLib/plModifier/plSDLModifier.cpp | 1 - .../plNetClient/plNetCliAgeJoiner.cpp | 1 - .../PubUtilLib/plNetClient/plNetClientMgr.cpp | 2 -- .../plNetClient/plNetClientMgrSend.cpp | 3 --- .../plNetClient/plNetClientMgrVoice.cpp | 1 - .../plNetClientComm/plNetClientComm.cpp | 26 ++++--------------- .../PubUtilLib/plNetMessage/CMakeLists.txt | 1 - .../PubUtilLib/plNetMessage/plNetMessage.h | 6 +---- 14 files changed, 6 insertions(+), 43 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp index 8124ae1d6d..0ca661a9a6 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp @@ -5270,7 +5270,6 @@ PF_CONSOLE_CMD(Age, ResetPythonSDL, "", "Resets the Python Age SDL") constexpr uint32_t writeOptions = plSDL::kDirtyOnly | plSDL::kBroadcast | plSDL::kTimeStampOnRead; plNetMsgSDLState* netMsg = rec->PrepNetMsg(0.f, writeOptions); - netMsg->SetNetProtocol(kNetProtocolCli2Game); netMsg->ObjectInfo()->SetUoid(sdlMod->GetStateOwnerKey()->GetUoid()); netMsg->SetPlayerID(plNetClientApp::GetInstance()->GetPlayerID()); plNetClientApp::GetInstance()->SendMsg(netMsg); diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp index 3e94fb4bc5..6b886075b8 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp @@ -506,7 +506,6 @@ PF_CONSOLE_CMD( Net, // groupName // send net msg plNetMsgObjectUpdateFilter netMsg; - netMsg.SetNetProtocol(kNetProtocolCli2Game); netMsg.SetMaxUpdateFreq(freq); netMsg.ObjectListInfo()->AddObject(key); plNetClientMgr::GetInstance()->SendMsg(&netMsg); diff --git a/Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoaderPaging.cpp b/Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoaderPaging.cpp index c055cb3862..235eafbfdc 100644 --- a/Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoaderPaging.cpp +++ b/Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoaderPaging.cpp @@ -97,7 +97,6 @@ void plAgeLoader::FinishedPagingInRoom(plKey* rmKey, int numRms) // Send a msg to the server indicating that we have this room paged in plNetMsgPagingRoom * pagingMsg = new plNetMsgPagingRoom; - pagingMsg->SetNetProtocol(kNetProtocolCli2Game); int i; for(i=0;iGetPlayerID()); if (plNetClientApp::GetInstance()->GetFlagsBit(plNetClientApp::kEchoVoice)) @@ -309,7 +308,6 @@ void plVoiceRecorder::Update(double time) if (packedLength) { plNetMsgVoice pMsg; - pMsg.SetNetProtocol(kNetProtocolCli2Game); pMsg.SetVoiceData(packet.get(), packedLength); pMsg.SetPlayerID(plNetClientApp::GetInstance()->GetPlayerID()); pMsg.SetFlag(encoder->GetVoiceFlag()); diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp index 14488ac125..e491b5573d 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp @@ -1556,7 +1556,6 @@ bool plArmatureMod::IEval(double time, float elapsed, uint32_t dirty) { // Send message to the server here. plNetMsgRelevanceRegions relRegionsNetMsg; - relRegionsNetMsg.SetNetProtocol(kNetProtocolCli2Game); relRegionsNetMsg.SetRegionsICareAbout(fRegionsICareAbout); relRegionsNetMsg.SetRegionsImIn(fRegionsImIn); plNetClientApp::GetInstance()->SendMsg(&relRegionsNetMsg); diff --git a/Sources/Plasma/PubUtilLib/plModifier/plLogicModifier.cpp b/Sources/Plasma/PubUtilLib/plModifier/plLogicModifier.cpp index 67dba7095c..a6dbb09f21 100644 --- a/Sources/Plasma/PubUtilLib/plModifier/plLogicModifier.cpp +++ b/Sources/Plasma/PubUtilLib/plModifier/plLogicModifier.cpp @@ -240,7 +240,6 @@ void plLogicModifier::UpdateSharedState(bool triggered) const ss.SetServerMayDelete(!lock); plNetMsgTestAndSet ts; - ts.SetNetProtocol(kNetProtocolCli2Game); ts.CopySharedState(&ss); ts.ObjectInfo()->SetFromKey(GetKey()); ts.SetLockRequest(lock); // if triggering, lock state, else unlock state diff --git a/Sources/Plasma/PubUtilLib/plModifier/plSDLModifier.cpp b/Sources/Plasma/PubUtilLib/plModifier/plSDLModifier.cpp index ff671dd2c2..882580fe89 100644 --- a/Sources/Plasma/PubUtilLib/plModifier/plSDLModifier.cpp +++ b/Sources/Plasma/PubUtilLib/plModifier/plSDLModifier.cpp @@ -102,7 +102,6 @@ void plSDLModifier::ISendNetMsg(plStateDataRecord*& state, const plKey& senderKe // send to server plNetMsgSDLState* msg = state->PrepNetMsg(0, writeOptions); - msg->SetNetProtocol(kNetProtocolCli2Game); msg->ObjectInfo()->SetUoid(senderKey->GetUoid()); if (sendFlags & plSynchedObject::kNewState) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetCliAgeJoiner.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetCliAgeJoiner.cpp index e5791f7ace..054bc39788 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetCliAgeJoiner.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetCliAgeJoiner.cpp @@ -315,7 +315,6 @@ void plNCAgeJoiner::ExecNextOp () { // Request initial SDL state plNetMsgGameStateRequest gsmsg; - gsmsg.SetNetProtocol(kNetProtocolCli2Game); gsmsg.SetBit(plNetMessage::kInitialAgeStateRequest); nc->SendMsg(&gsmsg); diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp index 5e6e589846..2d6057708d 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp @@ -1193,7 +1193,6 @@ bool plNetClientMgr::IHandlePlayerPageMsg(plPlayerPageMsg *playerMsg) // notify server - NOTE: he might not still be around to get this... plNetMsgPlayerPage npp (playerKey->GetUoid(), playerMsg->fUnload); - npp.SetNetProtocol(kNetProtocolCli2Game); SendMsg(&npp); } else if (int idx; IsRemotePlayerKey(playerKey, &idx)) @@ -1235,7 +1234,6 @@ bool plNetClientMgr::IHandlePlayerPageMsg(plPlayerPageMsg *playerMsg) // notify server plNetMsgPlayerPage npp (playerKey->GetUoid(), playerMsg->fUnload); - npp.SetNetProtocol(kNetProtocolCli2Game); SendMsg(&npp); } else diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp index 1a6b3afa6d..e295d3a677 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp @@ -80,7 +80,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com void plNetClientMgr::ISendMembersListRequest() { plNetMsgMembersListReq msg; - msg.SetNetProtocol(kNetProtocolCli2Game); SendMsg(&msg); } @@ -91,7 +90,6 @@ void plNetClientMgr::ISendRoomsReset() { plNetMsgPagingRoom msg; msg.SetPageFlags(plNetMsgPagingRoom::kResetList); - msg.SetNetProtocol(kNetProtocolCli2Game); SendMsg(&msg); } @@ -377,7 +375,6 @@ void plNetClientMgr::ISendGameMessage(plMessage* msg) #endif netMsgWrap->SetPlayerID(GetPlayerID()); - netMsgWrap->SetNetProtocol(kNetProtocolCli2Game); SendMsg(netMsgWrap); if (plNetObjectDebugger::GetInstance()->IsDebugObject(msg->GetSender() ? msg->GetSender()->ObjectIsLoaded() : nullptr)) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrVoice.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrVoice.cpp index 241cd93d54..88b1d7bf05 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrVoice.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrVoice.cpp @@ -106,7 +106,6 @@ bool plNetClientMgr::IApplyNewListenList(std::vector& newListenList, plNetMsgListenListUpdate llu; llu.SetPlayerID(GetPlayerID()); - llu.SetNetProtocol(kNetProtocolCli2Game); // // for each client in the old list, if not in the new list, send a ListenList remove msg diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp index 367ca36f35..26e6a3b51a 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp @@ -837,28 +837,12 @@ void NetCommSendMsg ( hsRAMStream stream; msg->PokeBuffer(&stream); - size_t msgSize = stream.GetEOF(); - auto buf = static_cast(stream.GetData()); - - switch (msg->GetNetProtocol()) { - case kNetProtocolCli2Auth: - NetCliAuthPropagateBuffer( - msg->ClassIndex(), - msgSize, - buf - ); - break; - - case kNetProtocolCli2Game: - NetCliGamePropagateBuffer( - msg->ClassIndex(), - msgSize, - buf - ); - break; - DEFAULT_FATAL(msg->GetNetProtocol()); - } + NetCliGamePropagateBuffer( + msg->ClassIndex(), + stream.GetEOF(), + static_cast(stream.GetData()) + ); } //============================================================================ diff --git a/Sources/Plasma/PubUtilLib/plNetMessage/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plNetMessage/CMakeLists.txt index a84624aab6..84746c33b8 100644 --- a/Sources/Plasma/PubUtilLib/plNetMessage/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plNetMessage/CMakeLists.txt @@ -17,7 +17,6 @@ target_link_libraries( CoreLib pnFactory pnKeyedObject - pnNetBase pnNetCommon plNetCommon plUnifiedTime diff --git a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h index fee672983d..73b88df7d1 100644 --- a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h +++ b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h @@ -45,7 +45,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "hsBitVector.h" -#include "pnNetBase/pnNetBase.h" #include "pnNetCommon/plNetGroup.h" #include "pnFactory/plCreatable.h" @@ -83,7 +82,6 @@ class plNetMessage : public plCreatable uint32_t fPeekStatus; // not sent. set on PeekBuffer, cleared on PokeBuffer uint8_t fProtocolVerMajor; // conditionally sent uint8_t fProtocolVerMinor; // conditionally sent - ENetProtocol fNetProtocol; // the server this msg should be sent to. this value is not sent over wire. enum ContentFlags { @@ -180,7 +178,7 @@ class plNetMessage : public plCreatable plNetMessage() : fTimeRecvd(), fBytesRead(), fContext(), fPeekStatus(), fTransactionID(), fPlayerID(kInvalidPlayerID), - fNetProtocol(), fProtocolVerMajor(), fProtocolVerMinor(), + fProtocolVerMajor(), fProtocolVerMinor(), fFlags(0) { } @@ -208,7 +206,6 @@ class plNetMessage : public plCreatable const plUUID * GetAcctUUID() const { return &fAcctUUID; } uint8_t GetVersionMajor() const { return fProtocolVerMajor; } uint8_t GetVersionMinor() const { return fProtocolVerMinor; } - ENetProtocol GetNetProtocol () const { return fNetProtocol; } // setters void SetTimeSent(const plUnifiedTime& t) { fTimeSent=t;SetHasTimeSent(true); } @@ -224,7 +221,6 @@ class plNetMessage : public plCreatable void SetHasAcctUUID( bool v ) { SetBit( kHasAcctUUID,v ); } void SetAcctUUID(const plUUID * v ) { fAcctUUID.CopyFrom(v); SetHasAcctUUID(true); } void SetVersion(uint8_t maj=kVerMajor, uint8_t min=kVerMinor) { SetBit(kHasVersion); fProtocolVerMajor=maj; fProtocolVerMinor=min; } - void SetNetProtocol (ENetProtocol v ) { fNetProtocol = v; } // init fContext, fTransactionID, etc. if needed. void InitReplyFieldsFrom(plNetMessage * msg); From 3010c68930c1c3ba56b542316ae29363b84157cd Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sun, 18 Jun 2023 23:29:48 +0200 Subject: [PATCH 11/13] Remove empty plNetCommonConstants.h --- Sources/Plasma/Apps/plClient/plClient.cpp | 1 - .../PubUtilLib/plNetCommon/CMakeLists.txt | 1 - .../plNetCommon/plNetCommonConstants.h | 49 ------------------- .../PubUtilLib/plNetMessage/plNetMessage.h | 1 - 4 files changed, 52 deletions(-) delete mode 100644 Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonConstants.h diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index 2eb8c1f1f7..5c8af209ba 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/Sources/Plasma/Apps/plClient/plClient.cpp @@ -110,7 +110,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plNetClient/plLinkEffectsMgr.h" #include "plNetClient/plNetLinkingMgr.h" #include "plNetClient/plNetClientMgr.h" -#include "plNetCommon/plNetCommonConstants.h" #include "plNetGameLib/plNetGameLib.h" #include "plPipeline/plCaptureRender.h" #include "plPipeline/plDTProgressMgr.h" diff --git a/Sources/Plasma/PubUtilLib/plNetCommon/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plNetCommon/CMakeLists.txt index 113d9699ea..650cfab1b4 100644 --- a/Sources/Plasma/PubUtilLib/plNetCommon/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plNetCommon/CMakeLists.txt @@ -12,7 +12,6 @@ set(plNetCommon_SOURCES set(plNetCommon_HEADERS plClientGuid.h plNetCommon.h - plNetCommonConstants.h plNetCommonCreatable.h plNetCommonHelpers.h plNetMember.h diff --git a/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonConstants.h b/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonConstants.h deleted file mode 100644 index 528ac1e596..0000000000 --- a/Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonConstants.h +++ /dev/null @@ -1,49 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ -#ifndef plNetCommonConstants_h_inc -#define plNetCommonConstants_h_inc - - - -#endif // plNetCommonConstants_h_inc - - diff --git a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h index 73b88df7d1..020454a87d 100644 --- a/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h +++ b/Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.h @@ -52,7 +52,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plNetCommon/plNetServerSessionInfo.h" #include "plNetCommon/plNetCommon.h" -#include "plNetCommon/plNetCommonConstants.h" #include "plNetCommon/plNetCommonHelpers.h" #include "plUnifiedTime/plClientUnifiedTime.h" From 9fba8cc9a03240ad4b946eb0978320f6494447ed Mon Sep 17 00:00:00 2001 From: dgelessus Date: Mon, 19 Jun 2023 22:10:00 +0200 Subject: [PATCH 12/13] Reduce indirection in plNetMessage handling The parsed plNetMessage is now passed directly to the actual handler, making the code much easier to follow. --- .../plNetClient/plNetClientCommInterface.cpp | 18 ++-------- .../PubUtilLib/plNetClient/plNetClientMgr.h | 8 +---- .../plNetClientComm/plNetClientComm.cpp | 35 ++++--------------- .../plNetClientComm/plNetClientComm.h | 26 +------------- 4 files changed, 11 insertions(+), 76 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientCommInterface.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientCommInterface.cpp index 074edcb806..1712f2b0ed 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientCommInterface.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientCommInterface.cpp @@ -41,34 +41,19 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ #include "plNetClientMgr.h" -#include "plNetLinkingMgr.h" - -#include "plgDispatch.h" -#include "hsTimer.h" - -#include "plNetClientRecorder/plNetClientRecorder.h" -#include "plNetMessage/plNetMessage.h" - // // Code for interfacing with plNetClientComm library, which in turn // handles most client-server communication // - -plNetMsgHandler::Status plNetClientCommMsgHandler::HandleMessage(plNetMessage* msg) -{ - plNetClientMgr* nc=plNetClientMgr::GetInstance(); - return nc->fMsgHandler.ReceiveMsg(msg); -} - void plNetClientMgr::IInitNetClientComm() { NetCommActivatePostInitErrorHandler(); NetCommActivateMsgDispatchers(); ASSERT(!GetFlagsBit(kNetClientCommInited)); - fNetClientComm.SetMsgHandler(&fNetClientCommMsgHandler); + fNetClientComm.SetMsgHandler(&fMsgHandler); SetFlagsBit(kNetClientCommInited); } @@ -78,5 +63,6 @@ void plNetClientMgr::IInitNetClientComm() // void plNetClientMgr::IDeInitNetClientComm() { + fNetClientComm.SetMsgHandler(nullptr); SetFlagsBit(kNetClientCommInited, false); } diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h index 2cc7f3e1bf..e8cad46975 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h @@ -81,10 +81,6 @@ class plCCRPetitionMsg; class plNetMsgPagingRoom; -struct plNetClientCommMsgHandler : plNetClientComm::MsgHandler { - plNetMsgHandler::Status HandleMessage(plNetMessage* msg) override; -}; - class plNetClientMgr : public plNetClientApp { private: @@ -370,8 +366,7 @@ class plNetClientMgr : public plNetClientApp private: plNetClientComm fNetClientComm; - plNetClientCommMsgHandler fNetClientCommMsgHandler; - + void IInitNetClientComm(); void IDeInitNetClientComm(); void INetClientCommOpStarted(uint32_t context); @@ -382,7 +377,6 @@ class plNetClientMgr : public plNetClientApp friend class plNetDniInfoSource; friend class plNetTalkList; friend class plNetClientMsgHandler; - friend struct plNetClientCommMsgHandler; }; #endif // PL_NET_CLIENT_inc diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp index 26e6a3b51a..eab5846245 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp @@ -121,8 +121,7 @@ static plUUID s_iniStartupAgeInstId; static unsigned s_iniStartupPlayerId = 0; static bool s_netError = false; -static FNetCommMsgHandler* s_msgHandlerProc = nullptr; -static void* s_msgHandlerState = nullptr; +static plNetMsgHandler* s_msgHandler = nullptr; //============================================================================ @@ -708,8 +707,6 @@ void NetCommStartup () { void NetCommShutdown () { s_shutdown = true; - NetCommSetMsgHandler(nullptr, nullptr); - NetCliGameDisconnect(); NetCliAuthDisconnect(); if (!gDataServerLocal) @@ -849,20 +846,11 @@ void NetCommSendMsg ( void NetCommRecvMsg ( plNetMessage * msg ) { - if (s_msgHandlerProc != nullptr) { - s_msgHandlerProc(msg, s_msgHandlerState); + if (s_msgHandler != nullptr) { + s_msgHandler->ReceiveMsg(msg); } } -//============================================================================ -void NetCommSetMsgHandler( - FNetCommMsgHandler * proc, - void * state -) { - s_msgHandlerProc = proc; - s_msgHandlerState = state; -} - //============================================================================ void NetCommSetAccountUsernamePassword ( const ST::string& username, @@ -1108,20 +1096,11 @@ void NetCommLogStackDump(const ST::string& stackDump) /***************************************************************************** * -* Msg handler interface - compatibility layer with legacy code +* Msg handler interface * ***/ - -//////////////////////////////////////////////////////////////////// - -// SetDefaultHandler ---------------------------------------------- -void plNetClientComm::SetMsgHandler(MsgHandler* msgHandler) { - NetCommSetMsgHandler(MsgHandler::StaticMsgHandler, msgHandler); -} - -// MsgHandler::StaticMsgHandler ---------------------------------------------- -plNetMsgHandler::Status plNetClientComm::MsgHandler::StaticMsgHandler(plNetMessage* msg, void* userState) { - plNetClientComm::MsgHandler * handler = (plNetClientComm::MsgHandler *) userState; - return handler->HandleMessage(msg); +void plNetClientComm::SetMsgHandler(plNetMsgHandler* msgHandler) +{ + s_msgHandler = msgHandler; } diff --git a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h index f394066982..3447cebfe8 100644 --- a/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h +++ b/Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.h @@ -141,22 +141,6 @@ void NetCommActivatePostInitErrorHandler(); void NetCommActivateMsgDispatchers(); -/***************************************************************************** -* -* Net message handlers -* -***/ - -typedef plNetMsgHandler::Status (FNetCommMsgHandler)( - plNetMessage * msg, - void * userState -); - -void NetCommSetMsgHandler( - FNetCommMsgHandler * handler, - void * userState -); - /***************************************************************************** * * Network requests @@ -241,15 +225,7 @@ void NetCommLogStackDump(const ST::string& stackDump); class plNetClientComm { public: - // Message handler for unsolicited msgs or registered for specific msg types. - class MsgHandler - { - public: - static plNetMsgHandler::Status StaticMsgHandler(plNetMessage* msg, void* userState); - virtual plNetMsgHandler::Status HandleMessage(plNetMessage* msg) = 0; - }; - - void SetMsgHandler(MsgHandler* msgHandler); + void SetMsgHandler(plNetMsgHandler* msgHandler); }; //////////////////////////////////////////////////////////////////// From bba383881e5ada08f6eca5d05f297680af18cfaf Mon Sep 17 00:00:00 2001 From: dgelessus Date: Mon, 19 Jun 2023 22:41:54 +0200 Subject: [PATCH 13/13] Change plNetMsgHandler message parameters to not be references --- .../Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.cpp | 2 +- .../Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.h | 2 +- Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgHandler.h | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.cpp index c20f2d991a..87b38aa7af 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.cpp @@ -104,7 +104,7 @@ void plNetClientMsgHandler::IFillInTransportMember(const plNetMsgMemberInfoHelpe mbr->SetAvatarKey(avKey); } -plNetMsgHandler::Status plNetClientMsgHandler::ReceiveMsg(plNetMessage *& netMsg) +plNetMsgHandler::Status plNetClientMsgHandler::ReceiveMsg(plNetMessage* netMsg) { #ifdef HS_DEBUGGING //plNetClientMgr::GetInstance()->DebugMsg(" {}", netMsg->ClassName()); diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.h b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.h index 0bd9d7363e..9ecd01e451 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.h +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMsgHandler.h @@ -70,7 +70,7 @@ class plNetClientMsgHandler : public plNetMsgHandler plNetClientMsgHandler(plNetClientMgr * mgr); ~plNetClientMsgHandler(); - plNetMsgHandler::Status ReceiveMsg(plNetMessage *& netMsg) override; + plNetMsgHandler::Status ReceiveMsg(plNetMessage* netMsg) override; MSG_HANDLER_DECL(plNetMsgTerminated) MSG_HANDLER_DECL(plNetMsgGroupOwner) diff --git a/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgHandler.h b/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgHandler.h index a08675a313..4fe32a2dc7 100644 --- a/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgHandler.h +++ b/Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgHandler.h @@ -68,7 +68,7 @@ class plNetMsgHandler void SetNetApp(plNetApp* na) { fNetApp=na; } plNetApp* GetNetApp() { return fNetApp; } - virtual Status ReceiveMsg(plNetMessage*& netMsg) = 0; + virtual Status ReceiveMsg(plNetMessage* netMsg) = 0; }; #define MSG_HANDLER(msgClassName) msgClassName##HandleMsg @@ -77,13 +77,13 @@ class plNetMsgHandler // Use to declare msg handler fxns in your MsgHandler .h class header // #define MSG_HANDLER_DECL(msgClassName) \ -virtual plNetMsgHandler::Status MSG_HANDLER(msgClassName)(plNetMessage*& netMsg); +virtual plNetMsgHandler::Status MSG_HANDLER(msgClassName)(plNetMessage* netMsg); // // Use to define msg handler fxns in your MsgHandler .cpp file // #define MSG_HANDLER_DEFN(handlerClassName, msgClassName) \ -plNetMsgHandler::Status handlerClassName::MSG_HANDLER(msgClassName)(plNetMessage*& netMsg) +plNetMsgHandler::Status handlerClassName::MSG_HANDLER(msgClassName)(plNetMessage* netMsg) // // Use in the switch statement in your ReceiveMsg function