private static void HandleMessage(NetMessageType type, NetConnection source, NetBuffer buffer)
{
switch (type)
{
case NetMessageType.DebugMessage:
WriteToConsole(buffer.ReadString());
break;
case NetMessageType.StatusChanged:
WriteToConsole("New status: " + source.Status + " (" + buffer.ReadString() + ")");
UpdateStatisticsDisplay(source);
break;
case NetMessageType.Data:
//System.IO.File.AppendAllText("C:\\receivedpackets.txt", s_userMessagesReceived.ToString() + ": " + msg.ReadString() + " (" + msg.m_sequenceNumber + ")" + Environment.NewLine);
s_userMessagesReceived++;
// simulate some processing of the message here
for (int i = 0; i < buffer.LengthBytes - 2; i++)
buffer.ReadByte();
// check checksum
ushort checksum = NetChecksum.Adler16(buffer.Data, 0, buffer.LengthBytes - 2);
ushort given = buffer.ReadUInt16();
if (checksum != given)
WriteToConsole("Wrong checksum! Expected " + checksum + " found given " + given);
double b = s_userMessagesReceived;
for (int i = 0; i < 1000; i++)
b += Math.Sqrt((double)i) / Math.Sin(s_tmp);
s_tmp += b / 10000.0;
break;
default:
break;
}
}