1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-12 10:03:53 +02:00
vcmi/lib/networkPacks/PacksForLobby.h

343 lines
7.4 KiB
C++
Raw Normal View History

/*
* PacksForLobby.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "StartInfo.h"
#include "NetPacksBase.h"
class CServerHandler;
class CVCMIServer;
VCMI_LIB_NAMESPACE_BEGIN
class CampaignState;
class CMapInfo;
struct StartInfo;
class CMapGenOptions;
struct ClientPlayer;
struct DLL_LINKAGE CLobbyPackToPropagate : public CPackForLobby
{
};
struct DLL_LINKAGE CLobbyPackToServer : public CPackForLobby
{
virtual bool isForServer() const override;
};
struct DLL_LINKAGE LobbyClientConnected : public CLobbyPackToPropagate
{
// Set by client before sending pack to server
std::string uuid;
std::vector<std::string> names;
2023-02-09 18:06:02 +02:00
StartInfo::EMode mode = StartInfo::INVALID;
// Changed by server before announcing pack
2023-02-09 18:06:02 +02:00
int clientId = -1;
int hostClientId = -1;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler & h, const int version)
{
h & uuid;
h & names;
h & mode;
h & clientId;
h & hostClientId;
}
};
struct DLL_LINKAGE LobbyClientDisconnected : public CLobbyPackToPropagate
{
int clientId;
2023-02-09 18:06:02 +02:00
bool shutdownServer = false;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & clientId;
h & shutdownServer;
}
};
struct DLL_LINKAGE LobbyChatMessage : public CLobbyPackToPropagate
{
std::string playerName;
std::string message;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & playerName;
h & message;
}
};
struct DLL_LINKAGE LobbyGuiAction : public CLobbyPackToPropagate
{
enum EAction : ui8 {
2023-12-28 20:41:01 +02:00
NONE, NO_TAB, OPEN_OPTIONS, OPEN_SCENARIO_LIST, OPEN_RANDOM_MAP_OPTIONS, OPEN_TURN_OPTIONS, OPEN_EXTRA_OPTIONS
2023-02-09 18:06:02 +02:00
} action = NONE;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & action;
}
};
2023-08-21 03:06:58 +02:00
struct DLL_LINKAGE LobbyLoadProgress : public CLobbyPackToPropagate
{
unsigned char progress;
void visitTyped(ICPackVisitor & visitor) override;
2023-08-21 03:06:58 +02:00
template <typename Handler> void serialize(Handler &h, const int version)
{
h & progress;
}
};
struct DLL_LINKAGE LobbyEndGame : public CLobbyPackToPropagate
{
bool closeConnection = false;
bool restart = false;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & closeConnection;
h & restart;
}
};
struct DLL_LINKAGE LobbyStartGame : public CLobbyPackToPropagate
{
// Set by server
2023-02-09 18:06:02 +02:00
std::shared_ptr<StartInfo> initializedStartInfo = nullptr;
CGameState * initializedGameState = nullptr;
int clientId = -1; //-1 means to all clients
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
2022-10-01 16:28:45 +02:00
h & clientId;
h & initializedStartInfo;
2022-09-28 21:15:05 +02:00
bool sps = h.smartPointerSerialization;
h.smartPointerSerialization = true;
h & initializedGameState;
h.smartPointerSerialization = sps;
}
};
struct DLL_LINKAGE LobbyChangeHost : public CLobbyPackToPropagate
{
2023-02-09 18:06:02 +02:00
int newHostConnectionId = -1;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler & h, const int version)
{
h & newHostConnectionId;
}
};
struct DLL_LINKAGE LobbyUpdateState : public CLobbyPackToPropagate
{
LobbyState state;
2023-02-09 18:06:02 +02:00
bool hostChanged = false; // Used on client-side only
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & state;
}
};
struct DLL_LINKAGE LobbySetMap : public CLobbyPackToServer
{
std::shared_ptr<CMapInfo> mapInfo;
std::shared_ptr<CMapGenOptions> mapGenOpts;
LobbySetMap() : mapInfo(nullptr), mapGenOpts(nullptr) {}
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & mapInfo;
h & mapGenOpts;
}
};
struct DLL_LINKAGE LobbySetCampaign : public CLobbyPackToServer
{
std::shared_ptr<CampaignState> ourCampaign;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & ourCampaign;
}
};
struct DLL_LINKAGE LobbySetCampaignMap : public CLobbyPackToServer
{
CampaignScenarioID mapId = CampaignScenarioID::NONE;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & mapId;
}
};
struct DLL_LINKAGE LobbySetCampaignBonus : public CLobbyPackToServer
{
2023-02-09 18:06:02 +02:00
int bonusId = -1;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & bonusId;
}
};
struct DLL_LINKAGE LobbyChangePlayerOption : public CLobbyPackToServer
{
enum EWhat : ui8 {UNKNOWN, TOWN, HERO, BONUS, TOWN_ID, HERO_ID, BONUS_ID};
2023-02-09 18:06:02 +02:00
ui8 what = UNKNOWN;
2023-08-17 17:29:31 +02:00
int32_t value = 0;
2023-02-09 18:06:02 +02:00
PlayerColor color = PlayerColor::CANNOT_DETERMINE;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & what;
h & value;
h & color;
}
};
struct DLL_LINKAGE LobbySetPlayer : public CLobbyPackToServer
{
2023-02-09 18:06:02 +02:00
PlayerColor clickedColor = PlayerColor::CANNOT_DETERMINE;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & clickedColor;
}
};
2023-10-13 23:04:35 +02:00
struct DLL_LINKAGE LobbySetPlayerName : public CLobbyPackToServer
{
PlayerColor color = PlayerColor::CANNOT_DETERMINE;
std::string name = "";
void visitTyped(ICPackVisitor & visitor) override;
2023-10-13 23:04:35 +02:00
template <typename Handler> void serialize(Handler &h, const int version)
{
h & color;
h & name;
}
};
struct DLL_LINKAGE LobbySetSimturns : public CLobbyPackToServer
{
SimturnsInfo simturnsInfo;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & simturnsInfo;
}
};
struct DLL_LINKAGE LobbySetTurnTime : public CLobbyPackToServer
{
2023-08-14 00:16:25 +02:00
TurnTimerInfo turnTimerInfo;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
2023-08-14 00:16:25 +02:00
h & turnTimerInfo;
}
};
2023-12-28 21:48:19 +02:00
struct DLL_LINKAGE LobbySetExtraOptions : public CLobbyPackToServer
2023-12-27 15:39:35 +02:00
{
2023-12-28 21:48:19 +02:00
ExtraOptionsInfo extraOptionsInfo;
2023-12-27 15:39:35 +02:00
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
2023-12-28 21:48:19 +02:00
h & extraOptionsInfo;
2023-12-27 15:39:35 +02:00
}
};
struct DLL_LINKAGE LobbySetDifficulty : public CLobbyPackToServer
{
2023-02-09 18:06:02 +02:00
ui8 difficulty = 0;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & difficulty;
}
};
struct DLL_LINKAGE LobbyForceSetPlayer : public CLobbyPackToServer
{
2023-02-09 18:06:02 +02:00
ui8 targetConnectedPlayer = -1;
PlayerColor targetPlayerColor = PlayerColor::CANNOT_DETERMINE;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler & h, const int version)
{
h & targetConnectedPlayer;
h & targetPlayerColor;
}
};
struct DLL_LINKAGE LobbyShowMessage : public CLobbyPackToPropagate
{
std::string message;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler & h, const int version)
{
h & message;
}
};
VCMI_LIB_NAMESPACE_END