Thema: Delphi Query an Gameserver

Einzelnen Beitrag anzeigen

Flodding

Registriert seit: 26. Dez 2007
Ort: Kiel
121 Beiträge
 
Turbo Delphi für Win32
 
#84

AW: Query an Gameserver

  Alt 25. Feb 2015, 15:32
Die Sekundenanzeige bei Der Playerinfo will auch nicht so ganz.

Delphi-Quellcode:
TPlayerResponse = record
  ResponseHeader: Integer;
  PacketHeader: Byte;
  Challenge: Integer;
  PlayerCount: Byte;
  PlayerIndex: Byte;
  PlayerName: String;
  PlayerScore: Integer;
  PlayerDuration: Integer;
end;
Delphi-Quellcode:
procedure Get_PLAYER_INFO;
var
  request: TInfoRequest;
  response: TPlayerResponse;
  buffer: TBufferArray;
  i: Integer;
  y: integer;
  PlayerList: TTreeNode;
begin
  request.RequestHeader := -1;
  request.PacketHeader := 'U';
  request.Payload := 'FFFFFFFF';

  Form1.udp1.BlockMode := bmNonBlocking;
  Form1.udp1.RemoteHost:= Form1.edit1.Text;
  Form1.udp1.RemotePort:= Form1.edit2.Text;
  Form1.udp1.Open;

  if (Form1.udp1.Connected) then
    begin
    Form1.Udp1.SendBuf(request, SizeOf(TInfoRequest));
    Form1.udp1.WaitForData(250);
    Form1.Udp1.ReceiveBuf(buffer, SizeOf(buffer));
    //Challenge aus Buffer lesen
    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.Challenge, SizeOf(response.Challenge)); inc(i, SizeOf(response.Challenge));
    if chr(response.PacketHeader) = 'Athen
      begin
      //Challende in den PayLoad schreiben
      request.Payload[0] := chr(buffer[5]);
      request.Payload[1] := chr(buffer[6]);
      request.Payload[2] := chr(buffer[7]);
      request.Payload[3] := chr(buffer[8]);
      //A2S_PLAYER request mit Challenge senden
      Form1.Udp1.SendBuf(request, SizeOf(TInfoRequest));
      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));
      if chr(response.PacketHeader) = 'Dthen
        begin
        Move(buffer[i], response.PlayerCount, SizeOf(response.PlayerCount)); inc(i, SizeOf(response.PlayerCount));
        Form1.TreeView1.Items.Clear;
        for y := 0 to response.PlayerCount - 1 do
          begin
          Move(buffer[i], response.PlayerIndex, SizeOf(response.PlayerIndex)); inc(i, SizeOf(response.PlayerIndex));
          response.PlayerName := GetString(buffer, i);
          Move(buffer[i], response.PlayerScore, SizeOf(response.PlayerScore)); inc(i, SizeOf(response.PlayerScore));
          Move(buffer[i], response.PlayerDuration, SizeOf(response.PlayerDuration)); inc(i, SizeOf(response.PlayerDuration));

          PlayerList := Form1.TreeView1.Items.Add(Nil, response.PlayerName);
          Form1.TreeView1.Items.AddChild(PlayerList, 'ID: ' + IntToStr(response.PlayerIndex));
          Form1.TreeView1.Items.AddChild(PlayerList, 'Kills: ' + IntToStr(response.PlayerScore));
          Form1.TreeView1.Items.AddChild(PlayerList, 'Seconds: ' + IntToStr(response.PlayerDuration));

          Application.ProcessMessages;
          end;
        end;
      end;
    end;
form1.TreeView1.FullExpand;
Form1.udp1.Active := false;
end;
Lese ich die Zeit flasch aus?
Flo
  Mit Zitat antworten Zitat