Keep players in gmNotSet (#4248)
This allows players game mode to update to the default after portal to another world. Fixes #4207
This commit is contained in:
parent
3e802932a6
commit
7b0db672d1
@ -373,16 +373,22 @@ void cClientHandle::FinishAuthenticate(const AString & a_Name, const cUUID & a_U
|
||||
InvalidateCachedSentChunk();
|
||||
m_Self.reset();
|
||||
|
||||
World = cRoot::Get()->GetWorld(m_Player->GetLoadedWorldName());
|
||||
if (World == nullptr)
|
||||
{
|
||||
World = cRoot::Get()->GetDefaultWorld();
|
||||
m_Player->SetPosition(World->GetSpawnX(), World->GetSpawnY(), World->GetSpawnZ());
|
||||
}
|
||||
|
||||
if (m_Player->GetGameMode() == eGameMode_NotSet)
|
||||
// New player use default world
|
||||
// Player who can load from disk, use loaded world
|
||||
if (m_Player->GetWorld() == nullptr)
|
||||
{
|
||||
m_Player->LoginSetGameMode(World->GetGameMode());
|
||||
World = cRoot::Get()->GetWorld(m_Player->GetLoadedWorldName());
|
||||
if (World == nullptr)
|
||||
{
|
||||
World = cRoot::Get()->GetDefaultWorld();
|
||||
m_Player->SetPosition(World->GetSpawnX(), World->GetSpawnY(), World->GetSpawnZ());
|
||||
}
|
||||
m_Player->SetWorld(World);
|
||||
}
|
||||
else
|
||||
{
|
||||
World = m_Player->GetWorld();
|
||||
}
|
||||
|
||||
m_Player->SetIP (m_IPString);
|
||||
@ -425,7 +431,6 @@ void cClientHandle::FinishAuthenticate(const AString & a_Name, const cUUID & a_U
|
||||
cRoot::Get()->BroadcastPlayerListsAddPlayer(*m_Player);
|
||||
cRoot::Get()->SendPlayerLists(m_Player);
|
||||
|
||||
m_Player->SetWorld(World);
|
||||
m_State = csAuthenticated;
|
||||
}
|
||||
|
||||
|
@ -148,6 +148,9 @@ cPlayer::cPlayer(cClientHandlePtr a_Client, const AString & a_PlayerName) :
|
||||
// This is a new player. Set the player spawn point to the spawn point of the default world
|
||||
SetBedPos(Vector3i(static_cast<int>(World->GetSpawnX()), static_cast<int>(World->GetSpawnY()), static_cast<int>(World->GetSpawnZ())), World);
|
||||
|
||||
SetWorld(World); // Use default world
|
||||
SetCapabilities();
|
||||
|
||||
LOGD("Player \"%s\" is connecting for the first time, spawning at default world spawn {%.2f, %.2f, %.2f}",
|
||||
a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ()
|
||||
);
|
||||
@ -1255,8 +1258,7 @@ Vector3d cPlayer::GetEyePosition(void) const
|
||||
|
||||
bool cPlayer::IsGameModeCreative(void) const
|
||||
{
|
||||
return (m_GameMode == gmCreative) || // Either the player is explicitly in Creative
|
||||
((m_GameMode == gmNotSet) && m_World->IsGameModeCreative()); // or they inherit from the world and the world is Creative
|
||||
return (GetEffectiveGameMode() == gmCreative);
|
||||
}
|
||||
|
||||
|
||||
@ -1265,8 +1267,7 @@ bool cPlayer::IsGameModeCreative(void) const
|
||||
|
||||
bool cPlayer::IsGameModeSurvival(void) const
|
||||
{
|
||||
return (m_GameMode == gmSurvival) || // Either the player is explicitly in Survival
|
||||
((m_GameMode == gmNotSet) && m_World->IsGameModeSurvival()); // or they inherit from the world and the world is Survival
|
||||
return (GetEffectiveGameMode() == gmSurvival);
|
||||
}
|
||||
|
||||
|
||||
@ -1275,8 +1276,7 @@ bool cPlayer::IsGameModeSurvival(void) const
|
||||
|
||||
bool cPlayer::IsGameModeAdventure(void) const
|
||||
{
|
||||
return (m_GameMode == gmAdventure) || // Either the player is explicitly in Adventure
|
||||
((m_GameMode == gmNotSet) && m_World->IsGameModeAdventure()); // or they inherit from the world and the world is Adventure
|
||||
return (GetEffectiveGameMode() == gmAdventure);
|
||||
}
|
||||
|
||||
|
||||
@ -1284,8 +1284,7 @@ bool cPlayer::IsGameModeAdventure(void) const
|
||||
|
||||
bool cPlayer::IsGameModeSpectator(void) const
|
||||
{
|
||||
return (m_GameMode == gmSpectator) || // Either the player is explicitly in Spectator
|
||||
((m_GameMode == gmNotSet) && m_World->IsGameModeSpectator()); // or they inherit from the world and the world is Spectator
|
||||
return (GetEffectiveGameMode() == gmSpectator);
|
||||
}
|
||||
|
||||
|
||||
@ -1553,30 +1552,32 @@ void cPlayer::SetGameMode(eGameMode a_GameMode)
|
||||
|
||||
|
||||
|
||||
void cPlayer::LoginSetGameMode( eGameMode a_GameMode)
|
||||
{
|
||||
m_GameMode = a_GameMode;
|
||||
|
||||
SetCapabilities();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cPlayer::SetCapabilities()
|
||||
{
|
||||
if (!IsGameModeCreative() || IsGameModeSpectator())
|
||||
// Fly ability
|
||||
if (IsGameModeCreative() || IsGameModeSpectator())
|
||||
{
|
||||
SetCanFly(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetFlying(false);
|
||||
SetCanFly(false);
|
||||
}
|
||||
|
||||
// Visible
|
||||
if (IsGameModeSpectator())
|
||||
{
|
||||
SetVisible(false);
|
||||
SetCanFly(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetVisible(true);
|
||||
}
|
||||
|
||||
// Set for spectator
|
||||
if (IsGameModeSpectator())
|
||||
{
|
||||
// Clear the current dragging item of the player
|
||||
if (GetWindow() != nullptr)
|
||||
{
|
||||
@ -1584,10 +1585,6 @@ void cPlayer::SetCapabilities()
|
||||
GetClientHandle()->SendInventorySlot(-1, -1, m_DraggingItem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2046,6 +2043,12 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d
|
||||
// Stop all mobs from targeting this player
|
||||
StopEveryoneFromTargetingMe();
|
||||
|
||||
// Deal with new world
|
||||
SetWorld(a_World);
|
||||
|
||||
// Set capabilities based on new world
|
||||
SetCapabilities();
|
||||
|
||||
cClientHandle * ch = this->GetClientHandle();
|
||||
if (ch != nullptr)
|
||||
{
|
||||
@ -2055,7 +2058,6 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d
|
||||
m_ClientHandle->SendRespawn(a_World->GetDimension());
|
||||
}
|
||||
|
||||
|
||||
// Update the view distance.
|
||||
ch->SetViewDistance(m_ClientHandle->GetRequestedViewDistance());
|
||||
|
||||
@ -2071,7 +2073,7 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d
|
||||
|
||||
// Queue add to new world and removal from the old one
|
||||
|
||||
SetWorld(a_World); // Chunks may be streamed before cWorld::AddPlayer() sets the world to the new value
|
||||
// Chunks may be streamed before cWorld::AddPlayer() sets the world to the new value
|
||||
cChunk * ParentChunk = this->GetParentChunk();
|
||||
|
||||
LOGD("Warping player \"%s\" from world \"%s\" to \"%s\". Source chunk: (%d, %d) ",
|
||||
|
@ -146,9 +146,6 @@ public:
|
||||
|
||||
virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) override;
|
||||
|
||||
// Sets the current gamemode, doesn't check validity, doesn't send update packets to client
|
||||
void LoginSetGameMode(eGameMode a_GameMode);
|
||||
|
||||
// Updates player's capabilities - flying, visibility, etc. from their gamemode.
|
||||
void SetCapabilities();
|
||||
|
||||
|
@ -140,7 +140,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (a_Player->GetGameMode() != gmCreative)
|
||||
if (!a_Player->IsGameModeCreative())
|
||||
{
|
||||
// Remove fluid bucket, add empty bucket:
|
||||
if (!a_Player->GetInventory().RemoveOneEquippedItem())
|
||||
|
@ -947,7 +947,7 @@ void cProtocol_1_8_0::SendPlayerListAddPlayer(const cPlayer & a_Player)
|
||||
}
|
||||
}
|
||||
|
||||
Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetGameMode()));
|
||||
Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetEffectiveGameMode()));
|
||||
Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetClientHandle()->GetPing()));
|
||||
Pkt.WriteBool(false);
|
||||
}
|
||||
@ -978,7 +978,7 @@ void cProtocol_1_8_0::SendPlayerListUpdateGameMode(const cPlayer & a_Player)
|
||||
Pkt.WriteVarInt32(1);
|
||||
Pkt.WriteVarInt32(1);
|
||||
Pkt.WriteUUID(a_Player.GetUUID());
|
||||
Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetGameMode()));
|
||||
Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetEffectiveGameMode()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -992,7 +992,7 @@ void cProtocol_1_9_0::SendPlayerListAddPlayer(const cPlayer & a_Player)
|
||||
}
|
||||
}
|
||||
|
||||
Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetGameMode()));
|
||||
Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetEffectiveGameMode()));
|
||||
Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetClientHandle()->GetPing()));
|
||||
Pkt.WriteBool(false);
|
||||
}
|
||||
@ -1023,7 +1023,7 @@ void cProtocol_1_9_0::SendPlayerListUpdateGameMode(const cPlayer & a_Player)
|
||||
Pkt.WriteVarInt32(1);
|
||||
Pkt.WriteVarInt32(1);
|
||||
Pkt.WriteUUID(a_Player.GetUUID());
|
||||
Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetGameMode()));
|
||||
Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetEffectiveGameMode()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -142,6 +142,7 @@ public:
|
||||
bool IsGameModeSpectator(void) const { return (m_GameMode == gmSpectator); }
|
||||
|
||||
bool IsPVPEnabled(void) const { return m_bEnabledPVP; }
|
||||
|
||||
bool IsDeepSnowEnabled(void) const { return m_IsDeepSnowEnabled; }
|
||||
|
||||
bool ShouldLavaSpawnFire(void) const { return m_ShouldLavaSpawnFire; }
|
||||
|
Loading…
Reference in New Issue
Block a user