/// <summary> /// Send a message to all players /// </summary> /// <param name="message">Message to be sent to all players</param> public GameEvent Broadcast(string message, EFClient sender = null) { var formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Say ?? "", $"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping)}"); ServerLogger.LogDebug("All-> {Message}", message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping).StripColors()); var e = new GameEvent { Type = GameEvent.EventType.Broadcast, Data = formattedMessage, Owner = this, Origin = sender, }; Manager.AddEvent(e); return(e); }
/// <summary> /// Send a message to a particular players /// </summary> /// <param name="message">Message to send</param> /// <param name="targetClient">EFClient to send message to</param> protected async Task Tell(string message, EFClient targetClient) { var engineMessage = message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping); if (!Utilities.IsDevelopment) { var temporalClientId = targetClient.GetAdditionalProperty <string>("ConnectionClientId"); var parsedClientId = string.IsNullOrEmpty(temporalClientId) ? (int?)null : int.Parse(temporalClientId); var clientNumber = parsedClientId ?? targetClient.ClientNumber; var formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Tell, clientNumber, $"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{engineMessage}"); if (targetClient.ClientNumber > -1 && message.Length > 0 && targetClient.Level != EFClient.Permission.Console) { await this.ExecuteCommandAsync(formattedMessage); } } else { ServerLogger.LogDebug("Tell[{ClientNumber}]->{Message}", targetClient.ClientNumber, message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping).StripColors()); } if (targetClient.Level == EFClient.Permission.Console) { Console.ForegroundColor = ConsoleColor.Green; using (LogContext.PushProperty("Server", ToString())) { ServerLogger.LogInformation("Command output received: {Message}", engineMessage.StripColors()); } Console.WriteLine(engineMessage.StripColors()); Console.ForegroundColor = ConsoleColor.Gray; } }