/// <summary> Broadcasts a message, prefixing wrapped lines. </summary> /// <param name="source"> List of players who will receive the message. </param> /// <param name="prefix"> Prefix to prepend to prepend to each line after the 1st, /// if any line-wrapping occurs. Does NOT get prepended to first line. </param> /// <param name="message"> String/message to send. </param> /// <returns> Number of players who received the message. </returns> public static int MessagePrefixed([NotNull] this IEnumerable <Player> source, [NotNull] string prefix, [NotNull] string message, [Optional] MessageType?type) { if (source == null) { throw new ArgumentNullException("source"); } if (prefix == null) { throw new ArgumentNullException("prefix"); } if (message == null) { throw new ArgumentNullException("message"); } if (type == null) { type = 0; } int i = 0; if (!MessageTypeUtil.Enabled() || message.Length >= 64) { type = MessageType.Chat; } foreach (Player player in source) { foreach (Packet packet in LineWrapper.WrapPrefixed(prefix, message, player.SupportsFullCP437, type.Value)) { player.Send(packet); i++; } } return(i); }
/// <summary> Broadcasts a message. </summary> /// <param name="source"> List of players who will receive the message. </param> /// <param name="except"> Player to exclude from the recepient list. </param> /// <param name="message"> String/message to send. </param> /// <returns> Number of players who received the message. </returns> public static int Message([NotNull] this IEnumerable <Player> source, [CanBeNull] Player except, MessageType type, [NotNull] string message) { if (source == null) { throw new ArgumentNullException("source"); } if (message == null) { throw new ArgumentNullException("message"); } if (!MessageTypeUtil.Enabled() || message.Length >= 64) { type = MessageType.Chat; } int i = 0; foreach (Player player in source) { foreach (Packet packet in LineWrapper.Wrap(message, player.SupportsFullCP437, type)) { if (player == except) { continue; } player.Send(packet); i++; } } return(i); }
/// <summary> Sends a global (white) chat as specified message type</summary> /// <param name="player"> Player writing the message. </param> /// <param name="rawMessage"> Message text. </param> /// <param name="type">MessageType</param> /// <returns> True if message was sent, false if it was cancelled by an event callback. </returns> public static bool SendGlobal([NotNull] Player player, [NotNull] string rawMessage, MessageType type) { if (player == null) { throw new ArgumentNullException("player"); } if (rawMessage == null) { throw new ArgumentNullException("rawMessage"); } if (!MessageTypeUtil.Enabled() || rawMessage.Length >= 64) { type = MessageType.Chat; } string OriginalMessage = rawMessage; if (Server.Moderation && !Server.VoicedPlayers.Contains(player) && player.World != null) { player.Message("&WError: Server Moderation is activated. Message failed to send"); return(false); } rawMessage = FormatMessage(rawMessage, player); var recepientList = Server.Players.NotIgnoring(player); //if (player.World.WorldOnlyChat) recepientList = player.World.Players.NotIgnoring(player); string formattedMessage = $"{player.ClassyName}&F: {rawMessage}"; if (!MessageTypeUtil.Enabled() || rawMessage.Length >= 64) { type = MessageType.Chat; } var e = new ChatSendingEventArgs(player, rawMessage, formattedMessage, ChatMessageType.Global, recepientList, type); if (!SendInternal(e)) { return(false); } Network.Remote.Server.Chats.Add( new ServerLog { Sender = player.Name, Message = OriginalMessage, ChatMode = "" } ); Logger.Log(LogType.GlobalChat, "{0}: {1}", player.Name, OriginalMessage); return(true); }
/// <summary> Sends a global announcement (/Say). </summary> /// <param name="player"> Player writing the message. </param> /// <param name="rawMessage"> Message text. </param> /// <returns> True if message was sent, false if it was cancelled by an event callback. </returns> public static bool SendSay([NotNull] Player player, [NotNull] string rawMessage, MessageType type) { if (player == null) { throw new ArgumentNullException("player"); } if (rawMessage == null) { throw new ArgumentNullException("rawMessage"); } if (!MessageTypeUtil.Enabled() || rawMessage.Length >= 64) { type = MessageType.Chat; } var recepientList = Server.Players.NotIgnoring(player); rawMessage = FormatMessage(rawMessage, player); string formattedMessage = Color.Say + rawMessage; var e = new ChatSendingEventArgs(player, rawMessage, formattedMessage, ChatMessageType.Say, recepientList, type); if (!SendInternal(e)) { return(false); } Network.Remote.Server.Chats.Add( new ServerLog { Sender = player.Name, Message = rawMessage, ChatMode = "Say" } ); Logger.Log(LogType.GlobalChat, "(say){0}: {1}", player.Name, rawMessage); return(true); }
public static int Message([NotNull] this IEnumerable <Player> source, [NotNull] string message, [Optional] MessageType?type, [NotNull] params object[] formatArgs) { if (source == null) { throw new ArgumentNullException("source"); } if (message == null) { throw new ArgumentNullException("message"); } if (formatArgs == null) { throw new ArgumentNullException("formatArgs"); } if (type == null) { type = 0; } if (!MessageTypeUtil.Enabled() || message.Length >= 64) { type = MessageType.Chat; } if (!Enum.IsDefined(typeof(MessageType), type)) { throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(MessageType)); } int i = 0; foreach (Player player in source) { foreach (Packet packet in LineWrapper.Wrap(string.Format(message, formatArgs), player.SupportsFullCP437, type.Value)) { player.Send(packet); i++; } } return(i); }