PacketCollection is our way of storing which packet id's have which structure and which function to handle them with.
- Source:
Example
// Use Set to add a packet to the collection // Usage: // var p = new PacketCollection(); // // When packet is just packet id no data // p.Set(0x00,{ function: function _Packet_00() { // // Do something // } }); // // When packet is going to use restruct/structure // // Should use // p.Set(0x01,{ // Restruct: restruct. // string('Name', 20). // int32lu('Age'), // function: function _Packet_01(p) { // // Do something with p // console.log(p.Name+' is '+p.Age+' years old.'); // } }); // // When packet is a id and size without restruct // p.Set(0x02,{ // Size: 10, function: funciton _Packet_02(data) { // // data will be a buffer with size of 10 bytes. // console.log(data.toString()); // } // }); // // If you don't know the function or data structure yet and just want to add it for starts so server dosnt complain. // p.Set(0x03,{Size: 50});
Methods
-
Get(id) → {object|null}
-
Gets a PacketCollection info for a PacketID.
Parameters:
Name Type Description id
Integer The PacketID to look up.
- Source:
Returns:
The PacketInfo object.
- Type
- object | null
-
Remove(id)
-
Removes a packet from the collection by ID.
Parameters:
Name Type Description id
Integer The packetID to remove.
- Source:
-
Set(id, id)
-
Sets a PacketCollection info for a PacketID.
Parameters:
Name Type Description id
Integer The PacketID.
id
object The PacketInfo object.
- Source: