public async void Broadcast(IGame game, string message, Structures.BroadcastType messageType, string src) { var colorName = string.Empty; switch (messageType) { case Structures.BroadcastType.Error: { colorName += "[FF0000FF]"; break; } case Structures.BroadcastType.Warning: { colorName += "[FFFF00FF]"; break; } case Structures.BroadcastType.Information: { colorName += "[00FF00FF]"; break; } case Structures.BroadcastType.Manual: { //the color is in the message already. break; } } //cName disabled : possible ban source. message = colorName + message; foreach (var destination in game.Players.ToList()) { if (destination.Client.Connection == null || !destination.Client.Connection.IsConnected) { Logger.LogWarning("ImpostorHQ : Warning - a residual client has been identified."); continue; } var msg = (Generator.WriteChat( game.Code.Value, destination.Character.NetId, destination.Character.PlayerInfo.PlayerName, new string[] { message }, src )); using (msg) destination.Client.Connection.SendAsync(msg); } }
public async Task SafeAsyncBroadcast(IGame game, string message, Structures.BroadcastType type) #pragma warning restore CS1998 { //the second try loop is for catching unknown errors. try { if (game == null) { return; } SafeMultiMessage(game, message, type); } catch (Exception ex) { //we have caught an unknown error. Logger.LogError($"ImpostorHQ : Critical unknown error : {ex.Message}"); } }
public void SafeMultiMessage(IGame game, string message, Structures.BroadcastType broadcastType, string source = "(server)", IClientPlayer destination = null) { try { if (destination == null) { //broadcast Broadcast(game, message, broadcastType, source); } else { //private chat message PrivateMessage(destination, message, source, broadcastType); } } catch (Structures.Exceptions.PlayerNullException ex) { Logger.LogError($"ImpostorHQ : Critical error : {ex.Message}"); } }
public async void PrivateMessage(IClientPlayer player, string message, string source, Structures.BroadcastType type) { var coloredName = string.Empty; var origName = player.Character.PlayerInfo.PlayerName; switch (type) { //we now set the color and compile the name. case Structures.BroadcastType.Error: { coloredName += "[FF0000FF]"; break; } case Structures.BroadcastType.Warning: { coloredName += "[FFFF00FF]"; break; } case Structures.BroadcastType.Information: { coloredName += "[00FF00FF]"; break; } case Structures.BroadcastType.Manual: { //the color is in the message already. break; } } //we now finish compiling the colored message string. var srcMessage = coloredName + message; var connection = player.Client.Connection; if (connection == null) { return; //how? } //we now compile the final packet. using (var chatMessage = Generator.WriteChat( player.Game.Code, player.Character.NetId, origName, new string[] { srcMessage }, source )) await connection.SendAsync(chatMessage).ConfigureAwait(false); }