aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/Asset_manager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Asset_manager.cs')
-rw-r--r--src/Asset_manager.cs231
1 files changed, 0 insertions, 231 deletions
diff --git a/src/Asset_manager.cs b/src/Asset_manager.cs
deleted file mode 100644
index 60f8945..0000000
--- a/src/Asset_manager.cs
+++ /dev/null
@@ -1,231 +0,0 @@
1/*
2Copyright (c) OpenSim project, http://osgrid.org/
3
4* Copyright (c) <year>, <copyright holder>
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28
29using System;
30using System.Collections.Generic;
31using libsecondlife;
32using System.Collections;
33using libsecondlife.Packets;
34using libsecondlife.AssetSystem;
35using System.IO;
36
37namespace OpenSim
38{
39 /// <summary>
40 /// Description of Asset_manager.
41 /// </summary>
42 public class AssetManager
43 {
44 public Dictionary<libsecondlife.LLUUID,AssetInfo> Assets;
45 public ArrayList requests=new ArrayList(); //should change to a generic
46 // public ArrayList uploads=new ArrayList();
47 private Server server;
48 public TextureManager TextureMan;
49 public InventoryManager InventoryManager;
50 private System.Text.Encoding enc = System.Text.Encoding.ASCII;
51
52 public AssetManager(Server serve)
53 {
54 server=serve;
55 Assets=new Dictionary<libsecondlife.LLUUID,AssetInfo> ();
56 this.initialise();
57 }
58
59 public void AddRequest(User_Agent_info user, LLUUID asset_id, TransferRequestPacket tran_req)
60 {
61 Console.WriteLine("Asset Request "+ asset_id);
62 if(!this.Assets.ContainsKey(asset_id))
63 {
64 //not found asset
65 return;
66 }
67 AssetInfo info=this.Assets[asset_id];
68 System.Console.WriteLine("send asset : "+asset_id);
69 //for now as it will be only skin or shape request just send back the asset
70 TransferInfoPacket Transfer=new TransferInfoPacket();
71 Transfer.TransferInfo.ChannelType=2;
72 Transfer.TransferInfo.Status=0;
73 Transfer.TransferInfo.TargetType=0;
74 Transfer.TransferInfo.Params=tran_req.TransferInfo.Params;
75 Transfer.TransferInfo.Size=info.data.Length;
76 Transfer.TransferInfo.TransferID=tran_req.TransferInfo.TransferID;
77
78 server.SendPacket(Transfer,true,user);
79
80 TransferPacketPacket tran_p=new TransferPacketPacket();
81 tran_p.TransferData.Packet=0;
82 tran_p.TransferData.ChannelType=2;
83 tran_p.TransferData.TransferID=tran_req.TransferInfo.TransferID;
84 if(info.data.Length>1000) //but needs to be less than 2000 at the moment
85 {
86 byte[] chunk=new byte[1000];
87 Array.Copy(info.data,chunk,1000);
88 tran_p.TransferData.Data=chunk;
89 tran_p.TransferData.Status=0;
90 server.SendPacket(tran_p,true,user);
91
92 tran_p=new TransferPacketPacket();
93 tran_p.TransferData.Packet=1;
94 tran_p.TransferData.ChannelType=2;
95 tran_p.TransferData.TransferID=tran_req.TransferInfo.TransferID;
96 byte[] chunk1=new byte[(info.data.Length-1000)];
97 Array.Copy(info.data,1000,chunk1,0,chunk1.Length);
98 tran_p.TransferData.Data=chunk1;
99 tran_p.TransferData.Status=1;
100 server.SendPacket(tran_p,true,user);
101 }
102 else
103 {
104 tran_p.TransferData.Status=1; //last packet? so set to 1
105 tran_p.TransferData.Data=info.data;
106 server.SendPacket(tran_p,true,user);
107 }
108
109 }
110 public void CreateNewBaseSet(ref AvatarData Avata,User_Agent_info UserInfo)
111 {
112 //LLUUID BaseFolder=new LLUUID("4f5f559e-77a0-a4b9-84f9-8c74c07f7cfc");//*/"4fb2dab6-a987-da66-05ee-96ca82bccbf1");
113 //LLUUID BaseFolder=new LLUUID("480e2d92-61f6-9f16-f4f5-0f77cfa4f8f9");
114 LLUUID BaseFolder=Avata.BaseFolder;
115 InventoryManager.CreateNewFolder(UserInfo,Avata.InventoryFolder);
116 InventoryManager.CreateNewFolder(UserInfo, BaseFolder);
117
118 AssetInfo Base=this.Assets[new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73")];
119 AssetInfo Shape=new AssetInfo();
120
121 Shape.filename="";
122 Shape.data=new byte[Base.data.Length];
123 Array.Copy(Base.data,Shape.data,Base.data.Length);
124 Shape.Full_ID=LLUUID.Random();
125 Shape.Name="Default Skin";
126 Shape.Description="Default";
127 Shape.InvType=18;
128
129 Shape.Type=libsecondlife.AssetSystem.ASSET_TYPE_WEARABLE_BODY;
130 byte[] Agentid=enc.GetBytes(UserInfo.AgentID.ToStringHyphenated());
131 Array.Copy(Agentid,0,Shape.data,294,Agentid.Length);
132 this.Assets.Add(Shape.Full_ID,Shape);
133 /*FileStream fStream = new FileStream("Assetshape.dat", FileMode.CreateNew);
134 BinaryWriter bw = new BinaryWriter(fStream);
135 bw.Write(Shape.data);
136 bw.Close();
137 fStream.Close();*/
138
139 Avata.Wearables[0].ItemID=InventoryManager.AddToInventory(UserInfo,BaseFolder,Shape);
140 Avata.Wearables[0].AssetID=Shape.Full_ID;
141 //Avata.RootFolder=BaseFolder;
142
143 //give test texture
144
145 TextureImage Texture=TextureMan.textures[new LLUUID("00000000-0000-0000-5005-000000000005")];
146 InventoryManager.AddToInventory(UserInfo,BaseFolder,Texture);
147
148 }
149
150 private void initialise()
151 {
152 //for now read in our test image
153 AssetInfo im=new AssetInfo();
154 im.filename="base_shape.dat";
155 im.Full_ID=new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
156 this.loadAsset(im);
157 this.Assets.Add(im.Full_ID,im);
158
159
160 im=new AssetInfo();
161 im.filename="base_skin.dat";
162 im.Full_ID=new LLUUID("e0ee49b5a4184df8d3c9a65361fe7f49");
163 this.loadAsset(im);
164 this.Assets.Add(im.Full_ID,im);
165 }
166 private void loadAsset(AssetInfo info)
167 {
168 //should request Asset from storage manager
169 //but for now read from file
170
171 string data_path = System.AppDomain.CurrentDomain.BaseDirectory + @"\assets\";
172 string filename=data_path+@info.filename;
173 FileInfo fInfo = new FileInfo(filename);
174
175 long numBytes = fInfo.Length;
176
177 FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
178 byte[] idata=new byte[numBytes];
179 BinaryReader br = new BinaryReader(fStream);
180 idata= br.ReadBytes((int)numBytes);
181 br.Close();
182 fStream.Close();
183 info.data=idata;
184 info.loaded=true;
185 }
186 }
187
188 public class AssetRequest
189 {
190 public User_Agent_info RequestUser;
191 public LLUUID RequestImage;
192 public AssetInfo asset_inf;
193 public long data_pointer=0;
194 public int num_packets=0;
195 public int packet_counter=0;
196
197 public AssetRequest()
198 {
199
200 }
201 }
202 public class AssetInfo:AssetBase
203 {
204 //public byte[] data;
205 //public LLUUID Full_ID;
206 public string filename;
207 public bool loaded;
208 public ulong last_used; //need to add a tick/time counter and keep record
209 // of how often images are requested to unload unused ones.
210
211 public AssetInfo()
212 {
213
214 }
215 }
216
217 public class AssetBase
218 {
219 public byte[] data;
220 public LLUUID Full_ID;
221 public sbyte Type;
222 public sbyte InvType;
223 public string Name;
224 public string Description;
225
226 public AssetBase()
227 {
228
229 }
230 }
231}