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") 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("Player", NetCommGetPlayer()->playerInt);
VaultDump(L"Age", NetCommGetAge()->ageVaultId); VaultDump("Age", NetCommGetAge()->ageVaultId);
} }
#endif #endif

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

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

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

@ -69,18 +69,4 @@ void * ModuleGetInstance ();
const wchar_t * AppGetCommandLine (); 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 #endif

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

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

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

@ -311,7 +311,7 @@ static void INetCliAuthSetPlayerRequestCallback (
s_needAvatarLoad = true; s_needAvatarLoad = true;
VaultDownload( VaultDownload(
L"SetActivePlayer", "SetActivePlayer",
s_player->playerInt, s_player->playerInt,
PlayerInitCallback, PlayerInitCallback,
param, param,
@ -367,7 +367,7 @@ static void INetCliAuthLoginSetPlayerRequestCallback (
} }
else { else {
VaultDownload( VaultDownload(
L"SetActivePlayer", "SetActivePlayer",
s_player->playerInt, s_player->playerInt,
LoginPlayerInitCallback, LoginPlayerInitCallback,
param, 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 "plGImage/plJPEG.h"
#include "plMessage/plVaultNotifyMsg.h" #include "plMessage/plVaultNotifyMsg.h"
#include "plNetClientComm/plNetClientComm.h" #include "plNetClientComm/plNetClientComm.h"
#include "plStatusLog/plStatusLog.h"
#define KI_CONSTANTS_ONLY #define KI_CONSTANTS_ONLY
#include "pfMessage/pfKIMsg.h" // for KI level constants =( #include "pfMessage/pfKIMsg.h" // for KI level constants =(

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

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

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

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

Loading…
Cancel
Save