Add player permission level (#5358)

This commit is contained in:
Simon Pribylski 2022-01-24 21:24:55 +01:00 committed by GitHub
parent 5614d267f7
commit f4c0429996
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 143 additions and 71 deletions

View File

@ -9774,7 +9774,7 @@ a_Player:OpenWindow(Window);
Type = "Vector3i", Type = "Vector3i",
}, },
}, },
Notes = "Function to find suitable teleport destination in or below box. Returns true and places result in Destination if found, otherwise returns false. Details at: https://minecraft.fandom.com/wiki/Enderman#Teleportation.", Notes = "Function to find suitable teleport destination in or below box. Returns true and places result in Destination if found, otherwise returns false. Details at: {{https://minecraft.fandom.com/wiki/Enderman#Teleportation}}.",
}, },
{ {
Params = Params =
@ -9800,7 +9800,7 @@ a_Player:OpenWindow(Window);
Type = "cBoundingBox", Type = "cBoundingBox",
}, },
}, },
Notes = "Function to find suitable teleport destination in or below box. Returns true and places result in Destination if found, otherwise returns false. Details at: https://minecraft.fandom.com/wiki/Enderman#Teleportation.", Notes = "Function to find suitable teleport destination in or below box. Returns true and places result in Destination if found, otherwise returns false. Details at: {{https://minecraft.fandom.com/wiki/Enderman#Teleportation}}.",
}, },
{ {
Params = Params =
@ -9826,7 +9826,7 @@ a_Player:OpenWindow(Window);
Type = "number", Type = "number",
}, },
}, },
Notes = "Function to find suitable teleport destination in or below box. Returns true and places result in Destination if found, otherwise returns false. Details at: https://minecraft.fandom.com/wiki/Enderman#Teleportation.", Notes = "Function to find suitable teleport destination in or below box. Returns true and places result in Destination if found, otherwise returns false. Details at: {{https://minecraft.fandom.com/wiki/Enderman#Teleportation}}.",
}, },
}, },
HasEntityEffect = HasEntityEffect =

View File

@ -459,6 +459,10 @@ void cClientHandle::FinishAuthenticate()
// Return a server login packet: // Return a server login packet:
m_Protocol->SendLogin(*m_Player, *World); m_Protocol->SendLogin(*m_Player, *World);
// Send the player's permission level.
// The key effect is to allow 1.9+ clients to open the command block UI.
SendPlayerPermissionLevel();
if (m_Player->GetKnownRecipes().empty()) if (m_Player->GetKnownRecipes().empty())
{ {
SendInitRecipes(0); SendInitRecipes(0);
@ -1042,7 +1046,7 @@ void cClientHandle::HandleCommandBlockBlockChange(int a_BlockX, int a_BlockY, in
return; return;
} }
if ((m_Player == nullptr) || !m_Player->HasPermission("comandblock.set")) if ((m_Player == nullptr) || !m_Player->HasPermission("cuberite.commandblock.set"))
{ {
SendChat("You cannot edit command blocks on this server", mtFailure); SendChat("You cannot edit command blocks on this server", mtFailure);
return; return;
@ -1589,7 +1593,7 @@ void cClientHandle::HandleChat(const AString & a_Message)
Msg.AddTextPart(m_Player->GetName(), Color); Msg.AddTextPart(m_Player->GetName(), Color);
Msg.ParseText(m_Player->GetSuffix()); Msg.ParseText(m_Player->GetSuffix());
Msg.AddTextPart("> "); Msg.AddTextPart("> ");
if (m_Player->HasPermission("chat.format")) if (m_Player->HasPermission("cuberite.chat.format"))
{ {
Msg.ParseText(Message); Msg.ParseText(Message);
} }
@ -2880,6 +2884,15 @@ void cClientHandle::SendPlayerMoveLook(void)
void cClientHandle::SendPlayerPermissionLevel()
{
m_Protocol->SendPlayerPermissionLevel();
}
void cClientHandle::SendPlayerPosition(void) void cClientHandle::SendPlayerPosition(void)
{ {
m_Protocol->SendPlayerPosition(); m_Protocol->SendPlayerPosition();

View File

@ -205,6 +205,7 @@ public: // tolua_export
void SendPlayerListUpdateGameMode (const cPlayer & a_Player); void SendPlayerListUpdateGameMode (const cPlayer & a_Player);
void SendPlayerListUpdatePing (); void SendPlayerListUpdatePing ();
void SendPlayerMoveLook (void); void SendPlayerMoveLook (void);
void SendPlayerPermissionLevel (void);
void SendPlayerPosition (void); void SendPlayerPosition (void);
void SendPlayerSpawn (const cPlayer & a_Player); void SendPlayerSpawn (const cPlayer & a_Player);
void SendPluginMessage (const AString & a_Channel, std::string_view a_Message); // Exported in ManualBindings.cpp void SendPluginMessage (const AString & a_Channel, std::string_view a_Message); // Exported in ManualBindings.cpp

View File

@ -503,11 +503,6 @@ enum class EntityAnimation
PlayerMainHandSwings, PlayerMainHandSwings,
// PlayerReducedDebugScreenDisables, // PlayerReducedDebugScreenDisables,
// PlayerReducedDebugScreenEnables, // PlayerReducedDebugScreenEnables,
// PlayerSetsOperatorLevelFour,
// PlayerSetsOperatorLevelOne,
// PlayerSetsOperatorLevelThree,
// PlayerSetsOperatorLevelTwo,
// PlayerSetsOperatorLevelZero,
PlayerOffHandSwings, PlayerOffHandSwings,
RabbitJumps, RabbitJumps,
RavagerAttacks, RavagerAttacks,

View File

@ -1567,7 +1567,7 @@ void cPlayer::PermuteEnchantmentSeed()
bool cPlayer::HasPermission(const AString & a_Permission) bool cPlayer::HasPermission(const AString & a_Permission) const
{ {
if (a_Permission.empty()) if (a_Permission.empty())
{ {
@ -1786,7 +1786,7 @@ void cPlayer::TossPickup(const cItem & a_Item)
void cPlayer::LoadFromDisk() void cPlayer::LoadFromDisk()
{ {
LoadRank(); RefreshRank();
Json::Value Root; Json::Value Root;
const auto & UUID = GetUUID(); const auto & UUID = GetUUID();
@ -2295,39 +2295,11 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos, bool a_PreviousIs
void cPlayer::LoadRank(void) void cPlayer::LoadRank(void)
{ {
const auto & UUID = GetUUID(); // Update our permissions:
cRankManager * RankMgr = cRoot::Get()->GetRankManager(); RefreshRank();
// Load the values from cRankManager: // Send a permission level update:
m_Rank = RankMgr->GetPlayerRankName(UUID); m_ClientHandle->SendPlayerPermissionLevel();
if (m_Rank.empty())
{
m_Rank = RankMgr->GetDefaultRank();
}
else
{
// Update the name:
RankMgr->UpdatePlayerName(UUID, GetName());
}
m_Permissions = RankMgr->GetPlayerPermissions(UUID);
m_Restrictions = RankMgr->GetPlayerRestrictions(UUID);
RankMgr->GetRankVisuals(m_Rank, m_MsgPrefix, m_MsgSuffix, m_MsgNameColorCode);
// Break up the individual permissions on each dot, into m_SplitPermissions:
m_SplitPermissions.clear();
m_SplitPermissions.reserve(m_Permissions.size());
for (auto & Permission: m_Permissions)
{
m_SplitPermissions.push_back(StringSplit(Permission, "."));
} // for Permission - m_Permissions[]
// Break up the individual restrictions on each dot, into m_SplitRestrictions:
m_SplitRestrictions.clear();
m_SplitRestrictions.reserve(m_Restrictions.size());
for (auto & Restriction: m_Restrictions)
{
m_SplitRestrictions.push_back(StringSplit(Restriction, "."));
} // for itr - m_Restrictions[]
} }
@ -2808,6 +2780,47 @@ void cPlayer::TickFreezeCode()
void cPlayer::RefreshRank()
{
const auto & UUID = GetUUID();
cRankManager * RankMgr = cRoot::Get()->GetRankManager();
// Load the values from cRankManager:
m_Rank = RankMgr->GetPlayerRankName(UUID);
if (m_Rank.empty())
{
m_Rank = RankMgr->GetDefaultRank();
}
else
{
// Update the name:
RankMgr->UpdatePlayerName(UUID, GetName());
}
m_Permissions = RankMgr->GetPlayerPermissions(UUID);
m_Restrictions = RankMgr->GetPlayerRestrictions(UUID);
RankMgr->GetRankVisuals(m_Rank, m_MsgPrefix, m_MsgSuffix, m_MsgNameColorCode);
// Break up the individual permissions on each dot, into m_SplitPermissions:
m_SplitPermissions.clear();
m_SplitPermissions.reserve(m_Permissions.size());
for (auto & Permission : m_Permissions)
{
m_SplitPermissions.push_back(StringSplit(Permission, "."));
}
// Break up the individual restrictions on each dot, into m_SplitRestrictions:
m_SplitRestrictions.clear();
m_SplitRestrictions.reserve(m_Restrictions.size());
for (auto & Restriction : m_Restrictions)
{
m_SplitRestrictions.push_back(StringSplit(Restriction, "."));
}
}
void cPlayer::ApplyArmorDamage(int a_DamageBlocked) void cPlayer::ApplyArmorDamage(int a_DamageBlocked)
{ {
short ArmorDamage = static_cast<short>(std::max(a_DamageBlocked / 4, 1)); short ArmorDamage = static_cast<short>(std::max(a_DamageBlocked / 4, 1));

View File

@ -301,7 +301,7 @@ public:
// tolua_end // tolua_end
bool HasPermission(const AString & a_Permission); // tolua_export bool HasPermission(const AString & a_Permission) const; // tolua_export
/** Returns true iff a_Permission matches the a_Template. /** Returns true iff a_Permission matches the a_Template.
A match is defined by either being exactly the same, or each sub-item matches until there's a wildcard in a_Template. A match is defined by either being exactly the same, or each sub-item matches until there's a wildcard in a_Template.
@ -545,8 +545,7 @@ public:
/** Returns wheter the player can fly or not. */ /** Returns wheter the player can fly or not. */
virtual bool CanFly(void) const { return m_IsFlightCapable; } virtual bool CanFly(void) const { return m_IsFlightCapable; }
/** (Re)loads the rank and permissions from the cRankManager. /** (Re)loads the rank and permissions from the cRankManager and sends a permission level update to the client. */
Loads the m_Rank, m_Permissions, m_MsgPrefix, m_MsgSuffix and m_MsgNameColorCode members. */
void LoadRank(void); void LoadRank(void);
/** Sends the block in the specified range around the specified coord to the client /** Sends the block in the specified range around the specified coord to the client
@ -626,7 +625,6 @@ private:
This is used mainly by the HasPermission() function to optimize the lookup. */ This is used mainly by the HasPermission() function to optimize the lookup. */
AStringVectorVector m_SplitRestrictions; AStringVectorVector m_SplitRestrictions;
// Message visuals: // Message visuals:
AString m_MsgPrefix, m_MsgSuffix; AString m_MsgPrefix, m_MsgSuffix;
AString m_MsgNameColorCode; AString m_MsgNameColorCode;
@ -787,6 +785,10 @@ private:
void TickFreezeCode(); void TickFreezeCode();
/** (Re)loads the rank and permissions from the cRankManager.
Loads the m_Rank, m_Permissions, m_MsgPrefix, m_MsgSuffix and m_MsgNameColorCode members. */
void RefreshRank();
// cEntity overrides: // cEntity overrides:
virtual void ApplyArmorDamage(int DamageBlocked) override; virtual void ApplyArmorDamage(int DamageBlocked) override;
virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = nullptr) override; virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = nullptr) override;

View File

@ -408,6 +408,7 @@ public:
virtual void SendPlayerListUpdatePing () = 0; virtual void SendPlayerListUpdatePing () = 0;
virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName) = 0; virtual void SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName) = 0;
virtual void SendPlayerMoveLook (void) = 0; virtual void SendPlayerMoveLook (void) = 0;
virtual void SendPlayerPermissionLevel (void) = 0;
virtual void SendPlayerPosition (void) = 0; virtual void SendPlayerPosition (void) = 0;
virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0; virtual void SendPlayerSpawn (const cPlayer & a_Player) = 0;
virtual void SendPluginMessage (const AString & a_Channel, ContiguousByteBufferView a_Message) = 0; virtual void SendPluginMessage (const AString & a_Channel, ContiguousByteBufferView a_Message) = 0;

View File

@ -1184,6 +1184,15 @@ void cProtocol_1_8_0::SendPlayerMoveLook(void)
void cProtocol_1_8_0::SendPlayerPermissionLevel()
{
// 1.8 has no concept of a permission level.
}
void cProtocol_1_8_0::SendPlayerPosition(void) void cProtocol_1_8_0::SendPlayerPosition(void)
{ {
// There is no dedicated packet for this, send the whole thing: // There is no dedicated packet for this, send the whole thing:

View File

@ -94,6 +94,7 @@ public:
virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) override; virtual void SendPlayerListUpdateGameMode (const cPlayer & a_Player) override;
virtual void SendPlayerListUpdatePing () override; virtual void SendPlayerListUpdatePing () override;
virtual void SendPlayerMoveLook (void) override; virtual void SendPlayerMoveLook (void) override;
virtual void SendPlayerPermissionLevel (void) override;
virtual void SendPlayerPosition (void) override; virtual void SendPlayerPosition (void) override;
virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
virtual void SendPluginMessage (const AString & a_Channel, ContiguousByteBufferView a_Message) override; virtual void SendPluginMessage (const AString & a_Channel, ContiguousByteBufferView a_Message) override;

View File

@ -501,6 +501,42 @@ void cProtocol_1_9_0::SendPlayerMoveLook(void)
void cProtocol_1_9_0::SendPlayerPermissionLevel()
{
const cPlayer & Player = *m_Client->GetPlayer();
cPacketizer Pkt(*this, pktEntityStatus);
Pkt.WriteBEUInt32(Player.GetUniqueID());
Pkt.WriteBEInt8([&Player]() -> signed char
{
if (Player.HasPermission("core.stop") || Player.HasPermission("core.reload") || Player.HasPermission("core.save-all"))
{
return 28;
}
if (Player.HasPermission("core.ban") || Player.HasPermission("core.deop") || Player.HasPermission("core.kick") || Player.HasPermission("core.op"))
{
return 27;
}
if (Player.HasPermission("cuberite.comandblock.set") || Player.HasPermission("core.clear") || Player.HasPermission("core.difficulty") || Player.HasPermission("core.effect") || Player.HasPermission("core.gamemode") || Player.HasPermission("core.tp") || Player.HasPermission("core.give"))
{
return 26;
}
if (Player.HasPermission("core.spawnprotect.bypass"))
{
return 25;
}
return 24;
}());
}
void cProtocol_1_9_0::SendPlayerSpawn(const cPlayer & a_Player) void cProtocol_1_9_0::SendPlayerSpawn(const cPlayer & a_Player)
{ {
// Called to spawn another player for the client // Called to spawn another player for the client

View File

@ -35,29 +35,30 @@ public:
cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_ServerAddress, State a_State); cProtocol_1_9_0(cClientHandle * a_Client, const AString & a_ServerAddress, State a_State);
virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity & a_Vehicle) override; virtual void SendAttachEntity (const cEntity & a_Entity, const cEntity & a_Vehicle) override;
virtual void SendBossBarAdd (UInt32 a_UniqueID, const cCompositeChat & a_Title, float a_FractionFilled, BossBarColor a_Color, BossBarDivisionType a_DivisionType, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog) override; virtual void SendBossBarAdd (UInt32 a_UniqueID, const cCompositeChat & a_Title, float a_FractionFilled, BossBarColor a_Color, BossBarDivisionType a_DivisionType, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog) override;
virtual void SendBossBarRemove (UInt32 a_UniqueID) override; virtual void SendBossBarRemove (UInt32 a_UniqueID) override;
virtual void SendBossBarUpdateFlags (UInt32 a_UniqueID, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog) override; virtual void SendBossBarUpdateFlags (UInt32 a_UniqueID, bool a_DarkenSky, bool a_PlayEndMusic, bool a_CreateFog) override;
virtual void SendBossBarUpdateHealth(UInt32 a_UniqueID, float a_FractionFilled) override; virtual void SendBossBarUpdateHealth (UInt32 a_UniqueID, float a_FractionFilled) override;
virtual void SendBossBarUpdateStyle (UInt32 a_UniqueID, BossBarColor a_Color, BossBarDivisionType a_DivisionType) override; virtual void SendBossBarUpdateStyle (UInt32 a_UniqueID, BossBarColor a_Color, BossBarDivisionType a_DivisionType) override;
virtual void SendBossBarUpdateTitle (UInt32 a_UniqueID, const cCompositeChat & a_Title) override; virtual void SendBossBarUpdateTitle (UInt32 a_UniqueID, const cCompositeChat & a_Title) override;
virtual void SendDetachEntity (const cEntity & a_Entity, const cEntity & a_PreviousVehicle) override; virtual void SendDetachEntity (const cEntity & a_Entity, const cEntity & a_PreviousVehicle) override;
virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override; virtual void SendEntityEquipment (const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) override;
virtual void SendEntityMetadata (const cEntity & a_Entity) override; virtual void SendEntityMetadata (const cEntity & a_Entity) override;
virtual void SendEntityPosition (const cEntity & a_Entity) override; virtual void SendEntityPosition (const cEntity & a_Entity) override;
virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override; virtual void SendExperienceOrb (const cExpOrb & a_ExpOrb) override;
virtual void SendKeepAlive (UInt32 a_PingID) override; virtual void SendKeepAlive (UInt32 a_PingID) override;
virtual void SendLeashEntity (const cEntity & a_Entity, const cEntity & a_EntityLeashedTo) override; virtual void SendLeashEntity (const cEntity & a_Entity, const cEntity & a_EntityLeashedTo) override;
virtual void SendMapData (const cMap & a_Map, int a_DataStartX, int a_DataStartY) override; virtual void SendMapData (const cMap & a_Map, int a_DataStartX, int a_DataStartY) override;
virtual void SendPaintingSpawn (const cPainting & a_Painting) override; virtual void SendPaintingSpawn (const cPainting & a_Painting) override;
virtual void SendPlayerMoveLook (void) override; virtual void SendPlayerMoveLook (void) override;
virtual void SendPlayerSpawn (const cPlayer & a_Player) override; virtual void SendPlayerPermissionLevel() override;
virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override; virtual void SendPlayerSpawn (const cPlayer & a_Player) override;
virtual void SendSpawnMob (const cMonster & a_Mob) override; virtual void SendSoundEffect (const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) override;
virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override; virtual void SendSpawnMob (const cMonster & a_Mob) override;
virtual void SendUnleashEntity (const cEntity & a_Entity) override; virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override; virtual void SendUnleashEntity (const cEntity & a_Entity) override;
virtual void SendUnloadChunk (int a_ChunkX, int a_ChunkZ) override;
protected: protected: