Skip to content

Commit

Permalink
by default remove all tags from player names, add :RichNick
Browse files Browse the repository at this point in the history
  • Loading branch information
Earu committed Jun 30, 2022
1 parent af7b328 commit e80bf9f
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 166 deletions.
2 changes: 1 addition & 1 deletion lua/easychat/chathud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ function chathud:AddText(...)
if IsValid(lp) and lp == arg and EC_USE_ME:GetBool() then
self:AppendNick("me")
else
self:AppendNick(arg:Nick())
self:AppendNick(arg:RichNick())
end
end

Expand Down
4 changes: 2 additions & 2 deletions lua/easychat/client/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ local function create_default_settings()
input_str = ("%s %s"):format(input_str, emote_tag)
end

input_str = ("%s %s<stop>: Hello!"):format(input_str, LocalPlayer():Nick())
input_str = ("%s %s<stop>: Hello!"):format(input_str, LocalPlayer():RichNick())
mk = ec_markup.Parse(input_str)
end

Expand Down Expand Up @@ -1029,7 +1029,7 @@ local function create_default_settings()
input_str = ("%s %s"):format(input_str, emote_display)
end

input_str = ("%s %s"):format(input_str, LocalPlayer():Nick())
input_str = ("%s %s"):format(input_str, LocalPlayer():RichNick())
local mk = ec_markup.Parse(input_str)
local mk_w, mk_h = mk:GetWide(), mk:GetTall()

Expand Down
73 changes: 48 additions & 25 deletions lua/easychat/easychat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,51 @@ function EasyChat.IsStringEmpty(str, is_nick)
return false
end

local function get_unknown_name(ply)
-- NULL is "pure", its not the same as a player becoming NULL
-- therefore this will only work if the ply is the server console
if ply == NULL then return "[SERVER]" end

-- this is always going to be a player thats not been networked yet or some weird
-- stuff that gmod is responsible for
return "[UNKNOWN]"
end

EasyChat.NativeNick = EasyChat.NativeNick or PLY.Nick
function EasyChat.GetProperNick(ply)
if not IsValid(ply) then return get_unknown_name(ply) end

local ply_nick = EasyChat.NativeNick(ply)
if not ec_markup then return ply_nick end
local mk = ec_markup.CachePlayer("EasyChat", ply, function()
return ec_markup.Parse(ply_nick, nil, true)
end)

return mk and mk:GetText() or ply_nick
end

function PLY:Nick()
return EasyChat.GetProperNick(self)
end
PLY.Name = PLY.Nick
PLY.GetName = PLY.Nick
PLY.GetNick = PLY.Nick

PLY.RealNick = PLY.EngineNick
PLY.RealName = PLY.EngineNick
PLY.GetRealName = PLY.EngineNick

function PLY:RichNick()
return EasyChat.NativeNick(self)
end
PLY.RichName = PLY.RichNick
PLY.GetRichNick = PLY.RichNick
PLY.GetRichName = PLY.RichNick
PLY.GetNameDecorated = PLY.RichNick
PLY.GetNickDecorated = PLY.RichNick
PLY.NickDecorated = PLY.RichNick
PLY.NameDecorated = PLY.RichNick

local load_modules, get_modules = include("easychat/autoloader.lua")
EasyChat.GetModules = get_modules -- maybe useful for modules?

Expand Down Expand Up @@ -1119,28 +1164,6 @@ if CLIENT then
return math.fmod(counter, 4294967291) -- 2^32 - 5: Prime (and different from the prime in the loop)
end

local function get_unknown_name(ply)
-- NULL is "pure", its not the same as a player becoming NULL
-- therefore this will only work if the ply is the server console
if ply == NULL then return "[SERVER]" end

-- this is always going to be a player thats not been networked yet or some weird
-- stuff that gmod is responsible for
return "[UNKNOWN]"
end

function EasyChat.GetProperNick(ply)
if not IsValid(ply) then return get_unknown_name(ply) end

local ply_nick = ply:Nick()
if not ec_markup then return ply_nick end
local mk = ec_markup.CachePlayer("EasyChat", ply, function()
return ec_markup.Parse(ply_nick, nil, true)
end)

return mk and mk:GetText() or ply_nick
end

function EasyChat.PastelizeNick(nick)
local hue = string_hash(nick)
local saturation, value = hue % 3 == 0, hue % 127 == 0
Expand Down Expand Up @@ -1495,7 +1518,7 @@ if CLIENT then
if empty_nick then
append_text(richtext, "[NO NAME]")
else
local tags_data = extract_tags_data(arg:Nick(), true)
local tags_data = extract_tags_data(arg:RichNick(), true)
for _, tag_data in ipairs(tags_data) do
if is_color(tag_data) then
richtext:InsertColorChange(tag_data.r, tag_data.g, tag_data.b, 255)
Expand Down Expand Up @@ -1857,7 +1880,7 @@ if CLIENT then
table.insert(data, UNKNOWN_COLOR)
table.insert(data, "[NO NAME]")
else
local nick = EasyChat.Config.AllowTagsInNames and ply:Nick() or stripped_ply_nick
local nick = EasyChat.Config.AllowTagsInNames and ply:RichNick() or stripped_ply_nick
local nick_data = global_append_nick(nick)
table.Add(data, nick_data)
end
Expand Down Expand Up @@ -2466,7 +2489,7 @@ if CLIENT then
end
end

local mk = ec_markup.Parse(ply:Nick(), nil, true)
local mk = ec_markup.Parse(ply:RichNick(), nil, true)
info_panel.PaintOver = function(_, w, h)
surface.SetDrawColor(0, 0, 0, 200)
surface.DrawOutlinedRect(0, 0, w, h)
Expand Down
2 changes: 1 addition & 1 deletion lua/easychat/markup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function ec_markup.CachePlayer(id, ply, callback)
sub_cache = player_cache[id]
end

local nick, team_color = ply:Nick(), team.GetColor(ply:Team())
local nick, team_color = EasyChat.NativeNick(ply), team.GetColor(ply:Team())
local cache = sub_cache[ply]
if cache and cache.Nick == nick and cache.TeamColor == team_color then
return cache.Markup
Expand Down
4 changes: 2 additions & 2 deletions lua/easychat/modules/admin_tab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ if CLIENT then
for _, ply in ipairs(player.GetAll()) do
if ply:IsAdmin() then
local mk = ec_markup.CachePlayer("AdminTab", ply, function()
return ec_markup.AdvancedParse(ply:Nick(), {
return ec_markup.AdvancedParse(ply:RichNick(), {
default_font = "EasyChatFont",
default_color = team.GetColor(ply:Team()),
nick = true,
Expand Down Expand Up @@ -100,7 +100,7 @@ if CLIENT then
for _, ply in ipairs(player.GetAll()) do
if ply:IsAdmin() then
local mk = ec_markup.CachePlayer("AdminTab", ply, function()
return ec_markup.AdvancedParse(ply:Nick(), {
return ec_markup.AdvancedParse(ply:RichNick(), {
default_font = "EasyChatFont",
default_color = team.GetColor(ply:Team()),
nick = true,
Expand Down
2 changes: 1 addition & 1 deletion lua/easychat/modules/client/local_ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function panel:Paint(w, h)
self:SetTall(5 + (20 * (i + 1)))

ec_markup.CachePlayer("LocalUI", ply, function()
return ec_markup.AdvancedParse(ply:Nick(), {
return ec_markup.AdvancedParse(ply:RichNick(), {
nick = true,
default_font = "EasyChatFont",
default_color = team.GetColor(ply:Team()),
Expand Down
125 changes: 0 additions & 125 deletions lua/easychat/modules/client/pac_ease_of_use.lua

This file was deleted.

4 changes: 2 additions & 2 deletions lua/easychat/modules/client/voice_hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ end
function PANEL:Setup(ply)
self.ply = ply

self.Markup = ec_markup.Parse(ply:Nick(), nil, true)
self.Markup = ec_markup.Parse(ply:RichNick(), nil, true)
self.LabelName:SetText("")

self.Avatar:SetPlayer(ply, 64)
Expand Down Expand Up @@ -125,7 +125,7 @@ end

function PANEL:Think()
if IsValid(self.ply) and not self.Markup then
self.LabelName:SetText(self.ply:Nick())
self.LabelName:SetText(self.ply:RichNick())
end

if self.RemoveTime and CurTime() >= self.RemoveTime then
Expand Down
6 changes: 3 additions & 3 deletions lua/easychat/modules/dm_tab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ if CLIENT then

self.DMList:Clear()
for _, chat in pairs(self.Chats) do
local line = self.DMList:AddLine(chat.Player:Nick())
local line = self.DMList:AddLine(chat.Player:RichNick())
chat.Line = line
line.Player = chat.Player
end
Expand Down Expand Up @@ -220,9 +220,9 @@ if CLIENT then
if not IsValid(chat.Player) then return end

if chat.NewMessages > 0 then
line:SetColumnText(1, chat.Player:Nick() .. " (" .. chat.NewMessages .. ")")
line:SetColumnText(1, chat.Player:RichNick() .. " (" .. chat.NewMessages .. ")")
else
line:SetColumnText(1, chat.Player:Nick())
line:SetColumnText(1, chat.Player:RichNick())
end
end
end,
Expand Down
2 changes: 1 addition & 1 deletion lua/easychat/modules/join_leave.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if SERVER then

net.Start(NET_SPAWN_LEAVE)
net.WriteBool(true)
net.WriteString(ply:Nick())
net.WriteString(ply:RichNick())
net.WriteInt(ply:Team(), 32)
net.WriteString(ply:SteamID())

Expand Down
4 changes: 2 additions & 2 deletions lua/easychat/networking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ if SERVER then
table.insert(print_args, "*DEAD* ")
end

local stripped_ply_nick = ply:Nick():gsub("<.->", "")
local stripped_ply_nick = ply:Nick()
if #stripped_ply_nick > 20 then
stripped_ply_nick = stripped_ply_nick:sub(1, 20) .. "..."
end
Expand Down Expand Up @@ -123,7 +123,7 @@ if SERVER then
local is_dead = not ply:Alive()
net.Start(NET_BROADCAST_MSG)
net.WriteUInt(ply:UserID(), 16)
net.WriteString(ply:Nick())
net.WriteString(ply:RichNick())
net.WriteString(msg)
net.WriteBool(is_dead)
net.WriteBool(is_team)
Expand Down
2 changes: 1 addition & 1 deletion lua/easychat/server_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ if SERVER then
local name = net.ReadString()
if not IsValid(target_ply) then return end

EasyChat.SafeHookRun("ECPlayerNameChange", ply, target_ply, target_ply:Nick(), name)
EasyChat.SafeHookRun("ECPlayerNameChange", ply, target_ply, target_ply:RichNick(), name)
end)

restricted_receive(NET_MODULE_IGNORE_LIST, function(_, ply)
Expand Down

0 comments on commit e80bf9f

Please sign in to comment.