예제 #1
0
 public static void Broadcast(string message, string username = "******", string color = "#eee", ulong userid = 0uL)
 {
     if (Interface.CallHook("OnServerMessage", message, username, color, userid) == null)
     {
         string text = username.EscapeRichText();
         ConsoleNetwork.BroadcastToAllClients("chat.add", 2, 0, "<color=" + color + ">" + text + "</color> " + message);
         ChatEntry chatEntry = default(ChatEntry);
         chatEntry.Channel  = ChatChannel.Server;
         chatEntry.Message  = message;
         chatEntry.UserId   = userid.ToString();
         chatEntry.Username = username;
         chatEntry.Color    = color;
         chatEntry.Time     = Epoch.Current;
         ChatEntry chatEntry2 = chatEntry;
         History.Add(chatEntry2);
         RCon.Broadcast(RCon.LogType.Chat, chatEntry2);
     }
 }
예제 #2
0
        public static void Broadcast(string message, string username = "******", string color = "#eee", ulong userid = 0)
        {
            if (Interface.CallHook("OnServerMessage", (object)message, (object)username, (object)color, (object)userid) != null)
            {
                return;
            }
            string str = StringEx.EscapeRichText(username);

            ConsoleNetwork.BroadcastToAllClients("chat.add", (object)0, (object)("<color=" + color + ">" + str + "</color> " + message));
            Chat.ChatEntry chatEntry = new Chat.ChatEntry()
            {
                Message  = message,
                UserId   = userid,
                Username = username,
                Color    = color,
                Time     = Epoch.get_Current()
            };
            Chat.History.Add(chatEntry);
            RCon.Broadcast(RCon.LogType.Chat, (object)chatEntry);
        }
예제 #3
0
        public static void Broadcast(string message, string username = "******", string color = "#eee", ulong userid = 0L)
        {
            if (Interface.CallHook("OnServerMessage", message, username, color, userid) != null)
            {
                return;
            }
            string str = username.EscapeRichText();

            object[] objArray = new object[] { 0, null };
            objArray[1] = string.Concat(new string[] { "<color=", color, ">", str, "</color> ", message });
            ConsoleNetwork.BroadcastToAllClients("chat.add", objArray);
            Chat.ChatEntry chatEntry = new Chat.ChatEntry()
            {
                Message  = message,
                UserId   = userid,
                Username = username,
                Color    = color,
                Time     = Epoch.Current
            };
            Chat.ChatEntry chatEntry1 = chatEntry;
            Chat.History.Add(chatEntry1);
            RCon.Broadcast(RCon.LogType.Chat, chatEntry1);
        }
예제 #4
0
        object OnUserChat(IPlayer player, string message)
        {
            if (message.Length > Configuration.MaxMessageLength)
            {
                message = message.Substring(0, Configuration.MaxMessageLength);
            }

            BetterChatMessage chatMessage = ChatGroup.FormatMessage(player, message);

            if (chatMessage == null)
            {
                return(null);
            }

            Dictionary <string, object> chatMessageDict = chatMessage.ToDictionary();

            foreach (Plugin plugin in plugins.GetAll())
            {
                object hookResult = plugin.CallHook("OnBetterChat", chatMessageDict);

                if (hookResult is Dictionary <string, object> )
                {
                    try
                    {
                        chatMessageDict = (Dictionary <string, object>)hookResult;
                    }
                    catch (Exception e)
                    {
                        PrintError($"Failed to load modified OnBetterChat data from plugin '{plugin.Title} ({plugin.Version})':{Environment.NewLine}{e}");
                        continue;
                    }
                }
                else if (hookResult != null)
                {
                    return(null);
                }
            }

            chatMessage = BetterChatMessage.FromDictionary(chatMessageDict);
            var output = chatMessage.GetOutput();

            List <string> blockedReceivers = (List <string>)chatMessageDict["BlockedReceivers"];

#if RUST
            foreach (BasePlayer p in BasePlayer.activePlayerList.Where(p => !blockedReceivers.Contains(p.UserIDString)))
            {
                p.SendConsoleCommand("chat.add", new object[] { player.Id, output.Chat });
            }
#else
            foreach (IPlayer p in players.Connected.Where(p => !blockedReceivers.Contains(p.Id)))
            {
                p.Message(output.Chat);
            }
#endif

            Puts(output.Console);

#if RUST
            Chat.ChatEntry chatEntry = new Chat.ChatEntry
            {
                Message  = output.Console,
                UserId   = Convert.ToUInt64(player.Id),
                Username = player.Name,
                Time     = Epoch.Current
            };

            RCon.Broadcast(RCon.LogType.Chat, chatEntry);
#endif

            return(true);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        private bool OnPlayerChat(ConsoleSystem.Arg arg, Chat.ChatChannel channel)
        {
            var player = arg.Player();
            var text   = arg.GetString(0, "text").Replace("\n", "").Replace("\r", "").Trim().EscapeRichText();

            if (Chat.serverlog)
            {
                ServerConsole.PrintColoured(ConsoleColor.DarkYellow, string.Concat("[", channel.ToString(), "] ", player.displayName, ": "), ConsoleColor.DarkGreen, text);
                DebugEx.Log(channel == Chat.ChatChannel.Team
                    ? $"[TEAM CHAT] {player} : {text}"
                    : $"[CHAT] {player} : {text}");
            }

            var color       = "#5af";
            var displayName = player.displayName.EscapeRichText();

            player.NextChatTime = Time.realtimeSinceStartup + 1.5f;

            var chatEntry = new Chat.ChatEntry
            {
                Channel  = channel,
                Message  = text,
                UserId   = player.UserIDString,
                Username = player.displayName,
                Color    = color,
                Time     = Epoch.Current
            };

            RCon.Broadcast(RCon.LogType.Chat, chatEntry);

            if (channel != Chat.ChatChannel.Global)
            {
                if (channel == Chat.ChatChannel.Team)
                {
                    var team = arg.Player().Team;
                    var list = team?.GetOnlineMemberConnections();
                    if (list == null)
                    {
                        return(false);
                    }

                    ConsoleNetwork.SendClientCommand(list, "chat.add2", new object[]
                    {
                        1,
                        player.userID,
                        text,
                        displayName,
                        color,
                        1f
                    });

                    return(false);
                }
            }
            else if (ConVar.Server.globalchat)
            {
                ConsoleNetwork.BroadcastToAllClients("chat.add2", 0, player.userID, text, displayName, color, 1f);
                return(false);
            }

            var radius = 2500f;

            foreach (var basePlayer2 in BasePlayer.activePlayerList)
            {
                var sqrMagnitude = (basePlayer2.transform.position - player.transform.position).sqrMagnitude;
                if (sqrMagnitude <= radius)
                {
                    ConsoleNetwork.SendClientCommand(basePlayer2.net.connection, "chat.add2", 0, player.userID, text, displayName, color, Mathf.Clamp01(radius - sqrMagnitude + 0.2f));
                }
            }

            return(false);
        }
예제 #8
0
        public static void say(ConsoleSystem.Arg arg)
        {
            if (!Chat.enabled)
            {
                arg.ReplyWith("Chat is disabled.");
                return;
            }
            BasePlayer basePlayer = arg.Player();

            if (!basePlayer)
            {
                return;
            }
            if (basePlayer.HasPlayerFlag(BasePlayer.PlayerFlags.ChatMute))
            {
                return;
            }
            if (!basePlayer.IsAdmin && !basePlayer.IsDeveloper)
            {
                if (basePlayer.NextChatTime == 0f)
                {
                    basePlayer.NextChatTime = UnityEngine.Time.realtimeSinceStartup - 30f;
                }
                if (basePlayer.NextChatTime > UnityEngine.Time.realtimeSinceStartup)
                {
                    basePlayer.NextChatTime += 2f;
                    float      nextChatTime = basePlayer.NextChatTime - UnityEngine.Time.realtimeSinceStartup;
                    Connection connection   = basePlayer.net.connection;
                    object[]   objArray     = new object[] { 0, null };
                    float      single       = nextChatTime + 0.5f;
                    objArray[1] = string.Concat("You're chatting too fast - try again in ", single.ToString("0"), " seconds");
                    ConsoleNetwork.SendClientCommand(connection, "chat.add", objArray);
                    if (nextChatTime > 120f)
                    {
                        basePlayer.Kick("Chatting too fast");
                    }
                    return;
                }
            }
            string str = arg.GetString(0, "text").Trim();

            if (str.Length > 128)
            {
                str = str.Substring(0, 128);
            }
            if (str.Length <= 0)
            {
                return;
            }
            if (str.StartsWith("/") || str.StartsWith("\\"))
            {
                if (Interface.CallHook("IOnPlayerCommand", arg) != null)
                {
                    return;
                }
                return;
            }
            str = str.EscapeRichText();
            if (Interface.CallHook("IOnPlayerChat", arg, str) != null)
            {
                return;
            }
            if (Chat.serverlog)
            {
                ServerConsole.PrintColoured(new object[] { ConsoleColor.DarkYellow, string.Concat(basePlayer.displayName, ": "), ConsoleColor.DarkGreen, str });
                DebugEx.Log(string.Format("[CHAT] {0} : {1}", basePlayer.ToString(), str), StackTraceLogType.None);
            }
            string str1 = "#5af";

            if (basePlayer.IsAdmin)
            {
                str1 = "#af5";
            }
            if (basePlayer.IsDeveloper)
            {
                str1 = "#fa5";
            }
            string str2 = basePlayer.displayName.EscapeRichText();

            basePlayer.NextChatTime = UnityEngine.Time.realtimeSinceStartup + 1.5f;
            Chat.ChatEntry chatEntry = new Chat.ChatEntry()
            {
                Message  = str,
                UserId   = basePlayer.userID,
                Username = basePlayer.displayName,
                Color    = str1,
                Time     = Epoch.Current
            };
            Chat.ChatEntry chatEntry1 = chatEntry;
            Chat.History.Add(chatEntry1);
            RCon.Broadcast(RCon.LogType.Chat, chatEntry1);
            if (ConVar.Server.globalchat)
            {
                ConsoleNetwork.BroadcastToAllClients("chat.add2", new object[] { basePlayer.userID, str, str2, str1, 1f });
                arg.ReplyWith("");
                return;
            }
            float single1 = 2500f;

            foreach (BasePlayer basePlayer1 in BasePlayer.activePlayerList)
            {
                Vector3 vector3 = basePlayer1.transform.position - basePlayer.transform.position;
                float   single2 = vector3.sqrMagnitude;
                if (single2 > single1)
                {
                    continue;
                }
                ConsoleNetwork.SendClientCommand(basePlayer1.net.connection, "chat.add2", new object[] { basePlayer.userID, str, str2, str1, Mathf.Clamp01(single1 - single2 + 0.2f) });
            }
            arg.ReplyWith("");
        }
예제 #9
0
 public static void say(ConsoleSystem.Arg arg)
 {
     if (!Chat.enabled)
     {
         arg.ReplyWith("Chat is disabled.");
     }
     else
     {
         BasePlayer basePlayer = arg.Player();
         if (!Object.op_Implicit((Object)basePlayer) || basePlayer.HasPlayerFlag(BasePlayer.PlayerFlags.ChatMute))
         {
             return;
         }
         if (!basePlayer.IsAdmin && !basePlayer.IsDeveloper)
         {
             if ((double)basePlayer.NextChatTime == 0.0)
             {
                 basePlayer.NextChatTime = Time.get_realtimeSinceStartup() - 30f;
             }
             if ((double)basePlayer.NextChatTime > (double)Time.get_realtimeSinceStartup())
             {
                 basePlayer.NextChatTime += 2f;
                 float num = basePlayer.NextChatTime - Time.get_realtimeSinceStartup();
                 ConsoleNetwork.SendClientCommand(basePlayer.net.get_connection(), "chat.add", (object)0, (object)("You're chatting too fast - try again in " + (num + 0.5f).ToString("0") + " seconds"));
                 if ((double)num <= 120.0)
                 {
                     return;
                 }
                 basePlayer.Kick("Chatting too fast");
                 return;
             }
         }
         string str1 = arg.GetString(0, "text").Trim();
         if (str1.Length > 128)
         {
             str1 = str1.Substring(0, 128);
         }
         if (str1.Length <= 0)
         {
             return;
         }
         if (str1.StartsWith("/") || str1.StartsWith("\\"))
         {
             if (Interface.CallHook("IOnPlayerCommand", (object)arg) != null)
             {
                 ;
             }
         }
         else
         {
             string str2 = StringEx.EscapeRichText(str1);
             if (Interface.CallHook("IOnPlayerChat", (object)arg) != null)
             {
                 return;
             }
             if (Chat.serverlog)
             {
                 ServerConsole.PrintColoured((object)ConsoleColor.DarkYellow, (object)(basePlayer.displayName + ": "), (object)ConsoleColor.DarkGreen, (object)str2);
                 DebugEx.Log((object)string.Format("[CHAT] {0} : {1}", (object)((object)basePlayer).ToString(), (object)str2), (StackTraceLogType)0);
             }
             string str3 = "#5af";
             if (basePlayer.IsAdmin)
             {
                 str3 = "#af5";
             }
             if (basePlayer.IsDeveloper)
             {
                 str3 = "#fa5";
             }
             string str4 = StringEx.EscapeRichText(basePlayer.displayName);
             basePlayer.NextChatTime = Time.get_realtimeSinceStartup() + 1.5f;
             Chat.ChatEntry chatEntry = new Chat.ChatEntry()
             {
                 Message  = str2,
                 UserId   = basePlayer.userID,
                 Username = basePlayer.displayName,
                 Color    = str3,
                 Time     = Epoch.get_Current()
             };
             Chat.History.Add(chatEntry);
             RCon.Broadcast(RCon.LogType.Chat, (object)chatEntry);
             if (Server.globalchat)
             {
                 ConsoleNetwork.BroadcastToAllClients("chat.add2", (object)basePlayer.userID, (object)str2, (object)str4, (object)str3, (object)1f);
                 arg.ReplyWith("");
             }
             else
             {
                 float num = 2500f;
                 foreach (BasePlayer activePlayer in BasePlayer.activePlayerList)
                 {
                     Vector3 vector3      = Vector3.op_Subtraction(((Component)activePlayer).get_transform().get_position(), ((Component)basePlayer).get_transform().get_position());
                     float   sqrMagnitude = ((Vector3) ref vector3).get_sqrMagnitude();
                     if ((double)sqrMagnitude <= (double)num)
                     {
                         ConsoleNetwork.SendClientCommand(activePlayer.net.get_connection(), "chat.add2", (object)basePlayer.userID, (object)str2, (object)str4, (object)str3, (object)Mathf.Clamp01((float)((double)num - (double)sqrMagnitude + 0.200000002980232)));
                     }
                 }
                 arg.ReplyWith("");
             }
         }
     }
 }
예제 #10
0
        private bool OnPlayerChat(BasePlayer player, string message, Chat.ChatChannel channel)
        {
            if (Chat.serverlog)
            {
                ServerConsole.PrintColoured(ConsoleColor.DarkYellow,
                                            string.Concat("[", channel, "] ", player.displayName, ": "), ConsoleColor.DarkGreen, message);

                var str = (player != null ? player.ToString() : null) ??
                          $"{player.displayName}[{player.userID}]";

                if (channel == Chat.ChatChannel.Team)
                {
                    DebugEx.Log("[TEAM CHAT] " + str + " : " + message);
                }
                else
                {
                    DebugEx.Log("[CHAT] " + str + " : " + message);
                }
            }

            var color       = "#5af";
            var displayName = player.displayName.EscapeRichText();
            var chatEntry   = new Chat.ChatEntry
            {
                Channel  = channel,
                Message  = message,
                UserId   = player.UserIDString,
                Username = displayName,
                Color    = color,
                Time     = Epoch.Current
            };

            RCon.Broadcast(RCon.LogType.Chat, chatEntry);
            if (channel != Chat.ChatChannel.Global)
            {
                if (channel == Chat.ChatChannel.Team)
                {
                    var playerTeam = RelationshipManager.Instance.FindPlayersTeam(player.userID);
                    if (playerTeam == null)
                    {
                        return(false);
                    }

                    var onlineMemberConnections = playerTeam.GetOnlineMemberConnections();
                    if (onlineMemberConnections != null)
                    {
                        ConsoleNetwork.SendClientCommand(onlineMemberConnections, "chat.add2", 1, player.userID,
                                                         message, displayName, color, 1f);
                    }

                    playerTeam.BroadcastTeamChat(player.userID, displayName, message, color);
                    return(true);
                }
            }
            else if (ConVar.Server.globalchat)
            {
                ConsoleNetwork.BroadcastToAllClients("chat.add2", 0, player.userID, message, displayName, color, 1f);
                return(true);
            }

            if (player == null)
            {
                return(true);
            }

            var radius = 2500f;

            foreach (var basePlayer in BasePlayer.activePlayerList)
            {
                var sqrMagnitude = (basePlayer.transform.position - player.transform.position).sqrMagnitude;
                if (sqrMagnitude <= radius)
                {
                    ConsoleNetwork.SendClientCommand(basePlayer.net.connection, "chat.add2", 0, player.userID,
                                                     message,
                                                     displayName, color, Mathf.Clamp01(radius - sqrMagnitude + 0.2f));
                }
            }

            return(true);
        }
예제 #11
0
        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);
        }