ACR_ServerCommunicator.ACR_ServerCommunicator.ProcessTellCommand C# (CSharp) Method

ProcessTellCommand() private method

Parse and act on a tell style internal command.
private ProcessTellCommand ( string Start, uint SenderObjectId, TELL_TYPE TellType ) : void
Start string Supplies the start of the tell command line, /// after the command prefix.
SenderObjectId uint Supplies the object id of the object /// that initiated the tell request.
TellType TELL_TYPE Supplies the type of tell command that was /// requested.
return void
        private void ProcessTellCommand(string Start, uint SenderObjectId, TELL_TYPE TellType)
        {
            //
            // Parse the destination field out.
            //

            string MessagePart;
            string NamePart;
//          int NameStartOffset;
            int NamePartEnd;
            string Destination;
            int Offset;
            GamePlayer Player;

            Destination = Start;

            if (Destination.Length < 2)
                return;

            //
            // Find the end of the name, which is either a second double quote,
            // or a space character.
            //

            if (Destination[0] == '\"')
            {
                Offset = Destination.IndexOf('\"', 1);

                if (Offset == -1)
                {
                    SendFeedbackError(SenderObjectId,
                        "Illegal tell command format (unmatched quote in destination).");
                    return;
                }

                Destination = Destination.Substring(0, Offset);

                NamePart = Destination.Substring(1); // Past the first quote
                NamePartEnd = Offset;
                MessagePart = Start.Substring(1 + Offset);
//              NameStartOffset = 1;

                //
                // Eat up to one single trailing space.
                //

                if (MessagePart.Length > 1 && Char.IsWhiteSpace(MessagePart[0]))
                    MessagePart = MessagePart.Substring(1);
            }
            else
            {
                Offset = Destination.IndexOf(' ');

                if (Offset == -1)
                {
                    SendFeedbackError(SenderObjectId,
                        "Illegal tell command format (missing destination).");
                    return;
                }

                Destination = Destination.Substring(0, Offset);

                NamePart = Destination;
                NamePartEnd = Offset;
                MessagePart = Start.Substring(Offset + 1); // After the space
//              NameStartOffset = 0;
            }

            if (String.IsNullOrEmpty(Destination))
            {
                SendFeedbackError(SenderObjectId,
                    "Illegal tell command format (empty destination).");
                return;
            }

            //
            // Message is parsed.  Figure out how to resolve the target name
            // and deliver it as appropriate.
            //

            lock (WorldManager)
            {
                switch (TellType)
                {

                    case TELL_TYPE.ToChar:
                        {
                            GameCharacter Character = WorldManager.ReferenceCharacterByName(NamePart, null);

                            if (Character != null && Character.Online)
                                Player = Character.Player;
                            else
                            {
                                Player = null;
                                SendFeedbackError(SenderObjectId, "That player is not logged on.");
                                return;
                            }

                            /*
                            string First;
                            string Last;

                            //
                            // Note that we might have a last name along for the
                            // ride.  Split it out if we can.
                            //

                            First = NamePart;
                            Last = null;

                            if ((Offset = First.IndexOf(' ')) != -1)
                            {
                                First = First.Substring(0, Offset);
                                Last = NamePart + Offset + 1; // Skip the space.
                            }

                            Player = GetPlayerByName(First, Last);

                            if (Player == null && !String.IsNullOrEmpty(Last))
                            {
                                //
                                // If the last name was all spaces, then retry
                                // without a last name.
                                //

                                if (String.IsNullOrWhiteSpace(Last))
                                    Player = GetPlayerByName(First, null);

                                //
                                // If we still don't have a match, the player could
                                // have a first name of the form "first name", with
                                // spaces and trailing characters.  Just try and
                                // resolve it as the entire first name.
                                //

                                if (Player == null && Destination[0] == '\"')
                                {
                                    string NameStart;

                                    NameStart = Start.Substring(NameStartOffset);
                                    First = NameStart.Substring(NamePartEnd - NameStartOffset);

                                    Player = GetPlayerByName(First, null);

                                    //
                                    // Try stripping spaces from the end too.
                                    //

                                    if (Player == null && First.Length > 1)
                                    {
                                        if (First[First.Length - 1] == ' ')
                                            First = First.Substring(0, First.Length - 1);

                                        Player = GetPlayerByName(First, null);
                                    }
                                }
                            }*/
                        }
                        break;

                    case TELL_TYPE.ToPlayer:
                        {
                            //
                            // Look it up by account name.
                            //

                            Player = WorldManager.ReferencePlayerByName(NamePart, null);
                            /*
                            Player = GetPlayerByAccountName(NamePart);
                             * */
                        }
                        break;

                    case TELL_TYPE.ToCharFirstName:
                        {
                            Player = GetPlayerByFirstName(NamePart);
                        }
                        break;

                    default:
                        return;

                }

                if (Player == null)
                {
                    SendFeedbackError(SenderObjectId, "Player not found.");
                }
                else
                {
                    GamePlayer SenderPlayer;

                    if (GetIsPC(SenderObjectId) != FALSE)
                        SenderPlayer = WorldManager.ReferencePlayerById(GetDatabase().ACR_GetPlayerID(SenderObjectId), GetDatabase());
                    else
                        SenderPlayer = WorldManager.ReferencePlayerById(GetDatabase().ACR_GetPlayerID(GetOwnedCharacter(SenderObjectId)), GetDatabase());

                    if (SenderPlayer == null)
                    {
                        SendFeedbackError(SenderObjectId, "No database entity exists for your character.");
                        return;
                    }

                    SendServerToServerTell(
                        SenderObjectId,
                        SenderPlayer,
                        Player,
                        MessagePart);
                }
            }
        }
ACR_ServerCommunicator