Guest User

Untitled

a guest
Nov 19th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. //After
  2.  
  3. Player::Player(ProtocolGame* p) :
  4. Creature()
  5. {
  6.  
  7. //Add this
  8.  
  9. nextSpectator = 0;
  10. cast.isCasting = false;
  11.  
  12. //After
  13.  
  14. Player::~Player()
  15. {
  16.  
  17. //Add this
  18.  
  19. kickCastViewers();
  20.  
  21. //After
  22.  
  23. setWriteItem(nullptr);
  24. setEditHouse(nullptr);
  25. }
  26.  
  27. //Add this
  28.  
  29. bool Player::getCastingState() const {
  30. return cast.isCasting;
  31. }
  32.  
  33. void Player::setCasting(bool castStatus) {
  34. cast.isCasting = castStatus;
  35. }
  36.  
  37. PlayerCast Player::getCast() {
  38. return cast;
  39. }
  40.  
  41. void Player::setCastPassword(std::string password_) {
  42. cast.password = password_;
  43. }
  44.  
  45. void Player::addCastViewer(ProtocolGame* pg) {
  46. cSpectators[nextSpectator] = pg;
  47. nextSpectator++;
  48.  
  49. std::stringstream ss;
  50. ss << "Spectator " << cast.curId;
  51. pg->viewerName = ss.str().c_str();
  52. cast.curId++;
  53. this->sendChannelEvent(this->cast.mCastChannelId, pg->viewerName, CHANNELEVENT_JOIN);
  54. }
  55.  
  56. void Player::removeCastViewer(uint32_t id) {
  57. cSpectators.erase(id);
  58. }
  59.  
  60. uint32_t Player::getCastIpByName(std::string n) {
  61. for (AutoList<ProtocolGame>::iterator it = cSpectators.begin(); it != cSpectators.end(); ++it)
  62. if (it->second->getViewerName() == n && it->second->getPlayer() == this)
  63. return it->second->getIP();
  64.  
  65. return 0;
  66. }
  67.  
  68. uint32_t Player::getCastViewerCount() const {
  69. uint32_t count = 0;
  70. for(AutoList<ProtocolGame>::const_iterator it = cSpectators.begin(); it != cSpectators.end(); ++it) {
  71. Connection_ptr tmpcon = it->second->getConnection();
  72. if(tmpcon) {
  73. //if (tmpcon->haveConnection())
  74. count++;
  75. }
  76. }
  77. return count;
  78. }
  79.  
  80. void Player::kickCastViewers() {
  81.  
  82. for (auto it : cSpectators) {
  83.  
  84. it.second->disconnect();
  85. it.second->unRef();
  86. it.second->player = 0;
  87. //removeCastViewer(it.first);
  88. }
  89. cast = PlayerCast();
  90.  
  91. cSpectators.clear();
  92. }
  93.  
  94. bool Player::kickCastViewerByName(std::string n) {
  95. for (auto it = cSpectators.begin(); it != cSpectators.end(); it++)
  96. {
  97. if (it->second->viewerName == n)
  98. {
  99. if (it->second->player)
  100. {
  101. it->second->disconnect();
  102. it->second->unRef();
  103. it->second->player = 0;
  104. cSpectators.erase(it);
  105. return true;
  106. }
  107. }
  108. }
  109. return false;
  110. };
  111.  
  112. //After
  113.  
  114. switch (playerinfo) {
  115.  
  116. //Add this
  117.  
  118. case PLAYERINFO_LEVEL: return level;
  119.  
  120. //After
  121.  
  122. void Player::sendStats()
  123. {
  124.  
  125. //Add this
  126.  
  127. for (auto it : cSpectators)
  128. it.second->sendStats();
  129.  
  130. //After
  131.  
  132. lastPing = timeNow;
  133.  
  134. //Add this
  135.  
  136. for (auto it : cSpectators)
  137. it.second->sendPing();
  138.  
  139. //After
  140.  
  141. } else if (openContainer.index >= container->capacity()) {
  142. item = container->getItemByIndex(openContainer.index - 1);
  143. }
  144.  
  145. //Add this
  146.  
  147. for (auto spec : cSpectators)
  148. spec.second->sendAddContainerItem(it.first, slot, item);
  149.  
  150. //After
  151.  
  152. if (slot >= pageEnd) {
  153. continue;
  154. }
  155.  
  156. //Add this
  157.  
  158. for (auto spec : cSpectators)
  159. spec.second->sendUpdateContainerItem(it.first, slot, newItem);
  160.  
  161. //After
  162.  
  163. if (firstIndex > 0 && firstIndex >= container->size() - 1) {
  164. firstIndex -= container->capacity();
  165. sendContainer(it.first, container, false, firstIndex);
  166. }
  167.  
  168. //Add this
  169.  
  170. for (auto spec : cSpectators)
  171. spec.second->sendRemoveContainerItem(it.first, std::max<uint16_t>(slot, firstIndex), container->getItemByIndex(container->capacity() + firstIndex));
  172.  
  173. //Replace
  174.  
  175. client->sendCloseContainer(it.first);
  176.  
  177. //With
  178.  
  179. sendCloseContainer(it.first);
  180.  
  181. //Replace
  182.  
  183. client->sendContainer(it.first, container, hasParent, openContainer.index);
  184.  
  185. //With
  186.  
  187. sendContainer(it.first, container, hasParent, openContainer.index);
  188.  
  189. //After
  190.  
  191. for (uint32_t containerId : closeList) {
  192. closeContainer(containerId);
  193.  
  194. //Add this
  195.  
  196. for (auto it : cSpectators) //Cast System Felipe Monteiro
  197. it.second->sendCloseContainer(containerId);
Advertisement
Add Comment
Please, Sign In to add comment