| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- /*
- * 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 CCampaignState;
- class CLobbyScreen;
- class CServerHandler;
- class CMapInfo;
- struct StartInfo;
- class CMapGenOptions;
- struct ClientPlayer;
- class CVCMIServer;
- struct CPackForLobby : public CPack
- {
- bool checkClientPermissions(CVCMIServer * srv) const
- {
- return false;
- }
- bool applyOnServer(CVCMIServer * srv)
- {
- return true;
- }
- void applyOnServerAfterAnnounce(CVCMIServer * srv) {}
- bool applyOnLobbyHandler(CServerHandler * handler)
- {
- return true;
- }
- void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler) {}
- };
- struct CLobbyPackToPropagate : public CPackForLobby
- {
- };
- struct CLobbyPackToServer : public CPackForLobby
- {
- bool checkClientPermissions(CVCMIServer * srv) const;
- void applyOnServerAfterAnnounce(CVCMIServer * srv);
- };
- struct LobbyClientConnected : public CLobbyPackToPropagate
- {
- // Set by client before sending pack to server
- std::string uuid;
- std::vector<std::string> names;
- StartInfo::EMode mode;
- // Changed by server before announcing pack
- int clientId;
- int hostClientId;
- LobbyClientConnected()
- : mode(StartInfo::INVALID), clientId(-1), hostClientId(-1)
- {}
- bool checkClientPermissions(CVCMIServer * srv) const;
- bool applyOnLobbyHandler(CServerHandler * handler);
- void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler);
- bool applyOnServer(CVCMIServer * srv);
- void applyOnServerAfterAnnounce(CVCMIServer * srv);
- template <typename Handler> void serialize(Handler & h, const int version)
- {
- h & uuid;
- h & names;
- h & mode;
- h & clientId;
- h & hostClientId;
- }
- };
- struct LobbyClientDisconnected : public CLobbyPackToPropagate
- {
- int clientId;
- bool shutdownServer;
- LobbyClientDisconnected() : shutdownServer(false) {}
- bool checkClientPermissions(CVCMIServer * srv) const;
- bool applyOnServer(CVCMIServer * srv);
- void applyOnServerAfterAnnounce(CVCMIServer * srv);
- bool applyOnLobbyHandler(CServerHandler * handler);
- void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler);
- template <typename Handler> void serialize(Handler &h, const int version)
- {
- h & clientId;
- h & shutdownServer;
- }
- };
- struct LobbyChatMessage : public CLobbyPackToPropagate
- {
- std::string playerName, message;
- bool checkClientPermissions(CVCMIServer * srv) const;
- void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler);
- template <typename Handler> void serialize(Handler &h, const int version)
- {
- h & playerName;
- h & message;
- }
- };
- struct LobbyGuiAction : public CLobbyPackToPropagate
- {
- enum EAction : ui8 {
- NONE, NO_TAB, OPEN_OPTIONS, OPEN_SCENARIO_LIST, OPEN_RANDOM_MAP_OPTIONS
- } action;
- LobbyGuiAction() : action(NONE) {}
- bool checkClientPermissions(CVCMIServer * srv) const;
- void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler);
- template <typename Handler> void serialize(Handler &h, const int version)
- {
- h & action;
- }
- };
- struct LobbyStartGame : public CLobbyPackToPropagate
- {
- // Set by server
- std::shared_ptr<StartInfo> initializedStartInfo;
- LobbyStartGame() : initializedStartInfo(nullptr) {}
- bool checkClientPermissions(CVCMIServer * srv) const;
- bool applyOnServer(CVCMIServer * srv);
- void applyOnServerAfterAnnounce(CVCMIServer * srv);
- bool applyOnLobbyHandler(CServerHandler * handler);
- void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler);
- template <typename Handler> void serialize(Handler &h, const int version)
- {
- h & initializedStartInfo;
- }
- };
- struct LobbyChangeHost : public CLobbyPackToPropagate
- {
- int newHostConnectionId;
- LobbyChangeHost() : newHostConnectionId(-1) {}
- bool checkClientPermissions(CVCMIServer * srv) const;
- bool applyOnServer(CVCMIServer * srv);
- bool applyOnServerAfterAnnounce(CVCMIServer * srv);
- template <typename Handler> void serialize(Handler & h, const int version)
- {
- h & newHostConnectionId;
- }
- };
- struct LobbyUpdateState : public CLobbyPackToPropagate
- {
- LobbyState state;
- bool hostChanged; // Used on client-side only
- LobbyUpdateState() : hostChanged(false) {}
- bool applyOnLobbyHandler(CServerHandler * handler);
- void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler);
- template <typename Handler> void serialize(Handler &h, const int version)
- {
- h & state;
- }
- };
- struct LobbySetMap : public CLobbyPackToServer
- {
- std::shared_ptr<CMapInfo> mapInfo;
- std::shared_ptr<CMapGenOptions> mapGenOpts;
- LobbySetMap() : mapInfo(nullptr), mapGenOpts(nullptr) {}
- bool applyOnServer(CVCMIServer * srv);
- template <typename Handler> void serialize(Handler &h, const int version)
- {
- h & mapInfo;
- h & mapGenOpts;
- }
- };
- struct LobbySetCampaign : public CLobbyPackToServer
- {
- std::shared_ptr<CCampaignState> ourCampaign;
- LobbySetCampaign() {}
- bool applyOnServer(CVCMIServer * srv);
- template <typename Handler> void serialize(Handler &h, const int version)
- {
- h & ourCampaign;
- }
- };
- struct LobbySetCampaignMap : public CLobbyPackToServer
- {
- int mapId;
- LobbySetCampaignMap() : mapId(-1) {}
- bool applyOnServer(CVCMIServer * srv);
- template <typename Handler> void serialize(Handler &h, const int version)
- {
- h & mapId;
- }
- };
- struct LobbySetCampaignBonus : public CLobbyPackToServer
- {
- int bonusId;
- LobbySetCampaignBonus() : bonusId(-1) {}
- bool applyOnServer(CVCMIServer * srv);
- template <typename Handler> void serialize(Handler &h, const int version)
- {
- h & bonusId;
- }
- };
- struct LobbyChangePlayerOption : public CLobbyPackToServer
- {
- enum EWhat : ui8 {UNKNOWN, TOWN, HERO, BONUS};
- ui8 what;
- si8 direction; //-1 or +1
- PlayerColor color;
- LobbyChangePlayerOption() : what(UNKNOWN), direction(0), color(PlayerColor::CANNOT_DETERMINE) {}
- bool checkClientPermissions(CVCMIServer * srv) const;
- bool applyOnServer(CVCMIServer * srv);
- template <typename Handler> void serialize(Handler &h, const int version)
- {
- h & what;
- h & direction;
- h & color;
- }
- };
- struct LobbySetPlayer : public CLobbyPackToServer
- {
- PlayerColor clickedColor;
- LobbySetPlayer() : clickedColor(PlayerColor::CANNOT_DETERMINE){}
- bool applyOnServer(CVCMIServer * srv);
- template <typename Handler> void serialize(Handler &h, const int version)
- {
- h & clickedColor;
- }
- };
- struct LobbySetTurnTime : public CLobbyPackToServer
- {
- ui8 turnTime;
- LobbySetTurnTime() : turnTime(0) {}
- bool applyOnServer(CVCMIServer * srv);
- template <typename Handler> void serialize(Handler &h, const int version)
- {
- h & turnTime;
- }
- };
- struct LobbySetDifficulty : public CLobbyPackToServer
- {
- ui8 difficulty;
- LobbySetDifficulty() : difficulty(0) {}
- bool applyOnServer(CVCMIServer * srv);
- template <typename Handler> void serialize(Handler &h, const int version)
- {
- h & difficulty;
- }
- };
- struct LobbyForceSetPlayer : public CLobbyPackToServer
- {
- ui8 targetConnectedPlayer;
- PlayerColor targetPlayerColor;
- LobbyForceSetPlayer() : targetConnectedPlayer(-1), targetPlayerColor(PlayerColor::CANNOT_DETERMINE) {}
- bool applyOnServer(CVCMIServer * srv);
- template <typename Handler> void serialize(Handler & h, const int version)
- {
- h & targetConnectedPlayer;
- h & targetPlayerColor;
- }
- };
- struct LobbyShowMessage : public CLobbyPackToPropagate
- {
- std::string message;
-
- void applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler);
-
- template <typename Handler> void serialize(Handler &h, const int version)
- {
- h & message;
- }
- };
|