diff options
author | lbsa71 | 2007-10-10 18:24:13 +0000 |
---|---|---|
committer | lbsa71 | 2007-10-10 18:24:13 +0000 |
commit | a40e7100a232827cffb813bbbbe9374324ad3448 (patch) | |
tree | 7f16f392d653f155ca90d5477c842db9c881f3ed /OpenSim/Region/Environment/Modules/XferModule.cs | |
parent | Added unit tests, based on nunit for the IInventoryData (diff) | |
download | opensim-SC_OLD-a40e7100a232827cffb813bbbbe9374324ad3448.zip opensim-SC_OLD-a40e7100a232827cffb813bbbbe9374324ad3448.tar.gz opensim-SC_OLD-a40e7100a232827cffb813bbbbe9374324ad3448.tar.bz2 opensim-SC_OLD-a40e7100a232827cffb813bbbbe9374324ad3448.tar.xz |
* Gave ModuleLoader some good lovin'
* Introduced ModuleLoader.PickupModules that currently picks up IRegionModule:s from /bin
* Made LogBase thread-safe (or at least not thread-ignorant)
* Ignored some genned files
Diffstat (limited to 'OpenSim/Region/Environment/Modules/XferModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/XferModule.cs | 344 |
1 files changed, 172 insertions, 172 deletions
diff --git a/OpenSim/Region/Environment/Modules/XferModule.cs b/OpenSim/Region/Environment/Modules/XferModule.cs index 9f93c1e..819e894 100644 --- a/OpenSim/Region/Environment/Modules/XferModule.cs +++ b/OpenSim/Region/Environment/Modules/XferModule.cs | |||
@@ -1,173 +1,173 @@ | |||
1 | using System; | 1 | using System; |
2 | using System.Collections.Generic; | 2 | using System.Collections.Generic; |
3 | using libsecondlife; | 3 | using libsecondlife; |
4 | using OpenSim.Framework.Interfaces; | 4 | using OpenSim.Framework.Interfaces; |
5 | using OpenSim.Region.Environment.Interfaces; | 5 | using OpenSim.Region.Environment.Interfaces; |
6 | using OpenSim.Region.Environment.Scenes; | 6 | using OpenSim.Region.Environment.Scenes; |
7 | 7 | ||
8 | namespace OpenSim.Region.Environment.Modules | 8 | namespace OpenSim.Region.Environment.Modules |
9 | { | 9 | { |
10 | public class XferModule : IRegionModule, IXfer | 10 | public class XferModule : IRegionModule, IXfer |
11 | { | 11 | { |
12 | public Dictionary<string, byte[]> NewFiles = new Dictionary<string, byte[]>(); | 12 | public Dictionary<string, byte[]> NewFiles = new Dictionary<string, byte[]>(); |
13 | public Dictionary<ulong, XferDownLoad> Transfers = new Dictionary<ulong, XferDownLoad>(); | 13 | public Dictionary<ulong, XferDownLoad> Transfers = new Dictionary<ulong, XferDownLoad>(); |
14 | 14 | ||
15 | private Scene m_scene; | 15 | private Scene m_scene; |
16 | 16 | ||
17 | public XferModule() | 17 | public XferModule() |
18 | { | 18 | { |
19 | } | 19 | } |
20 | 20 | ||
21 | public void Initialise(Scene scene) | 21 | public void Initialise(Scene scene) |
22 | { | 22 | { |
23 | m_scene = scene; | 23 | m_scene = scene; |
24 | m_scene.EventManager.OnNewClient += NewClient; | 24 | m_scene.EventManager.OnNewClient += NewClient; |
25 | 25 | ||
26 | m_scene.RegisterModuleInterface<IXfer>(this); | 26 | m_scene.RegisterModuleInterface<IXfer>(this); |
27 | } | 27 | } |
28 | 28 | ||
29 | public void PostInitialise() | 29 | public void PostInitialise() |
30 | { | 30 | { |
31 | } | 31 | } |
32 | 32 | ||
33 | public void CloseDown() | 33 | public void Close() |
34 | { | 34 | { |
35 | } | 35 | } |
36 | 36 | ||
37 | public string GetName() | 37 | public string Name |
38 | { | 38 | { |
39 | return "XferModule"; | 39 | get { return "XferModule"; } |
40 | } | 40 | } |
41 | 41 | ||
42 | public bool IsSharedModule() | 42 | public bool IsSharedModule |
43 | { | 43 | { |
44 | return false; | 44 | get { return false; } |
45 | } | 45 | } |
46 | 46 | ||
47 | public void NewClient(IClientAPI client) | 47 | public void NewClient(IClientAPI client) |
48 | { | 48 | { |
49 | client.OnRequestXfer += RequestXfer; | 49 | client.OnRequestXfer += RequestXfer; |
50 | client.OnConfirmXfer += AckPacket; | 50 | client.OnConfirmXfer += AckPacket; |
51 | } | 51 | } |
52 | 52 | ||
53 | /// <summary> | 53 | /// <summary> |
54 | /// | 54 | /// |
55 | /// </summary> | 55 | /// </summary> |
56 | /// <param name="remoteClient"></param> | 56 | /// <param name="remoteClient"></param> |
57 | /// <param name="xferID"></param> | 57 | /// <param name="xferID"></param> |
58 | /// <param name="fileName"></param> | 58 | /// <param name="fileName"></param> |
59 | public void RequestXfer(IClientAPI remoteClient, ulong xferID, string fileName) | 59 | public void RequestXfer(IClientAPI remoteClient, ulong xferID, string fileName) |
60 | { | 60 | { |
61 | lock (NewFiles) | 61 | lock (NewFiles) |
62 | { | 62 | { |
63 | if (NewFiles.ContainsKey(fileName)) | 63 | if (NewFiles.ContainsKey(fileName)) |
64 | { | 64 | { |
65 | if (!Transfers.ContainsKey(xferID)) | 65 | if (!Transfers.ContainsKey(xferID)) |
66 | { | 66 | { |
67 | byte[] fileData = NewFiles[fileName]; | 67 | byte[] fileData = NewFiles[fileName]; |
68 | XferDownLoad transaction = new XferDownLoad(fileName, fileData, xferID, remoteClient); | 68 | XferDownLoad transaction = new XferDownLoad(fileName, fileData, xferID, remoteClient); |
69 | Transfers.Add(xferID, transaction); | 69 | Transfers.Add(xferID, transaction); |
70 | NewFiles.Remove(fileName); | 70 | NewFiles.Remove(fileName); |
71 | transaction.StartSend(); | 71 | transaction.StartSend(); |
72 | } | 72 | } |
73 | } | 73 | } |
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | public void AckPacket(IClientAPI remoteClient, ulong xferID, uint packet) | 77 | public void AckPacket(IClientAPI remoteClient, ulong xferID, uint packet) |
78 | { | 78 | { |
79 | if (Transfers.ContainsKey(xferID)) | 79 | if (Transfers.ContainsKey(xferID)) |
80 | { | 80 | { |
81 | Transfers[xferID].AckPacket(packet); | 81 | Transfers[xferID].AckPacket(packet); |
82 | } | 82 | } |
83 | } | 83 | } |
84 | 84 | ||
85 | public bool AddNewFile(string fileName, byte[] data) | 85 | public bool AddNewFile(string fileName, byte[] data) |
86 | { | 86 | { |
87 | lock (NewFiles) | 87 | lock (NewFiles) |
88 | { | 88 | { |
89 | if (NewFiles.ContainsKey(fileName)) | 89 | if (NewFiles.ContainsKey(fileName)) |
90 | { | 90 | { |
91 | NewFiles[fileName] = data; | 91 | NewFiles[fileName] = data; |
92 | } | 92 | } |
93 | else | 93 | else |
94 | { | 94 | { |
95 | NewFiles.Add(fileName, data); | 95 | NewFiles.Add(fileName, data); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | return true; | 98 | return true; |
99 | } | 99 | } |
100 | 100 | ||
101 | 101 | ||
102 | public class XferDownLoad | 102 | public class XferDownLoad |
103 | { | 103 | { |
104 | public byte[] Data = new byte[0]; | 104 | public byte[] Data = new byte[0]; |
105 | public string FileName = ""; | 105 | public string FileName = ""; |
106 | public ulong XferID = 0; | 106 | public ulong XferID = 0; |
107 | public int DataPointer = 0; | 107 | public int DataPointer = 0; |
108 | public uint Packet = 0; | 108 | public uint Packet = 0; |
109 | public IClientAPI Client; | 109 | public IClientAPI Client; |
110 | public uint Serial = 1; | 110 | public uint Serial = 1; |
111 | private bool complete = false; | 111 | private bool complete = false; |
112 | 112 | ||
113 | public XferDownLoad(string fileName, byte[] data, ulong xferID, IClientAPI client) | 113 | public XferDownLoad(string fileName, byte[] data, ulong xferID, IClientAPI client) |
114 | { | 114 | { |
115 | FileName = fileName; | 115 | FileName = fileName; |
116 | Data = data; | 116 | Data = data; |
117 | XferID = xferID; | 117 | XferID = xferID; |
118 | Client = client; | 118 | Client = client; |
119 | } | 119 | } |
120 | 120 | ||
121 | public XferDownLoad() | 121 | public XferDownLoad() |
122 | { | 122 | { |
123 | } | 123 | } |
124 | 124 | ||
125 | public void StartSend() | 125 | public void StartSend() |
126 | { | 126 | { |
127 | if (Data.Length < 1000) | 127 | if (Data.Length < 1000) |
128 | { | 128 | { |
129 | // for now (testing ) we only support files under 1000 bytes | 129 | // for now (testing ) we only support files under 1000 bytes |
130 | byte[] transferData = new byte[Data.Length + 4]; | 130 | byte[] transferData = new byte[Data.Length + 4]; |
131 | Array.Copy(Helpers.IntToBytes(Data.Length), 0, transferData, 0, 4); | 131 | Array.Copy(Helpers.IntToBytes(Data.Length), 0, transferData, 0, 4); |
132 | Array.Copy(Data, 0, transferData, 4, Data.Length); | 132 | Array.Copy(Data, 0, transferData, 4, Data.Length); |
133 | Client.SendXferPacket(XferID, 0 + 0x80000000, transferData); | 133 | Client.SendXferPacket(XferID, 0 + 0x80000000, transferData); |
134 | complete = true; | 134 | complete = true; |
135 | } | 135 | } |
136 | else | 136 | else |
137 | { | 137 | { |
138 | byte[] transferData = new byte[1000 + 4]; | 138 | byte[] transferData = new byte[1000 + 4]; |
139 | Array.Copy(Helpers.IntToBytes(Data.Length), 0, transferData, 0, 4); | 139 | Array.Copy(Helpers.IntToBytes(Data.Length), 0, transferData, 0, 4); |
140 | Array.Copy(Data, 0, transferData, 4, 1000); | 140 | Array.Copy(Data, 0, transferData, 4, 1000); |
141 | Client.SendXferPacket(XferID, 0, transferData); | 141 | Client.SendXferPacket(XferID, 0, transferData); |
142 | Packet++; | 142 | Packet++; |
143 | DataPointer = 1000; | 143 | DataPointer = 1000; |
144 | } | 144 | } |
145 | } | 145 | } |
146 | 146 | ||
147 | public void AckPacket(uint packet) | 147 | public void AckPacket(uint packet) |
148 | { | 148 | { |
149 | if (!complete) | 149 | if (!complete) |
150 | { | 150 | { |
151 | if ((Data.Length - DataPointer) > 1000) | 151 | if ((Data.Length - DataPointer) > 1000) |
152 | { | 152 | { |
153 | byte[] transferData = new byte[1000]; | 153 | byte[] transferData = new byte[1000]; |
154 | Array.Copy(Data, DataPointer, transferData, 0, 1000); | 154 | Array.Copy(Data, DataPointer, transferData, 0, 1000); |
155 | Client.SendXferPacket(XferID, Packet, transferData); | 155 | Client.SendXferPacket(XferID, Packet, transferData); |
156 | Packet++; | 156 | Packet++; |
157 | DataPointer += 1000; | 157 | DataPointer += 1000; |
158 | } | 158 | } |
159 | else | 159 | else |
160 | { | 160 | { |
161 | byte[] transferData = new byte[Data.Length - DataPointer]; | 161 | byte[] transferData = new byte[Data.Length - DataPointer]; |
162 | Array.Copy(Data, DataPointer, transferData, 0, Data.Length - DataPointer); | 162 | Array.Copy(Data, DataPointer, transferData, 0, Data.Length - DataPointer); |
163 | uint endPacket = Packet |= (uint) 0x80000000; | 163 | uint endPacket = Packet |= (uint) 0x80000000; |
164 | Client.SendXferPacket(XferID, endPacket, transferData); | 164 | Client.SendXferPacket(XferID, endPacket, transferData); |
165 | Packet++; | 165 | Packet++; |
166 | DataPointer += (Data.Length - DataPointer); | 166 | DataPointer += (Data.Length - DataPointer); |
167 | complete = true; | 167 | complete = true; |
168 | } | 168 | } |
169 | } | 169 | } |
170 | } | 170 | } |
171 | } | 171 | } |
172 | } | 172 | } |
173 | } \ No newline at end of file | 173 | } \ No newline at end of file |