diff options
author | Teravus Ovares | 2008-11-14 14:42:00 +0000 |
---|---|---|
committer | Teravus Ovares | 2008-11-14 14:42:00 +0000 |
commit | 3e4b094921dddfe10f6ee5f73eb1b917381c2c30 (patch) | |
tree | 7cdce613258028725b555e43ad0125081a2fc305 /OpenSim/Region/Environment/Modules/World/Estate/EstateTerrainXferHandler.cs | |
parent | reverting #7295, as it still fails a test case (as pointed out very (diff) | |
download | opensim-SC-3e4b094921dddfe10f6ee5f73eb1b917381c2c30.zip opensim-SC-3e4b094921dddfe10f6ee5f73eb1b917381c2c30.tar.gz opensim-SC-3e4b094921dddfe10f6ee5f73eb1b917381c2c30.tar.bz2 opensim-SC-3e4b094921dddfe10f6ee5f73eb1b917381c2c30.tar.xz |
* Implements terrain raw upload. You can now upload your .raw terrain files using the Estate Tools.
* Could this be extended in the future to support .oar uploads too? Only time will tell!
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Estate/EstateTerrainXferHandler.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Estate/EstateTerrainXferHandler.cs | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Estate/EstateTerrainXferHandler.cs b/OpenSim/Region/Environment/Modules/World/Estate/EstateTerrainXferHandler.cs new file mode 100644 index 0000000..3ee633e --- /dev/null +++ b/OpenSim/Region/Environment/Modules/World/Estate/EstateTerrainXferHandler.cs | |||
@@ -0,0 +1,129 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Reflection; | ||
31 | using log4net; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Communications.Cache; | ||
35 | using OpenSim.Region.Environment.Scenes; | ||
36 | |||
37 | |||
38 | namespace OpenSim.Region.Environment.Modules.World.Estate | ||
39 | { | ||
40 | |||
41 | public class EstateTerrainXferHandler | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | private AssetBase m_asset; | ||
46 | |||
47 | public delegate void TerrainUploadComplete(string name, byte[] filedata, IClientAPI remoteClient); | ||
48 | |||
49 | public event TerrainUploadComplete TerrainUploadDone; | ||
50 | |||
51 | private string m_description = String.Empty; | ||
52 | private string m_name = String.Empty; | ||
53 | private UUID TransactionID = UUID.Zero; | ||
54 | private sbyte type = 0; | ||
55 | |||
56 | public ulong mXferID; | ||
57 | private TerrainUploadComplete handlerTerrainUploadDone; | ||
58 | |||
59 | |||
60 | |||
61 | public EstateTerrainXferHandler(IClientAPI pRemoteClient, string pClientFilename) | ||
62 | { | ||
63 | |||
64 | m_asset = new AssetBase(); | ||
65 | m_asset.FullID = UUID.Zero; | ||
66 | m_asset.Type = type; | ||
67 | m_asset.Data = new byte[0]; | ||
68 | m_asset.Name = pClientFilename; | ||
69 | m_asset.Description = "empty"; | ||
70 | m_asset.Local = true; | ||
71 | m_asset.Temporary = true; | ||
72 | |||
73 | } | ||
74 | |||
75 | public ulong XferID | ||
76 | { | ||
77 | get { return mXferID; } | ||
78 | } | ||
79 | |||
80 | public void RequestStartXfer(IClientAPI pRemoteClient) | ||
81 | { | ||
82 | mXferID = Util.GetNextXferID(); | ||
83 | pRemoteClient.SendXferRequest(mXferID, m_asset.Type, m_asset.FullID, 0, Utils.StringToBytes(m_asset.Name)); | ||
84 | } | ||
85 | |||
86 | /// <summary> | ||
87 | /// Process transfer data received from the client. | ||
88 | /// </summary> | ||
89 | /// <param name="xferID"></param> | ||
90 | /// <param name="packetID"></param> | ||
91 | /// <param name="data"></param> | ||
92 | public void XferReceive(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) | ||
93 | { | ||
94 | if (mXferID == xferID) | ||
95 | { | ||
96 | if (m_asset.Data.Length > 1) | ||
97 | { | ||
98 | byte[] destinationArray = new byte[m_asset.Data.Length + data.Length]; | ||
99 | Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length); | ||
100 | Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length); | ||
101 | m_asset.Data = destinationArray; | ||
102 | } | ||
103 | else | ||
104 | { | ||
105 | byte[] buffer2 = new byte[data.Length - 4]; | ||
106 | Array.Copy(data, 4, buffer2, 0, data.Length - 4); | ||
107 | m_asset.Data = buffer2; | ||
108 | } | ||
109 | |||
110 | remoteClient.SendConfirmXfer(xferID, packetID); | ||
111 | |||
112 | if ((packetID & 0x80000000) != 0) | ||
113 | { | ||
114 | SendCompleteMessage(remoteClient); | ||
115 | |||
116 | } | ||
117 | } | ||
118 | } | ||
119 | |||
120 | public void SendCompleteMessage(IClientAPI remoteClient) | ||
121 | { | ||
122 | handlerTerrainUploadDone = TerrainUploadDone; | ||
123 | if (handlerTerrainUploadDone != null) | ||
124 | { | ||
125 | handlerTerrainUploadDone(m_asset.Name,m_asset.Data, remoteClient); | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | } | ||