From 74fafbedbf2a35cb29df0b50ac9f1e535201227a Mon Sep 17 00:00:00 2001 From: "ori.bar" Date: Sat, 17 Sep 2011 18:15:10 +0000 Subject: [PATCH] Fix #807 --- client/CPlayerInterface.cpp | 3 +++ server/CGameHandler.cpp | 27 ++++++++++++++++++--------- server/CGameHandler.h | 4 +++- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index e04f505a2..8dd100ca2 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -1186,7 +1186,10 @@ bool CPlayerInterface::altPressed() const void CPlayerInterface::showGarrisonDialog( const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, boost::function &onEnd ) { if(stillMoveHero.get() == DURING_MOVE && adventureInt->terrain.currentPath->nodes.size() > 1) //to ignore calls on passing through garrisons + { + onEnd(); return; + } { boost::unique_lock un(showingDialog->mx); diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 02ec1ed6b..80bb4a327 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -634,8 +634,9 @@ void CGameHandler::handleConnection(std::set players, CConnection &c) int packType = typeList.getTypeID(pack); //get the id of type CBaseForGHApply *apply = applier->apps[packType]; //and appropriae applier object - - if(packType != typeList.getTypeID() && states[getCurrentPlayer()].queries.size()) + if(packType != typeList.getTypeID() && + (packType != typeList.getTypeID() || !isAllowedArrangePack((ArrangeStacks*)pack)) && // for dialogs like garrison + states[getCurrentPlayer()].queries.size()) { complain("Answer the query before attempting any further actions!"); PackageApplied applied; @@ -4003,18 +4004,26 @@ void CGameHandler::showThievesGuildWindow(int requestingObjId) sendAndApply(&ow); } +bool CGameHandler::isAllowedArrangePack(const ArrangeStacks *pack) +{ + return isAllowedExchangeForQuery(pack->id1, pack->id2); +} + +bool CGameHandler::isAllowedExchangeForQuery(int id1, int id2) { + boost::unique_lock lock(gsm); + for(std::map >::const_iterator i = allowedExchanges.begin(); i!=allowedExchanges.end(); i++) + if((id1 == i->second.first && id2 == i->second.second) || + (id2 == i->second.first && id1 == i->second.second)) + return true; +} + bool CGameHandler::isAllowedExchange( int id1, int id2 ) { if(id1 == id2) return true; - { - boost::unique_lock lock(gsm); - for(std::map >::const_iterator i = allowedExchanges.begin(); i!=allowedExchanges.end(); i++) - if((id1 == i->second.first && id2 == i->second.second) || - (id2 == i->second.first && id1 == i->second.second)) - return true; - } + if (isAllowedExchangeForQuery(id1, id2)) + return true; const CGObjectInstance *o1 = getObj(id1), *o2 = getObj(id2); diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 8ecdd74b8..7c4d52089 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -89,6 +89,7 @@ class CGameHandler : public IGameCallback { private: void makeStackDoNothing(const CStack * next); + bool isAllowedExchangeForQuery(int id1, int id2); public: CVCMIServer *s; std::map connections; //player color -> connection to client with interface of that player @@ -103,6 +104,7 @@ public: std::map > allowedExchanges; bool isAllowedExchange(int id1, int id2); + bool isAllowedArrangePack(const ArrangeStacks *pack); void giveSpells(const CGTownInstance *t, const CGHeroInstance *h); int moveStack(int stack, THex dest); //returned value - travelled distance void startBattle(const CArmedInstance *armies[2], int3 tile, const CGHeroInstance *heroes[2], bool creatureBank, boost::function cb, const CGTownInstance *town = NULL); //use hero=NULL for no hero @@ -261,4 +263,4 @@ public: #endif // __CGAMEHANDLER_H__ -void makeStackDoNothing(); \ No newline at end of file +void makeStackDoNothing();