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.
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 :]
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 :]
public class MessageBoard
{
COClient Client = null;
byte[] Data = null;
public MessageBoard(byte[] data, COClient client)
{
Client = client;
Data = data;
}
int MessUID = 1;
int MessageBoardUID
{
get
{
if (MessUID + 1 == int.MaxValue) MessUID = 0;
while (WorldKernel.MessageBoards.ContainsKey(MessUID))
MessUID++;
return MessUID;
}
}
public void getBoard()
{
try
{
int BoardType = PacketHandler.ReadShort(Data, 6);
int Page = Data[4];
int SubPage = Data[5];
int Type = Data[8];
string Name = "";
#region GetName
if (Type == 4 && Data.Length > 10)
{
for (int i = 11; i < 11 + Data[10]; i++)
Name += Convert.ToChar(Data[i]);
}
#endregion
if (Type == 1)
{
#region Delete Message
try
{
foreach (MessageBoardData Board in WorldKernel.MessageBoards.Values)
{
if (Board.BoardType == BoardType && Board.CharID == Client.Char.id)
{
WorldKernel.MessageBoards.ThreadSafeRemove(Board.UID);
Client.SendData(COPackets.Packet1004("System", Client.Char.name, "Message deleted.", ChatType.Top, ChatColor.Red));
break;
}
}
}
catch { }
#endregion
}
else if (Type == 4)
{
#region View Message
try
{
foreach (MessageBoardData Board in WorldKernel.MessageBoards.Values)
{
if (Board.BoardType == BoardType && Board.From == Name)
{
Client.SendData(COPackets.Packet1004(Board.From, "ALLUSERS", Board.Message, (ChatType)Board.BoardType, ChatColor.White));
break;
}
}
}
catch { }
#endregion
}
Client.SendData(COPackets.Packet1111(Page, BoardType));
}
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
}
public void newBoard(COClient Client, string From, string Message, int BoardType)
{
try
{
if (Client.Char.level < 16)
{
Client.SendData(COPackets.Packet1004("System", Client.Char.name, "Your level is not enough, you need to be at last level 16!", ChatType.Top, ChatColor.Red));
return;
}
if (Message.Length < 1 || Message.Length > 16)
{
Client.SendData(COPackets.Packet1004("System", Client.Char.name, "Sorry! The minimum message length is 1 and the maximum is 16.", ChatType.Top, ChatColor.Red));
return;
}
MessageBoardData MyBoard = null;
foreach (MessageBoardData Board in WorldKernel.MessageBoards.Values)
{
if (Board.BoardType == BoardType && Board.CharID == Client.Char.id)
{
MyBoard = Board;
break;
}
}
if (MyBoard == null)//new
{
#region Write New
MyBoard = new MessageBoardData();
MyBoard.CharID = Client.Char.id;
MyBoard.BoardType = BoardType;
MyBoard.From = From;
MyBoard.Message = Message;
MyBoard.SendAt = String.Format("{0:yyyyMMddHHmm}", DateTime.Now);
tryy:
MyBoard.UID = MessageBoardUID;
if (!WorldKernel.MessageBoards.ContainsKey(MyBoard.UID))
WorldKernel.MessageBoards.ThreadSafeAdd(MyBoard.UID, MyBoard);
else
goto tryy;
#endregion
}
else//replace
{
#region Replace old
WorldKernel.MessageBoards.ThreadSafeRemove(MyBoard.UID);
MyBoard = new MessageBoardData();
MyBoard.CharID = Client.Char.id;
MyBoard.BoardType = BoardType;
MyBoard.From = From;
MyBoard.Message = Message;
MyBoard.SendAt = String.Format("{0:yyyyMMddHHmm}", DateTime.Now);
tryy:
MyBoard.UID = MessageBoardUID;
if (!WorldKernel.MessageBoards.ContainsKey(MyBoard.UID))
WorldKernel.MessageBoards.ThreadSafeAdd(MyBoard.UID, MyBoard);
else
goto tryy;
#endregion
}
Client.SendData(COPackets.Packet1111(0, BoardType));
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
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.
MessageBoard PacketID? 07/26/2009 - CO2 Private Server - 5 Replies Heya.
Was just wondering if anyone has the messageboard packetid to make a text be written in the messageboard. I got so far that I can get what message the user inputs in the window, but not sure how to get it to write a text in the board.
Thanks.