예제 #1
0
    /// <summary>
    /// Send a Chat Msg from a player to the selected Chat Channels
    /// Server only
    /// </summary>
    public static void AddChatMsgToChat(ConnectedPlayer sentByPlayer, string message, ChatChannel channels)
    {
        var player = sentByPlayer.Script;

        var chatEvent = new ChatEvent
        {
            message    = message,
            modifiers  = (player == null) ? ChatModifier.None : player.GetCurrentChatModifiers(),
            speaker    = player.name,
            position   = ((player == null) ? Vector2.zero : (Vector2)player.gameObject.transform.position),
            channels   = channels,
            originator = sentByPlayer.GameObject
        };

        if (channels.HasFlag(ChatChannel.OOC))
        {
            chatEvent.speaker = sentByPlayer.Username;
            Instance.addChatLogServer.Invoke(chatEvent);
            return;
        }

        // There could be multiple channels we need to send a message for each.
        // We do this on the server side that local chans can be determined correctly
        foreach (Enum value in Enum.GetValues(channels.GetType()))
        {
            if (channels.HasFlag((ChatChannel)value))
            {
                //Using HasFlag will always return true for flag at value 0 so skip it
                if ((ChatChannel)value == ChatChannel.None)
                {
                    continue;
                }

                if (IsNamelessChan((ChatChannel)value))
                {
                    continue;
                }

                chatEvent.channels = (ChatChannel)value;
                Instance.addChatLogServer.Invoke(chatEvent);
            }
        }
    }
예제 #2
0
    /// <summary>
    /// Send a Chat Msg from a player to the selected Chat Channels
    /// Server only
    /// </summary>
    public static void AddChatMsgToChat(ConnectedPlayer sentByPlayer, string message, ChatChannel channels)
    {
        var player = sentByPlayer.Script;

        // The exact words that leave the player's mouth (or that are narrated). Already includes HONKs, stutters, etc.
        // This step is skipped when speaking in the OOC channel.
        (string message, ChatModifier chatModifiers)processedMessage = (string.Empty, ChatModifier.None);          // Placeholder values
        bool isOOC = channels.HasFlag(ChatChannel.OOC);

        if (!isOOC)
        {
            processedMessage = ProcessMessage(sentByPlayer, message);
        }

        var chatEvent = new ChatEvent
        {
            message    = isOOC ? message : processedMessage.message,
            modifiers  = (player == null) ? ChatModifier.None : processedMessage.chatModifiers,
            speaker    = (player == null) ? sentByPlayer.Username : player.name,
            position   = ((player == null) ? TransformState.HiddenPos : player.WorldPos),
            channels   = channels,
            originator = sentByPlayer.GameObject
        };

        if (channels.HasFlag(ChatChannel.OOC))
        {
            chatEvent.speaker = sentByPlayer.Username;
            Instance.addChatLogServer.Invoke(chatEvent);
            return;
        }

        // TODO the following code uses player.playerHealth, but ConciousState would be more appropriate.
        // Check if the player is allowed to talk:
        if (player != null && player.playerHealth != null)
        {
            if (player.playerHealth.IsCrit || player.playerHealth.IsCardiacArrest)
            {
                if (!player.playerHealth.IsDead)
                {
                    return;
                }
                else
                {
                    channels = ChatChannel.Ghost;
                }
            }
            else if (!player.playerHealth.IsDead && !player.IsGhost)
            {
                //Control the chat bubble
                player.playerNetworkActions.CmdToggleChatIcon(true, processedMessage.message, channels, processedMessage.chatModifiers);
            }
        }

        // There could be multiple channels we need to send a message for each.
        // We do this on the server side that local chans can be determined correctly
        foreach (Enum value in Enum.GetValues(channels.GetType()))
        {
            if (channels.HasFlag((ChatChannel)value))
            {
                //Using HasFlag will always return true for flag at value 0 so skip it
                if ((ChatChannel)value == ChatChannel.None)
                {
                    continue;
                }

                if (IsNamelessChan((ChatChannel)value))
                {
                    continue;
                }

                chatEvent.channels = (ChatChannel)value;
                Instance.addChatLogServer.Invoke(chatEvent);
            }
        }
    }
예제 #3
0
    /// <summary>
    /// Send a Chat Msg from a player to the selected Chat Channels
    /// Server only
    /// </summary>
    public static void AddChatMsgToChat(ConnectedPlayer sentByPlayer, string message, ChatChannel channels)
    {
        var player = sentByPlayer.Script;


        var chatEvent = new ChatEvent
        {
            message    = message,
            modifiers  = (player == null) ? ChatModifier.None : player.GetCurrentChatModifiers(),
            speaker    = (player == null) ? sentByPlayer.Username : player.name,
            position   = ((player == null) ? Vector2.zero : (Vector2)player.gameObject.transform.position),
            channels   = channels,
            originator = sentByPlayer.GameObject
        };

        if (channels.HasFlag(ChatChannel.OOC))
        {
            chatEvent.speaker = sentByPlayer.Username;
            Instance.addChatLogServer.Invoke(chatEvent);
            return;
        }

        //Check if the player is allowed to talk:
        if (player.playerHealth != null)
        {
            if (player.playerHealth.IsCrit || player.playerHealth.IsCardiacArrest)
            {
                if (!player.playerHealth.IsDead)
                {
                    return;
                }
                else
                {
                    channels = ChatChannel.Ghost;
                }
            }
            else
            {
                if (!player.playerHealth.IsDead && !player.IsGhost)
                {
                    {
                        //Control the chat bubble
                        player.playerNetworkActions.CmdToggleChatIcon(true, message, channels);
                    }
                }
            }
        }

        // There could be multiple channels we need to send a message for each.
        // We do this on the server side that local chans can be determined correctly
        foreach (Enum value in Enum.GetValues(channels.GetType()))
        {
            if (channels.HasFlag((ChatChannel)value))
            {
                //Using HasFlag will always return true for flag at value 0 so skip it
                if ((ChatChannel)value == ChatChannel.None)
                {
                    continue;
                }

                if (IsNamelessChan((ChatChannel)value))
                {
                    continue;
                }

                chatEvent.channels = (ChatChannel)value;
                Instance.addChatLogServer.Invoke(chatEvent);
            }
        }
    }
예제 #4
0
    /// <summary>
    /// Send a Chat Msg from a player to the selected Chat Channels
    /// Server only
    /// </summary>
    public static void AddChatMsgToChat(ConnectedPlayer sentByPlayer, string message, ChatChannel channels)
    {
        message = AutoMod.ProcessChatServer(sentByPlayer, message);
        if (string.IsNullOrWhiteSpace(message))
        {
            return;
        }

        var player = sentByPlayer.Script;

        // The exact words that leave the player's mouth (or that are narrated). Already includes HONKs, stutters, etc.
        // This step is skipped when speaking in the OOC channel.
        (string message, ChatModifier chatModifiers)processedMessage = (string.Empty, ChatModifier.None);          // Placeholder values
        bool isOOC = channels.HasFlag(ChatChannel.OOC);

        if (!isOOC)
        {
            processedMessage = ProcessMessage(sentByPlayer, message);
        }

        var chatEvent = new ChatEvent
        {
            message    = isOOC ? message : processedMessage.message,
            modifiers  = (player == null) ? ChatModifier.None : processedMessage.chatModifiers,
            speaker    = (player == null) ? sentByPlayer.Username : player.name,
            position   = ((player == null) ? TransformState.HiddenPos : player.WorldPos),
            channels   = channels,
            originator = sentByPlayer.GameObject
        };

        if (channels.HasFlag(ChatChannel.OOC))
        {
            chatEvent.speaker = sentByPlayer.Username;

            var isAdmin = PlayerList.Instance.IsAdmin(sentByPlayer.UserId);

            if (isAdmin)
            {
                chatEvent.speaker = "[Admin] " + chatEvent.speaker;
            }

            if (OOCMute && !isAdmin)
            {
                return;
            }

            Instance.addChatLogServer.Invoke(chatEvent);

            //Sends OOC message to a discord webhook
            DiscordWebhookMessage.Instance.AddWebHookMessageToQueue(DiscordWebhookURLs.DiscordWebhookOOCURL, message, chatEvent.speaker, ServerData.ServerConfig.DiscordWebhookOOCMentionsID);

            if (!ServerData.ServerConfig.DiscordWebhookSendOOCToAllChat)
            {
                return;
            }

            //Send it to All chat
            DiscordWebhookMessage.Instance.AddWebHookMessageToQueue(DiscordWebhookURLs.DiscordWebhookAllChatURL, $"[{ChatChannel.OOC}]  {message}\n", chatEvent.speaker);

            return;
        }

        // TODO the following code uses player.playerHealth, but ConciousState would be more appropriate.
        // Check if the player is allowed to talk:
        if (player != null && player.playerHealth != null)
        {
            if (!player.IsDeadOrGhost && player.mind.IsMiming && !processedMessage.chatModifiers.HasFlag(ChatModifier.Emote))
            {
                AddWarningMsgFromServer(sentByPlayer.GameObject, "You can't talk because you made a vow of silence.");
                return;
            }

            if (player.playerHealth.IsCrit || player.playerHealth.IsCardiacArrest)
            {
                if (!player.playerHealth.IsDead)
                {
                    return;
                }
                else
                {
                    channels = ChatChannel.Ghost;
                }
            }
            else if (!player.playerHealth.IsDead && !player.IsGhost)
            {
                //Control the chat bubble
                player.playerNetworkActions.CmdToggleChatIcon(true, processedMessage.message, channels, processedMessage.chatModifiers);
            }
        }

        string discordMessage = "";

        // There could be multiple channels we need to send a message for each.
        // We do this on the server side that local chans can be determined correctly
        foreach (Enum value in Enum.GetValues(channels.GetType()))
        {
            if (channels.HasFlag((ChatChannel)value))
            {
                //Using HasFlag will always return true for flag at value 0 so skip it
                if ((ChatChannel)value == ChatChannel.None)
                {
                    continue;
                }

                if (IsNamelessChan((ChatChannel)value))
                {
                    continue;
                }

                chatEvent.channels = (ChatChannel)value;
                Instance.addChatLogServer.Invoke(chatEvent);

                discordMessage += $"[{chatEvent.channels}] ";
            }
        }

        discordMessage += $"\n{chatEvent.speaker}: {message}\n";

        //Sends All Chat messages to a discord webhook
        DiscordWebhookMessage.Instance.AddWebHookMessageToQueue(DiscordWebhookURLs.DiscordWebhookAllChatURL, discordMessage, "");
    }