aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/InterGrid/OGSRadmin.cs150
-rw-r--r--OpenSim/Region/CoreModules/InterGrid/OpenGridProtocolModule.cs1297
2 files changed, 0 insertions, 1447 deletions
diff --git a/OpenSim/Region/CoreModules/InterGrid/OGSRadmin.cs b/OpenSim/Region/CoreModules/InterGrid/OGSRadmin.cs
deleted file mode 100644
index 2cc0a07..0000000
--- a/OpenSim/Region/CoreModules/InterGrid/OGSRadmin.cs
+++ /dev/null
@@ -1,150 +0,0 @@
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.Collections.Generic;
31using System.Net;
32using System.Reflection;
33using System.Text;
34using log4net;
35using Nini.Config;
36using Nwc.XmlRpc;
37using OpenMetaverse;
38using OpenSim.Framework;
39using OpenSim.Framework.Communications;
40using OpenSim.Framework.Servers;
41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes;
43
44namespace OpenSim.Region.CoreModules.InterGrid
45{
46 public class OGSRadmin : IRegionModule
47 {
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 private readonly List<Scene> m_scenes = new List<Scene>();
50 private IConfigSource m_settings;
51
52 #region Implementation of IRegionModuleBase
53
54 public string Name
55 {
56 get { return "OGS Supporting RAdmin"; }
57 }
58
59
60 public void Initialise(IConfigSource source)
61 {
62 m_settings = source;
63 }
64
65 public void Close()
66 {
67
68 }
69
70 public void AddRegion(Scene scene)
71 {
72 lock (m_scenes)
73 m_scenes.Add(scene);
74 }
75
76 public void RemoveRegion(Scene scene)
77 {
78 lock (m_scenes)
79 m_scenes.Remove(scene);
80 }
81
82 public void RegionLoaded(Scene scene)
83 {
84
85 }
86
87 public void PostInitialise()
88 {
89 if (m_settings.Configs["Startup"].GetBoolean("gridmode", false))
90 {
91 MainServer.Instance.AddXmlRPCHandler("grid_message", GridWideMessage);
92 }
93 }
94
95 #endregion
96
97 #region IRegionModule
98
99 public void Initialise(Scene scene, IConfigSource source)
100 {
101 m_settings = source;
102
103 lock (m_scenes)
104 m_scenes.Add(scene);
105 }
106
107 public bool IsSharedModule
108 {
109 get { return true; }
110 }
111
112 #endregion
113
114 public XmlRpcResponse GridWideMessage(XmlRpcRequest req, IPEndPoint remoteClient)
115 {
116 XmlRpcResponse response = new XmlRpcResponse();
117 Hashtable responseData = new Hashtable();
118
119 Hashtable requestData = (Hashtable)req.Params[0];
120
121 // REFACTORING PROBLEM. This authorization needs to be replaced with some other
122 //if ((!requestData.Contains("password") || (string)requestData["password"] != m_com.NetworkServersInfo.GridRecvKey))
123 //{
124 // responseData["accepted"] = false;
125 // responseData["success"] = false;
126 // responseData["error"] = "Invalid Key";
127 // response.Value = responseData;
128 // return response;
129 //}
130
131 string message = (string)requestData["message"];
132 string user = (string)requestData["user"];
133 m_log.InfoFormat("[RADMIN]: Broadcasting: {0}", message);
134
135 lock (m_scenes)
136 foreach (Scene scene in m_scenes)
137 {
138 IDialogModule dialogModule = scene.RequestModuleInterface<IDialogModule>();
139 if (dialogModule != null)
140 dialogModule.SendNotificationToUsersInRegion(UUID.Random(), user, message);
141 }
142
143 responseData["accepted"] = true;
144 responseData["success"] = true;
145 response.Value = responseData;
146
147 return response;
148 }
149 }
150}
diff --git a/OpenSim/Region/CoreModules/InterGrid/OpenGridProtocolModule.cs b/OpenSim/Region/CoreModules/InterGrid/OpenGridProtocolModule.cs
deleted file mode 100644
index 4a76b00..0000000
--- a/OpenSim/Region/CoreModules/InterGrid/OpenGridProtocolModule.cs
+++ /dev/null
@@ -1,1297 +0,0 @@
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.Generic;
30using System.IO;
31using System.Net;
32using System.Net.Security;
33using System.Reflection;
34using System.Security.Cryptography.X509Certificates;
35using System.Threading;
36using System.Web;
37using log4net;
38using Nini.Config;
39using OpenMetaverse;
40using OpenMetaverse.StructuredData;
41using OpenSim.Framework;
42using OpenSim.Framework.Capabilities;
43using OpenSim.Framework.Monitoring;
44using OpenSim.Framework.Servers;
45using OpenSim.Region.Framework.Interfaces;
46using OpenSim.Region.Framework.Scenes;
47using Caps=OpenSim.Framework.Capabilities.Caps;
48using OSDArray=OpenMetaverse.StructuredData.OSDArray;
49using OSDMap=OpenMetaverse.StructuredData.OSDMap;
50
51namespace OpenSim.Region.CoreModules.InterGrid
52{
53 public struct OGPState
54 {
55 public string first_name;
56 public string last_name;
57 public UUID agent_id;
58 public UUID local_agent_id;
59 public UUID region_id;
60 public uint circuit_code;
61 public UUID secure_session_id;
62 public UUID session_id;
63 public bool agent_access;
64 public string sim_access;
65 public uint god_level;
66 public bool god_overide;
67 public bool identified;
68 public bool transacted;
69 public bool age_verified;
70 public bool allow_redirect;
71 public int limited_to_estate;
72 public string inventory_host;
73 public bool src_can_see_mainland;
74 public int src_estate_id;
75 public int src_version;
76 public int src_parent_estate_id;
77 public bool visible_to_parent;
78 public string teleported_into_region;
79 }
80
81 public class OpenGridProtocolModule : IRegionModule
82 {
83 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
84 private List<Scene> m_scene = new List<Scene>();
85
86 private Dictionary<string, AgentCircuitData> CapsLoginID = new Dictionary<string, AgentCircuitData>();
87 private Dictionary<UUID, OGPState> m_OGPState = new Dictionary<UUID, OGPState>();
88 private Dictionary<string, string> m_loginToRegionState = new Dictionary<string, string>();
89
90
91 private string LastNameSuffix = "_EXTERNAL";
92 private string FirstNamePrefix = "";
93 private string httpsCN = "";
94 private bool httpSSL = false;
95 private uint httpsslport = 0;
96// private bool GridMode = false;
97
98 #region IRegionModule Members
99
100 public void Initialise(Scene scene, IConfigSource config)
101 {
102 bool enabled = false;
103 IConfig cfg = null;
104 IConfig httpcfg = null;
105// IConfig startupcfg = null;
106 try
107 {
108 cfg = config.Configs["OpenGridProtocol"];
109 } catch (NullReferenceException)
110 {
111 enabled = false;
112 }
113
114 try
115 {
116 httpcfg = config.Configs["Network"];
117 }
118 catch (NullReferenceException)
119 {
120
121 }
122// try
123// {
124// startupcfg = config.Configs["Startup"];
125// }
126// catch (NullReferenceException)
127// {
128//
129// }
130
131// if (startupcfg != null)
132// {
133// GridMode = enabled = startupcfg.GetBoolean("gridmode", false);
134// }
135
136 if (cfg != null)
137 {
138 enabled = cfg.GetBoolean("ogp_enabled", false);
139 LastNameSuffix = cfg.GetString("ogp_lastname_suffix", "_EXTERNAL");
140 FirstNamePrefix = cfg.GetString("ogp_firstname_prefix", "");
141 if (enabled)
142 {
143 m_log.Warn("[OGP]: Open Grid Protocol is on, Listening for Clients on /agent/");
144 lock (m_scene)
145 {
146 if (m_scene.Count == 0)
147 {
148 MainServer.Instance.AddLLSDHandler("/agent/", ProcessAgentDomainMessage);
149 MainServer.Instance.AddLLSDHandler("/", ProcessRegionDomainSeed);
150 try
151 {
152 ServicePointManager.ServerCertificateValidationCallback += customXertificateValidation;
153 }
154 catch (NotImplementedException)
155 {
156 try
157 {
158#pragma warning disable 0612, 0618
159 // Mono does not implement the ServicePointManager.ServerCertificateValidationCallback yet! Don't remove this!
160 ServicePointManager.CertificatePolicy = new MonoCert();
161#pragma warning restore 0612, 0618
162 }
163 catch (Exception)
164 {
165 m_log.Error("[OGP]: Certificate validation handler change not supported. You may get ssl certificate validation errors teleporting from your region to some SSL regions.");
166 }
167 }
168
169 }
170 // can't pick the region 'agent' because it would conflict with our agent domain handler
171 // a zero length region name would conflict with are base region seed cap
172 if (!SceneListDuplicateCheck(scene.RegionInfo.RegionName) && scene.RegionInfo.RegionName.ToLower() != "agent" && scene.RegionInfo.RegionName.Length > 0)
173 {
174 MainServer.Instance.AddLLSDHandler(
175 "/" + HttpUtility.UrlPathEncode(scene.RegionInfo.RegionName.ToLower()),
176 ProcessRegionDomainSeed);
177 }
178
179 if (!m_scene.Contains(scene))
180 m_scene.Add(scene);
181 }
182 }
183 }
184 lock (m_scene)
185 {
186 if (m_scene.Count == 1)
187 {
188 if (httpcfg != null)
189 {
190 httpSSL = httpcfg.GetBoolean("http_listener_ssl", false);
191 httpsCN = httpcfg.GetString("http_listener_cn", scene.RegionInfo.ExternalHostName);
192 if (httpsCN.Length == 0)
193 httpsCN = scene.RegionInfo.ExternalHostName;
194 httpsslport = (uint)httpcfg.GetInt("http_listener_sslport",((int)scene.RegionInfo.HttpPort + 1));
195 }
196 }
197 }
198 }
199
200 public void PostInitialise()
201 {
202 }
203
204 public void Close()
205 {
206 //scene.EventManager.OnAvatarEnteringNewParcel -= AvatarEnteringParcel;
207 }
208
209 public string Name
210 {
211 get { return "OpenGridProtocolModule"; }
212 }
213
214 public bool IsSharedModule
215 {
216 get { return true; }
217 }
218
219 #endregion
220
221 public OSD ProcessRegionDomainSeed(string path, OSD request, string endpoint)
222 {
223 string[] pathSegments = path.Split('/');
224
225 if (pathSegments.Length <= 1)
226 {
227 return GenerateNoHandlerMessage();
228
229 }
230
231 return GenerateRezAvatarRequestMessage(pathSegments[1]);
232
233
234
235 //m_log.InfoFormat("[OGP]: path {0}, segments {1} segment[1] {2} Last segment {3}",
236 // path, pathSegments.Length, pathSegments[1], pathSegments[pathSegments.Length - 1]);
237 //return new OSDMap();
238
239 }
240
241 public OSD ProcessAgentDomainMessage(string path, OSD request, string endpoint)
242 {
243 // /agent/*
244
245 string[] pathSegments = path.Split('/');
246 if (pathSegments.Length <= 1)
247 {
248 return GenerateNoHandlerMessage();
249
250 }
251 if (pathSegments[0].Length == 0 && pathSegments[1].Length == 0)
252 {
253 return GenerateRezAvatarRequestMessage("");
254 }
255 m_log.InfoFormat("[OGP]: path {0}, segments {1} segment[1] {2} Last segment {3}",
256 path, pathSegments.Length, pathSegments[1], pathSegments[pathSegments.Length - 1]);
257
258 switch (pathSegments[pathSegments.Length - 1])
259 {
260 case "rez_avatar":
261 return RezAvatarMethod(path, request);
262 //break;
263 case "derez_avatar":
264 return DerezAvatarMethod(path, request);
265 //break;
266
267 }
268 if (path.Length < 2)
269 {
270 return GenerateNoHandlerMessage();
271 }
272
273 switch (pathSegments[pathSegments.Length - 2] + "/" + pathSegments[pathSegments.Length - 1])
274 {
275 case "rez_avatar/rez":
276 return RezAvatarMethod(path, request);
277 //break;
278 case "rez_avatar/request":
279 return RequestRezAvatarMethod(path, request);
280 case "rez_avatar/place":
281 return RequestRezAvatarMethod(path, request);
282 case "rez_avatar/derez":
283 return DerezAvatarMethod(path, request);
284 //break;
285 default:
286 return GenerateNoHandlerMessage();
287 }
288 //return null;
289 }
290
291 private OSD GenerateRezAvatarRequestMessage(string regionname)
292 {
293 Scene region = null;
294 bool usedroot = false;
295
296 if (regionname.Length == 0)
297 {
298 region = GetRootScene();
299 usedroot = true;
300 }
301 else
302 {
303 region = GetScene(HttpUtility.UrlDecode(regionname).ToLower());
304 }
305
306 // this shouldn't happen since we don't listen for a region that is down.. but
307 // it might if the region was taken down or is in the middle of restarting
308
309 if (region == null)
310 {
311 region = GetRootScene();
312 usedroot = true;
313 }
314
315 UUID statekeeper = UUID.Random();
316
317
318
319
320 RegionInfo reg = region.RegionInfo;
321
322 OSDMap responseMap = new OSDMap();
323 string rezHttpProtocol = "http://";
324 //string regionCapsHttpProtocol = "http://";
325 string httpaddr = reg.ExternalHostName;
326 string urlport = reg.HttpPort.ToString();
327 string requestpath = "/agent/" + statekeeper + "/rez_avatar/request";
328
329 if (!usedroot)
330 {
331 lock (m_loginToRegionState)
332 {
333 if (!m_loginToRegionState.ContainsKey(requestpath))
334 {
335 m_loginToRegionState.Add(requestpath, region.RegionInfo.RegionName.ToLower());
336 }
337 }
338 }
339
340 if (httpSSL)
341 {
342 rezHttpProtocol = "https://";
343 //regionCapsHttpProtocol = "https://";
344 urlport = httpsslport.ToString();
345
346 if (httpsCN.Length > 0)
347 httpaddr = httpsCN;
348 }
349
350 responseMap["connect"] = OSD.FromBoolean(true);
351 OSDMap capabilitiesMap = new OSDMap();
352 capabilitiesMap["rez_avatar/request"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + requestpath);
353 responseMap["capabilities"] = capabilitiesMap;
354
355 return responseMap;
356 }
357
358 // Using OpenSim.Framework.Capabilities.Caps here one time..
359 // so the long name is probably better then a using statement
360 public void OnRegisterCaps(UUID agentID, Caps caps)
361 {
362 /* If we ever want to register our own caps here....
363 *
364 string capsBase = "/CAPS/" + caps.CapsObjectPath;
365 caps.RegisterHandler("CAPNAME",
366 new RestStreamHandler("POST", capsBase + CAPSPOSTFIX!,
367 delegate(string request, string path, string param,
368 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
369 {
370 return METHODHANDLER(request, path, param,
371 agentID, caps);
372 }));
373
374 *
375 */
376 }
377
378 public OSD RequestRezAvatarMethod(string path, OSD request)
379 {
380 //m_log.Debug("[REQUESTREZAVATAR]: " + request.ToString());
381
382 OSDMap requestMap = (OSDMap)request;
383
384
385 Scene homeScene = null;
386
387 lock (m_loginToRegionState)
388 {
389 if (m_loginToRegionState.ContainsKey(path))
390 {
391 homeScene = GetScene(m_loginToRegionState[path]);
392 m_loginToRegionState.Remove(path);
393
394 if (homeScene == null)
395 homeScene = GetRootScene();
396 }
397 else
398 {
399 homeScene = GetRootScene();
400 }
401 }
402
403 // Homescene is still null, we must have no regions that are up
404 if (homeScene == null)
405 return GenerateNoHandlerMessage();
406
407 RegionInfo reg = homeScene.RegionInfo;
408 ulong regionhandle = GetOSCompatibleRegionHandle(reg);
409 //string RegionURI = reg.ServerURI;
410 //int RegionPort = (int)reg.HttpPort;
411
412 UUID RemoteAgentID = requestMap["agent_id"].AsUUID();
413
414 // will be used in the future. The client always connects with the aditi agentid currently
415 UUID LocalAgentID = RemoteAgentID;
416
417 string FirstName = requestMap["first_name"].AsString();
418 string LastName = requestMap["last_name"].AsString();
419
420 FirstName = FirstNamePrefix + FirstName;
421 LastName = LastName + LastNameSuffix;
422
423 OGPState userState = GetOGPState(LocalAgentID);
424
425 userState.first_name = requestMap["first_name"].AsString();
426 userState.last_name = requestMap["last_name"].AsString();
427 userState.age_verified = requestMap["age_verified"].AsBoolean();
428 userState.transacted = requestMap["transacted"].AsBoolean();
429 userState.agent_access = requestMap["agent_access"].AsBoolean();
430 userState.allow_redirect = requestMap["allow_redirect"].AsBoolean();
431 userState.identified = requestMap["identified"].AsBoolean();
432 userState.god_level = (uint)requestMap["god_level"].AsInteger();
433 userState.sim_access = requestMap["sim_access"].AsString();
434 userState.agent_id = RemoteAgentID;
435 userState.limited_to_estate = requestMap["limited_to_estate"].AsInteger();
436 userState.src_can_see_mainland = requestMap["src_can_see_mainland"].AsBoolean();
437 userState.src_estate_id = requestMap["src_estate_id"].AsInteger();
438 userState.local_agent_id = LocalAgentID;
439 userState.teleported_into_region = reg.RegionName.ToLower();
440
441 UpdateOGPState(LocalAgentID, userState);
442
443 OSDMap responseMap = new OSDMap();
444
445 if (RemoteAgentID == UUID.Zero)
446 {
447 responseMap["connect"] = OSD.FromBoolean(false);
448 responseMap["message"] = OSD.FromString("No agent ID was specified in rez_avatar/request");
449 m_log.Error("[OGP]: rez_avatar/request failed because no avatar UUID was provided in the request body");
450 return responseMap;
451 }
452
453 responseMap["sim_host"] = OSD.FromString(reg.ExternalHostName);
454
455 // DEPRECATED
456 responseMap["sim_ip"] = OSD.FromString(Util.GetHostFromDNS(reg.ExternalHostName).ToString());
457
458 responseMap["connect"] = OSD.FromBoolean(true);
459 responseMap["sim_port"] = OSD.FromInteger(reg.InternalEndPoint.Port);
460 responseMap["region_x"] = OSD.FromInteger(reg.RegionLocX * (uint)Constants.RegionSize); // LLX
461 responseMap["region_y"] = OSD.FromInteger(reg.RegionLocY * (uint)Constants.RegionSize); // LLY
462 responseMap["region_id"] = OSD.FromUUID(reg.originRegionID);
463
464 if (reg.RegionSettings.Maturity == 1)
465 {
466 responseMap["sim_access"] = OSD.FromString("Mature");
467 }
468 else if (reg.RegionSettings.Maturity == 2)
469 {
470 responseMap["sim_access"] = OSD.FromString("Adult");
471 }
472 else
473 {
474 responseMap["sim_access"] = OSD.FromString("PG");
475 }
476
477 // Generate a dummy agent for the user so we can get back a CAPS path
478 AgentCircuitData agentData = new AgentCircuitData();
479 agentData.AgentID = LocalAgentID;
480 agentData.BaseFolder = UUID.Zero;
481 agentData.CapsPath = CapsUtil.GetRandomCapsObjectPath();
482 agentData.child = false;
483 agentData.circuitcode = (uint)(Util.RandomClass.Next());
484 agentData.firstname = FirstName;
485 agentData.lastname = LastName;
486 agentData.SecureSessionID = UUID.Random();
487 agentData.SessionID = UUID.Random();
488 agentData.startpos = new Vector3(128f, 128f, 100f);
489
490 // Pre-Fill our region cache with information on the agent.
491 UserAgentData useragent = new UserAgentData();
492 useragent.AgentIP = "unknown";
493 useragent.AgentOnline = true;
494 useragent.AgentPort = (uint)0;
495 useragent.Handle = regionhandle;
496 useragent.InitialRegion = reg.originRegionID;
497 useragent.LoginTime = Util.UnixTimeSinceEpoch();
498 useragent.LogoutTime = 0;
499 useragent.Position = agentData.startpos;
500 useragent.Region = reg.originRegionID;
501 useragent.SecureSessionID = agentData.SecureSessionID;
502 useragent.SessionID = agentData.SessionID;
503
504 UserProfileData userProfile = new UserProfileData();
505 userProfile.AboutText = "OGP User";
506 userProfile.CanDoMask = (uint)0;
507 userProfile.Created = Util.UnixTimeSinceEpoch();
508 userProfile.CurrentAgent = useragent;
509 userProfile.CustomType = "OGP";
510 userProfile.FirstLifeAboutText = "I'm testing OpenGrid Protocol";
511 userProfile.FirstLifeImage = UUID.Zero;
512 userProfile.FirstName = agentData.firstname;
513 userProfile.GodLevel = 0;
514 userProfile.HomeLocation = agentData.startpos;
515 userProfile.HomeLocationX = agentData.startpos.X;
516 userProfile.HomeLocationY = agentData.startpos.Y;
517 userProfile.HomeLocationZ = agentData.startpos.Z;
518 userProfile.HomeLookAt = Vector3.Zero;
519 userProfile.HomeLookAtX = userProfile.HomeLookAt.X;
520 userProfile.HomeLookAtY = userProfile.HomeLookAt.Y;
521 userProfile.HomeLookAtZ = userProfile.HomeLookAt.Z;
522 userProfile.HomeRegion = reg.RegionHandle;
523 userProfile.HomeRegionID = reg.originRegionID;
524 userProfile.HomeRegionX = reg.RegionLocX;
525 userProfile.HomeRegionY = reg.RegionLocY;
526 userProfile.ID = agentData.AgentID;
527 userProfile.Image = UUID.Zero;
528 userProfile.LastLogin = Util.UnixTimeSinceEpoch();
529 userProfile.Partner = UUID.Zero;
530 userProfile.PasswordHash = "$1$";
531 userProfile.PasswordSalt = "";
532 userProfile.SurName = agentData.lastname;
533 //userProfile.UserAssetURI = homeScene.CommsManager.NetworkServersInfo.AssetURL;
534 userProfile.UserFlags = 0;
535 //userProfile.UserInventoryURI = homeScene.CommsManager.NetworkServersInfo.InventoryURL;
536 userProfile.WantDoMask = 0;
537 userProfile.WebLoginKey = UUID.Random();
538
539 // !!! REFACTORING PROBLEM. This needs to be changed for 0.7
540 //
541 //// Do caps registration
542 //// get seed capagentData.firstname = FirstName;agentData.lastname = LastName;
543 //if (homeScene.CommsManager.UserService.GetUserProfile(agentData.AgentID) == null && !GridMode)
544 //{
545 // homeScene.CommsManager.UserAdminService.AddUser(
546 // agentData.firstname, agentData.lastname, CreateRandomStr(7), "",
547 // homeScene.RegionInfo.RegionLocX, homeScene.RegionInfo.RegionLocY, agentData.AgentID);
548
549 // UserProfileData userProfile2 = homeScene.CommsManager.UserService.GetUserProfile(agentData.AgentID);
550 // if (userProfile2 != null)
551 // {
552 // userProfile = userProfile2;
553 // userProfile.AboutText = "OGP USER";
554 // userProfile.FirstLifeAboutText = "OGP USER";
555 // homeScene.CommsManager.UserService.UpdateUserProfile(userProfile);
556 // }
557 //}
558
559 //// Stick our data in the cache so the region will know something about us
560 //homeScene.CommsManager.UserProfileCacheService.PreloadUserCache(userProfile);
561
562 // Call 'new user' event handler
563 string reason;
564 if (!homeScene.NewUserConnection(agentData, (uint)TeleportFlags.ViaLogin, out reason))
565 {
566 responseMap["connect"] = OSD.FromBoolean(false);
567 responseMap["message"] = OSD.FromString(String.Format("Connection refused: {0}", reason));
568 m_log.ErrorFormat("[OGP]: rez_avatar/request failed: {0}", reason);
569 return responseMap;
570 }
571
572
573 //string raCap = string.Empty;
574
575 UUID AvatarRezCapUUID = LocalAgentID;
576 string rezAvatarPath = "/agent/" + AvatarRezCapUUID + "/rez_avatar/rez";
577 string derezAvatarPath = "/agent/" + AvatarRezCapUUID + "/rez_avatar/derez";
578 // Get a reference to the user's cap so we can pull out the Caps Object Path
579 Caps userCap
580 = homeScene.CapsModule.GetCapsForUser(agentData.AgentID);
581
582 string rezHttpProtocol = "http://";
583 string regionCapsHttpProtocol = "http://";
584 string httpaddr = reg.ExternalHostName;
585 string urlport = reg.HttpPort.ToString();
586
587 if (httpSSL)
588 {
589 rezHttpProtocol = "https://";
590 regionCapsHttpProtocol = "https://";
591 urlport = httpsslport.ToString();
592
593 if (httpsCN.Length > 0)
594 httpaddr = httpsCN;
595 }
596
597 // DEPRECATED
598 responseMap["seed_capability"]
599 = OSD.FromString(
600 regionCapsHttpProtocol + httpaddr + ":" + reg.HttpPort + "/" + CapsUtil.GetCapsSeedPath(userCap.CapsObjectPath));
601
602 // REPLACEMENT
603 responseMap["region_seed_capability"]
604 = OSD.FromString(
605 regionCapsHttpProtocol + httpaddr + ":" + reg.HttpPort + "/" + CapsUtil.GetCapsSeedPath(userCap.CapsObjectPath));
606
607 responseMap["rez_avatar"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + rezAvatarPath);
608 responseMap["rez_avatar/rez"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + rezAvatarPath);
609 responseMap["rez_avatar/derez"] = OSD.FromString(rezHttpProtocol + httpaddr + ":" + urlport + derezAvatarPath);
610
611 // Add the user to the list of CAPS that are outstanding.
612 // well allow the caps hosts in this dictionary
613 lock (CapsLoginID)
614 {
615 if (CapsLoginID.ContainsKey(rezAvatarPath))
616 {
617 CapsLoginID[rezAvatarPath] = agentData;
618
619 // This is a joke, if you didn't notice... It's so unlikely to happen, that I'll print this message if it does occur!
620 m_log.Error("[OGP]: Holy anomoly batman! Caps path already existed! All the UUID Duplication worries were founded!");
621 }
622 else
623 {
624 CapsLoginID.Add(rezAvatarPath, agentData);
625 }
626 }
627
628 //m_log.Debug("Response:" + responseMap.ToString());
629 return responseMap;
630 }
631
632 public OSD RezAvatarMethod(string path, OSD request)
633 {
634 m_log.WarnFormat("[REZAVATAR]: {0}", request.ToString());
635
636 OSDMap responseMap = new OSDMap();
637
638 AgentCircuitData userData = null;
639
640 // Only people we've issued a cap can go further
641 if (TryGetAgentCircuitData(path,out userData))
642 {
643 OSDMap requestMap = (OSDMap)request;
644
645 // take these values to start. There's a few more
646 UUID SecureSessionID=requestMap["secure_session_id"].AsUUID();
647 UUID SessionID = requestMap["session_id"].AsUUID();
648 int circuitcode = requestMap["circuit_code"].AsInteger();
649 OSDArray Parameter = new OSDArray();
650 if (requestMap.ContainsKey("parameter"))
651 {
652 Parameter = (OSDArray)requestMap["parameter"];
653 }
654
655 //int version = 1;
656 int estateID = 1;
657 int parentEstateID = 1;
658 UUID regionID = UUID.Zero;
659 bool visibleToParent = true;
660
661 for (int i = 0; i < Parameter.Count; i++)
662 {
663 OSDMap item = (OSDMap)Parameter[i];
664// if (item.ContainsKey("version"))
665// {
666// version = item["version"].AsInteger();
667// }
668 if (item.ContainsKey("estate_id"))
669 {
670 estateID = item["estate_id"].AsInteger();
671 }
672 if (item.ContainsKey("parent_estate_id"))
673 {
674 parentEstateID = item["parent_estate_id"].AsInteger();
675
676 }
677 if (item.ContainsKey("region_id"))
678 {
679 regionID = item["region_id"].AsUUID();
680
681 }
682 if (item.ContainsKey("visible_to_parent"))
683 {
684 visibleToParent = item["visible_to_parent"].AsBoolean();
685 }
686 }
687 //Update our Circuit data with the real values
688 userData.SecureSessionID = SecureSessionID;
689 userData.SessionID = SessionID;
690
691 OGPState userState = GetOGPState(userData.AgentID);
692
693 // Locate a home scene suitable for the user.
694 Scene homeScene = null;
695
696 homeScene = GetScene(userState.teleported_into_region);
697
698 if (homeScene == null)
699 homeScene = GetRootScene();
700
701 if (homeScene != null)
702 {
703 // Get a referenceokay - to their Cap object so we can pull out the capobjectroot
704 Caps userCap
705 = homeScene.CapsModule.GetCapsForUser(userData.AgentID);
706
707 //Update the circuit data in the region so this user is authorized
708 homeScene.UpdateCircuitData(userData);
709 homeScene.ChangeCircuitCode(userData.circuitcode,(uint)circuitcode);
710
711 // Load state
712
713
714 // Keep state changes
715 userState.first_name = requestMap["first_name"].AsString();
716 userState.secure_session_id = requestMap["secure_session_id"].AsUUID();
717 userState.age_verified = requestMap["age_verified"].AsBoolean();
718 userState.region_id = homeScene.RegionInfo.originRegionID; // replace 0000000 with our regionid
719 userState.transacted = requestMap["transacted"].AsBoolean();
720 userState.agent_access = requestMap["agent_access"].AsBoolean();
721 userState.inventory_host = requestMap["inventory_host"].AsString();
722 userState.identified = requestMap["identified"].AsBoolean();
723 userState.session_id = requestMap["session_id"].AsUUID();
724 userState.god_level = (uint)requestMap["god_level"].AsInteger();
725 userState.last_name = requestMap["last_name"].AsString();
726 userState.god_overide = requestMap["god_override"].AsBoolean();
727 userState.circuit_code = (uint)requestMap["circuit_code"].AsInteger();
728 userState.limited_to_estate = requestMap["limited_to_estate"].AsInteger();
729 userState.src_estate_id = estateID;
730 userState.region_id = regionID;
731 userState.src_parent_estate_id = parentEstateID;
732 userState.visible_to_parent = visibleToParent;
733
734 // Save state changes
735 UpdateOGPState(userData.AgentID, userState);
736
737 // Get the region information for the home region.
738 RegionInfo reg = homeScene.RegionInfo;
739
740 // Dummy positional and look at info.. we don't have it.
741 OSDArray PositionArray = new OSDArray();
742 PositionArray.Add(OSD.FromInteger(128));
743 PositionArray.Add(OSD.FromInteger(128));
744 PositionArray.Add(OSD.FromInteger(40));
745
746 OSDArray LookAtArray = new OSDArray();
747 LookAtArray.Add(OSD.FromInteger(1));
748 LookAtArray.Add(OSD.FromInteger(1));
749 LookAtArray.Add(OSD.FromInteger(1));
750
751 // Our region's X and Y position in OpenSimulator space.
752 uint fooX = reg.RegionLocX;
753 uint fooY = reg.RegionLocY;
754 m_log.InfoFormat("[OGP]: region x({0}) region y({1})", fooX, fooY);
755 m_log.InfoFormat("[OGP]: region http {0} {1}", reg.ServerURI, reg.HttpPort);
756 m_log.InfoFormat("[OGO]: region UUID {0} ", reg.RegionID);
757
758 // Convert the X and Y position to LL space
759 responseMap["region_x"] = OSD.FromInteger(fooX * (uint)Constants.RegionSize); // convert it to LL X
760 responseMap["region_y"] = OSD.FromInteger(fooY * (uint)Constants.RegionSize); // convert it to LL Y
761
762 // Give em a new seed capability
763 responseMap["seed_capability"] = OSD.FromString("http://" + reg.ExternalHostName + ":" + reg.HttpPort + "/CAPS/" + userCap.CapsObjectPath + "0000/");
764 responseMap["region"] = OSD.FromUUID(reg.originRegionID);
765 responseMap["look_at"] = LookAtArray;
766
767 responseMap["sim_port"] = OSD.FromInteger(reg.InternalEndPoint.Port);
768 responseMap["sim_host"] = OSD.FromString(reg.ExternalHostName);// + ":" + reg.InternalEndPoint.Port.ToString());
769
770 // DEPRECATED
771 responseMap["sim_ip"] = OSD.FromString(Util.GetHostFromDNS(reg.ExternalHostName).ToString());
772
773 responseMap["session_id"] = OSD.FromUUID(SessionID);
774 responseMap["secure_session_id"] = OSD.FromUUID(SecureSessionID);
775 responseMap["circuit_code"] = OSD.FromInteger(circuitcode);
776
777 responseMap["position"] = PositionArray;
778
779 responseMap["region_id"] = OSD.FromUUID(reg.originRegionID);
780
781 responseMap["sim_access"] = OSD.FromString("Mature");
782
783 responseMap["connect"] = OSD.FromBoolean(true);
784
785
786
787 m_log.InfoFormat("[OGP]: host: {0}, IP {1}", responseMap["sim_host"].ToString(), responseMap["sim_ip"].ToString());
788 }
789 }
790
791 return responseMap;
792 }
793
794 public OSD DerezAvatarMethod(string path, OSD request)
795 {
796 m_log.ErrorFormat("DerezPath: {0}, Request: {1}", path, request.ToString());
797
798 //LLSD llsdResponse = null;
799 OSDMap responseMap = new OSDMap();
800
801 string[] PathArray = path.Split('/');
802 m_log.InfoFormat("[OGP]: prefix {0}, uuid {1}, suffix {2}", PathArray[1], PathArray[2], PathArray[3]);
803 string uuidString = PathArray[2];
804 m_log.InfoFormat("[OGP]: Request to Derez avatar with UUID {0}", uuidString);
805 UUID userUUID = UUID.Zero;
806 if (UUID.TryParse(uuidString, out userUUID))
807 {
808 UUID RemoteID = (UUID)uuidString;
809 UUID LocalID = RemoteID;
810 // FIXME: TODO: Routine to map RemoteUUIDs to LocalUUIds
811 // would be done already.. but the client connects with the Aditi UUID
812 // regardless over the UDP stack
813
814 OGPState userState = GetOGPState(LocalID);
815 if (userState.agent_id != UUID.Zero)
816 {
817 //OSDMap outboundRequestMap = new OSDMap();
818 OSDMap inboundRequestMap = (OSDMap)request;
819 string rezAvatarString = inboundRequestMap["rez_avatar"].AsString();
820 if (rezAvatarString.Length == 0)
821 {
822 rezAvatarString = inboundRequestMap["rez_avatar/rez"].AsString();
823 }
824 OSDArray LookAtArray = new OSDArray();
825 LookAtArray.Add(OSD.FromInteger(1));
826 LookAtArray.Add(OSD.FromInteger(1));
827 LookAtArray.Add(OSD.FromInteger(1));
828
829 OSDArray PositionArray = new OSDArray();
830 PositionArray.Add(OSD.FromInteger(128));
831 PositionArray.Add(OSD.FromInteger(128));
832 PositionArray.Add(OSD.FromInteger(40));
833
834 OSDArray lookArray = new OSDArray();
835 lookArray.Add(OSD.FromInteger(128));
836 lookArray.Add(OSD.FromInteger(128));
837 lookArray.Add(OSD.FromInteger(40));
838
839 responseMap["connect"] = OSD.FromBoolean(true);// it's okay to give this user up
840 responseMap["look_at"] = LookAtArray;
841
842 m_log.WarnFormat("[OGP]: Invoking rez_avatar on host:{0} for avatar: {1} {2}", rezAvatarString, userState.first_name, userState.last_name);
843
844 OSDMap rezResponseMap = invokeRezAvatarCap(responseMap, rezAvatarString,userState);
845
846 // If invoking it returned an error, parse and end
847 if (rezResponseMap.ContainsKey("connect"))
848 {
849 if (rezResponseMap["connect"].AsBoolean() == false)
850 {
851 return responseMap;
852 }
853 }
854
855 string rezRespSeedCap = "";
856
857 // DEPRECATED
858 if (rezResponseMap.ContainsKey("seed_capability"))
859 rezRespSeedCap = rezResponseMap["seed_capability"].AsString();
860
861 // REPLACEMENT
862 if (rezResponseMap.ContainsKey("region_seed_capability"))
863 rezRespSeedCap = rezResponseMap["region_seed_capability"].AsString();
864
865 // REPLACEMENT
866 if (rezResponseMap.ContainsKey("rez_avatar/rez"))
867 rezRespSeedCap = rezResponseMap["rez_avatar/rez"].AsString();
868
869 // DEPRECATED
870 string rezRespSim_ip = rezResponseMap["sim_ip"].AsString();
871
872 string rezRespSim_host = rezResponseMap["sim_host"].AsString();
873
874 int rrPort = rezResponseMap["sim_port"].AsInteger();
875 int rrX = rezResponseMap["region_x"].AsInteger();
876 int rrY = rezResponseMap["region_y"].AsInteger();
877 m_log.ErrorFormat("X:{0}, Y:{1}", rrX, rrY);
878 UUID rrRID = rezResponseMap["region_id"].AsUUID();
879 OSDArray RezResponsePositionArray = null;
880 string rrAccess = rezResponseMap["sim_access"].AsString();
881 if (rezResponseMap.ContainsKey("position"))
882 {
883 RezResponsePositionArray = (OSDArray)rezResponseMap["position"];
884 }
885 // DEPRECATED
886 responseMap["seed_capability"] = OSD.FromString(rezRespSeedCap);
887
888 // REPLACEMENT r3
889 responseMap["region_seed_capability"] = OSD.FromString(rezRespSeedCap);
890
891 // DEPRECATED
892 responseMap["sim_ip"] = OSD.FromString(Util.GetHostFromDNS(rezRespSim_ip).ToString());
893
894 responseMap["sim_host"] = OSD.FromString(rezRespSim_host);
895 responseMap["sim_port"] = OSD.FromInteger(rrPort);
896 responseMap["region_x"] = OSD.FromInteger(rrX);
897 responseMap["region_y"] = OSD.FromInteger(rrY);
898 responseMap["region_id"] = OSD.FromUUID(rrRID);
899 responseMap["sim_access"] = OSD.FromString(rrAccess);
900
901 if (RezResponsePositionArray != null)
902 {
903 responseMap["position"] = RezResponsePositionArray;
904 }
905 responseMap["look_at"] = lookArray;
906 responseMap["connect"] = OSD.FromBoolean(true);
907
908 ShutdownConnection(LocalID,this);
909 // PLEASE STOP CHANGING THIS TO an M_LOG, M_LOG DOESN'T WORK ON MULTILINE .TOSTRINGS
910 Console.WriteLine("RESPONSEDEREZ: " + responseMap.ToString());
911 return responseMap;
912 }
913 else
914 {
915 return GenerateNoStateMessage(LocalID);
916 }
917 }
918 else
919 {
920 return GenerateNoHandlerMessage();
921 }
922
923 //return responseMap;
924 }
925
926 private OSDMap invokeRezAvatarCap(OSDMap responseMap, string CapAddress, OGPState userState)
927 {
928 Scene reg = GetRootScene();
929
930 WebRequest DeRezRequest = WebRequest.Create(CapAddress);
931 DeRezRequest.Method = "POST";
932 DeRezRequest.ContentType = "application/xml+llsd";
933
934 OSDMap RAMap = new OSDMap();
935 OSDMap AgentParms = new OSDMap();
936 OSDMap RegionParms = new OSDMap();
937
938 OSDArray Parameter = new OSDArray(2);
939
940 OSDMap version = new OSDMap();
941 version["version"] = OSD.FromInteger(userState.src_version);
942 Parameter.Add(version);
943
944 OSDMap SrcData = new OSDMap();
945 SrcData["estate_id"] = OSD.FromInteger(reg.RegionInfo.EstateSettings.EstateID);
946 SrcData["parent_estate_id"] = OSD.FromInteger((reg.RegionInfo.EstateSettings.ParentEstateID == 100 ? 1 : reg.RegionInfo.EstateSettings.ParentEstateID));
947 SrcData["region_id"] = OSD.FromUUID(reg.RegionInfo.originRegionID);
948 SrcData["visible_to_parent"] = OSD.FromBoolean(userState.visible_to_parent);
949 Parameter.Add(SrcData);
950
951 AgentParms["first_name"] = OSD.FromString(userState.first_name);
952 AgentParms["last_name"] = OSD.FromString(userState.last_name);
953 AgentParms["agent_id"] = OSD.FromUUID(userState.agent_id);
954 RegionParms["region_id"] = OSD.FromUUID(userState.region_id);
955 AgentParms["circuit_code"] = OSD.FromInteger(userState.circuit_code);
956 AgentParms["secure_session_id"] = OSD.FromUUID(userState.secure_session_id);
957 AgentParms["session_id"] = OSD.FromUUID(userState.session_id);
958 AgentParms["agent_access"] = OSD.FromBoolean(userState.agent_access);
959 AgentParms["god_level"] = OSD.FromInteger(userState.god_level);
960 AgentParms["god_overide"] = OSD.FromBoolean(userState.god_overide);
961 AgentParms["identified"] = OSD.FromBoolean(userState.identified);
962 AgentParms["transacted"] = OSD.FromBoolean(userState.transacted);
963 AgentParms["age_verified"] = OSD.FromBoolean(userState.age_verified);
964 AgentParms["limited_to_estate"] = OSD.FromInteger(userState.limited_to_estate);
965 AgentParms["inventory_host"] = OSD.FromString(userState.inventory_host);
966
967 // version 1
968 RAMap = AgentParms;
969
970 // Planned for version 2
971 // RAMap["agent_params"] = AgentParms;
972
973 RAMap["region_params"] = RegionParms;
974 RAMap["parameter"] = Parameter;
975
976 string RAMapString = RAMap.ToString();
977 m_log.InfoFormat("[OGP] RAMap string {0}", RAMapString);
978 OSD LLSDofRAMap = RAMap; // RENAME if this works
979
980 m_log.InfoFormat("[OGP]: LLSD of map as string was {0}", LLSDofRAMap.ToString());
981 //m_log.InfoFormat("[OGP]: LLSD+XML: {0}", LLSDParser.SerializeXmlString(LLSDofRAMap));
982 byte[] buffer = OSDParser.SerializeLLSDXmlBytes(LLSDofRAMap);
983
984 //string bufferDump = System.Text.Encoding.ASCII.GetString(buffer);
985 //m_log.InfoFormat("[OGP]: buffer form is {0}",bufferDump);
986 //m_log.InfoFormat("[OGP]: LLSD of map was {0}",buffer.Length);
987
988 Stream os = null;
989 try
990 { // send the Post
991 DeRezRequest.ContentLength = buffer.Length; //Count bytes to send
992 os = DeRezRequest.GetRequestStream();
993 os.Write(buffer, 0, buffer.Length); //Send it
994 os.Close();
995 m_log.InfoFormat("[OGP]: Derez Avatar Posted Rez Avatar request to remote sim {0}", CapAddress);
996 }
997 catch (WebException ex)
998 {
999 m_log.InfoFormat("[OGP] Bad send on de_rez_avatar {0}", ex.Message);
1000 responseMap["connect"] = OSD.FromBoolean(false);
1001
1002 return responseMap;
1003 }
1004
1005 m_log.Info("[OGP] waiting for a reply after rez avatar send");
1006 string rez_avatar_reply = null;
1007 { // get the response
1008 try
1009 {
1010 WebResponse webResponse = DeRezRequest.GetResponse();
1011 if (webResponse == null)
1012 {
1013 m_log.Info("[OGP:] Null reply on rez_avatar post");
1014 }
1015
1016 StreamReader sr = new StreamReader(webResponse.GetResponseStream());
1017 rez_avatar_reply = sr.ReadToEnd().Trim();
1018 m_log.InfoFormat("[OGP]: rez_avatar reply was {0} ", rez_avatar_reply);
1019
1020 }
1021 catch (WebException ex)
1022 {
1023 m_log.InfoFormat("[OGP]: exception on read after send of rez avatar {0}", ex.Message);
1024 responseMap["connect"] = OSD.FromBoolean(false);
1025
1026 return responseMap;
1027 }
1028 OSD rezResponse = null;
1029 try
1030 {
1031 rezResponse = OSDParser.DeserializeLLSDXml(rez_avatar_reply);
1032
1033 responseMap = (OSDMap)rezResponse;
1034 }
1035 catch (Exception ex)
1036 {
1037 m_log.InfoFormat("[OGP]: exception on parse of rez reply {0}", ex.Message);
1038 responseMap["connect"] = OSD.FromBoolean(false);
1039
1040 return responseMap;
1041 }
1042 }
1043 return responseMap;
1044 }
1045
1046 public OSD GenerateNoHandlerMessage()
1047 {
1048 OSDMap map = new OSDMap();
1049 map["reason"] = OSD.FromString("LLSDRequest");
1050 map["message"] = OSD.FromString("No handler registered for LLSD Requests");
1051 map["login"] = OSD.FromString("false");
1052 map["connect"] = OSD.FromString("false");
1053 return map;
1054 }
1055 public OSD GenerateNoStateMessage(UUID passedAvatar)
1056 {
1057 OSDMap map = new OSDMap();
1058 map["reason"] = OSD.FromString("derez failed");
1059 map["message"] = OSD.FromString("Unable to locate OGP state for avatar " + passedAvatar.ToString());
1060 map["login"] = OSD.FromString("false");
1061 map["connect"] = OSD.FromString("false");
1062 return map;
1063 }
1064 private bool TryGetAgentCircuitData(string path, out AgentCircuitData userdata)
1065 {
1066 userdata = null;
1067 lock (CapsLoginID)
1068 {
1069 if (CapsLoginID.ContainsKey(path))
1070 {
1071 userdata = CapsLoginID[path];
1072 DiscardUsedCap(path);
1073 return true;
1074 }
1075 }
1076 return false;
1077 }
1078
1079 private void DiscardUsedCap(string path)
1080 {
1081 CapsLoginID.Remove(path);
1082 }
1083
1084 private Scene GetRootScene()
1085 {
1086 Scene ReturnScene = null;
1087 lock (m_scene)
1088 {
1089 if (m_scene.Count > 0)
1090 {
1091 ReturnScene = m_scene[0];
1092 }
1093 }
1094
1095 return ReturnScene;
1096 }
1097
1098 private Scene GetScene(string scenename)
1099 {
1100 Scene ReturnScene = null;
1101 lock (m_scene)
1102 {
1103 foreach (Scene s in m_scene)
1104 {
1105 if (s.RegionInfo.RegionName.ToLower() == scenename)
1106 {
1107 ReturnScene = s;
1108 break;
1109 }
1110 }
1111 }
1112
1113 return ReturnScene;
1114 }
1115
1116 private ulong GetOSCompatibleRegionHandle(RegionInfo reg)
1117 {
1118 return Util.UIntsToLong(reg.RegionLocX, reg.RegionLocY);
1119 }
1120
1121 private OGPState InitializeNewState()
1122 {
1123 OGPState returnState = new OGPState();
1124 returnState.first_name = "";
1125 returnState.last_name = "";
1126 returnState.agent_id = UUID.Zero;
1127 returnState.local_agent_id = UUID.Zero;
1128 returnState.region_id = UUID.Zero;
1129 returnState.circuit_code = 0;
1130 returnState.secure_session_id = UUID.Zero;
1131 returnState.session_id = UUID.Zero;
1132 returnState.agent_access = true;
1133 returnState.god_level = 0;
1134 returnState.god_overide = false;
1135 returnState.identified = false;
1136 returnState.transacted = false;
1137 returnState.age_verified = false;
1138 returnState.limited_to_estate = 1;
1139 returnState.inventory_host = "http://inv4.mysql.aditi.lindenlab.com";
1140 returnState.allow_redirect = true;
1141 returnState.sim_access = "";
1142 returnState.src_can_see_mainland = true;
1143 returnState.src_estate_id = 1;
1144 returnState.src_version = 1;
1145 returnState.src_parent_estate_id = 1;
1146 returnState.visible_to_parent = true;
1147 returnState.teleported_into_region = "";
1148
1149 return returnState;
1150 }
1151
1152 private OGPState GetOGPState(UUID agentId)
1153 {
1154 lock (m_OGPState)
1155 {
1156 if (m_OGPState.ContainsKey(agentId))
1157 {
1158 return m_OGPState[agentId];
1159 }
1160 else
1161 {
1162 return InitializeNewState();
1163 }
1164 }
1165 }
1166
1167 public void DeleteOGPState(UUID agentId)
1168 {
1169 lock (m_OGPState)
1170 {
1171 if (m_OGPState.ContainsKey(agentId))
1172 m_OGPState.Remove(agentId);
1173 }
1174 }
1175
1176 private void UpdateOGPState(UUID agentId, OGPState state)
1177 {
1178 lock (m_OGPState)
1179 {
1180 if (m_OGPState.ContainsKey(agentId))
1181 {
1182 m_OGPState[agentId] = state;
1183 }
1184 else
1185 {
1186 m_OGPState.Add(agentId,state);
1187 }
1188 }
1189 }
1190 private bool SceneListDuplicateCheck(string str)
1191 {
1192 // no lock, called from locked space!
1193 bool found = false;
1194
1195 foreach (Scene s in m_scene)
1196 {
1197 if (s.RegionInfo.RegionName == str)
1198 {
1199 found = true;
1200 break;
1201 }
1202 }
1203
1204 return found;
1205 }
1206
1207 public void ShutdownConnection(UUID avatarId, OpenGridProtocolModule mod)
1208 {
1209 Scene homeScene = GetRootScene();
1210 ScenePresence avatar = null;
1211 if (homeScene.TryGetScenePresence(avatarId,out avatar))
1212 {
1213 KillAUser ku = new KillAUser(avatar,mod);
1214 Watchdog.StartThread(ku.ShutdownNoLogout, "OGPShutdown", ThreadPriority.Normal, true, true);
1215 }
1216 }
1217
1218// private string CreateRandomStr(int len)
1219// {
1220// Random rnd = new Random(Environment.TickCount);
1221// string returnstring = "";
1222// string chars = "abcdefghijklmnopqrstuvwxyz0123456789";
1223//
1224// for (int i = 0; i < len; i++)
1225// {
1226// returnstring += chars.Substring(rnd.Next(chars.Length), 1);
1227// }
1228// return returnstring;
1229// }
1230
1231 // Temporary hack to allow teleporting to and from Vaak
1232 private static bool customXertificateValidation(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
1233 {
1234 //if (cert.Subject == "E=root@lindenlab.com, CN=*.vaak.lindenlab.com, O=\"Linden Lab, Inc.\", L=San Francisco, S=California, C=US")
1235 //{
1236 return true;
1237 //}
1238
1239 //return false;
1240 }
1241 }
1242
1243 public class KillAUser
1244 {
1245 private ScenePresence avToBeKilled = null;
1246 private OpenGridProtocolModule m_mod = null;
1247
1248 public KillAUser(ScenePresence avatar, OpenGridProtocolModule mod)
1249 {
1250 avToBeKilled = avatar;
1251 m_mod = mod;
1252 }
1253
1254 public void ShutdownNoLogout()
1255 {
1256 UUID avUUID = UUID.Zero;
1257
1258 if (avToBeKilled != null)
1259 {
1260 avUUID = avToBeKilled.UUID;
1261 avToBeKilled.MakeChildAgent();
1262
1263 avToBeKilled.ControllingClient.SendLogoutPacketWhenClosing = false;
1264
1265 int sleepMS = 30000;
1266 while (sleepMS > 0)
1267 {
1268 Watchdog.UpdateThread();
1269 Thread.Sleep(1000);
1270 sleepMS -= 1000;
1271 }
1272
1273 // test for child agent because they might have come back
1274 if (avToBeKilled.IsChildAgent)
1275 {
1276 m_mod.DeleteOGPState(avUUID);
1277 avToBeKilled.ControllingClient.Close();
1278 }
1279 }
1280
1281 Watchdog.RemoveThread();
1282 }
1283
1284 }
1285
1286 public class MonoCert : ICertificatePolicy
1287 {
1288 #region ICertificatePolicy Members
1289
1290 public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem)
1291 {
1292 return true;
1293 }
1294
1295 #endregion
1296 }
1297}