First, the syntax for usage of the JS Packet Class:
var myPacket = new Packet;
myPacket.WriteByte( pos, byte );
myPacket.WriteShort( pos, short );
myPacket.WriteLong( pos, long );
myPacket.WriteString( pos, string, len );
socket.Send( myPacket );
myPacket.Free();
myPacket.WriteByte( pos, byte );
myPacket.WriteShort( pos, short );
myPacket.WriteLong( pos, long );
myPacket.WriteString( pos, string, len );
socket.Send( myPacket );
myPacket.Free();
The first entry (WriteByte) in any packet starts at position 0, and contains the command - or packet ID. The second entry starts at position 1, and for each subsequent entry afterwards you add a value (size of WriteByte/WriteShort/WriteLong/WriteString used in previous entry, see table above) to the position-value of the previous entry to find the new position. So if you have a WriteShort at position 1, the next entry will start at position 1+2. If this entry was a WriteLong, you take the position it started at - in this case 3 (1+2) - and add 4 for a total of 7, which becomes either the position of the next entry - or the total packet length if this was the last entry.WriteByte = add 1 to pos(ition) value for next entry
WriteShort = add 2 to pos value for next entry
WriteLong = add 4 to pos value for next entry
WriteString = add 8? to pos value for next entry
Example:
var myPacket = new Packet;
myPacket.ReserveSize( 7 ); // Last entry was a WriteShort starting at position 5, so add 2 to find total packet size
myPacket.WriteByte( 0, 0x0B ); // Start position 0, packetID
myPacket.WriteLong( 1, pUser.serial ); //First entry was WriteByte, so add 1 to find this position
myPacket.WriteShort( 5, 0x9 ); //Previous entry was WriteLong, so add 4 to previous position to find this position
socket.Send( myPacket );
myPacket.Free();
myPacket.ReserveSize( 7 ); // Last entry was a WriteShort starting at position 5, so add 2 to find total packet size
myPacket.WriteByte( 0, 0x0B ); // Start position 0, packetID
myPacket.WriteLong( 1, pUser.serial ); //First entry was WriteByte, so add 1 to find this position
myPacket.WriteShort( 5, 0x9 ); //Previous entry was WriteLong, so add 4 to previous position to find this position
socket.Send( myPacket );
myPacket.Free();