Browse Source

Convert vault tree printing to plString

After hacking the old to just barely use plString, I received some UTF-8
asserts. So, that seemed like a good excuse to convert the whole mess to
plString. Note that the output is now saved in VaultClient.log. This
should help with getting some of the chaos out of OLD_ASYNC_LOG.log
Adam Johnson 10 years ago
parent
commit
3b983bca8e
  1. 4
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp
  2. 2
      Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp
  3. 14
      Sources/Plasma/NucleusLib/pnUtils/pnUtMisc.h
  4. 2
      Sources/Plasma/PubUtilLib/plNetClient/plNetCliAgeJoiner.cpp
  5. 4
      Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp
  6. 1
      Sources/Plasma/PubUtilLib/plVault/Pch.h
  7. 231
      Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp
  8. 11
      Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h

4
Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp

@ -6913,8 +6913,8 @@ PF_CONSOLE_GROUP(Vault)
PF_CONSOLE_CMD(Vault, Dump, "", "Prints the vault structure of current player and age to the nearest log file")
{
VaultDump(L"Player", NetCommGetPlayer()->playerInt);
VaultDump(L"Age", NetCommGetAge()->ageVaultId);
VaultDump("Player", NetCommGetPlayer()->playerInt);
VaultDump("Age", NetCommGetAge()->ageVaultId);
}
#endif

2
Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp

@ -2932,7 +2932,7 @@ void cyMisc::ForceVaultNodeUpdate(unsigned nodeId)
void cyMisc::VaultDownload(unsigned nodeId)
{
VaultDownloadAndWait(
L"PyVaultDownload",
"PyVaultDownload",
nodeId,
nil,
nil

14
Sources/Plasma/NucleusLib/pnUtils/pnUtMisc.h

@ -69,18 +69,4 @@ void * ModuleGetInstance ();
const wchar_t * AppGetCommandLine ();
/*****************************************************************************
*
* Misc types
*
***/
// used to dump the internal state of a module
typedef void (CDECL * FStateDump)(
void * param,
const wchar_t fmt[],
...
);
#endif

2
Sources/Plasma/PubUtilLib/plNetClient/plNetCliAgeJoiner.cpp

@ -408,7 +408,7 @@ bool plNCAgeJoiner::MsgReceive (plMessage * msg) {
else if (unsigned ageVaultId = NetCommGetAge()->ageVaultId) {
// Download the age vault
VaultDownload(
L"AgeJoin",
"AgeJoin",
ageVaultId,
AgeVaultDownloadCallback,
this,

4
Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp

@ -311,7 +311,7 @@ static void INetCliAuthSetPlayerRequestCallback (
s_needAvatarLoad = true;
VaultDownload(
L"SetActivePlayer",
"SetActivePlayer",
s_player->playerInt,
PlayerInitCallback,
param,
@ -367,7 +367,7 @@ static void INetCliAuthLoginSetPlayerRequestCallback (
}
else {
VaultDownload(
L"SetActivePlayer",
"SetActivePlayer",
s_player->playerInt,
LoginPlayerInitCallback,
param,

1
Sources/Plasma/PubUtilLib/plVault/Pch.h

@ -80,6 +80,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plGImage/plJPEG.h"
#include "plMessage/plVaultNotifyMsg.h"
#include "plNetClientComm/plNetClientComm.h"
#include "plStatusLog/plStatusLog.h"
#define KI_CONSTANTS_ONLY
#include "pfMessage/pfKIMsg.h" // for KI level constants =(

231
Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp

@ -173,7 +173,7 @@ struct VaultDownloadTrans {
FVaultProgressCallback progressCallback;
void * cbProgressParam;
wchar_t tag[MAX_PATH];
plString tag;
unsigned nodeCount;
unsigned nodesLeft;
unsigned vaultId;
@ -183,18 +183,15 @@ struct VaultDownloadTrans {
: callback(nil), cbParam(nil), progressCallback(nil), cbProgressParam(nil),
nodeCount(0), nodesLeft(0), vaultId(0), result(kNetSuccess)
{
memset(tag, 0, sizeof(tag));
}
VaultDownloadTrans (const wchar_t * _tag, FVaultDownloadCallback _callback,
VaultDownloadTrans (const plString& _tag, FVaultDownloadCallback _callback,
void * _cbParam, FVaultProgressCallback _progressCallback,
void * _cbProgressParam, unsigned _vaultId)
: callback(_callback), cbParam(_cbParam), progressCallback(_progressCallback),
cbProgressParam(_cbProgressParam), nodeCount(0), nodesLeft(0),
vaultId(_vaultId), result(kNetSuccess)
vaultId(_vaultId), result(kNetSuccess), tag(_tag)
{
wcsncpy(tag, _tag, arrsize(tag));
tag[arrsize(tag)-1] = 0;
}
@ -545,7 +542,7 @@ static void VaultNodeFetched (
link->node->CopyFrom(node);
InitFetchedNode(link->node);
link->node->Print(L"Fetched", LogDumpProc, 0);
link->node->Print("Fetched", 0);
}
//============================================================================
@ -636,7 +633,7 @@ static void VaultNodeAdded (
continue;
prevId = link->node->GetNodeId();
VaultDownload(
L"NodeAdded",
"NodeAdded",
nodeIds[i],
VaultNodeAddedDownloadCallback,
(void*)nodeIds[i],
@ -714,7 +711,7 @@ static void SaveDirtyNodes () {
if (link->node->IsDirty()) {
if (unsigned bytes = NetCliAuthVaultNodeSave(link->node, nil, nil)) {
bytesWritten += bytes;
link->node->Print(L"Saving", LogDumpProc, 0);
link->node->Print("Saving", 0);
}
}
}
@ -862,7 +859,7 @@ void VaultDownloadTrans::VaultNodeFetched (
}
if (!trans->nodesLeft) {
VaultDump(trans->tag, trans->vaultId, LogDumpProc);
VaultDump(trans->tag, trans->vaultId);
if (trans->callback)
trans->callback(
@ -1369,93 +1366,12 @@ void RelVaultNode::SetSeen (unsigned parentId, bool seen) {
}
//============================================================================
template <typename T>
static bool IStrSqlEscape (const T src[], T * dst, unsigned dstChars) {
// count the number of ' chars
unsigned ticks = 0;
{
const T * cur = src;
while (*cur) {
if (*cur == L'\'')
++ticks;
cur++;
}
}
unsigned reqChars = StrLen(src) + ticks + 1;
if (dstChars < reqChars)
// failure!
return false;
T * cur = dst;
// copy src to dst, escaping ' chars
while (*src) {
if (*src == L'\'') {
*cur++ = L'\'';
*cur++ = *src++;
continue;
}
*cur++ = *src++;
}
// null-terminate dst string
*cur = 0;
// success!
return true;
}
static void IGetStringFieldValue (
const plString & value,
wchar_t * dst,
size_t dstChars
) {
wchar_t * tmp = (wchar_t*)malloc(sizeof(wchar_t) * dstChars);
IStrSqlEscape(value.ToWchar().GetData(), tmp, dstChars);
swprintf(dst, dstChars, L"'%s'", tmp);
free(tmp);
}
static void IGetUuidFieldValue (
const plUUID & value,
wchar_t * dst,
size_t dstChars
) {
swprintf(dst, dstChars, L"hextoraw('%S')", value.AsString().c_str());
}
static void IGetUintFieldValue (
uint32_t value,
wchar_t * dst,
size_t dstChars
) {
swprintf(dst, dstChars, L"%u", value);
}
static void IGetIntFieldValue (
int32_t value,
wchar_t * dst,
size_t dstChars
) {
swprintf(dst, dstChars, L"%d", value);
}
void RelVaultNode::Print (const wchar_t tag[], FStateDump dumpProc, unsigned level) {
wchar_t str[1024];
StrPrintf(
str,
arrsize(str),
L"%s%*s%*s%u, %S",
tag ? tag : L"",
tag ? 1 : 0,
" ",
level * 2,
" ",
GetNodeId(),
plVault::NodeTypeStr(GetNodeType(), false)
);
void RelVaultNode::Print (const plString& tag, unsigned level) {
plStringStream ss;
ss << tag;
ss << plFormat(plFormat("{{{}}", level * 2).c_str(), " "); // creates the indentation
ss << " " << GetNodeId();
ss << " " << plVault::NodeTypeStr(GetNodeType());
for (uint64_t bit = 1; bit; bit <<= 1) {
if (!(GetFieldFlags() & bit))
@ -1463,60 +1379,66 @@ void RelVaultNode::Print (const wchar_t tag[], FStateDump dumpProc, unsigned lev
if (bit > GetFieldFlags())
break;
#define STPRINT(flag, func) case k##flag: { \
wcsncat(str, L", " L ## #flag L"=", arrsize(str)); \
const size_t chars = wcslen(str); \
func(Get##flag(), str + chars, arrsize(str) - chars * sizeof(str[0])); \
}; break
#define STNAME(flag) case k##flag: { \
wcsncat(str, L", " L ## #flag, arrsize(str)); \
}; break
#define STPRINT(flag) \
case k##flag: \
ss << ", " #flag "=\"" << Get##flag() << "\""; \
break;
#define STPRINT_ESCAPE(flag) \
case k##flag: \
ss << ", " #flag "=\"" << Get##flag().Replace("\"", "\\\"") << "\""; \
break;
#define STNAME(flag) \
case k##flag: \
ss << ", " << #flag; \
break;
switch (bit) {
STPRINT(NodeId, IGetUintFieldValue);
STPRINT(CreateTime, IGetUintFieldValue);
STPRINT(ModifyTime, IGetUintFieldValue);
STPRINT(CreateAgeName, IGetStringFieldValue);
STPRINT(CreateAgeUuid, IGetUuidFieldValue);
STPRINT(CreatorAcct, IGetUuidFieldValue);
STPRINT(CreatorId, IGetUintFieldValue);
STPRINT(NodeType, IGetUintFieldValue);
STPRINT(Int32_1, IGetIntFieldValue);
STPRINT(Int32_2, IGetIntFieldValue);
STPRINT(Int32_3, IGetIntFieldValue);
STPRINT(Int32_4, IGetIntFieldValue);
STPRINT(UInt32_1, IGetUintFieldValue);
STPRINT(UInt32_2, IGetUintFieldValue);
STPRINT(UInt32_3, IGetUintFieldValue);
STPRINT(UInt32_4, IGetUintFieldValue);
STPRINT(Uuid_1, IGetUuidFieldValue);
STPRINT(Uuid_2, IGetUuidFieldValue);
STPRINT(Uuid_3, IGetUuidFieldValue);
STPRINT(Uuid_4, IGetUuidFieldValue);
STPRINT(String64_1, IGetStringFieldValue);
STPRINT(String64_2, IGetStringFieldValue);
STPRINT(String64_3, IGetStringFieldValue);
STPRINT(String64_4, IGetStringFieldValue);
STPRINT(String64_5, IGetStringFieldValue);
STPRINT(String64_6, IGetStringFieldValue);
STPRINT(IString64_1, IGetStringFieldValue);
STPRINT(IString64_2, IGetStringFieldValue);
STPRINT(NodeId);
STPRINT(CreateTime);
STPRINT(ModifyTime);
STPRINT(CreateAgeName);
STPRINT(CreateAgeUuid);
STPRINT(CreatorAcct);
STPRINT(CreatorId);
STPRINT(NodeType);
STPRINT(Int32_1);
STPRINT(Int32_2);
STPRINT(Int32_3);
STPRINT(Int32_4);
STPRINT(UInt32_1);
STPRINT(UInt32_2);
STPRINT(UInt32_3);
STPRINT(UInt32_4);
STPRINT(Uuid_1);
STPRINT(Uuid_2);
STPRINT(Uuid_3);
STPRINT(Uuid_4);
STPRINT_ESCAPE(String64_1);
STPRINT_ESCAPE(String64_2);
STPRINT_ESCAPE(String64_3);
STPRINT_ESCAPE(String64_4);
STPRINT_ESCAPE(String64_5);
STPRINT_ESCAPE(String64_6);
STPRINT_ESCAPE(IString64_1);
STPRINT_ESCAPE(IString64_2);
STNAME(Text_1);
STNAME(Text_2);
STNAME(Blob_1);
STNAME(Blob_2);
DEFAULT_FATAL(bit);
}
#undef STPRINT
#undef STPRINT
#undef STNAME
}
dumpProc(nil, str);
plStatusLog::AddLineS("VaultClient.log", ss.GetString().c_str());
}
//============================================================================
void RelVaultNode::PrintTree (FStateDump dumpProc, unsigned level) {
Print(L"", dumpProc, level);
void RelVaultNode::PrintTree (unsigned level) {
Print("", level);
for (RelVaultNodeLink * link = state->children.Head(); link; link = state->children.Next(link))
link->node->PrintTree(dumpProc, level + 1);
link->node->PrintTree(level + 1);
}
//============================================================================
@ -2649,7 +2571,7 @@ bool VaultRegisterOwnedAgeAndWait (const plAgeLinkStruct * link) {
memset(&param, 0, sizeof(param));
VaultDownload(
L"RegisterOwnedAge",
"RegisterOwnedAge",
ageInfoId,
_FetchVaultCallback,
&param,
@ -2831,7 +2753,7 @@ namespace _VaultRegisterOwnedAge {
p->fSpawn = (plSpawnPointInfo*)param;
VaultDownload(
L"RegisterOwnedAge",
"RegisterOwnedAge",
ageInfoVaultId,
(FVaultDownloadCallback)_DownloadCallback,
p,
@ -3009,7 +2931,7 @@ bool VaultRegisterVisitAgeAndWait (const plAgeLinkStruct * link) {
memset(&param, 0, sizeof(param));
VaultDownload(
L"RegisterVisitAge",
"RegisterVisitAge",
ageInfoId,
_FetchVaultCallback,
&param,
@ -3183,7 +3105,7 @@ namespace _VaultRegisterVisitAge {
_Params* p = (_Params*)param;
p->fAgeInfoId = (void*)ageInfoId;
VaultDownload(L"RegisterVisitAge",
VaultDownload("RegisterVisitAge",
ageInfoId,
(FVaultDownloadCallback)_DownloadCallback,
param,
@ -3419,18 +3341,13 @@ bool VaultSetCCRStatus (bool online) {
}
//============================================================================
void VaultDump (const wchar_t tag[], unsigned vaultId, FStateDump dumpProc) {
LogMsg(kLogDebug, L"<---- ID:%u, Begin Vault%*s%s ---->", vaultId, tag ? 1 : 0, L" ", tag);
void VaultDump (const plString& tag, unsigned vaultId) {
plStatusLog::AddLineS("VaultClient.log", plFormat("<---- ID:{}, Begin Vault {} ---->", vaultId, tag).c_str());
if (hsRef<RelVaultNode> rvn = VaultGetNode(vaultId))
rvn->PrintTree(dumpProc, 0);
LogMsg(kLogDebug, L"<---- ID:%u, End Vault%*s%s ---->", vaultId, tag ? 1 : 0, L" ", tag);
}
rvn->PrintTree(0);
//============================================================================
void VaultDump (const wchar_t tag[], unsigned vaultId) {
VaultDump (tag, vaultId, LogDumpProc);
plStatusLog::AddLineS("VaultClient.log", plFormat("<---- ID:{}, End Vault {} ---->", vaultId, tag).c_str());
}
//============================================================================
@ -4122,7 +4039,7 @@ bool VaultAgeFindOrCreateSubAgeLinkAndWait (
memset(&param, 0, sizeof(param));
VaultDownload(
L"CreateSubAge",
"CreateSubAge",
ageInfoId,
_FetchVaultCallback,
&param,
@ -4239,7 +4156,7 @@ namespace _VaultCreateSubAge {
}
// Download age vault
VaultDownload(L"CreateSubAge",
VaultDownload("CreateSubAge",
ageInfoId,
(FVaultDownloadCallback)_DownloadCallback,
(void*)ageInfoId,
@ -4462,7 +4379,7 @@ bool VaultAgeFindOrCreateChildAgeLinkAndWait (
memset(&param, 0, sizeof(param));
VaultDownload(
L"CreateChildAge",
"CreateChildAge",
ageInfoId,
_FetchVaultCallback,
&param,
@ -4591,7 +4508,7 @@ namespace _VaultCreateChildAge {
p->fAgeInfoId = (void*)ageInfoId;
// Download age vault
VaultDownload(L"CreateChildAge",
VaultDownload("CreateChildAge",
ageInfoId,
(FVaultDownloadCallback)_DownloadCallback,
param,
@ -4683,7 +4600,7 @@ void VaultCCRDumpPlayers() {
//============================================================================
void VaultDownload (
const wchar_t tag[],
const plString& tag,
unsigned vaultId,
FVaultDownloadCallback callback,
void * cbParam,
@ -4715,7 +4632,7 @@ static void _DownloadVaultCallback (
}
void VaultDownloadAndWait (
const wchar_t tag[],
const plString& tag,
unsigned vaultId,
FVaultProgressCallback progressCallback,
void * cbProgressParam

11
Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h

@ -181,8 +181,8 @@ struct RelVaultNode : NetVaultNode {
void SetSeen (unsigned parentId, bool seen);
// logging
void Print (const wchar_t tag[], FStateDump dumpProc, unsigned level);
void PrintTree (FStateDump dumpProc, unsigned level);
void Print (const plString& tag, unsigned level);
void PrintTree (unsigned level);
// AgeInfoNode-specific (and it checks!)
hsRef<RelVaultNode> GetParentAgeLink ();
@ -366,8 +366,7 @@ bool VaultAmIgnoringPlayer (unsigned playerId);
unsigned VaultGetKILevel ();
bool VaultGetCCRStatus (); // true=online, false=away
bool VaultSetCCRStatus (bool online); // true=online, false=away
void VaultDump (const wchar_t tag[], unsigned vaultId, FStateDump dumpProc);
void VaultDump (const wchar_t tag[], unsigned vaultId);
void VaultDump (const plString& tag, unsigned vaultId);
bool VaultAmInMyPersonalAge ();
bool VaultAmInMyNeighborhoodAge ();
@ -470,7 +469,7 @@ typedef void (*FVaultProgressCallback)(
);
void VaultDownload (
const wchar_t tag[],
const plString& tag,
unsigned vaultId,
FVaultDownloadCallback callback,
void * cbParam,
@ -478,7 +477,7 @@ void VaultDownload (
void * cbProgressParam
);
void VaultDownloadAndWait (
const wchar_t tag[],
const plString& tag,
unsigned vaultId,
FVaultProgressCallback progressCallback,
void * cbProgressParam

Loading…
Cancel
Save