Original Post
I'm working on my network class using DPlay. And I've been working on the packet handling system. Well for you who don't know DPlay it's not that confusing:
I've got:
struct DPN_BUFFER_DESC
{
DWORD dwBufferSize;
BYTE* pBufferData;
}
okey... so this is my idea:
I've got two DWORDS as the files header. My use for it doesn't really matter except the first DWORD specifies the type of data found in the buffer. One packet looks like this:
DWORD | DWORD | ...(dynamic mem)
So I've got my:
sturct PACKET
{
DWORD dwType;
DWORD dwSendRecv; (don't worry about this now)
BYTE *pbyData;
}
Okey.. well, when I want to send some player info to a client I send a:
struct PLAYER
{
DWORD dwPlayer;
char szName[64];
};
in the dynamic mem(in this case it has a set size) and set the dwType to MSGID_PLAYERINFO.. mmmkey?
quote:then when I receive it and check the *(DWORD*) ReceivedBuffer == MSGID_PLAYINFO I know if it includes player info. Well, then shouldn't it work to have: PLAYER *pPlayer; pPlayer = (PLAYER*)(((DWORD*)ReceivedBuffer)+2); shouldn't that work? Somehow I'm doing something wrong!? One other question. Should this work: PACKET *pPacket; pPacket = (PACKET*)ReceivedBuffer; pPlacyer = pPacket->pbyData; Shouldn't all this work!? But somehow the header is fine (the two dwords) but the rest is screwed up /MindWipe [edited by - MindWipe on December 2, 2002 10:49:05 AM]
bool CNetwork::Server_SendPlayerInfo( DWORD dwPlayerID, ... ) { DPN_BUFFER_DESC dpnBuffer; PLAYER player; PACKET datapacket; Player.dwPlayer = m_Player[ dwPlayerID ].dwPlayer; strcpy( player.szName, m_Player[ dwPlayerID ].szName ); datapacket.dwType = MSGID_PLAYERINFO; datapacket.dwSendRecv = ... datapacket.pbyData; = new unsigned char[sizeof(PLAYER)]; memcpy( datapacket.*pbyData, &player, sizeof(PLAYER) ); dpnBuffer.pBufferData = (unsigned char*)&datapacket dpnBuffer.dwBufferSize = 8 + sizeof(PLAYER); ... }