Skip to content

Commit

Permalink
Merge pull request #1463 from dgelessus/netclient_simplification
Browse files Browse the repository at this point in the history
Remove lots of unused logic in game server messaging
  • Loading branch information
Hoikas authored Aug 15, 2023
2 parents a96199a + bba3838 commit 49eb827
Show file tree
Hide file tree
Showing 32 changed files with 60 additions and 980 deletions.
1 change: 0 additions & 1 deletion Sources/Plasma/Apps/plClient/plClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions Sources/Plasma/PubUtilLib/plAgeLoader/plAgeLoaderPaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;i<numRms;i++)
{
Expand Down Expand Up @@ -168,7 +167,6 @@ void plAgeLoader::StartPagingOutRoom(plKey* rmKey, int numRms)
plNetClientApp* nc = plNetClientApp::GetInstance();

plNetMsgPagingRoom pagingMsg;
pagingMsg.SetNetProtocol(kNetProtocolCli2Game);
pagingMsg.SetPagingOut(true);
int i;
for(i=0;i<numRms;i++)
Expand Down
2 changes: 0 additions & 2 deletions Sources/Plasma/PubUtilLib/plAudio/plVoiceChat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ void plVoiceRecorder::Update(double time)

if (!encoder) {
plNetMsgVoice pMsg;
pMsg.SetNetProtocol(kNetProtocolCli2Game);
pMsg.SetVoiceData(buffer.get(), totalSamples * sizeof(int16_t));
pMsg.SetPlayerID(plNetClientApp::GetInstance()->GetPlayerID());
if (plNetClientApp::GetInstance()->GetFlagsBit(plNetClientApp::kEchoVoice))
Expand All @@ -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());
Expand Down
1 change: 0 additions & 1 deletion Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion Sources/Plasma/PubUtilLib/plModifier/plLogicModifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Sources/Plasma/PubUtilLib/plModifier/plSDLModifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ void plNCAgeJoiner::ExecNextOp () {

// Request initial SDL state
plNetMsgGameStateRequest gsmsg;
gsmsg.SetNetProtocol(kNetProtocolCli2Game);
gsmsg.SetBit(plNetMessage::kInitialAgeStateRequest);
nc->SendMsg(&gsmsg);

Expand Down
18 changes: 2 additions & 16 deletions Sources/Plasma/PubUtilLib/plNetClient/plNetClientCommInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.SetDefaultHandler(&fNetClientCommMsgHandler);
fNetClientComm.SetMsgHandler(&fMsgHandler);

SetFlagsBit(kNetClientCommInited);
}
Expand All @@ -78,5 +63,6 @@ void plNetClientMgr::IInitNetClientComm()
//
void plNetClientMgr::IDeInitNetClientComm()
{
fNetClientComm.SetMsgHandler(nullptr);
SetFlagsBit(kNetClientCommInited, false);
}
40 changes: 2 additions & 38 deletions Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

//
Expand Down Expand Up @@ -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;
Expand All @@ -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;i<rl->GetNumReceivers();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;
}

//
Expand Down Expand Up @@ -1227,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))
Expand Down Expand Up @@ -1269,7 +1234,6 @@ bool plNetClientMgr::IHandlePlayerPageMsg(plPlayerPageMsg *playerMsg)

// notify server
plNetMsgPlayerPage npp (playerKey->GetUoid(), playerMsg->fUnload);
npp.SetNetProtocol(kNetProtocolCli2Game);
SendMsg(&npp);
}
else
Expand Down
23 changes: 2 additions & 21 deletions Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,11 @@ class plCCRPetitionMsg;
class plNetMsgPagingRoom;


struct plNetClientCommMsgHandler : plNetClientComm::MsgHandler {
plNetMsgHandler::Status HandleMessage(plNetMessage* msg) override;
};

class plNetClientMgr : public plNetClientApp
{
private:
typedef std::vector<plKey> plKeyVec;
public:

enum NetChannels
{
kNetChanDefault,
kNetChanVoice,
kNetChanListenListUpdate,
kNetChanDirectedMsg,
kNetNumChannels
};

enum DirectedSendFlags
{
kInterAgeMsg = 0x1
Expand Down Expand Up @@ -211,7 +197,7 @@ class plNetClientMgr : public plNetClientApp
bool IUpdateListenList(double secs);
void IHandleNetVoiceListMsg(plNetVoiceListMsg* msg);
bool IApplyNewListenList(std::vector<DistSqInfo>& newListenList, bool forceSynch);
int IPrepMsg(plNetMessage* msg);
void IPrepMsg(plNetMessage* msg);
void IPlayerChangeAge(bool exiting, int32_t spawnPt);

void IAddCloneRoom();
Expand Down Expand Up @@ -289,9 +275,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; }
Expand Down Expand Up @@ -383,8 +366,7 @@ class plNetClientMgr : public plNetClientApp

private:
plNetClientComm fNetClientComm;
plNetClientCommMsgHandler fNetClientCommMsgHandler;


void IInitNetClientComm();
void IDeInitNetClientComm();
void INetClientCommOpStarted(uint32_t context);
Expand All @@ -395,7 +377,6 @@ class plNetClientMgr : public plNetClientApp
friend class plNetDniInfoSource;
friend class plNetTalkList;
friend class plNetClientMsgHandler;
friend struct plNetClientCommMsgHandler;
};

#endif // PL_NET_CLIENT_inc
Expand Down
7 changes: 2 additions & 5 deletions Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -91,7 +90,6 @@ void plNetClientMgr::ISendRoomsReset()
{
plNetMsgPagingRoom msg;
msg.SetPageFlags(plNetMsgPagingRoom::kResetList);
msg.SetNetProtocol(kNetProtocolCli2Game);
SendMsg(&msg);
}

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -412,11 +409,11 @@ void plNetClientMgr::SendMsg(plNetMessage* msg)
}

msg->SetTimeSent(plUnifiedTime::GetCurrent());
int channel = IPrepMsg(msg);
IPrepMsg(msg);

// hsLogEntry( DebugMsg( "<SND> {} {}", msg->ClassName(), msg->AsStdString()) );

fTransport.SendMsg(channel, msg);
fTransport.SendMsg(msg);

// Debug
if (plNetMsgVoice::ConvertNoRef(msg))
Expand Down
9 changes: 4 additions & 5 deletions Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrShow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgrVoice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ bool plNetClientMgr::IApplyNewListenList(std::vector<DistSqInfo>& 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
Expand Down Expand Up @@ -275,11 +274,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
Expand Down
Loading

0 comments on commit 49eb827

Please sign in to comment.