Index: OpenSim/Region/Environment/Modules/World/Estate/EstateManagementModule.cs =================================================================== --- OpenSim/Region/Environment/Modules/World/Estate/EstateManagementModule.cs (revision 8245) +++ OpenSim/Region/Environment/Modules/World/Estate/EstateManagementModule.cs (working copy) @@ -34,6 +34,7 @@ using OpenSim.Framework; using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Scenes; +using System.IO; namespace OpenSim.Region.Environment.Modules.World.Estate { @@ -458,6 +459,17 @@ TerrainUploader = null; } remoteClient.SendAlertMessage("Terrain Upload Complete. Loading...."); + + //now decide what type of file it was + char[] dot = new char[] { '.' }; + + bool isOar = false; + string [] parts = filename.Split(dot); + if (parts.Length > 2) + { + isOar = true; + } + OpenSim.Region.Environment.Modules.World.Terrain.ITerrainModule terr = m_scene.RequestModuleInterface(); if (terr != null) @@ -497,16 +509,32 @@ - - try + if (isOar == false) { - terr.LoadFromFile(Util.dataDir() + "/terrain.raw"); - remoteClient.SendAlertMessage("Your terrain was loaded. Give it a minute or two to apply"); + try + { + terr.LoadFromFile(Util.dataDir() + "/terrain.raw"); + remoteClient.SendAlertMessage("Your terrain was loaded. Give it a minute or two to apply"); + } + catch (Exception e) + { + m_log.ErrorFormat("[TERRAIN]: Error loading a terrain file uploaded via the estate tools. It gave us the following error: {0}", e.ToString()); + remoteClient.SendAlertMessage("There was a general error loading your terrain. Please fix the terrain file and try again"); + } } - catch (Exception e) + else { - m_log.ErrorFormat("[TERRAIN]: Error loading a terrain file uploaded via the estate tools. It gave us the following error: {0}", e.ToString()); - remoteClient.SendAlertMessage("There was a general error loading your terrain. Please fix the terrain file and try again"); + try + { + IRegionArchiverModule archiver = m_scene.RequestModuleInterface(); + + archiver.DearchiveRegion(Util.dataDir() + "/terrain.raw"); + } + catch (Exception e) + { + m_log.ErrorFormat("[ESTATE MANAGEMENT]: Error loading an oarfile uploaded via the estate tools. It gave us the following error: {0}", e.ToString()); + remoteClient.SendAlertMessage("There was a general error loading your OAR File. Please fix the OAR file file and try again"); + } } } @@ -531,6 +559,7 @@ remote_client.OnXferReceive += TerrainUploader.XferReceive; remote_client.OnAbortXfer += AbortTerrainXferHandler; TerrainUploader.TerrainUploadDone += HandleTerrainApplication; + } TerrainUploader.RequestStartXfer(remote_client); @@ -541,8 +570,43 @@ } } + + + private IClientAPI currClient; + private string currFilename; + + private void OarSaved(string message) + { + m_scene.EventManager.OnOarFileSaved -= OarSaved; + + System.IO.FileStream input = new System.IO.FileStream(Util.dataDir() + "/terrain.raw", System.IO.FileMode.Open); + byte[] bdata = new byte[input.Length]; + input.Read(bdata, 0, (int)input.Length); + currClient.SendAlertMessage("Terrain file written, starting download..."); + m_scene.XferManager.AddNewFile("terrain.raw", bdata); + // Tell client about it + m_log.Warn("[CLIENT]: Sending Terrain to " + currClient.Name); + currClient.SendInitiateDownload("terrain.raw", currFilename); + } + + private void handleTerrainRequest(IClientAPI remote_client, string clientFileName) { + + //now decide what type of file it was + char[] dot = new char[] { '.' }; + + bool isOar = false; + string[] parts = clientFileName.Split(dot); + if (parts.Length > 2) + { + isOar = true; + m_scene.EventManager.OnOarFileSaved += OarSaved; + currClient = remote_client; + currFilename = clientFileName; + } + + // Save terrain here OpenSim.Region.Environment.Modules.World.Terrain.ITerrainModule terr = m_scene.RequestModuleInterface(); @@ -553,16 +617,25 @@ { System.IO.File.Delete(Util.dataDir() + "/terrain.raw"); } - terr.SaveToFile(Util.dataDir() + "/terrain.raw"); + if (isOar == false) + { + terr.SaveToFile(Util.dataDir() + "/terrain.raw"); - System.IO.FileStream input = new System.IO.FileStream(Util.dataDir() + "/terrain.raw", System.IO.FileMode.Open); - byte[] bdata = new byte[input.Length]; - input.Read(bdata, 0, (int)input.Length); - remote_client.SendAlertMessage("Terrain file written, starting download..."); - m_scene.XferManager.AddNewFile("terrain.raw", bdata); - // Tell client about it - m_log.Warn("[CLIENT]: Sending Terrain to " + remote_client.Name); - remote_client.SendInitiateDownload("terrain.raw", clientFileName); + System.IO.FileStream input = new System.IO.FileStream(Util.dataDir() + "/terrain.raw", System.IO.FileMode.Open); + byte[] bdata = new byte[input.Length]; + input.Read(bdata, 0, (int)input.Length); + remote_client.SendAlertMessage("Terrain file written, starting download..."); + m_scene.XferManager.AddNewFile("terrain.raw", bdata); + // Tell client about it + m_log.Warn("[CLIENT]: Sending Terrain to " + remote_client.Name); + remote_client.SendInitiateDownload("terrain.raw", clientFileName); + } + else + { + IRegionArchiverModule archiver = m_scene.RequestModuleInterface(); + archiver.ArchiveRegion(Util.dataDir() + "/terrain.raw"); + } + } }