2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-13 18:17:49 -04:00

Fix line endings and tabs

This commit is contained in:
Branan Purvine-Riley
2011-04-11 16:27:55 -07:00
parent d4250e19b5
commit 908aaeb6f6
2738 changed files with 702562 additions and 702562 deletions

View File

@ -1,19 +1,19 @@
include_directories("../../CoreLib")
include_directories("../../NucleusLib/inc")
include_directories("../../NucleusLib")
include_directories("../../PubUtilLib")
set(plNetClientRecorder_SOURCES
plNetClientRecorder.cpp
plNetClientStatsRecorder.cpp
plNetClientStreamRecorder.cpp
)
set(plNetClientRecorder_HEADERS
plNetClientRecorder.h
)
add_library(plNetClientRecorder STATIC ${plNetClientRecorder_SOURCES} ${plNetClientRecorder_HEADERS})
source_group("Source Files" FILES ${plNetClientRecorder_SOURCES})
source_group("Header Files" FILES ${plNetClientRecorder_HEADERS})
include_directories("../../CoreLib")
include_directories("../../NucleusLib/inc")
include_directories("../../NucleusLib")
include_directories("../../PubUtilLib")
set(plNetClientRecorder_SOURCES
plNetClientRecorder.cpp
plNetClientStatsRecorder.cpp
plNetClientStreamRecorder.cpp
)
set(plNetClientRecorder_HEADERS
plNetClientRecorder.h
)
add_library(plNetClientRecorder STATIC ${plNetClientRecorder_SOURCES} ${plNetClientRecorder_HEADERS})
source_group("Source Files" FILES ${plNetClientRecorder_SOURCES})
source_group("Header Files" FILES ${plNetClientRecorder_HEADERS})

View File

@ -1,160 +1,160 @@
/*==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 <http://www.gnu.org/licenses/>.
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==*/
#include "plNetClientRecorder.h"
#include "hsStream.h"
#include "hsTimer.h"
#include "plNetMessage/plNetMessage.h"
#include "plCreatableIndex.h"
#include "hsResMgr.h"
#include "plgDispatch.h"
#include "plSDL/plSDL.h"
#include "pnNetCommon/plNetApp.h"
#include "plMessage/plLinkToAgeMsg.h"
#include "plMessage/plLoadAvatarMsg.h"
#include "pnMessage/plNotifyMsg.h"
#include "plMessage/plAgeLoadedMsg.h"
#include "plStatusLog/plStatusLog.h"
#include "plFile/hsFiles.h"
plNetClientRecorder::plNetClientRecorder(TimeWrapper* timeWrapper) :
fTimeWrapper(timeWrapper)
{
}
plNetClientRecorder::~plNetClientRecorder()
{
}
double plNetClientRecorder::GetTime()
{
if (fTimeWrapper)
return fTimeWrapper->GetWrappedTime();
else
return hsTimer::GetSysSeconds();
}
void plNetClientRecorder::IMakeFilename(const char* recName, char* path)
{
strcpy(path, "Recordings" PATH_SEPARATOR_STR);
#if HS_BUILD_FOR_WIN32
CreateDirectory(path, NULL);
#endif
const char* lastDot = strrchr(recName, '.');
if (lastDot)
strncat(path, recName, lastDot-recName);
else
strcat(path, recName);
strcat(path, ".rec");
}
bool plNetClientRecorder::IsRecordableMsg(plNetMessage* msg) const
{
UInt16 idx = msg->ClassIndex();
return (
idx == CLASS_INDEX_SCOPED(plNetMsgLoadClone) ||
idx == CLASS_INDEX_SCOPED(plNetMsgSDLStateBCast) ||
idx == CLASS_INDEX_SCOPED(plNetMsgSDLState) ||
idx == CLASS_INDEX_SCOPED(plNetMsgGameMessage)
);
}
plNetClientLoggingRecorder::plNetClientLoggingRecorder(TimeWrapper* timeWrapper) :
plNetClientRecorder(timeWrapper),
fPlaybackTimeOffset(0),
fNextPlaybackTime(0),
fLog(nil),
fBetweenAges(true)
{
}
plNetClientLoggingRecorder::~plNetClientLoggingRecorder()
{
delete fLog;
fLog = nil;
}
bool plNetClientLoggingRecorder::IProcessRecordMsg(plNetMessage* msg, double secs)
{
if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plNetMsgGameMessage))
{
plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg);
UInt16 gameMsgIdx = gameMsg->StreamInfo()->GetStreamType();
if (gameMsgIdx == CLASS_INDEX_SCOPED(plServerReplyMsg))
return false;
// Throw out any notify messages that don't involve picking (running into
// detectors and that sort of thing should be recreated automatically
// during playback)
if (gameMsgIdx == CLASS_INDEX_SCOPED(plNotifyMsg))
{
bool hasPick = false;
plNotifyMsg* notifyMsg = plNotifyMsg::ConvertNoRef(gameMsg->GetContainedMsg());
int numEvents = notifyMsg->GetEventCount();
for (int i = 0; i < numEvents; i++)
{
proEventData* event = notifyMsg->GetEventRecord(i);
if (event->fEventType == proEventData::kPicked)
hasPick = true;
}
hsRefCnt_SafeUnRef(notifyMsg);
if (!hasPick)
return false;
}
}
if (fPlaybackTimeOffset == 0)
fPlaybackTimeOffset = secs;
return true;
}
void plNetClientLoggingRecorder::RecordLinkMsg(plLinkToAgeMsg* linkMsg, double secs)
{
if (!linkMsg->HasBCastFlag(plMessage::kNetSent))
{
plNetMsgGameMessage netMsgWrap;
// write message (and label) to ram stream
hsRAMStream stream;
hsgResMgr::ResMgr()->WriteCreatable(&stream, linkMsg);
// put stream in net msg wrapper
netMsgWrap.StreamInfo()->CopyStream(&stream);
// netMsgWrap.StreamInfo()->SetStreamType(linkMsg->ClassIndex()); // type of game msg
RecordMsg(&netMsgWrap, secs);
}
}
/*==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 <http://www.gnu.org/licenses/>.
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==*/
#include "plNetClientRecorder.h"
#include "hsStream.h"
#include "hsTimer.h"
#include "plNetMessage/plNetMessage.h"
#include "plCreatableIndex.h"
#include "hsResMgr.h"
#include "plgDispatch.h"
#include "plSDL/plSDL.h"
#include "pnNetCommon/plNetApp.h"
#include "plMessage/plLinkToAgeMsg.h"
#include "plMessage/plLoadAvatarMsg.h"
#include "pnMessage/plNotifyMsg.h"
#include "plMessage/plAgeLoadedMsg.h"
#include "plStatusLog/plStatusLog.h"
#include "plFile/hsFiles.h"
plNetClientRecorder::plNetClientRecorder(TimeWrapper* timeWrapper) :
fTimeWrapper(timeWrapper)
{
}
plNetClientRecorder::~plNetClientRecorder()
{
}
double plNetClientRecorder::GetTime()
{
if (fTimeWrapper)
return fTimeWrapper->GetWrappedTime();
else
return hsTimer::GetSysSeconds();
}
void plNetClientRecorder::IMakeFilename(const char* recName, char* path)
{
strcpy(path, "Recordings" PATH_SEPARATOR_STR);
#if HS_BUILD_FOR_WIN32
CreateDirectory(path, NULL);
#endif
const char* lastDot = strrchr(recName, '.');
if (lastDot)
strncat(path, recName, lastDot-recName);
else
strcat(path, recName);
strcat(path, ".rec");
}
bool plNetClientRecorder::IsRecordableMsg(plNetMessage* msg) const
{
UInt16 idx = msg->ClassIndex();
return (
idx == CLASS_INDEX_SCOPED(plNetMsgLoadClone) ||
idx == CLASS_INDEX_SCOPED(plNetMsgSDLStateBCast) ||
idx == CLASS_INDEX_SCOPED(plNetMsgSDLState) ||
idx == CLASS_INDEX_SCOPED(plNetMsgGameMessage)
);
}
plNetClientLoggingRecorder::plNetClientLoggingRecorder(TimeWrapper* timeWrapper) :
plNetClientRecorder(timeWrapper),
fPlaybackTimeOffset(0),
fNextPlaybackTime(0),
fLog(nil),
fBetweenAges(true)
{
}
plNetClientLoggingRecorder::~plNetClientLoggingRecorder()
{
delete fLog;
fLog = nil;
}
bool plNetClientLoggingRecorder::IProcessRecordMsg(plNetMessage* msg, double secs)
{
if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plNetMsgGameMessage))
{
plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg);
UInt16 gameMsgIdx = gameMsg->StreamInfo()->GetStreamType();
if (gameMsgIdx == CLASS_INDEX_SCOPED(plServerReplyMsg))
return false;
// Throw out any notify messages that don't involve picking (running into
// detectors and that sort of thing should be recreated automatically
// during playback)
if (gameMsgIdx == CLASS_INDEX_SCOPED(plNotifyMsg))
{
bool hasPick = false;
plNotifyMsg* notifyMsg = plNotifyMsg::ConvertNoRef(gameMsg->GetContainedMsg());
int numEvents = notifyMsg->GetEventCount();
for (int i = 0; i < numEvents; i++)
{
proEventData* event = notifyMsg->GetEventRecord(i);
if (event->fEventType == proEventData::kPicked)
hasPick = true;
}
hsRefCnt_SafeUnRef(notifyMsg);
if (!hasPick)
return false;
}
}
if (fPlaybackTimeOffset == 0)
fPlaybackTimeOffset = secs;
return true;
}
void plNetClientLoggingRecorder::RecordLinkMsg(plLinkToAgeMsg* linkMsg, double secs)
{
if (!linkMsg->HasBCastFlag(plMessage::kNetSent))
{
plNetMsgGameMessage netMsgWrap;
// write message (and label) to ram stream
hsRAMStream stream;
hsgResMgr::ResMgr()->WriteCreatable(&stream, linkMsg);
// put stream in net msg wrapper
netMsgWrap.StreamInfo()->CopyStream(&stream);
// netMsgWrap.StreamInfo()->SetStreamType(linkMsg->ClassIndex()); // type of game msg
RecordMsg(&netMsgWrap, secs);
}
}

View File

@ -1,178 +1,178 @@
/*==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 <http://www.gnu.org/licenses/>.
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 plNetClientRecorder_h_inc
#define plNetClientRecorder_h_inc
#include "hsTypes.h"
class hsStream;
class plNetMessage;
class plStatusLog;
class plLinkToAgeMsg;
class plAgeLoadedMsg;
class hsResMgr;
class plNetClientRecorder
{
public:
class TimeWrapper
{
public:
virtual double GetWrappedTime() = 0;
};
protected:
TimeWrapper *fTimeWrapper;
// Puts the full path to recName in path
virtual void IMakeFilename(const char* recName, char* path);
public:
plNetClientRecorder(TimeWrapper* timeWrapper);
virtual ~plNetClientRecorder();
virtual bool BeginRecording(const char* recName) = 0;;
virtual bool BeginPlayback(const char* recName) { hsAssert(false,"plNetClientRecording: Playback not supported"); return false; }
// Recording functions
virtual bool IsRecordableMsg(plNetMessage* msg) const;
virtual void RecordMsg(plNetMessage* msg, double secs) = 0;
virtual void RecordLinkMsg(plLinkToAgeMsg* linkMsg, double secs) = 0;
virtual void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg) = 0;
// Playback functions
double GetTime();
virtual bool IsQueueEmpty() { hsAssert(false,"plNetClientRecording: Playback not supported"); return true; }
virtual plNetMessage* GetNextMessage() { hsAssert(false,"plNetClientRecording: Playback not supported"); return nil; }
virtual double GetNextMessageTimeDelta() { hsAssert(false,"plNetClientRecording: Playback not supported"); return 0; }
};
class plNetClientLoggingRecorder : public plNetClientRecorder
{
protected:
double fPlaybackTimeOffset;
double fNextPlaybackTime;
plStatusLog* fLog;
// We don't send messages when between ages
bool fBetweenAges;
virtual void ILogMsg(plNetMessage* msg, const char* preText="") = 0;
bool IProcessRecordMsg(plNetMessage* msg, double secs);
public:
plNetClientLoggingRecorder(TimeWrapper* timeWrapper);
~plNetClientLoggingRecorder();
void RecordLinkMsg(plLinkToAgeMsg* linkMsg, double secs);
virtual void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg) = 0;
};
//
// Record the net client msgs to a file
//
class plNetClientStreamRecorder : public plNetClientLoggingRecorder
{
protected:
hsStream* fRecordStream;
hsResMgr* fResMgr;
plNetMessage* IGetNextMessage();
virtual bool IIsValidMsg(plNetMessage* msg);
void ILogMsg(plNetMessage* msg, const char* preText="");
public:
plNetClientStreamRecorder(TimeWrapper* timeWrapper = nil);
~plNetClientStreamRecorder();
bool BeginRecording(const char* recName);
bool BeginPlayback(const char* recName);
// Recording functions
void RecordMsg(plNetMessage* msg, double secs);
void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg);
// Playback functions
void SetResMgr(hsResMgr* resmgr) { fResMgr = resmgr; }
hsResMgr* GetResMgr();
bool IsQueueEmpty();
plNetMessage* GetNextMessage();
double GetNextMessageTimeDelta();
};
class plNetClientStatsRecorder : public plNetClientLoggingRecorder
{
protected:
void ILogMsg(plNetMessage* msg, const char* preText="");
public:
plNetClientStatsRecorder(TimeWrapper* timeWrapper = nil);
~plNetClientStatsRecorder();
bool BeginRecording(const char* recName);
// Recording functions
void RecordMsg(plNetMessage* msg, double secs);
void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg) { };
};
class plNetClientStreamAndStatsRecorder : public plNetClientRecorder
{
protected:
plNetClientStreamRecorder* fStreamRecorder;
plNetClientStatsRecorder* fStatsRecorder;
public:
plNetClientStreamAndStatsRecorder(plNetClientStreamRecorder* streamrec, plNetClientStatsRecorder* statrec) :
plNetClientRecorder(nil),fStreamRecorder(streamrec), fStatsRecorder(statrec) {}
~plNetClientStreamAndStatsRecorder() { delete fStreamRecorder; delete fStatsRecorder; }
bool BeginRecording(const char* recName) { return fStreamRecorder->BeginRecording(recName) && fStatsRecorder->BeginRecording(recName); }
bool BeginPlayback(const char* recName) { return fStreamRecorder->BeginPlayback(recName); }
// Recording functions
bool IsRecordableMsg(plNetMessage* msg) const { return fStreamRecorder->IsRecordableMsg(msg) || fStatsRecorder->IsRecordableMsg(msg); }
void RecordMsg(plNetMessage* msg, double secs) { fStreamRecorder->RecordMsg(msg,secs); fStatsRecorder->RecordMsg(msg,secs); }
void RecordLinkMsg(plLinkToAgeMsg* linkMsg, double secs) { fStreamRecorder->RecordLinkMsg(linkMsg,secs); fStatsRecorder->RecordLinkMsg(linkMsg,secs); }
void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg) { fStreamRecorder->RecordAgeLoadedMsg(ageLoadedMsg); fStatsRecorder->RecordAgeLoadedMsg(ageLoadedMsg); }
// Playback functions
bool IsQueueEmpty() { return fStreamRecorder->IsQueueEmpty(); }
plNetMessage* GetNextMessage() { return fStreamRecorder->GetNextMessage(); }
double GetNextMessageTimeDelta() { return fStreamRecorder->GetNextMessageTimeDelta(); }
};
class plNetClientStressStreamRecorder : public plNetClientStreamRecorder
{
public:
plNetClientStressStreamRecorder(TimeWrapper* timeWrapper = nil) : plNetClientStreamRecorder(timeWrapper) {}
bool IsRecordableMsg(plNetMessage* msg) const;
};
#endif // plNetClientRecorder_h_inc
/*==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 <http://www.gnu.org/licenses/>.
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 plNetClientRecorder_h_inc
#define plNetClientRecorder_h_inc
#include "hsTypes.h"
class hsStream;
class plNetMessage;
class plStatusLog;
class plLinkToAgeMsg;
class plAgeLoadedMsg;
class hsResMgr;
class plNetClientRecorder
{
public:
class TimeWrapper
{
public:
virtual double GetWrappedTime() = 0;
};
protected:
TimeWrapper *fTimeWrapper;
// Puts the full path to recName in path
virtual void IMakeFilename(const char* recName, char* path);
public:
plNetClientRecorder(TimeWrapper* timeWrapper);
virtual ~plNetClientRecorder();
virtual bool BeginRecording(const char* recName) = 0;;
virtual bool BeginPlayback(const char* recName) { hsAssert(false,"plNetClientRecording: Playback not supported"); return false; }
// Recording functions
virtual bool IsRecordableMsg(plNetMessage* msg) const;
virtual void RecordMsg(plNetMessage* msg, double secs) = 0;
virtual void RecordLinkMsg(plLinkToAgeMsg* linkMsg, double secs) = 0;
virtual void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg) = 0;
// Playback functions
double GetTime();
virtual bool IsQueueEmpty() { hsAssert(false,"plNetClientRecording: Playback not supported"); return true; }
virtual plNetMessage* GetNextMessage() { hsAssert(false,"plNetClientRecording: Playback not supported"); return nil; }
virtual double GetNextMessageTimeDelta() { hsAssert(false,"plNetClientRecording: Playback not supported"); return 0; }
};
class plNetClientLoggingRecorder : public plNetClientRecorder
{
protected:
double fPlaybackTimeOffset;
double fNextPlaybackTime;
plStatusLog* fLog;
// We don't send messages when between ages
bool fBetweenAges;
virtual void ILogMsg(plNetMessage* msg, const char* preText="") = 0;
bool IProcessRecordMsg(plNetMessage* msg, double secs);
public:
plNetClientLoggingRecorder(TimeWrapper* timeWrapper);
~plNetClientLoggingRecorder();
void RecordLinkMsg(plLinkToAgeMsg* linkMsg, double secs);
virtual void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg) = 0;
};
//
// Record the net client msgs to a file
//
class plNetClientStreamRecorder : public plNetClientLoggingRecorder
{
protected:
hsStream* fRecordStream;
hsResMgr* fResMgr;
plNetMessage* IGetNextMessage();
virtual bool IIsValidMsg(plNetMessage* msg);
void ILogMsg(plNetMessage* msg, const char* preText="");
public:
plNetClientStreamRecorder(TimeWrapper* timeWrapper = nil);
~plNetClientStreamRecorder();
bool BeginRecording(const char* recName);
bool BeginPlayback(const char* recName);
// Recording functions
void RecordMsg(plNetMessage* msg, double secs);
void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg);
// Playback functions
void SetResMgr(hsResMgr* resmgr) { fResMgr = resmgr; }
hsResMgr* GetResMgr();
bool IsQueueEmpty();
plNetMessage* GetNextMessage();
double GetNextMessageTimeDelta();
};
class plNetClientStatsRecorder : public plNetClientLoggingRecorder
{
protected:
void ILogMsg(plNetMessage* msg, const char* preText="");
public:
plNetClientStatsRecorder(TimeWrapper* timeWrapper = nil);
~plNetClientStatsRecorder();
bool BeginRecording(const char* recName);
// Recording functions
void RecordMsg(plNetMessage* msg, double secs);
void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg) { };
};
class plNetClientStreamAndStatsRecorder : public plNetClientRecorder
{
protected:
plNetClientStreamRecorder* fStreamRecorder;
plNetClientStatsRecorder* fStatsRecorder;
public:
plNetClientStreamAndStatsRecorder(plNetClientStreamRecorder* streamrec, plNetClientStatsRecorder* statrec) :
plNetClientRecorder(nil),fStreamRecorder(streamrec), fStatsRecorder(statrec) {}
~plNetClientStreamAndStatsRecorder() { delete fStreamRecorder; delete fStatsRecorder; }
bool BeginRecording(const char* recName) { return fStreamRecorder->BeginRecording(recName) && fStatsRecorder->BeginRecording(recName); }
bool BeginPlayback(const char* recName) { return fStreamRecorder->BeginPlayback(recName); }
// Recording functions
bool IsRecordableMsg(plNetMessage* msg) const { return fStreamRecorder->IsRecordableMsg(msg) || fStatsRecorder->IsRecordableMsg(msg); }
void RecordMsg(plNetMessage* msg, double secs) { fStreamRecorder->RecordMsg(msg,secs); fStatsRecorder->RecordMsg(msg,secs); }
void RecordLinkMsg(plLinkToAgeMsg* linkMsg, double secs) { fStreamRecorder->RecordLinkMsg(linkMsg,secs); fStatsRecorder->RecordLinkMsg(linkMsg,secs); }
void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg) { fStreamRecorder->RecordAgeLoadedMsg(ageLoadedMsg); fStatsRecorder->RecordAgeLoadedMsg(ageLoadedMsg); }
// Playback functions
bool IsQueueEmpty() { return fStreamRecorder->IsQueueEmpty(); }
plNetMessage* GetNextMessage() { return fStreamRecorder->GetNextMessage(); }
double GetNextMessageTimeDelta() { return fStreamRecorder->GetNextMessageTimeDelta(); }
};
class plNetClientStressStreamRecorder : public plNetClientStreamRecorder
{
public:
plNetClientStressStreamRecorder(TimeWrapper* timeWrapper = nil) : plNetClientStreamRecorder(timeWrapper) {}
bool IsRecordableMsg(plNetMessage* msg) const;
};
#endif // plNetClientRecorder_h_inc

View File

@ -1,144 +1,144 @@
/*==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 <http://www.gnu.org/licenses/>.
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==*/
#include "plNetClientRecorder.h"
#include "hsStream.h"
#include "plNetMessage/plNetMessage.h"
#include "plCreatableIndex.h"
#include "plgDispatch.h"
#include "plSDL/plSDL.h"
#include "pnNetCommon/plNetApp.h"
#include "plMessage/plLinkToAgeMsg.h"
#include "plMessage/plLoadAvatarMsg.h"
#include "plMessage/plLinkToAgeMsg.h"
#include "pnMessage/plNotifyMsg.h"
#include "plMessage/plAgeLoadedMsg.h"
#include "plStatusLog/plStatusLog.h"
plNetClientStatsRecorder::plNetClientStatsRecorder(TimeWrapper* timeWrapper) :
plNetClientLoggingRecorder(timeWrapper)
{
if (fLog)
delete fLog;
fLog = plStatusLogMgr::GetInstance().CreateStatusLog(30, "StatsRecorder.log", plStatusLog::kAlignToTop);
}
plNetClientStatsRecorder::~plNetClientStatsRecorder()
{
}
bool plNetClientStatsRecorder::BeginRecording(const char* recName)
{
return true;
}
void plNetClientStatsRecorder::RecordMsg(plNetMessage* msg, double secs)
{
if (IProcessRecordMsg(msg,secs))
{
char stats[256];
sprintf(stats,"tm:%4.2f;sz:%u,plrid:%s%u : ",secs,msg->GetPackSize(),msg->GetHasPlayerID()?"":"XX",msg->GetHasPlayerID()?msg->GetPlayerID():0);
// GetPackSize might compress the buffer on us, so uncompress it
plNetMsgStreamedObject* so = plNetMsgStreamedObject::ConvertNoRef(msg);
if (so)
so->StreamInfo()->Uncompress();
ILogMsg(msg,stats);
}
}
void plNetClientStatsRecorder::ILogMsg(plNetMessage* msg, const char* preText)
{
if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plNetMsgGameMessage))
{
plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg);
fLog->AddLineF("%s%s(%s)", preText, msg->ClassName(), plFactory::GetNameOfClass(gameMsg->StreamInfo()->GetStreamType()));
if (gameMsg->StreamInfo()->GetStreamType() == CLASS_INDEX_SCOPED(plNotifyMsg))
{
plNotifyMsg* notifyMsg = plNotifyMsg::ConvertNoRef(gameMsg->GetContainedMsg());
int numEvents = notifyMsg->GetEventCount();
for (int i = 0; i < numEvents; i++)
{
const char* eventName = "";
proEventData* event = notifyMsg->GetEventRecord(i);
switch (event->fEventType)
{
case proEventData::kCollision: eventName = "Collision"; break;
case proEventData::kPicked: eventName = "Picked"; break;
case proEventData::kControlKey: eventName = "ControlKey"; break;
case proEventData::kVariable: eventName = "Variable"; break;
case proEventData::kFacing: eventName = "Facing"; break;
case proEventData::kContained: eventName = "Contained"; break;
case proEventData::kActivate: eventName = "Activate"; break;
case proEventData::kCallback: eventName = "Callback"; break;
case proEventData::kResponderState: eventName = "ResponderState"; break;
case proEventData::kMultiStage: eventName = "MultiStage"; break;
case proEventData::kSpawned: eventName = "Spawned"; break;
case proEventData::kClickDrag: eventName = "ClickDrag"; break;
}
fLog->AddLineF("\t%s", eventName);
}
hsRefCnt_SafeUnRef(notifyMsg);
}
}
else if (plNetMsgSDLState* sdlMsg = plNetMsgSDLState::ConvertNoRef(msg))
{
hsReadOnlyStream stream(sdlMsg->StreamInfo()->GetStreamLen(), sdlMsg->StreamInfo()->GetStreamBuf());
char* descName=nil;
int ver;
if (plStateDataRecord::ReadStreamHeader(&stream, &descName, &ver))
{
fLog->AddLineF("%s%s(%s)", preText, msg->ClassName(), descName);
int i;
plStateDataRecord sdRec(descName, ver);
sdRec.Read(&stream, 0);
plStateDataRecord::SimpleVarsList vars;
sdRec.GetDirtyVars(&vars);
for (i = 0; i < vars.size(); i++)
{
fLog->AddLineF("\t%s", vars[i]->GetVarDescriptor()->GetName());
}
plStateDataRecord::SDVarsList sdVars;
sdRec.GetDirtySDVars(&sdVars);
for (i = 0; i < sdVars.size(); i++)
{
fLog->AddLineF("\t%s", sdVars[i]->GetSDVarDescriptor()->GetName());
}
}
delete [] descName;
}
else
fLog->AddLineF("%s%s", preText, msg->ClassName());
}
/*==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 <http://www.gnu.org/licenses/>.
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==*/
#include "plNetClientRecorder.h"
#include "hsStream.h"
#include "plNetMessage/plNetMessage.h"
#include "plCreatableIndex.h"
#include "plgDispatch.h"
#include "plSDL/plSDL.h"
#include "pnNetCommon/plNetApp.h"
#include "plMessage/plLinkToAgeMsg.h"
#include "plMessage/plLoadAvatarMsg.h"
#include "plMessage/plLinkToAgeMsg.h"
#include "pnMessage/plNotifyMsg.h"
#include "plMessage/plAgeLoadedMsg.h"
#include "plStatusLog/plStatusLog.h"
plNetClientStatsRecorder::plNetClientStatsRecorder(TimeWrapper* timeWrapper) :
plNetClientLoggingRecorder(timeWrapper)
{
if (fLog)
delete fLog;
fLog = plStatusLogMgr::GetInstance().CreateStatusLog(30, "StatsRecorder.log", plStatusLog::kAlignToTop);
}
plNetClientStatsRecorder::~plNetClientStatsRecorder()
{
}
bool plNetClientStatsRecorder::BeginRecording(const char* recName)
{
return true;
}
void plNetClientStatsRecorder::RecordMsg(plNetMessage* msg, double secs)
{
if (IProcessRecordMsg(msg,secs))
{
char stats[256];
sprintf(stats,"tm:%4.2f;sz:%u,plrid:%s%u : ",secs,msg->GetPackSize(),msg->GetHasPlayerID()?"":"XX",msg->GetHasPlayerID()?msg->GetPlayerID():0);
// GetPackSize might compress the buffer on us, so uncompress it
plNetMsgStreamedObject* so = plNetMsgStreamedObject::ConvertNoRef(msg);
if (so)
so->StreamInfo()->Uncompress();
ILogMsg(msg,stats);
}
}
void plNetClientStatsRecorder::ILogMsg(plNetMessage* msg, const char* preText)
{
if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plNetMsgGameMessage))
{
plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg);
fLog->AddLineF("%s%s(%s)", preText, msg->ClassName(), plFactory::GetNameOfClass(gameMsg->StreamInfo()->GetStreamType()));
if (gameMsg->StreamInfo()->GetStreamType() == CLASS_INDEX_SCOPED(plNotifyMsg))
{
plNotifyMsg* notifyMsg = plNotifyMsg::ConvertNoRef(gameMsg->GetContainedMsg());
int numEvents = notifyMsg->GetEventCount();
for (int i = 0; i < numEvents; i++)
{
const char* eventName = "";
proEventData* event = notifyMsg->GetEventRecord(i);
switch (event->fEventType)
{
case proEventData::kCollision: eventName = "Collision"; break;
case proEventData::kPicked: eventName = "Picked"; break;
case proEventData::kControlKey: eventName = "ControlKey"; break;
case proEventData::kVariable: eventName = "Variable"; break;
case proEventData::kFacing: eventName = "Facing"; break;
case proEventData::kContained: eventName = "Contained"; break;
case proEventData::kActivate: eventName = "Activate"; break;
case proEventData::kCallback: eventName = "Callback"; break;
case proEventData::kResponderState: eventName = "ResponderState"; break;
case proEventData::kMultiStage: eventName = "MultiStage"; break;
case proEventData::kSpawned: eventName = "Spawned"; break;
case proEventData::kClickDrag: eventName = "ClickDrag"; break;
}
fLog->AddLineF("\t%s", eventName);
}
hsRefCnt_SafeUnRef(notifyMsg);
}
}
else if (plNetMsgSDLState* sdlMsg = plNetMsgSDLState::ConvertNoRef(msg))
{
hsReadOnlyStream stream(sdlMsg->StreamInfo()->GetStreamLen(), sdlMsg->StreamInfo()->GetStreamBuf());
char* descName=nil;
int ver;
if (plStateDataRecord::ReadStreamHeader(&stream, &descName, &ver))
{
fLog->AddLineF("%s%s(%s)", preText, msg->ClassName(), descName);
int i;
plStateDataRecord sdRec(descName, ver);
sdRec.Read(&stream, 0);
plStateDataRecord::SimpleVarsList vars;
sdRec.GetDirtyVars(&vars);
for (i = 0; i < vars.size(); i++)
{
fLog->AddLineF("\t%s", vars[i]->GetVarDescriptor()->GetName());
}
plStateDataRecord::SDVarsList sdVars;
sdRec.GetDirtySDVars(&sdVars);
for (i = 0; i < sdVars.size(); i++)
{
fLog->AddLineF("\t%s", sdVars[i]->GetSDVarDescriptor()->GetName());
}
}
delete [] descName;
}
else
fLog->AddLineF("%s%s", preText, msg->ClassName());
}

View File

@ -1,362 +1,362 @@
/*==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 <http://www.gnu.org/licenses/>.
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==*/
#include "plNetClientRecorder.h"
#include "hsStream.h"
#include "plNetMessage/plNetMessage.h"
#include "plCreatableIndex.h"
#include "hsResMgr.h"
#include "plgDispatch.h"
#include "plSDL/plSDL.h"
#include "pnNetCommon/plNetApp.h"
#include "plMessage/plLinkToAgeMsg.h"
#include "plMessage/plLoadAvatarMsg.h"
#include "plMessage/plLinkToAgeMsg.h"
#include "pnMessage/plNotifyMsg.h"
#include "plMessage/plAgeLoadedMsg.h"
#include "plStatusLog/plStatusLog.h"
plNetClientStreamRecorder::plNetClientStreamRecorder(TimeWrapper* timeWrapper) :
plNetClientLoggingRecorder(timeWrapper),
fRecordStream(nil),
fResMgr(nil)
{
if (fLog)
delete fLog;
fLog = plStatusLogMgr::GetInstance().CreateStatusLog(30, "StreamRecorder.log", plStatusLog::kAlignToTop);
}
plNetClientStreamRecorder::~plNetClientStreamRecorder()
{
if (fRecordStream)
{
fRecordStream->Close();
delete fRecordStream;
}
}
hsResMgr* plNetClientStreamRecorder::GetResMgr()
{
if (fResMgr)
return fResMgr;
else
return hsgResMgr::ResMgr();
}
double plNetClientStreamRecorder::GetNextMessageTimeDelta()
{
return fNextPlaybackTime - (GetTime() - fPlaybackTimeOffset);
}
enum NetClientRecFlags
{
kNetClientRecSDLDesc,
};
bool plNetClientStreamRecorder::BeginRecording(const char* recName)
{
if (!fRecordStream)
{
fRecordStream = TRACKED_NEW hsUNIXStream;
char path[256];
IMakeFilename(recName, path);
if (!fRecordStream->Open(path, "wb"))
{
delete fRecordStream;
return false;
}
hsBitVector contentFlags;
contentFlags.SetBit(kNetClientRecSDLDesc);
contentFlags.Write(fRecordStream);
// kNetClientRecSDLDesc
plSDLMgr::GetInstance()->Write(fRecordStream);
return true;
}
return false;
}
bool plNetClientStreamRecorder::BeginPlayback(const char* recName)
{
if (!fRecordStream)
{
fRecordStream = TRACKED_NEW hsUNIXStream;
char path[256];
IMakeFilename(recName, path);
if (fRecordStream->Open(path, "rb"))
{
hsBitVector contentFlags;
contentFlags.Read(fRecordStream);
if (contentFlags.IsBitSet(kNetClientRecSDLDesc))
plSDLMgr::GetInstance()->Read(fRecordStream);
fPlaybackTimeOffset = GetTime();
fNextPlaybackTime = fRecordStream->ReadSwapDouble();
fBetweenAges = false;
}
else
{
delete fRecordStream;
fRecordStream = nil;
return false;
}
return true;
}
return false;
}
void plNetClientStreamRecorder::RecordMsg(plNetMessage* msg, double secs)
{
if (!fRecordStream)
return;
if (IProcessRecordMsg(msg,secs))
{
fRecordStream->WriteSwapDouble(secs - fPlaybackTimeOffset);
GetResMgr()->WriteCreatableVersion(fRecordStream, msg);
ILogMsg(msg);
}
}
void plNetClientStreamRecorder::RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg)
{
fLog->AddLineF("Age %s", ageLoadedMsg->fLoaded ? "Loaded" : "Unloaded");
if (ageLoadedMsg->fLoaded)
{
fBetweenAges = false;
fPlaybackTimeOffset = GetTime();
}
else
{
fBetweenAges = true;
}
}
bool plNetClientStreamRecorder::IsQueueEmpty()
{
return (fRecordStream == nil);
}
plNetMessage* plNetClientStreamRecorder::GetNextMessage()
{
plNetMessage* msg = nil;
while (!fBetweenAges && (msg = IGetNextMessage()))
{
if (IIsValidMsg(msg))
return msg;
else
hsRefCnt_SafeUnRef(msg);
}
return nil;
}
plNetMessage* plNetClientStreamRecorder::IGetNextMessage()
{
plNetMessage* msg = nil;
if (!IsQueueEmpty() && GetNextMessageTimeDelta() <= 0 )
{
msg = plNetMessage::ConvertNoRef(GetResMgr()->ReadCreatableVersion(fRecordStream));
// msg->SetPeeked(true);
// Fix the flags on game messages, so we won't get an assert later
plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg);
if (gameMsg)
{
plMessage* plMsg = gameMsg->GetContainedMsg(GetResMgr());
plNetClientApp::GetInstance()->UnInheritNetMsgFlags(plMsg);
// write message (and label) to ram stream
hsRAMStream stream;
GetResMgr()->WriteCreatable(&stream, plMsg);
// put stream in net msg wrapper
gameMsg->StreamInfo()->CopyStream(&stream);
// gameMsg->StreamInfo()->SetStreamType(plMsg->ClassIndex()); // type of game msg
}
double nextPlaybackTime = fRecordStream->ReadSwapDouble();
if (nextPlaybackTime < fNextPlaybackTime)
fBetweenAges = true;
fNextPlaybackTime = nextPlaybackTime;
// If this was the last message, stop playing back
if (fRecordStream->AtEnd())
{
fRecordStream->Close();
delete fRecordStream;
fRecordStream = nil;
}
}
return msg;
}
bool plNetClientStreamRecorder::IIsValidMsg(plNetMessage* msg)
{
if (plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg))
{
Int16 type = gameMsg->StreamInfo()->GetStreamType();
//
// These messages will be regenerated if they are for the local avatar,
// so don't dispatch them in that case.
//
if (type == CLASS_INDEX_SCOPED(plLinkEffectsTriggerMsg))
{
plLinkEffectsTriggerMsg* linkMsg = plLinkEffectsTriggerMsg::ConvertNoRef(gameMsg->GetContainedMsg(GetResMgr()));
if (plNetClientApp::GetInstance())
{
bool isLocal = (linkMsg->GetLinkKey() == plNetClientApp::GetInstance()->GetLocalPlayerKey());
hsRefCnt_SafeUnRef(linkMsg);
if (isLocal)
{
ILogMsg(msg, "IGNORING ");
return false;
}
}
}
else if (type == CLASS_INDEX_SCOPED(plLoadAvatarMsg))
{
plLoadAvatarMsg* loadAvMsg = plLoadAvatarMsg::ConvertNoRef(gameMsg->GetContainedMsg(GetResMgr()));
if (plNetClientApp::GetInstance())
{
bool isLocal = (loadAvMsg->GetCloneKey() == plNetClientApp::GetInstance()->GetLocalPlayerKey());
hsRefCnt_SafeUnRef(loadAvMsg);
if (isLocal)
{
ILogMsg(msg, "IGNORING ");
return false;
}
}
}
}
ILogMsg(msg);
return true;
}
void plNetClientStreamRecorder::ILogMsg(plNetMessage* msg, const char* preText)
{
if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plNetMsgGameMessage))
{
plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg);
fLog->AddLineF("%s%s(%s)", preText, msg->ClassName(), plFactory::GetNameOfClass(gameMsg->StreamInfo()->GetStreamType()));
if (gameMsg->StreamInfo()->GetStreamType() == CLASS_INDEX_SCOPED(plNotifyMsg))
{
plNotifyMsg* notifyMsg = plNotifyMsg::ConvertNoRef(gameMsg->GetContainedMsg(GetResMgr()));
int numEvents = notifyMsg->GetEventCount();
for (int i = 0; i < numEvents; i++)
{
const char* eventName = "";
proEventData* event = notifyMsg->GetEventRecord(i);
switch (event->fEventType)
{
case proEventData::kCollision: eventName = "Collision"; break;
case proEventData::kPicked: eventName = "Picked"; break;
case proEventData::kControlKey: eventName = "ControlKey"; break;
case proEventData::kVariable: eventName = "Variable"; break;
case proEventData::kFacing: eventName = "Facing"; break;
case proEventData::kContained: eventName = "Contained"; break;
case proEventData::kActivate: eventName = "Activate"; break;
case proEventData::kCallback: eventName = "Callback"; break;
case proEventData::kResponderState: eventName = "ResponderState"; break;
case proEventData::kMultiStage: eventName = "MultiStage"; break;
case proEventData::kSpawned: eventName = "Spawned"; break;
case proEventData::kClickDrag: eventName = "ClickDrag"; break;
}
fLog->AddLineF("\t%s", eventName);
}
hsRefCnt_SafeUnRef(notifyMsg);
}
}
else if (plNetMsgSDLState* sdlMsg = plNetMsgSDLState::ConvertNoRef(msg))
{
hsReadOnlyStream stream(sdlMsg->StreamInfo()->GetStreamLen(), sdlMsg->StreamInfo()->GetStreamBuf());
char* descName=nil;
int ver;
if (plStateDataRecord::ReadStreamHeader(&stream, &descName, &ver))
{
fLog->AddLineF("%s%s(%s)", preText, msg->ClassName(), descName);
int i;
plStateDataRecord sdRec(descName, ver);
sdRec.Read(&stream, 0);
plStateDataRecord::SimpleVarsList vars;
sdRec.GetDirtyVars(&vars);
for (i = 0; i < vars.size(); i++)
{
fLog->AddLineF("\t%s", vars[i]->GetVarDescriptor()->GetName());
}
plStateDataRecord::SDVarsList sdVars;
sdRec.GetDirtySDVars(&sdVars);
for (i = 0; i < sdVars.size(); i++)
{
fLog->AddLineF("\t%s", sdVars[i]->GetSDVarDescriptor()->GetName());
}
}
delete [] descName;
}
else
fLog->AddLineF("%s%s", preText, msg->ClassName());
}
bool plNetClientStressStreamRecorder::IsRecordableMsg(plNetMessage* msg) const
{
UInt16 idx = msg->ClassIndex();
return (
plNetClientStreamRecorder::IsRecordableMsg(msg)
|| idx == CLASS_INDEX_SCOPED(plNetMsgTestAndSet)
|| idx == CLASS_INDEX_SCOPED(plNetMsgGameMessageDirected)
|| idx == CLASS_INDEX_SCOPED(plNetMsgVoice)
);
/*==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 <http://www.gnu.org/licenses/>.
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==*/
#include "plNetClientRecorder.h"
#include "hsStream.h"
#include "plNetMessage/plNetMessage.h"
#include "plCreatableIndex.h"
#include "hsResMgr.h"
#include "plgDispatch.h"
#include "plSDL/plSDL.h"
#include "pnNetCommon/plNetApp.h"
#include "plMessage/plLinkToAgeMsg.h"
#include "plMessage/plLoadAvatarMsg.h"
#include "plMessage/plLinkToAgeMsg.h"
#include "pnMessage/plNotifyMsg.h"
#include "plMessage/plAgeLoadedMsg.h"
#include "plStatusLog/plStatusLog.h"
plNetClientStreamRecorder::plNetClientStreamRecorder(TimeWrapper* timeWrapper) :
plNetClientLoggingRecorder(timeWrapper),
fRecordStream(nil),
fResMgr(nil)
{
if (fLog)
delete fLog;
fLog = plStatusLogMgr::GetInstance().CreateStatusLog(30, "StreamRecorder.log", plStatusLog::kAlignToTop);
}
plNetClientStreamRecorder::~plNetClientStreamRecorder()
{
if (fRecordStream)
{
fRecordStream->Close();
delete fRecordStream;
}
}
hsResMgr* plNetClientStreamRecorder::GetResMgr()
{
if (fResMgr)
return fResMgr;
else
return hsgResMgr::ResMgr();
}
double plNetClientStreamRecorder::GetNextMessageTimeDelta()
{
return fNextPlaybackTime - (GetTime() - fPlaybackTimeOffset);
}
enum NetClientRecFlags
{
kNetClientRecSDLDesc,
};
bool plNetClientStreamRecorder::BeginRecording(const char* recName)
{
if (!fRecordStream)
{
fRecordStream = TRACKED_NEW hsUNIXStream;
char path[256];
IMakeFilename(recName, path);
if (!fRecordStream->Open(path, "wb"))
{
delete fRecordStream;
return false;
}
hsBitVector contentFlags;
contentFlags.SetBit(kNetClientRecSDLDesc);
contentFlags.Write(fRecordStream);
// kNetClientRecSDLDesc
plSDLMgr::GetInstance()->Write(fRecordStream);
return true;
}
return false;
}
bool plNetClientStreamRecorder::BeginPlayback(const char* recName)
{
if (!fRecordStream)
{
fRecordStream = TRACKED_NEW hsUNIXStream;
char path[256];
IMakeFilename(recName, path);
if (fRecordStream->Open(path, "rb"))
{
hsBitVector contentFlags;
contentFlags.Read(fRecordStream);
if (contentFlags.IsBitSet(kNetClientRecSDLDesc))
plSDLMgr::GetInstance()->Read(fRecordStream);
fPlaybackTimeOffset = GetTime();
fNextPlaybackTime = fRecordStream->ReadSwapDouble();
fBetweenAges = false;
}
else
{
delete fRecordStream;
fRecordStream = nil;
return false;
}
return true;
}
return false;
}
void plNetClientStreamRecorder::RecordMsg(plNetMessage* msg, double secs)
{
if (!fRecordStream)
return;
if (IProcessRecordMsg(msg,secs))
{
fRecordStream->WriteSwapDouble(secs - fPlaybackTimeOffset);
GetResMgr()->WriteCreatableVersion(fRecordStream, msg);
ILogMsg(msg);
}
}
void plNetClientStreamRecorder::RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg)
{
fLog->AddLineF("Age %s", ageLoadedMsg->fLoaded ? "Loaded" : "Unloaded");
if (ageLoadedMsg->fLoaded)
{
fBetweenAges = false;
fPlaybackTimeOffset = GetTime();
}
else
{
fBetweenAges = true;
}
}
bool plNetClientStreamRecorder::IsQueueEmpty()
{
return (fRecordStream == nil);
}
plNetMessage* plNetClientStreamRecorder::GetNextMessage()
{
plNetMessage* msg = nil;
while (!fBetweenAges && (msg = IGetNextMessage()))
{
if (IIsValidMsg(msg))
return msg;
else
hsRefCnt_SafeUnRef(msg);
}
return nil;
}
plNetMessage* plNetClientStreamRecorder::IGetNextMessage()
{
plNetMessage* msg = nil;
if (!IsQueueEmpty() && GetNextMessageTimeDelta() <= 0 )
{
msg = plNetMessage::ConvertNoRef(GetResMgr()->ReadCreatableVersion(fRecordStream));
// msg->SetPeeked(true);
// Fix the flags on game messages, so we won't get an assert later
plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg);
if (gameMsg)
{
plMessage* plMsg = gameMsg->GetContainedMsg(GetResMgr());
plNetClientApp::GetInstance()->UnInheritNetMsgFlags(plMsg);
// write message (and label) to ram stream
hsRAMStream stream;
GetResMgr()->WriteCreatable(&stream, plMsg);
// put stream in net msg wrapper
gameMsg->StreamInfo()->CopyStream(&stream);
// gameMsg->StreamInfo()->SetStreamType(plMsg->ClassIndex()); // type of game msg
}
double nextPlaybackTime = fRecordStream->ReadSwapDouble();
if (nextPlaybackTime < fNextPlaybackTime)
fBetweenAges = true;
fNextPlaybackTime = nextPlaybackTime;
// If this was the last message, stop playing back
if (fRecordStream->AtEnd())
{
fRecordStream->Close();
delete fRecordStream;
fRecordStream = nil;
}
}
return msg;
}
bool plNetClientStreamRecorder::IIsValidMsg(plNetMessage* msg)
{
if (plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg))
{
Int16 type = gameMsg->StreamInfo()->GetStreamType();
//
// These messages will be regenerated if they are for the local avatar,
// so don't dispatch them in that case.
//
if (type == CLASS_INDEX_SCOPED(plLinkEffectsTriggerMsg))
{
plLinkEffectsTriggerMsg* linkMsg = plLinkEffectsTriggerMsg::ConvertNoRef(gameMsg->GetContainedMsg(GetResMgr()));
if (plNetClientApp::GetInstance())
{
bool isLocal = (linkMsg->GetLinkKey() == plNetClientApp::GetInstance()->GetLocalPlayerKey());
hsRefCnt_SafeUnRef(linkMsg);
if (isLocal)
{
ILogMsg(msg, "IGNORING ");
return false;
}
}
}
else if (type == CLASS_INDEX_SCOPED(plLoadAvatarMsg))
{
plLoadAvatarMsg* loadAvMsg = plLoadAvatarMsg::ConvertNoRef(gameMsg->GetContainedMsg(GetResMgr()));
if (plNetClientApp::GetInstance())
{
bool isLocal = (loadAvMsg->GetCloneKey() == plNetClientApp::GetInstance()->GetLocalPlayerKey());
hsRefCnt_SafeUnRef(loadAvMsg);
if (isLocal)
{
ILogMsg(msg, "IGNORING ");
return false;
}
}
}
}
ILogMsg(msg);
return true;
}
void plNetClientStreamRecorder::ILogMsg(plNetMessage* msg, const char* preText)
{
if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plNetMsgGameMessage))
{
plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg);
fLog->AddLineF("%s%s(%s)", preText, msg->ClassName(), plFactory::GetNameOfClass(gameMsg->StreamInfo()->GetStreamType()));
if (gameMsg->StreamInfo()->GetStreamType() == CLASS_INDEX_SCOPED(plNotifyMsg))
{
plNotifyMsg* notifyMsg = plNotifyMsg::ConvertNoRef(gameMsg->GetContainedMsg(GetResMgr()));
int numEvents = notifyMsg->GetEventCount();
for (int i = 0; i < numEvents; i++)
{
const char* eventName = "";
proEventData* event = notifyMsg->GetEventRecord(i);
switch (event->fEventType)
{
case proEventData::kCollision: eventName = "Collision"; break;
case proEventData::kPicked: eventName = "Picked"; break;
case proEventData::kControlKey: eventName = "ControlKey"; break;
case proEventData::kVariable: eventName = "Variable"; break;
case proEventData::kFacing: eventName = "Facing"; break;
case proEventData::kContained: eventName = "Contained"; break;
case proEventData::kActivate: eventName = "Activate"; break;
case proEventData::kCallback: eventName = "Callback"; break;
case proEventData::kResponderState: eventName = "ResponderState"; break;
case proEventData::kMultiStage: eventName = "MultiStage"; break;
case proEventData::kSpawned: eventName = "Spawned"; break;
case proEventData::kClickDrag: eventName = "ClickDrag"; break;
}
fLog->AddLineF("\t%s", eventName);
}
hsRefCnt_SafeUnRef(notifyMsg);
}
}
else if (plNetMsgSDLState* sdlMsg = plNetMsgSDLState::ConvertNoRef(msg))
{
hsReadOnlyStream stream(sdlMsg->StreamInfo()->GetStreamLen(), sdlMsg->StreamInfo()->GetStreamBuf());
char* descName=nil;
int ver;
if (plStateDataRecord::ReadStreamHeader(&stream, &descName, &ver))
{
fLog->AddLineF("%s%s(%s)", preText, msg->ClassName(), descName);
int i;
plStateDataRecord sdRec(descName, ver);
sdRec.Read(&stream, 0);
plStateDataRecord::SimpleVarsList vars;
sdRec.GetDirtyVars(&vars);
for (i = 0; i < vars.size(); i++)
{
fLog->AddLineF("\t%s", vars[i]->GetVarDescriptor()->GetName());
}
plStateDataRecord::SDVarsList sdVars;
sdRec.GetDirtySDVars(&sdVars);
for (i = 0; i < sdVars.size(); i++)
{
fLog->AddLineF("\t%s", sdVars[i]->GetSDVarDescriptor()->GetName());
}
}
delete [] descName;
}
else
fLog->AddLineF("%s%s", preText, msg->ClassName());
}
bool plNetClientStressStreamRecorder::IsRecordableMsg(plNetMessage* msg) const
{
UInt16 idx = msg->ClassIndex();
return (
plNetClientStreamRecorder::IsRecordableMsg(msg)
|| idx == CLASS_INDEX_SCOPED(plNetMsgTestAndSet)
|| idx == CLASS_INDEX_SCOPED(plNetMsgGameMessageDirected)
|| idx == CLASS_INDEX_SCOPED(plNetMsgVoice)
);
}