如何修复此服务器查询样本?

时间:2019-04-24 23:23:03

标签: delphi

我正在尝试在Samp中实现查询机制。我写了代码,但是不能正常工作。我试图从数据包“ i”中获取所有信息。 我正在使用该网站获取有关我的一些信息 问题。不幸的是我还不够了解。 https://wiki.sa-mp.com/wiki/Query/Request#Recieving_the_packets

主要问题是,我不能从maxplayers中获得超过126名的玩家。 我意识到这是ASCII可打印的最大索引 字符。

unit Unit6;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IdBaseComponent,
  IdComponent, IdUDPBase, IdUDPClient, IdIPWatch;

type
  TForm6 = class(TForm)
    StrList: TMemo;
    UDPClient: TIdUDPClient;
    Button1: TButton;
    IdIPWatch1: TIdIPWatch;
    hostname: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form6: TForm6;

const
ip: string = '109.230.228.151';
port: integer = 7777;

implementation

{$R *.dfm}

procedure TForm6.Button1Click(Sender: TObject);
var
Players,MaxPlayers,receivedstring,kopreceivedstring,kopreceivedstring2,Buffer:string;
stringlen,stringlenfromtext:integer;
begin
  StrList.Lines.Text:= ip;
  StrList.Lines.Text:=StringReplace(StrList.Lines.Text, '.', #13, [rfReplaceAll]);
  Buffer := 'SAMP' + Chr(StrToIntDef(StrList.Lines[0], 100)) + Chr(StrToIntDef(StrList.Lines[1], 100)) + Chr(StrToIntDef(StrList.Lines[2], 100)) + Chr(StrToIntDef(StrList.Lines[3], 100));
  Buffer := Buffer + Chr(port and 255) + Chr((port shr 8) and 255)+ 'i';

    UDPClient.Host:=IdIPWatch1.LocalIP;
    UDPClient:= TIdUDPClient.Create(self);
    UDPClient.Active := True;
    UDPClient.Send(ip,port,Buffer);
    UDPClient.ReceiveTimeout := 1500;
    receivedstring:=UDPClient.ReceiveString();
      if (receivedstring<>'') then
      begin
      kopreceivedstring:=receivedstring;
      kopreceivedstring2:=kopreceivedstring;
      Delete(receivedstring, 1, 1);
      Delete(kopreceivedstring,1,1);
      Delete(kopreceivedstring2,1,1);
        Players:=receivedstring;
        MaxPlayers:=receivedstring;
      label3.Caption:= inttostr(ord(Players[12]))+' / '+inttostr(ord(MaxPlayers[14]));
      stringlen:= ord(kopreceivedstring[16]);
      Delete(receivedstring, 1, Length(receivedstring[4])+18);
      hostname.Caption:=receivedstring;
        //gamemode
        Delete(kopreceivedstring,1,length(kopreceivedstring[4])+22+stringlen);
         label1.Caption:=kopreceivedstring;
         stringlenfromtext:=label1.GetTextLen;
        //Language
        Delete(kopreceivedstring2,1,length(kopreceivedstring2[4])+25+stringlenfromtext+stringlen);
        label2.Caption:=kopreceivedstring2;
      UDPClient.Active := False;
      UDPClient.Free;
  end;
end;

end.

Picture of result!

我尝试找球员,正确的是0 / 500,但是我得到了0 / 65533 如果你们能解释它的工作原理,我将非常高兴。

0 个答案:

没有答案