Update Player.cpp
This commit is contained in:
parent
2bfe962e28
commit
507df71845
@ -377,7 +377,7 @@ short cPlayer::DeltaExperience(short a_Xp_delta)
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOGD("Player \"%s\" gained/lost %d experience, total is now: %d",
|
LOGD("Player \"%s\" gained/lost %d experience, total is now: %d",
|
||||||
m_PlayerName.c_str(), a_Xp_delta, m_CurrentXp);
|
GetName().c_str(), a_Xp_delta, m_CurrentXp);
|
||||||
|
|
||||||
// Set experience to be updated
|
// Set experience to be updated
|
||||||
m_bDirtyExperience = true;
|
m_bDirtyExperience = true;
|
||||||
@ -391,7 +391,7 @@ short cPlayer::DeltaExperience(short a_Xp_delta)
|
|||||||
|
|
||||||
void cPlayer::StartChargingBow(void)
|
void cPlayer::StartChargingBow(void)
|
||||||
{
|
{
|
||||||
LOGD("Player \"%s\" started charging their bow", m_PlayerName.c_str());
|
LOGD("Player \"%s\" started charging their bow", GetName().c_str());
|
||||||
m_IsChargingBow = true;
|
m_IsChargingBow = true;
|
||||||
m_BowCharge = 0;
|
m_BowCharge = 0;
|
||||||
}
|
}
|
||||||
@ -402,7 +402,7 @@ void cPlayer::StartChargingBow(void)
|
|||||||
|
|
||||||
int cPlayer::FinishChargingBow(void)
|
int cPlayer::FinishChargingBow(void)
|
||||||
{
|
{
|
||||||
LOGD("Player \"%s\" finished charging their bow at a charge of %d", m_PlayerName.c_str(), m_BowCharge);
|
LOGD("Player \"%s\" finished charging their bow at a charge of %d", GetName().c_str(), m_BowCharge);
|
||||||
int res = m_BowCharge;
|
int res = m_BowCharge;
|
||||||
m_IsChargingBow = false;
|
m_IsChargingBow = false;
|
||||||
m_BowCharge = 0;
|
m_BowCharge = 0;
|
||||||
@ -415,7 +415,7 @@ int cPlayer::FinishChargingBow(void)
|
|||||||
|
|
||||||
void cPlayer::CancelChargingBow(void)
|
void cPlayer::CancelChargingBow(void)
|
||||||
{
|
{
|
||||||
LOGD("Player \"%s\" cancelled charging their bow at a charge of %d", m_PlayerName.c_str(), m_BowCharge);
|
LOGD("Player \"%s\" cancelled charging their bow at a charge of %d", GetName().c_str(), m_BowCharge);
|
||||||
m_IsChargingBow = false;
|
m_IsChargingBow = false;
|
||||||
m_BowCharge = 0;
|
m_BowCharge = 0;
|
||||||
}
|
}
|
||||||
@ -1305,7 +1305,7 @@ void cPlayer::AddToGroup( const AString & a_GroupName )
|
|||||||
{
|
{
|
||||||
cGroup* Group = cRoot::Get()->GetGroupManager()->GetGroup( a_GroupName );
|
cGroup* Group = cRoot::Get()->GetGroupManager()->GetGroup( a_GroupName );
|
||||||
m_Groups.push_back( Group );
|
m_Groups.push_back( Group );
|
||||||
LOGD("Added %s to group %s", m_PlayerName.c_str(), a_GroupName.c_str() );
|
LOGD("Added %s to group %s", GetName().c_str(), a_GroupName.c_str() );
|
||||||
ResolveGroups();
|
ResolveGroups();
|
||||||
ResolvePermissions();
|
ResolvePermissions();
|
||||||
}
|
}
|
||||||
@ -1329,13 +1329,13 @@ void cPlayer::RemoveFromGroup( const AString & a_GroupName )
|
|||||||
|
|
||||||
if( bRemoved )
|
if( bRemoved )
|
||||||
{
|
{
|
||||||
LOGD("Removed %s from group %s", m_PlayerName.c_str(), a_GroupName.c_str() );
|
LOGD("Removed %s from group %s", GetName().c_str(), a_GroupName.c_str() );
|
||||||
ResolveGroups();
|
ResolveGroups();
|
||||||
ResolvePermissions();
|
ResolvePermissions();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOGWARN("Tried to remove %s from group %s but was not in that group", m_PlayerName.c_str(), a_GroupName.c_str() );
|
LOGWARN("Tried to remove %s from group %s but was not in that group", GetName().c_str(), a_GroupName.c_str() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1441,7 +1441,7 @@ void cPlayer::ResolveGroups()
|
|||||||
if( AllGroups.find( CurrentGroup ) != AllGroups.end() )
|
if( AllGroups.find( CurrentGroup ) != AllGroups.end() )
|
||||||
{
|
{
|
||||||
LOGWARNING("ERROR: Player \"%s\" is in the group multiple times (\"%s\"). Please fix your settings in users.ini!",
|
LOGWARNING("ERROR: Player \"%s\" is in the group multiple times (\"%s\"). Please fix your settings in users.ini!",
|
||||||
m_PlayerName.c_str(), CurrentGroup->GetName().c_str()
|
GetName().c_str(), CurrentGroup->GetName().c_str()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1453,7 +1453,7 @@ void cPlayer::ResolveGroups()
|
|||||||
{
|
{
|
||||||
if( AllGroups.find( *itr ) != AllGroups.end() )
|
if( AllGroups.find( *itr ) != AllGroups.end() )
|
||||||
{
|
{
|
||||||
LOGERROR("ERROR: Player %s is in the same group multiple times due to inheritance (%s). FIX IT!", m_PlayerName.c_str(), (*itr)->GetName().c_str() );
|
LOGERROR("ERROR: Player %s is in the same group multiple times due to inheritance (%s). FIX IT!", GetName().c_str(), (*itr)->GetName().c_str() );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ToIterate.push_back( *itr );
|
ToIterate.push_back( *itr );
|
||||||
@ -1605,19 +1605,19 @@ void cPlayer::LoadPermissionsFromDisk()
|
|||||||
cIniFile IniFile;
|
cIniFile IniFile;
|
||||||
if (IniFile.ReadFile("users.ini"))
|
if (IniFile.ReadFile("users.ini"))
|
||||||
{
|
{
|
||||||
AString Groups = IniFile.GetValueSet(m_PlayerName, "Groups", "Default");
|
AString Groups = IniFile.GetValueSet(GetName(), "Groups", "Default");
|
||||||
AStringVector Split = StringSplitAndTrim(Groups, ",");
|
AStringVector Split = StringSplitAndTrim(Groups, ",");
|
||||||
|
|
||||||
for (AStringVector::const_iterator itr = Split.begin(), end = Split.end(); itr != end; ++itr)
|
for (AStringVector::const_iterator itr = Split.begin(), end = Split.end(); itr != end; ++itr)
|
||||||
{
|
{
|
||||||
if (!cRoot::Get()->GetGroupManager()->ExistsGroup(*itr))
|
if (!cRoot::Get()->GetGroupManager()->ExistsGroup(*itr))
|
||||||
{
|
{
|
||||||
LOGWARNING("The group %s for player %s was not found!", itr->c_str(), m_PlayerName.c_str());
|
LOGWARNING("The group %s for player %s was not found!", itr->c_str(), GetName().c_str());
|
||||||
}
|
}
|
||||||
AddToGroup(*itr);
|
AddToGroup(*itr);
|
||||||
}
|
}
|
||||||
|
|
||||||
AString Color = IniFile.GetValue(m_PlayerName, "Color", "-");
|
AString Color = IniFile.GetValue(GetName(), "Color", "-");
|
||||||
if (!Color.empty())
|
if (!Color.empty())
|
||||||
{
|
{
|
||||||
m_Color = Color[0];
|
m_Color = Color[0];
|
||||||
@ -1626,7 +1626,7 @@ void cPlayer::LoadPermissionsFromDisk()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
cGroupManager::GenerateDefaultUsersIni(IniFile);
|
cGroupManager::GenerateDefaultUsersIni(IniFile);
|
||||||
IniFile.AddValue("Groups", m_PlayerName, "Default");
|
IniFile.AddValue("Groups", GetName(), "Default");
|
||||||
AddToGroup("Default");
|
AddToGroup("Default");
|
||||||
}
|
}
|
||||||
IniFile.WriteFile("users.ini");
|
IniFile.WriteFile("users.ini");
|
||||||
@ -1641,14 +1641,14 @@ bool cPlayer::LoadFromDisk()
|
|||||||
LoadPermissionsFromDisk();
|
LoadPermissionsFromDisk();
|
||||||
|
|
||||||
// Log player permissions, cause it's what the cool kids do
|
// Log player permissions, cause it's what the cool kids do
|
||||||
LOGINFO("Player %s has permissions:", m_PlayerName.c_str() );
|
LOGINFO("Player %s has permissions:", GetName().c_str() );
|
||||||
for( PermissionMap::iterator itr = m_ResolvedPermissions.begin(); itr != m_ResolvedPermissions.end(); ++itr )
|
for( PermissionMap::iterator itr = m_ResolvedPermissions.begin(); itr != m_ResolvedPermissions.end(); ++itr )
|
||||||
{
|
{
|
||||||
if( itr->second ) LOG(" - %s", itr->first.c_str() );
|
if( itr->second ) LOG(" - %s", itr->first.c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
AString SourceFile;
|
AString SourceFile;
|
||||||
Printf(SourceFile, "players/%s.json", m_PlayerName.c_str() );
|
Printf(SourceFile, "players/%s.json", GetName().c_str() );
|
||||||
|
|
||||||
cFile f;
|
cFile f;
|
||||||
if (!f.Open(SourceFile, cFile::fmRead))
|
if (!f.Open(SourceFile, cFile::fmRead))
|
||||||
@ -1716,7 +1716,7 @@ bool cPlayer::LoadFromDisk()
|
|||||||
StatSerializer.Load();
|
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()
|
GetName().c_str(), GetPosX(), GetPosY(), GetPosZ(), m_LoadedWorldName.c_str()
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -1772,12 +1772,12 @@ bool cPlayer::SaveToDisk()
|
|||||||
std::string JsonData = writer.write(root);
|
std::string JsonData = writer.write(root);
|
||||||
|
|
||||||
AString SourceFile;
|
AString SourceFile;
|
||||||
Printf(SourceFile, "players/%s.json", m_PlayerName.c_str() );
|
Printf(SourceFile, "players/%s.json", GetName().c_str() );
|
||||||
|
|
||||||
cFile f;
|
cFile f;
|
||||||
if (!f.Open(SourceFile, cFile::fmWrite))
|
if (!f.Open(SourceFile, cFile::fmWrite))
|
||||||
{
|
{
|
||||||
LOGERROR("ERROR WRITING PLAYER \"%s\" TO FILE \"%s\" - cannot open file", m_PlayerName.c_str(), SourceFile.c_str());
|
LOGERROR("ERROR WRITING PLAYER \"%s\" TO FILE \"%s\" - cannot open file", GetName().c_str(), SourceFile.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (f.Write(JsonData.c_str(), JsonData.size()) != (int)JsonData.size())
|
if (f.Write(JsonData.c_str(), JsonData.size()) != (int)JsonData.size())
|
||||||
@ -1791,7 +1791,7 @@ bool cPlayer::SaveToDisk()
|
|||||||
cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), &m_Stats);
|
cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), &m_Stats);
|
||||||
if (!StatSerializer.Save())
|
if (!StatSerializer.Save())
|
||||||
{
|
{
|
||||||
LOGERROR("Could not save stats for player %s", m_PlayerName.c_str());
|
LOGERROR("Could not save stats for player %s", GetName().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user