NetPacksServer.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. CGameState* CPackForServer::GS(CGameHandler *gh)
  9. {
  10. return gh->gs;
  11. }
  12. void SaveGame::applyGh( CGameHandler *gh )
  13. {
  14. gh->sendMessageTo(*c,"Saving...");
  15. gh->save(fname);
  16. gh->sendMessageTo(*c,"Game has been succesfully saved!");
  17. }
  18. void CloseServer::applyGh( CGameHandler *gh )
  19. {
  20. gh->close();
  21. }
  22. void EndTurn::applyGh( CGameHandler *gh )
  23. {
  24. gh->states.setFlag(GS(gh)->currentPlayer,&PlayerStatus::makingTurn,false);
  25. }
  26. void DismissHero::applyGh( CGameHandler *gh )
  27. {
  28. ERROR_IF_NOT_OWNS(hid);
  29. gh->removeObject(hid);
  30. }
  31. void MoveHero::applyGh( CGameHandler *gh )
  32. {
  33. ERROR_IF_NOT_OWNS(hid);
  34. gh->moveHero(hid,dest,0,gh->getPlayerAt(c));
  35. }
  36. void ArrangeStacks::applyGh( CGameHandler *gh )
  37. {
  38. ERROR_IF_NOT_OWNS(id1);
  39. ERROR_IF_NOT_OWNS(id2);
  40. gh->arrangeStacks(id1,id2,what,p1,p2,val);
  41. }
  42. void DisbandCreature::applyGh( CGameHandler *gh )
  43. {
  44. ERROR_IF_NOT_OWNS(id);
  45. gh->disbandCreature(id,pos);
  46. }
  47. void BuildStructure::applyGh( CGameHandler *gh )
  48. {
  49. ERROR_IF_NOT_OWNS(tid);
  50. gh->buildStructure(tid,bid);
  51. }
  52. void RecruitCreatures::applyGh( CGameHandler *gh )
  53. {
  54. ERROR_IF_NOT_OWNS(tid);
  55. gh->recruitCreatures(tid,crid,amount);
  56. }
  57. void UpgradeCreature::applyGh( CGameHandler *gh )
  58. {
  59. ERROR_IF_NOT_OWNS(id);
  60. gh->upgradeCreature(id,pos,cid);
  61. }
  62. void GarrisonHeroSwap::applyGh( CGameHandler *gh )
  63. {
  64. ERROR_IF_NOT_OWNS(tid);
  65. gh->garrisonSwap(tid);
  66. }
  67. void ExchangeArtifacts::applyGh( CGameHandler *gh )
  68. {
  69. ERROR_IF_NOT_OWNS(hid1);
  70. ERROR_IF_NOT_OWNS(hid2);
  71. gh->swapArtifacts(hid1,hid2,slot1,slot2);
  72. }
  73. void BuyArtifact::applyGh( CGameHandler *gh )
  74. {
  75. ERROR_IF_NOT_OWNS(hid);
  76. gh->buyArtifact(hid,aid);
  77. }
  78. void TradeOnMarketplace::applyGh( CGameHandler *gh )
  79. {
  80. if(gh->getPlayerAt(c) != player) ERROR_AND_RETURN;
  81. gh->tradeResources(val,player,r1,r2);
  82. }
  83. void SetFormation::applyGh( CGameHandler *gh )
  84. {
  85. ERROR_IF_NOT_OWNS(hid);
  86. gh->setFormation(hid,formation);
  87. }
  88. void HireHero::applyGh( CGameHandler *gh )
  89. {
  90. ERROR_IF_NOT_OWNS(tid);
  91. gh->hireHero(tid,hid);
  92. }
  93. void QueryReply::applyGh( CGameHandler *gh )
  94. {
  95. gh->queryReply(qid,answer);
  96. }
  97. void MakeAction::applyGh( CGameHandler *gh )
  98. {
  99. if(gh->connections[GS(gh)->curB->getStack(GS(gh)->curB->activeStack)->owner] != c) ERROR_AND_RETURN;
  100. gh->makeBattleAction(ba);
  101. }
  102. void MakeCustomAction::applyGh( CGameHandler *gh )
  103. {
  104. if(gh->connections[GS(gh)->curB->getStack(GS(gh)->curB->activeStack)->owner] != c) ERROR_AND_RETURN;
  105. gh->makeCustomAction(ba);
  106. }
  107. void PlayerMessage::applyGh( CGameHandler *gh )
  108. {
  109. if(gh->getPlayerAt(c) != player) ERROR_AND_RETURN;
  110. gh->playerMessage(player,text);
  111. }
  112. void SetSelection::applyGh( CGameHandler *gh )
  113. {
  114. if(gh->getPlayerAt(c) != player) ERROR_AND_RETURN;
  115. gh->sendAndApply(this);
  116. }