internal static bool sayAs(ChatChannel targetChannel, ulong userId, string username, string message, BasePlayer player = null) { if (!player) { player = null; } if (!enabled) { return(false); } if (player != null && player.HasPlayerFlag(BasePlayer.PlayerFlags.ChatMute)) { return(false); } ServerUsers.UserGroup userGroup = ServerUsers.Get(userId)?.group ?? ServerUsers.UserGroup.None; if (userGroup == ServerUsers.UserGroup.Banned) { return(false); } string text = message.Replace("\n", "").Replace("\r", "").Trim(); if (text.Length > 128) { text = text.Substring(0, 128); } if (text.Length <= 0) { return(false); } if (text.StartsWith("/") || text.StartsWith("\\")) { Interface.CallHook("IOnPlayerCommand", player, message); return(false); } text = text.EscapeRichText(); object obj = Interface.CallHook("IOnPlayerChat", userId, username, text, targetChannel, player); if (obj is bool) { return((bool)obj); } if (serverlog) { ServerConsole.PrintColoured(ConsoleColor.DarkYellow, string.Concat("[", targetChannel, "] ", username, ": "), ConsoleColor.DarkGreen, text); string text2 = player?.ToString() ?? $"{username}[{userId}]"; switch (targetChannel) { case ChatChannel.Team: DebugEx.Log("[TEAM CHAT] " + text2 + " : " + text); break; case ChatChannel.Cards: DebugEx.Log("[CARDS CHAT] " + text2 + " : " + text); break; default: DebugEx.Log("[CHAT] " + text2 + " : " + text); break; } } bool flag = userGroup == ServerUsers.UserGroup.Owner || userGroup == ServerUsers.UserGroup.Moderator; bool num = ((player != null) ? player.IsDeveloper : DeveloperList.Contains(userId)); string text3 = "#5af"; if (flag) { text3 = "#af5"; } if (num) { text3 = "#fa5"; } string text4 = username.EscapeRichText(); ChatEntry chatEntry = default(ChatEntry); chatEntry.Channel = targetChannel; chatEntry.Message = text; chatEntry.UserId = ((player != null) ? player.UserIDString : userId.ToString()); chatEntry.Username = username; chatEntry.Color = text3; chatEntry.Time = Epoch.Current; ChatEntry chatEntry2 = chatEntry; History.Add(chatEntry2); RCon.Broadcast(RCon.LogType.Chat, chatEntry2); switch (targetChannel) { case ChatChannel.Cards: { if (player == null) { return(false); } if (!player.isMounted) { return(false); } CardTable cardTable = player.GetMountedVehicle() as CardTable; if (cardTable == null || !cardTable.GameController.PlayerIsInGame(player)) { return(false); } List <Network.Connection> obj2 = Facepunch.Pool.GetList <Network.Connection>(); cardTable.GameController.GetConnectionsInGame(obj2); if (obj2.Count > 0) { ConsoleNetwork.SendClientCommand(obj2, "chat.add2", 3, userId, text, text4, text3, 1f); } Facepunch.Pool.FreeList(ref obj2); return(true); } case ChatChannel.Global: if (Server.globalchat) { ConsoleNetwork.BroadcastToAllClients("chat.add2", 0, userId, text, text4, text3, 1f); return(true); } break; case ChatChannel.Team: { RelationshipManager.PlayerTeam playerTeam = RelationshipManager.ServerInstance.FindPlayersTeam(userId); if (playerTeam == null) { return(false); } List <Network.Connection> onlineMemberConnections = playerTeam.GetOnlineMemberConnections(); if (onlineMemberConnections != null) { ConsoleNetwork.SendClientCommand(onlineMemberConnections, "chat.add2", 1, userId, text, text4, text3, 1f); } Util.BroadcastTeamChat(playerTeam, userId, text4, text, text3); return(true); } } if (player != null) { float num2 = 2500f; foreach (BasePlayer activePlayer in BasePlayer.activePlayerList) { float sqrMagnitude = (activePlayer.transform.position - player.transform.position).sqrMagnitude; if (!(sqrMagnitude > num2)) { ConsoleNetwork.SendClientCommand(activePlayer.net.connection, "chat.add2", 0, userId, text, text4, text3, Mathf.Clamp01(num2 - sqrMagnitude + 0.2f)); } } return(true); } return(false); }
private object OnUserChat(IPlayer player, string message) { #endif if (message.Length > _instance._config.MaxMessageLength) { message = message.Substring(0, _instance._config.MaxMessageLength); } BetterChatMessage chatMessage = ChatGroup.FormatMessage(player, message); if (chatMessage == null) { return(null); } Dictionary <string, object> chatMessageDict = chatMessage.ToDictionary(); #if RUST chatMessageDict.Add("ChatChannel", chatchannel); #endif foreach (Plugin plugin in plugins.GetAll()) { object hookResult = plugin.CallHook("OnBetterChat", chatMessageDict); if (hookResult is Dictionary <string, object> ) { try { chatMessageDict = hookResult as Dictionary <string, object>; } catch (Exception e) { PrintError($"Failed to load modified OnBetterChat hook data from plugin '{plugin.Title} ({plugin.Version})':{Environment.NewLine}{e}"); continue; } } else if (hookResult != null) { return(null); } } chatMessage = BetterChatMessage.FromDictionary(chatMessageDict); switch (chatMessage.CancelOption) { case BetterChatMessage.CancelOptions.BetterChatOnly: return(null); case BetterChatMessage.CancelOptions.BetterChatAndDefault: return(true); } var output = chatMessage.GetOutput(); #if RUST switch (chatchannel) { case Chat.ChatChannel.Team: RelationshipManager.PlayerTeam team = BasePlayer.Find(player.Id).Team; if (team == null || team.members.Count == 0) { return(true); } team.BroadcastTeamChat(Convert.ToUInt64(player.Id), player.Name, chatMessage.Message, chatMessage.UsernameSettings.Color); List <Network.Connection> onlineMemberConnections = team.GetOnlineMemberConnections(); if (onlineMemberConnections != null) { ConsoleNetwork.SendClientCommand(onlineMemberConnections, "chat.add", new object[] { (int)chatchannel, player.Id, output.Chat }); } break; default: foreach (BasePlayer p in BasePlayer.activePlayerList.Where(p => !chatMessage.BlockedReceivers.Contains(p.UserIDString))) { p.SendConsoleCommand("chat.add", new object[] { (int)chatchannel, player.Id, output.Chat }); } break; } #else foreach (IPlayer p in players.Connected.Where(p => !chatMessage.BlockedReceivers.Contains(p.Id))) { p.Message(output.Chat); } #endif #if RUST Puts($"[{chatchannel}] {output.Console}"); RCon.Broadcast(RCon.LogType.Chat, new Chat.ChatEntry { Channel = chatchannel, Message = output.Console, UserId = player.Id, Username = player.Name, Color = chatMessage.UsernameSettings.Color, Time = Epoch.Current }); #else Puts(output.Console); #endif return(true); }
private BetterChatMessage.CancelOptions SendBetterChatMessage(BetterChatMessage chatMessage) #endif { Dictionary <string, object> chatMessageDict = chatMessage.ToDictionary(); #if RUST chatMessageDict.Add("ChatChannel", chatchannel); #endif foreach (Plugin plugin in plugins.GetAll()) { object hookResult = plugin.CallHook("OnBetterChat", chatMessageDict); if (hookResult is Dictionary <string, object> ) { try { chatMessageDict = hookResult as Dictionary <string, object>; } catch (Exception e) { PrintError($"Failed to load modified OnBetterChat hook data from plugin '{plugin.Title} ({plugin.Version})':{Environment.NewLine}{e}"); continue; } } else if (hookResult != null) { return(BetterChatMessage.CancelOptions.BetterChatOnly); } } chatMessage = BetterChatMessage.FromDictionary(chatMessageDict); if (chatMessage.CancelOption != BetterChatMessage.CancelOptions.None) { return(chatMessage.CancelOption); } var output = chatMessage.GetOutput(); #if RUST BasePlayer basePlayer = chatMessage.Player.Object as BasePlayer; switch (chatchannel) { case Chat.ChatChannel.Team: RelationshipManager.PlayerTeam team = basePlayer.Team; if (team == null || team.members.Count == 0) { throw new InvalidOperationException("Chat channel is set to Team, however the player is not in a team."); } team.BroadcastTeamChat(basePlayer.userID, chatMessage.Player.Name, chatMessage.Message, chatMessage.UsernameSettings.Color); List <Network.Connection> onlineMemberConnections = team.GetOnlineMemberConnections(); if (onlineMemberConnections != null) { ConsoleNetwork.SendClientCommand(onlineMemberConnections, "chat.add", (int)chatchannel, chatMessage.Player.Id, output.Chat); } break; case Chat.ChatChannel.Cards: CardTable cardTable = basePlayer.GetMountedVehicle() as CardTable; if (cardTable == null /* || !cardTable.GameController.PlayerIsInGame(basePlayer) */) { throw new InvalidOperationException("Chat channel is set to Cards, however the player is not in a participating in a card game."); } List <Network.Connection> list = Facepunch.Pool.GetList <Network.Connection>(); foreach (CardPlayerData playerData in cardTable.GameController.playerData) { if (playerData.HasUser) { list.Add(BasePlayer.FindByID(playerData.UserID).net.connection); } } if (list.Count > 0) { ConsoleNetwork.SendClientCommand(list, "chat.add", (int)chatchannel, chatMessage.Player.Id, output.Chat); } Facepunch.Pool.FreeList(ref list); break; default: foreach (BasePlayer p in BasePlayer.activePlayerList.Where(p => !chatMessage.BlockedReceivers.Contains(p.UserIDString))) { p.SendConsoleCommand("chat.add", (int)chatchannel, chatMessage.Player.Id, output.Chat); } break; } #else foreach (IPlayer p in players.Connected.Where(p => !chatMessage.BlockedReceivers.Contains(p.Id))) { p.Message(output.Chat); } #endif #if RUST Puts($"[{chatchannel}] {output.Console}"); var chatEntry = new Chat.ChatEntry { Channel = chatchannel, Message = output.Console, UserId = chatMessage.Player.Id, Username = chatMessage.Player.Name, Color = chatMessage.UsernameSettings.Color, Time = Epoch.Current }; Chat.Record(chatEntry); RCon.Broadcast(RCon.LogType.Chat, chatEntry); #else Puts(output.Console); #endif return(chatMessage.CancelOption); }