1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-04 09:42:40 +02:00
vcmi/lib/NetPacksLobby.h

292 lines
6.4 KiB
C
Raw Normal View History

/*
* NetPacksLobby.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 "NetPacksBase.h"
#include "StartInfo.h"
class CServerHandler;
class CVCMIServer;
VCMI_LIB_NAMESPACE_BEGIN
class CCampaignState;
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;
virtual 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;
virtual 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, message;
virtual 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 {
NONE, NO_TAB, OPEN_OPTIONS, OPEN_SCENARIO_LIST, OPEN_RANDOM_MAP_OPTIONS
2023-02-09 18:06:02 +02:00
} action = NONE;
virtual void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & action;
}
};
struct DLL_LINKAGE LobbyEndGame : public CLobbyPackToPropagate
{
bool closeConnection = false, restart = false;
virtual 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
virtual 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;
virtual 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
virtual 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) {}
virtual 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<CCampaignState> ourCampaign;
virtual void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & ourCampaign;
}
};
struct DLL_LINKAGE LobbySetCampaignMap : public CLobbyPackToServer
{
2023-02-09 18:06:02 +02:00
int mapId = -1;
virtual 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;
virtual 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};
2023-02-09 18:06:02 +02:00
ui8 what = UNKNOWN;
si8 direction = 0; //-1 or +1
PlayerColor color = PlayerColor::CANNOT_DETERMINE;
virtual void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & what;
h & direction;
h & color;
}
};
struct DLL_LINKAGE LobbySetPlayer : public CLobbyPackToServer
{
2023-02-09 18:06:02 +02:00
PlayerColor clickedColor = PlayerColor::CANNOT_DETERMINE;
virtual void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & clickedColor;
}
};
struct DLL_LINKAGE LobbySetTurnTime : public CLobbyPackToServer
{
2023-02-09 18:06:02 +02:00
ui8 turnTime = 0;
virtual void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & turnTime;
}
};
struct DLL_LINKAGE LobbySetDifficulty : public CLobbyPackToServer
{
2023-02-09 18:06:02 +02:00
ui8 difficulty = 0;
virtual 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;
virtual 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;
virtual void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler & h, const int version)
{
h & message;
}
};
VCMI_LIB_NAMESPACE_END