Skip to content

Commit

Permalink
* Initial mute player feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jprzimba committed Jan 22, 2025
1 parent f78f884 commit bd17559
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/libs/systems/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Features = {
ChainSystem = "chainSystem",
EmoteSpells = "emoteSpells",
SpellNameInsteadOfWords = "spellNameInsteadOfWords",
MutePlayer = "mutePlayer",
}

local function validateFeature(feature)
Expand Down
62 changes: 62 additions & 0 deletions data/scripts/talkactions/god/mute.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
local mute = TalkAction("/mute")

function mute.onSay(player, words, param)
-- create log
logCommand(player, words, param)

if param == "" then
player:sendCancelMessage("You must specify a player. Usage: /mute playerName.")
return true
end

local split = param:split(",")
local targetName = split[1]:trim()
local target = Player(targetName)

if not target then
player:sendCancelMessage("A player with that name is not online.")
return true
end

if target:getGroup():getId() >= GROUP_TYPE_GAMEMASTER then
player:sendCancelMessage("You cannot mute this character.")
return true
end

target:setFeature(Features.MutePlayer, 1)
player:popupFYI(target:getName() .. " has been muted.")
return true
end

mute:separator(" ")
mute:groupType("god")
mute:register()

-- Unmute player
local unmute = TalkAction("/unmute")

function unmute.onSay(player, words, param)
-- create log
logCommand(player, words, param)

if param == "" then
player:sendCancelMessage("You must specify a player. Usage: /unmute playerName.")
return true
end

local targetName = param:trim()
local target = Player(targetName)

if not target then
player:sendCancelMessage("A player with that name is not online.")
return true
end

target:setFeature(Features.MutePlayer, 0)
player:popupFYI(target:getName() .. " has been unmuted.")
return true
end

unmute:separator(" ")
unmute:groupType("god")
unmute:register()
14 changes: 14 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5242,6 +5242,20 @@ bool Player::checkSpellNameInsteadOfWords() const {
return false;
}

bool Player::checkMute() const {
auto featureKV = kv()->scoped("features")->get("mutePlayer");
if (featureKV.has_value()) {
auto value = featureKV->getNumber();
if (value == 1) {
return true;
} else if (value == 0) {
return false;
}
}

return false;
}

QuickLootFilter_t Player::getQuickLootFilter() const {
return quickLootFilter;
}
Expand Down
1 change: 1 addition & 0 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,7 @@ class Player final : public Creature, public Cylinder, public Bankable {
bool checkChainSystem() const;
bool checkEmoteSpells() const;
bool checkSpellNameInsteadOfWords() const;
bool checkMute() const;

QuickLootFilter_t getQuickLootFilter() const;

Expand Down
7 changes: 7 additions & 0 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6223,6 +6223,13 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, c
return;
}

if (player->checkMute()) {
std::ostringstream ss;
ss << "You are unable to talk.";
player->sendTextMessage(MESSAGE_FAILURE, ss.str());
return;
}

uint32_t muteTime = player->isMuted();
if (muteTime > 0) {
std::ostringstream ss;
Expand Down

0 comments on commit bd17559

Please sign in to comment.