diff --git a/lua/entities/gmod_wire_egp/lib/egplib/materials.lua b/lua/entities/gmod_wire_egp/lib/egplib/materials.lua index 78158986ed..d8b79923ae 100644 --- a/lua/entities/gmod_wire_egp/lib/egplib/materials.lua +++ b/lua/entities/gmod_wire_egp/lib/egplib/materials.lua @@ -3,10 +3,6 @@ -------------------------------------------------------- local EGP = EGP -if SERVER then - EGP.PlayerFontCount = EGP.PlayerFontCount or {} -end - if CLIENT then -- Valid fonts table EGP.ValidFonts_Lookup = EGP.ValidFonts_Lookup or {} diff --git a/lua/entities/gmod_wire_expression2/core/egpfunctions.lua b/lua/entities/gmod_wire_expression2/core/egpfunctions.lua index 4d3ebb59f0..d466df3350 100644 --- a/lua/entities/gmod_wire_expression2/core/egpfunctions.lua +++ b/lua/entities/gmod_wire_expression2/core/egpfunctions.lua @@ -255,20 +255,7 @@ end -- Font ---------------------------- local function canCreateFont( ply, font, size ) - size = size or 18 - - EGP.PlayerFontCount[ply:SteamID64()] = EGP.PlayerFontCount[ply:SteamID64()] or { fonts = {}, count = 0 } - local fontTable = EGP.PlayerFontCount[ply:SteamID64()] - - if fontTable.count >= 50 then return false end - - local fontName = font .. size - if fontTable.fonts[fontName] then return true end - - fontTable.count = fontTable.count + 1 - fontTable.fonts[fontName] = true - - return true + return WireLib.CanFont(font .. (size or 18), ply) end e2function void wirelink:egpFont( number index, string font ) diff --git a/lua/entities/gmod_wire_textscreen.lua b/lua/entities/gmod_wire_textscreen.lua index ae410711bc..779eff725d 100644 --- a/lua/entities/gmod_wire_textscreen.lua +++ b/lua/entities/gmod_wire_textscreen.lua @@ -275,9 +275,18 @@ end function ENT:SendConfig(ply) self.doSendConfig = false + + local font = string.sub(self.tfont, 0, 31) + local size = self.chrPerLine + + if not WireLib.CheckFont(font .. math.floor(760 / size), self:GetPlayer()) then + font = "Arial" + size = 10 + end + WireLib.netStart(self) net.WriteBit(true) -- Sending Config - net.WriteUInt(self.chrPerLine, 4) + net.WriteUInt(size, 4) net.WriteUInt(self.textJust, 2) net.WriteUInt(self.valign, 2) @@ -288,7 +297,7 @@ function ENT:SendConfig(ply) net.WriteUInt(self.bgcolor.r, 8) net.WriteUInt(self.bgcolor.g, 8) net.WriteUInt(self.bgcolor.b, 8) - net.WriteString(string.sub(self.tfont,0,31)) + net.WriteString(font) WireLib.netEnd(ply) end diff --git a/lua/wire/server/wirelib.lua b/lua/wire/server/wirelib.lua index bc54fb0b12..b3c09aa3f3 100644 --- a/lua/wire/server/wirelib.lua +++ b/lua/wire/server/wirelib.lua @@ -1641,6 +1641,27 @@ function WireLib.SoundExists(path, ply) return path end +local uniqueFontsTbl = setmetatable({}, {__index=function(t,k) local r={[1]=0} t[k]=r return r end}) +local maxUniqueFonts = CreateConVar("wire_fonts_unique_max", "50", FCVAR_ARCHIVE, "The maximum number of fonts a player is allowed to create", 0) + +function WireLib.CheckFont(font, ply) + if ply then + -- A player can only create a certain number of fonts + local playerFonts = uniqueFontsTbl[ply:SteamID()] + + if not playerFonts[font] then + if playerFonts[1] >= maxUniqueFonts:GetInt() then + return + end + + playerFonts[font] = true + playerFonts[1] = playerFonts[1] + 1 + end + end + + return font +end + -- Notify -- local triv_start = WireLib.Net.Trivial.Start