NextCo V2 Extreamly basic source framework

08/08/2013 01:01 Ultimation#16
First thing i would use is a circular buffer, Reasons dont rely on getting all the packets from the client everytime u call recv, u will mostly only get part if the buffer is full, this is why tq prefix there packets with the sizes, so later when you extract the packet from the buffer u know if its all there. Secondly Have a base packet type, i dunno lets go along with Packet wich has some basic functionality i.e type field Build and read functions, and then just have a class for each packet type you want to parse, inheriting from Packet, and call them something along the lines of

Code:
public class Packet
{
public short PacketType;
public virtual void Read(byte[] buffer){}
public virtual byte[] Build(){return null;}
}

Code:
Public class DataPacket:Packet
{
//I do this next part in the constructor.
public int UID; //Example Purpose

public DataPacket(){PacketType=10010;}

public override void Read(byte[] buffer)
{
//Watever reading method you want to use here
UID = BitConverter.ToInt32(buffer,4);
}


}
i found it to be easier, and regarding the Circular Buffer, You have Put and Get

Put(byte[] Data);
Get(int length);

In my case it would be.


Code:
public Packet ParseBuffer()
{
byte[] p = Buffer.Get(BitConverter.ToInt16(Buffer.Get(2),0));
//this will cause a "wait" action untill the whole packet is there if its not received complete.
tqpacket= null;
switch (packettype)
{
case 10010:tqpacket=new DataPacket();break; 
}

if (tqpacket != null)
{
tqpacket.Read(p);
}

return tqpacket;
}

this is just my 2 cents worth, Hope it helps
08/08/2013 01:46 go for it#17
thank you for taking time to help me out :)
yup that's what i actually do with the custom queue, byte array with enqueue to it's end and dequeue first packet while it can dequeue (data length inside the byte array is equal or exceeds the packet length), where there is one pointer for enqueue and always dequeue from the very first

about the base packet type, it's what im actually doing but im also inheriting the base type class from another interface so i can treat them all the same instead of parsing from child to parent and back again, that was the whole point after using the interface

sorry if i said something wrong, please feel free to correct me, and thanks once more for taking time to help me out
08/08/2013 06:57 Super Aids#18
How do you handle threading?
08/08/2013 12:24 go for it#19
Quote:
Originally Posted by Super Aids View Post
How do you handle threading?
well i didn't use threading yet, the main thread just pass the packet to it's own objects to handle it statically then send back to the object connection

prolly will create a timer thread with 1000 ms rest for sending msgs and raising all events and so on, still need to think about it, any advice ?
08/08/2013 12:42 Super Aids#20
Quote:
Originally Posted by go for it View Post
well i didn't use threading yet, the main thread just pass the packet to it's own objects to handle it statically then send back to the object connection

prolly will create a timer thread with 1000 ms rest for sending msgs and raising all events and so on, still need to think about it, any advice ?
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
06/01/2014 23:57 jason1#21
what patch is this please?
06/02/2014 05:50 Spirited#22
Looking at the source (which looks a bit like Impulse's 5165 base source but a bit messier), it has absolutely no documentation in it. It seems that there was an attempt to make it 5187 or above, but I'm not sure if it was successful since the password cipher wasn't implemented (or I can't see one implemented).