Skip to content
RustPluginGenerator

OnServerMessage

OnServerMessage is called every time ConVar.Chat.Broadcast is invoked, which covers server-side chat broadcasts such as join/leave notices, save and restart warnings, and plugin calls to Server.Broadcast.

Signature
object OnServerMessage(string message, string username, string color, ulong userid)

Parameters

Hook parameters
ParameterTypeDescription
messagestringThe chat text being broadcast, usually the server-generated part of the line, e.g. 'Player joined' or a save notice.
usernamestringThe sender name shown before the message, defaulting to 'SERVER'. It is escaped before being sent to clients.
colorstringHex color tag used for the username, e.g. '#eee'. Applied to the escaped username, not to the message text.
useridulongSteam ID of the user the message is attributed to; 0 for messages that come from the server itself.

Return value

Returning null lets the original broadcast run unchanged. Returning any non-null value cancels the broadcast entirely, so nothing is sent to clients, and the game skips the rest of the method, including writing the ChatEntry to the chat history record.

How it works

The hook fires inside ConVar.Chat.Broadcast, the method Rust uses for messages that are not real player chat. That includes connection and disconnect notices, automatic save and shutdown warnings, and anything a plugin sends through Server.Broadcast, PrintToChat or the same underlying call. Player-typed chat goes through the player chat path instead, so it does not appear here; use OnPlayerChat for that.

message is the payload text, username is the display name placed before it (default SERVER), color is the hex color applied to the username tag and userid is the Steam ID the line is attributed to or 0 for server-originated text. To only act on joins, save warnings or a particular color, filter on these strings rather than assuming every call is a player event.

Declaring the hooks with the exact parameter types is required here: Oxide only calls your method when each argument matches the declared type, so widen or keep the types as given (string, string, string, ulong). Because this fires for every broadcast, keep the body cheap and avoid Puts in it.

Example plugin: Mute server save and shutdown warnings in chat

ServerMessageFilter.cs
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Core;

namespace Oxide.Plugins
{
    [Info("Server Message Filter", "RustPluginGenerator", "1.0.0")]
    [Description("Suppresses configured automatic server chat broadcasts such as save warnings.")]
    public class ServerMessageFilter : RustPlugin
    {
        private const string PermAdmin = "servermessagefilter.admin";

        private PluginConfig config;

        private class PluginConfig
        {
            [JsonProperty("Filtering enabled")]
            public bool Enabled = true;

            [JsonProperty("Blocked keywords (case insensitive)")]
            public List<string> BlockedKeywords = new List<string>
            {
                "Saving",
                "Restarting",
                "Server is shutting down"
            };
        }

        protected override void LoadDefaultConfig() => config = new PluginConfig();

        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                config = Config.ReadObject<PluginConfig>();
                if (config == null) throw new Exception();
            }
            catch
            {
                PrintWarning("Configuration file is invalid, using defaults");
                LoadDefaultConfig();
            }
            SaveConfig();
        }

        protected override void SaveConfig() => Config.WriteObject(config);

        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["FilterOn"] = "Server message filtering is now enabled.",
                ["FilterOff"] = "Server message filtering is now disabled.",
                ["NoPermission"] = "You do not have permission to use this command."
            }, this);
        }

        private void Init()
        {
            permission.RegisterPermission(PermAdmin, this);
        }

        [ChatCommand("smsg")]
        private void CmdServerMessage(BasePlayer player, string command, string[] args)
        {
            if (player == null) return;
            if (!permission.UserHasPermission(player.UserIDString, PermAdmin))
            {
                SendReply(player, Msg("NoPermission", player.UserIDString));
                return;
            }

            config.Enabled = !config.Enabled;
            SaveConfig();
            SendReply(player, Msg(config.Enabled ? "FilterOn" : "FilterOff", player.UserIDString));
        }

        private object OnServerMessage(string message, string username, string color, ulong userid)
        {
            if (!config.Enabled || string.IsNullOrEmpty(message)) return null;

            foreach (string keyword in config.BlockedKeywords)
            {
                if (string.IsNullOrEmpty(keyword)) continue;
                if (message.IndexOf(keyword, StringComparison.OrdinalIgnoreCase) >= 0)
                    return false;
            }

            return null;
        }

        private string Msg(string key, string userId = null) => lang.GetMessage(key, this, userId);
    }
}

The plugin lets admins suppress automatic server broadcasts that annoy players, such as save warnings and restart countdowns. OnServerMessage inspects the incoming text and returns a non-null value when it matches a configured keyword, which stops Rust from sending it. Keywords are compared case-insensitively and stored in oxide/config/ServerMessageFilter.json so admins can edit the list without recompiling. A chat command /smsg toggle flips filtering on and off at runtime, and the setting is written back to config. The check is a short loop over a small list, so it is cheap enough to run on every broadcast.

Common use cases

  • Hide save and restart spam

    Suppress automatic 'Saving...' or restart countdown lines when players find them noisy, while leaving join and leave notices intact.

  • Recolor or reroute server notices

    Return a value to block the default line and send your own through Server.Broadcast with a custom prefix or color.

  • Log all server broadcasts

    Record every server-wide message into a data file or a Discord bridge call so staff can audit what the server and plugins are announcing.

Pitfalls

  • This is not player chat

    Typed player messages are handled by OnPlayerChat. Filtering here will not mute players and blocking player chat requires the other hook.

  • Blocking everything is silent

    Returning non-null on every call removes join notices, save warnings and plugin announcements with no error, which is hard to debug if done by accident. Always gate on a config flag.

  • Fires very often

    Every server broadcast reaches this hook. Avoid logging with Puts, building strings unnecessarily or doing expensive lookups in the method body.

Build a plugin with OnServerMessage

Describe what should happen and get a compiled plugin that uses this hook.

Prompt: Hide save and restart spam using the OnServerMessage hook, with a config file and a permission
Generate this plugin

Edit the prompt on the next screen. 2 free plugins a month, no card.

Last updated Oct 26, 2026. Found a mistake? Email support@rustplugingenerator.com.

Build a plugin with OnServerMessage

Generate