var
NMUDP1: TNMUDP;
procedure DoUpdate;
var
TmpStr:
String;
buffer:
array[0..25]
of Char;
I:Integer;
Begin
NMUDP1.ReportLevel := Status_Basic;
NMUDP1.RemoteHost := '
irgendeine IP';
NMUDP1.RemotePort := '
meistens irgendwas mit 27000';
// Sende 4x Das Char 255 und dann 'details' und am Ende Char 0
TmpStr := Chr(255)+Chr(255)+Chr(255)+Chr(255)+'
details'+Chr(0);
For i:= 1
to Length(TMPStr)
do
buffer[i-1]:=tmpstr[i];
NMUDP1.SendBuffer(buffer,Length(TmpStr));
// Sende 4x Das Char 255 und dann 'players' und am Ende Char 0
TmpStr := Chr(255)+Chr(255)+Chr(255)+Chr(255)+'
players'+Chr(0);
For i:= 1
to Length(TMPStr)
do
buffer[i-1]:=tmpstr[i];
NMUDP1.SendBuffer(buffer,Length(TmpStr));
// Sende 4x Das Char 255 und dann 'rules' und am Ende Char 0
TmpStr := Chr(255)+Chr(255)+Chr(255)+Chr(255)+'
rules'+Chr(0);
For i:= 1
to Length(TMPStr)
do
buffer[i-1]:=tmpstr[i];
NMUDP1.SendBuffer(buffer,Length(TmpStr));
end;
// Und zum auswerten:
procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP:
String; Port: Integer);
var
MyStream: TMemoryStream;
TmpStr,TmpStr2:
String;
buffer:
array[0..2048]
of Char;
I,j:Integer;
ID,styp,
os:Char;
mccount,ccount,count,pv,pass:Word;
pfrag:longInt;
ptime:single;
tfrag:longint;
begin
NMUDP1.ReadBuffer(buffer, NumberBytes);
ID:=buffer[4];
case ID
of
'
D':
begin
//No. of Players ub ein Stringgrid namens "pl"
i:=0; J:=5;tfrag:=0;
pl.RowCount:=2; pl.cells[0,1]:='
'; pl.cells[1,1]:='
';
count:=Ord(buffer[J]); J:=7;
if count > 0
then begin
repeat
tmpstr:='
'; pfrag:=0;
While buffer[j] <> Chr(0)
do
begin
tmpstr:=tmpStr+buffer[j];
Inc(j);
end;
J:=j+10;
// Ein kleiner "Workaround" für Frags <= 0
pfrag:=Ord(buffer[j-9]);
if Ord(buffer[j-8])=255
then
pfrag:=pfrag -256; tfrag:=tfrag+pfrag;
inc(i);
pl.cells[0,I]:=IntToStr(pfrag);
pl.cells[1,I]:=tmpStr;
pl.RowCount:=I+1;
until I =count;
end;
DoSort;
end;
'
E':
begin // jetzt kommen Serverdaten, also RULES
i:=0; J:=5;
// im Format "variable=irgendwas"
count:=Ord(buffer[J])+Ord(buffer[j+1])*256; J:=7;
if count > 0
then begin
repeat
tmpstr:='
';
tmpstr2:='
';
While buffer[j] <> Chr(0)
do
begin
tmpstr:=tmpStr+buffer[j];
Inc(j);
end;
Inc(J);
rg.Cells[0,i+1]:=tmpstr;
While buffer[j] <> Chr(0)
do
begin
tmpstr2:=tmpStr2+buffer[j];
Inc(j);
end;
rg.Cells[1,i+1]:=tmpstr2;
if tmpstr='
sv_contact'
then // steht da Punkbuster drin?
If Pos('
{PB',tmpStr2)> 0
then
// pbimg.Visible:=True else pbimg.Visible:=False;
Inc(j);
Inc(I);
until I =count;
rg.RowCount:=count+1;
end;
end;
'
m':
begin // Server-Kurzinfo
J:=5; I:=0;
repeat
INC(I);
tmpstr:='
';
While buffer[j] <> Chr(0)
do
begin
tmpstr:=tmpStr+buffer[j];
Inc(j);
end;
Inc(J);
case I
of
2: form1.Caption:='
go2bf - '+tmpStr;
3: status.caption:='
Map: '+tmpstr;
//if lmap.Caption <> tmpstr then
4:
begin lmod.caption:=tmpstr; status.caption:=status.caption+'
Mod: '+tmpstr;
end;
end;
until I=5;
ccount:=Ord(buffer[J]);Inc(J);
mccount:=Ord(buffer[J]);Inc(J);
status.caption:=status.caption+'
Spieler: '+IntToStr(ccount)+'
/'+IntToStr(mccount);
if ccount=mccount
then full.Visible:=True
else
full.Visible:=False;
// Protocol Version - unused
// pv:=Ord(buffer[J]);
Inc(J);
styp:=buffer[J];Inc(J);
os:=buffer[J];Inc(J);
case styp
of // Servertyp
'
d': tmpstr:='
Dedicated';
'
l': tmpstr:='
Listen ';
end;
{ case os of // OS => w=windows l=linux
'w': begin osimg.Visible:=true; osimg.hint:=tmpstr; end;
'l': begin osimg2.Visible:=true; osimg2.hint:=tmpstr; end;
end;
osimg.visible:=True;}
pass:=Ord(buffer[J]);
if pass=1
then // Passwort?
begin
pw.visible:=true;
labelpassw.Visible:=true;
passw.visible:=true;
end else
begin
pw.Visible:=false;
labelpassw.Visible:=False;
passw.Visible:=false;
end;
end;
end;
end;