From abf9e3f6dd9b610ef83a586e12abfbbd00dea640 Mon Sep 17 00:00:00 2001 From: "lapayo94@gmail.com" Date: Fri, 13 Jul 2012 15:26:27 +0000 Subject: The gamemode is now only saved if it is different from the current gamemode. Default gamemode now depends on the joined world, not on the default world git-svn-id: http://mc-server.googlecode.com/svn/trunk@661 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Defines.h | 1 + source/cClientHandle.cpp | 3 ++- source/cPlayer.cpp | 15 ++++++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/source/Defines.h b/source/Defines.h index e0880ad24..edb1b485f 100644 --- a/source/Defines.h +++ b/source/Defines.h @@ -273,6 +273,7 @@ namespace ItemCategory //tolua_begin enum eGameMode { + eGameMode_NotSet = -1, eGameMode_Survival = 0, eGameMode_Creative = 1, }; diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index 6e7df2bb8..1ce6fa37b 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -307,7 +307,8 @@ void cClientHandle::Authenticate(void) World = cRoot::Get()->GetDefaultWorld(); } - // We donīt need this, do we? m_Player->LoginSetGameMode (World->GetGameMode()); //set player's gamemode to server's gamemode at login. TODO: set to last player's gamemode at logout + if(m_Player->GetGameMode() == eGameMode_NotSet) + m_Player->LoginSetGameMode(World->GetGameMode()); m_Player->SetIP (m_Socket.GetIPString()); diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp index 5ab06fa62..9e54b7c44 100644 --- a/source/cPlayer.cpp +++ b/source/cPlayer.cpp @@ -53,7 +53,7 @@ CLASS_DEFINITION( cPlayer, cPawn ); cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) - : m_GameMode( eGameMode_Survival ) + : m_GameMode(eGameMode_NotSet) , m_IP("") , m_LastBlockActionTime( 0 ) , m_LastBlockActionCnt( 0 ) @@ -915,7 +915,10 @@ bool cPlayer::LoadFromDisk() m_Health = (short)root.get("health", 0 ).asInt(); m_FoodLevel = (short)root.get("food", 0 ).asInt(); - m_GameMode = (eGameMode) root.get("gamemode", cRoot::Get()->GetDefaultWorld()->GetGameMode()).asInt(); + + m_GameMode = (eGameMode) root.get("gamemode", eGameMode_NotSet).asInt(); + + m_Inventory->LoadFromJson(root["inventory"]); m_CreativeInventory->LoadFromJson(root["creativeinventory"]); @@ -961,7 +964,13 @@ bool cPlayer::SaveToDisk() root["health"] = m_Health; root["food"] = m_FoodLevel; root["world"] = GetWorld()->GetName(); - root["gamemode"] = (int) m_GameMode; + + if(m_GameMode == GetWorld()->GetGameMode()) + { + root["gamemode"] = (int) eGameMode_NotSet; + }else{ + root["gamemode"] = (int) m_GameMode; + } Json::StyledWriter writer; std::string JsonData = writer.write( root ); -- cgit v1.2.3