1
0

EstateTerrainXferHandler.cs 4.8 KB

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