TInfoRequest =
packed record
RequestHeader: Integer;
PacketHeader: AnsiChar;
Payload:
array[0..19]
of AnsiChar;
end;
TInfoResponse =
record
ResponseHeader: Integer;
PacketHeader: Byte;
Protocol: Byte;
Name:
String;
Map:
String;
Folder:
String;
Game:
String;
ID: SmallInt;
Players: Byte;
MaxPlayers: Byte;
Bots: Byte;
ServerType: Byte;
Environment: Byte;
Visibility: Byte;
VAC: Byte;
Version:
String;
end;
TBufferArray =
array[0..1400]
of Byte;
function GetString(aBuffer: TBufferArray;
var aIndex: Integer):
String;
var
b: Byte;
begin
result := '
';
repeat
Move(aBuffer[aIndex], b, SizeOf(b));
if b <> 0
then
result := result + IntToStr(b);
inc(aIndex);
until b = 0;
end;
procedure GetInfo;
var
request: TInfoRequest;
response: TInfoResponse;
buffer: TBufferArray;
i: Integer;
begin
request.RequestHeader := -1;
request.PacketHeader := '
T';
request.Payload := '
Source Engine Query';
// Von mir aus auch mit einer Konstante oder einem Ressourcestring
request.Payload[19] := #0;
Udp1.SendBuf(request, SizeOf(TInfoRequest));
Udp1.ReceiveBuf(buffer, SizeOf(buffer));
i := 0;
Move(buffer[i], response.ResponseHeader, SizeOf(response.ResponseHeader)); inc(i, SizeOf(response.ResponseHeader));
Move(buffer[i], response.PacketHeader, SizeOf(response.PacketHeader)); inc(i, SizeOf(response.PacketHeader));
Move(buffer[i], response.Protocol, SizeOf(response.Protocol)); inc(i, SizeOf(response.Protocol));
response.
Name := GetString(buffer, i);
response.Map := GetString(buffer, i);
response.Folder := GetString(buffer, i);
response.Game := GetString(buffer, i);
Move(buffer[i], response.ID, SizeOf(response.ID)); inc(i, SizeOf(response.ID));
Move(buffer[i], response.Players, SizeOf(response.Players)); inc(i, SizeOf(response.Players));
Move(buffer[i], response.MaxPlayers, SizeOf(response.MaxPlayers)); inc(i, SizeOf(response.MaxPlayers));
Move(buffer[i], response.Bots, SizeOf(response.Bots)); inc(i, SizeOf(response.Bots));
Move(buffer[i], response.ServerType, SizeOf(response.ServerType)); inc(i, SizeOf(response.ServerType));
Move(buffer[i], response.Environment, SizeOf(response.Environment)); inc(i, SizeOf(response.Environment));
Move(buffer[i], response.Visibility, SizeOf(response.Visibility)); inc(i, SizeOf(response.Visibility));
Move(buffer[i], response.VAC, SizeOf(response.VAC)); inc(i, SizeOf(response.VAC));
response.Version := GetString(buffer, i);
// In response steht jetzt alles richtig schön drin. Nicht als Hexkacke, sondern sauber als der Typ, den Valve vorgibt.
end;