1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
/**
* @file lllandmarkactions.cpp
* @brief LLLandmarkActions class implementation
*
* $LicenseInfo:firstyear=2001&license=viewergpl$
*
* Copyright (c) 2001-2009, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "lllandmarkactions.h"
#include "roles_constants.h"
#include "llinventory.h"
#include "lllandmark.h"
#include "llparcel.h"
#include "llnotifications.h"
#include "llagent.h"
#include "llinventorymodel.h"
#include "lllandmarklist.h"
#include "llslurl.h"
#include "llviewerinventory.h"
#include "llviewerparcelmgr.h"
#include "llworldmap.h"
#include "lllandmark.h"
#include "llinventorymodel.h"
#include "llagentui.h"
// Returns true if the given inventory item is a landmark pointing to the current parcel.
// Used to filter inventory items.
class LLIsAgentParcelLandmark : public LLInventoryCollectFunctor
{
public:
/*virtual*/ bool operator()(LLInventoryCategory* cat, LLInventoryItem* item)
{
if (!item || item->getType() != LLAssetType::AT_LANDMARK)
return false;
LLLandmark* landmark = gLandmarkList.getAsset(item->getAssetUUID());
if (!landmark) // the landmark not been loaded yet
return false;
LLVector3d landmark_global_pos;
if (!landmark->getGlobalPos(landmark_global_pos))
return false;
return LLViewerParcelMgr::getInstance()->inAgentParcel(landmark_global_pos);
}
};
class LLFetchLandmarksByName : public LLInventoryCollectFunctor
{
private:
std::string name;
BOOL use_substring;
//this member will be contain copy of founded items to keep the result unique
std::set<std::string> check_duplicate;
public:
LLFetchLandmarksByName(std::string &landmark_name, BOOL if_use_substring)
:name(landmark_name),
use_substring(if_use_substring)
{
LLStringUtil::toLower(name);
}
public:
/*virtual*/ bool operator()(LLInventoryCategory* cat, LLInventoryItem* item)
{
if (!item || item->getType() != LLAssetType::AT_LANDMARK)
return false;
LLLandmark* landmark = gLandmarkList.getAsset(item->getAssetUUID());
if (!landmark) // the landmark not been loaded yet
return false;
bool acceptable = false;
std::string landmark_name = item->getName();
LLStringUtil::toLower(landmark_name);
if(use_substring)
{
acceptable = landmark_name.find( name ) != std::string::npos;
}
else
{
acceptable = landmark_name == name;
}
if(acceptable){
if(check_duplicate.find(landmark_name) != check_duplicate.end()){
// we have duplicated items in landmarks
acceptable = false;
}else{
check_duplicate.insert(landmark_name);
}
}
return acceptable;
}
};
LLInventoryModel::item_array_t LLLandmarkActions::fetchLandmarksByName(std::string& name, BOOL use_substring)
{
LLInventoryModel::cat_array_t cats;
LLInventoryModel::item_array_t items;
LLFetchLandmarksByName fetchLandmarks(name, use_substring);
gInventory.collectDescendentsIf(gInventory.getRootFolderID(),
cats,
items,
LLInventoryModel::EXCLUDE_TRASH,
fetchLandmarks);
return items;
}
bool LLLandmarkActions::landmarkAlreadyExists()
{
// Determine whether there are landmarks pointing to the current parcel.
LLInventoryModel::item_array_t items;
collectParcelLandmark(items);
return !items.empty();
}
LLViewerInventoryItem* LLLandmarkActions::findLandmarkForAgentParcel()
{
// Determine whether there are landmarks pointing to the current parcel.
LLInventoryModel::cat_array_t cats;
LLInventoryModel::item_array_t items;
LLIsAgentParcelLandmark is_current_parcel_landmark;
gInventory.collectDescendentsIf(gInventory.getRootFolderID(),
cats,
items,
LLInventoryModel::EXCLUDE_TRASH,
is_current_parcel_landmark);
if(items.empty())
{
return NULL;
}
return items[0];
}
bool LLLandmarkActions::canCreateLandmarkHere()
{
LLParcel* agent_parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
if(!agent_parcel)
{
llwarns << "No agent region" << llendl;
return false;
}
if (agent_parcel->getAllowLandmark()
|| LLViewerParcelMgr::isParcelOwnedByAgent(agent_parcel, GP_LAND_ALLOW_LANDMARK))
{
return true;
}
return false;
}
void LLLandmarkActions::createLandmarkHere(
const std::string& name,
const std::string& desc,
const LLUUID& folder_id)
{
if(!gAgent.getRegion())
{
llwarns << "No agent region" << llendl;
return;
}
LLParcel* agent_parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
if (!agent_parcel)
{
llwarns << "No agent parcel" << llendl;
return;
}
if (!canCreateLandmarkHere())
{
LLNotifications::instance().add("CannotCreateLandmarkNotOwner");
return;
}
create_inventory_item(gAgent.getID(), gAgent.getSessionID(),
folder_id, LLTransactionID::tnull,
name, desc,
LLAssetType::AT_LANDMARK,
LLInventoryType::IT_LANDMARK,
NOT_WEARABLE, PERM_ALL,
NULL);
}
void LLLandmarkActions::createLandmarkHere()
{
std::string landmark_name, landmark_desc;
LLAgentUI::buildLocationString(landmark_name, LLAgentUI::LOCATION_FORMAT_LANDMARK);
LLAgentUI::buildLocationString(landmark_desc, LLAgentUI::LOCATION_FORMAT_FULL);
LLUUID folder_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_LANDMARK);
createLandmarkHere(landmark_name, landmark_desc, folder_id);
}
void LLLandmarkActions::getSLURLfromPosGlobal(const LLVector3d& global_pos, slurl_callback_t cb, bool escaped /* = true */)
{
std::string sim_name;
bool gotSimName = LLWorldMap::getInstance()->simNameFromPosGlobal(global_pos, sim_name);
if (gotSimName)
{
std::string slurl = LLSLURL::buildSLURLfromPosGlobal(sim_name, global_pos, escaped);
cb(slurl);
return;
}
else
{
U64 new_region_handle = to_region_handle(global_pos);
LLWorldMap::url_callback_t url_cb = boost::bind(&LLLandmarkActions::onRegionResponse,
cb,
global_pos,
escaped,
_1, _2, _3, _4);
LLWorldMap::getInstance()->sendHandleRegionRequest(new_region_handle, url_cb, std::string("unused"), false);
}
}
void LLLandmarkActions::onRegionResponse(slurl_callback_t cb,
const LLVector3d& global_pos,
bool escaped,
U64 region_handle,
const std::string& url,
const LLUUID& snapshot_id,
bool teleport)
{
std::string sim_name;
std::string slurl;
bool gotSimName = LLWorldMap::getInstance()->simNameFromPosGlobal(global_pos, sim_name);
if (gotSimName)
{
slurl = LLSLURL::buildSLURLfromPosGlobal(sim_name, global_pos, escaped);
}
else
{
slurl = "";
}
cb(slurl);
}
bool LLLandmarkActions::getLandmarkGlobalPos(const LLUUID& landmarkInventoryItemID, LLVector3d& posGlobal)
{
LLViewerInventoryItem* item = gInventory.getItem(landmarkInventoryItemID);
if (NULL == item)
return false;
const LLUUID& asset_id = item->getAssetUUID();
LLLandmark* landmark = gLandmarkList.getAsset(asset_id, NULL);
if (NULL == landmark)
return false;
return landmark->getGlobalPos(posGlobal);
}
void LLLandmarkActions::collectParcelLandmark(LLInventoryModel::item_array_t& items){
LLInventoryModel::cat_array_t cats;
LLIsAgentParcelLandmark is_current_parcel_landmark;
gInventory.collectDescendentsIf(gInventory.getRootFolderID(),
cats,
items,
LLInventoryModel::EXCLUDE_TRASH,
is_current_parcel_landmark);
}
|