i wont take much of your time. But im working on a gameserver, sometimes when data has been sent ( packets ) i get this error "Index was outside the bounds of the array".
This is how my code looks like:
internal void HandleConnectionData(ref byte[] data)
{
if (data[0] == 64)
{
int pos = 0;
while (pos < data.Length)
{
try
{
int MessageLength = Base64Encoding.DecodeInt32(new byte[] { data[pos++], data[pos++], data[pos++] });
uint MessageId = Base64Encoding.DecodeUInt32(new byte[] { data[pos++], data[pos++] });
byte[] Content = new byte[MessageLength - 2];
for (int i = 0; i < Content.Length; i++)
{
Content[i] = data[pos++];
}
ClientMessage Message = new ClientMessage(MessageId, Content);
if (MessageHandler == null)
{
InitHandler(); //Never ever register the packets BEFORE you receive any data.
}
//DateTime PacketMsgStart = DateTime.Now;
try
{
MessageHandler.HandleRequest(Message);
}
catch (Exception e) { Logging.LogPacketException(Message.ToString(), e.ToString()); }
}
catch (Exception e)
{
Logging.HandleException(e, "packet handling");
Disconnect();
}
}
}
else
{
Connection.SendData(CrossdomainPolicy.GetXmlPolicy());
Connection.Disposes();
}
}
Any ideas? thank you.