EstateTerrainXferHandler.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. private TerrainUploadComplete handlerTerrainUploadDone;
  44. public EstateTerrainXferHandler(IClientAPI pRemoteClient, string pClientFilename)
  45. {
  46. m_asset = new AssetBase(UUID.Zero, pClientFilename, type, pRemoteClient.AgentId.ToString());
  47. m_asset.Data = new byte[0];
  48. m_asset.Description = "empty";
  49. m_asset.Local = true;
  50. m_asset.Temporary = true;
  51. }
  52. public ulong XferID
  53. {
  54. get { return mXferID; }
  55. }
  56. public void RequestStartXfer(IClientAPI pRemoteClient)
  57. {
  58. mXferID = Util.GetNextXferID();
  59. pRemoteClient.SendXferRequest(mXferID, m_asset.Type, m_asset.FullID, 0, Utils.StringToBytes(m_asset.Name));
  60. }
  61. /// <summary>
  62. /// Process transfer data received from the client.
  63. /// </summary>
  64. /// <param name="xferID"></param>
  65. /// <param name="packetID"></param>
  66. /// <param name="data"></param>
  67. public void XferReceive(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data)
  68. {
  69. if (mXferID != xferID)
  70. return;
  71. lock (this)
  72. {
  73. if (m_asset.Data.Length > 1)
  74. {
  75. byte[] destinationArray = new byte[m_asset.Data.Length + data.Length];
  76. Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length);
  77. Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length);
  78. m_asset.Data = destinationArray;
  79. }
  80. else
  81. {
  82. byte[] buffer2 = new byte[data.Length - 4];
  83. Array.Copy(data, 4, buffer2, 0, data.Length - 4);
  84. m_asset.Data = buffer2;
  85. }
  86. remoteClient.SendConfirmXfer(xferID, packetID);
  87. if ((packetID & 0x80000000) != 0)
  88. {
  89. SendCompleteMessage(remoteClient);
  90. }
  91. }
  92. }
  93. public void SendCompleteMessage(IClientAPI remoteClient)
  94. {
  95. handlerTerrainUploadDone = TerrainUploadDone;
  96. if (handlerTerrainUploadDone != null)
  97. {
  98. handlerTerrainUploadDone(m_asset.Name, m_asset.Data, remoteClient);
  99. }
  100. }
  101. }
  102. }