source code checkin

This commit is contained in:
Brett Hewitson 2021-01-07 16:23:23 +10:00
parent 5f8fb2c825
commit 7e57b72e35
675 changed files with 168433 additions and 0 deletions

View file

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QueryMaster
{
static class RconUtil
{
internal static byte[] GetBytes(RconSrcPacket packet)
{
byte[] command = Util.StringToBytes(packet.Body);
packet.Size = 10 + command.Length;
List<byte> y = new List<byte>(packet.Size + 4);
y.AddRange(BitConverter.GetBytes(packet.Size));
y.AddRange(BitConverter.GetBytes(packet.Id));
y.AddRange(BitConverter.GetBytes(packet.Type));
y.AddRange(command);
//part of string
y.Add(0x00);
//end terminater
y.Add(0x00);
return y.ToArray();
}
internal static RconSrcPacket ProcessPacket(byte[] data)
{
RconSrcPacket packet = new RconSrcPacket();
try
{
Parser parser = new Parser(data);
packet.Size = parser.ReadInt();
packet.Id = parser.ReadInt();
packet.Type = parser.ReadInt();
byte[] body = parser.GetUnParsedData();
if (body.Length == 2)
packet.Body = string.Empty;
else
{
packet.Body = Util.BytesToString(body).TrimEnd('\0', ' ');
}
}
catch (Exception e)
{
e.Data.Add("ReceivedData", data);
throw;
}
return packet;
}
}
}