コード例 #1
0
        object OnUserChat(IPlayer player, string message)
        {
            object hookResult = Interface.CallHook("OnBetterChat", player, message);

            if (hookResult is string)
            {
                message = (string)hookResult;
            }
            else if (hookResult != null)
            {
                return(null);
            }

            var output = ChatGroup.FormatMessage(player, message);

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

#if RUST
            ConsoleNetwork.BroadcastToAllClients("chat.add", new object[] { player.Id, output.Chat });
#else
            server.Broadcast(output.Chat);
#endif

            Puts(output.Console);

            return(true);
        }
コード例 #2
0
ファイル: BetterChat.cs プロジェクト: mbello2/anatomiarust2.0
 private string API_GetFormattedMessage(IPlayer player, string message, bool console = false) => console?ChatGroup.FormatMessage(player, message).GetOutput().Console : ChatGroup.FormatMessage(player, message).GetOutput().Chat;
コード例 #3
0
ファイル: BetterChat.cs プロジェクト: mbello2/anatomiarust2.0
 private Dictionary <string, object> API_GetMessageData(IPlayer player, string message) => ChatGroup.FormatMessage(player, message)?.ToDictionary();
コード例 #4
0
ファイル: BetterChat.cs プロジェクト: mbello2/anatomiarust2.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);
        }