mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
Merge pull request #305 from vcmi/networkImprovements
Network and multiplayer improvements
This commit is contained in:
@@ -19,19 +19,22 @@
|
||||
struct ServerReady
|
||||
{
|
||||
bool ready;
|
||||
uint16_t port; //ui16?
|
||||
boost::interprocess::interprocess_mutex mutex;
|
||||
boost::interprocess::interprocess_condition cond;
|
||||
|
||||
ServerReady()
|
||||
{
|
||||
ready = false;
|
||||
port = 0;
|
||||
}
|
||||
|
||||
void setToTrueAndNotify()
|
||||
void setToTrueAndNotify(uint16_t Port)
|
||||
{
|
||||
{
|
||||
boost::unique_lock<boost::interprocess::interprocess_mutex> lock(mutex);
|
||||
ready = true;
|
||||
port = Port;
|
||||
}
|
||||
cond.notify_all();
|
||||
}
|
||||
|
||||
@@ -152,6 +152,21 @@ struct PlayerBlocked : public CPackForClient
|
||||
}
|
||||
};
|
||||
|
||||
struct PlayerCheated : public CPackForClient
|
||||
{
|
||||
PlayerCheated() : losingCheatCode(false), winningCheatCode(false) {}
|
||||
DLL_LINKAGE void applyGs(CGameState *gs);
|
||||
|
||||
PlayerColor player;
|
||||
bool losingCheatCode;
|
||||
bool winningCheatCode;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & player & losingCheatCode & winningCheatCode;
|
||||
}
|
||||
};
|
||||
|
||||
struct YourTurn : public CPackForClient
|
||||
{
|
||||
YourTurn(){}
|
||||
@@ -1774,6 +1789,13 @@ struct CloseServer : public CPackForServer
|
||||
{}
|
||||
};
|
||||
|
||||
struct LeaveGame : public CPackForServer
|
||||
{
|
||||
bool applyGh(CGameHandler *gh);
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{}
|
||||
};
|
||||
|
||||
struct EndTurn : public CPackForServer
|
||||
{
|
||||
bool applyGh(CGameHandler *gh);
|
||||
|
||||
@@ -1840,6 +1840,12 @@ DLL_LINKAGE void BattleSetStackProperty::applyGs(CGameState *gs)
|
||||
}
|
||||
}
|
||||
|
||||
DLL_LINKAGE void PlayerCheated::applyGs(CGameState *gs)
|
||||
{
|
||||
gs->getPlayer(player)->enteredLosingCheatCode = losingCheatCode;
|
||||
gs->getPlayer(player)->enteredWinningCheatCode = winningCheatCode;
|
||||
}
|
||||
|
||||
DLL_LINKAGE void YourTurn::applyGs(CGameState *gs)
|
||||
{
|
||||
gs->currentPlayer = player;
|
||||
|
||||
@@ -424,4 +424,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -669,4 +669,4 @@
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -210,6 +210,7 @@ void registerTypesClientPacks1(Serializer &s)
|
||||
s.template registerType<CPackForClient, PackageApplied>();
|
||||
s.template registerType<CPackForClient, SystemMessage>();
|
||||
s.template registerType<CPackForClient, PlayerBlocked>();
|
||||
s.template registerType<CPackForClient, PlayerCheated>();
|
||||
s.template registerType<CPackForClient, YourTurn>();
|
||||
s.template registerType<CPackForClient, SetResources>();
|
||||
s.template registerType<CPackForClient, SetPrimSkill>();
|
||||
@@ -314,6 +315,7 @@ void registerTypesServerPacks(Serializer &s)
|
||||
{
|
||||
s.template registerType<CPack, CPackForServer>();
|
||||
s.template registerType<CPackForServer, CloseServer>();
|
||||
s.template registerType<CPackForServer, LeaveGame>();
|
||||
s.template registerType<CPackForServer, EndTurn>();
|
||||
s.template registerType<CPackForServer, DismissHero>();
|
||||
s.template registerType<CPackForServer, MoveHero>();
|
||||
|
||||
@@ -191,8 +191,7 @@ void CConnection::close()
|
||||
if(socket)
|
||||
{
|
||||
socket->close();
|
||||
delete socket;
|
||||
socket = nullptr;
|
||||
vstd::clear_pointer(socket);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,6 +200,11 @@ bool CConnection::isOpen() const
|
||||
return socket && connected;
|
||||
}
|
||||
|
||||
bool CConnection::isHost() const
|
||||
{
|
||||
return connectionID == 1;
|
||||
}
|
||||
|
||||
void CConnection::reportState(CLogger * out)
|
||||
{
|
||||
out->debugStream() << "CConnection";
|
||||
|
||||
@@ -74,6 +74,7 @@ public:
|
||||
|
||||
void close();
|
||||
bool isOpen() const;
|
||||
bool isHost() const;
|
||||
template<class T>
|
||||
CConnection &operator&(const T&);
|
||||
virtual ~CConnection(void);
|
||||
|
||||
Reference in New Issue
Block a user