summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorandrew <xdotftw@gmail.com>2014-01-22 14:49:21 +0100
committerandrew <xdotftw@gmail.com>2014-01-22 14:49:21 +0100
commitdd04f5a73ccc125be80a3ba3a3ab508ac300b99a (patch)
treedb504bb2f55757a79a4173f7d2b82f9a66d08229 /src
parentMerge branch 'master' of https://github.com/mc-server/MCServer (diff)
downloadcuberite-dd04f5a73ccc125be80a3ba3a3ab508ac300b99a.tar
cuberite-dd04f5a73ccc125be80a3ba3a3ab508ac300b99a.tar.gz
cuberite-dd04f5a73ccc125be80a3ba3a3ab508ac300b99a.tar.bz2
cuberite-dd04f5a73ccc125be80a3ba3a3ab508ac300b99a.tar.lz
cuberite-dd04f5a73ccc125be80a3ba3a3ab508ac300b99a.tar.xz
cuberite-dd04f5a73ccc125be80a3ba3a3ab508ac300b99a.tar.zst
cuberite-dd04f5a73ccc125be80a3ba3a3ab508ac300b99a.zip
Diffstat (limited to '')
-rw-r--r--src/Scoreboard.cpp3
-rw-r--r--src/Scoreboard.h32
-rw-r--r--src/World.cpp9
-rw-r--r--src/WorldStorage/ScoreboardSerializer.cpp15
4 files changed, 44 insertions, 15 deletions
diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp
index e6812d3d7..b2edd613b 100644
--- a/src/Scoreboard.cpp
+++ b/src/Scoreboard.cpp
@@ -238,6 +238,8 @@ bool cTeam::HasPlayer(const AString & a_Name) const
void cTeam::Reset(void)
{
+ // TODO 2014-01-22 xdot: Inform online players
+
m_Players.clear();
}
@@ -505,3 +507,4 @@ unsigned int cScoreboard::GetNumTeams(void) const
+
diff --git a/src/Scoreboard.h b/src/Scoreboard.h
index 11b456739..f64ba2bce 100644
--- a/src/Scoreboard.h
+++ b/src/Scoreboard.h
@@ -27,8 +27,6 @@ class cObjective
{
public:
- // tolua_end
-
typedef int Score;
enum eType
@@ -52,6 +50,8 @@ public:
E_TYPE_STAT_ENTITY_KILLED_BY
};
+ // tolua_end
+
static AString TypeToString(eType a_Type);
static eType StringToType(const AString & a_Name);
@@ -60,6 +60,8 @@ public:
cObjective(const AString & a_Name, const AString & a_DisplayName, eType a_Type, cWorld * a_World);
+ // tolua_begin
+
eType GetType(void) const { return m_Type; }
const AString & GetName(void) const { return m_Name; }
@@ -85,6 +87,8 @@ public:
void SetDisplayName(const AString & a_Name);
+ // tolua_end
+
/// Send this objective to the specified client
void SendTo(cClientHandle & a_Client);
@@ -135,6 +139,8 @@ public:
/// Removes all registered players
void Reset(void);
+ // tolua_begin
+
/// Returns the number of registered players
unsigned int GetNumPlayers(void) const;
@@ -147,13 +153,15 @@ public:
const AString & GetPrefix(void) const { return m_Prefix; }
const AString & GetSuffix(void) const { return m_Suffix; }
- void SetFriendlyFire(bool a_Flag) { m_AllowsFriendlyFire = a_Flag; }
+ void SetFriendlyFire(bool a_Flag) { m_AllowsFriendlyFire = a_Flag; }
void SetCanSeeFriendlyInvisible(bool a_Flag) { m_CanSeeFriendlyInvisible = a_Flag; }
void SetDisplayName(const AString & a_Name);
- void SetPrefix(const AString & a_Prefix);
- void SetSuffix(const AString & a_Suffix);
+ void SetPrefix(const AString & a_Prefix) { m_Prefix = a_Prefix; }
+ void SetSuffix(const AString & a_Suffix) { m_Suffix = a_Suffix; }
+
+ // tolua_end
private:
@@ -183,8 +191,6 @@ class cScoreboard
{
public:
- // tolua_end
-
enum eDisplaySlot
{
E_DISPLAY_SLOT_LIST = 0,
@@ -194,11 +200,15 @@ public:
E_DISPLAY_SLOT_COUNT
};
+ // tolua_end
+
public:
cScoreboard(cWorld * a_World);
+ // tolua_begin
+
/// Registers a new scoreboard objective, returns the cObjective instance, NULL on name collision
cObjective * RegisterObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type);
@@ -228,13 +238,15 @@ public:
/// Execute callback for each objective with the specified type
void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback);
- /// Send this scoreboard to the specified client
- void SendTo(cClientHandle & a_Client);
-
unsigned int GetNumObjectives(void) const;
unsigned int GetNumTeams(void) const;
+ // tolua_end
+
+ /// Send this scoreboard to the specified client
+ void SendTo(cClientHandle & a_Client);
+
private:
diff --git a/src/World.cpp b/src/World.cpp
index f83de0342..49d42f08e 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -12,6 +12,7 @@
#include "ChunkMap.h"
#include "Generating/ChunkDesc.h"
#include "OSSupport/Timer.h"
+#include "WorldStorage/ScoreboardSerializer.h"
// Entities (except mobs):
#include "Entities/ExpOrb.h"
@@ -248,6 +249,10 @@ cWorld::cWorld(const AString & a_WorldName) :
LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str());
cFile::CreateFolder(FILE_IO_PREFIX + m_WorldName);
+
+ // Load the scoreboard
+ cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard);
+ Serializer.Load();
}
@@ -267,6 +272,10 @@ cWorld::~cWorld()
m_Storage.WaitForFinish();
+ // Unload the scoreboard
+ cScoreboardSerializer Serializer(m_WorldName, &m_Scoreboard);
+ Serializer.Save();
+
delete m_ChunkMap;
}
diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp
index bcac50bb6..dabc5e2e1 100644
--- a/src/WorldStorage/ScoreboardSerializer.cpp
+++ b/src/WorldStorage/ScoreboardSerializer.cpp
@@ -22,7 +22,12 @@
cScoreboardSerializer::cScoreboardSerializer(const AString & a_WorldName, cScoreboard* a_ScoreBoard)
: m_ScoreBoard(a_ScoreBoard)
{
- Printf(m_Path, "%s/data/scoreboard.dat", a_WorldName.c_str());
+ AString DataPath;
+ Printf(DataPath, "%s/data", a_WorldName.c_str());
+
+ m_Path = DataPath + "/scoreboard.dat";
+
+ cFile::CreateFolder(FILE_IO_PREFIX + DataPath);
}
@@ -33,7 +38,7 @@ bool cScoreboardSerializer::Load(void)
{
cFile File;
- if (!File.Open(m_Path, cFile::fmReadWrite))
+ if (!File.Open(FILE_IO_PREFIX + m_Path, cFile::fmReadWrite))
{
return false;
}
@@ -60,7 +65,7 @@ bool cScoreboardSerializer::Load(void)
{
return false;
}
-
+
// Parse the NBT data:
cParsedNBT NBT(Uncompressed, strm.total_out);
if (!NBT.IsValid())
@@ -81,7 +86,7 @@ bool cScoreboardSerializer::Save(void)
cFastNBTWriter Writer;
Writer.BeginCompound("");
-
+ m_ScoreBoard->RegisterObjective("test","test",cObjective::E_TYPE_DUMMY)->AddScore("dot", 2);
SaveScoreboardToNBT(Writer);
Writer.EndCompound();
@@ -91,7 +96,7 @@ bool cScoreboardSerializer::Save(void)
cParsedNBT TestParse(Writer.GetResult().data(), Writer.GetResult().size());
ASSERT(TestParse.IsValid());
#endif // _DEBUG
-
+
gzFile gz = gzopen((FILE_IO_PREFIX + m_Path).c_str(), "wb");
if (gz != NULL)
{