示例#1
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);
        }
示例#2
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);
        }