clockwerk-opensim-stable – Blame information for rev 1

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