summaryrefslogtreecommitdiff
path: root/indra/newview/llhomelocationresponder.cpp
blob: d0492bcdb438b0e190fcb982b07c9f9d7e1141ce (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
/** 
 * @file llhomelocationresponder.cpp
 * @author Meadhbh Hamrick
 * @brief Processes responses to the HomeLocation CapReq
 *
 * $LicenseInfo:firstyear=2008&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$
 */

/* File Inclusions */
#include "llviewerprecompiledheaders.h"

#include "llhomelocationresponder.h"
#include "llsdutil.h"
#include "llagent.h"
#include "llviewerregion.h"

void LLHomeLocationResponder::httpSuccess()
{
  const LLSD& content = getContent();
  LLVector3 agent_pos;
  bool      error = true;

  do {

    // was the call to /agent/<agent-id>/home-location successful?
    // If not, we keep error set to true
    if( ! content.has("success") )
    {
      break;
    }

    if( 0 != strncmp("true", content["success"].asString().c_str(), 4 ) )
    {
      break;
    }

    // did the simulator return a "justified" home location?
    // If no, we keep error set to true
    if( ! content.has( "HomeLocation" ) )
    {
      break;
    }

    if( ! content["HomeLocation"].has("LocationPos") )
    {
      break;
    }

    if( ! content["HomeLocation"]["LocationPos"].has("X") )
    {
      break;
    }

    agent_pos.mV[VX] = content["HomeLocation"]["LocationPos"]["X"].asInteger();

    if( ! content["HomeLocation"]["LocationPos"].has("Y") )
    {
      break;
    }

    agent_pos.mV[VY] = content["HomeLocation"]["LocationPos"]["Y"].asInteger();

    if( ! content["HomeLocation"]["LocationPos"].has("Z") )
    {
      break;
    }

    agent_pos.mV[VZ] = content["HomeLocation"]["LocationPos"]["Z"].asInteger();

    error = false;
  } while( 0 );

  if( error )
  {
    failureResult(HTTP_INTERNAL_ERROR, "Invalid server response content", content);
  }
  else
  {
    LL_INFOS() << "setting home position" << LL_ENDL;

    LLViewerRegion *viewer_region = gAgent.getRegion();
    gAgent.setHomePosRegion( viewer_region->getHandle(), agent_pos );
  }
}

void LLHomeLocationResponder::httpFailure()
{
  LL_WARNS() << dumpResponse() << LL_ENDL;
}