aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Asset_manager.cs
diff options
context:
space:
mode:
authorcw2007-01-31 22:09:20 +0000
committercw2007-01-31 22:09:20 +0000
commita82950672860eedeaa23da75421c74e094b5c0a4 (patch)
tree6901851f8e1de03d5eadfbe05e03563126b879a2 /Asset_manager.cs
downloadopensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.zip
opensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.tar.gz
opensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.tar.bz2
opensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.tar.xz
Making trunk; applying appropriate license to each file
Diffstat (limited to 'Asset_manager.cs')
-rw-r--r--Asset_manager.cs167
1 files changed, 167 insertions, 0 deletions
diff --git a/Asset_manager.cs b/Asset_manager.cs
new file mode 100644
index 0000000..194d28f
--- /dev/null
+++ b/Asset_manager.cs
@@ -0,0 +1,167 @@
1/*
2Copyright (c) 2007 Michael Wright
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 Second_server
38{
39 /// <summary>
40 /// Description of Asset_manager.
41 /// </summary>
42 public class Asset_manager
43 {
44 public Dictionary<libsecondlife.LLUUID,Asset_info> Assets;
45 public ArrayList requests=new ArrayList(); //should change to a generic
46 // public ArrayList uploads=new ArrayList();
47 private Server server;
48
49 public Asset_manager(Server serve)
50 {
51 server=serve;
52 Assets=new Dictionary<libsecondlife.LLUUID,Asset_info> ();
53 this.initialise();
54 }
55
56 public void add_request(User_Agent_info user, LLUUID asset_id, TransferRequestPacket tran_req)
57 {
58
59 if(!this.Assets.ContainsKey(asset_id))
60 {
61 //not found asset
62 return;
63 }
64 Asset_info info=this.Assets[asset_id];
65 System.Console.WriteLine("send asset : "+asset_id);
66 //for now as it will be only skin or shape request just send back the asset
67 TransferInfoPacket tran_i=new TransferInfoPacket();
68 tran_i.TransferInfo.ChannelType=2;
69 tran_i.TransferInfo.Status=0;
70 tran_i.TransferInfo.TargetType=0;
71 tran_i.TransferInfo.Params=tran_req.TransferInfo.Params;
72 tran_i.TransferInfo.Size=info.data.Length;
73 tran_i.TransferInfo.TransferID=tran_req.TransferInfo.TransferID;
74
75 server.SendPacket(tran_i,true,user);
76
77 TransferPacketPacket tran_p=new TransferPacketPacket();
78 tran_p.TransferData.Packet=0;
79 tran_p.TransferData.ChannelType=2;
80 tran_p.TransferData.TransferID=tran_req.TransferInfo.TransferID;
81 if(info.data.Length>1000) //but needs to be less than 2000 at the moment
82 {
83 byte[] chunk=new byte[1000];
84 Array.Copy(info.data,chunk,1000);
85 tran_p.TransferData.Data=chunk;
86 tran_p.TransferData.Status=0;
87 server.SendPacket(tran_p,true,user);
88
89 tran_p=new TransferPacketPacket();
90 tran_p.TransferData.Packet=1;
91 tran_p.TransferData.ChannelType=2;
92 tran_p.TransferData.TransferID=tran_req.TransferInfo.TransferID;
93 byte[] chunk1=new byte[(info.data.Length-1000)];
94 Array.Copy(info.data,1000,chunk1,0,chunk1.Length);
95 tran_p.TransferData.Data=chunk1;
96 tran_p.TransferData.Status=1;
97 server.SendPacket(tran_p,true,user);
98 }
99 else
100 {
101 tran_p.TransferData.Status=1; //last packet? so set to 1
102 tran_p.TransferData.Data=info.data;
103 server.SendPacket(tran_p,true,user);
104 }
105
106
107
108 }
109
110 private void initialise()
111 {
112 //for now read in our test image
113 Asset_info im=new Asset_info();
114 im.filename="base_shape.dat";
115 im.Full_ID=new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
116 this.load_asset(im);
117 this.Assets.Add(im.Full_ID,im);
118 }
119 private void load_asset(Asset_info info)
120 {
121 string data_path=System.Windows.Forms.Application.StartupPath + @"\assets\";
122 string filename=data_path+@info.filename;
123 FileInfo fInfo = new FileInfo(filename);
124
125 long numBytes = fInfo.Length;
126
127 FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
128 byte[] idata=new byte[numBytes];
129 BinaryReader br = new BinaryReader(fStream);
130 idata= br.ReadBytes((int)numBytes);
131 br.Close();
132 fStream.Close();
133 info.data=idata;
134 info.loaded=true;
135 }
136 }
137
138 public class Asset_request
139 {
140 public User_Agent_info req_user;
141 public LLUUID req_image;
142 public Asset_info asset_inf;
143 public long data_pointer=0;
144 public int num_packets=0;
145 public int packet_counter=0;
146
147 public Asset_request()
148 {
149
150 }
151 }
152 public class Asset_info
153 {
154 public byte[] data;
155 public LLUUID Full_ID;
156 public string name;
157 public string filename;
158 public bool loaded;
159 public ulong last_used; //need to add a tick/time counter and keep record
160 // of how often images are requested to unload unused ones.
161
162 public Asset_info()
163 {
164
165 }
166 }
167}