public int Recieve()
{
try
{
_count = 0;
EndPoint endpoint = new IPEndPoint(address, _port);
byte[] rBuffer = new byte[500];
qSocket.ReceiveFrom(rBuffer, ref endpoint);
timestamp[1] = DateTime.Now;
using (MemoryStream stream = new MemoryStream(rBuffer))
{
using (BinaryReader reader = new BinaryReader(stream))
{
if (stream.Length <= 10)
return _count;
reader.ReadBytes(10);
switch (reader.ReadChar())
{
case 'i': // Information
{
results = new string[6];
results[_count++] = Convert.ToString(reader.ReadByte());
results[_count++] = Convert.ToString(reader.ReadInt16());
results[_count++] = Convert.ToString(reader.ReadInt16());
int hostnamelen = reader.ReadInt32();
results[_count++] = new string(reader.ReadChars(hostnamelen));
int gamemodelen = reader.ReadInt32();
results[_count++] = new string(reader.ReadChars(gamemodelen));
int mapnamelen = reader.ReadInt32();
results[_count++] = new string(reader.ReadChars(mapnamelen));
return _count;
}
case 'r': // Rules
{
int rulecount = reader.ReadInt16();
results = new string[rulecount * 2];
for (int i = 0; i < rulecount; i++)
{
int rulelen = reader.ReadByte();
results[_count++] = new string(reader.ReadChars(rulelen));
int valuelen = reader.ReadByte();
results[_count++] = new string(reader.ReadChars(valuelen));
}
return _count;
}
case 'c': // Client list
{
int playercount = reader.ReadInt16();
results = new string[playercount * 2];
for (int i = 0; i < playercount; i++)
{
int namelen = reader.ReadByte();
results[_count++] = new string(reader.ReadChars(namelen));
results[_count++] = Convert.ToString(reader.ReadInt32());
}
return _count;
}
case 'd': // Detailed player information
{
int playercount = reader.ReadInt16();
results = new string[playercount * 4];
for (int i = 0; i < playercount; i++)
{
results[_count++] = Convert.ToString(reader.ReadByte());
int namelen = reader.ReadByte();
results[_count++] = new string(reader.ReadChars(namelen));
results[_count++] = Convert.ToString(reader.ReadInt32());
results[_count++] = Convert.ToString(reader.ReadInt32());
}
return _count;
}
case 'p': // Ping
{
results = new string[1];
results[_count++] = timestamp[1].Subtract(timestamp[0]).Milliseconds.ToString();
return _count;
}
default:
return _count;
}
}
}
}
catch
{
return _count;
}
}