MessageBoard

05/24/2012 18:36 Zeroxelli#1
Well, I've never implemented it, but I was getting "Unknown packet: 1111" from players trying to use it, so I decided to go for it. Through trial and error, I found what I believe to be the right packet for displaying the list of messages, however even if there are multiple messages, the last one overwrites any that were before it. I'm sure there's something I'm supposed to change, but I haven't figured it out yet. Here's my packet.

Code:
        public static byte[] MessageBoard(MessageBoardPost Post, int Page)
        {
            string Msg = Post.Message;
            if (Msg.Length > 50)
                Msg = Msg.Substring(0, 50);
            Packet Packet = new Packet(13 + (Post.Poster.Length + Msg.Length + Post.TimeStamp.Length), 1111);
            Packet.Short(Page); // Assuming this is the page, since it does nothing atm.
            Packet.Short((int)Post.Board); // The board type, aka TradeBoard, FriendBoard, ...
            Packet.Byte(3); // Flag - Should always be 3? 3=Send List
            Packet.Byte(3); // String Count
            Packet.String(Post.Poster, true); // Poster's name
            Packet.String(Msg, true); // The [truncated] message
            Packet.String(Post.TimeStamp, true); // And the timestamp, YYYY-MM-DD-HH-MM
            return Packet.Buffer; 
        }
The bool "true" passed to the string function simply means that it should send a byte containing the length first, thus why the packet length is 13 + (string lengths)

Anywho, a shove in the right direction would be awesome. :)

Edit: Also, everything else works, including viewing messages in full. The number of items displayed is my only problem.
05/24/2012 23:45 12tails#2
Took it from my VERY... VERY... VERYYY Old source.... :]
hope it helps

Its not the best system... but it works... so implement it the best way you can... i'll do it in my new source when i get the packet handling system fully working :]

packet:

Handler:
05/25/2012 00:39 Zeroxelli#3
Quote:
Originally Posted by 12tails View Post
Took it from my VERY... VERY... VERYYY Old source.... :]
hope it helps

Its not the best system... but it works... so implement it the best way you can... i'll do it in my new source when i get the packet handling system fully working :]

packet:

Handler:
Ahh okay, so I was right in assuming that I should just put my foreach inside the packet itself, and use one packet for the entire page. Just got home, so I'll confirm that in a second here. Thanks dude :)

Edit: Okay, finally got to sit down. Anyway, it worked, thank you :) Here's my packet now
Code:
        public static byte[] MessageBoard(ChatType Board, int Page)
        {
            int TotalStringLength = 0;

            List<MessageBoardPost> Posts = new List<MessageBoardPost>();

            int PostsAdded = 0;
            int Skip = (Page * 10);
            foreach (MessageBoardPost Post in Program.MessageBoard.Values)
            {
                if (Skip > 0)
                {
                    Skip--;
                    continue;
                }
                Posts.Add(Post);
                PostsAdded++;
                TotalStringLength += (Post.Poster.Length + (Post.Message.Length > 50 ? 50 : Post.Message.Length) + Post.TimeStamp.Length);
                if (PostsAdded == 10) break;
            }

            Packet Packet = new Packet(10 + TotalStringLength + (3 * Posts.Count), 1111);
            Packet.Short(Page); // Assuming this is the page, since it does nothing atm.
            Packet.Short((int)Board); // The board type, aka TradeBoard, FriendBoard, ...
            Packet.Byte(3); // Flag - Should always be 3? 3=Send List
            Packet.Byte(3 * Posts.Count); // String Count
            foreach (MessageBoardPost Post in Posts)// If we wanted to display oldest first, we'd replace Posts with Posts.Reverse<MessageBoardPost>()
            {
                string Msg = Post.Message;
                if (Msg.Length > 50)
                    Msg = Msg.Substring(0, 50);
                Packet.String(Post.Poster, 0, true); // Poster's name
                Packet.String(Msg, 0, true); // The [truncated] message
                Packet.String(Post.TimeStamp, 0, true); // And the timestamp, YYYY-MM-DD-HH-MM
            }
            return Packet.Buffer; 
        }
Don't know if I'm going to fully implement pages yet, as I want it to sorta be where people sell things.
05/25/2012 01:32 12tails#4
Nice ^^

good luck with your server bro... if u need some other packet for lower patches.... just let me know .... cya!