2010-03-24 14:39:08 +01:00
|
|
|
|
// ==============================================================
|
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
|
//
|
2010-04-22 01:13:39 +02:00
|
|
|
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
2010-03-24 14:39:08 +01:00
|
|
|
|
//
|
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
|
|
#ifndef _GLEST_GAME_NETWORKMESSAGE_H_
|
|
|
|
|
#define _GLEST_GAME_NETWORKMESSAGE_H_
|
|
|
|
|
|
|
|
|
|
#include "socket.h"
|
|
|
|
|
#include "game_constants.h"
|
|
|
|
|
#include "network_types.h"
|
2010-09-07 07:25:40 +02:00
|
|
|
|
#include "leak_dumper.h"
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
using Shared::Platform::Socket;
|
|
|
|
|
using Shared::Platform::int8;
|
2010-04-30 04:41:42 +02:00
|
|
|
|
using Shared::Platform::uint8;
|
2010-03-24 14:39:08 +01:00
|
|
|
|
using Shared::Platform::int16;
|
|
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
|
|
class GameSettings;
|
|
|
|
|
|
2010-05-04 04:32:43 +02:00
|
|
|
|
enum NetworkMessageType {
|
2010-03-24 14:39:08 +01:00
|
|
|
|
nmtInvalid,
|
|
|
|
|
nmtIntro,
|
|
|
|
|
nmtPing,
|
|
|
|
|
nmtReady,
|
|
|
|
|
nmtLaunch,
|
|
|
|
|
nmtCommandList,
|
|
|
|
|
nmtText,
|
|
|
|
|
nmtQuit,
|
|
|
|
|
nmtSynchNetworkGameData,
|
|
|
|
|
nmtSynchNetworkGameDataStatus,
|
|
|
|
|
nmtSynchNetworkGameDataFileCRCCheck,
|
|
|
|
|
nmtSynchNetworkGameDataFileGet,
|
2010-04-22 01:13:39 +02:00
|
|
|
|
nmtBroadCastSetup,
|
2010-04-29 01:59:37 +02:00
|
|
|
|
nmtSwitchSetupRequest,
|
2010-04-30 03:08:29 +02:00
|
|
|
|
nmtPlayerIndexMessage,
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
nmtCount
|
|
|
|
|
};
|
|
|
|
|
|
2010-05-12 17:25:56 +02:00
|
|
|
|
enum NetworkGameStateType {
|
|
|
|
|
nmgstInvalid,
|
|
|
|
|
nmgstOk,
|
|
|
|
|
nmgstNoSlots,
|
|
|
|
|
|
|
|
|
|
nmgstCount
|
|
|
|
|
};
|
|
|
|
|
|
2010-03-24 14:39:08 +01:00
|
|
|
|
// =====================================================
|
|
|
|
|
// class NetworkMessage
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-05-04 04:32:43 +02:00
|
|
|
|
class NetworkMessage {
|
2010-03-24 14:39:08 +01:00
|
|
|
|
public:
|
|
|
|
|
virtual ~NetworkMessage(){}
|
|
|
|
|
virtual bool receive(Socket* socket)= 0;
|
|
|
|
|
virtual void send(Socket* socket) const = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool peek(Socket* socket, void* data, int dataSize);
|
|
|
|
|
bool receive(Socket* socket, void* data, int dataSize);
|
|
|
|
|
void send(Socket* socket, const void* data, int dataSize) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class NetworkMessageIntro
|
|
|
|
|
//
|
|
|
|
|
// Message sent from the server to the client
|
|
|
|
|
// when the client connects and vice versa
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(push, 1)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
class NetworkMessageIntro: public NetworkMessage{
|
|
|
|
|
private:
|
2010-04-30 08:45:30 +02:00
|
|
|
|
static const int maxVersionStringSize= 128;
|
|
|
|
|
static const int maxNameSize= 32;
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct Data{
|
|
|
|
|
int8 messageType;
|
2010-08-23 17:40:43 +02:00
|
|
|
|
int32 sessionId;
|
2010-03-24 14:39:08 +01:00
|
|
|
|
NetworkString<maxVersionStringSize> versionString;
|
|
|
|
|
NetworkString<maxNameSize> name;
|
|
|
|
|
int16 playerIndex;
|
2010-05-12 17:25:56 +02:00
|
|
|
|
int8 gameState;
|
2010-03-24 14:39:08 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Data data;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
NetworkMessageIntro();
|
2010-08-23 17:40:43 +02:00
|
|
|
|
NetworkMessageIntro(int32 sessionId, const string &versionString, const string &name, int playerIndex, NetworkGameStateType gameState);
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
2010-08-23 17:40:43 +02:00
|
|
|
|
int32 getSessionId() const { return data.sessionId;}
|
2010-05-12 17:25:56 +02:00
|
|
|
|
string getVersionString() const { return data.versionString.getString(); }
|
|
|
|
|
string getName() const { return data.name.getString(); }
|
|
|
|
|
int getPlayerIndex() const { return data.playerIndex; }
|
|
|
|
|
NetworkGameStateType getGameState() const { return static_cast<NetworkGameStateType>(data.gameState); }
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
virtual bool receive(Socket* socket);
|
|
|
|
|
virtual void send(Socket* socket) const;
|
|
|
|
|
};
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(pop)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
2010-07-09 17:01:49 +02:00
|
|
|
|
// =====================================================
|
|
|
|
|
// class NetworkMessagePing
|
|
|
|
|
//
|
|
|
|
|
// Message sent at any time
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(push, 1)
|
2010-07-09 17:01:49 +02:00
|
|
|
|
class NetworkMessagePing: public NetworkMessage{
|
|
|
|
|
private:
|
|
|
|
|
struct Data{
|
|
|
|
|
int8 messageType;
|
|
|
|
|
int32 pingFrequency;
|
|
|
|
|
int64 pingTime;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Data data;
|
2010-07-09 20:49:01 +02:00
|
|
|
|
int64 pingReceivedLocalTime;
|
2010-07-09 17:01:49 +02:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
NetworkMessagePing();
|
|
|
|
|
NetworkMessagePing(int32 pingFrequency, int64 pingTime);
|
|
|
|
|
|
|
|
|
|
int32 getPingFrequency() const {return data.pingFrequency;}
|
|
|
|
|
int64 getPingTime() const {return data.pingTime;}
|
2010-07-09 20:49:01 +02:00
|
|
|
|
int64 getPingReceivedLocalTime() const { return pingReceivedLocalTime; }
|
2010-07-09 17:01:49 +02:00
|
|
|
|
|
|
|
|
|
virtual bool receive(Socket* socket);
|
|
|
|
|
virtual void send(Socket* socket) const;
|
|
|
|
|
};
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(pop)
|
2010-07-09 17:01:49 +02:00
|
|
|
|
|
2010-03-24 14:39:08 +01:00
|
|
|
|
// =====================================================
|
|
|
|
|
// class NetworkMessageReady
|
|
|
|
|
//
|
2010-07-09 17:01:49 +02:00
|
|
|
|
// Message sent at the beginning of the game
|
2010-03-24 14:39:08 +01:00
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(push, 1)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
class NetworkMessageReady: public NetworkMessage{
|
|
|
|
|
private:
|
|
|
|
|
struct Data{
|
|
|
|
|
int8 messageType;
|
|
|
|
|
int32 checksum;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Data data;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
NetworkMessageReady();
|
|
|
|
|
NetworkMessageReady(int32 checksum);
|
|
|
|
|
|
|
|
|
|
int32 getChecksum() const {return data.checksum;}
|
|
|
|
|
|
|
|
|
|
virtual bool receive(Socket* socket);
|
|
|
|
|
virtual void send(Socket* socket) const;
|
|
|
|
|
};
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(pop)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class NetworkMessageLaunch
|
|
|
|
|
//
|
|
|
|
|
// Message sent from the server to the client
|
|
|
|
|
// to launch the game
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(push, 1)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
class NetworkMessageLaunch: public NetworkMessage{
|
|
|
|
|
private:
|
|
|
|
|
static const int maxStringSize= 256;
|
2010-08-22 10:00:05 +02:00
|
|
|
|
static const int maxSmallStringSize= 60;
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct Data{
|
|
|
|
|
int8 messageType;
|
|
|
|
|
NetworkString<maxStringSize> description;
|
2010-08-22 10:00:05 +02:00
|
|
|
|
NetworkString<maxSmallStringSize> map;
|
|
|
|
|
NetworkString<maxSmallStringSize> tileset;
|
|
|
|
|
NetworkString<maxSmallStringSize> tech;
|
|
|
|
|
NetworkString<maxSmallStringSize> factionTypeNames[GameConstants::maxPlayers]; //faction names
|
|
|
|
|
NetworkString<maxSmallStringSize> networkPlayerNames[GameConstants::maxPlayers]; //networkPlayerNames
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
int8 factionControls[GameConstants::maxPlayers];
|
|
|
|
|
|
|
|
|
|
int8 thisFactionIndex;
|
|
|
|
|
int8 factionCount;
|
|
|
|
|
int8 teams[GameConstants::maxPlayers];
|
|
|
|
|
int8 startLocationIndex[GameConstants::maxPlayers];
|
|
|
|
|
int8 defaultResources;
|
|
|
|
|
int8 defaultUnits;
|
|
|
|
|
int8 defaultVictoryConditions;
|
2010-03-27 08:09:34 +01:00
|
|
|
|
int8 fogOfWar;
|
2010-09-04 03:24:17 +02:00
|
|
|
|
int8 allowObservers;
|
2010-06-03 09:52:17 +02:00
|
|
|
|
int8 enableObserverModeAtEndGame;
|
|
|
|
|
int8 enableServerControlledAI;
|
2010-06-05 09:52:14 +02:00
|
|
|
|
uint8 networkFramePeriod; // allowed values 0 - 255
|
2010-08-05 01:39:12 +02:00
|
|
|
|
int8 networkPauseGameForLaggedClients;
|
|
|
|
|
int8 pathFinderType;
|
2010-03-24 14:39:08 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Data data;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
NetworkMessageLaunch();
|
2010-04-22 01:13:39 +02:00
|
|
|
|
NetworkMessageLaunch(const GameSettings *gameSettings,int8 messageType);
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
void buildGameSettings(GameSettings *gameSettings) const;
|
2010-08-22 10:00:05 +02:00
|
|
|
|
int getMessageType() const { return data.messageType; }
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
virtual bool receive(Socket* socket);
|
|
|
|
|
virtual void send(Socket* socket) const;
|
|
|
|
|
};
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(pop)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class CommandList
|
|
|
|
|
//
|
|
|
|
|
// Message to order a commands to several units
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-06-08 09:40:32 +02:00
|
|
|
|
//const int32 commandListHeaderSize = 6;
|
|
|
|
|
|
2010-03-24 14:39:08 +01:00
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
|
class NetworkMessageCommandList: public NetworkMessage{
|
|
|
|
|
private:
|
2010-04-30 04:34:19 +02:00
|
|
|
|
//static const int maxCommandCount= 16*4;
|
2010-06-08 09:40:32 +02:00
|
|
|
|
//static const int maxCommandCount = (16 * 4) * 2;
|
|
|
|
|
static const int maxCommandCount = 2048; // can be as large as 65535
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
private:
|
2010-06-08 09:40:32 +02:00
|
|
|
|
struct DataHeader {
|
2010-03-24 14:39:08 +01:00
|
|
|
|
int8 messageType;
|
2010-06-08 09:40:32 +02:00
|
|
|
|
uint16 commandCount;
|
2010-05-01 12:46:56 +02:00
|
|
|
|
//int8 commandCount;
|
2010-03-24 14:39:08 +01:00
|
|
|
|
int32 frameCount;
|
2010-06-08 09:40:32 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const int32 commandListHeaderSize = sizeof(DataHeader);
|
|
|
|
|
|
|
|
|
|
struct Data {
|
|
|
|
|
DataHeader header;
|
2010-03-24 14:39:08 +01:00
|
|
|
|
NetworkCommand commands[maxCommandCount];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Data data;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
NetworkMessageCommandList(int32 frameCount= -1);
|
|
|
|
|
|
|
|
|
|
bool addCommand(const NetworkCommand* networkCommand);
|
|
|
|
|
|
2010-06-08 09:40:32 +02:00
|
|
|
|
void clear() {data.header.commandCount= 0;}
|
|
|
|
|
int getCommandCount() const {return data.header.commandCount;}
|
|
|
|
|
int getFrameCount() const {return data.header.frameCount;}
|
2010-03-24 14:39:08 +01:00
|
|
|
|
const NetworkCommand* getCommand(int i) const {return &data.commands[i];}
|
|
|
|
|
|
|
|
|
|
virtual bool receive(Socket* socket);
|
|
|
|
|
virtual void send(Socket* socket) const;
|
|
|
|
|
};
|
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class NetworkMessageText
|
|
|
|
|
//
|
|
|
|
|
// Chat text message
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(push, 1)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
class NetworkMessageText: public NetworkMessage{
|
|
|
|
|
private:
|
2010-08-07 05:26:38 +02:00
|
|
|
|
static const int maxTextStringSize= 340;
|
|
|
|
|
static const int maxSenderStringSize= 60;
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct Data{
|
|
|
|
|
int8 messageType;
|
2010-08-07 05:26:38 +02:00
|
|
|
|
NetworkString<maxTextStringSize> text;
|
|
|
|
|
NetworkString<maxSenderStringSize> sender;
|
2010-03-24 14:39:08 +01:00
|
|
|
|
int8 teamIndex;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Data data;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
NetworkMessageText(){}
|
|
|
|
|
NetworkMessageText(const string &text, const string &sender, int teamIndex);
|
|
|
|
|
|
|
|
|
|
string getText() const {return data.text.getString();}
|
|
|
|
|
string getSender() const {return data.sender.getString();}
|
|
|
|
|
int getTeamIndex() const {return data.teamIndex;}
|
|
|
|
|
|
|
|
|
|
virtual bool receive(Socket* socket);
|
|
|
|
|
virtual void send(Socket* socket) const;
|
|
|
|
|
};
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(pop)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class NetworkMessageQuit
|
|
|
|
|
//
|
|
|
|
|
// Message sent at the beggining of the game
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(push, 1)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
class NetworkMessageQuit: public NetworkMessage{
|
|
|
|
|
private:
|
|
|
|
|
struct Data{
|
|
|
|
|
int8 messageType;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Data data;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
NetworkMessageQuit();
|
|
|
|
|
|
|
|
|
|
virtual bool receive(Socket* socket);
|
|
|
|
|
virtual void send(Socket* socket) const;
|
|
|
|
|
};
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(pop)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class NetworkMessageSynchNetworkGameData
|
|
|
|
|
//
|
|
|
|
|
// Message sent at the beggining of a network game
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(push, 1)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
class NetworkMessageSynchNetworkGameData: public NetworkMessage{
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2010-08-26 04:36:17 +02:00
|
|
|
|
static const int maxStringSize= 255;
|
2010-08-26 22:28:26 +02:00
|
|
|
|
static const int maxFileCRCCount= 1500;
|
2010-08-27 00:29:48 +02:00
|
|
|
|
static const int maxFileCRCPacketCount= 25;
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
private:
|
2010-08-22 10:00:05 +02:00
|
|
|
|
|
|
|
|
|
struct DataHeader {
|
2010-03-24 14:39:08 +01:00
|
|
|
|
int8 messageType;
|
|
|
|
|
|
|
|
|
|
NetworkString<maxStringSize> map;
|
|
|
|
|
NetworkString<maxStringSize> tileset;
|
|
|
|
|
NetworkString<maxStringSize> tech;
|
|
|
|
|
|
|
|
|
|
int32 mapCRC;
|
|
|
|
|
int32 tilesetCRC;
|
|
|
|
|
int32 techCRC;
|
2010-08-22 10:00:05 +02:00
|
|
|
|
|
|
|
|
|
int32 techCRCFileCount;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const int32 HeaderSize = sizeof(DataHeader);
|
|
|
|
|
|
|
|
|
|
struct DataDetail {
|
|
|
|
|
NetworkString<maxStringSize> techCRCFileList[maxFileCRCCount];
|
|
|
|
|
int32 techCRCFileCRCList[maxFileCRCCount];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const int32 DetailSize1 = sizeof(NetworkString<maxStringSize>);
|
|
|
|
|
static const int32 DetailSize2 = sizeof(int32);
|
|
|
|
|
|
|
|
|
|
struct Data {
|
|
|
|
|
DataHeader header;
|
|
|
|
|
DataDetail detail;
|
2010-03-24 14:39:08 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Data data;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
NetworkMessageSynchNetworkGameData() {};
|
|
|
|
|
NetworkMessageSynchNetworkGameData(const GameSettings *gameSettings);
|
|
|
|
|
|
|
|
|
|
virtual bool receive(Socket* socket);
|
|
|
|
|
virtual void send(Socket* socket) const;
|
|
|
|
|
|
2010-08-22 10:00:05 +02:00
|
|
|
|
string getMap() const {return data.header.map.getString();}
|
|
|
|
|
string getTileset() const {return data.header.tileset.getString();}
|
|
|
|
|
string getTech() const {return data.header.tech.getString();}
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
2010-08-22 10:00:05 +02:00
|
|
|
|
int32 getMapCRC() const {return data.header.mapCRC;}
|
|
|
|
|
int32 getTilesetCRC() const {return data.header.tilesetCRC;}
|
|
|
|
|
int32 getTechCRC() const {return data.header.techCRC;}
|
|
|
|
|
|
|
|
|
|
int32 getTechCRCFileCount() const {return data.header.techCRCFileCount;}
|
|
|
|
|
const NetworkString<maxStringSize> * getTechCRCFileList() const {return &data.detail.techCRCFileList[0];}
|
|
|
|
|
const int32 * getTechCRCFileCRCList() const {return data.detail.techCRCFileCRCList;}
|
|
|
|
|
|
|
|
|
|
string getTechCRCFileMismatchReport(vector<std::pair<string,int32> > &vctFileList);
|
2010-03-24 14:39:08 +01:00
|
|
|
|
};
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(pop)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class NetworkMessageSynchNetworkGameDataStatus
|
|
|
|
|
//
|
|
|
|
|
// Message sent at the beggining of a network game
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(push, 1)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
class NetworkMessageSynchNetworkGameDataStatus: public NetworkMessage{
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2010-08-26 04:36:17 +02:00
|
|
|
|
static const int maxStringSize= 255;
|
2010-08-26 22:28:26 +02:00
|
|
|
|
static const int maxFileCRCCount= 1500;
|
2010-08-27 00:29:48 +02:00
|
|
|
|
static const int maxFileCRCPacketCount= 25;
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
private:
|
2010-08-22 10:00:05 +02:00
|
|
|
|
|
|
|
|
|
struct DataHeader {
|
2010-03-24 14:39:08 +01:00
|
|
|
|
int8 messageType;
|
|
|
|
|
|
|
|
|
|
int32 mapCRC;
|
|
|
|
|
int32 tilesetCRC;
|
|
|
|
|
int32 techCRC;
|
|
|
|
|
|
2010-08-22 10:00:05 +02:00
|
|
|
|
int32 techCRCFileCount;
|
|
|
|
|
};
|
|
|
|
|
static const int32 HeaderSize = sizeof(DataHeader);
|
|
|
|
|
|
|
|
|
|
struct DataDetail {
|
|
|
|
|
NetworkString<maxStringSize> techCRCFileList[maxFileCRCCount];
|
|
|
|
|
int32 techCRCFileCRCList[maxFileCRCCount];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const int32 DetailSize1 = sizeof(NetworkString<maxStringSize>);
|
|
|
|
|
static const int32 DetailSize2 = sizeof(int32);
|
|
|
|
|
|
|
|
|
|
struct Data {
|
|
|
|
|
DataHeader header;
|
|
|
|
|
DataDetail detail;
|
2010-03-24 14:39:08 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Data data;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
NetworkMessageSynchNetworkGameDataStatus() {};
|
2010-08-22 10:00:05 +02:00
|
|
|
|
NetworkMessageSynchNetworkGameDataStatus(int32 mapCRC, int32 tilesetCRC, int32 techCRC, vector<std::pair<string,int32> > &vctFileList);
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
virtual bool receive(Socket* socket);
|
|
|
|
|
virtual void send(Socket* socket) const;
|
|
|
|
|
|
2010-08-22 10:00:05 +02:00
|
|
|
|
int32 getMapCRC() const {return data.header.mapCRC;}
|
|
|
|
|
int32 getTilesetCRC() const {return data.header.tilesetCRC;}
|
|
|
|
|
int32 getTechCRC() const {return data.header.techCRC;}
|
|
|
|
|
|
|
|
|
|
int32 getTechCRCFileCount() const {return data.header.techCRCFileCount;}
|
|
|
|
|
const NetworkString<maxStringSize> * getTechCRCFileList() const {return &data.detail.techCRCFileList[0];}
|
|
|
|
|
const int32 * getTechCRCFileCRCList() const {return data.detail.techCRCFileCRCList;}
|
|
|
|
|
|
2010-08-26 05:15:36 +02:00
|
|
|
|
string getTechCRCFileMismatchReport(string techtree, vector<std::pair<string,int32> > &vctFileList);
|
2010-08-22 10:00:05 +02:00
|
|
|
|
|
2010-03-24 14:39:08 +01:00
|
|
|
|
};
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(pop)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class NetworkMessageSynchNetworkGameDataFileCRCCheck
|
|
|
|
|
//
|
|
|
|
|
// Message sent at the beggining of a network game
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(push, 1)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
class NetworkMessageSynchNetworkGameDataFileCRCCheck: public NetworkMessage{
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
static const int maxStringSize= 256;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct Data{
|
|
|
|
|
int8 messageType;
|
|
|
|
|
|
|
|
|
|
int32 totalFileCount;
|
|
|
|
|
int32 fileIndex;
|
|
|
|
|
int32 fileCRC;
|
|
|
|
|
NetworkString<maxStringSize> fileName;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Data data;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
NetworkMessageSynchNetworkGameDataFileCRCCheck() {};
|
|
|
|
|
NetworkMessageSynchNetworkGameDataFileCRCCheck(int32 totalFileCount, int32 fileIndex, int32 fileCRC, const string fileName);
|
|
|
|
|
|
|
|
|
|
virtual bool receive(Socket* socket);
|
|
|
|
|
virtual void send(Socket* socket) const;
|
|
|
|
|
|
|
|
|
|
int32 getTotalFileCount() const {return data.totalFileCount;}
|
|
|
|
|
int32 getFileIndex() const {return data.fileIndex;}
|
|
|
|
|
int32 getFileCRC() const {return data.fileCRC;}
|
|
|
|
|
string getFileName() const {return data.fileName.getString();}
|
|
|
|
|
};
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(pop)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
|
// class NetworkMessageSynchNetworkGameDataFileGet
|
|
|
|
|
//
|
|
|
|
|
// Message sent at the beggining of a network game
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(push, 1)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
class NetworkMessageSynchNetworkGameDataFileGet: public NetworkMessage{
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
static const int maxStringSize= 256;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct Data{
|
|
|
|
|
int8 messageType;
|
|
|
|
|
|
|
|
|
|
NetworkString<maxStringSize> fileName;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Data data;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
NetworkMessageSynchNetworkGameDataFileGet() {};
|
|
|
|
|
NetworkMessageSynchNetworkGameDataFileGet(const string fileName);
|
|
|
|
|
|
|
|
|
|
virtual bool receive(Socket* socket);
|
|
|
|
|
virtual void send(Socket* socket) const;
|
|
|
|
|
|
|
|
|
|
string getFileName() const {return data.fileName.getString();}
|
|
|
|
|
};
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(pop)
|
2010-03-24 14:39:08 +01:00
|
|
|
|
|
2010-04-29 01:59:37 +02:00
|
|
|
|
// =====================================================
|
|
|
|
|
// class SwitchSetupRequest
|
|
|
|
|
//
|
2010-05-04 02:05:10 +02:00
|
|
|
|
// Message sent from the client to the server
|
|
|
|
|
// to switch its settings
|
2010-04-29 01:59:37 +02:00
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-08-23 06:33:21 +02:00
|
|
|
|
// Each bit represents which item in the packet has a changed value
|
|
|
|
|
enum SwitchSetupRequestFlagType {
|
|
|
|
|
ssrft_None = 0x00,
|
|
|
|
|
ssrft_SelectedFactionName = 0x01,
|
|
|
|
|
ssrft_CurrentFactionIndex = 0x02,
|
|
|
|
|
ssrft_ToFactionIndex = 0x04,
|
|
|
|
|
ssrft_ToTeam = 0x08,
|
|
|
|
|
ssrft_NetworkPlayerName = 0x10
|
|
|
|
|
};
|
|
|
|
|
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(push, 1)
|
2010-04-29 01:59:37 +02:00
|
|
|
|
class SwitchSetupRequest: public NetworkMessage{
|
|
|
|
|
private:
|
|
|
|
|
static const int maxStringSize= 256;
|
2010-08-23 06:33:21 +02:00
|
|
|
|
static const int maxPlayernameStringSize= 80;
|
2010-04-29 01:59:37 +02:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct Data{
|
|
|
|
|
int8 messageType;
|
|
|
|
|
NetworkString<maxStringSize> selectedFactionName; //wanted faction name
|
|
|
|
|
int8 currentFactionIndex;
|
|
|
|
|
int8 toFactionIndex;
|
|
|
|
|
int8 toTeam;
|
2010-08-23 06:33:21 +02:00
|
|
|
|
NetworkString<maxPlayernameStringSize> networkPlayerName;
|
|
|
|
|
int8 switchFlags;
|
2010-04-29 01:59:37 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Data data;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
SwitchSetupRequest();
|
2010-08-23 06:33:21 +02:00
|
|
|
|
SwitchSetupRequest( string selectedFactionName, int8 currentFactionIndex,
|
|
|
|
|
int8 toFactionIndex,int8 toTeam,string networkPlayerName, int8 flags);
|
2010-04-29 01:59:37 +02:00
|
|
|
|
|
|
|
|
|
string getSelectedFactionName() const {return data.selectedFactionName.getString();}
|
2010-08-21 15:04:52 +02:00
|
|
|
|
int getCurrentFactionIndex() const {return data.currentFactionIndex;}
|
|
|
|
|
int getToFactionIndex() const {return data.toFactionIndex;}
|
2010-04-29 01:59:37 +02:00
|
|
|
|
int getToTeam() const {return data.toTeam;}
|
2010-08-21 15:04:52 +02:00
|
|
|
|
string getNetworkPlayerName() const {return data.networkPlayerName.getString(); }
|
2010-08-23 06:33:21 +02:00
|
|
|
|
int getSwitchFlags() const {return data.switchFlags;}
|
|
|
|
|
int addSwitchFlag(SwitchSetupRequestFlagType flag) { data.switchFlags |= flag;}
|
|
|
|
|
int clearSwitchFlag(SwitchSetupRequestFlagType flag) { data.switchFlags &= ~flag;}
|
2010-04-29 01:59:37 +02:00
|
|
|
|
|
|
|
|
|
virtual bool receive(Socket* socket);
|
|
|
|
|
virtual void send(Socket* socket) const;
|
|
|
|
|
};
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(pop)
|
2010-04-29 01:59:37 +02:00
|
|
|
|
|
2010-04-30 03:08:29 +02:00
|
|
|
|
// =====================================================
|
2010-05-04 02:05:10 +02:00
|
|
|
|
// class PlayerIndexMessage
|
2010-04-30 03:08:29 +02:00
|
|
|
|
//
|
2010-05-04 02:05:10 +02:00
|
|
|
|
// Message sent from the server to the clients
|
|
|
|
|
// to tell them about a slot change ( caused by another client )
|
2010-04-30 03:08:29 +02:00
|
|
|
|
// =====================================================
|
|
|
|
|
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(push, 1)
|
2010-04-30 03:08:29 +02:00
|
|
|
|
class PlayerIndexMessage: public NetworkMessage{
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct Data{
|
|
|
|
|
int8 messageType;
|
|
|
|
|
int16 playerIndex;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Data data;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
PlayerIndexMessage( int16 playerIndex);
|
|
|
|
|
|
|
|
|
|
int16 getPlayerIndex() const {return data.playerIndex;}
|
|
|
|
|
|
|
|
|
|
virtual bool receive(Socket* socket);
|
|
|
|
|
virtual void send(Socket* socket) const;
|
|
|
|
|
};
|
2010-08-07 08:19:56 +02:00
|
|
|
|
#pragma pack(pop)
|
2010-04-29 01:59:37 +02:00
|
|
|
|
|
2010-03-24 14:39:08 +01:00
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
|
|
#endif
|