MWF2 RCON TOOL 使用 indyUDP 与 delphi 通信
MWF2 RCON TOOL Communication with delphi using indyUDP
Modern Warefare 2 (MWF2):是一款视频游戏。
RCON TOOL: 是一个使用 UDP 向游戏服务器发送命令的工具。
我正在尝试使用 indy 向服务器发送命令,使用 idUDPclient 发送一些字符串很容易,但我的问题是
我应该以这种格式发送它:
ÿÿÿÿrcon "1234" kick cheater101
where :-
password quoted: "1234"
and command is : kick cheater101
像这样的字节
FFFFFFFF72636F6E2020223132333422206B69636B2063686561746572313031
注意发送的任何内容都必须以 FFFFFFFF 开头
以及它在 Wireshark 中的外观..
问题是我不能像上面那样发送..我只是像字符串一样发送..
我需要用 indyUDP 制作它,因为我打算在 android 上测试它。
这是我正在尝试的代码:
function rcon(const IP: String; Port: TIdPort; const Pass, Command: String): String;
var
Query: TIdBytes;
Buffer, Data:
TIdBytes;
Len: Integer;
begin
SetLength(Query, 4);
Query[0] := $FF;
Query[1] := $FF;
Query[2] := $FF;
Query[3] := $FF;
AppendString(Query, 'rcon "' + Pass + '" ' + Command);
SetLength(Data, 0);
with TIdUDPClient.Create do try ReceiveTimeout := 2000;
SendBuffer(IP, Port, Query);
repeat SetLength(Buffer, 10000);
Len := ReceiveBuffer(Buffer);
if Len < 1 then Break;
SetLength(Buffer, Len);
AppendBytes(Data, Buffer);
until False; finally Free;
end; // preprocess Data as needed... Result := BytesToString(Data);
end
用法!
rcon('10.0.0.4', 28961, '1234', 'kick cheater101');
Wireshark:
这行得通,它会 return 正确的字节数组(无论如何作为 AnsiString)!。我使用格式来组合输入,并在前面加上 FFFFFFFFs
Function MakeKickCommand(pass, user: LPCSTR): AnsiString; //is wide strings okay
var
Temp : AnsiString;
len, I: integer;
a: integer;
Begin
Temp:= AnsiString( format('rcon "%s" kick %s', [pass, user]) );
len := length(Temp);
//set length of the result
SetLength(Result, 4+len);
//add FF FF FF FF
FillChar (Result[1], 4, $FF);
//copy the formatted string
Move(Temp[1], Result[5], len);
End;
您遇到的是 DISPLAY 问题,而不是 DATA 问题。在您的 Wireshark 屏幕截图中,您正在按原样查看 原始字节 ,而不是那些相同字节的 十六进制格式表示 。 Wireshark 可以向您展示两者。
您发送的实际字节没有问题 - 除了您在 rcon
和引用的密码之间缺少 2nd space 字符。
function rcon(const IP: String; Port: TIdPort; const Pass, Command: String): String;
var
Query: TIdBytes;
Buffer, Data: TIdBytes;
Len: Integer;
begin
SetLength(Query, 4);
FillBytes(Query, 4, $FF);
AppendString(Query, 'rcon "' + Pass + '" ' + Command);
SetLength(Data, 0);
with TIdUDPClient.Create do
try
SendBuffer(IP, Port, Query);
ReceiveTimeout := 2000;
SetLength(Buffer, 10000);
repeat
Len := ReceiveBuffer(Buffer);
if Len < 1 then Break;
AppendBytes(Data, Buffer, 0, Len);
until False;
finally
Free;
end;
// preprocess Data as needed...
Result := BytesToString(Data);
end;
此外,在您的 Wireshark 屏幕截图中,它清楚地显示了为每个命令发送的 70 个字节,其中命令本身为 32 个字节,其余为 38 个字节的填充。如果服务器需要填充,则需要将其添加到传出 Query
:
function rcon(const IP: String; Port: TIdPort; const Pass, Command: String): String;
var
Query: TIdBytes;
Buffer, Data: TIdBytes;
Len: Integer;
begin
SetLength(Query, 4);
FillBytes(Query, 4, $FF);
AppendString(Query, 'rcon "' + Pass + '" ' + Command);
if (Length(Query) < 70) then
ExpandBytes(Query, Length(Query), 70-Length(Query));
SetLength(Data, 0);
with TIdUDPClient.Create do
try
SendBuffer(IP, Port, Query);
ReceiveTimeout := 2000;
SetLength(Buffer, 10000);
repeat
Len := ReceiveBuffer(Buffer);
if Len < 1 then Break;
AppendBytes(Data, Buffer, 0, Len);
until False;
finally
Free;
end;
// preprocess Data as needed...
Result := BytesToString(Data);
end;
Modern Warefare 2 (MWF2):是一款视频游戏。 RCON TOOL: 是一个使用 UDP 向游戏服务器发送命令的工具。
我正在尝试使用 indy 向服务器发送命令,使用 idUDPclient 发送一些字符串很容易,但我的问题是 我应该以这种格式发送它:
ÿÿÿÿrcon "1234" kick cheater101
where :-
password quoted: "1234"
and command is : kick cheater101
像这样的字节
FFFFFFFF72636F6E2020223132333422206B69636B2063686561746572313031
注意发送的任何内容都必须以 FFFFFFFF 开头
以及它在 Wireshark 中的外观..
问题是我不能像上面那样发送..我只是像字符串一样发送..
我需要用 indyUDP 制作它,因为我打算在 android 上测试它。
这是我正在尝试的代码:
function rcon(const IP: String; Port: TIdPort; const Pass, Command: String): String;
var
Query: TIdBytes;
Buffer, Data:
TIdBytes;
Len: Integer;
begin
SetLength(Query, 4);
Query[0] := $FF;
Query[1] := $FF;
Query[2] := $FF;
Query[3] := $FF;
AppendString(Query, 'rcon "' + Pass + '" ' + Command);
SetLength(Data, 0);
with TIdUDPClient.Create do try ReceiveTimeout := 2000;
SendBuffer(IP, Port, Query);
repeat SetLength(Buffer, 10000);
Len := ReceiveBuffer(Buffer);
if Len < 1 then Break;
SetLength(Buffer, Len);
AppendBytes(Data, Buffer);
until False; finally Free;
end; // preprocess Data as needed... Result := BytesToString(Data);
end
用法!
rcon('10.0.0.4', 28961, '1234', 'kick cheater101');
Wireshark:
这行得通,它会 return 正确的字节数组(无论如何作为 AnsiString)!。我使用格式来组合输入,并在前面加上 FFFFFFFFs
Function MakeKickCommand(pass, user: LPCSTR): AnsiString; //is wide strings okay
var
Temp : AnsiString;
len, I: integer;
a: integer;
Begin
Temp:= AnsiString( format('rcon "%s" kick %s', [pass, user]) );
len := length(Temp);
//set length of the result
SetLength(Result, 4+len);
//add FF FF FF FF
FillChar (Result[1], 4, $FF);
//copy the formatted string
Move(Temp[1], Result[5], len);
End;
您遇到的是 DISPLAY 问题,而不是 DATA 问题。在您的 Wireshark 屏幕截图中,您正在按原样查看 原始字节 ,而不是那些相同字节的 十六进制格式表示 。 Wireshark 可以向您展示两者。
您发送的实际字节没有问题 - 除了您在 rcon
和引用的密码之间缺少 2nd space 字符。
function rcon(const IP: String; Port: TIdPort; const Pass, Command: String): String;
var
Query: TIdBytes;
Buffer, Data: TIdBytes;
Len: Integer;
begin
SetLength(Query, 4);
FillBytes(Query, 4, $FF);
AppendString(Query, 'rcon "' + Pass + '" ' + Command);
SetLength(Data, 0);
with TIdUDPClient.Create do
try
SendBuffer(IP, Port, Query);
ReceiveTimeout := 2000;
SetLength(Buffer, 10000);
repeat
Len := ReceiveBuffer(Buffer);
if Len < 1 then Break;
AppendBytes(Data, Buffer, 0, Len);
until False;
finally
Free;
end;
// preprocess Data as needed...
Result := BytesToString(Data);
end;
此外,在您的 Wireshark 屏幕截图中,它清楚地显示了为每个命令发送的 70 个字节,其中命令本身为 32 个字节,其余为 38 个字节的填充。如果服务器需要填充,则需要将其添加到传出 Query
:
function rcon(const IP: String; Port: TIdPort; const Pass, Command: String): String;
var
Query: TIdBytes;
Buffer, Data: TIdBytes;
Len: Integer;
begin
SetLength(Query, 4);
FillBytes(Query, 4, $FF);
AppendString(Query, 'rcon "' + Pass + '" ' + Command);
if (Length(Query) < 70) then
ExpandBytes(Query, Length(Query), 70-Length(Query));
SetLength(Data, 0);
with TIdUDPClient.Create do
try
SendBuffer(IP, Port, Query);
ReceiveTimeout := 2000;
SetLength(Buffer, 10000);
repeat
Len := ReceiveBuffer(Buffer);
if Len < 1 then Break;
AppendBytes(Data, Buffer, 0, Len);
until False;
finally
Free;
end;
// preprocess Data as needed...
Result := BytesToString(Data);
end;