[Help] Weather Packet (My First Packet)

05/02/2010 00:51 -Spirits-#1
delete this thread.
05/02/2010 01:22 herekorvac#2
If I'm not mistaken there is two packets for weather ( well. its atleast what I have had )

1. Type (Rain, FireFlies, Snow, Leaves, etc.)

2. On/Off
05/02/2010 01:29 Korvacs#3
P.WriteInt16((ushort)(Packet.Length - 13));

Should read:

P.WriteInt16((ushort)(Packet.Length));
05/02/2010 04:18 -Spirits-#4
delete this thread.
05/02/2010 11:36 Korvacs#5
Actually you dont need that at all.

The pointer is where you write data that is actually going to be sent, im not sure what you were trying to do but there is nothing before the length and type, they are the start of the packet.
05/02/2010 14:53 tanelipe#6
Pseudo code for packets:
PHP Code:
struct HEADER
{
    
ushort Size;
    
ushort Type;    
}
struct NET_MSG
{
    
HEADER Header;
    
ByteArray Data;

NET_MSG is the packet you send/receive which consists of header and the data it contains. Header contains the size of packet and also the type of the packet. This means that the first two bytes are the size and the next two bytes are the type of the message (packet).

PHP Code:
public static COPacket Weather(byte Typeuint Intensityuint Directionuint Appearance)
{
    
COPacket Packet = new COPacket(new byte[17])
    
Packet.WriteInt16(Packet.Length);
    
Packet.WriteInt16(1016);
    
Packet.WriteByte(Type);
    
Packet.WriteInt32(Intensity);
    
Packet.WriteInt32(Direction);
    
Packet.WriteInt32(Appearance);
    return 
Packet;

First of all, scratch all those conversions to uint:
PHP Code:
 P.WriteInt32((uint)(Weather_Intensity)); 
You're already passing the param Weather_Intensity as uint, no need to cast it to uint again. Oh and why are you doing (ushort)1016, it can already be counted as ushort since the value 1016 isn't magically going to change the type.

When creating a new instance of COPacket you can start writing the size/type and data to it immetiadly since it contains self incrementing counter/indexer. (WriteInt16 increases it by 2 and WriteInt32 by 4 and so on.)
05/03/2010 23:53 -Spirits-#7
delete this thread.
05/05/2010 02:38 -NewDawn-#8
#bumped.
unsolved
05/05/2010 03:34 CptSky#9
Wrong structure... The length should be 20 and the type 0x3f8 (1017?).

Code:
Length -> Int16
Type -> Int16
Look -> Int32
Intensity -> Int32
Direction -> Int32
Color -> Int32
05/08/2010 03:39 -Spirits-#10
delete this thread.
05/08/2010 11:06 Korvacs#11
Which client is this for?
05/08/2010 11:08 Arcо#12
5165.
05/08/2010 11:40 -impulse-#13
public static COPacket Weather(byte Type, uint Intensity, uint Direction, uint Appearance)
{
byte[] Packet = new byte[28];
COPacket P = new COPacket(Packet);
P.WriteInt16((ushort)(Packet.Length - 8));
P.WriteInt16(1016);
P.WriteInt16(Type);
P.WriteInt32(Intensity);
P.WriteInt32(Direction);
P.WriteInt32(Appearance);
return P;
}
[/code]
You gotta add 8 bytes for "TQServer" string. When the client receives a packet it verifies it's 8 last bytes, and if it's not TQServer the client will dc its self. Anyway, you don't need to add TQServer string when you build the packet(the string will be added when client.Send(COPacket) is accessed), but you need to give 8 bytes for the string in buffer.
05/08/2010 14:11 CptSky#14
Sorry, wrong conversion :) The packet type is 0x3f8 in hexadecimal, but it's 1016 in decimal, not 1017. And you need the TQServer at the end for new client.
05/08/2010 15:53 Basser#15
Code:
public static COPacket Weather(byte Type, uint Intensity, uint Direction, uint Appearance)
        {
            byte[] Packet = new byte[20];
            COPacket P = new COPacket(Packet);
            P.WriteInt16((ushort)(Packet.Length));
            P.WriteInt16((ushort)(1017));
            P.WriteInt16(Type);
            P.WriteInt32(Intensity);
            P.WriteInt32(Direction);
            P.WriteInt32(Appearance);

            return P;
        }
Okay, I'll give you one hint.
First thing I do when I get a disconnection error when I just added a new packet structure, is count the Length.

Code:
            byte[20] >> 20
            Int16  >> 18
            Int16  >> 16
            Int16  >> 14
            Int32  >> 10
            Int32  >> 6
            Int32  >> 2
Change the Length to 18.
Also another thing, I am pretty sure you should make the PacketType 1016.
Not sure if this is the correct structure though.