PageRenderTime 321ms CodeModel.GetById 135ms app.highlight 70ms RepoModel.GetById 111ms app.codeStats 0ms

/indra/newview/llworldmapmessage.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 258 lines | 172 code | 35 blank | 51 comment | 12 complexity | e4c33778bffc46f0794032ef151188aa MD5 | raw file
  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=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llworldmapmessage.h"
 30#include "message.h"
 31
 32#include "llworldmap.h"
 33#include "llagent.h"
 34#include "llfloaterworldmap.h"
 35
 36const U32 LAYER_FLAG = 2;
 37
 38//---------------------------------------------------------------------------
 39// World Map Message Handling
 40//---------------------------------------------------------------------------
 41
 42LLWorldMapMessage::LLWorldMapMessage() :
 43	mSLURLRegionName(),
 44	mSLURLRegionHandle(0),
 45	mSLURL(),
 46	mSLURLCallback(0),
 47	mSLURLTeleport(false)
 48{
 49}
 50
 51LLWorldMapMessage::~LLWorldMapMessage()
 52{
 53}
 54
 55void LLWorldMapMessage::sendItemRequest(U32 type, U64 handle)
 56{
 57	//LL_INFOS("World Map") << "Send item request : type = " << type << LL_ENDL;
 58	LLMessageSystem* msg = gMessageSystem;
 59
 60	msg->newMessageFast(_PREHASH_MapItemRequest);
 61	msg->nextBlockFast(_PREHASH_AgentData);
 62	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
 63	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
 64	msg->addU32Fast(_PREHASH_Flags, LAYER_FLAG);
 65	msg->addU32Fast(_PREHASH_EstateID, 0); // Filled in on sim
 66	msg->addBOOLFast(_PREHASH_Godlike, FALSE); // Filled in on sim
 67
 68	msg->nextBlockFast(_PREHASH_RequestData);
 69	msg->addU32Fast(_PREHASH_ItemType, type);
 70	msg->addU64Fast(_PREHASH_RegionHandle, handle); // If zero, filled in on sim
 71
 72	gAgent.sendReliableMessage();
 73}
 74
 75void LLWorldMapMessage::sendNamedRegionRequest(std::string region_name)
 76{
 77	//LL_INFOS("World Map") << "LLWorldMap::sendNamedRegionRequest()" << LL_ENDL;
 78	LLMessageSystem* msg = gMessageSystem;
 79
 80	// Request for region data
 81	msg->newMessageFast(_PREHASH_MapNameRequest);
 82	msg->nextBlockFast(_PREHASH_AgentData);
 83	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
 84	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
 85	msg->addU32Fast(_PREHASH_Flags, LAYER_FLAG);
 86	msg->addU32Fast(_PREHASH_EstateID, 0); // Filled in on sim
 87	msg->addBOOLFast(_PREHASH_Godlike, FALSE); // Filled in on sim
 88	msg->nextBlockFast(_PREHASH_NameData);
 89	msg->addStringFast(_PREHASH_Name, region_name);
 90	gAgent.sendReliableMessage();
 91}
 92
 93void LLWorldMapMessage::sendNamedRegionRequest(std::string region_name, 
 94		url_callback_t callback,
 95		const std::string& callback_url,
 96		bool teleport)	// immediately teleport when result returned
 97{
 98	//LL_INFOS("World Map") << "LLWorldMap::sendNamedRegionRequest()" << LL_ENDL;
 99	mSLURLRegionName = region_name;
100	mSLURLRegionHandle = 0;
101	mSLURL = callback_url;
102	mSLURLCallback = callback;
103	mSLURLTeleport = teleport;
104
105	sendNamedRegionRequest(region_name);
106}
107
108void LLWorldMapMessage::sendHandleRegionRequest(U64 region_handle, 
109		url_callback_t callback,
110		const std::string& callback_url,
111		bool teleport)	// immediately teleport when result returned
112{
113	//LL_INFOS("World Map") << "LLWorldMap::sendHandleRegionRequest()" << LL_ENDL;
114	mSLURLRegionName.clear();
115	mSLURLRegionHandle = region_handle;
116	mSLURL = callback_url;
117	mSLURLCallback = callback;
118	mSLURLTeleport = teleport;
119
120	U32 global_x;
121	U32 global_y;
122	from_region_handle(region_handle, &global_x, &global_y);
123	U16 grid_x = (U16)(global_x / REGION_WIDTH_UNITS);
124	U16 grid_y = (U16)(global_y / REGION_WIDTH_UNITS);
125	
126	sendMapBlockRequest(grid_x, grid_y, grid_x, grid_y, true);
127}
128
129void LLWorldMapMessage::sendMapBlockRequest(U16 min_x, U16 min_y, U16 max_x, U16 max_y, bool return_nonexistent)
130{
131	//LL_INFOS("World Map") << "LLWorldMap::sendMapBlockRequest()" << ", min = (" << min_x << ", " << min_y << "), max = (" << max_x << ", " << max_y << "), nonexistent = " << return_nonexistent << LL_ENDL;
132	LLMessageSystem* msg = gMessageSystem;
133	msg->newMessageFast(_PREHASH_MapBlockRequest);
134	msg->nextBlockFast(_PREHASH_AgentData);
135	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
136	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
137	U32 flags = LAYER_FLAG;
138	flags |= (return_nonexistent ? 0x10000 : 0);
139	msg->addU32Fast(_PREHASH_Flags, flags);
140	msg->addU32Fast(_PREHASH_EstateID, 0); // Filled in on sim
141	msg->addBOOLFast(_PREHASH_Godlike, FALSE); // Filled in on sim
142	msg->nextBlockFast(_PREHASH_PositionData);
143	msg->addU16Fast(_PREHASH_MinX, min_x);
144	msg->addU16Fast(_PREHASH_MinY, min_y);
145	msg->addU16Fast(_PREHASH_MaxX, max_x);
146	msg->addU16Fast(_PREHASH_MaxY, max_y);
147	gAgent.sendReliableMessage();
148}
149
150// public static
151void LLWorldMapMessage::processMapBlockReply(LLMessageSystem* msg, void**)
152{
153	U32 agent_flags;
154	msg->getU32Fast(_PREHASH_AgentData, _PREHASH_Flags, agent_flags);
155
156	// There's only one flag that we ever use here
157	if (agent_flags != LAYER_FLAG)
158	{
159		llwarns << "Invalid map image type returned! layer = " << agent_flags << llendl;
160		return;
161	}
162
163	S32 num_blocks = msg->getNumberOfBlocksFast(_PREHASH_Data);
164	//LL_INFOS("World Map") << "LLWorldMap::processMapBlockReply(), num_blocks = " << num_blocks << LL_ENDL;
165
166	bool found_null_sim = false;
167
168	for (S32 block=0; block<num_blocks; ++block)
169	{
170		U16 x_regions;
171		U16 y_regions;
172		std::string name;
173		U8 accesscode;
174		U32 region_flags;
175//		U8 water_height;
176//		U8 agents;
177		LLUUID image_id;
178		msg->getU16Fast(_PREHASH_Data, _PREHASH_X, x_regions, block);
179		msg->getU16Fast(_PREHASH_Data, _PREHASH_Y, y_regions, block);
180		msg->getStringFast(_PREHASH_Data, _PREHASH_Name, name, block);
181		msg->getU8Fast(_PREHASH_Data, _PREHASH_Access, accesscode, block);
182		msg->getU32Fast(_PREHASH_Data, _PREHASH_RegionFlags, region_flags, block);
183//		msg->getU8Fast(_PREHASH_Data, _PREHASH_WaterHeight, water_height, block);
184//		msg->getU8Fast(_PREHASH_Data, _PREHASH_Agents, agents, block);
185		msg->getUUIDFast(_PREHASH_Data, _PREHASH_MapImageID, image_id, block);
186
187		U32 x_world = (U32)(x_regions) * REGION_WIDTH_UNITS;
188		U32 y_world = (U32)(y_regions) * REGION_WIDTH_UNITS;
189
190		// name shouldn't be empty, see EXT-4568
191		llassert(!name.empty());
192
193		// Insert that region in the world map, if failure, flag it as a "null_sim"
194		if (!(LLWorldMap::getInstance()->insertRegion(x_world, y_world, name, image_id, (U32)accesscode, region_flags)))
195		{
196			found_null_sim = true;
197		}
198
199		// If we hit a valid tracking location, do what needs to be done app level wise
200		if (LLWorldMap::getInstance()->isTrackingValidLocation())
201		{
202			LLVector3d pos_global = LLWorldMap::getInstance()->getTrackedPositionGlobal();
203			if (LLWorldMap::getInstance()->isTrackingDoubleClick())
204			{
205				// Teleport if the user double clicked
206				gAgent.teleportViaLocation(pos_global);
207			}
208			// Update the "real" tracker information
209			gFloaterWorldMap->trackLocation(pos_global);
210		}
211
212		// Handle the SLURL callback if any
213		url_callback_t callback = LLWorldMapMessage::getInstance()->mSLURLCallback;
214		if(callback != NULL)
215		{
216			U64 handle = to_region_handle(x_world, y_world);
217			// Check if we reached the requested region
218			if ((LLStringUtil::compareInsensitive(LLWorldMapMessage::getInstance()->mSLURLRegionName, name)==0)
219				|| (LLWorldMapMessage::getInstance()->mSLURLRegionHandle == handle))
220			{
221				LLWorldMapMessage::getInstance()->mSLURLCallback = NULL;
222				LLWorldMapMessage::getInstance()->mSLURLRegionName.clear();
223				LLWorldMapMessage::getInstance()->mSLURLRegionHandle = 0;
224
225				callback(handle, LLWorldMapMessage::getInstance()->mSLURL, image_id, LLWorldMapMessage::getInstance()->mSLURLTeleport);
226			}
227		}
228	}
229	// Tell the UI to update itself
230	gFloaterWorldMap->updateSims(found_null_sim);
231}
232
233// public static
234void LLWorldMapMessage::processMapItemReply(LLMessageSystem* msg, void**)
235{
236	//LL_INFOS("World Map") << "LLWorldMap::processMapItemReply()" << LL_ENDL;
237	U32 type;
238	msg->getU32Fast(_PREHASH_RequestData, _PREHASH_ItemType, type);
239
240	S32 num_blocks = msg->getNumberOfBlocks("Data");
241
242	for (S32 block=0; block<num_blocks; ++block)
243	{
244		U32 X, Y;
245		std::string name;
246		S32 extra, extra2;
247		LLUUID uuid;
248		msg->getU32Fast(_PREHASH_Data, _PREHASH_X, X, block);
249		msg->getU32Fast(_PREHASH_Data, _PREHASH_Y, Y, block);
250		msg->getStringFast(_PREHASH_Data, _PREHASH_Name, name, block);
251		msg->getUUIDFast(_PREHASH_Data, _PREHASH_ID, uuid, block);
252		msg->getS32Fast(_PREHASH_Data, _PREHASH_Extra, extra, block);
253		msg->getS32Fast(_PREHASH_Data, _PREHASH_Extra2, extra2, block);
254
255		LLWorldMap::getInstance()->insertItem(X, Y, name, uuid, type, extra, extra2);
256	}
257}
258