Danke für den Hinweis mit dem Leeren des Buffers. Leider hat dies noch nicht zum Erfolg geführt.
FillChar(buffer, SizeOf(buffer), 0);
Nachdem ich das ganze ein wenig überarbeitet habe, komme ich nun wenigstens schonmal zu einem sicheren Ergebnis. Ich bekomme immer exakt 2 Mal die selbe Liste (geplant -> y - Vaiable) obwohl ich die
IP Adresse im "response" ändere.
Hier erstmal der Code:
Delphi-Quellcode:
procedure Get_SERVER_LIST();
var
request : TServerListRequest;
response : TServerListResponse;
buffer : TBufferArray;
i : Integer;
y : Integer;
new_a1 : byte;
new_a2 : byte;
new_a3 : byte;
new_a4 : byte;
new_a5 : word;
old_a1 : byte;
old_a2 : byte;
old_a3 : byte;
old_a4 : byte;
old_a5 : word;
old_seed : String;
new_seed : String;
begin
old_a1 := 30;
old_a2 := 30;
old_a3 := 30;
old_a4 := 30;
old_a5 := 3030;
// \gamedir\arma2arrowpc
// 31 FF 30 2e 30 2e 30 2e 30 3a 30 00 5c 67 61 6d 65 64 69 72 5c 61 72 6d 61 32 61 72 72 6f 77 70 63 00
// \gamedir\arma3
// 31 ff 30 2e 30 2e 30 2e 30 3a 30 00 5c 67 61 6d 65 64 69 72 5c 61 72 6d 61 33
Form1.udp1.BlockMode := bmNonBlocking;
Form1.udp1.RemoteHost := 'hl2master.steampowered.com';
Form1.udp1.RemotePort := '27011';
form1.udp1.Open;
y := 0;
form1.ListBox1.Clear;
if (Form1.udp1.Connected) then
begin
repeat
request.RequestHeader := $31;
request.PacketHeader := $FF;
request.First := old_a1;
request.First_dot := $2E;
request.Second := old_a2;
request.Second_dot := $2E;
request.Third := old_a3;
request.Third_dot := $2E;
request.Fourth := old_a4;
request.double_dot := $3A;
request.Port := old_a5;
request.Payload[0] := $00;
request.Payload[1] := $5C;
request.Payload[2] := $67;
request.Payload[3] := $61;
request.Payload[4] := $6D;
request.Payload[5] := $65;
request.Payload[6] := $64;
request.Payload[7] := $69;
request.Payload[8] := $72;
request.Payload[9] := $5C;
request.Payload[10] := $61;
request.Payload[11] := $72;
request.Payload[12] := $6D;
request.Payload[13] := $61;
request.Payload[14] := $33;
request.Payload[15] := $00;
Form1.Udp1.SendBuf(request, SizeOf(request));
Form1.udp1.WaitForData(250);
Form1.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));
repeat
Move(buffer[i], response.First, SizeOf(response.First)); inc(i, SizeOf(response.First));
Move(buffer[i], response.Second, SizeOf(response.Second)); inc(i, SizeOf(response.Second));
Move(buffer[i], response.Third, SizeOf(response.Third)); inc(i, SizeOf(response.Third));
Move(buffer[i], response.Fourth, SizeOf(response.Fourth)); inc(i, SizeOf(response.Fourth));
Response.Port := Buffer[i] * 256 + Buffer[i+1]; Inc(i, SizeOf(Response.Port)); // Weil die Bytes vertauscht sind, müssen sie umgedreht werden für ein richtiges
new_a1 := response.First;
new_a2 := response.Second;
new_a3 := response.Third;
new_a4 := response.Fourth;
new_a5 := response.Port;
new_seed := IntToStr(new_a1) + IntToStr(new_a2) + IntToStr(new_a3) + IntToStr(new_a4) + IntToStr(new_a5);
if (new_seed <> '00000') then
begin
form1.duplicatcounter := 0;
Form1.ListBox1.Items.Add ((IntToStr(new_a1)) + '.' + (IntToStr(new_a2)) + '.' + (IntToStr(new_a3)) + '.' + (IntToStr(new_a4)) + ':' + IntToStr((new_a5)) );
old_a1 := new_a1;
old_a2 := new_a2;
old_a3 := new_a3;
old_a4 := new_a4;
old_a5 := new_a5;
old_seed := IntToStr(old_a1) + IntToStr(old_a2) + IntToStr(old_a3) + IntToStr(old_a4) + IntToStr(new_a5);
Application.ProcessMessages;
end
else
begin
Form1.duplicatcounter := form1.duplicatcounter + 1;
end;
until form1.duplicatcounter = 1;
y := y + 1;
Form1.ListBox1.Items.Add ('---------------');
Form1.ListBox1.Items.Add ('---------------');
Form1.ListBox1.Items.Add ('NewSeed: ' + new_seed);
Form1.ListBox1.Items.Add ('OldSeed: ' + old_seed);
Form1.ListBox1.Items.Add ('---------------');
Form1.ListBox1.Items.Add ('---------------');
FillChar(Buffer, SizeOf(buffer), 0); // Buffer leeren
until y = 2;
end;
Form1.udp1.Close;
form1.Caption := 'Servers: ' + inttostr(Form1.ListBox1.Items.Count -1);
end;
Mir scheint ich hab immernoch ein Problem damit die empfangenen Bytes für die
IP und das Word für den Port richtig zu übergeben.