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