Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

BlobHandler.cpp 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include "net/BlobHandler.h"
  19. #include "net/BlobWriter.h"
  20. #include "BinReader.h"
  21. #include "Core.h"
  22. #include "Log.h"
  23. #include "ObjectManager.h"
  24. #include "Property.h"
  25. #include "util.h"
  26. BlobHandler::BlobHandler() : sequence_(1)
  27. {}
  28. void BlobHandler::handle(BlobPtr blob)
  29. {
  30. BinReader reader(blob.get() + 1, blob->size);
  31. MessageType messageType = static_cast<MessageType>(reader.readInt());
  32. if(messageType == MessageType::kWeenie_Ordered)
  33. {
  34. /*objectId*/ reader.readInt();
  35. uint32_t messageSequence = reader.readInt();
  36. orderedBlobs_[messageSequence] = move(blob);
  37. pumpOrderedBlobs();
  38. }
  39. else
  40. {
  41. handle(messageType, reader);
  42. }
  43. }
  44. void BlobHandler::pumpOrderedBlobs()
  45. {
  46. for(auto it = orderedBlobs_.begin(); it != orderedBlobs_.end(); it = orderedBlobs_.erase(it))
  47. {
  48. if(it->first > sequence_)
  49. {
  50. break;
  51. }
  52. BinReader reader(it->second.get() + 1, it->second->size);
  53. /*messageType*/ reader.readInt();
  54. /*objectId*/ reader.readInt();
  55. /*messageSequence*/ reader.readInt();
  56. MessageType actualMessageType = static_cast<MessageType>(reader.readInt());
  57. handle(actualMessageType, reader);
  58. sequence_++;
  59. }
  60. }
  61. // PlayerDescription.cpp
  62. void handlePlayerDescription(BinReader& reader);
  63. // CreateObject.cpp
  64. void handleCreateObject(BinReader& reader);
  65. void BlobHandler::handle(MessageType messageType, BinReader& reader)
  66. {
  67. if(messageType == MessageType::kLogin_CharacterSet)
  68. {
  69. /*unknown1*/ reader.readInt();
  70. uint32_t characterCount = reader.readInt();
  71. for(uint32_t i = 0; i < characterCount; i++)
  72. {
  73. uint32_t objectId = reader.readInt();
  74. string name = reader.readString();
  75. uint32_t deleteTimeout = reader.readInt();
  76. LOG(Net, Debug) << " objectId=" << hexn(objectId) << " name=" << name << " deleteTimeout=" << deleteTimeout << "\n";
  77. }
  78. }
  79. else if(messageType == MessageType::kLogin_WorldInfo)
  80. {
  81. uint32_t playerCount = reader.readInt();
  82. uint32_t unknown = reader.readInt();
  83. string server = reader.readString();
  84. LOG(Net, Debug) << " playerCount=" << playerCount << " unknown=" << hexn(unknown) << " server=" << server << "\n";
  85. }
  86. else if(messageType == MessageType::kDDD_Interrogation)
  87. {
  88. uint32_t serversRegion = reader.readInt();
  89. assert(serversRegion == 1);
  90. UNUSED(serversRegion);
  91. uint32_t nameRuleLanguage = reader.readInt();
  92. assert(nameRuleLanguage == 1);
  93. UNUSED(nameRuleLanguage);
  94. uint32_t productId = reader.readInt();
  95. assert(productId == 1);
  96. UNUSED(productId);
  97. uint32_t numSupportedLanguages = reader.readInt();
  98. assert(numSupportedLanguages == 2);
  99. for(uint32_t i = 0; i < numSupportedLanguages; i++)
  100. {
  101. /*supportedLanguage*/ reader.readInt();
  102. }
  103. assert(reader.remaining() == 0);
  104. BlobWriter writer(MessageType::kDDD_InterrogationResponse, NetQueueId::kDatabase);
  105. /*clientLanguage*/ writer.writeInt(1);
  106. /*numItersWithKeys*/ writer.writeInt(0);
  107. /*numItersWithoutKeys*/ writer.writeInt(0);
  108. /*flags*/ writer.writeInt(0);
  109. }
  110. else if(messageType == MessageType::kDDD_EndDDD)
  111. {
  112. BlobWriter writer(MessageType::kDDD_EndDDD, NetQueueId::kDatabase);
  113. // empty body
  114. BlobWriter writer2(MessageType::kClient_Request_Enter_Game, NetQueueId::kLogon);
  115. // empty body
  116. }
  117. else if(messageType == MessageType::kCharacter_EnterGame_ServerReady)
  118. {
  119. //NET DEBUG objectId=500F4D79h name=Aeriin deleteTimeout=0
  120. //NET DEBUG objectId=500F4CFBh name=Madlyn deleteTimeout=0
  121. //NET DEBUG objectId=500F4D7Ah name=Madds deleteTimeout=0
  122. BlobWriter writer(MessageType::kCharacter_Enter_Game, NetQueueId::kLogon);
  123. writer.writeInt(0x500F4CFB);
  124. writer.writeString("md9nq9m3njxjlpdcwy4anqdnq");
  125. Core::get().objectManager().setPlayerId(ObjectId{0x500F4CFB});
  126. }
  127. else if(messageType == MessageType::kPhysics_CreatePlayer)
  128. {
  129. ObjectId playerId = ObjectId{reader.readInt()};
  130. Core::get().objectManager().setPlayerId(playerId);
  131. }
  132. else if(messageType == MessageType::kPlayer_Description)
  133. {
  134. handlePlayerDescription(reader);
  135. }
  136. else if(messageType == MessageType::kPhysics_CreateObject)
  137. {
  138. handleCreateObject(reader);
  139. }
  140. else if(messageType == MessageType::kQualities_PrivateUpdateBool)
  141. {
  142. /*sequence*/ reader.readByte();
  143. BoolProperty property = BoolProperty(reader.readInt());
  144. uint32_t value = reader.readInt();
  145. Core::get().objectManager().player().setProperty(property, value != 0);
  146. }
  147. else if(messageType == MessageType::kQualities_PrivateUpdateInt)
  148. {
  149. /*sequence*/ reader.readByte();
  150. IntProperty property = IntProperty(reader.readInt());
  151. uint32_t value = reader.readInt();
  152. Core::get().objectManager().player().setProperty(property, value);
  153. }
  154. else if(messageType == MessageType::kQualities_PrivateUpdateFloat)
  155. {
  156. /*sequence*/ reader.readByte();
  157. FloatProperty property = FloatProperty(reader.readInt());
  158. double value = reader.readDouble();
  159. Core::get().objectManager().player().setProperty(property, value);
  160. }
  161. else if(messageType == MessageType::kQualities_UpdateDataID)
  162. {
  163. /*sequence*/ reader.readByte();
  164. ObjectId objectId = ObjectId{reader.readInt()};
  165. DIDProperty property = DIDProperty(reader.readInt());
  166. uint32_t value = reader.readInt();
  167. Core::get().objectManager()[objectId].setProperty(property, value);
  168. }
  169. else if(messageType == MessageType::kPhysics_ObjDescEvent)
  170. {
  171. // ignore for now
  172. }
  173. else if(messageType == MessageType::kMovement_UpdatePosition)
  174. {
  175. enum PositionFlags
  176. {
  177. kVelocity = 0x1,
  178. kPlacementId = 0x2,
  179. kContact = 0x4,
  180. kZeroQW = 0x8,
  181. kZeroQX = 0x10,
  182. kZeroQY = 0x20,
  183. kZeroQZ = 0x40
  184. };
  185. ObjectId objectId = ObjectId{reader.readInt()};
  186. Object& object = Core::get().objectManager()[objectId];
  187. uint32_t flags = reader.readInt();
  188. object.setLandcellId(LandcellId{reader.readInt()});
  189. Location location;
  190. read(reader, location.position);
  191. if(!(flags & kZeroQW))
  192. {
  193. location.rotation.w = reader.readFloat();
  194. }
  195. if(!(flags & kZeroQX))
  196. {
  197. location.rotation.x = reader.readFloat();
  198. }
  199. if(!(flags & kZeroQY))
  200. {
  201. location.rotation.y = reader.readFloat();
  202. }
  203. if(!(flags & kZeroQZ))
  204. {
  205. location.rotation.z = reader.readFloat();
  206. }
  207. object.setLocation(location);
  208. }
  209. else if(messageType == MessageType::kMovement_MovementEvent)
  210. {
  211. // ignore for now
  212. }
  213. else if(messageType == MessageType::kPhysics_PlayScriptType)
  214. {
  215. // ignore for now
  216. }
  217. else
  218. {
  219. LOG(Net, Info) << "received blob " << hexn(static_cast<uint32_t>(messageType)) << " " << getMessageName(messageType) << "\n";
  220. }
  221. }