From a476a2e017a805b99e06fca21e1a97b608b7391e Mon Sep 17 00:00:00 2001 From: nocode Date: Mon, 20 Jul 2026 12:46:46 +0200 Subject: [PATCH] feat(announcement): implement server-side announcement functions 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 --- lua/bladw_announcement/server/sv_function.lua | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/lua/bladw_announcement/server/sv_function.lua b/lua/bladw_announcement/server/sv_function.lua index 5afe3bf..e3b3a99 100644 --- a/lua/bladw_announcement/server/sv_function.lua +++ b/lua/bladw_announcement/server/sv_function.lua @@ -1 +1,35 @@ -print("sv_function.lua") \ No newline at end of file +-- 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)