Fixed stat serialization
This commit is contained in:
parent
c7c3724a3e
commit
e3c6c8f3dd
|
@ -31,8 +31,6 @@
|
||||||
#include "CompositeChat.h"
|
#include "CompositeChat.h"
|
||||||
#include "Items/ItemSword.h"
|
#include "Items/ItemSword.h"
|
||||||
|
|
||||||
#include "WorldStorage/StatSerializer.h"
|
|
||||||
|
|
||||||
#include "md5/md5.h"
|
#include "md5/md5.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -339,12 +337,6 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID)
|
||||||
// Send scoreboard data
|
// Send scoreboard data
|
||||||
World->GetScoreBoard().SendTo(*this);
|
World->GetScoreBoard().SendTo(*this);
|
||||||
|
|
||||||
#if 0
|
|
||||||
// Load stats
|
|
||||||
cStatSerializer StatSerializer(World->GetName(), m_Player->GetName(), &m_Player->GetStatManager());
|
|
||||||
StatSerializer.Load();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Delay the first ping until the client "settles down"
|
// Delay the first ping until the client "settles down"
|
||||||
// This should fix #889, "BadCast exception, cannot convert bit to fm" error in client
|
// This should fix #889, "BadCast exception, cannot convert bit to fm" error in client
|
||||||
cTimer t1;
|
cTimer t1;
|
||||||
|
|
|
@ -133,15 +133,6 @@ cPlayer::~cPlayer(void)
|
||||||
|
|
||||||
SaveToDisk();
|
SaveToDisk();
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* Save statistics. */
|
|
||||||
cStatSerializer StatSerializer(m_World->GetName(), m_PlayerName, &m_Stats);
|
|
||||||
if (!StatSerializer.Save())
|
|
||||||
{
|
|
||||||
LOGERROR("Could not save stats for player %s", m_PlayerName.c_str());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
m_World->RemovePlayer( this );
|
m_World->RemovePlayer( this );
|
||||||
|
|
||||||
m_ClientHandle = NULL;
|
m_ClientHandle = NULL;
|
||||||
|
@ -1638,6 +1629,12 @@ bool cPlayer::LoadFromDisk()
|
||||||
m_Inventory.LoadFromJson(root["inventory"]);
|
m_Inventory.LoadFromJson(root["inventory"]);
|
||||||
|
|
||||||
m_LoadedWorldName = root.get("world", "world").asString();
|
m_LoadedWorldName = root.get("world", "world").asString();
|
||||||
|
|
||||||
|
/* Load the player stats.
|
||||||
|
* We use the default world name (like bukkit) because stats are shared between dimensions/worlds.
|
||||||
|
*/
|
||||||
|
cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), &m_Stats);
|
||||||
|
StatSerializer.Load();
|
||||||
|
|
||||||
LOGD("Player \"%s\" was read from file, spawning at {%.2f, %.2f, %.2f} in world \"%s\"",
|
LOGD("Player \"%s\" was read from file, spawning at {%.2f, %.2f, %.2f} in world \"%s\"",
|
||||||
m_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ(), m_LoadedWorldName.c_str()
|
m_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ(), m_LoadedWorldName.c_str()
|
||||||
|
@ -1709,6 +1706,17 @@ bool cPlayer::SaveToDisk()
|
||||||
LOGERROR("ERROR WRITING PLAYER JSON TO FILE \"%s\"", SourceFile.c_str());
|
LOGERROR("ERROR WRITING PLAYER JSON TO FILE \"%s\"", SourceFile.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Save the player stats.
|
||||||
|
* We use the default world name (like bukkit) because stats are shared between dimensions/worlds.
|
||||||
|
*/
|
||||||
|
cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), m_PlayerName, &m_Stats);
|
||||||
|
if (!StatSerializer.Save())
|
||||||
|
{
|
||||||
|
LOGERROR("Could not save stats for player %s", m_PlayerName.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1723,7 +1731,10 @@ cPlayer::StringList cPlayer::GetResolvedPermissions()
|
||||||
const PermissionMap& ResolvedPermissions = m_ResolvedPermissions;
|
const PermissionMap& ResolvedPermissions = m_ResolvedPermissions;
|
||||||
for( PermissionMap::const_iterator itr = ResolvedPermissions.begin(); itr != ResolvedPermissions.end(); ++itr )
|
for( PermissionMap::const_iterator itr = ResolvedPermissions.begin(); itr != ResolvedPermissions.end(); ++itr )
|
||||||
{
|
{
|
||||||
if( itr->second ) Permissions.push_back( itr->first );
|
if (itr->second)
|
||||||
|
{
|
||||||
|
Permissions.push_back( itr->first );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Permissions;
|
return Permissions;
|
||||||
|
|
|
@ -114,7 +114,7 @@ eStatistic cStatInfo::GetType(const AString & a_Name)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < ARRAYCOUNT(ms_Info); ++i)
|
for (unsigned int i = 0; i < ARRAYCOUNT(ms_Info); ++i)
|
||||||
{
|
{
|
||||||
if (NoCaseCompare(ms_Info[i].m_Name, a_Name))
|
if (NoCaseCompare(ms_Info[i].m_Name, a_Name) == 0)
|
||||||
{
|
{
|
||||||
return ms_Info[i].m_Type;
|
return ms_Info[i].m_Type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
|
|
||||||
#include "../Statistics.h"
|
#include "../Statistics.h"
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +17,7 @@ cStatSerializer::cStatSerializer(const AString& a_WorldName, const AString& a_Pl
|
||||||
AString StatsPath;
|
AString StatsPath;
|
||||||
Printf(StatsPath, "%s/stats", a_WorldName.c_str());
|
Printf(StatsPath, "%s/stats", a_WorldName.c_str());
|
||||||
|
|
||||||
m_Path = StatsPath + "/" + a_PlayerName + ".dat";
|
m_Path = StatsPath + "/" + a_PlayerName + ".json";
|
||||||
|
|
||||||
/* Ensure that the directory exists. */
|
/* Ensure that the directory exists. */
|
||||||
cFile::CreateFolder(FILE_IO_PREFIX + StatsPath);
|
cFile::CreateFolder(FILE_IO_PREFIX + StatsPath);
|
||||||
|
@ -88,6 +86,8 @@ void cStatSerializer::SaveStatToJSON(Json::Value & a_Out)
|
||||||
|
|
||||||
a_Out[StatName] = Value;
|
a_Out[StatName] = Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO 2014-05-11 xdot: Save "progress"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,11 +107,28 @@ bool cStatSerializer::LoadStatFromJSON(const Json::Value & a_In)
|
||||||
|
|
||||||
if (StatType == statInvalid)
|
if (StatType == statInvalid)
|
||||||
{
|
{
|
||||||
LOGWARNING("Invalid statistic type %s", StatName.c_str());
|
LOGWARNING("Invalid statistic type \"%s\"", StatName.c_str());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Manager->SetValue(StatType, (*it).asInt());
|
Json::Value & Node = *it;
|
||||||
|
|
||||||
|
if (Node.isInt())
|
||||||
|
{
|
||||||
|
m_Manager->SetValue(StatType, Node.asInt());
|
||||||
|
}
|
||||||
|
else if (Node.isObject())
|
||||||
|
{
|
||||||
|
StatValue Value = Node.get("value", 0).asInt();
|
||||||
|
|
||||||
|
// TODO 2014-05-11 xdot: Load "progress"
|
||||||
|
|
||||||
|
m_Manager->SetValue(StatType, Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOGWARNING("Invalid statistic value for type \"%s\"", StatName.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user