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();
|
InvalidateCachedSentChunk();
|
||||||
m_Self.reset();
|
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);
|
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()->BroadcastPlayerListsAddPlayer(*m_Player);
|
||||||
cRoot::Get()->SendPlayerLists(m_Player);
|
cRoot::Get()->SendPlayerLists(m_Player);
|
||||||
|
|
||||||
m_Player->SetWorld(World);
|
|
||||||
m_State = csAuthenticated;
|
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
|
// 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);
|
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}",
|
LOGD("Player \"%s\" is connecting for the first time, spawning at default world spawn {%.2f, %.2f, %.2f}",
|
||||||
a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ()
|
a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ()
|
||||||
);
|
);
|
||||||
@ -1255,8 +1258,7 @@ Vector3d cPlayer::GetEyePosition(void) const
|
|||||||
|
|
||||||
bool cPlayer::IsGameModeCreative(void) const
|
bool cPlayer::IsGameModeCreative(void) const
|
||||||
{
|
{
|
||||||
return (m_GameMode == gmCreative) || // Either the player is explicitly in Creative
|
return (GetEffectiveGameMode() == gmCreative);
|
||||||
((m_GameMode == gmNotSet) && m_World->IsGameModeCreative()); // or they inherit from the world and the world is Creative
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1265,8 +1267,7 @@ bool cPlayer::IsGameModeCreative(void) const
|
|||||||
|
|
||||||
bool cPlayer::IsGameModeSurvival(void) const
|
bool cPlayer::IsGameModeSurvival(void) const
|
||||||
{
|
{
|
||||||
return (m_GameMode == gmSurvival) || // Either the player is explicitly in Survival
|
return (GetEffectiveGameMode() == gmSurvival);
|
||||||
((m_GameMode == gmNotSet) && m_World->IsGameModeSurvival()); // or they inherit from the world and the world is Survival
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1275,8 +1276,7 @@ bool cPlayer::IsGameModeSurvival(void) const
|
|||||||
|
|
||||||
bool cPlayer::IsGameModeAdventure(void) const
|
bool cPlayer::IsGameModeAdventure(void) const
|
||||||
{
|
{
|
||||||
return (m_GameMode == gmAdventure) || // Either the player is explicitly in Adventure
|
return (GetEffectiveGameMode() == gmAdventure);
|
||||||
((m_GameMode == gmNotSet) && m_World->IsGameModeAdventure()); // or they inherit from the world and the world is Adventure
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1284,8 +1284,7 @@ bool cPlayer::IsGameModeAdventure(void) const
|
|||||||
|
|
||||||
bool cPlayer::IsGameModeSpectator(void) const
|
bool cPlayer::IsGameModeSpectator(void) const
|
||||||
{
|
{
|
||||||
return (m_GameMode == gmSpectator) || // Either the player is explicitly in Spectator
|
return (GetEffectiveGameMode() == gmSpectator);
|
||||||
((m_GameMode == gmNotSet) && m_World->IsGameModeSpectator()); // or they inherit from the world and the world is Spectator
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1553,30 +1552,32 @@ void cPlayer::SetGameMode(eGameMode a_GameMode)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cPlayer::LoginSetGameMode( eGameMode a_GameMode)
|
|
||||||
{
|
|
||||||
m_GameMode = a_GameMode;
|
|
||||||
|
|
||||||
SetCapabilities();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cPlayer::SetCapabilities()
|
void cPlayer::SetCapabilities()
|
||||||
{
|
{
|
||||||
if (!IsGameModeCreative() || IsGameModeSpectator())
|
// Fly ability
|
||||||
|
if (IsGameModeCreative() || IsGameModeSpectator())
|
||||||
|
{
|
||||||
|
SetCanFly(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
SetFlying(false);
|
SetFlying(false);
|
||||||
SetCanFly(false);
|
SetCanFly(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Visible
|
||||||
if (IsGameModeSpectator())
|
if (IsGameModeSpectator())
|
||||||
{
|
{
|
||||||
SetVisible(false);
|
SetVisible(false);
|
||||||
SetCanFly(true);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set for spectator
|
||||||
|
if (IsGameModeSpectator())
|
||||||
|
{
|
||||||
// Clear the current dragging item of the player
|
// Clear the current dragging item of the player
|
||||||
if (GetWindow() != nullptr)
|
if (GetWindow() != nullptr)
|
||||||
{
|
{
|
||||||
@ -1584,10 +1585,6 @@ void cPlayer::SetCapabilities()
|
|||||||
GetClientHandle()->SendInventorySlot(-1, -1, m_DraggingItem);
|
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
|
// Stop all mobs from targeting this player
|
||||||
StopEveryoneFromTargetingMe();
|
StopEveryoneFromTargetingMe();
|
||||||
|
|
||||||
|
// Deal with new world
|
||||||
|
SetWorld(a_World);
|
||||||
|
|
||||||
|
// Set capabilities based on new world
|
||||||
|
SetCapabilities();
|
||||||
|
|
||||||
cClientHandle * ch = this->GetClientHandle();
|
cClientHandle * ch = this->GetClientHandle();
|
||||||
if (ch != nullptr)
|
if (ch != nullptr)
|
||||||
{
|
{
|
||||||
@ -2055,7 +2058,6 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d
|
|||||||
m_ClientHandle->SendRespawn(a_World->GetDimension());
|
m_ClientHandle->SendRespawn(a_World->GetDimension());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update the view distance.
|
// Update the view distance.
|
||||||
ch->SetViewDistance(m_ClientHandle->GetRequestedViewDistance());
|
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
|
// 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();
|
cChunk * ParentChunk = this->GetParentChunk();
|
||||||
|
|
||||||
LOGD("Warping player \"%s\" from world \"%s\" to \"%s\". Source chunk: (%d, %d) ",
|
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;
|
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.
|
// Updates player's capabilities - flying, visibility, etc. from their gamemode.
|
||||||
void SetCapabilities();
|
void SetCapabilities();
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a_Player->GetGameMode() != gmCreative)
|
if (!a_Player->IsGameModeCreative())
|
||||||
{
|
{
|
||||||
// Remove fluid bucket, add empty bucket:
|
// Remove fluid bucket, add empty bucket:
|
||||||
if (!a_Player->GetInventory().RemoveOneEquippedItem())
|
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.WriteVarInt32(static_cast<UInt32>(a_Player.GetClientHandle()->GetPing()));
|
||||||
Pkt.WriteBool(false);
|
Pkt.WriteBool(false);
|
||||||
}
|
}
|
||||||
@ -978,7 +978,7 @@ void cProtocol_1_8_0::SendPlayerListUpdateGameMode(const cPlayer & a_Player)
|
|||||||
Pkt.WriteVarInt32(1);
|
Pkt.WriteVarInt32(1);
|
||||||
Pkt.WriteVarInt32(1);
|
Pkt.WriteVarInt32(1);
|
||||||
Pkt.WriteUUID(a_Player.GetUUID());
|
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.WriteVarInt32(static_cast<UInt32>(a_Player.GetClientHandle()->GetPing()));
|
||||||
Pkt.WriteBool(false);
|
Pkt.WriteBool(false);
|
||||||
}
|
}
|
||||||
@ -1023,7 +1023,7 @@ void cProtocol_1_9_0::SendPlayerListUpdateGameMode(const cPlayer & a_Player)
|
|||||||
Pkt.WriteVarInt32(1);
|
Pkt.WriteVarInt32(1);
|
||||||
Pkt.WriteVarInt32(1);
|
Pkt.WriteVarInt32(1);
|
||||||
Pkt.WriteUUID(a_Player.GetUUID());
|
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 IsGameModeSpectator(void) const { return (m_GameMode == gmSpectator); }
|
||||||
|
|
||||||
bool IsPVPEnabled(void) const { return m_bEnabledPVP; }
|
bool IsPVPEnabled(void) const { return m_bEnabledPVP; }
|
||||||
|
|
||||||
bool IsDeepSnowEnabled(void) const { return m_IsDeepSnowEnabled; }
|
bool IsDeepSnowEnabled(void) const { return m_IsDeepSnowEnabled; }
|
||||||
|
|
||||||
bool ShouldLavaSpawnFire(void) const { return m_ShouldLavaSpawnFire; }
|
bool ShouldLavaSpawnFire(void) const { return m_ShouldLavaSpawnFire; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user