Fix 32/64 bit MP message structure packing issues

- 32 bit and 64 bit should work the same way now (need to test).
  The server compiles 32 bit at the moment.
- 8 bytes from the NetMessage header were removed, and the protocol
  version was bumped.
This commit is contained in:
Scott Ludwig 2016-01-01 14:26:25 -08:00
parent fd51170580
commit 3618d1a6b2
5 changed files with 38 additions and 35 deletions

View File

@ -138,6 +138,8 @@ STARTLABEL(LobbyLeaveResults)
LABEL(knLobbyLeaveResultFail)
ENDLABEL(LobbyLeaveResults)
#pragma pack(push, 2)
typedef XMsg2<XMSG_HANDSHAKE> XMsgHandshake;
typedef XMsg2<XMSG_HANDSHAKERESULT> XMsgHandshakeResult;
typedef XMsg0<XMSG_ECHO> XMsgEcho;
@ -320,8 +322,8 @@ struct XMsgGameNetMessage : public XMsg
const dword XMSGSIZE_GAMENETMESSAGE_FIXED = XMSGSIZE_FIXED;
struct XMsgGameUpdateEmpty : public XMsg {
//long cUpdatesBlock;
//long cUpdatesSync;
//int cUpdatesBlock;
//int cUpdatesSync;
static base::ByteBuffer *ToBuffer(UpdateNetMessage *punm);
static XMsgGameNetMessage *FromBuffer(base::ByteBuffer& bb, dword cb);
@ -329,7 +331,7 @@ struct XMsgGameUpdateEmpty : public XMsg {
const dword XMSGSIZE_GAMEUPDATEEMPTY = XMSGSIZE_FIXED + sizeof(dword) * 2;
struct XMsgGameUpdateResult : public XMsg {
//long cUpdatesBlock;
//int cUpdatesBlock;
//dword hash;
//short cmsLatency;
@ -339,6 +341,8 @@ struct XMsgGameUpdateResult : public XMsg {
const dword XMSGSIZE_GAMEUPDATERESULT = XMSGSIZE_FIXED + sizeof(dword) +
sizeof(dword) + sizeof(short);
#pragma pack(pop)
} // namespace wi
#endif // __MESSAGES_H__

View File

@ -7,7 +7,9 @@
namespace wi {
const long kcUpdatesBlockInitial = 1;
#pragma pack(push, 2)
const int kcUpdatesBlockInitial = 1;
const dword kdwClientID = 0x47414d45;
@ -22,7 +24,7 @@ typedef word Gid; // gid
typedef word StateMachineId; // smid
typedef word Side; // side
typedef short UnitType; // ut
typedef unsigned long UnitMask; // um
typedef unsigned int UnitMask; // um
typedef signed short TCoord;
typedef signed short WCoord;
typedef word Pid; // pid
@ -114,7 +116,7 @@ struct GameParams // rams
{
PackId packid; // 20
dword dwVersionSimulation; // 4
long tGameSpeed; // 4
int tGameSpeed; // 4
char szLvlFilename[kcbFilename]; // 29
byte filler[3]; // 3
}; // 60
@ -137,8 +139,8 @@ struct Message // msg
// UNDONE: smidSender isn't used except by DEBUG_HELPERS
StateMachineId smidSender;
StateMachineId smidReceiver;
word wDummy; // for long alignment
long tDelivery;
word wDummy; // for alignment
int tDelivery;
// MessageId-specific arguments
@ -311,11 +313,13 @@ ENDLABEL(MessageNames)
struct UpdateResult // ur
{
long cUpdatesBlock;
int cUpdatesBlock;
dword hash;
long cmsLatency;
int cmsLatency;
};
#pragma pack(pop)
} // namespace wi
#endif // __MPHT_H__

View File

@ -7,7 +7,7 @@
namespace wi {
long gatGameSpeeds[15] = {
int gatGameSpeeds[15] = {
64, 48, 32, 24, 16, 12, 10, 8, 7, 6, 5, 4, 3, 2, 1
};

View File

@ -58,6 +58,8 @@ const NetMessageId knmidScCheckWin = 22;
const NetMessageId knmidCsChallengeWin = 23;
const NetMessageId knmidMax = 24;
#pragma pack(push, 2)
class NetMessage // nm
{
public:
@ -67,14 +69,6 @@ public:
word cb; // size of whole message, including these fields
NetMessageId nmid;
// This (and the pad below) are DEBUG only information.
// We want to play DEBUG vs. Release so it's not conditional
// OPT: ditch it to shorten each message by 4 bytes
byte nSeq;
byte abPad[3];
// OPT: Could move this out of the message to shorten each by 4 bytes
NetMessage *pnmNext;
// After this is dword aligned
};
@ -82,7 +76,7 @@ inline NetMessage::NetMessage(NetMessageId nmid)
{
this->nmid = nmid;
this->cb = sizeof(NetMessage);
this->pnmNext = NULL;
//this->pnmNext = NULL;
CompileAssert((sizeof(this) % 4) == 0);
}
@ -135,11 +129,11 @@ inline ConnectNetMessage::ConnectNetMessage()
class BeginGameNetMessage : public NetMessage {
public:
BeginGameNetMessage();
unsigned long ulRandomSeed;
unsigned int ulRandomSeed;
#ifdef LOGGING
void ToString(char *psz, int cb) {
snprintf(psz, cb, "ScBeginGame(seed: %ld)", ulRandomSeed);
snprintf(psz, cb, "ScBeginGame(seed: %u)", ulRandomSeed);
}
#endif
};
@ -155,7 +149,7 @@ class ClientCommandsNetMessage : public NetMessage {
public:
ClientCommandsNetMessage();
word cmsgCommands;
word wDummy; // for long aligning the Messages on 68K
word wDummy; // for aligning the Messages on 68K
Message amsgCommands[1];
#ifdef LOGGING
@ -179,15 +173,15 @@ inline ClientCommandsNetMessage::ClientCommandsNetMessage()
class UpdateNetMessage : public NetMessage {
public:
UpdateNetMessage();
long cUpdatesBlock;
long cUpdatesSync;
int cUpdatesBlock;
int cUpdatesSync;
word cmsgCommands;
word wDummy; // for long aligning the Messages on 68K
word wDummy; // for aligning the Messages on 68K
Message amsgCommands[1];
#ifdef LOGGING
void ToString(char *psz, int cb) {
snprintf(psz, cb, "ScUpdate(cmsg: %d, cUpdatesBlock: %ld, cUpdatesSync: %ld)",
snprintf(psz, cb, "ScUpdate(cmsg: %d, cUpdatesBlock: %d, cUpdatesSync: %d)",
cmsgCommands, cUpdatesBlock, cUpdatesSync);
}
#endif
@ -253,9 +247,9 @@ struct PlayerRecord // plrr
class PlayersUpdateNetMessage : public NetMessage {
public:
PlayersUpdateNetMessage();
PlayersUpdateNetMessage();
word cplrr;
word wDummy; // for long alignment
word wDummy; // for alignment
PlayerRecord aplrr[1];
#ifdef LOGGING
@ -284,7 +278,7 @@ public:
#ifdef LOGGING
void ToString(char *psz, int cb) {
snprintf(psz, cb,
"CsUpdateResult(cUpdatesBlock: %ld, hash %08x, cmsLatency: %ld)",
"CsUpdateResult(cUpdatesBlock: %d, hash %08x, cmsLatency: %d)",
ur.cUpdatesBlock, ur.hash, ur.cmsLatency);
}
#endif
@ -300,8 +294,8 @@ inline UpdateResultNetMessage::UpdateResultNetMessage()
struct GameHost { // gh
GameHost *pghNext;
NetAddress nad;
unsigned long msLastContact;
unsigned long id;
unsigned int msLastContact;
unsigned int id;
char szGameName[kcbGameName];
};
@ -549,6 +543,8 @@ inline PlayerResignNetMessage::PlayerResignNetMessage()
CompileAssert((sizeof(this) % 4) == 0);
}
#pragma pack(pop)
#ifdef __CPU_68K // 68K byte order == our chosen network byte order
#define NetMessageByteOrderSwap(a, b)
#define MessageByteOrderSwap(a, b, c)
@ -561,7 +557,7 @@ void SwapGameParams(GameParams *prams);
bool ValidateGameParams(const GameParams& params);
extern long gatGameSpeeds[15];
extern int gatGameSpeeds[15];
} // namespace wi

View File

@ -791,8 +791,7 @@ void Game::OnClientCommands(Endpoint *endpoint, ClientCommandsNetMessage *pnm) {
cmds_.push_back(pnm->amsgCommands[i]);
}
LOG() << base::Log::Format("0x%08lx seq: %d ccmds:%d",
endpoint, pnm->nSeq, pnm->cmsgCommands);
LOG() << base::Log::Format("0x%08lx ccmds:%d", endpoint, pnm->cmsgCommands);
// TODO: Validation
}