EstateTerrainXferHandler.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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();
  47. m_asset.FullID = UUID.Zero;
  48. m_asset.Type = type;
  49. m_asset.Data = new byte[0];
  50. m_asset.Name = pClientFilename;
  51. m_asset.Description = "empty";
  52. m_asset.Local = true;
  53. m_asset.Temporary = true;
  54. }
  55. public ulong XferID
  56. {
  57. get { return mXferID; }
  58. }
  59. public void RequestStartXfer(IClientAPI pRemoteClient)
  60. {
  61. mXferID = Util.GetNextXferID();
  62. pRemoteClient.SendXferRequest(mXferID, m_asset.Type, m_asset.FullID, 0, Utils.StringToBytes(m_asset.Name));
  63. }
  64. /// <summary>
  65. /// Process transfer data received from the client.
  66. /// </summary>
  67. /// <param name="xferID"></param>
  68. /// <param name="packetID"></param>
  69. /// <param name="data"></param>
  70. public void XferReceive(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data)
  71. {
  72. if (mXferID == xferID)
  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. handlerTerrainUploadDone = TerrainUploadDone;
  97. if (handlerTerrainUploadDone != null)
  98. {
  99. handlerTerrainUploadDone(m_asset.Name, m_asset.Data, remoteClient);
  100. }
  101. }
  102. }
  103. }