llworldmapmessage.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:9k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llworldmapmessage.cpp
  3.  * @brief Handling of the messages to the DB made by and for the world map.
  4.  *
  5.  * $LicenseInfo:firstyear=2003&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2003-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llworldmapmessage.h"
  34. #include "message.h"
  35. #include "llworldmap.h"
  36. #include "llagent.h"
  37. #include "llfloaterworldmap.h"
  38. const U32 LAYER_FLAG = 2;
  39. //---------------------------------------------------------------------------
  40. // World Map Message Handling
  41. //---------------------------------------------------------------------------
  42. LLWorldMapMessage::LLWorldMapMessage() :
  43. mSLURLRegionName(),
  44. mSLURLRegionHandle(0),
  45. mSLURL(),
  46. mSLURLCallback(0),
  47. mSLURLTeleport(false)
  48. {
  49. }
  50. LLWorldMapMessage::~LLWorldMapMessage()
  51. {
  52. }
  53. void LLWorldMapMessage::sendItemRequest(U32 type, U64 handle)
  54. {
  55. //LL_INFOS("World Map") << "Send item request : type = " << type << LL_ENDL;
  56. LLMessageSystem* msg = gMessageSystem;
  57. msg->newMessageFast(_PREHASH_MapItemRequest);
  58. msg->nextBlockFast(_PREHASH_AgentData);
  59. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  60. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  61. msg->addU32Fast(_PREHASH_Flags, LAYER_FLAG);
  62. msg->addU32Fast(_PREHASH_EstateID, 0); // Filled in on sim
  63. msg->addBOOLFast(_PREHASH_Godlike, FALSE); // Filled in on sim
  64. msg->nextBlockFast(_PREHASH_RequestData);
  65. msg->addU32Fast(_PREHASH_ItemType, type);
  66. msg->addU64Fast(_PREHASH_RegionHandle, handle); // If zero, filled in on sim
  67. gAgent.sendReliableMessage();
  68. }
  69. void LLWorldMapMessage::sendNamedRegionRequest(std::string region_name)
  70. {
  71. //LL_INFOS("World Map") << "LLWorldMap::sendNamedRegionRequest()" << LL_ENDL;
  72. LLMessageSystem* msg = gMessageSystem;
  73. // Request for region data
  74. msg->newMessageFast(_PREHASH_MapNameRequest);
  75. msg->nextBlockFast(_PREHASH_AgentData);
  76. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  77. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  78. msg->addU32Fast(_PREHASH_Flags, LAYER_FLAG);
  79. msg->addU32Fast(_PREHASH_EstateID, 0); // Filled in on sim
  80. msg->addBOOLFast(_PREHASH_Godlike, FALSE); // Filled in on sim
  81. msg->nextBlockFast(_PREHASH_NameData);
  82. msg->addStringFast(_PREHASH_Name, region_name);
  83. gAgent.sendReliableMessage();
  84. }
  85. void LLWorldMapMessage::sendNamedRegionRequest(std::string region_name, 
  86. url_callback_t callback,
  87. const std::string& callback_url,
  88. bool teleport) // immediately teleport when result returned
  89. {
  90. //LL_INFOS("World Map") << "LLWorldMap::sendNamedRegionRequest()" << LL_ENDL;
  91. mSLURLRegionName = region_name;
  92. mSLURLRegionHandle = 0;
  93. mSLURL = callback_url;
  94. mSLURLCallback = callback;
  95. mSLURLTeleport = teleport;
  96. sendNamedRegionRequest(region_name);
  97. }
  98. void LLWorldMapMessage::sendHandleRegionRequest(U64 region_handle, 
  99. url_callback_t callback,
  100. const std::string& callback_url,
  101. bool teleport) // immediately teleport when result returned
  102. {
  103. //LL_INFOS("World Map") << "LLWorldMap::sendHandleRegionRequest()" << LL_ENDL;
  104. mSLURLRegionName.clear();
  105. mSLURLRegionHandle = region_handle;
  106. mSLURL = callback_url;
  107. mSLURLCallback = callback;
  108. mSLURLTeleport = teleport;
  109. U32 global_x;
  110. U32 global_y;
  111. from_region_handle(region_handle, &global_x, &global_y);
  112. U16 grid_x = (U16)(global_x / REGION_WIDTH_UNITS);
  113. U16 grid_y = (U16)(global_y / REGION_WIDTH_UNITS);
  114. sendMapBlockRequest(grid_x, grid_y, grid_x, grid_y, true);
  115. }
  116. void LLWorldMapMessage::sendMapBlockRequest(U16 min_x, U16 min_y, U16 max_x, U16 max_y, bool return_nonexistent)
  117. {
  118. //LL_INFOS("World Map") << "LLWorldMap::sendMapBlockRequest()" << ", min = (" << min_x << ", " << min_y << "), max = (" << max_x << ", " << max_y << "), nonexistent = " << return_nonexistent << LL_ENDL;
  119. LLMessageSystem* msg = gMessageSystem;
  120. msg->newMessageFast(_PREHASH_MapBlockRequest);
  121. msg->nextBlockFast(_PREHASH_AgentData);
  122. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  123. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  124. U32 flags = LAYER_FLAG;
  125. flags |= (return_nonexistent ? 0x10000 : 0);
  126. msg->addU32Fast(_PREHASH_Flags, flags);
  127. msg->addU32Fast(_PREHASH_EstateID, 0); // Filled in on sim
  128. msg->addBOOLFast(_PREHASH_Godlike, FALSE); // Filled in on sim
  129. msg->nextBlockFast(_PREHASH_PositionData);
  130. msg->addU16Fast(_PREHASH_MinX, min_x);
  131. msg->addU16Fast(_PREHASH_MinY, min_y);
  132. msg->addU16Fast(_PREHASH_MaxX, max_x);
  133. msg->addU16Fast(_PREHASH_MaxY, max_y);
  134. gAgent.sendReliableMessage();
  135. }
  136. // public static
  137. void LLWorldMapMessage::processMapBlockReply(LLMessageSystem* msg, void**)
  138. {
  139. U32 agent_flags;
  140. msg->getU32Fast(_PREHASH_AgentData, _PREHASH_Flags, agent_flags);
  141. // There's only one flag that we ever use here
  142. if (agent_flags != LAYER_FLAG)
  143. {
  144. llwarns << "Invalid map image type returned! layer = " << agent_flags << llendl;
  145. return;
  146. }
  147. S32 num_blocks = msg->getNumberOfBlocksFast(_PREHASH_Data);
  148. //LL_INFOS("World Map") << "LLWorldMap::processMapBlockReply(), num_blocks = " << num_blocks << LL_ENDL;
  149. bool found_null_sim = false;
  150. for (S32 block=0; block<num_blocks; ++block)
  151. {
  152. U16 x_regions;
  153. U16 y_regions;
  154. std::string name;
  155. U8 accesscode;
  156. U32 region_flags;
  157. // U8 water_height;
  158. // U8 agents;
  159. LLUUID image_id;
  160. msg->getU16Fast(_PREHASH_Data, _PREHASH_X, x_regions, block);
  161. msg->getU16Fast(_PREHASH_Data, _PREHASH_Y, y_regions, block);
  162. msg->getStringFast(_PREHASH_Data, _PREHASH_Name, name, block);
  163. msg->getU8Fast(_PREHASH_Data, _PREHASH_Access, accesscode, block);
  164. msg->getU32Fast(_PREHASH_Data, _PREHASH_RegionFlags, region_flags, block);
  165. // msg->getU8Fast(_PREHASH_Data, _PREHASH_WaterHeight, water_height, block);
  166. // msg->getU8Fast(_PREHASH_Data, _PREHASH_Agents, agents, block);
  167. msg->getUUIDFast(_PREHASH_Data, _PREHASH_MapImageID, image_id, block);
  168. U32 x_world = (U32)(x_regions) * REGION_WIDTH_UNITS;
  169. U32 y_world = (U32)(y_regions) * REGION_WIDTH_UNITS;
  170. // Insert that region in the world map, if failure, flag it as a "null_sim"
  171. if (!(LLWorldMap::getInstance()->insertRegion(x_world, y_world, name, image_id, (U32)accesscode, region_flags)))
  172. {
  173. found_null_sim = true;
  174. }
  175. // If we hit a valid tracking location, do what needs to be done app level wise
  176. if (LLWorldMap::getInstance()->isTrackingValidLocation())
  177. {
  178. LLVector3d pos_global = LLWorldMap::getInstance()->getTrackedPositionGlobal();
  179. if (LLWorldMap::getInstance()->isTrackingDoubleClick())
  180. {
  181. // Teleport if the user double clicked
  182. gAgent.teleportViaLocation(pos_global);
  183. }
  184. // Update the "real" tracker information
  185. gFloaterWorldMap->trackLocation(pos_global);
  186. }
  187. // Handle the SLURL callback if any
  188. if(LLWorldMapMessage::getInstance()->mSLURLCallback != NULL)
  189. {
  190. U64 handle = to_region_handle(x_world, y_world);
  191. // Check if we reached the requested region
  192. if ((LLStringUtil::compareInsensitive(LLWorldMapMessage::getInstance()->mSLURLRegionName, name)==0)
  193. || (LLWorldMapMessage::getInstance()->mSLURLRegionHandle == handle))
  194. {
  195. url_callback_t callback = LLWorldMapMessage::getInstance()->mSLURLCallback;
  196. LLWorldMapMessage::getInstance()->mSLURLCallback = NULL;
  197. LLWorldMapMessage::getInstance()->mSLURLRegionName.clear();
  198. LLWorldMapMessage::getInstance()->mSLURLRegionHandle = 0;
  199. callback(handle, LLWorldMapMessage::getInstance()->mSLURL, image_id, LLWorldMapMessage::getInstance()->mSLURLTeleport);
  200. }
  201. }
  202. }
  203. // Tell the UI to update itself
  204. gFloaterWorldMap->updateSims(found_null_sim);
  205. }
  206. // public static
  207. void LLWorldMapMessage::processMapItemReply(LLMessageSystem* msg, void**)
  208. {
  209. //LL_INFOS("World Map") << "LLWorldMap::processMapItemReply()" << LL_ENDL;
  210. U32 type;
  211. msg->getU32Fast(_PREHASH_RequestData, _PREHASH_ItemType, type);
  212. S32 num_blocks = msg->getNumberOfBlocks("Data");
  213. for (S32 block=0; block<num_blocks; ++block)
  214. {
  215. U32 X, Y;
  216. std::string name;
  217. S32 extra, extra2;
  218. LLUUID uuid;
  219. msg->getU32Fast(_PREHASH_Data, _PREHASH_X, X, block);
  220. msg->getU32Fast(_PREHASH_Data, _PREHASH_Y, Y, block);
  221. msg->getStringFast(_PREHASH_Data, _PREHASH_Name, name, block);
  222. msg->getUUIDFast(_PREHASH_Data, _PREHASH_ID, uuid, block);
  223. msg->getS32Fast(_PREHASH_Data, _PREHASH_Extra, extra, block);
  224. msg->getS32Fast(_PREHASH_Data, _PREHASH_Extra2, extra2, block);
  225. LLWorldMap::getInstance()->insertItem(X, Y, name, uuid, type, extra, extra2);
  226. }
  227. }