SendPM() public static method

Sends a private message (PM). Does NOT send a copy of the message to the sender.
public static SendPM ( [ from, [ to, [ rawMessage ) : bool
from [ Sender player.
to [ Recepient player.
rawMessage [ Message text.
return bool
Exemplo n.º 1
0
        static void ReplyHandler([NotNull] Player player, [NotNull] CommandReader cmd)
        {
            string messageText = cmd.NextAll();

            if (messageText.Length == 0)
            {
                player.Message("Reply: No message to send!");
                return;
            }
            string targetName = player.LastPrivateMessageSender;

            if (targetName != null)
            {
                Player targetPlayer = Server.FindPlayerExact(player,
                                                             targetName,
                                                             SearchOptions.IncludeHidden);
                if (targetPlayer != null)
                {
                    if (player.CanSee(targetPlayer))
                    {
                        if (targetPlayer.IsDeaf)
                        {
                            player.Message("Cannot PM {0}&S: they are currently deaf.", targetPlayer.ClassyName);
                        }
                        else if (targetPlayer.IsIgnoring(player.Info))
                        {
                            player.Message("&WCannot PM {0}&W: you are ignored.", targetPlayer.ClassyName);
                        }
                        else
                        {
                            Chat.SendPM(player, targetPlayer, messageText);
                            player.MessageNow("&Pto {0}: {1}", targetPlayer.Name, messageText);
                        }
                    }
                    else
                    {
                        player.Message("Reply: Cannot send message; player {0}&S is offline.",
                                       PlayerDB.FindExactClassyName(targetName));
                        if (targetPlayer.CanHear(player))
                        {
                            Chat.SendPM(player, targetPlayer, messageText);
                            player.Info.DecrementMessageWritten();
                        }
                    }
                }
                else
                {
                    player.Message("Reply: Cannot send message; player {0}&S is offline.",
                                   PlayerDB.FindExactClassyName(targetName));
                }
            }
            else
            {
                player.Message("Reply: You have not sent any messages yet.");
            }
        }
Exemplo n.º 2
0
        void HandlePrivateChatMessage([NotNull] string rawMessage)
        {
            if (rawMessage == null)
            {
                throw new ArgumentNullException("rawMessage");
            }
            if (!Can(Permission.Chat))
            {
                return;
            }

            if (Info.IsMuted)
            {
                MessageMuted();
                return;
            }

            if (DetectChatSpam())
            {
                return;
            }

            if (rawMessage.EndsWith("//"))
            {
                rawMessage = rawMessage.Substring(0, rawMessage.Length - 1);
            }

            string otherPlayerName, messageText;

            if (rawMessage[1] == ' ')
            {
                otherPlayerName = rawMessage.Substring(2, rawMessage.IndexOf(' ', 2) - 2);
                messageText     = rawMessage.Substring(rawMessage.IndexOf(' ', 2) + 1);
            }
            else
            {
                otherPlayerName = rawMessage.Substring(1, rawMessage.IndexOf(' ') - 1);
                messageText     = rawMessage.Substring(rawMessage.IndexOf(' ') + 1);
            }

            if (otherPlayerName == "-")
            {
                if (LastUsedPlayerName != null)
                {
                    otherPlayerName = LastUsedPlayerName;
                }
                else
                {
                    Message("Cannot repeat player name: you haven't used any names yet.");
                    return;
                }
            }

            // first, find ALL players (visible and hidden)
            Player[] allPlayers = Server.FindPlayers(otherPlayerName, SearchOptions.Default);

            // if there is more than 1 target player, exclude hidden players
            if (allPlayers.Length > 1)
            {
                allPlayers = Server.FindPlayers(this, otherPlayerName, SearchOptions.ReturnSelfIfOnlyMatch);
            }

            switch (allPlayers.Length)
            {
            case 0:
                MessageNoPlayer(otherPlayerName);
                break;

            case 1: {
                Player target = allPlayers[0];
                if (target == this)
                {
                    Message("Trying to talk to yourself?");
                    return;
                }
                bool messageSent = false;
                if (target.CanHear(this))
                {
                    messageSent = Chat.SendPM(this, target, messageText);
                    // Echo this message to spectators,
                    // excluding the PM target, and anyone from whom the target is hiding.
                    Server.Players
                    .Where(p => p.spectatedPlayer == this && p != target && p.CanSee(target))
                    .Message("[Spectate]: &Fto {0}&F: {1}", target.ClassyName, messageText);
                }

                if (!CanSee(target))
                {
                    // message was sent to a hidden player
                    MessageNoPlayer(otherPlayerName);
                    if (messageSent)
                    {
                        Info.DecrementMessageWritten();
                    }
                }
                else
                {
                    // message was sent normally
                    LastUsedPlayerName = target.Name;
                    if (target.IsIgnoring(Info))
                    {
                        if (CanSee(target))
                        {
                            MessageNow("&WCannot PM {0}&W: you are ignored.", target.ClassyName);
                        }
                    }
                    else if (target.IsDeaf)
                    {
                        MessageNow("Cannot PM {0}&S: they are currently deaf.", target.ClassyName);
                    }
                    else
                    {
                        MessageNow("&Pto {0}: {1}",
                                   target.Name,
                                   messageText);
                    }
                }
            }
            break;

            default:
                MessageManyMatches("player", allPlayers);
                break;
            }
        }