/// <summary> /// </summary> /// <param name = "value">uuid[;endpoint[;name]]</param> /// <param name = "uuid"></param> /// <param name = "url"></param> /// <param name = "firstname"></param> /// <param name = "lastname"></param> public static bool ParseUniversalUserIdentifier(string value, out UUID uuid, out string url, out string firstname, out string lastname, out string secret) { uuid = UUID.Zero; url = string.Empty; firstname = "Unknown"; lastname = "User"; secret = string.Empty; string[] parts = value.Split(';'); if (parts.Length >= 1) { if (!UUID.TryParse(parts[0], out uuid)) { return(false); } } if (parts.Length >= 2) { url = parts[1]; } if (parts.Length >= 3) { string[] name = parts[2].Split(); if (name.Length == 2) { firstname = name[0]; lastname = name[1]; } } if (parts.Length >= 4) { secret = parts[3]; } if (Registry != null && url != "") { IUserFinder uf = Registry.RequestModuleInterface <IUserFinder>(); if (uf != null) { uf.AddUser(uuid, firstname, lastname, url); //Add to the cache } } return(url != ""); }
private void DearchiveRegion0DotStar() { int successfulAssetRestores = 0; int failedAssetRestores = 0; string filePath = "NONE"; DateTime start = DateTime.Now; TarArchiveReader archive = new TarArchiveReader(m_loadStream); if (!m_skipAssets) { m_threadpool = new Aurora.Framework.AuroraThreadPool(new Aurora.Framework.AuroraThreadPoolStartInfo() { Threads = 1, priority = System.Threading.ThreadPriority.BelowNormal }); } IBackupModule backup = m_scene.RequestModuleInterface <IBackupModule>(); if (!m_merge) { DateTime before = DateTime.Now; MainConsole.Instance.Info("[ARCHIVER]: Clearing all existing scene objects"); if (backup != null) { backup.DeleteAllSceneObjects(); } MainConsole.Instance.Info("[ARCHIVER]: Cleared all existing scene objects in " + (DateTime.Now - before).Minutes + ":" + (DateTime.Now - before).Seconds); } IScriptModule[] modules = m_scene.RequestModuleInterfaces <IScriptModule>(); //Disable the script engine so that it doesn't load in the background and kill OAR loading foreach (IScriptModule module in modules) { module.Disabled = true; } //Disable backup for now as well if (backup != null) { backup.LoadingPrims = true; } IRegionSerialiserModule serialiser = m_scene.RequestModuleInterface <IRegionSerialiserModule>(); int sceneObjectsLoadedCount = 0; //We save the groups so that we can back them up later List <SceneObjectGroup> groupsToBackup = new List <SceneObjectGroup>(); List <LandData> landData = new List <LandData>(); IUserFinder UserManager = m_scene.RequestModuleInterface <IUserFinder>(); // must save off some stuff until after assets have been saved and recieved new uuids // keeping these collection local because I am sure they will get large and garbage collection is better that way List <byte[]> seneObjectGroups = new List <byte[]>(); Dictionary <UUID, UUID> assetBinaryChangeRecord = new Dictionary <UUID, UUID>(); Queue <UUID> assets2Save = new Queue <UUID>(); try { byte[] data; TarArchiveReader.TarEntryType entryType; while ((data = archive.ReadEntry(out filePath, out entryType)) != null) { if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType) { continue; } if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH)) { seneObjectGroups.Add(data); } else if (!m_skipAssets && filePath.StartsWith(ArchiveConstants.ASSETS_PATH)) { AssetBase asset; if (LoadAsset(filePath, data, out asset)) { successfulAssetRestores++; if (m_useAsync) { lock (AssetsToAdd) AssetsToAdd.Add(asset); } else { if (asset.IsBinaryAsset) { UUID aid = asset.ID; asset.ID = m_scene.AssetService.Store(asset); if (asset.ID != aid && asset.ID != UUID.Zero) { assetBinaryChangeRecord.Add(aid, asset.ID); } } else { if (!assetNonBinaryCollection.ContainsKey(asset.ID)) { assetNonBinaryCollection.Add(asset.ID, asset); // I need something I can safely loop through assets2Save.Enqueue(asset.ID); } } } } else { failedAssetRestores++; } if ((successfulAssetRestores + failedAssetRestores) % 250 == 0) { MainConsole.Instance.Info("[ARCHIVER]: Loaded " + successfulAssetRestores + " assets and failed to load " + failedAssetRestores + " assets..."); } } else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH)) { LoadTerrain(filePath, data); } else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH)) { LoadRegionSettings(filePath, data); } else if (filePath.StartsWith(ArchiveConstants.LANDDATA_PATH)) { LandData parcel = LandDataSerializer.Deserialize(m_utf8Encoding.GetString(data)); parcel.OwnerID = ResolveUserUuid(parcel.OwnerID, UUID.Zero, "", Vector3.Zero, null); landData.Add(parcel); } else if (filePath == ArchiveConstants.CONTROL_FILE_PATH) { LoadControlFile(data); } } // Save Assets int savingAssetsCount = 0; while (assets2Save.Count > 0) { try { UUID assetid = assets2Save.Dequeue(); SaveNonBinaryAssets(assetid, assetNonBinaryCollection[assetid], assetBinaryChangeRecord); savingAssetsCount++; if ((savingAssetsCount) % 250 == 0) { MainConsole.Instance.Info("[ARCHIVER]: Saving " + savingAssetsCount + " assets..."); } } catch (Exception ex) { MainConsole.Instance.Info("[ARCHIVER]: Exception in saving an asset: " + ex.ToString()); } } foreach (byte[] data2 in seneObjectGroups) { byte[] data3 = data2; string stringData = Utils.BytesToString(data3); MatchCollection mc = Regex.Matches(stringData, sPattern); bool didChange = false; if (mc.Count >= 1) { foreach (Match match in mc) { UUID thematch = new UUID(match.Value); UUID newvalue = thematch; if (assetNonBinaryCollection.ContainsKey(thematch)) { newvalue = assetNonBinaryCollection[thematch].ID; } else if (assetBinaryChangeRecord.ContainsKey(thematch)) { newvalue = assetBinaryChangeRecord[thematch]; } if (thematch == newvalue) { continue; } stringData = stringData.Replace(thematch.ToString().Trim(), newvalue.ToString().Trim()); didChange = true; } } if (didChange) { data3 = Utils.StringToBytes(stringData); } SceneObjectGroup sceneObject = (SceneObjectGroup)serialiser.DeserializeGroupFromXml2(data3, m_scene); if (sceneObject == null) { //! big error! MainConsole.Instance.Error("Error reading SOP XML (Please mantis this!): " + m_asciiEncoding.GetString(data3)); continue; } foreach (SceneObjectPart part in sceneObject.ChildrenList) { if (string.IsNullOrEmpty(part.CreatorData)) { part.CreatorID = ResolveUserUuid(part.CreatorID, part.CreatorID, part.CreatorData, part.AbsolutePosition, landData); } if (UserManager != null) { UserManager.AddUser(part.CreatorID, part.CreatorData); } part.OwnerID = ResolveUserUuid(part.OwnerID, part.CreatorID, part.CreatorData, part.AbsolutePosition, landData); part.LastOwnerID = ResolveUserUuid(part.LastOwnerID, part.CreatorID, part.CreatorData, part.AbsolutePosition, landData); // And zap any troublesome sit target information part.SitTargetOrientation = new Quaternion(0, 0, 0, 1); part.SitTargetPosition = new Vector3(0, 0, 0); // Fix ownership/creator of inventory items // Not doing so results in inventory items // being no copy/no mod for everyone lock (part.TaskInventory) { TaskInventoryDictionary inv = part.TaskInventory; foreach (KeyValuePair <UUID, TaskInventoryItem> kvp in inv) { kvp.Value.OwnerID = ResolveUserUuid(kvp.Value.OwnerID, kvp.Value.CreatorID, kvp.Value.CreatorData, part.AbsolutePosition, landData); if (string.IsNullOrEmpty(kvp.Value.CreatorData)) { kvp.Value.CreatorID = ResolveUserUuid(kvp.Value.CreatorID, kvp.Value.CreatorID, kvp.Value.CreatorData, part.AbsolutePosition, landData); } if (UserManager != null) { UserManager.AddUser(kvp.Value.CreatorID, kvp.Value.CreatorData); } } } } //Add the offsets of the region Vector3 newPos = new Vector3(sceneObject.AbsolutePosition.X + m_offsetX, sceneObject.AbsolutePosition.Y + m_offsetY, sceneObject.AbsolutePosition.Z + m_offsetZ); if (m_flipX) { newPos.X = m_scene.RegionInfo.RegionSizeX - newPos.X; } if (m_flipY) { newPos.Y = m_scene.RegionInfo.RegionSizeY - newPos.Y; } sceneObject.SetAbsolutePosition(false, newPos); if (m_scene.SceneGraph.AddPrimToScene(sceneObject)) { groupsToBackup.Add(sceneObject); sceneObject.ScheduleGroupUpdate(PrimUpdateFlags.ForcedFullUpdate); sceneObject.CreateScriptInstances(0, false, StateSource.RegionStart, UUID.Zero, true); } sceneObjectsLoadedCount++; if (sceneObjectsLoadedCount % 250 == 0) { MainConsole.Instance.Info("[ARCHIVER]: Loaded " + sceneObjectsLoadedCount + " objects..."); } } assetNonBinaryCollection.Clear(); assetBinaryChangeRecord.Clear(); seneObjectGroups.Clear(); } catch (Exception e) { MainConsole.Instance.ErrorFormat( "[ARCHIVER]: Aborting load with error in archive file {0}. {1}", filePath, e); m_errorMessage += e.ToString(); m_scene.EventManager.TriggerOarFileLoaded(UUID.Zero.Guid, m_errorMessage); return; } finally { archive.Close(); m_loadStream.Close(); m_loadStream.Dispose(); //Reeanble now that we are done foreach (IScriptModule module in modules) { module.Disabled = false; } //Reset backup too if (backup != null) { backup.LoadingPrims = false; } } //Now back up the prims foreach (SceneObjectGroup grp in groupsToBackup) { //Backup! grp.HasGroupChanged = true; } if (!m_skipAssets && m_useAsync && !AssetSaverIsRunning) { m_threadpool.QueueEvent(SaveAssets, 0); } if (!m_skipAssets) { MainConsole.Instance.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores); if (failedAssetRestores > 0) { MainConsole.Instance.ErrorFormat("[ARCHIVER]: Failed to load {0} assets", failedAssetRestores); m_errorMessage += String.Format("Failed to load {0} assets", failedAssetRestores); } } // Try to retain the original creator/owner/lastowner if their uuid is present on this grid // otherwise, use the master avatar uuid instead // Reload serialized parcels MainConsole.Instance.InfoFormat("[ARCHIVER]: Loading {0} parcels. Please wait.", landData.Count); IParcelManagementModule parcelManagementModule = m_scene.RequestModuleInterface <IParcelManagementModule>(); if (!m_merge && parcelManagementModule != null) { parcelManagementModule.ClearAllParcels(); } if (landData.Count > 0) { m_scene.EventManager.TriggerIncomingLandDataFromStorage(landData, new Vector2(m_offsetX, m_offsetY)); //Update the database as well! if (parcelManagementModule != null) { foreach (LandData parcel in landData) { parcelManagementModule.UpdateLandObject(parcelManagementModule.GetLandObject(parcel.LocalID)); } } } else if (parcelManagementModule != null) { parcelManagementModule.ResetSimLandObjects(); } MainConsole.Instance.InfoFormat("[ARCHIVER]: Restored {0} parcels.", landData.Count); //Clean it out landData.Clear(); MainConsole.Instance.InfoFormat("[ARCHIVER]: Successfully loaded archive in " + (DateTime.Now - start).Minutes + ":" + (DateTime.Now - start).Seconds); m_validUserUuids.Clear(); m_scene.EventManager.TriggerOarFileLoaded(UUID.Zero.Guid, m_errorMessage); }
public bool LoginAgent(AgentCircuitData aCircuit, GridRegion destination, out string reason) { reason = string.Empty; string authURL = string.Empty; if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) { authURL = aCircuit.ServiceURLs["HomeURI"].ToString(); } MainConsole.Instance.InfoFormat("[GATEKEEPER SERVICE]: Login request for {0} {1} @ {2}", authURL, aCircuit.AgentID, destination.RegionName); // // Authenticate the user // if (!Authenticate(aCircuit)) { reason = "Unable to verify identity"; MainConsole.Instance.InfoFormat("[GATEKEEPER SERVICE]: Unable to verify identity of agent {0}. Refusing service.", aCircuit.AgentID); return(false); } MainConsole.Instance.DebugFormat("[GATEKEEPER SERVICE]: Identity verified for {0} @ {1}", aCircuit.AgentID, authURL); // // Check for impersonations // UserAccount account = null; if (m_UserAccountService != null) { // Check to see if we have a local user with that UUID account = m_UserAccountService.GetUserAccount(null, aCircuit.AgentID); if (account != null && m_userFinder.IsLocalGridUser(account.PrincipalID)) { // Make sure this is the user coming home, and not a foreign user with same UUID as a local user if (m_UserAgentService != null) { if (!m_UserAgentService.AgentIsComingHome(aCircuit.SessionID, m_ExternalName)) { // Can't do, sorry reason = "Unauthorized"; MainConsole.Instance.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} has same ID as local user. Refusing service.", aCircuit.AgentID); return(false); } } } } MainConsole.Instance.InfoFormat("[GATEKEEPER SERVICE]: User is ok"); // May want to authorize //bool isFirstLogin = false; // // Login the presence, if it's not there yet (by the login service) // UserInfo presence = m_PresenceService.GetUserInfo(aCircuit.AgentID.ToString()); if (m_userFinder.IsLocalGridUser(aCircuit.AgentID) && presence != null && presence.IsOnline) // it has been placed there by the login service { // isFirstLogin = true; } else { IUserAgentService userAgentService = new UserAgentServiceConnector(aCircuit.ServiceURLs["HomeURI"].ToString()); Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY; GridRegion finalDestination = userAgentService.GetHomeRegion(aCircuit.AgentID, out position, out lookAt); if (finalDestination == null) { reason = "You do not have a home position set."; return(false); } m_PresenceService.SetHomePosition(aCircuit.AgentID.ToString(), finalDestination.RegionID, position, lookAt); m_PresenceService.SetLoggedIn(aCircuit.AgentID.ToString(), true, true, destination.RegionID); } MainConsole.Instance.DebugFormat("[GATEKEEPER SERVICE]: Login presence ok"); // // Get the region // destination = m_GridService.GetRegionByUUID(null, destination.RegionID); if (destination == null) { reason = "Destination region not found"; return(false); } // // Adjust the visible name // if (account != null) { aCircuit.firstname = account.FirstName; aCircuit.lastname = account.LastName; } if (account == null && !aCircuit.lastname.StartsWith("@")) { aCircuit.firstname = aCircuit.firstname + "." + aCircuit.lastname; try { Uri uri = new Uri(aCircuit.ServiceURLs["HomeURI"].ToString()); aCircuit.lastname = "@" + uri.Host; // + ":" + uri.Port; } catch { MainConsole.Instance.WarnFormat("[GATEKEEPER SERVICE]: Malformed HomeURI (this should never happen): {0}", aCircuit.ServiceURLs["HomeURI"]); aCircuit.lastname = "@" + aCircuit.ServiceURLs["HomeURI"].ToString(); } m_userFinder.AddUser(aCircuit.AgentID, aCircuit.firstname, aCircuit.lastname, aCircuit.ServiceURLs); m_UserAccountService.CacheAccount(new UserAccount(UUID.Zero, aCircuit.AgentID, aCircuit.firstname + aCircuit.lastname, "") { UserFlags = 1024 }); } retry: // // Finally launch the agent at the destination // TeleportFlags loginFlag = /*isFirstLogin ? */ TeleportFlags.ViaLogin /* : TeleportFlags.ViaHGLogin*/; IRegionClientCapsService regionClientCaps = null; if (m_CapsService != null) { //Remove any previous users string ServerCapsBase = Aurora.Framework.Capabilities.CapsUtil.GetRandomCapsObjectPath(); m_CapsService.CreateCAPS(aCircuit.AgentID, Aurora.Framework.Capabilities.CapsUtil.GetCapsSeedPath(ServerCapsBase), destination.RegionHandle, true, aCircuit, 0); regionClientCaps = m_CapsService.GetClientCapsService(aCircuit.AgentID).GetCapsService(destination.RegionHandle); if (aCircuit.ServiceURLs == null) { aCircuit.ServiceURLs = new Dictionary <string, object>(); } aCircuit.ServiceURLs["IncomingCAPSHandler"] = regionClientCaps.CapsUrl; } aCircuit.child = false;//FIX THIS, OPENSIM ALWAYS SENDS CHILD! int requestedUDPPort = 0; bool success = m_SimulationService.CreateAgent(destination, aCircuit, (uint)loginFlag, null, out requestedUDPPort, out reason); if (success) { if (regionClientCaps != null) { if (requestedUDPPort == 0) { requestedUDPPort = destination.ExternalEndPoint.Port; } IPAddress ipAddress = destination.ExternalEndPoint.Address; aCircuit.RegionUDPPort = requestedUDPPort; regionClientCaps.LoopbackRegionIP = ipAddress; regionClientCaps.CircuitData.RegionUDPPort = requestedUDPPort; OSDMap responseMap = (OSDMap)OSDParser.DeserializeJson(reason); OSDMap SimSeedCaps = (OSDMap)responseMap["CapsUrls"]; regionClientCaps.AddCAPS(SimSeedCaps); } } else { if (m_CapsService != null) { m_CapsService.RemoveCAPS(aCircuit.AgentID); } m_GridService.SetRegionUnsafe(destination.RegionID); if (!m_foundDefaultRegion) { m_DefaultGatewayRegion = FindDefaultRegion(); } if (destination != m_DefaultGatewayRegion) { destination = m_DefaultGatewayRegion; goto retry; } else { m_DefaultGatewayRegion = FindDefaultRegion(); if (m_DefaultGatewayRegion == destination) { return(false);//It failed to find a new one } destination = m_DefaultGatewayRegion; goto retry;//It found a new default region } } return(success); }