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