• Advertisement

Archived

This topic is now archived and is closed to further replies.

Getting corrupt data from directplay

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

Hi! I got a problem when sending directplay messages. Everything works great when I send a message of type ''netmsg''. But when I''m about to send a message of type ''netmsg_position'' for example, some of the data in the struct is corrupt. I don''t think there is something wrong with directplay, I''m sure that I screw up somewhere with the pointers or something. Below is some of my source code for you to check out.

// my message structs


struct netmsg
{
int type;
};

struct netmsg_position : public netmsg
{
	int x,y;
};

// message types


enum messagetype { msgtype_position = 0, msgtype_message = 1 };

// function that send a message


void myengine::net::client::send(netmsg msg,int msgsize)
{
	if(m_connected)
	{
		DPNHANDLE handle;

		// description

		DPN_BUFFER_DESC desc;
		desc.dwBufferSize = msgsize;
		desc.pBufferData = (BYTE*)&msg;

		// send

		m_dpclient->Send(&desc,1,0,NULL,NULL,DPNSEND_SYNC | 
			DPNSEND_GUARANTEED | DPNSEND_NOCOPY | DPNSEND_NOLOOPBACK);
	}
}

// send a message


netmsg_position pos;
pos.type = msgtype_position;
pos.x = 23;
pos.y = 19;

m_client->send(msg,sizeof(netmsg_message));

// inside message handler for server


case DPN_MSGID_RECEIVE:
	// message received

	PDPNMSG_RECEIVE data = (PDPNMSG_RECEIVE)msg_buffer;
	netmsg *msg = (netmsg*)data->pReceiveData;
	((server*)user_context)->on_client_receive(msg->type,data->pReceiveData);
	return S_OK;

// function that handles message


void myengine::net::server::on_client_receive(int msgtype,PBYTE msg)
{
if(msgtype == msgtype_position)
{ 
	netmsg_position *pos = (netmsg_position*)msg;
	dosomething(pos);
}
else if(msgtype == msgtype_message)
{
	netmsg_message *mess = (netmsg_message*)msg;
	dosomething(mess);
}
}
	
Thanks in advance for any help I can get.

Share this post


Link to post
Share on other sites
Advertisement
Oh, your right..
But that doesn''t really solve my problem... (I pasted in wrong code there, it should be "sizeof(netmsg_position)" ).

Share this post


Link to post
Share on other sites

  • Advertisement