Jump to content
  • Advertisement
Sign in to follow this  
Westeria

Is this valid buffer code?

This topic is 5133 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

char bufInternet[300];
unsigned short intLocalPlayer;
unsigned short intMonster;
/* Objects */
struct strObject
{
	unsigned char bytIdentity;
	unsigned short intX;
	unsigned short intY;
	unsigned short intGridX;
	unsigned short intGridY;
        ....... 107 bytes ......
}



	if(n>0)
	{
		/* Each packet is an individual creature. */
		memcpy(&intLocalPlayer, &bufInternet[n-(2+2)], 2);
		memcpy(&intMonster, &bufInternet[n-2], 2);
		if(intLocalPlayer == intMonster) bytRecievedGameState = 1;
		memcpy(&arrObjects, &bufInternet, n-4);
	}



Normally I wouldn't ask such a question, but accessing two computers isn't easy from where I am. "Fleebow.exe - 0 error(s), 0 warning(s)" Edit: It looks right to me, but it felt too ez.

Share this post


Link to post
Share on other sites
Advertisement
If n is the size of bufInternet, it looks like it would work. I just skimmed it over so there could be something I missed. Print out the buffer and look at it to make sure it's what you want (also remember that any weird characters will be printed in ascii).

Edit: to be sure you're compatible, you could do this instead:

if(n>0)
{
/* Each packet is an individual creature. */
memcpy(&intLocalPlayer, &bufInternet[n-(sizeof(unsigned short)*2)], sizeof(unsigned short));
memcpy(&intMonster, &bufInternet[n-sizeof(unsigned short)], sizeof(unsigned short));
if(intLocalPlayer == intMonster) bytRecievedGameState = 1;
memcpy(&arrObjects, &bufInternet, n-(sizeof(unsigned short)*2));
}

Share this post


Link to post
Share on other sites
	memcpy(&arrObjects, &bufInternet, n-4);

&bufInternet is a pointer to the address of your character array, not a pointer to your character array...
	memcpy( &arrObjects, bufInternet, n-4 );
or
	memcpy( &arrObjects, &bufInternet[0], n-4 );
would copy out of the buffer properly...(as long as n is less then the size of hte buffer :)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!