Jump to content
  • Advertisement
Sign in to follow this  
TiitHns

Is this possible

This topic is 3800 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
Advertisement
it should be a pointer to a byte *byte or a pointer to your structure then just copy the data into a structure using the cpymem or memmove, memory copy

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!