I'm working on a tool which receives packets from phconnector and send again to phconnector. I was working on getting charlist, getting mp/hp of the char when its loaded and they are done. However recently i cannot capture the packet '3020'. I was able to catch it but now i'm not able to do it again.
PHP Code:
data := stringtohex(socket.ReceiveText); //where i receive whole packet
data := stringreplace(data, ' ', '', [rfReplaceAll]); //delete all spaces
size := hexatoint(copy(data,3,2)+copy(data, 1, 2)); //get the size
opcode:=(copy(data,7,2)+copy(data, 5, 2)); //this never gives me 3020
security:=copy(data,11,2)+copy(data, 9, 2); //security byte
listbox1.items.Add('['+inttostr(size)+'] ['+opcode+'] ['+security+']');
packetdata:=copy(data,13,size*2); //this is the the data part of packet
listbox1.Items.Add('Data: '+ packetdata);
listbox1.Items.add('------------------------');
Thank you ! As i can see 3020 packet's content seems in b602 and 30bf packet. And i think they are stricted together. I wonder how can i separate them? There is no example of separating stricted packets?
Thank you ! As i can see 3020 packet's content seems in b602 and 30bf packet. And i think they are stricted together. I wonder how can i separate them? There is no example of separating stricted packets?
TCP is a low-level streaming protocol. The SRO packet protocol is built on top of TCP. This means that one physical (i.e. TCP) packet can contain more logical (i.e. SRO) packets. Substract the length (first 16 bits of the SRO packet's header) from each SRO packet received from the actual number of bytes received. If the result is above zero, there are multiple SRO packets in the TCP packet.
I have been trying to do it when i saw your message. But i thought that merged packet can contain only 2 packet. I was wrong as i can see. Then i changed my code to;
Receive function:
PHP Code:
size := hexatoint(copy(data,3,2)+copy(data, 1, 2));
opcode:=(copy(data,7,2)+copy(data, 5, 2));
security:=copy(data,11,2)+copy(data, 9, 2);
listbox1.items.Add('['+inttostr(size)+'] ['+opcode+'] ['+security+']');
packetdata:=copy(data,13,size*2);
otherdata:=copy(data,(size*2)+2,length(data));
if length(otherdata) > 1 then
begin
PacketMerged(otherdata);
end;
PacketMerged function;
PHP Code:
size := hexatoint(copy(data,3,2)+copy(data, 1, 2));
opcode:=(copy(data,7,2)+copy(data, 5, 2));
security:=copy(data,11,2)+copy(data, 9, 2);
listbox1.items.Add('['+inttostr(size)+'] ['+opcode+'] ['+security+']');
packetdata:=copy(data,13,size*2);
otherdata:=copy(data,(size*2)+2,length(data));
if length(otherdata) > 1 then
begin
PacketMerged(otherdata);
end;
But it still doesn't find all of the 3020 packets. I cant see any problem right now. Do you see any logical mistake?
I cannot code in Delphi. But you got the size, opcode, security and packetdata of a packet. And you know how long the fields are. Substract this packet length from length(data). If the value is not zero continue parsing the packet.
I can get every other packet without any problem. But this 3020 code doesn't appear sometimes. But instead of 3020 i get B602 code which contains char id. So does B602 a real packet or do i see it by mistake of any code?
I think your problem is receiving Text instead of receiving Buffer. try something like that
Code:
function TForm1.SocketRecive(Socket: TCustomWinSocket; var Buffer : Pointer): Integer;
var
N : Integer;
begin
FreeMem(Buffer);
N := Socket.ReceiveLength;
GetMem(Buffer, N);
Socket.ReceiveBuf(Buffer^, N);
Result := N;
end;
then in your socket onread event do
Code:
procedure TForm1.ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
var
N : Integer;
packet : PPacket;
Pd : pointer;
IsEnc : Boolean;
begin
N : Integer;
Nw : Word;
packet_size : integer;
packet : PPacket;
P : pointer;
IsEnc : Boolean;
begin
// Read the data avaliable on the socket
N := SocketRecive(Socket, P);
try
// Now handle the packets
Packet := PPacket(P);
IsEnc := ((Packet.Size and $8000) <> 0);
case packet.opcode of
$3020 :
do something here
end;
finally
FreeMem(P);
end;
end;
in your interface section you define the Packet record and pointer like that :
Code:
Type
// Generic packet structure
PPacket = ^TPacket;
TPacket = packed Record
Size : WORD ; // Size of this packet.
Opcode : WORD ; // Opcode of this packet
SecurityCount : BYTE ; // Security count byte
SecurityCRC : BYTE ; // Security crc
Data : BYTE ;
end;
To extend lesderid's answer. The packets "sticking" together is because of Nagle's algorithm to reduce the amount of overhead on small packets.
Also TCP only guarantees the order that you're receiving the packets. It doesn't guarantee that the packets are complete. So your code could work most of the time but it isn't very reliable.
A way (not the only one) to fix this is to append all received data to a second buffer. This way if you receive an incomplete packet or multiple packets at once it gets added to the second buffer.
Then read the buffer (First two bytes in the SRO protocol is always the size) and check if the buffer contains that amount of bytes. If so, then you have received a full packet and can read it. If it doesn't then you just wait for the rest of the packet to be received.
Note: The above method isn't the most optimal method to handle this situation but it was the only one I could think of right now. Maybe some else can give you a better method to handle this situation.
Ehab.Hamed i think this looks better than my code. But i think it wont solve the sticked packets. I have managed seperating packets but again i have a problem with incomplete packets i think i'm going to make a check for if its completed or incomplete then if its incomplete i'm going to work on it. By the way thank you everybody
DELPHI - Who make Exploits, Hacks and Tools with DELPHI? 05/15/2013 - CO2 Programming - 13 Replies Hi all.
Iwith DELPHI, but a dont now.
hello, I use Delphi to program and i like someone put here source code of make Exploits, Hacks and Tools bot here, or part of the code.
ty to all
[Release] +5500 Packets structure , client/packets constants 10/07/2012 - CO2 PServer Guides & Releases - 10 Replies edit : if u know nothing about packets go to this post first
explaining what is packets , and explaining a packet with details and everything
http://www.elitepvpers.com/forum/co2-pserver-disc ussions-questions/2162344-packets-packets-packets. html#post19074533
i start making my very own packet structure to use them on my new proxy but i thought of ripping them from the source
so yeah the following packets is ripped of trinity base source
right now im just providing the packets structure...
[Packets] Wie änder ich flyff packets? 07/16/2011 - Flyff Private Server - 19 Replies HeyHo,
Ich würde sehr gerne wissen wie man die Flyff Packets ändert...
ich denke mal Zahlen ändern werden nicht ausreichen oder?
[DELPHI&METIN]Wie sind die Delphi Befehle für einen Bot? 03/07/2010 - General Coding - 3 Replies Hallo liebe com,
ich habe mal eine Frage: Ich möchte einen Metin Bot in Delphi schreiben aber ich weiß nicht die Befehle für
eine bestimmte Taste senden etc.
könnt ihr mir die pls sagen oder per pn geben
MfGGGGGG