From b5b920dedaa62302795b0b8f3db84a0650d236e0 Mon Sep 17 00:00:00 2001 From: faketruth Date: Tue, 1 Nov 2011 21:57:08 +0000 Subject: You can now run multiple worlds by defining them in settings.ini . However there's no way to change worlds on the fly yet Players are now stored in separate folder /players instead of in the world folder (!so move the folder!) Fixed a memory leak/error in cPickup.cpp Multiple worlds are stored in cRoot cClientHandle lists are taken out of cWorld and now stored in cServer Worlds now have names to distinguish them by Some functions in the Core plugin now distinguish between worlds git-svn-id: http://mc-server.googlecode.com/svn/trunk@40 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cPlayer.cpp | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'source/cPlayer.cpp') diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp index fe3f5a7d6..69e163629 100644 --- a/source/cPlayer.cpp +++ b/source/cPlayer.cpp @@ -15,6 +15,7 @@ #include "cItem.h" #include "cTracer.h" #include "cRoot.h" +#include "cMakeDir.h" #include "packets/cPacket_NamedEntitySpawn.h" #include "packets/cPacket_EntityLook.h" @@ -86,13 +87,16 @@ cPlayer::cPlayer(cClientHandle* a_Client, const char* a_PlayerName) if( !LoadFromDisk() ) { m_Inventory->Clear(); - SetPosX( cRoot::Get()->GetWorld()->GetSpawnX() ); // TODO - Get from the correct world? - SetPosY( cRoot::Get()->GetWorld()->GetSpawnY() ); - SetPosZ( cRoot::Get()->GetWorld()->GetSpawnZ() ); + SetPosX( cRoot::Get()->GetDefaultWorld()->GetSpawnX() ); + SetPosY( cRoot::Get()->GetDefaultWorld()->GetSpawnY() ); + SetPosZ( cRoot::Get()->GetDefaultWorld()->GetSpawnZ() ); } +} - //MoveToCorrectChunk(); - cRoot::Get()->GetWorld()->AddPlayer( this ); // TODO - Add to correct world? Or get rid of this? +void cPlayer::Initialize( cWorld* a_World ) +{ + cPawn::Initialize( a_World ); + GetWorld()->AddPlayer( this ); } cPlayer::~cPlayer(void) @@ -618,7 +622,7 @@ void cPlayer::TossItem( bool a_bDraggingItem, int a_Amount /* = 1 */ ) } } -bool cPlayer::LoadFromDisk() +bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the correct world for this player { cIniFile IniFile("users.ini"); if( IniFile.ReadFile() ) @@ -653,7 +657,7 @@ bool cPlayer::LoadFromDisk() } char SourceFile[128]; - sprintf_s(SourceFile, 128, "world/player/%s.json", m_pState->PlayerName.c_str() ); + sprintf_s(SourceFile, 128, "players/%s.json", m_pState->PlayerName.c_str() ); FILE* f; #ifdef _WIN32 @@ -696,7 +700,7 @@ bool cPlayer::LoadFromDisk() m_Rot->z = (float)JSON_PlayerRotation[(unsigned int)2].asDouble(); } - m_Health = root.get("health", 0 ).asInt(); + m_Health = (short)root.get("health", 0 ).asInt(); m_Inventory->LoadFromJson(root["inventory"]); return true; @@ -706,21 +710,7 @@ bool cPlayer::LoadFromDisk() bool cPlayer::SaveToDisk() { - #ifdef _WIN32 - { // Make sure some folders exist - SECURITY_ATTRIBUTES Attrib; - Attrib.nLength = sizeof(SECURITY_ATTRIBUTES); - Attrib.lpSecurityDescriptor = NULL; - Attrib.bInheritHandle = false; - ::CreateDirectory("world", &Attrib); - ::CreateDirectory("world/player", &Attrib); - } - #else - { - mkdir("world", S_IRWXU | S_IRWXG | S_IRWXO); - mkdir("world/player", S_IRWXU | S_IRWXG | S_IRWXO); - } - #endif + cMakeDir::MakeDir("players"); // create the JSON data Json::Value JSON_PlayerPosition; @@ -746,7 +736,7 @@ bool cPlayer::SaveToDisk() std::string JsonData = writer.write( root ); char SourceFile[128]; - sprintf_s(SourceFile, 128, "world/player/%s.json", m_pState->PlayerName.c_str() ); + sprintf_s(SourceFile, 128, "players/%s.json", m_pState->PlayerName.c_str() ); FILE* f; #ifdef _WIN32 -- cgit v1.2.3