aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs
diff options
context:
space:
mode:
authorDiva Canto2010-01-31 11:10:57 -0800
committerDiva Canto2010-01-31 11:10:57 -0800
commit40d8e91008b7d76ce6b9398484c591eb51c85bdb (patch)
tree7851807bee519bcae508f77e11107c7ed1e99ae9 /OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs
parentAdded missing file. (diff)
downloadopensim-SC_OLD-40d8e91008b7d76ce6b9398484c591eb51c85bdb.zip
opensim-SC_OLD-40d8e91008b7d76ce6b9398484c591eb51c85bdb.tar.gz
opensim-SC_OLD-40d8e91008b7d76ce6b9398484c591eb51c85bdb.tar.bz2
opensim-SC_OLD-40d8e91008b7d76ce6b9398484c591eb51c85bdb.tar.xz
* Added a few files that were missing in the repo.
* New HGInventoryService which allows restricted access to inventory while outside
Diffstat (limited to 'OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs')
-rw-r--r--OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs181
1 files changed, 181 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs
new file mode 100644
index 0000000..17d7850
--- /dev/null
+++ b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs
@@ -0,0 +1,181 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.IO;
31using System.Reflection;
32using System.Net;
33using System.Text;
34
35using OpenSim.Server.Base;
36using OpenSim.Server.Handlers.Base;
37using OpenSim.Services.Interfaces;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using OpenSim.Framework;
40using OpenSim.Framework.Servers.HttpServer;
41using OpenSim.Server.Handlers.Simulation;
42using Utils = OpenSim.Server.Handlers.Simulation.Utils;
43
44using OpenMetaverse;
45using OpenMetaverse.StructuredData;
46using Nini.Config;
47using log4net;
48
49
50namespace OpenSim.Server.Handlers.Hypergrid
51{
52 public class HomeAgentHandler
53 {
54 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55 private IUserAgentService m_UserAgentService;
56
57 public HomeAgentHandler(IUserAgentService userAgentService)
58 {
59 m_UserAgentService = userAgentService;
60 }
61
62 public Hashtable Handler(Hashtable request)
63 {
64 m_log.Debug("[CONNECTION DEBUGGING]: HomeAgentHandler Called");
65
66 m_log.Debug("---------------------------");
67 m_log.Debug(" >> uri=" + request["uri"]);
68 m_log.Debug(" >> content-type=" + request["content-type"]);
69 m_log.Debug(" >> http-method=" + request["http-method"]);
70 m_log.Debug("---------------------------\n");
71
72 Hashtable responsedata = new Hashtable();
73 responsedata["content_type"] = "text/html";
74 responsedata["keepalive"] = false;
75
76
77 UUID agentID;
78 UUID regionID;
79 string action;
80 if (!Utils.GetParams((string)request["uri"], out agentID, out regionID, out action))
81 {
82 m_log.InfoFormat("[HOME AGENT HANDLER]: Invalid parameters for agent message {0}", request["uri"]);
83 responsedata["int_response_code"] = 404;
84 responsedata["str_response_string"] = "false";
85
86 return responsedata;
87 }
88
89 // Next, let's parse the verb
90 string method = (string)request["http-method"];
91 if (method.Equals("POST"))
92 {
93 DoAgentPost(request, responsedata, agentID);
94 return responsedata;
95 }
96 else
97 {
98 m_log.InfoFormat("[HOME AGENT HANDLER]: method {0} not supported in agent message", method);
99 responsedata["int_response_code"] = HttpStatusCode.MethodNotAllowed;
100 responsedata["str_response_string"] = "Method not allowed";
101
102 return responsedata;
103 }
104
105 }
106
107 protected void DoAgentPost(Hashtable request, Hashtable responsedata, UUID id)
108 {
109 OSDMap args = Utils.GetOSDMap((string)request["body"]);
110 if (args == null)
111 {
112 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
113 responsedata["str_response_string"] = "Bad request";
114 return;
115 }
116
117 // retrieve the input arguments
118 int x = 0, y = 0;
119 UUID uuid = UUID.Zero;
120 string regionname = string.Empty;
121 string gatekeeper_host = string.Empty;
122 int gatekeeper_port = 0;
123
124 if (args.ContainsKey("gatekeeper_host") && args["gatekeeper_host"] != null)
125 gatekeeper_host = args["gatekeeper_host"].AsString();
126 if (args.ContainsKey("gatekeeper_port") && args["gatekeeper_port"] != null)
127 Int32.TryParse(args["gatekeeper_port"].AsString(), out gatekeeper_port);
128
129 GridRegion gatekeeper = new GridRegion();
130 gatekeeper.ExternalHostName = gatekeeper_host;
131 gatekeeper.HttpPort = (uint)gatekeeper_port;
132 gatekeeper.InternalEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
133
134 if (args.ContainsKey("destination_x") && args["destination_x"] != null)
135 Int32.TryParse(args["destination_x"].AsString(), out x);
136 else
137 m_log.WarnFormat(" -- request didn't have destination_x");
138 if (args.ContainsKey("destination_y") && args["destination_y"] != null)
139 Int32.TryParse(args["destination_y"].AsString(), out y);
140 else
141 m_log.WarnFormat(" -- request didn't have destination_y");
142 if (args.ContainsKey("destination_uuid") && args["destination_uuid"] != null)
143 UUID.TryParse(args["destination_uuid"].AsString(), out uuid);
144 if (args.ContainsKey("destination_name") && args["destination_name"] != null)
145 regionname = args["destination_name"].ToString();
146
147 GridRegion destination = new GridRegion();
148 destination.RegionID = uuid;
149 destination.RegionLocX = x;
150 destination.RegionLocY = y;
151 destination.RegionName = regionname;
152
153 AgentCircuitData aCircuit = new AgentCircuitData();
154 try
155 {
156 aCircuit.UnpackAgentCircuitData(args);
157 }
158 catch (Exception ex)
159 {
160 m_log.InfoFormat("[HOME AGENT HANDLER]: exception on unpacking ChildCreate message {0}", ex.Message);
161 responsedata["int_response_code"] = HttpStatusCode.BadRequest;
162 responsedata["str_response_string"] = "Bad request";
163 return;
164 }
165
166 OSDMap resp = new OSDMap(2);
167 string reason = String.Empty;
168
169 bool result = m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, out reason);
170
171 resp["reason"] = OSD.FromString(reason);
172 resp["success"] = OSD.FromBoolean(result);
173
174 // TODO: add reason if not String.Empty?
175 responsedata["int_response_code"] = HttpStatusCode.OK;
176 responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp);
177 }
178
179 }
180
181}