EstateTerrainXferHandler.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. using System;
  28. using OpenMetaverse;
  29. using OpenSim.Framework;
  30. namespace OpenSim.Region.CoreModules.World.Estate
  31. {
  32. public class EstateTerrainXferHandler
  33. {
  34. //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  35. private AssetBase m_asset;
  36. public delegate void TerrainUploadComplete(string name, byte[] filedata, IClientAPI remoteClient);
  37. public event TerrainUploadComplete TerrainUploadDone;
  38. //private string m_description = String.Empty;
  39. //private string m_name = String.Empty;
  40. //private UUID TransactionID = UUID.Zero;
  41. private sbyte type = 0;
  42. public ulong mXferID;
  43. public EstateTerrainXferHandler(IClientAPI pRemoteClient, string pClientFilename)
  44. {
  45. m_asset = new AssetBase(UUID.Zero, pClientFilename, type, pRemoteClient.AgentId.ToString())
  46. {
  47. Data = new byte[0],
  48. Description = "empty",
  49. Local = true,
  50. Temporary = true
  51. };
  52. }
  53. public ulong XferID
  54. {
  55. get { return mXferID; }
  56. }
  57. public void RequestStartXfer(IClientAPI pRemoteClient)
  58. {
  59. mXferID = Util.GetNextXferID();
  60. pRemoteClient.SendXferRequest(mXferID, m_asset.Type, m_asset.FullID, 0, Utils.StringToBytes(m_asset.Name));
  61. }
  62. /// <summary>
  63. /// Process transfer data received from the client.
  64. /// </summary>
  65. /// <param name="xferID"></param>
  66. /// <param name="packetID"></param>
  67. /// <param name="data"></param>
  68. public void XferReceive(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data)
  69. {
  70. if (mXferID != xferID)
  71. return;
  72. lock (this)
  73. {
  74. if (m_asset.Data.Length > 1)
  75. {
  76. byte[] destinationArray = new byte[m_asset.Data.Length + data.Length];
  77. Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length);
  78. Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length);
  79. m_asset.Data = destinationArray;
  80. }
  81. else
  82. {
  83. byte[] buffer2 = new byte[data.Length - 4];
  84. Array.Copy(data, 4, buffer2, 0, data.Length - 4);
  85. m_asset.Data = buffer2;
  86. }
  87. remoteClient.SendConfirmXfer(xferID, packetID);
  88. if ((packetID & 0x80000000) != 0)
  89. {
  90. SendCompleteMessage(remoteClient);
  91. }
  92. }
  93. }
  94. public void SendCompleteMessage(IClientAPI remoteClient)
  95. {
  96. TerrainUploadDone?.Invoke(m_asset.Name, m_asset.Data, remoteClient);
  97. }
  98. }
  99. }