- attempt to correct network message alignment problem

This commit is contained in:
Mark Vejvoda 2010-08-07 06:19:56 +00:00
parent cee6b8dfc8
commit 0f8eb267c6
2 changed files with 25 additions and 2 deletions

View File

@ -76,6 +76,7 @@ protected:
// when the client connects and vice versa // when the client connects and vice versa
// ===================================================== // =====================================================
#pragma pack(push, 1)
class NetworkMessageIntro: public NetworkMessage{ class NetworkMessageIntro: public NetworkMessage{
private: private:
static const int maxVersionStringSize= 128; static const int maxVersionStringSize= 128;
@ -105,6 +106,7 @@ public:
virtual bool receive(Socket* socket); virtual bool receive(Socket* socket);
virtual void send(Socket* socket) const; virtual void send(Socket* socket) const;
}; };
#pragma pack(pop)
// ===================================================== // =====================================================
// class NetworkMessagePing // class NetworkMessagePing
@ -112,6 +114,7 @@ public:
// Message sent at any time // Message sent at any time
// ===================================================== // =====================================================
#pragma pack(push, 1)
class NetworkMessagePing: public NetworkMessage{ class NetworkMessagePing: public NetworkMessage{
private: private:
struct Data{ struct Data{
@ -135,6 +138,7 @@ public:
virtual bool receive(Socket* socket); virtual bool receive(Socket* socket);
virtual void send(Socket* socket) const; virtual void send(Socket* socket) const;
}; };
#pragma pack(pop)
// ===================================================== // =====================================================
// class NetworkMessageReady // class NetworkMessageReady
@ -142,6 +146,7 @@ public:
// Message sent at the beginning of the game // Message sent at the beginning of the game
// ===================================================== // =====================================================
#pragma pack(push, 1)
class NetworkMessageReady: public NetworkMessage{ class NetworkMessageReady: public NetworkMessage{
private: private:
struct Data{ struct Data{
@ -161,6 +166,7 @@ public:
virtual bool receive(Socket* socket); virtual bool receive(Socket* socket);
virtual void send(Socket* socket) const; virtual void send(Socket* socket) const;
}; };
#pragma pack(pop)
// ===================================================== // =====================================================
// class NetworkMessageLaunch // class NetworkMessageLaunch
@ -169,6 +175,7 @@ public:
// to launch the game // to launch the game
// ===================================================== // =====================================================
#pragma pack(push, 1)
class NetworkMessageLaunch: public NetworkMessage{ class NetworkMessageLaunch: public NetworkMessage{
private: private:
static const int maxStringSize= 256; static const int maxStringSize= 256;
@ -213,6 +220,7 @@ public:
virtual bool receive(Socket* socket); virtual bool receive(Socket* socket);
virtual void send(Socket* socket) const; virtual void send(Socket* socket) const;
}; };
#pragma pack(pop)
// ===================================================== // =====================================================
// class CommandList // class CommandList
@ -268,6 +276,7 @@ public:
// Chat text message // Chat text message
// ===================================================== // =====================================================
#pragma pack(push, 1)
class NetworkMessageText: public NetworkMessage{ class NetworkMessageText: public NetworkMessage{
private: private:
static const int maxTextStringSize= 340; static const int maxTextStringSize= 340;
@ -295,6 +304,7 @@ public:
virtual bool receive(Socket* socket); virtual bool receive(Socket* socket);
virtual void send(Socket* socket) const; virtual void send(Socket* socket) const;
}; };
#pragma pack(pop)
// ===================================================== // =====================================================
// class NetworkMessageQuit // class NetworkMessageQuit
@ -302,6 +312,7 @@ public:
// Message sent at the beggining of the game // Message sent at the beggining of the game
// ===================================================== // =====================================================
#pragma pack(push, 1)
class NetworkMessageQuit: public NetworkMessage{ class NetworkMessageQuit: public NetworkMessage{
private: private:
struct Data{ struct Data{
@ -317,6 +328,7 @@ public:
virtual bool receive(Socket* socket); virtual bool receive(Socket* socket);
virtual void send(Socket* socket) const; virtual void send(Socket* socket) const;
}; };
#pragma pack(pop)
// ===================================================== // =====================================================
// class NetworkMessageSynchNetworkGameData // class NetworkMessageSynchNetworkGameData
@ -324,6 +336,7 @@ public:
// Message sent at the beggining of a network game // Message sent at the beggining of a network game
// ===================================================== // =====================================================
#pragma pack(push, 1)
class NetworkMessageSynchNetworkGameData: public NetworkMessage{ class NetworkMessageSynchNetworkGameData: public NetworkMessage{
private: private:
@ -361,6 +374,7 @@ public:
int32 getTilesetCRC() const {return data.tilesetCRC;} int32 getTilesetCRC() const {return data.tilesetCRC;}
int32 getTechCRC() const {return data.techCRC;} int32 getTechCRC() const {return data.techCRC;}
}; };
#pragma pack(pop)
// ===================================================== // =====================================================
// class NetworkMessageSynchNetworkGameDataStatus // class NetworkMessageSynchNetworkGameDataStatus
@ -368,6 +382,7 @@ public:
// Message sent at the beggining of a network game // Message sent at the beggining of a network game
// ===================================================== // =====================================================
#pragma pack(push, 1)
class NetworkMessageSynchNetworkGameDataStatus: public NetworkMessage{ class NetworkMessageSynchNetworkGameDataStatus: public NetworkMessage{
private: private:
@ -398,6 +413,7 @@ public:
int32 getTilesetCRC() const {return data.tilesetCRC;} int32 getTilesetCRC() const {return data.tilesetCRC;}
int32 getTechCRC() const {return data.techCRC;} int32 getTechCRC() const {return data.techCRC;}
}; };
#pragma pack(pop)
// ===================================================== // =====================================================
// class NetworkMessageSynchNetworkGameDataFileCRCCheck // class NetworkMessageSynchNetworkGameDataFileCRCCheck
@ -405,6 +421,7 @@ public:
// Message sent at the beggining of a network game // Message sent at the beggining of a network game
// ===================================================== // =====================================================
#pragma pack(push, 1)
class NetworkMessageSynchNetworkGameDataFileCRCCheck: public NetworkMessage{ class NetworkMessageSynchNetworkGameDataFileCRCCheck: public NetworkMessage{
private: private:
@ -436,6 +453,7 @@ public:
int32 getFileCRC() const {return data.fileCRC;} int32 getFileCRC() const {return data.fileCRC;}
string getFileName() const {return data.fileName.getString();} string getFileName() const {return data.fileName.getString();}
}; };
#pragma pack(pop)
// ===================================================== // =====================================================
// class NetworkMessageSynchNetworkGameDataFileGet // class NetworkMessageSynchNetworkGameDataFileGet
@ -443,6 +461,7 @@ public:
// Message sent at the beggining of a network game // Message sent at the beggining of a network game
// ===================================================== // =====================================================
#pragma pack(push, 1)
class NetworkMessageSynchNetworkGameDataFileGet: public NetworkMessage{ class NetworkMessageSynchNetworkGameDataFileGet: public NetworkMessage{
private: private:
@ -468,7 +487,7 @@ public:
string getFileName() const {return data.fileName.getString();} string getFileName() const {return data.fileName.getString();}
}; };
#pragma pack(pop)
// ===================================================== // =====================================================
// class SwitchSetupRequest // class SwitchSetupRequest
@ -477,6 +496,7 @@ public:
// to switch its settings // to switch its settings
// ===================================================== // =====================================================
#pragma pack(push, 1)
class SwitchSetupRequest: public NetworkMessage{ class SwitchSetupRequest: public NetworkMessage{
private: private:
static const int maxStringSize= 256; static const int maxStringSize= 256;
@ -505,6 +525,7 @@ public:
virtual bool receive(Socket* socket); virtual bool receive(Socket* socket);
virtual void send(Socket* socket) const; virtual void send(Socket* socket) const;
}; };
#pragma pack(pop)
// ===================================================== // =====================================================
// class PlayerIndexMessage // class PlayerIndexMessage
@ -513,6 +534,7 @@ public:
// to tell them about a slot change ( caused by another client ) // to tell them about a slot change ( caused by another client )
// ===================================================== // =====================================================
#pragma pack(push, 1)
class PlayerIndexMessage: public NetworkMessage{ class PlayerIndexMessage: public NetworkMessage{
private: private:
@ -532,6 +554,7 @@ public:
virtual bool receive(Socket* socket); virtual bool receive(Socket* socket);
virtual void send(Socket* socket) const; virtual void send(Socket* socket) const;
}; };
#pragma pack(pop)
}}//end namespace }}//end namespace

View File

@ -43,7 +43,7 @@ public:
void operator=(const string& str) { void operator=(const string& str) {
// ensure we don't have a buffer overflow // ensure we don't have a buffer overflow
int maxBufferSize = sizeof(buffer) / sizeof(buffer[0]); int maxBufferSize = sizeof(buffer) / sizeof(buffer[0]);
strncpy(buffer, str.c_str(), std::min(S-1,maxBufferSize)); strncpy(buffer, str.c_str(), std::min(S-1,maxBufferSize-1));
} }
string getString() const {return buffer;} string getString() const {return buffer;}
}; };