1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Full rework of pre-game interface and networking

New features for players:
* Loading for multiplayer. Any save could be used for multiplayer.
* Restart for multiplayer. All clients will restart together.
* Loading from single save.
* Hotseat mixed with network game. Multiple players per client.
* Now connection to server could be cancelled.
* Return to menu on disconnections instead of crashes.
* Restoring of last selected map, save or campaign on next run.

TLDR on important changes in engine code:
* UI: work with server separated from UI
* UI: all explitic blitting replaced with IntObject's
* UI: all new code use smart pointers instead of DISPOSE
* Gameplay always start through lobby controlled by server.
* Threads receiving netpacks now shared for lobby and gameplay.
* Campaigns: heroes for crossover now serialized as JsonNode.
This commit is contained in:
Arseniy Shestakov
2018-01-05 20:21:07 +03:00
parent 14f03e22da
commit ac66fc7f42
85 changed files with 8808 additions and 7938 deletions

View File

@@ -30,6 +30,9 @@ class IMarket;
class SpellCastEnvironment;
template<typename T> class CApplier;
class CBaseForGHApply;
struct PlayerStatus
{
bool makingTurn;
@@ -74,6 +77,8 @@ struct CasualtiesAfterBattle
class CGameHandler : public IGameCallback, CBattleInfoCallback
{
CVCMIServer * lobby;
std::shared_ptr<CApplier<CBaseForGHApply>> applier;
public:
using FireShieldInfo = std::vector<std::pair<const CStack *, int64_t>>;
//use enums as parameters, because doMove(sth, true, false, true) is not readable
@@ -81,9 +86,8 @@ public:
enum EVisitDest {VISIT_DEST, DONT_VISIT_DEST};
enum ELEaveTile {LEAVING_TILE, REMAINING_ON_TILE};
std::map<PlayerColor, CConnection*> connections; //player color -> connection to client with interface of that player
std::map<PlayerColor, std::set<std::shared_ptr<CConnection>>> connections; //player color -> connection to client with interface of that player
PlayerStatuses states; //player color -> player state
std::set<CConnection*> conns;
//queries stuff
boost::recursive_mutex gsm;
@@ -111,7 +115,7 @@ public:
void setupBattle(int3 tile, const CArmedInstance *armies[2], const CGHeroInstance *heroes[2], bool creatureBank, const CGTownInstance *town);
void setBattleResult(BattleResult::EResult resultType, int victoriusSide);
CGameHandler();
CGameHandler(CVCMIServer * lobby);
~CGameHandler();
//////////////////////////////////////////////////////////////////////////
@@ -189,8 +193,9 @@ public:
void commitPackage(CPackForClient *pack) override;
void init(StartInfo *si);
void handleConnection(std::set<PlayerColor> players, CConnection &c);
PlayerColor getPlayerAt(CConnection *c) const;
void handleClientDisconnection(std::shared_ptr<CConnection> c);
void handleReceivedPack(CPackForServer * pack);
PlayerColor getPlayerAt(std::shared_ptr<CConnection> c) const;
void playerMessage(PlayerColor player, const std::string &message, ObjectInstanceID currObj);
void updateGateState();
@@ -225,8 +230,8 @@ public:
bool disbandCreature( ObjectInstanceID id, SlotID pos );
bool arrangeStacks( ObjectInstanceID id1, ObjectInstanceID id2, ui8 what, SlotID p1, SlotID p2, si32 val, PlayerColor player);
void save(const std::string &fname);
void close();
void playerLeftGame(int cid);
void load(const std::string &fname);
void handleTimeEvents();
void handleTownEvents(CGTownInstance *town, NewTurn &n);
bool complain(const std::string &problem); //sends message to all clients, prints on the logs and return true
@@ -248,7 +253,7 @@ public:
}
void sendMessageToAll(const std::string &message);
void sendMessageTo(CConnection &c, const std::string &message);
void sendMessageTo(std::shared_ptr<CConnection> c, const std::string &message);
void sendToAllClients(CPackForClient * info);
void sendAndApply(CPackForClient * info) override;
void applyAndSend(CPackForClient * info);
@@ -308,10 +313,6 @@ private:
void checkVictoryLossConditionsForAll();
};
class clientDisconnectedException : public std::exception
{
};
class ExceptionNotAllowedAction : public std::exception
{