|
You last visited: Today at 03:50
Advertisement
MessageBoard
Discussion on MessageBoard within the CO2 Private Server forum part of the Conquer Online 2 category.
05/24/2012, 18:36
|
#1
|
elite*gold: 0
Join Date: May 2008
Posts: 1,769
Received Thanks: 1,143
|
MessageBoard
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
|
#2
|
elite*gold: 0
Join Date: Apr 2009
Posts: 782
Received Thanks: 458
|
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:
Code:
public static byte[] Packet1111(int Page, int BoardType)
{
int Amount = 0;
int ToPage = (Page + 8);
int Calc = 0;
int MaxSize = 0;
#region Get Current Board at Page
Dictionary<int, MessageBoardData> SaveBoard = new Dictionary<int, MessageBoardData>();
foreach (MessageBoardData TheBoard in WorldKernel.MessageBoards.Values)
{
if (TheBoard.BoardType == BoardType)
{
if (Calc >= Page)
{
if (Calc < ToPage)
{
SaveBoard.ThreadSafeAdd(TheBoard.UID, TheBoard);
MaxSize += TheBoard.From.Length + TheBoard.Message.Length + TheBoard.SendAt.Length;
Amount++;
}
}
Calc++;
}
}
#endregion
COPackets Packet = new COPackets(new byte[(10 + (Amount * 3) + MaxSize)]);
Packet.Short(Packet.Packet.Length);
Packet.Short(1111);
Packet.Short(0);
Packet.Short((ushort)BoardType);
Packet.Byte(3);//strings amount
Packet.Byte((byte)(Amount * 3));//strings amount
tryy:
int Pos = 0;
foreach (MessageBoardData TheBoard in SaveBoard.Values)
{
Pos++;
if (Pos == SaveBoard.Count)
{
Packet.StringWithLength(TheBoard.From);
Packet.StringWithLength(TheBoard.Message);
Packet.StringWithLength(TheBoard.SendAt);
SaveBoard.ThreadSafeRemove(TheBoard.UID);
goto tryy;
}
}
return Packet.Packet;
}
Handler:
Code:
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());
}
}
}
|
|
|
05/25/2012, 00:39
|
#3
|
elite*gold: 0
Join Date: May 2008
Posts: 1,769
Received Thanks: 1,143
|
Quote:
Originally Posted by 12tails
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:
Code:
public static byte[] Packet1111(int Page, int BoardType)
{
int Amount = 0;
int ToPage = (Page + 8);
int Calc = 0;
int MaxSize = 0;
#region Get Current Board at Page
Dictionary<int, MessageBoardData> SaveBoard = new Dictionary<int, MessageBoardData>();
foreach (MessageBoardData TheBoard in WorldKernel.MessageBoards.Values)
{
if (TheBoard.BoardType == BoardType)
{
if (Calc >= Page)
{
if (Calc < ToPage)
{
SaveBoard.ThreadSafeAdd(TheBoard.UID, TheBoard);
MaxSize += TheBoard.From.Length + TheBoard.Message.Length + TheBoard.SendAt.Length;
Amount++;
}
}
Calc++;
}
}
#endregion
COPackets Packet = new COPackets(new byte[(10 + (Amount * 3) + MaxSize)]);
Packet.Short(Packet.Packet.Length);
Packet.Short(1111);
Packet.Short(0);
Packet.Short((ushort)BoardType);
Packet.Byte(3);//strings amount
Packet.Byte((byte)(Amount * 3));//strings amount
tryy:
int Pos = 0;
foreach (MessageBoardData TheBoard in SaveBoard.Values)
{
Pos++;
if (Pos == SaveBoard.Count)
{
Packet.StringWithLength(TheBoard.From);
Packet.StringWithLength(TheBoard.Message);
Packet.StringWithLength(TheBoard.SendAt);
SaveBoard.ThreadSafeRemove(TheBoard.UID);
goto tryy;
}
}
return Packet.Packet;
}
Handler:
Code:
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.
|
|
|
05/25/2012, 01:32
|
#4
|
elite*gold: 0
Join Date: Apr 2009
Posts: 782
Received Thanks: 458
|
Nice ^^
good luck with your server bro... if u need some other packet for lower patches.... just let me know .... cya!
|
|
|
Similar Threads
|
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.
|
All times are GMT +1. The time now is 03:51.
|
|