Add server-side functionality for the announcement system: - Add bladw_amenu console command to open admin announcement menu - Add /bannonce and !bannonce chat commands for opening the menu - Implement bladWSendAnnouncement net message handler to broadcast announcements - Validate admin permissions and sanitize announcement content (title max 64 chars, text max 200 chars) - Use default title "Annonce" if not provided
36 lines
1.1 KiB
Lua
36 lines
1.1 KiB
Lua
-- Ouvre le menu admin pour le joueur (réservé aux admins)
|
|
concommand.Add("bladw_amenu", function(ply, cmd)
|
|
if not IsValid(ply) then return end
|
|
|
|
net.Start("bladWOpenAnnouncementMenu")
|
|
net.Send(ply)
|
|
end)
|
|
|
|
-- Commande chat : /bannonce (ou !bannonce) -> ouvre le menu d'annonce
|
|
hook.Add("PlayerSay", "BladW:AnnouncementChatCmd", function(ply, text)
|
|
local cmd = string.lower(string.Trim(text))
|
|
if cmd ~= "/bannonce" and cmd ~= "!bannonce" then return end
|
|
if not IsValid(ply) then return end
|
|
|
|
net.Start("bladWOpenAnnouncementMenu")
|
|
net.Send(ply)
|
|
|
|
return "" -- masque la commande dans le chat
|
|
end)
|
|
|
|
-- Un admin demande l'envoi d'une annonce -> on la diffuse à tout le monde
|
|
net.Receive("bladWSendAnnouncement", function(len, ply)
|
|
if not IsValid(ply) or not ply:IsAdmin() then return end
|
|
|
|
local title = string.sub(net.ReadString(), 1, 64)
|
|
local text = string.sub(net.ReadString(), 1, 200)
|
|
|
|
if text == "" then return end
|
|
if title == "" then title = "Annonce" end
|
|
|
|
net.Start("bladWShowAnnouncement")
|
|
net.WriteString(title)
|
|
net.WriteString(text)
|
|
net.Broadcast()
|
|
end)
|