Sign in to follow this  

Is this possible

This topic is 3589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How to make base packet what holds message ID, and sub struct where is data.

struct basestruct{
int MessageCode; //hex code
*PointerToSubStruct //what data type it should be?
}

struct sub1{
int hp;
int mp;
};
struct sub2{
float x;
float y;
float z;
float heading;
};

When packet is recv-d we read MessageCode first to know what struct it has inside.

Share this post


Link to post
Share on other sites
First of all, having any kind of pointers in a packet struct is a no-no. Always try to include the exact data if possible. That being said, another way is to just tack on the substruct data onto the end of the packet data buffer.


struct basestruct{
int MessageCode; //hex code
}
struct sub1{
int hp;
int mp;
};

basestruct MyData;
MyData.MessageCode = 1;

sub1 SubData;
SubData.hp = 42;
SubData.mp = 42;

char DataBuffer[512];
memcpy(DataBuffer, &MyData, sizeof(MyData))
memcpy(DataBuffer + sizeof(MyData), &SubData, sizeof(sub1));


Now DataBuffer contains the main struct followed by the substruct.

Share this post


Link to post
Share on other sites
What I did was make a class with a byte buffer[maxSize] and just had things like addu8, addu16 addu32.. etc. the client (or sever w/e was reciving the data at the time) would then check for a message ID, say id 103 - walks left, that was just added with addu8, it would then parse the data run the code to make it move left, by the end the packet should have been empty and it would just dump everything else. Worked good..

Share this post


Link to post
Share on other sites

This topic is 3589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this