summaryrefslogtreecommitdiff
path: root/indra/newview/llworldmapmessage.cpp
blob: c60d075e0c16847ad8423288a300c48ce93d3338 (plain)
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
/**
 * @file llworldmapmessage.cpp
 * @brief Handling of the messages to the DB made by and for the world map.
 *
 * $LicenseInfo:firstyear=2003&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "llviewerprecompiledheaders.h"

#include "llworldmapmessage.h"
#include "message.h"

#include "llworldmap.h"
#include "llagent.h"
#include "llfloaterworldmap.h"

const U32 LAYER_FLAG = 2;

//---------------------------------------------------------------------------
// World Map Message Handling
//---------------------------------------------------------------------------

LLWorldMapMessage::LLWorldMapMessage() :
    mSLURLRegionName(),
    mSLURLRegionHandle(0),
    mSLURL(),
    mSLURLCallback(0),
    mSLURLTeleport(false)
{
}

LLWorldMapMessage::~LLWorldMapMessage()
{
}

void LLWorldMapMessage::sendItemRequest(U32 type, U64 handle)
{
    //LL_INFOS("WorldMap") << "Send item request : type = " << type << LL_ENDL;
    LLMessageSystem* msg = gMessageSystem;

    msg->newMessageFast(_PREHASH_MapItemRequest);
    msg->nextBlockFast(_PREHASH_AgentData);
    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
    msg->addU32Fast(_PREHASH_Flags, LAYER_FLAG);
    msg->addU32Fast(_PREHASH_EstateID, 0); // Filled in on sim
    msg->addBOOLFast(_PREHASH_Godlike, false); // Filled in on sim

    msg->nextBlockFast(_PREHASH_RequestData);
    msg->addU32Fast(_PREHASH_ItemType, type);
    msg->addU64Fast(_PREHASH_RegionHandle, handle); // If zero, filled in on sim

    gAgent.sendReliableMessage();
}

void LLWorldMapMessage::sendNamedRegionRequest(std::string region_name)
{
    //LL_INFOS("WorldMap") << LL_ENDL;
    LLMessageSystem* msg = gMessageSystem;

    // Request for region data
    msg->newMessageFast(_PREHASH_MapNameRequest);
    msg->nextBlockFast(_PREHASH_AgentData);
    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
    msg->addU32Fast(_PREHASH_Flags, LAYER_FLAG);
    msg->addU32Fast(_PREHASH_EstateID, 0); // Filled in on sim
    msg->addBOOLFast(_PREHASH_Godlike, false); // Filled in on sim
    msg->nextBlockFast(_PREHASH_NameData);
    msg->addStringFast(_PREHASH_Name, region_name);
    gAgent.sendReliableMessage();
}

void LLWorldMapMessage::sendNamedRegionRequest(std::string region_name,
        url_callback_t callback,
        const std::string& callback_url,
        bool teleport)  // immediately teleport when result returned
{
    //LL_INFOS("WorldMap") << LL_ENDL;
    mSLURLRegionName = region_name;
    mSLURLRegionHandle = 0;
    mSLURL = callback_url;
    mSLURLCallback = callback;
    mSLURLTeleport = teleport;

    sendNamedRegionRequest(region_name);
}

void LLWorldMapMessage::sendHandleRegionRequest(U64 region_handle,
        url_callback_t callback,
        const std::string& callback_url,
        bool teleport)  // immediately teleport when result returned
{
    //LL_INFOS("WorldMap") << LL_ENDL;
    mSLURLRegionName.clear();
    mSLURLRegionHandle = region_handle;
    mSLURL = callback_url;
    mSLURLCallback = callback;
    mSLURLTeleport = teleport;

    U32 global_x;
    U32 global_y;
    from_region_handle(region_handle, &global_x, &global_y);
    U16 grid_x = (U16)(global_x / REGION_WIDTH_UNITS);
    U16 grid_y = (U16)(global_y / REGION_WIDTH_UNITS);

    sendMapBlockRequest(grid_x, grid_y, grid_x, grid_y, true);
}

void LLWorldMapMessage::sendMapBlockRequest(U16 min_x, U16 min_y, U16 max_x, U16 max_y, bool return_nonexistent)
{
    //LL_INFOS("WorldMap" << " min = (" << min_x << ", " << min_y << "), max = (" << max_x << ", " << max_y << ", nonexistent = " << return_nonexistent << LL_ENDL;
    LLMessageSystem* msg = gMessageSystem;
    msg->newMessageFast(_PREHASH_MapBlockRequest);
    msg->nextBlockFast(_PREHASH_AgentData);
    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
    U32 flags = LAYER_FLAG;
    flags |= (return_nonexistent ? 0x10000 : 0);
    msg->addU32Fast(_PREHASH_Flags, flags);
    msg->addU32Fast(_PREHASH_EstateID, 0); // Filled in on sim
    msg->addBOOLFast(_PREHASH_Godlike, false); // Filled in on sim
    msg->nextBlockFast(_PREHASH_PositionData);
    msg->addU16Fast(_PREHASH_MinX, min_x);
    msg->addU16Fast(_PREHASH_MinY, min_y);
    msg->addU16Fast(_PREHASH_MaxX, max_x);
    msg->addU16Fast(_PREHASH_MaxY, max_y);
    gAgent.sendReliableMessage();
}

// public static
void LLWorldMapMessage::processMapBlockReply(LLMessageSystem* msg, void**)
{
    if (gNonInteractive)
    {
        return;
    }
    U32 agent_flags;
    msg->getU32Fast(_PREHASH_AgentData, _PREHASH_Flags, agent_flags);

    // There's only one flag that we ever use here
    if (agent_flags != LAYER_FLAG)
    {
        LL_WARNS() << "Invalid map image type returned! layer = " << agent_flags << LL_ENDL;
        return;
    }

    S32 num_blocks = msg->getNumberOfBlocksFast(_PREHASH_Data);
    //LL_INFOS("WorldMap") << "num_blocks = " << num_blocks << LL_ENDL;

    bool found_null_sim = false;

    for (S32 block=0; block<num_blocks; ++block)
    {
        U16 x_regions;
        U16 y_regions;
        std::string name;
        U8 accesscode;
        U32 region_flags;
//      U8 water_height;
//      U8 agents;
        LLUUID image_id;
        msg->getU16Fast(_PREHASH_Data, _PREHASH_X, x_regions, block);
        msg->getU16Fast(_PREHASH_Data, _PREHASH_Y, y_regions, block);
        msg->getStringFast(_PREHASH_Data, _PREHASH_Name, name, block);
        msg->getU8Fast(_PREHASH_Data, _PREHASH_Access, accesscode, block);
        msg->getU32Fast(_PREHASH_Data, _PREHASH_RegionFlags, region_flags, block);
//      msg->getU8Fast(_PREHASH_Data, _PREHASH_WaterHeight, water_height, block);
//      msg->getU8Fast(_PREHASH_Data, _PREHASH_Agents, agents, block);
        msg->getUUIDFast(_PREHASH_Data, _PREHASH_MapImageID, image_id, block);

        U32 x_world = (U32)(x_regions) * REGION_WIDTH_UNITS;
        U32 y_world = (U32)(y_regions) * REGION_WIDTH_UNITS;

        // name shouldn't be empty, see EXT-4568
        llassert(!name.empty());

        // Insert that region in the world map, if failure, flag it as a "null_sim"
        if (!(LLWorldMap::getInstance()->insertRegion(x_world, y_world, name, image_id, (U32)accesscode, region_flags)))
        {
            found_null_sim = true;
        }

        // If we hit a valid tracking location, do what needs to be done app level wise
        if (LLWorldMap::getInstance()->isTrackingValidLocation())
        {
            LLVector3d pos_global = LLWorldMap::getInstance()->getTrackedPositionGlobal();
            if (LLWorldMap::getInstance()->isTrackingDoubleClick())
            {
                // Teleport if the user double clicked
                gAgent.teleportViaLocation(pos_global);
            }
            // Update the "real" tracker information
            gFloaterWorldMap->trackLocation(pos_global);
        }

        // Handle the SLURL callback if any
        url_callback_t callback = LLWorldMapMessage::getInstance()->mSLURLCallback;
        if(callback != NULL)
        {
            U64 handle = to_region_handle(x_world, y_world);
            // Check if we reached the requested region
            if ((LLStringUtil::compareInsensitive(LLWorldMapMessage::getInstance()->mSLURLRegionName, name)==0)
                || (LLWorldMapMessage::getInstance()->mSLURLRegionHandle == handle))
            {
                LLWorldMapMessage::getInstance()->mSLURLCallback = NULL;
                LLWorldMapMessage::getInstance()->mSLURLRegionName.clear();
                LLWorldMapMessage::getInstance()->mSLURLRegionHandle = 0;

                callback(handle, LLWorldMapMessage::getInstance()->mSLURL, image_id, LLWorldMapMessage::getInstance()->mSLURLTeleport);
            }
        }
    }
    // Tell the UI to update itself
    gFloaterWorldMap->updateSims(found_null_sim);
}

// public static
void LLWorldMapMessage::processMapItemReply(LLMessageSystem* msg, void**)
{
    //LL_INFOS("WorldMap") << LL_ENDL;
    U32 type;
    msg->getU32Fast(_PREHASH_RequestData, _PREHASH_ItemType, type);

    S32 num_blocks = msg->getNumberOfBlocks("Data");

    for (S32 block=0; block<num_blocks; ++block)
    {
        U32 X, Y;
        std::string name;
        S32 extra, extra2;
        LLUUID uuid;
        msg->getU32Fast(_PREHASH_Data, _PREHASH_X, X, block);
        msg->getU32Fast(_PREHASH_Data, _PREHASH_Y, Y, block);
        msg->getStringFast(_PREHASH_Data, _PREHASH_Name, name, block);
        msg->getUUIDFast(_PREHASH_Data, _PREHASH_ID, uuid, block);
        msg->getS32Fast(_PREHASH_Data, _PREHASH_Extra, extra, block);
        msg->getS32Fast(_PREHASH_Data, _PREHASH_Extra2, extra2, block);

        LLWorldMap::getInstance()->insertItem(X, Y, name, uuid, type, extra, extra2);
    }
}