NetPacksServer.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #include "../lib/NetPacks.h"
  2. #include "CGameHandler.h"
  3. #define PLAYER_OWNS(id) (gh->getPlayerAt(c)==gh->getOwner(id))
  4. #define ERROR_AND_RETURN {if(c) *c << &SystemMessage("You are not allowed to perform this action!"); \
  5. tlog1<<"Player is not allowed to perform this action!\n"; \
  6. return;}
  7. #define ERROR_IF_NOT_OWNS(id) if(!PLAYER_OWNS(id)) ERROR_AND_RETURN
  8. /*
  9. * NetPacksServer.cpp, part of VCMI engine
  10. *
  11. * Authors: listed in file AUTHORS in main folder
  12. *
  13. * License: GNU General Public License v2.0 or later
  14. * Full text of license available in license.txt file, in main folder
  15. *
  16. */
  17. CGameState* CPackForServer::GS(CGameHandler *gh)
  18. {
  19. return gh->gs;
  20. }
  21. void SaveGame::applyGh( CGameHandler *gh )
  22. {
  23. gh->sendMessageTo(*c,"Saving...");
  24. gh->save(fname);
  25. gh->sendMessageTo(*c,"Game has been succesfully saved!");
  26. }
  27. void CloseServer::applyGh( CGameHandler *gh )
  28. {
  29. gh->close();
  30. }
  31. void EndTurn::applyGh( CGameHandler *gh )
  32. {
  33. gh->states.setFlag(GS(gh)->currentPlayer,&PlayerStatus::makingTurn,false);
  34. }
  35. void DismissHero::applyGh( CGameHandler *gh )
  36. {
  37. ERROR_IF_NOT_OWNS(hid);
  38. gh->removeObject(hid);
  39. }
  40. void MoveHero::applyGh( CGameHandler *gh )
  41. {
  42. ERROR_IF_NOT_OWNS(hid);
  43. gh->moveHero(hid,dest,0,gh->getPlayerAt(c));
  44. }
  45. void ArrangeStacks::applyGh( CGameHandler *gh )
  46. {
  47. //ERROR_IF_NOT_OWNS(id1);
  48. //ERROR_IF_NOT_OWNS(id2);
  49. gh->arrangeStacks(id1,id2,what,p1,p2,val);
  50. }
  51. void DisbandCreature::applyGh( CGameHandler *gh )
  52. {
  53. ERROR_IF_NOT_OWNS(id);
  54. gh->disbandCreature(id,pos);
  55. }
  56. void BuildStructure::applyGh( CGameHandler *gh )
  57. {
  58. ERROR_IF_NOT_OWNS(tid);
  59. gh->buildStructure(tid,bid);
  60. }
  61. void RecruitCreatures::applyGh( CGameHandler *gh )
  62. {
  63. ERROR_IF_NOT_OWNS(tid);
  64. gh->recruitCreatures(tid,crid,amount);
  65. }
  66. void UpgradeCreature::applyGh( CGameHandler *gh )
  67. {
  68. ERROR_IF_NOT_OWNS(id);
  69. gh->upgradeCreature(id,pos,cid);
  70. }
  71. void GarrisonHeroSwap::applyGh( CGameHandler *gh )
  72. {
  73. ERROR_IF_NOT_OWNS(tid);
  74. gh->garrisonSwap(tid);
  75. }
  76. void ExchangeArtifacts::applyGh( CGameHandler *gh )
  77. {
  78. ERROR_IF_NOT_OWNS(hid1);
  79. ERROR_IF_NOT_OWNS(hid2);
  80. gh->swapArtifacts(hid1,hid2,slot1,slot2);
  81. }
  82. void BuyArtifact::applyGh( CGameHandler *gh )
  83. {
  84. ERROR_IF_NOT_OWNS(hid);
  85. gh->buyArtifact(hid,aid);
  86. }
  87. void TradeOnMarketplace::applyGh( CGameHandler *gh )
  88. {
  89. if(gh->getPlayerAt(c) != player) ERROR_AND_RETURN;
  90. gh->tradeResources(val,player,r1,r2);
  91. }
  92. void SetFormation::applyGh( CGameHandler *gh )
  93. {
  94. ERROR_IF_NOT_OWNS(hid);
  95. gh->setFormation(hid,formation);
  96. }
  97. void HireHero::applyGh( CGameHandler *gh )
  98. {
  99. ERROR_IF_NOT_OWNS(tid);
  100. gh->hireHero(tid,hid);
  101. }
  102. void QueryReply::applyGh( CGameHandler *gh )
  103. {
  104. gh->queryReply(qid,answer);
  105. }
  106. void MakeAction::applyGh( CGameHandler *gh )
  107. {
  108. if(gh->connections[GS(gh)->curB->getStack(GS(gh)->curB->activeStack)->owner] != c) ERROR_AND_RETURN;
  109. gh->makeBattleAction(ba);
  110. }
  111. void MakeCustomAction::applyGh( CGameHandler *gh )
  112. {
  113. if(gh->connections[GS(gh)->curB->getStack(GS(gh)->curB->activeStack)->owner] != c) ERROR_AND_RETURN;
  114. gh->makeCustomAction(ba);
  115. }
  116. void PlayerMessage::applyGh( CGameHandler *gh )
  117. {
  118. if(gh->getPlayerAt(c) != player) ERROR_AND_RETURN;
  119. gh->playerMessage(player,text);
  120. }
  121. void SetSelection::applyGh( CGameHandler *gh )
  122. {
  123. if(gh->getPlayerAt(c) != player) ERROR_AND_RETURN;
  124. gh->sendAndApply(this);
  125. }