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

385 lines
7.9 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"
#include "../serializer/ESerializationVersion.h"
#include "../texts/MetaString.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
{
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;
EStartMode mode = EStartMode::INVALID;
// Changed by server before announcing pack
2023-02-09 18:06:02 +02:00
int clientId = -1;
int hostClientId = -1;
ESerializationVersion version = ESerializationVersion::CURRENT;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler & h)
{
h & uuid;
h & names;
h & mode;
h & clientId;
h & hostClientId;
h & version;
}
};
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)
{
h & clientId;
h & shutdownServer;
}
};
struct DLL_LINKAGE LobbyChatMessage : public CLobbyPackToPropagate
{
std::string playerName;
2024-05-02 21:03:23 +02:00
MetaString message;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h)
{
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)
{
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)
2023-08-21 03:06:58 +02:00
{
h & progress;
}
};
struct DLL_LINKAGE LobbyRestartGame : public CLobbyPackToPropagate
{
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h)
{
}
};
struct DLL_LINKAGE LobbyPrepareStartGame : public CLobbyPackToPropagate
{
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h)
{
}
};
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)
{
if (!h.saving)
h.loadingGamestate = true;
2022-10-01 16:28:45 +02:00
h & clientId;
h & initializedStartInfo;
2022-09-28 21:15:05 +02:00
h & initializedGameState;
if (!h.saving)
h.loadingGamestate = false;
}
};
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)
{
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)
{
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)
{
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)
{
h & ourCampaign;
}
};
struct DLL_LINKAGE LobbySetCampaignMap : public CLobbyPackToServer
{
CampaignScenarioID mapId = CampaignScenarioID::NONE;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h)
{
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)
{
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)
{
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)
{
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)
2023-10-13 23:04:35 +02:00
{
h & color;
h & name;
}
};
2024-07-16 00:40:39 +02:00
struct DLL_LINKAGE LobbySetPlayerHandicap : public CLobbyPackToServer
{
PlayerColor color = PlayerColor::CANNOT_DETERMINE;
2024-07-29 22:54:42 +02:00
Handicap handicap = Handicap();
2024-07-16 00:40:39 +02:00
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h)
{
h & color;
2024-07-29 22:54:42 +02:00
h & handicap;
2024-07-16 00:40:39 +02:00
}
};
struct DLL_LINKAGE LobbySetSimturns : public CLobbyPackToServer
{
SimturnsInfo simturnsInfo;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h)
{
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)
{
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)
2023-12-27 15:39:35 +02:00
{
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)
{
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)
{
h & targetConnectedPlayer;
h & targetPlayerColor;
}
};
struct DLL_LINKAGE LobbyShowMessage : public CLobbyPackToPropagate
{
2024-05-02 21:03:23 +02:00
MetaString message;
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler & h)
{
h & message;
}
};
2024-04-30 01:52:49 +02:00
struct DLL_LINKAGE LobbyPvPAction : public CLobbyPackToServer
{
enum EAction : ui8 {
NONE, COIN, RANDOM_TOWN, RANDOM_TOWN_VS
};
EAction action = NONE;
2024-05-01 00:49:33 +02:00
std::vector<FactionID> bannedTowns;
2024-04-30 01:52:49 +02:00
void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h)
{
h & action;
2024-05-01 00:49:33 +02:00
h & bannedTowns;
2024-04-30 01:52:49 +02:00
}
};
VCMI_LIB_NAMESPACE_END