Beispiel #1
0
        public static void BulletinBoardMessage(NetState state, PacketReader pvSrc)
        {
            try
            {
                // Log the incoming packet
                BulletinPacket.LogPacket("BulletinSendPostMessage", pvSrc.Buffer);

                // Get the player character who performed the action that sent the packet
                Mobile from = state.Mobile;

#if BULLETIN_DEBUG
                // Log to the console information about the selected posting
                Console.WriteLine("BulletinSendPostMessage: Post Requested from Mobile '{0}' {1}", from.Name, from.Serial);
#endif

                // Get the type of bulletin message (packet sub type)
                BulletinPacket.PacketSubType SubType = (BulletinPacket.PacketSubType)pvSrc.ReadByte();
#if BULLETIN_DEBUG
                Console.WriteLine("BulletinSendPostMessage: Sub-Type={0}", SubType.ToString());
#endif

                // Find the bulletin board this packet is referring to
                BulletinBoard Board = World.FindItem(pvSrc.ReadInt32()) as BulletinBoard;
                if (Board == null)
                {
                    return;
                }

#if BULLETIN_DEBUG
                // Log to the console information about the selected posting
                Console.WriteLine("BulletinSendPostMessage: Post Requested from Bulletin Board '{0}' {1} - Total Items = {2}", Board.Name, Board.Serial, Board.Items.Count);
#endif

                // Switch the message sub-type
                switch (SubType)
                {
                // Client wants to post a new message
                case BulletinPacket.PacketSubType.RequestPostCreation:
                {
                    from.SendAsciiMessage("You cannot post messages on this board.");
                    return;

                    // Make sure the client is still close enough to interact with the bulletin board
                    if (!from.InRange(Board.GetWorldLocation(), 2))
                    {
                        from.SendMessage("You are too far away from the board to post a message.");
                        return;
                    }

                    // Read in the next 4 bytes to see if this is a reply
                    BulletinBoardPost ReplyToPost = World.FindItem(pvSrc.ReadInt32()) as BulletinBoardPost;

                    // Check if the reply is to a global posting
                    if (ReplyToPost is BulletinBoardGlobalPost)
                    {
                        // Tell the player that they can not reply to this message
                        state.Mobile.SendMessage("You may not reply to this message.");
                        return;
                    }

                    // Get the length of the subject
                    short SubjectLength = pvSrc.ReadByte();

                    // Get the subject line including the terminatin NULL
                    string Subject = pvSrc.ReadString();

                    // Get the number of message lines
                    short MessageLines = pvSrc.ReadByte();

                    // Retrieve all of the lines in the message
                    string[] Message = new string[MessageLines];
                    for (int x = 0; x < Message.Length; x++)
                    {
                        short CurrentLineLength = pvSrc.ReadByte();
                        Message[x] = pvSrc.ReadString();
                    }

                    // Now that all of the data has been collected, create a BulletinBoardPost item
                    BulletinBoardPost NewPost = new BulletinBoardPost(Subject, from.Name, Message);

                    // Check if this is a reply to a previous post
                    if (ReplyToPost != null)
                    {
                        // Check if the post being replied to is a base post
                        // on the board.  Only base posts can be replied to.
                        // This code ensures that replies can only be done to
                        // base posts, and not to other replies
                        if (ReplyToPost.Parent == Board)
                        {
                            ReplyToPost.AddItem(NewPost);
                        }
                        else
                        {
                            ((Item)(ReplyToPost.Parent)).AddItem(NewPost);
                        }

                        // Send update to the client that a reply was posted
                        // This shows the new reply immediately on the board
                        // (Strange, but the client automatically does this part
                        //  if the posting is not a reply)
                        from.Send(new AddPostReplyItemPacket(NewPost));
                    }
                    else
                    {
                        // This is a new post, so add it to the boards item list
                        Board.AddItem(NewPost);
                    }

#if BULLETIN_DEBUG
                    // Log to the console information about the selected posting
                    Console.WriteLine("BulletinSendPostMessage: Added New Post {0} to Bulletin Board '{1}' {2} - Total Items = {3}", NewPost.Serial, Board.Name, Board.Serial, Board.Items.Count);
#endif
                    break;
                }

                // Client is requesting a summary of a posted message
                case BulletinPacket.PacketSubType.RequestPostSummary:
                {
                    // Try to find the post that this message is referring to
                    int PostSerial         = pvSrc.ReadInt32();
                    BulletinBoardPost Post = World.FindItem(PostSerial) as BulletinBoardPost;
                    if (Post == null)
                    {
                        Console.WriteLine("Unknown Bulletin Board Post Item - Serial: {0}", PostSerial);
                        return;
                    }

                    from.Send(new BulletinBoardSendPostSummaryPacket(Board, Post));
                    break;
                }

                // Client is requesting the full details of the post (the entire message)
                case BulletinPacket.PacketSubType.RequestPostMessage:
                {
                    // Make sure the client is still close enough to interact with the bulletin board
                    if (!from.InRange(Board.GetWorldLocation(), 2))
                    {
                        from.SendMessage("You are too far away from the board to read the message.");
                        return;
                    }

                    // Try to find the post that this message is referring to
                    int PostSerial         = pvSrc.ReadInt32();
                    BulletinBoardPost Post = World.FindItem(PostSerial) as BulletinBoardPost;
                    if (Post == null)
                    {
                        Console.WriteLine("Unknown Bulletin Board Post Item - Serial: {0}", PostSerial);
                        return;
                    }

                    from.Send(new BulletinBoardPostPacket(Post));
                    break;
                }

                // Client is requesting to remove a post
                case BulletinPacket.PacketSubType.RequestPostRemove:
                {
                    // Don't handle this situation at the moment
                    // The T2A client and the UOTD client behave differently
                    // so therefore, it's not handled at all for simplicity

                    /*
                     * // Try to find the post that this message is referring to
                     * int PostSerial = pvSrc.ReadInt32();
                     * BulletinBoardPost Post = World.FindItem( PostSerial ) as BulletinBoardPost;
                     * if ( Post == null )
                     * {
                     *  Console.WriteLine( "Unknown Bulletin Board Post Item - Serial: {0}", PostSerial );
                     *  return;
                     * }
                     *
                     * // Delete the post item
                     * Post.Delete();
                     */
                    break;
                }

                default:
                {
                    Console.WriteLine("BulletinBoardPost: Unknown Bulletin Board Message SubType: ", SubType);
                    break;
                }
                }
            }
            catch (System.Exception se)
            {
                Console.WriteLine(se.ToString());
            }

            return;
        }