aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack')
-rw-r--r--OpenSim/Region/ClientStack/Assets/InventoryCache.cs338
-rw-r--r--OpenSim/Region/ClientStack/ClientStackNetworkHandler.cs46
-rw-r--r--OpenSim/Region/ClientStack/ClientView.API.cs976
-rw-r--r--OpenSim/Region/ClientStack/ClientView.AgentAssetUpload.cs358
-rw-r--r--OpenSim/Region/ClientStack/ClientView.PacketHandlers.cs196
-rw-r--r--OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs556
-rw-r--r--OpenSim/Region/ClientStack/ClientView.cs273
-rw-r--r--OpenSim/Region/ClientStack/ClientViewBase.cs327
-rw-r--r--OpenSim/Region/ClientStack/OpenSim.Region.ClientStack.csproj166
-rw-r--r--OpenSim/Region/ClientStack/OpenSim.Region.ClientStack.dll.build60
-rw-r--r--OpenSim/Region/ClientStack/PacketServer.cs183
-rw-r--r--OpenSim/Region/ClientStack/RegionApplicationBase.cs128
-rw-r--r--OpenSim/Region/ClientStack/UDPServer.cs207
13 files changed, 3814 insertions, 0 deletions
diff --git a/OpenSim/Region/ClientStack/Assets/InventoryCache.cs b/OpenSim/Region/ClientStack/Assets/InventoryCache.cs
new file mode 100644
index 0000000..da74f85
--- /dev/null
+++ b/OpenSim/Region/ClientStack/Assets/InventoryCache.cs
@@ -0,0 +1,338 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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
29using System;
30using System.Collections.Generic;
31using libsecondlife;
32using OpenSim;
33using libsecondlife.Packets;
34//using OpenSim.GridServers;
35using OpenSim.Framework.Inventory;
36using OpenSim.Framework.Types;
37using OpenSim.Framework.Interfaces;
38using OpenSim.Region.ClientStack;
39
40namespace OpenSim.Assets
41{
42 /// <summary>
43 /// Description of InventoryManager.
44 /// </summary>
45 public class InventoryCache
46 {
47 private Dictionary<LLUUID, AgentInventory> _agentsInventory;
48 private List<UserServerRequest> _serverRequests; //list of requests made to user server.
49 private System.Text.Encoding _enc = System.Text.Encoding.ASCII;
50 private const uint FULL_MASK_PERMISSIONS = 2147483647;
51
52 public InventoryCache()
53 {
54 _agentsInventory = new Dictionary<LLUUID, AgentInventory>();
55 _serverRequests = new List<UserServerRequest>();
56 }
57
58 public void AddNewAgentsInventory(AgentInventory agentInventory)
59 {
60 if (!this._agentsInventory.ContainsKey(agentInventory.AgentID))
61 {
62 this._agentsInventory.Add(agentInventory.AgentID, agentInventory);
63 }
64 }
65
66 public AgentInventory FetchAgentsInventory(LLUUID agentID, IUserServer userserver)
67 {
68 AgentInventory res = null;
69 if (!this._agentsInventory.ContainsKey(agentID))
70 {
71 res = userserver.RequestAgentsInventory(agentID);
72 this._agentsInventory.Add(agentID,res);
73 }
74 return res;
75 }
76
77 public AgentInventory GetAgentsInventory(LLUUID agentID)
78 {
79 if (this._agentsInventory.ContainsKey(agentID))
80 {
81 return this._agentsInventory[agentID];
82 }
83
84 return null;
85 }
86
87 public void ClientLeaving(LLUUID clientID, IUserServer userserver)
88 {
89 if (this._agentsInventory.ContainsKey(clientID))
90 {
91 if (userserver != null)
92 {
93 userserver.UpdateAgentsInventory(clientID, this._agentsInventory[clientID]);
94 }
95 this._agentsInventory.Remove(clientID);
96 }
97 }
98
99 public bool CreateNewInventoryFolder(ClientView remoteClient, LLUUID folderID)
100 {
101 return this.CreateNewInventoryFolder(remoteClient, folderID, 0);
102 }
103
104 public bool CreateNewInventoryFolder(ClientView remoteClient, LLUUID folderID, ushort type)
105 {
106 bool res = false;
107 if (folderID != LLUUID.Zero) //don't create a folder with a zero id
108 {
109 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
110 {
111 res = this._agentsInventory[remoteClient.AgentID].CreateNewFolder(folderID, type);
112 }
113 }
114 return res;
115 }
116
117 public bool CreateNewInventoryFolder(ClientView remoteClient, LLUUID folderID, ushort type, string folderName, LLUUID parent)
118 {
119 bool res = false;
120 if (folderID != LLUUID.Zero) //don't create a folder with a zero id
121 {
122 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
123 {
124 res = this._agentsInventory[remoteClient.AgentID].CreateNewFolder(folderID, type, folderName, parent);
125 }
126 }
127 return res;
128 }
129
130 public LLUUID AddNewInventoryItem(ClientView remoteClient, LLUUID folderID, OpenSim.Framework.Types.AssetBase asset)
131 {
132 LLUUID newItem = null;
133 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
134 {
135 newItem = this._agentsInventory[remoteClient.AgentID].AddToInventory(folderID, asset);
136 if (newItem != null)
137 {
138 InventoryItem Item = this._agentsInventory[remoteClient.AgentID].InventoryItems[newItem];
139 this.SendItemUpdateCreate(remoteClient, Item);
140 }
141 }
142
143 return newItem;
144 }
145 public bool DeleteInventoryItem(ClientView remoteClient, LLUUID itemID)
146 {
147 bool res = false;
148 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
149 {
150 res = this._agentsInventory[remoteClient.AgentID].DeleteFromInventory(itemID);
151 if (res)
152 {
153 RemoveInventoryItemPacket remove = new RemoveInventoryItemPacket();
154 remove.AgentData.AgentID = remoteClient.AgentID;
155 remove.AgentData.SessionID = remoteClient.SessionID;
156 remove.InventoryData = new RemoveInventoryItemPacket.InventoryDataBlock[1];
157 remove.InventoryData[0] = new RemoveInventoryItemPacket.InventoryDataBlock();
158 remove.InventoryData[0].ItemID = itemID;
159 remoteClient.OutPacket(remove);
160 }
161 }
162
163 return res;
164 }
165
166 public bool UpdateInventoryItemAsset(ClientView remoteClient, LLUUID itemID, OpenSim.Framework.Types.AssetBase asset)
167 {
168 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
169 {
170 bool res = _agentsInventory[remoteClient.AgentID].UpdateItemAsset(itemID, asset);
171 if (res)
172 {
173 InventoryItem Item = this._agentsInventory[remoteClient.AgentID].InventoryItems[itemID];
174 this.SendItemUpdateCreate(remoteClient, Item);
175 }
176 return res;
177 }
178
179 return false;
180 }
181
182 public bool UpdateInventoryItemDetails(ClientView remoteClient, LLUUID itemID, UpdateInventoryItemPacket.InventoryDataBlock packet)
183 {
184 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
185 {
186 bool res = _agentsInventory[remoteClient.AgentID].UpdateItemDetails(itemID, packet);
187 if (res)
188 {
189 InventoryItem Item = this._agentsInventory[remoteClient.AgentID].InventoryItems[itemID];
190 this.SendItemUpdateCreate(remoteClient, Item);
191 }
192 return res;
193 }
194
195 return false;
196 }
197
198 public void FetchInventoryDescendents(ClientView userInfo, FetchInventoryDescendentsPacket FetchDescend)
199 {
200 if (this._agentsInventory.ContainsKey(userInfo.AgentID))
201 {
202 AgentInventory agentInventory = this._agentsInventory[userInfo.AgentID];
203 if (FetchDescend.InventoryData.FetchItems)
204 {
205 if (agentInventory.InventoryFolders.ContainsKey(FetchDescend.InventoryData.FolderID))
206 {
207 InventoryFolder Folder = agentInventory.InventoryFolders[FetchDescend.InventoryData.FolderID];
208 InventoryDescendentsPacket Descend = new InventoryDescendentsPacket();
209 Descend.AgentData.AgentID = userInfo.AgentID;
210 Descend.AgentData.OwnerID = Folder.OwnerID;
211 Descend.AgentData.FolderID = FetchDescend.InventoryData.FolderID;
212 Descend.AgentData.Descendents = Folder.Items.Count;
213 Descend.AgentData.Version = Folder.Items.Count;
214
215
216 Descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[Folder.Items.Count];
217 for (int i = 0; i < Folder.Items.Count; i++)
218 {
219
220 InventoryItem Item = Folder.Items[i];
221 Descend.ItemData[i] = new InventoryDescendentsPacket.ItemDataBlock();
222 Descend.ItemData[i].ItemID = Item.ItemID;
223 Descend.ItemData[i].AssetID = Item.AssetID;
224 Descend.ItemData[i].CreatorID = Item.CreatorID;
225 Descend.ItemData[i].BaseMask = FULL_MASK_PERMISSIONS;
226 Descend.ItemData[i].CreationDate = 1000;
227 Descend.ItemData[i].Description = _enc.GetBytes(Item.Description + "\0");
228 Descend.ItemData[i].EveryoneMask = FULL_MASK_PERMISSIONS;
229 Descend.ItemData[i].Flags = 1;
230 Descend.ItemData[i].FolderID = Item.FolderID;
231 Descend.ItemData[i].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
232 Descend.ItemData[i].GroupMask = FULL_MASK_PERMISSIONS;
233 Descend.ItemData[i].InvType = Item.InvType;
234 Descend.ItemData[i].Name = _enc.GetBytes(Item.Name + "\0");
235 Descend.ItemData[i].NextOwnerMask = FULL_MASK_PERMISSIONS;
236 Descend.ItemData[i].OwnerID = Item.OwnerID;
237 Descend.ItemData[i].OwnerMask = FULL_MASK_PERMISSIONS;
238 Descend.ItemData[i].SalePrice = 100;
239 Descend.ItemData[i].SaleType = 0;
240 Descend.ItemData[i].Type = Item.Type;
241 Descend.ItemData[i].CRC = libsecondlife.Helpers.InventoryCRC(1000, 0, Descend.ItemData[i].InvType, Descend.ItemData[i].Type, Descend.ItemData[i].AssetID, Descend.ItemData[i].GroupID, 100, Descend.ItemData[i].OwnerID, Descend.ItemData[i].CreatorID, Descend.ItemData[i].ItemID, Descend.ItemData[i].FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS);
242 }
243
244 userInfo.OutPacket(Descend);
245
246 }
247 }
248 else
249 {
250 Console.WriteLine("fetch subfolders");
251 }
252 }
253 }
254
255 public void FetchInventory(ClientView userInfo, FetchInventoryPacket FetchItems)
256 {
257 if (this._agentsInventory.ContainsKey(userInfo.AgentID))
258 {
259 AgentInventory agentInventory = this._agentsInventory[userInfo.AgentID];
260
261 for (int i = 0; i < FetchItems.InventoryData.Length; i++)
262 {
263 if (agentInventory.InventoryItems.ContainsKey(FetchItems.InventoryData[i].ItemID))
264 {
265 InventoryItem Item = agentInventory.InventoryItems[FetchItems.InventoryData[i].ItemID];
266 FetchInventoryReplyPacket InventoryReply = new FetchInventoryReplyPacket();
267 InventoryReply.AgentData.AgentID = userInfo.AgentID;
268 InventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[1];
269 InventoryReply.InventoryData[0] = new FetchInventoryReplyPacket.InventoryDataBlock();
270 InventoryReply.InventoryData[0].ItemID = Item.ItemID;
271 InventoryReply.InventoryData[0].AssetID = Item.AssetID;
272 InventoryReply.InventoryData[0].CreatorID = Item.CreatorID;
273 InventoryReply.InventoryData[0].BaseMask = FULL_MASK_PERMISSIONS;
274 InventoryReply.InventoryData[0].CreationDate = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
275 InventoryReply.InventoryData[0].Description = _enc.GetBytes(Item.Description + "\0");
276 InventoryReply.InventoryData[0].EveryoneMask = FULL_MASK_PERMISSIONS;
277 InventoryReply.InventoryData[0].Flags = 0;
278 InventoryReply.InventoryData[0].FolderID = Item.FolderID;
279 InventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
280 InventoryReply.InventoryData[0].GroupMask = FULL_MASK_PERMISSIONS;
281 InventoryReply.InventoryData[0].InvType = Item.InvType;
282 InventoryReply.InventoryData[0].Name = _enc.GetBytes(Item.Name + "\0");
283 InventoryReply.InventoryData[0].NextOwnerMask = FULL_MASK_PERMISSIONS;
284 InventoryReply.InventoryData[0].OwnerID = Item.OwnerID;
285 InventoryReply.InventoryData[0].OwnerMask = FULL_MASK_PERMISSIONS;
286 InventoryReply.InventoryData[0].SalePrice = 100;
287 InventoryReply.InventoryData[0].SaleType = 0;
288 InventoryReply.InventoryData[0].Type = Item.Type;
289 InventoryReply.InventoryData[0].CRC = libsecondlife.Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType, InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID, InventoryReply.InventoryData[0].GroupID, 100, InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID, InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS);
290 userInfo.OutPacket(InventoryReply);
291 }
292 }
293 }
294 }
295
296 private void SendItemUpdateCreate(ClientView remoteClient, InventoryItem Item)
297 {
298
299 UpdateCreateInventoryItemPacket InventoryReply = new UpdateCreateInventoryItemPacket();
300 InventoryReply.AgentData.AgentID = remoteClient.AgentID;
301 InventoryReply.AgentData.SimApproved = true;
302 InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1];
303 InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock();
304 InventoryReply.InventoryData[0].ItemID = Item.ItemID;
305 InventoryReply.InventoryData[0].AssetID = Item.AssetID;
306 InventoryReply.InventoryData[0].CreatorID = Item.CreatorID;
307 InventoryReply.InventoryData[0].BaseMask = FULL_MASK_PERMISSIONS;
308 InventoryReply.InventoryData[0].CreationDate = 1000;
309 InventoryReply.InventoryData[0].Description = _enc.GetBytes(Item.Description + "\0");
310 InventoryReply.InventoryData[0].EveryoneMask = FULL_MASK_PERMISSIONS;
311 InventoryReply.InventoryData[0].Flags = 0;
312 InventoryReply.InventoryData[0].FolderID = Item.FolderID;
313 InventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
314 InventoryReply.InventoryData[0].GroupMask = FULL_MASK_PERMISSIONS;
315 InventoryReply.InventoryData[0].InvType = Item.InvType;
316 InventoryReply.InventoryData[0].Name = _enc.GetBytes(Item.Name + "\0");
317 InventoryReply.InventoryData[0].NextOwnerMask = FULL_MASK_PERMISSIONS;
318 InventoryReply.InventoryData[0].OwnerID = Item.OwnerID;
319 InventoryReply.InventoryData[0].OwnerMask = FULL_MASK_PERMISSIONS;
320 InventoryReply.InventoryData[0].SalePrice = 100;
321 InventoryReply.InventoryData[0].SaleType = 0;
322 InventoryReply.InventoryData[0].Type = Item.Type;
323 InventoryReply.InventoryData[0].CRC = libsecondlife.Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType, InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID, InventoryReply.InventoryData[0].GroupID, 100, InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID, InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS);
324
325 remoteClient.OutPacket(InventoryReply);
326 }
327 }
328
329
330
331 public class UserServerRequest
332 {
333 public UserServerRequest()
334 {
335
336 }
337 }
338}
diff --git a/OpenSim/Region/ClientStack/ClientStackNetworkHandler.cs b/OpenSim/Region/ClientStack/ClientStackNetworkHandler.cs
new file mode 100644
index 0000000..f99cf79
--- /dev/null
+++ b/OpenSim/Region/ClientStack/ClientStackNetworkHandler.cs
@@ -0,0 +1,46 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using System.Net;
32using System.Net.Sockets;
33using libsecondlife;
34
35
36namespace OpenSim.Region.ClientStack
37{
38
39 public interface ClientStackNetworkHandler
40 {
41 void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode);// EndPoint packetSender);
42 void RemoveClientCircuit(uint circuitcode);
43 void RegisterPacketServer(PacketServer server);
44 }
45
46}
diff --git a/OpenSim/Region/ClientStack/ClientView.API.cs b/OpenSim/Region/ClientStack/ClientView.API.cs
new file mode 100644
index 0000000..9650b42
--- /dev/null
+++ b/OpenSim/Region/ClientStack/ClientView.API.cs
@@ -0,0 +1,976 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using OpenSim.Framework.Interfaces;
32using OpenSim.Framework.Inventory;
33using OpenSim.Framework.Types;
34
35using libsecondlife;
36using libsecondlife.Packets;
37
38namespace OpenSim.Region.ClientStack
39{
40 partial class ClientView
41 {
42 public event ChatFromViewer OnChatFromViewer;
43 public event RezObject OnRezObject;
44 public event GenericCall4 OnDeRezObject;
45 public event ModifyTerrain OnModifyTerrain;
46 public event GenericCall OnRegionHandShakeReply;
47 public event GenericCall OnRequestWearables;
48 public event SetAppearance OnSetAppearance;
49 public event GenericCall2 OnCompleteMovementToRegion;
50 public event UpdateAgent OnAgentUpdate;
51 public event StartAnim OnStartAnim;
52 public event GenericCall OnRequestAvatarsData;
53 public event LinkObjects OnLinkObjects;
54 public event UpdateVector OnGrapObject;
55 public event ObjectSelect OnDeGrapObject;
56 public event MoveObject OnGrapUpdate;
57 public event GenericCall4 OnAddPrim;
58 public event UpdateShape OnUpdatePrimShape;
59 public event ObjectSelect OnObjectSelect;
60 public event UpdatePrimFlags OnUpdatePrimFlags;
61 public event UpdatePrimTexture OnUpdatePrimTexture;
62 public event UpdateVector OnUpdatePrimPosition;
63 public event UpdatePrimRotation OnUpdatePrimRotation;
64 public event UpdateVector OnUpdatePrimScale;
65 public event StatusChange OnChildAgentStatus;
66 public event GenericCall2 OnStopMovement;
67 public event NewAvatar OnNewAvatar;
68 public event GenericCall6 OnRemoveAvatar;
69 public event RequestMapBlocks OnRequestMapBlocks;
70 public event TeleportLocationRequest OnTeleportLocationRequest;
71
72 public event UUIDNameRequest OnNameFromUUIDRequest;
73
74 public event ParcelPropertiesRequest OnParcelPropertiesRequest;
75 public event ParcelDivideRequest OnParcelDivideRequest;
76 public event ParcelJoinRequest OnParcelJoinRequest;
77 public event ParcelPropertiesUpdateRequest OnParcelPropertiesUpdateRequest;
78
79 public event EstateOwnerMessageRequest OnEstateOwnerMessage;
80 /// <summary>
81 ///
82 /// </summary>
83 public LLVector3 StartPos
84 {
85 get
86 {
87 return startpos;
88 }
89 set
90 {
91 startpos = value;
92 }
93 }
94
95 /// <summary>
96 ///
97 /// </summary>
98 public LLUUID AgentId
99 {
100 get
101 {
102 return this.AgentID;
103 }
104 }
105
106 /// <summary>
107 ///
108 /// </summary>
109 public string FirstName
110 {
111 get
112 {
113 return this.firstName;
114 }
115
116 }
117
118 /// <summary>
119 ///
120 /// </summary>
121 public string LastName
122 {
123 get
124 {
125 return this.lastName;
126 }
127 }
128
129 #region World/Avatar to Client
130
131 /// <summary>
132 ///
133 /// </summary>
134 /// <param name="regionInfo"></param>
135 public void SendRegionHandshake(RegionInfo regionInfo)
136 {
137 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
138 RegionHandshakePacket handshake = new RegionHandshakePacket();
139
140 handshake.RegionInfo.BillableFactor = regionInfo.estateSettings.billableFactor;
141 handshake.RegionInfo.IsEstateManager = false;
142 handshake.RegionInfo.TerrainHeightRange00 = regionInfo.estateSettings.terrainHeightRange0;
143 handshake.RegionInfo.TerrainHeightRange01 = regionInfo.estateSettings.terrainHeightRange1;
144 handshake.RegionInfo.TerrainHeightRange10 = regionInfo.estateSettings.terrainHeightRange2;
145 handshake.RegionInfo.TerrainHeightRange11 = regionInfo.estateSettings.terrainHeightRange3;
146 handshake.RegionInfo.TerrainStartHeight00 = regionInfo.estateSettings.terrainStartHeight0;
147 handshake.RegionInfo.TerrainStartHeight01 = regionInfo.estateSettings.terrainStartHeight1;
148 handshake.RegionInfo.TerrainStartHeight10 = regionInfo.estateSettings.terrainStartHeight2;
149 handshake.RegionInfo.TerrainStartHeight11 = regionInfo.estateSettings.terrainStartHeight3;
150 handshake.RegionInfo.SimAccess = (byte)regionInfo.estateSettings.simAccess;
151 handshake.RegionInfo.WaterHeight = regionInfo.estateSettings.waterHeight;
152
153
154 handshake.RegionInfo.RegionFlags = (uint)regionInfo.estateSettings.regionFlags;
155
156 handshake.RegionInfo.SimName = _enc.GetBytes(regionInfo.RegionName + "\0");
157 handshake.RegionInfo.SimOwner = regionInfo.MasterAvatarAssignedUUID;
158 handshake.RegionInfo.TerrainBase0 = regionInfo.estateSettings.terrainBase0;
159 handshake.RegionInfo.TerrainBase1 = regionInfo.estateSettings.terrainBase1;
160 handshake.RegionInfo.TerrainBase2 = regionInfo.estateSettings.terrainBase2;
161 handshake.RegionInfo.TerrainBase3 = regionInfo.estateSettings.terrainBase3;
162 handshake.RegionInfo.TerrainDetail0 = regionInfo.estateSettings.terrainDetail0;
163 handshake.RegionInfo.TerrainDetail1 = regionInfo.estateSettings.terrainDetail1;
164 handshake.RegionInfo.TerrainDetail2 = regionInfo.estateSettings.terrainDetail2;
165 handshake.RegionInfo.TerrainDetail3 = regionInfo.estateSettings.terrainDetail3;
166 handshake.RegionInfo.CacheID = LLUUID.Random(); //I guess this is for the client to remember an old setting?
167
168 this.OutPacket(handshake);
169 }
170
171 /// <summary>
172 ///
173 /// </summary>
174 /// <param name="regInfo"></param>
175 public void MoveAgentIntoRegion(RegionInfo regInfo, LLVector3 pos, LLVector3 look)
176 {
177 AgentMovementCompletePacket mov = new AgentMovementCompletePacket();
178 mov.AgentData.SessionID = this.SessionID;
179 mov.AgentData.AgentID = this.AgentID;
180 mov.Data.RegionHandle = regInfo.RegionHandle;
181 mov.Data.Timestamp = 1172750370; // TODO - dynamicalise this
182
183 if ((pos.X == 0) && (pos.Y == 0) && (pos.Z == 0))
184 {
185 mov.Data.Position = this.startpos;
186 }
187 else
188 {
189 mov.Data.Position = pos;
190 }
191 mov.Data.LookAt = look;
192
193 OutPacket(mov);
194 }
195
196 /// <summary>
197 ///
198 /// </summary>
199 /// <param name="message"></param>
200 /// <param name="type"></param>
201 /// <param name="fromPos"></param>
202 /// <param name="fromName"></param>
203 /// <param name="fromAgentID"></param>
204 public void SendChatMessage(string message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
205 {
206 SendChatMessage(Helpers.StringToField(message), type, fromPos, fromName, fromAgentID);
207 }
208
209 /// <summary>
210 ///
211 /// </summary>
212 /// <param name="message"></param>
213 /// <param name="type"></param>
214 /// <param name="fromPos"></param>
215 /// <param name="fromName"></param>
216 /// <param name="fromAgentID"></param>
217 public void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
218 {
219 System.Text.Encoding enc = System.Text.Encoding.ASCII;
220 libsecondlife.Packets.ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket();
221 reply.ChatData.Audible = 1;
222 reply.ChatData.Message = message;
223 reply.ChatData.ChatType = type;
224 reply.ChatData.SourceType = 1;
225 reply.ChatData.Position = fromPos;
226 reply.ChatData.FromName = enc.GetBytes(fromName + "\0");
227 reply.ChatData.OwnerID = fromAgentID;
228 reply.ChatData.SourceID = fromAgentID;
229
230 this.OutPacket(reply);
231 }
232
233
234 /// <summary>
235 /// Send the region heightmap to the client
236 /// </summary>
237 /// <param name="map">heightmap</param>
238 public virtual void SendLayerData(float[] map)
239 {
240 try
241 {
242 int[] patches = new int[4];
243
244 for (int y = 0; y < 16; y++)
245 {
246 for (int x = 0; x < 16; x = x + 4)
247 {
248 patches[0] = x + 0 + y * 16;
249 patches[1] = x + 1 + y * 16;
250 patches[2] = x + 2 + y * 16;
251 patches[3] = x + 3 + y * 16;
252
253 Packet layerpack = TerrainManager.CreateLandPacket(map, patches);
254 OutPacket(layerpack);
255 }
256 }
257 }
258 catch (Exception e)
259 {
260 OpenSim.Framework.Console.MainLog.Instance.Warn("ClientView API.cs: SendLayerData() - Failed with exception " + e.ToString());
261 }
262 }
263
264 /// <summary>
265 /// Sends a specified patch to a client
266 /// </summary>
267 /// <param name="px">Patch coordinate (x) 0..16</param>
268 /// <param name="py">Patch coordinate (y) 0..16</param>
269 /// <param name="map">heightmap</param>
270 public void SendLayerData(int px, int py, float[] map)
271 {
272 try
273 {
274 int[] patches = new int[1];
275 int patchx, patchy;
276 patchx = px / 16;
277 patchy = py / 16;
278
279 patches[0] = patchx + 0 + patchy * 16;
280
281 Packet layerpack = TerrainManager.CreateLandPacket(map, patches);
282 OutPacket(layerpack);
283 }
284 catch (Exception e)
285 {
286 OpenSim.Framework.Console.MainLog.Instance.Warn("ClientView API .cs: SendLayerData() - Failed with exception " + e.ToString());
287 }
288 }
289
290 /// <summary>
291 ///
292 /// </summary>
293 /// <param name="neighbourHandle"></param>
294 /// <param name="neighbourIP"></param>
295 /// <param name="neighbourPort"></param>
296 public void InformClientOfNeighbour(ulong neighbourHandle, System.Net.IPAddress neighbourIP, ushort neighbourPort)
297 {
298 EnableSimulatorPacket enablesimpacket = new EnableSimulatorPacket();
299 enablesimpacket.SimulatorInfo = new EnableSimulatorPacket.SimulatorInfoBlock();
300 enablesimpacket.SimulatorInfo.Handle = neighbourHandle;
301
302 byte[] byteIP = neighbourIP.GetAddressBytes();
303 enablesimpacket.SimulatorInfo.IP = (uint)byteIP[3] << 24;
304 enablesimpacket.SimulatorInfo.IP += (uint)byteIP[2] << 16;
305 enablesimpacket.SimulatorInfo.IP += (uint)byteIP[1] << 8;
306 enablesimpacket.SimulatorInfo.IP += (uint)byteIP[0];
307 enablesimpacket.SimulatorInfo.Port = neighbourPort;
308 OutPacket(enablesimpacket);
309 }
310
311 /// <summary>
312 ///
313 /// </summary>
314 /// <returns></returns>
315 public AgentCircuitData RequestClientInfo()
316 {
317 AgentCircuitData agentData = new AgentCircuitData();
318 agentData.AgentID = this.AgentId;
319 agentData.SessionID = this.SessionID;
320 agentData.SecureSessionID = this.SecureSessionID;
321 agentData.circuitcode = this.CircuitCode;
322 agentData.child = false;
323 agentData.firstname = this.firstName;
324 agentData.lastname = this.lastName;
325
326 return agentData;
327 }
328
329 public void CrossRegion(ulong newRegionHandle, LLVector3 pos, LLVector3 lookAt, System.Net.IPAddress newRegionIP, ushort newRegionPort)
330 {
331 LLVector3 look = new LLVector3(lookAt.X * 10, lookAt.Y * 10, lookAt.Z * 10);
332
333 CrossedRegionPacket newSimPack = new CrossedRegionPacket();
334 newSimPack.AgentData = new CrossedRegionPacket.AgentDataBlock();
335 newSimPack.AgentData.AgentID = this.AgentID;
336 newSimPack.AgentData.SessionID = this.SessionID;
337 newSimPack.Info = new CrossedRegionPacket.InfoBlock();
338 newSimPack.Info.Position = pos;
339 newSimPack.Info.LookAt = look; // new LLVector3(0.0f, 0.0f, 0.0f); // copied from Avatar.cs - SHOULD BE DYNAMIC!!!!!!!!!!
340 newSimPack.RegionData = new libsecondlife.Packets.CrossedRegionPacket.RegionDataBlock();
341 newSimPack.RegionData.RegionHandle = newRegionHandle;
342 byte[] byteIP = newRegionIP.GetAddressBytes();
343 newSimPack.RegionData.SimIP = (uint)byteIP[3] << 24;
344 newSimPack.RegionData.SimIP += (uint)byteIP[2] << 16;
345 newSimPack.RegionData.SimIP += (uint)byteIP[1] << 8;
346 newSimPack.RegionData.SimIP += (uint)byteIP[0];
347 newSimPack.RegionData.SimPort = newRegionPort;
348 newSimPack.RegionData.SeedCapability = new byte[0];
349
350 this.OutPacket(newSimPack);
351 //this.DowngradeClient();
352 }
353
354 public void SendMapBlock(List<MapBlockData> mapBlocks)
355 {
356 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
357
358 MapBlockReplyPacket mapReply = new MapBlockReplyPacket();
359 mapReply.AgentData.AgentID = this.AgentID;
360 mapReply.Data = new MapBlockReplyPacket.DataBlock[mapBlocks.Count];
361 mapReply.AgentData.Flags = 0;
362
363 for (int i = 0; i < mapBlocks.Count; i++)
364 {
365 mapReply.Data[i] = new MapBlockReplyPacket.DataBlock();
366 mapReply.Data[i].MapImageID = mapBlocks[i].MapImageId;
367 mapReply.Data[i].X = mapBlocks[i].X;
368 mapReply.Data[i].Y = mapBlocks[i].Y;
369 mapReply.Data[i].WaterHeight = mapBlocks[i].WaterHeight;
370 mapReply.Data[i].Name = _enc.GetBytes(mapBlocks[i].Name);
371 mapReply.Data[i].RegionFlags = mapBlocks[i].RegionFlags;
372 mapReply.Data[i].Access = mapBlocks[i].Access;
373 mapReply.Data[i].Agents = mapBlocks[i].Agents;
374 }
375 this.OutPacket(mapReply);
376 }
377
378 public void SendLocalTeleport(LLVector3 position, LLVector3 lookAt, uint flags)
379 {
380 TeleportLocalPacket tpLocal = new TeleportLocalPacket();
381 tpLocal.Info.AgentID = this.AgentID;
382 tpLocal.Info.TeleportFlags = flags;
383 tpLocal.Info.LocationID = 2;
384 tpLocal.Info.LookAt = lookAt;
385 tpLocal.Info.Position = position;
386 OutPacket(tpLocal);
387 }
388
389 public void SendRegionTeleport(ulong regionHandle, byte simAccess, string ipAddress, ushort ipPort, uint locationID, uint flags)
390 {
391 TeleportFinishPacket teleport = new TeleportFinishPacket();
392 teleport.Info.AgentID = this.AgentID;
393 teleport.Info.RegionHandle = regionHandle;
394 teleport.Info.SimAccess = simAccess;
395 teleport.Info.SeedCapability = new byte[0];
396
397 System.Net.IPAddress oIP = System.Net.IPAddress.Parse(ipAddress);
398 byte[] byteIP = oIP.GetAddressBytes();
399 uint ip = (uint)byteIP[3] << 24;
400 ip += (uint)byteIP[2] << 16;
401 ip += (uint)byteIP[1] << 8;
402 ip += (uint)byteIP[0];
403
404 teleport.Info.SimIP = ip;
405 teleport.Info.SimPort = ipPort;
406 teleport.Info.LocationID = 4;
407 teleport.Info.TeleportFlags = 1 << 4;
408 OutPacket(teleport);
409 }
410
411 /// <summary>
412 ///
413 /// </summary>
414 public void SendTeleportCancel()
415 {
416 TeleportCancelPacket tpCancel = new TeleportCancelPacket();
417 tpCancel.Info.SessionID = this.SessionID;
418 tpCancel.Info.AgentID = this.AgentID;
419
420 OutPacket(tpCancel);
421 }
422
423 /// <summary>
424 ///
425 /// </summary>
426 public void SendTeleportLocationStart()
427 {
428 TeleportStartPacket tpStart = new TeleportStartPacket();
429 tpStart.Info.TeleportFlags = 16; // Teleport via location
430 OutPacket(tpStart);
431 }
432
433 public void SendMoneyBalance(LLUUID transaction, bool success, byte[] description, int balance)
434 {
435 MoneyBalanceReplyPacket money = new MoneyBalanceReplyPacket();
436 money.MoneyData.AgentID = this.AgentID;
437 money.MoneyData.TransactionID = transaction;
438 money.MoneyData.TransactionSuccess = success;
439 money.MoneyData.Description = description;
440 money.MoneyData.MoneyBalance = balance;
441 OutPacket(money);
442 }
443
444 #region Appearance/ Wearables Methods
445
446 /// <summary>
447 ///
448 /// </summary>
449 /// <param name="wearables"></param>
450 public void SendWearables(AvatarWearable[] wearables)
451 {
452 AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket();
453 aw.AgentData.AgentID = this.AgentID;
454 aw.AgentData.SerialNum = 0;
455 aw.AgentData.SessionID = this.SessionID;
456
457 aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13];
458 AgentWearablesUpdatePacket.WearableDataBlock awb;
459 for (int i = 0; i < wearables.Length; i++)
460 {
461 awb = new AgentWearablesUpdatePacket.WearableDataBlock();
462 awb.WearableType = (byte)i;
463 awb.AssetID = wearables[i].AssetID;
464 awb.ItemID = wearables[i].ItemID;
465 aw.WearableData[i] = awb;
466 }
467
468 this.OutPacket(aw);
469 }
470
471 /// <summary>
472 ///
473 /// </summary>
474 /// <param name="agentID"></param>
475 /// <param name="visualParams"></param>
476 /// <param name="textureEntry"></param>
477 public void SendAppearance(LLUUID agentID, byte[] visualParams, byte[] textureEntry)
478 {
479 AvatarAppearancePacket avp = new AvatarAppearancePacket();
480 avp.VisualParam = new AvatarAppearancePacket.VisualParamBlock[218];
481 avp.ObjectData.TextureEntry = textureEntry;
482
483 AvatarAppearancePacket.VisualParamBlock avblock = null;
484 for (int i = 0; i < visualParams.Length; i++)
485 {
486 avblock = new AvatarAppearancePacket.VisualParamBlock();
487 avblock.ParamValue = visualParams[i];
488 avp.VisualParam[i] = avblock;
489 }
490
491 avp.Sender.IsTrial = false;
492 avp.Sender.ID = agentID;
493 OutPacket(avp);
494 }
495
496 #endregion
497
498 #region Avatar Packet/data sending Methods
499
500 /// <summary>
501 ///
502 /// </summary>
503 /// <param name="regionInfo"></param>
504 /// <param name="firstName"></param>
505 /// <param name="lastName"></param>
506 /// <param name="avatarID"></param>
507 /// <param name="avatarLocalID"></param>
508 /// <param name="Pos"></param>
509 public void SendAvatarData(ulong regionHandle, string firstName, string lastName, LLUUID avatarID, uint avatarLocalID, LLVector3 Pos, byte[] textureEntry)
510 {
511 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
512 //send a objectupdate packet with information about the clients avatar
513
514 ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
515 objupdate.RegionData.RegionHandle = regionHandle;
516 objupdate.RegionData.TimeDilation = 64096;
517 objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
518 objupdate.ObjectData[0] = this.CreateDefaultAvatarPacket(textureEntry);
519 //give this avatar object a local id and assign the user a name
520
521 objupdate.ObjectData[0].ID = avatarLocalID;
522 objupdate.ObjectData[0].FullID = avatarID;
523 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstName + "\nLastName STRING RW SV " + lastName + " \0");
524 libsecondlife.LLVector3 pos2 = new LLVector3((float)Pos.X, (float)Pos.Y, (float)Pos.Z);
525 byte[] pb = pos2.GetBytes();
526 Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
527
528 OutPacket(objupdate);
529
530 }
531
532 /// <summary>
533 ///
534 /// </summary>
535 /// <param name="regionHandle"></param>
536 /// <param name="timeDilation"></param>
537 /// <param name="localID"></param>
538 /// <param name="position"></param>
539 /// <param name="velocity"></param>
540 public void SendAvatarTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position, LLVector3 velocity)
541 {
542 ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = this.CreateAvatarImprovedBlock(localID, position, velocity);
543 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
544 terse.RegionData.RegionHandle = regionHandle;
545 terse.RegionData.TimeDilation = timeDilation;
546 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
547 terse.ObjectData[0] = terseBlock;
548
549 this.OutPacket(terse);
550 }
551
552 #endregion
553
554 #region Primitive Packet/data Sending Methods
555
556 /// <summary>
557 ///
558 /// </summary>
559 /// <param name="localID"></param>
560 /// <param name="rotation"></param>
561 /// <param name="attachPoint"></param>
562 public void AttachObject(uint localID, LLQuaternion rotation, byte attachPoint)
563 {
564 ObjectAttachPacket attach = new ObjectAttachPacket();
565 attach.AgentData.AgentID = this.AgentID;
566 attach.AgentData.SessionID = this.SessionID;
567 attach.AgentData.AttachmentPoint = attachPoint;
568 attach.ObjectData = new ObjectAttachPacket.ObjectDataBlock[1];
569 attach.ObjectData[0] = new ObjectAttachPacket.ObjectDataBlock();
570 attach.ObjectData[0].ObjectLocalID = localID;
571 attach.ObjectData[0].Rotation = rotation;
572
573 this.OutPacket(attach);
574 }
575
576 /// <summary>
577 /// Sends a full ObjectUpdatePacket to a client to inform it of a new primitive
578 /// or big changes to a existing primitive.
579 /// </summary>
580 /// <param name="regionHandle"></param>
581 /// <param name="timeDilation"></param>
582 /// <param name="localID"></param>
583 /// <param name="primData"></param>
584 /// <param name="pos"></param>
585 /// <param name="rotation"></param>
586 /// <param name="textureID"></param>
587 public void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimData primData, LLVector3 pos, LLQuaternion rotation, LLUUID textureID, uint flags)
588 {
589 ObjectUpdatePacket outPacket = new ObjectUpdatePacket();
590 outPacket.RegionData.RegionHandle = regionHandle;
591 outPacket.RegionData.TimeDilation = timeDilation;
592 outPacket.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
593 outPacket.ObjectData[0] = this.CreatePrimUpdateBlock(primData, textureID, flags);
594 outPacket.ObjectData[0].ID = localID;
595 outPacket.ObjectData[0].FullID = primData.FullID;
596 byte[] pb = pos.GetBytes();
597 Array.Copy(pb, 0, outPacket.ObjectData[0].ObjectData, 0, pb.Length);
598 byte[] rot = rotation.GetBytes();
599 Array.Copy(rot, 0, outPacket.ObjectData[0].ObjectData, 48, rot.Length);
600 OutPacket(outPacket);
601 }
602
603 /// <summary>
604 /// Sends a full ObjectUpdatePacket to a client to inform it of a new primitive
605 /// or big changes to a existing primitive.
606 /// Uses default rotation
607 /// </summary>
608 /// <param name="primData"></param>
609 /// <param name="pos"></param>
610 public void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimData primData, LLVector3 pos, LLUUID textureID , uint flags)
611 {
612 ObjectUpdatePacket outPacket = new ObjectUpdatePacket();
613 outPacket.RegionData.RegionHandle = regionHandle;
614 outPacket.RegionData.TimeDilation = timeDilation;
615 outPacket.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1];
616 outPacket.ObjectData[0] = this.CreatePrimUpdateBlock(primData, textureID, flags);
617 outPacket.ObjectData[0].ID = localID;
618 outPacket.ObjectData[0].FullID = primData.FullID;
619 byte[] pb = pos.GetBytes();
620 Array.Copy(pb, 0, outPacket.ObjectData[0].ObjectData, 0, pb.Length);
621
622 OutPacket(outPacket);
623 }
624
625 /// <summary>
626 ///
627 /// </summary>
628 /// <param name="regionHandle"></param>
629 /// <param name="timeDilation"></param>
630 /// <param name="localID"></param>
631 /// <param name="position"></param>
632 /// <param name="rotation"></param>
633 public void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position, LLQuaternion rotation)
634 {
635 ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
636 terse.RegionData.RegionHandle = regionHandle;
637 terse.RegionData.TimeDilation = timeDilation;
638 terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
639 terse.ObjectData[0] = this.CreatePrimImprovedBlock(localID, position, rotation);
640
641 this.OutPacket(terse);
642 }
643
644 #endregion
645
646 #endregion
647
648 #region Helper Methods
649
650 protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateAvatarImprovedBlock(uint localID, LLVector3 pos, LLVector3 velocity)
651 {
652 byte[] bytes = new byte[60];
653 int i = 0;
654 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
655
656 dat.TextureEntry = new byte[0];// AvatarTemplate.TextureEntry;
657
658 uint ID = localID;
659
660 bytes[i++] = (byte)(ID % 256);
661 bytes[i++] = (byte)((ID >> 8) % 256);
662 bytes[i++] = (byte)((ID >> 16) % 256);
663 bytes[i++] = (byte)((ID >> 24) % 256);
664 bytes[i++] = 0;
665 bytes[i++] = 1;
666 i += 14;
667 bytes[i++] = 128;
668 bytes[i++] = 63;
669
670 byte[] pb = pos.GetBytes();
671 Array.Copy(pb, 0, bytes, i, pb.Length);
672 i += 12;
673 ushort InternVelocityX;
674 ushort InternVelocityY;
675 ushort InternVelocityZ;
676 Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(0, 0, 0);
677
678 internDirec = new Axiom.MathLib.Vector3(velocity.X, velocity.Y, velocity.Z);
679
680 internDirec = internDirec / 128.0f;
681 internDirec.x += 1;
682 internDirec.y += 1;
683 internDirec.z += 1;
684
685 InternVelocityX = (ushort)(32768 * internDirec.x);
686 InternVelocityY = (ushort)(32768 * internDirec.y);
687 InternVelocityZ = (ushort)(32768 * internDirec.z);
688
689 ushort ac = 32767;
690 bytes[i++] = (byte)(InternVelocityX % 256);
691 bytes[i++] = (byte)((InternVelocityX >> 8) % 256);
692 bytes[i++] = (byte)(InternVelocityY % 256);
693 bytes[i++] = (byte)((InternVelocityY >> 8) % 256);
694 bytes[i++] = (byte)(InternVelocityZ % 256);
695 bytes[i++] = (byte)((InternVelocityZ >> 8) % 256);
696
697 //accel
698 bytes[i++] = (byte)(ac % 256);
699 bytes[i++] = (byte)((ac >> 8) % 256);
700 bytes[i++] = (byte)(ac % 256);
701 bytes[i++] = (byte)((ac >> 8) % 256);
702 bytes[i++] = (byte)(ac % 256);
703 bytes[i++] = (byte)((ac >> 8) % 256);
704
705 //rot
706 bytes[i++] = (byte)(ac % 256);
707 bytes[i++] = (byte)((ac >> 8) % 256);
708 bytes[i++] = (byte)(ac % 256);
709 bytes[i++] = (byte)((ac >> 8) % 256);
710 bytes[i++] = (byte)(ac % 256);
711 bytes[i++] = (byte)((ac >> 8) % 256);
712 bytes[i++] = (byte)(ac % 256);
713 bytes[i++] = (byte)((ac >> 8) % 256);
714
715 //rotation vel
716 bytes[i++] = (byte)(ac % 256);
717 bytes[i++] = (byte)((ac >> 8) % 256);
718 bytes[i++] = (byte)(ac % 256);
719 bytes[i++] = (byte)((ac >> 8) % 256);
720 bytes[i++] = (byte)(ac % 256);
721 bytes[i++] = (byte)((ac >> 8) % 256);
722
723 dat.Data = bytes;
724 return (dat);
725 }
726
727 /// <summary>
728 ///
729 /// </summary>
730 /// <param name="localID"></param>
731 /// <param name="position"></param>
732 /// <param name="rotation"></param>
733 /// <returns></returns>
734 protected ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreatePrimImprovedBlock(uint localID, LLVector3 position, LLQuaternion rotation)
735 {
736 uint ID = localID;
737 byte[] bytes = new byte[60];
738
739 int i = 0;
740 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
741 dat.TextureEntry = new byte[0];
742 bytes[i++] = (byte)(ID % 256);
743 bytes[i++] = (byte)((ID >> 8) % 256);
744 bytes[i++] = (byte)((ID >> 16) % 256);
745 bytes[i++] = (byte)((ID >> 24) % 256);
746 bytes[i++] = 0;
747 bytes[i++] = 0;
748
749 byte[] pb = position.GetBytes();
750 Array.Copy(pb, 0, bytes, i, pb.Length);
751 i += 12;
752 ushort ac = 32767;
753
754 //vel
755 bytes[i++] = (byte)(ac % 256);
756 bytes[i++] = (byte)((ac >> 8) % 256);
757 bytes[i++] = (byte)(ac % 256);
758 bytes[i++] = (byte)((ac >> 8) % 256);
759 bytes[i++] = (byte)(ac % 256);
760 bytes[i++] = (byte)((ac >> 8) % 256);
761
762 //accel
763 bytes[i++] = (byte)(ac % 256);
764 bytes[i++] = (byte)((ac >> 8) % 256);
765 bytes[i++] = (byte)(ac % 256);
766 bytes[i++] = (byte)((ac >> 8) % 256);
767 bytes[i++] = (byte)(ac % 256);
768 bytes[i++] = (byte)((ac >> 8) % 256);
769
770 ushort rw, rx, ry, rz;
771 rw = (ushort)(32768 * (rotation.W + 1));
772 rx = (ushort)(32768 * (rotation.X + 1));
773 ry = (ushort)(32768 * (rotation.Y + 1));
774 rz = (ushort)(32768 * (rotation.Z + 1));
775
776 //rot
777 bytes[i++] = (byte)(rx % 256);
778 bytes[i++] = (byte)((rx >> 8) % 256);
779 bytes[i++] = (byte)(ry % 256);
780 bytes[i++] = (byte)((ry >> 8) % 256);
781 bytes[i++] = (byte)(rz % 256);
782 bytes[i++] = (byte)((rz >> 8) % 256);
783 bytes[i++] = (byte)(rw % 256);
784 bytes[i++] = (byte)((rw >> 8) % 256);
785
786 //rotation vel
787 bytes[i++] = (byte)(ac % 256);
788 bytes[i++] = (byte)((ac >> 8) % 256);
789 bytes[i++] = (byte)(ac % 256);
790 bytes[i++] = (byte)((ac >> 8) % 256);
791 bytes[i++] = (byte)(ac % 256);
792 bytes[i++] = (byte)((ac >> 8) % 256);
793
794 dat.Data = bytes;
795 return dat;
796 }
797
798
799 /// <summary>
800 /// Create the ObjectDataBlock for a ObjectUpdatePacket (for a Primitive)
801 /// </summary>
802 /// <param name="primData"></param>
803 /// <returns></returns>
804 protected ObjectUpdatePacket.ObjectDataBlock CreatePrimUpdateBlock(PrimData primData, LLUUID textureID, uint flags)
805 {
806 ObjectUpdatePacket.ObjectDataBlock objupdate = new ObjectUpdatePacket.ObjectDataBlock();
807 this.SetDefaultPrimPacketValues(objupdate);
808 objupdate.UpdateFlags = flags;
809 this.SetPrimPacketShapeData(objupdate, primData, textureID);
810
811 return objupdate;
812 }
813
814 /// <summary>
815 /// Copy the data from a PrimData object to a ObjectUpdatePacket
816 /// </summary>
817 /// <param name="objectData"></param>
818 /// <param name="primData"></param>
819 protected void SetPrimPacketShapeData(ObjectUpdatePacket.ObjectDataBlock objectData, PrimData primData, LLUUID textureID)
820 {
821 LLObject.TextureEntry ntex = new LLObject.TextureEntry(textureID);
822 objectData.TextureEntry = ntex.ToBytes();
823 objectData.OwnerID = primData.OwnerID;
824 objectData.PCode = primData.PCode;
825 objectData.PathBegin = primData.PathBegin;
826 objectData.PathEnd = primData.PathEnd;
827 objectData.PathScaleX = primData.PathScaleX;
828 objectData.PathScaleY = primData.PathScaleY;
829 objectData.PathShearX = primData.PathShearX;
830 objectData.PathShearY = primData.PathShearY;
831 objectData.PathSkew = primData.PathSkew;
832 objectData.ProfileBegin = primData.ProfileBegin;
833 objectData.ProfileEnd = primData.ProfileEnd;
834 objectData.Scale = primData.Scale;
835 objectData.PathCurve = primData.PathCurve;
836 objectData.ProfileCurve = primData.ProfileCurve;
837 objectData.ParentID = primData.ParentID;
838 objectData.ProfileHollow = primData.ProfileHollow;
839 objectData.PathRadiusOffset = primData.PathRadiusOffset;
840 objectData.PathRevolutions = primData.PathRevolutions;
841 objectData.PathTaperX = primData.PathTaperX;
842 objectData.PathTaperY = primData.PathTaperY;
843 objectData.PathTwist = primData.PathTwist;
844 objectData.PathTwistBegin = primData.PathTwistBegin;
845 }
846
847 /// <summary>
848 /// Set some default values in a ObjectUpdatePacket
849 /// </summary>
850 /// <param name="objdata"></param>
851 protected void SetDefaultPrimPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata)
852 {
853 objdata.PSBlock = new byte[0];
854 objdata.ExtraParams = new byte[1];
855 objdata.MediaURL = new byte[0];
856 objdata.NameValue = new byte[0];
857 objdata.Text = new byte[0];
858 objdata.TextColor = new byte[4];
859 objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
860 objdata.JointPivot = new LLVector3(0, 0, 0);
861 objdata.Material = 3;
862 objdata.TextureAnim = new byte[0];
863 objdata.Sound = LLUUID.Zero;
864 objdata.State = 0;
865 objdata.Data = new byte[0];
866
867 objdata.ObjectData = new byte[60];
868 objdata.ObjectData[46] = 128;
869 objdata.ObjectData[47] = 63;
870 }
871
872
873 /// <summary>
874 ///
875 /// </summary>
876 /// <returns></returns>
877 protected ObjectUpdatePacket.ObjectDataBlock CreateDefaultAvatarPacket(byte[] textureEntry)
878 {
879 libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new ObjectUpdatePacket.ObjectDataBlock(); // new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i);
880
881 SetDefaultAvatarPacketValues(ref objdata);
882 objdata.UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24);
883 objdata.PathCurve = 16;
884 objdata.ProfileCurve = 1;
885 objdata.PathScaleX = 100;
886 objdata.PathScaleY = 100;
887 objdata.ParentID = 0;
888 objdata.OwnerID = LLUUID.Zero;
889 objdata.Scale = new LLVector3(1, 1, 1);
890 objdata.PCode = 47;
891 if (textureEntry != null)
892 {
893 objdata.TextureEntry = textureEntry;
894 }
895 System.Text.Encoding enc = System.Text.Encoding.ASCII;
896 libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
897 pos.X = 100f;
898 objdata.ID = 8880000;
899 objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
900 libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100f, 23f);
901 //objdata.FullID=user.AgentID;
902 byte[] pb = pos.GetBytes();
903 Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length);
904
905 return objdata;
906 }
907
908 /// <summary>
909 ///
910 /// </summary>
911 /// <param name="objdata"></param>
912 protected void SetDefaultAvatarPacketValues(ref ObjectUpdatePacket.ObjectDataBlock objdata)
913 {
914 objdata.PSBlock = new byte[0];
915 objdata.ExtraParams = new byte[1];
916 objdata.MediaURL = new byte[0];
917 objdata.NameValue = new byte[0];
918 objdata.Text = new byte[0];
919 objdata.TextColor = new byte[4];
920 objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0);
921 objdata.JointPivot = new LLVector3(0, 0, 0);
922 objdata.Material = 4;
923 objdata.TextureAnim = new byte[0];
924 objdata.Sound = LLUUID.Zero;
925 LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
926 objdata.TextureEntry = ntex.ToBytes();
927 objdata.State = 0;
928 objdata.Data = new byte[0];
929
930 objdata.ObjectData = new byte[76];
931 objdata.ObjectData[15] = 128;
932 objdata.ObjectData[16] = 63;
933 objdata.ObjectData[56] = 128;
934 objdata.ObjectData[61] = 102;
935 objdata.ObjectData[62] = 40;
936 objdata.ObjectData[63] = 61;
937 objdata.ObjectData[64] = 189;
938 }
939
940 /// <summary>
941 ///
942 /// </summary>
943 /// <param name="addPacket"></param>
944 /// <returns></returns>
945 protected PrimData CreatePrimFromObjectAdd(ObjectAddPacket addPacket)
946 {
947 PrimData PData = new PrimData();
948 PData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
949 PData.PCode = addPacket.ObjectData.PCode;
950 PData.PathBegin = addPacket.ObjectData.PathBegin;
951 PData.PathEnd = addPacket.ObjectData.PathEnd;
952 PData.PathScaleX = addPacket.ObjectData.PathScaleX;
953 PData.PathScaleY = addPacket.ObjectData.PathScaleY;
954 PData.PathShearX = addPacket.ObjectData.PathShearX;
955 PData.PathShearY = addPacket.ObjectData.PathShearY;
956 PData.PathSkew = addPacket.ObjectData.PathSkew;
957 PData.ProfileBegin = addPacket.ObjectData.ProfileBegin;
958 PData.ProfileEnd = addPacket.ObjectData.ProfileEnd;
959 PData.Scale = addPacket.ObjectData.Scale;
960 PData.PathCurve = addPacket.ObjectData.PathCurve;
961 PData.ProfileCurve = addPacket.ObjectData.ProfileCurve;
962 PData.ParentID = 0;
963 PData.ProfileHollow = addPacket.ObjectData.ProfileHollow;
964 PData.PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
965 PData.PathRevolutions = addPacket.ObjectData.PathRevolutions;
966 PData.PathTaperX = addPacket.ObjectData.PathTaperX;
967 PData.PathTaperY = addPacket.ObjectData.PathTaperY;
968 PData.PathTwist = addPacket.ObjectData.PathTwist;
969 PData.PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
970
971 return PData;
972 }
973 #endregion
974
975 }
976}
diff --git a/OpenSim/Region/ClientStack/ClientView.AgentAssetUpload.cs b/OpenSim/Region/ClientStack/ClientView.AgentAssetUpload.cs
new file mode 100644
index 0000000..bc6cc21
--- /dev/null
+++ b/OpenSim/Region/ClientStack/ClientView.AgentAssetUpload.cs
@@ -0,0 +1,358 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using OpenSim.Assets;
32using OpenSim.Framework.Types;
33using OpenSim.Framework.Interfaces;
34using OpenSim.Framework.Utilities;
35using OpenSim.Region.Caches;
36using libsecondlife;
37using libsecondlife.Packets;
38
39namespace OpenSim.Region.ClientStack
40{
41 partial class ClientView
42 {
43 public class AgentAssetUpload
44 {
45 private Dictionary<LLUUID, AssetTransaction> transactions = new Dictionary<LLUUID, AssetTransaction>();
46 private ClientView ourClient;
47 private AssetCache m_assetCache;
48 private InventoryCache m_inventoryCache;
49
50 public AgentAssetUpload(ClientView client, AssetCache assetCache, InventoryCache inventoryCache)
51 {
52 this.ourClient = client;
53 m_assetCache = assetCache;
54 m_inventoryCache = inventoryCache;
55 }
56
57 public void AddUpload(LLUUID transactionID, AssetBase asset)
58 {
59 AssetTransaction upload = new AssetTransaction();
60 lock (this.transactions)
61 {
62 upload.Asset = asset;
63 upload.TransactionID = transactionID;
64 this.transactions.Add(transactionID, upload);
65 }
66 if (upload.Asset.Data.Length > 2)
67 {
68 //is complete
69 upload.UploadComplete = true;
70 AssetUploadCompletePacket response = new AssetUploadCompletePacket();
71 response.AssetBlock.Type = asset.Type;
72 response.AssetBlock.Success = true;
73 response.AssetBlock.UUID = transactionID.Combine(this.ourClient.SecureSessionID);
74 this.ourClient.OutPacket(response);
75 m_assetCache.AddAsset(asset);
76 }
77 else
78 {
79 upload.UploadComplete = false;
80 upload.XferID = Util.GetNextXferID();
81 RequestXferPacket xfer = new RequestXferPacket();
82 xfer.XferID.ID = upload.XferID;
83 xfer.XferID.VFileType = upload.Asset.Type;
84 xfer.XferID.VFileID = transactionID.Combine(this.ourClient.SecureSessionID);
85 xfer.XferID.FilePath = 0;
86 xfer.XferID.Filename = new byte[0];
87 this.ourClient.OutPacket(xfer);
88 }
89
90 }
91
92 public AssetBase GetUpload(LLUUID transactionID)
93 {
94 if (this.transactions.ContainsKey(transactionID))
95 {
96 return this.transactions[transactionID].Asset;
97 }
98
99 return null;
100 }
101
102 public void HandleUploadPacket(AssetUploadRequestPacket pack, LLUUID assetID)
103 {
104 // Console.Write("asset upload request , type = " + pack.AssetBlock.Type.ToString());
105 AssetBase asset = null;
106 if (pack.AssetBlock.Type == 0)
107 {
108
109 //first packet for transaction
110 asset = new AssetBase();
111 asset.FullID = assetID;
112 asset.Type = pack.AssetBlock.Type;
113 asset.InvType = asset.Type;
114 asset.Name = "UploadedTexture" + Util.RandomClass.Next(1, 1000).ToString("000");
115 asset.Data = pack.AssetBlock.AssetData;
116
117
118 }
119 else if (pack.AssetBlock.Type == 13 | pack.AssetBlock.Type == 5 | pack.AssetBlock.Type == 7)
120 {
121
122 asset = new AssetBase();
123 asset.FullID = assetID;
124 // Console.WriteLine("skin asset id is " + assetID.ToStringHyphenated());
125 asset.Type = pack.AssetBlock.Type;
126 asset.InvType = asset.Type;
127 asset.Name = "NewClothing" + Util.RandomClass.Next(1, 1000).ToString("000");
128 asset.Data = pack.AssetBlock.AssetData;
129
130
131 }
132
133 if (asset != null)
134 {
135 this.AddUpload(pack.AssetBlock.TransactionID, asset);
136 }
137 else
138 {
139
140 //currently we don't support this asset type
141 //so lets just tell the client that the upload is complete
142 AssetUploadCompletePacket response = new AssetUploadCompletePacket();
143 response.AssetBlock.Type = pack.AssetBlock.Type;
144 response.AssetBlock.Success = true;
145 response.AssetBlock.UUID = pack.AssetBlock.TransactionID.Combine(this.ourClient.SecureSessionID);
146 this.ourClient.OutPacket(response);
147 }
148
149 }
150
151 #region Xfer packet system for larger uploads
152
153 public void HandleXferPacket(SendXferPacketPacket xferPacket)
154 {
155 lock (this.transactions)
156 {
157 foreach (AssetTransaction trans in this.transactions.Values)
158 {
159 if (trans.XferID == xferPacket.XferID.ID)
160 {
161 if (trans.Asset.Data.Length > 1)
162 {
163 byte[] newArray = new byte[trans.Asset.Data.Length + xferPacket.DataPacket.Data.Length];
164 Array.Copy(trans.Asset.Data, 0, newArray, 0, trans.Asset.Data.Length);
165 Array.Copy(xferPacket.DataPacket.Data, 0, newArray, trans.Asset.Data.Length, xferPacket.DataPacket.Data.Length);
166 trans.Asset.Data = newArray;
167 }
168 else
169 {
170 byte[] newArray = new byte[xferPacket.DataPacket.Data.Length - 4];
171 Array.Copy(xferPacket.DataPacket.Data, 4, newArray, 0, xferPacket.DataPacket.Data.Length - 4);
172 trans.Asset.Data = newArray;
173 }
174
175 if ((xferPacket.XferID.Packet & 2147483648) != 0)
176 {
177 //end of transfer
178 trans.UploadComplete = true;
179 AssetUploadCompletePacket response = new AssetUploadCompletePacket();
180 response.AssetBlock.Type = trans.Asset.Type;
181 response.AssetBlock.Success = true;
182 response.AssetBlock.UUID = trans.TransactionID.Combine(this.ourClient.SecureSessionID);
183 this.ourClient.OutPacket(response);
184
185 m_assetCache.AddAsset(trans.Asset);
186 //check if we should add it to inventory
187 if (trans.AddToInventory)
188 {
189 // m_assetCache.AddAsset(trans.Asset);
190 m_inventoryCache.AddNewInventoryItem(this.ourClient, trans.InventFolder, trans.Asset);
191 }
192
193
194 }
195 break;
196 }
197
198 }
199 }
200
201 ConfirmXferPacketPacket confirmXfer = new ConfirmXferPacketPacket();
202 confirmXfer.XferID.ID = xferPacket.XferID.ID;
203 confirmXfer.XferID.Packet = xferPacket.XferID.Packet;
204 this.ourClient.OutPacket(confirmXfer);
205 }
206
207 #endregion
208
209 public AssetBase AddUploadToAssetCache(LLUUID transactionID)
210 {
211 AssetBase asset = null;
212 if (this.transactions.ContainsKey(transactionID))
213 {
214 AssetTransaction trans = this.transactions[transactionID];
215 if (trans.UploadComplete)
216 {
217 m_assetCache.AddAsset(trans.Asset);
218 asset = trans.Asset;
219 }
220 }
221
222 return asset;
223 }
224
225 public void CreateInventoryItem(CreateInventoryItemPacket packet)
226 {
227 if (this.transactions.ContainsKey(packet.InventoryBlock.TransactionID))
228 {
229 AssetTransaction trans = this.transactions[packet.InventoryBlock.TransactionID];
230 trans.Asset.Description = Util.FieldToString(packet.InventoryBlock.Description);
231 trans.Asset.Name = Util.FieldToString(packet.InventoryBlock.Name);
232 trans.Asset.Type = packet.InventoryBlock.Type;
233 trans.Asset.InvType = packet.InventoryBlock.InvType;
234 if (trans.UploadComplete)
235 {
236 //already complete so we can add it to the inventory
237 //m_assetCache.AddAsset(trans.Asset);
238 m_inventoryCache.AddNewInventoryItem(this.ourClient, packet.InventoryBlock.FolderID, trans.Asset);
239 }
240 else
241 {
242 trans.AddToInventory = true;
243 trans.InventFolder = packet.InventoryBlock.FolderID;
244 }
245 }
246 }
247
248 private class AssetTransaction
249 {
250 public uint XferID;
251 public AssetBase Asset;
252 public bool AddToInventory;
253 public LLUUID InventFolder = LLUUID.Zero;
254 public bool UploadComplete = false;
255 public LLUUID TransactionID = LLUUID.Zero;
256
257 public AssetTransaction()
258 {
259
260 }
261 }
262
263 //new class , not currently used.
264 public class AssetXferUploader
265 {
266 private IClientAPI ourClient;
267
268 public bool UploadComplete = false;
269
270 public bool AddToInventory;
271 public LLUUID InventFolder = LLUUID.Zero;
272
273 public uint XferID;
274 public AssetBase Asset;
275 public LLUUID TransactionID = LLUUID.Zero;
276
277
278 public AssetXferUploader(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data)
279 {
280 ourClient = remoteClient;
281 Asset = new AssetBase();
282 Asset.FullID = assetID;
283 Asset.InvType = type;
284 Asset.Type = type;
285 Asset.Data = data;
286 Asset.Name = "blank";
287 Asset.Description = "empty";
288 TransactionID = transaction;
289
290 if (Asset.Data.Length > 2)
291 {
292 //data block should only have data in it, if there is no more data to be uploaded
293 this.SendCompleteMessage();
294 }
295 else
296 {
297 this.ReqestStartXfer();
298 }
299 }
300
301 protected void SendCompleteMessage()
302 {
303 UploadComplete = true;
304 AssetUploadCompletePacket response = new AssetUploadCompletePacket();
305 response.AssetBlock.Type = Asset.Type;
306 response.AssetBlock.Success = true;
307 response.AssetBlock.UUID = Asset.FullID;
308 this.ourClient.OutPacket(response);
309
310 //TODO trigger event
311 }
312
313 protected void ReqestStartXfer()
314 {
315 UploadComplete = false;
316 XferID = Util.GetNextXferID();
317 RequestXferPacket xfer = new RequestXferPacket();
318 xfer.XferID.ID = XferID;
319 xfer.XferID.VFileType = Asset.Type;
320 xfer.XferID.VFileID = Asset.FullID;
321 xfer.XferID.FilePath = 0;
322 xfer.XferID.Filename = new byte[0];
323 this.ourClient.OutPacket(xfer);
324 }
325
326 public void HandleXferPacket(uint xferID, uint packetID, byte[] data)
327 {
328 if (XferID == xferID)
329 {
330 if (Asset.Data.Length > 1)
331 {
332 byte[] newArray = new byte[Asset.Data.Length + data.Length];
333 Array.Copy(Asset.Data, 0, newArray, 0, Asset.Data.Length);
334 Array.Copy(data, 0, newArray, Asset.Data.Length, data.Length);
335 Asset.Data = newArray;
336 }
337 else
338 {
339 byte[] newArray = new byte[data.Length - 4];
340 Array.Copy(data, 4, newArray, 0, data.Length - 4);
341 Asset.Data = newArray;
342 }
343
344 ConfirmXferPacketPacket confirmXfer = new ConfirmXferPacketPacket();
345 confirmXfer.XferID.ID = xferID;
346 confirmXfer.XferID.Packet = packetID;
347 this.ourClient.OutPacket(confirmXfer);
348
349 if ((packetID & 2147483648) != 0)
350 {
351 this.SendCompleteMessage();
352 }
353 }
354 }
355 }
356 }
357 }
358}
diff --git a/OpenSim/Region/ClientStack/ClientView.PacketHandlers.cs b/OpenSim/Region/ClientStack/ClientView.PacketHandlers.cs
new file mode 100644
index 0000000..0456e3c
--- /dev/null
+++ b/OpenSim/Region/ClientStack/ClientView.PacketHandlers.cs
@@ -0,0 +1,196 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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*/
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using libsecondlife;
32using libsecondlife.Packets;
33using Nwc.XmlRpc;
34using System.Net;
35using System.Net.Sockets;
36using System.IO;
37using System.Threading;
38using System.Timers;
39using OpenSim.Framework.Interfaces;
40using OpenSim.Framework.Types;
41using OpenSim.Framework.Inventory;
42using OpenSim.Framework.Utilities;
43using OpenSim.Assets;
44
45namespace OpenSim.Region.ClientStack
46{
47 public partial class ClientView
48 {
49 protected virtual void RegisterLocalPacketHandlers()
50 {
51 this.AddLocalPacketHandler(PacketType.LogoutRequest, this.Logout);
52 this.AddLocalPacketHandler(PacketType.AgentCachedTexture, this.AgentTextureCached);
53 this.AddLocalPacketHandler(PacketType.MultipleObjectUpdate, this.MultipleObjUpdate);
54 }
55
56 protected virtual bool Logout(ClientView simClient, Packet packet)
57 {
58 OpenSim.Framework.Console.MainLog.Instance.Verbose( "OpenSimClient.cs:ProcessInPacket() - Got a logout request");
59 //send reply to let the client logout
60 LogoutReplyPacket logReply = new LogoutReplyPacket();
61 logReply.AgentData.AgentID = this.AgentID;
62 logReply.AgentData.SessionID = this.SessionID;
63 logReply.InventoryData = new LogoutReplyPacket.InventoryDataBlock[1];
64 logReply.InventoryData[0] = new LogoutReplyPacket.InventoryDataBlock();
65 logReply.InventoryData[0].ItemID = LLUUID.Zero;
66 OutPacket(logReply);
67 //tell all clients to kill our object
68 KillObjectPacket kill = new KillObjectPacket();
69 kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
70 kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
71 // kill.ObjectData[0].ID = this.ClientAvatar.localid;
72 foreach (ClientView client in m_clientThreads.Values)
73 {
74 client.OutPacket(kill);
75 }
76
77 this.m_inventoryCache.ClientLeaving(this.AgentID, null);
78
79
80 // m_gridServer.LogoutSession(this.SessionID, this.AgentID, this.CircuitCode);
81 /*lock (m_world.Entities)
82 {
83 m_world.Entities.Remove(this.AgentID);
84 }*/
85 // m_world.RemoveViewerAgent(this);
86 //need to do other cleaning up here too
87 m_clientThreads.Remove(this.CircuitCode);
88 m_networkServer.RemoveClientCircuit(this.CircuitCode);
89 this.ClientThread.Abort();
90 return true;
91 }
92
93 protected bool AgentTextureCached(ClientView simclient, Packet packet)
94 {
95 // Console.WriteLine(packet.ToString());
96 AgentCachedTexturePacket chechedtex = (AgentCachedTexturePacket)packet;
97 AgentCachedTextureResponsePacket cachedresp = new AgentCachedTextureResponsePacket();
98 cachedresp.AgentData.AgentID = this.AgentID;
99 cachedresp.AgentData.SessionID = this.SessionID;
100 cachedresp.AgentData.SerialNum = this.cachedtextureserial;
101 this.cachedtextureserial++;
102 cachedresp.WearableData = new AgentCachedTextureResponsePacket.WearableDataBlock[chechedtex.WearableData.Length];
103 for (int i = 0; i < chechedtex.WearableData.Length; i++)
104 {
105 cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
106 cachedresp.WearableData[i].TextureIndex = chechedtex.WearableData[i].TextureIndex;
107 cachedresp.WearableData[i].TextureID = LLUUID.Zero;
108 cachedresp.WearableData[i].HostName = new byte[0];
109 }
110 this.OutPacket(cachedresp);
111 return true;
112 }
113
114 protected bool MultipleObjUpdate(ClientView simClient, Packet packet)
115 {
116 MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)packet;
117 for (int i = 0; i < multipleupdate.ObjectData.Length; i++)
118 {
119 if (multipleupdate.ObjectData[i].Type == 9) //change position
120 {
121 if (OnUpdatePrimPosition != null)
122 {
123 libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0);
124 OnUpdatePrimPosition(multipleupdate.ObjectData[i].ObjectLocalID, pos, this);
125 }
126 //should update stored position of the prim
127 }
128 else if (multipleupdate.ObjectData[i].Type == 10)//rotation
129 {
130 if (OnUpdatePrimRotation != null)
131 {
132 libsecondlife.LLQuaternion rot = new LLQuaternion(multipleupdate.ObjectData[i].Data, 0, true);
133 OnUpdatePrimRotation(multipleupdate.ObjectData[i].ObjectLocalID, rot, this);
134 }
135 }
136 else if (multipleupdate.ObjectData[i].Type == 13)//scale
137 {
138 if (OnUpdatePrimScale != null)
139 {
140 libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 12);
141 OnUpdatePrimScale(multipleupdate.ObjectData[i].ObjectLocalID, scale, this);
142 }
143 }
144 }
145 return true;
146 }
147
148 public void RequestMapLayer()
149 {
150 //should be getting the map layer from the grid server
151 //send a layer covering the 800,800 - 1200,1200 area (should be covering the requested area)
152 MapLayerReplyPacket mapReply = new MapLayerReplyPacket();
153 mapReply.AgentData.AgentID = this.AgentID;
154 mapReply.AgentData.Flags = 0;
155 mapReply.LayerData = new MapLayerReplyPacket.LayerDataBlock[1];
156 mapReply.LayerData[0] = new MapLayerReplyPacket.LayerDataBlock();
157 mapReply.LayerData[0].Bottom = 0;
158 mapReply.LayerData[0].Left = 0;
159 mapReply.LayerData[0].Top = 30000;
160 mapReply.LayerData[0].Right = 30000;
161 mapReply.LayerData[0].ImageID = new LLUUID("00000000-0000-0000-9999-000000000006");
162 this.OutPacket(mapReply);
163 }
164
165 public void RequestMapBlocks(int minX, int minY, int maxX, int maxY)
166 {
167 /*
168 IList simMapProfiles = m_gridServer.RequestMapBlocks(minX, minY, maxX, maxY);
169 MapBlockReplyPacket mbReply = new MapBlockReplyPacket();
170 mbReply.AgentData.AgentID = this.AgentID;
171 int len;
172 if (simMapProfiles == null)
173 len = 0;
174 else
175 len = simMapProfiles.Count;
176
177 mbReply.Data = new MapBlockReplyPacket.DataBlock[len];
178 int iii;
179 for (iii = 0; iii < len; iii++)
180 {
181 Hashtable mp = (Hashtable)simMapProfiles[iii];
182 mbReply.Data[iii] = new MapBlockReplyPacket.DataBlock();
183 mbReply.Data[iii].Name = System.Text.Encoding.UTF8.GetBytes((string)mp["name"]);
184 mbReply.Data[iii].Access = System.Convert.ToByte(mp["access"]);
185 mbReply.Data[iii].Agents = System.Convert.ToByte(mp["agents"]);
186 mbReply.Data[iii].MapImageID = new LLUUID((string)mp["map-image-id"]);
187 mbReply.Data[iii].RegionFlags = System.Convert.ToUInt32(mp["region-flags"]);
188 mbReply.Data[iii].WaterHeight = System.Convert.ToByte(mp["water-height"]);
189 mbReply.Data[iii].X = System.Convert.ToUInt16(mp["x"]);
190 mbReply.Data[iii].Y = System.Convert.ToUInt16(mp["y"]);
191 }
192 this.OutPacket(mbReply);
193 */
194 }
195 }
196}
diff --git a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs
new file mode 100644
index 0000000..794ce79
--- /dev/null
+++ b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs
@@ -0,0 +1,556 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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*/
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using libsecondlife;
32using libsecondlife.Packets;
33using Nwc.XmlRpc;
34using System.Net;
35using System.Net.Sockets;
36using System.IO;
37using System.Threading;
38using System.Timers;
39using OpenSim.Framework.Interfaces;
40using OpenSim.Framework.Types;
41using OpenSim.Framework.Inventory;
42using OpenSim.Framework.Utilities;
43using OpenSim.Assets;
44
45namespace OpenSim.Region.ClientStack
46{
47 public partial class ClientView
48 {
49 protected override void ProcessInPacket(Packet Pack)
50 {
51 ack_pack(Pack);
52 if (debug)
53 {
54 if (Pack.Type != PacketType.AgentUpdate)
55 {
56 Console.WriteLine(Pack.Type.ToString());
57 }
58 }
59
60 if (this.ProcessPacketMethod(Pack))
61 {
62 //there is a handler registered that handled this packet type
63 return;
64 }
65 else
66 {
67 System.Text.Encoding _enc = System.Text.Encoding.ASCII;
68
69 switch (Pack.Type)
70 {
71 case PacketType.ViewerEffect:
72 ViewerEffectPacket viewer = (ViewerEffectPacket)Pack;
73 foreach (ClientView client in m_clientThreads.Values)
74 {
75 if (client.AgentID != this.AgentID)
76 {
77 viewer.AgentData.AgentID = client.AgentID;
78 viewer.AgentData.SessionID = client.SessionID;
79 client.OutPacket(viewer);
80 }
81 }
82 break;
83
84 #region World/Avatar
85 case PacketType.ChatFromViewer:
86 ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack;
87 if (Util.FieldToString(inchatpack.ChatData.Message) == "")
88 {
89 //empty message so don't bother with it
90 break;
91 }
92 string fromName = ""; //ClientAvatar.firstname + " " + ClientAvatar.lastname;
93 byte[] message = inchatpack.ChatData.Message;
94 byte type = inchatpack.ChatData.Type;
95 LLVector3 fromPos = new LLVector3(); // ClientAvatar.Pos;
96 LLUUID fromAgentID = AgentID;
97 if (OnChatFromViewer != null)
98 {
99 this.OnChatFromViewer(message, type, fromPos, fromName, fromAgentID);
100 }
101 break;
102 case PacketType.RezObject:
103 RezObjectPacket rezPacket = (RezObjectPacket)Pack;
104 AgentInventory inven = this.m_inventoryCache.GetAgentsInventory(this.AgentID);
105 if (inven != null)
106 {
107 if (inven.InventoryItems.ContainsKey(rezPacket.InventoryData.ItemID))
108 {
109 AssetBase asset = this.m_assetCache.GetAsset(inven.InventoryItems[rezPacket.InventoryData.ItemID].AssetID);
110 if (asset != null)
111 {
112 if (OnRezObject != null)
113 {
114 this.OnRezObject(asset, rezPacket.RezData.RayEnd);
115 this.m_inventoryCache.DeleteInventoryItem(this, rezPacket.InventoryData.ItemID);
116 }
117 }
118 }
119 }
120 break;
121 case PacketType.DeRezObject:
122 if (OnDeRezObject != null)
123 {
124 OnDeRezObject(Pack, this);
125 }
126 break;
127 case PacketType.ModifyLand:
128 ModifyLandPacket modify = (ModifyLandPacket)Pack;
129 if (modify.ParcelData.Length > 0)
130 {
131 if (OnModifyTerrain != null)
132 {
133 OnModifyTerrain(modify.ModifyBlock.Height, modify.ModifyBlock.Seconds, modify.ModifyBlock.BrushSize,
134 modify.ModifyBlock.Action, modify.ParcelData[0].North, modify.ParcelData[0].West);
135 }
136 }
137 break;
138 case PacketType.RegionHandshakeReply:
139 if (OnRegionHandShakeReply != null)
140 {
141 OnRegionHandShakeReply(this);
142 }
143 break;
144 case PacketType.AgentWearablesRequest:
145 if (OnRequestWearables != null)
146 {
147 OnRequestWearables(this);
148 }
149 if (OnRequestAvatarsData != null)
150 {
151 OnRequestAvatarsData(this);
152 }
153 break;
154 case PacketType.AgentSetAppearance:
155 AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack;
156 if (OnSetAppearance != null)
157 {
158 OnSetAppearance(appear.ObjectData.TextureEntry, appear.VisualParam);
159 }
160 break;
161 case PacketType.CompleteAgentMovement:
162 if (OnCompleteMovementToRegion != null)
163 {
164 OnCompleteMovementToRegion();
165 }
166 break;
167 case PacketType.AgentUpdate:
168 if (OnAgentUpdate != null)
169 {
170 AgentUpdatePacket agenUpdate = (AgentUpdatePacket) Pack;
171 OnAgentUpdate(this, agenUpdate.AgentData.ControlFlags, agenUpdate.AgentData.BodyRotation );
172 }
173 break;
174 case PacketType.AgentAnimation:
175 if (!m_child)
176 {
177 AgentAnimationPacket AgentAni = (AgentAnimationPacket)Pack;
178 for (int i = 0; i < AgentAni.AnimationList.Length; i++)
179 {
180 if (AgentAni.AnimationList[i].StartAnim)
181 {
182 if (OnStartAnim != null)
183 {
184 OnStartAnim(AgentAni.AnimationList[i].AnimID, 1);
185 }
186 }
187 }
188 }
189 break;
190
191 #endregion
192
193 #region Objects/Prims
194 case PacketType.ObjectLink:
195 // OpenSim.Framework.Console.MainLog.Instance.Verbose( Pack.ToString());
196 ObjectLinkPacket link = (ObjectLinkPacket)Pack;
197 uint parentprimid = 0;
198 List<uint> childrenprims = new List<uint>();
199 if (link.ObjectData.Length > 1)
200 {
201 parentprimid = link.ObjectData[0].ObjectLocalID;
202
203 for (int i = 1; i < link.ObjectData.Length; i++)
204 {
205 childrenprims.Add(link.ObjectData[i].ObjectLocalID);
206 }
207 }
208 if (OnLinkObjects != null)
209 {
210 OnLinkObjects(parentprimid, childrenprims);
211 }
212 break;
213 case PacketType.ObjectAdd:
214 // m_world.AddNewPrim((ObjectAddPacket)Pack, this);
215 if (OnAddPrim != null)
216 {
217 OnAddPrim(Pack, this);
218 }
219 break;
220 case PacketType.ObjectShape:
221 ObjectShapePacket shape = (ObjectShapePacket)Pack;
222 for (int i = 0; i < shape.ObjectData.Length; i++)
223 {
224 if (OnUpdatePrimShape != null)
225 {
226 OnUpdatePrimShape(shape.ObjectData[i].ObjectLocalID, shape.ObjectData[i]);
227 }
228 }
229 break;
230 case PacketType.ObjectSelect:
231 ObjectSelectPacket incomingselect = (ObjectSelectPacket)Pack;
232 for (int i = 0; i < incomingselect.ObjectData.Length; i++)
233 {
234 if (OnObjectSelect != null)
235 {
236 OnObjectSelect(incomingselect.ObjectData[i].ObjectLocalID, this);
237 }
238 }
239 break;
240 case PacketType.ObjectFlagUpdate:
241 ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket)Pack;
242 if (OnUpdatePrimFlags != null)
243 {
244 OnUpdatePrimFlags(flags.AgentData.ObjectLocalID, Pack, this);
245 }
246 break;
247 case PacketType.ObjectImage:
248 ObjectImagePacket imagePack = (ObjectImagePacket)Pack;
249 for (int i = 0; i < imagePack.ObjectData.Length; i++)
250 {
251 if (OnUpdatePrimTexture != null)
252 {
253 OnUpdatePrimTexture(imagePack.ObjectData[i].ObjectLocalID, imagePack.ObjectData[i].TextureEntry, this);
254 }
255 }
256 break;
257 case PacketType.ObjectGrab:
258 ObjectGrabPacket grap = (ObjectGrabPacket)Pack;
259 if (OnGrapObject != null)
260 {
261 OnGrapObject(grap.ObjectData.LocalID, grap.ObjectData.GrabOffset, this);
262 }
263 break;
264 case PacketType.ObjectGrabUpdate:
265 ObjectGrabUpdatePacket grapUpdate = (ObjectGrabUpdatePacket)Pack;
266 if (OnGrapUpdate != null)
267 {
268 OnGrapUpdate(grapUpdate.ObjectData.ObjectID, grapUpdate.ObjectData.GrabOffsetInitial, grapUpdate.ObjectData.GrabPosition, this);
269 }
270 break;
271 case PacketType.ObjectDeGrab:
272 ObjectDeGrabPacket deGrap = (ObjectDeGrabPacket)Pack;
273 if (OnDeGrapObject != null)
274 {
275 OnDeGrapObject(deGrap.ObjectData.LocalID, this);
276 }
277 break;
278 #endregion
279
280 #region Inventory/Asset/Other related packets
281 case PacketType.RequestImage:
282 RequestImagePacket imageRequest = (RequestImagePacket)Pack;
283 for (int i = 0; i < imageRequest.RequestImage.Length; i++)
284 {
285 m_assetCache.AddTextureRequest(this, imageRequest.RequestImage[i].Image);
286 }
287 break;
288 case PacketType.TransferRequest:
289 //Console.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got transfer request");
290 TransferRequestPacket transfer = (TransferRequestPacket)Pack;
291 m_assetCache.AddAssetRequest(this, transfer);
292 break;
293 case PacketType.AssetUploadRequest:
294 AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack;
295 this.UploadAssets.HandleUploadPacket(request, request.AssetBlock.TransactionID.Combine(this.SecureSessionID));
296 break;
297 case PacketType.RequestXfer:
298 //Console.WriteLine(Pack.ToString());
299 break;
300 case PacketType.SendXferPacket:
301 this.UploadAssets.HandleXferPacket((SendXferPacketPacket)Pack);
302 break;
303 case PacketType.CreateInventoryFolder:
304 CreateInventoryFolderPacket invFolder = (CreateInventoryFolderPacket)Pack;
305 m_inventoryCache.CreateNewInventoryFolder(this, invFolder.FolderData.FolderID, (ushort)invFolder.FolderData.Type, Util.FieldToString(invFolder.FolderData.Name), invFolder.FolderData.ParentID);
306 //Console.WriteLine(Pack.ToString());
307 break;
308 case PacketType.CreateInventoryItem:
309 //Console.WriteLine(Pack.ToString());
310 CreateInventoryItemPacket createItem = (CreateInventoryItemPacket)Pack;
311 if (createItem.InventoryBlock.TransactionID != LLUUID.Zero)
312 {
313 this.UploadAssets.CreateInventoryItem(createItem);
314 }
315 else
316 {
317 // Console.Write(Pack.ToString());
318 this.CreateInventoryItem(createItem);
319 }
320 break;
321 case PacketType.FetchInventory:
322 //Console.WriteLine("fetch item packet");
323 FetchInventoryPacket FetchInventory = (FetchInventoryPacket)Pack;
324 m_inventoryCache.FetchInventory(this, FetchInventory);
325 break;
326 case PacketType.FetchInventoryDescendents:
327 FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack;
328 m_inventoryCache.FetchInventoryDescendents(this, Fetch);
329 break;
330 case PacketType.UpdateInventoryItem:
331 UpdateInventoryItemPacket update = (UpdateInventoryItemPacket)Pack;
332 //Console.WriteLine(Pack.ToString());
333 for (int i = 0; i < update.InventoryData.Length; i++)
334 {
335 if (update.InventoryData[i].TransactionID != LLUUID.Zero)
336 {
337 AssetBase asset = m_assetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionID));
338 if (asset != null)
339 {
340 // Console.WriteLine("updating inventory item, found asset" + asset.FullID.ToStringHyphenated() + " already in cache");
341 m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
342 }
343 else
344 {
345 asset = this.UploadAssets.AddUploadToAssetCache(update.InventoryData[i].TransactionID);
346 if (asset != null)
347 {
348 //Console.WriteLine("updating inventory item, adding asset" + asset.FullID.ToStringHyphenated() + " to cache");
349 m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset);
350 }
351 else
352 {
353 //Console.WriteLine("trying to update inventory item, but asset is null");
354 }
355 }
356 }
357 else
358 {
359 m_inventoryCache.UpdateInventoryItemDetails(this, update.InventoryData[i].ItemID, update.InventoryData[i]); ;
360 }
361 }
362 break;
363 case PacketType.RequestTaskInventory:
364 // Console.WriteLine(Pack.ToString());
365 RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack;
366 ReplyTaskInventoryPacket replytask = new ReplyTaskInventoryPacket();
367 bool foundent = false;
368 /* foreach (Entity ent in m_world.Entities.Values)
369 {
370 if (ent.localid == requesttask.InventoryData.LocalID)
371 {
372 replytask.InventoryData.TaskID = ent.uuid;
373 replytask.InventoryData.Serial = 0;
374 replytask.InventoryData.Filename = new byte[0];
375 foundent = true;
376 }
377 }
378 if (foundent)
379 {
380 this.OutPacket(replytask);
381 }*/
382 break;
383 case PacketType.UpdateTaskInventory:
384 // Console.WriteLine(Pack.ToString());
385 UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack;
386 AgentInventory myinventory = this.m_inventoryCache.GetAgentsInventory(this.AgentID);
387 /*if (myinventory != null)
388 {
389 if (updatetask.UpdateData.Key == 0)
390 {
391 if (myinventory.InventoryItems[updatetask.InventoryData.ItemID] != null)
392 {
393 if (myinventory.InventoryItems[updatetask.InventoryData.ItemID].Type == 7)
394 {
395 LLUUID noteaid = myinventory.InventoryItems[updatetask.InventoryData.ItemID].AssetID;
396 AssetBase assBase = this.m_assetCache.GetAsset(noteaid);
397 if (assBase != null)
398 {
399 foreach (Entity ent in m_world.Entities.Values)
400 {
401 if (ent.localid == updatetask.UpdateData.LocalID)
402 {
403 if (ent is OpenSim.world.Primitive)
404 {
405 this.m_world.AddScript(ent, Util.FieldToString(assBase.Data));
406 }
407 }
408 }
409 }
410 }
411 }
412 }
413 }*/
414 break;
415 case PacketType.MapLayerRequest:
416 this.RequestMapLayer();
417 break;
418 case PacketType.MapBlockRequest:
419 MapBlockRequestPacket MapRequest = (MapBlockRequestPacket)Pack;
420 if (OnRequestMapBlocks != null)
421 {
422 OnRequestMapBlocks(this, MapRequest.PositionData.MinX, MapRequest.PositionData.MinY, MapRequest.PositionData.MaxX, MapRequest.PositionData.MaxY);
423 }
424 break;
425 case PacketType.TeleportLandmarkRequest:
426 TeleportLandmarkRequestPacket tpReq = (TeleportLandmarkRequestPacket)Pack;
427
428 TeleportStartPacket tpStart = new TeleportStartPacket();
429 tpStart.Info.TeleportFlags = 8; // tp via lm
430 this.OutPacket(tpStart);
431
432 TeleportProgressPacket tpProgress = new TeleportProgressPacket();
433 tpProgress.Info.Message = (new System.Text.ASCIIEncoding()).GetBytes("sending_landmark");
434 tpProgress.Info.TeleportFlags = 8;
435 tpProgress.AgentData.AgentID = tpReq.Info.AgentID;
436 this.OutPacket(tpProgress);
437
438 // Fetch landmark
439 LLUUID lmid = tpReq.Info.LandmarkID;
440 AssetBase lma = this.m_assetCache.GetAsset(lmid);
441 if (lma != null)
442 {
443 AssetLandmark lm = new AssetLandmark(lma);
444
445 if (lm.RegionID == m_regionData.SimUUID)
446 {
447 TeleportLocalPacket tpLocal = new TeleportLocalPacket();
448
449 tpLocal.Info.AgentID = tpReq.Info.AgentID;
450 tpLocal.Info.TeleportFlags = 8; // Teleport via landmark
451 tpLocal.Info.LocationID = 2;
452 tpLocal.Info.Position = lm.Position;
453 OutPacket(tpLocal);
454 }
455 else
456 {
457 TeleportCancelPacket tpCancel = new TeleportCancelPacket();
458 tpCancel.Info.AgentID = tpReq.Info.AgentID;
459 tpCancel.Info.SessionID = tpReq.Info.SessionID;
460 OutPacket(tpCancel);
461 }
462 }
463 else
464 {
465 Console.WriteLine("Cancelling Teleport - fetch asset not yet implemented");
466
467 TeleportCancelPacket tpCancel = new TeleportCancelPacket();
468 tpCancel.Info.AgentID = tpReq.Info.AgentID;
469 tpCancel.Info.SessionID = tpReq.Info.SessionID;
470 OutPacket(tpCancel);
471 }
472 break;
473 case PacketType.TeleportLocationRequest:
474 TeleportLocationRequestPacket tpLocReq = (TeleportLocationRequestPacket)Pack;
475 // Console.WriteLine(tpLocReq.ToString());
476
477 if (OnTeleportLocationRequest != null)
478 {
479 OnTeleportLocationRequest(this, tpLocReq.Info.RegionHandle, tpLocReq.Info.Position, tpLocReq.Info.LookAt, 16);
480 }
481 else
482 {
483 //no event handler so cancel request
484 TeleportCancelPacket tpCancel = new TeleportCancelPacket();
485 tpCancel.Info.SessionID = tpLocReq.AgentData.SessionID;
486 tpCancel.Info.AgentID = tpLocReq.AgentData.AgentID;
487 OutPacket(tpCancel);
488 }
489 break;
490 #endregion
491
492 case PacketType.MoneyBalanceRequest:
493 this.SendMoneyBalance(LLUUID.Zero, true, new byte[0], 1000);
494 break;
495 case PacketType.UUIDNameRequest:
496 UUIDNameRequestPacket incoming = (UUIDNameRequestPacket)Pack;
497 foreach (UUIDNameRequestPacket.UUIDNameBlockBlock UUIDBlock in incoming.UUIDNameBlock)
498 {
499 OnNameFromUUIDRequest(UUIDBlock.ID, this);
500 }
501 break;
502 #region Parcel related packets
503 case PacketType.ParcelPropertiesRequest:
504 ParcelPropertiesRequestPacket propertiesRequest = (ParcelPropertiesRequestPacket)Pack;
505 if (OnParcelPropertiesRequest != null)
506 {
507 OnParcelPropertiesRequest((int)Math.Round(propertiesRequest.ParcelData.West), (int)Math.Round(propertiesRequest.ParcelData.South), (int)Math.Round(propertiesRequest.ParcelData.East), (int)Math.Round(propertiesRequest.ParcelData.North), propertiesRequest.ParcelData.SequenceID, propertiesRequest.ParcelData.SnapSelection, this);
508 }
509 break;
510 case PacketType.ParcelDivide:
511 ParcelDividePacket parcelDivide = (ParcelDividePacket)Pack;
512 if (OnParcelDivideRequest != null)
513 {
514 OnParcelDivideRequest((int)Math.Round(parcelDivide.ParcelData.West), (int)Math.Round(parcelDivide.ParcelData.South), (int)Math.Round(parcelDivide.ParcelData.East), (int)Math.Round(parcelDivide.ParcelData.North), this);
515 }
516 break;
517 case PacketType.ParcelJoin:
518 ParcelJoinPacket parcelJoin = (ParcelJoinPacket)Pack;
519 if (OnParcelJoinRequest != null)
520 {
521 OnParcelJoinRequest((int)Math.Round(parcelJoin.ParcelData.West), (int)Math.Round(parcelJoin.ParcelData.South), (int)Math.Round(parcelJoin.ParcelData.East), (int)Math.Round(parcelJoin.ParcelData.North), this);
522 }
523 break;
524 case PacketType.ParcelPropertiesUpdate:
525 ParcelPropertiesUpdatePacket updatePacket = (ParcelPropertiesUpdatePacket)Pack;
526 if (OnParcelPropertiesUpdateRequest != null)
527 {
528 OnParcelPropertiesUpdateRequest(updatePacket, this);
529 }
530 break;
531 #endregion
532
533 #region Estate Packets
534 case PacketType.EstateOwnerMessage:
535 EstateOwnerMessagePacket messagePacket = (EstateOwnerMessagePacket)Pack;
536 if (OnEstateOwnerMessage != null)
537 {
538 OnEstateOwnerMessage(messagePacket, this);
539 }
540 break;
541 #endregion
542
543 #region unimplemented handlers
544 case PacketType.AgentIsNowWearing:
545 // AgentIsNowWearingPacket wear = (AgentIsNowWearingPacket)Pack;
546 //Console.WriteLine(Pack.ToString());
547 break;
548 case PacketType.ObjectScale:
549 //OpenSim.Framework.Console.MainLog.Instance.Verbose( Pack.ToString());
550 break;
551 #endregion
552 }
553 }
554 }
555 }
556}
diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs
new file mode 100644
index 0000000..9c4462d
--- /dev/null
+++ b/OpenSim/Region/ClientStack/ClientView.cs
@@ -0,0 +1,273 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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*/
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using libsecondlife;
32using libsecondlife.Packets;
33using Nwc.XmlRpc;
34using System.Net;
35using System.Net.Sockets;
36using System.IO;
37using System.Threading;
38using System.Timers;
39using OpenSim.Framework;
40using OpenSim.Framework.Interfaces;
41using OpenSim.Framework.Types;
42using OpenSim.Framework.Inventory;
43using OpenSim.Framework.Utilities;
44using OpenSim.Assets;
45using OpenSim.Region.Caches;
46
47namespace OpenSim.Region.ClientStack
48{
49 public delegate bool PacketMethod(ClientView simClient, Packet packet);
50
51 /// <summary>
52 /// Handles new client connections
53 /// Constructor takes a single Packet and authenticates everything
54 /// </summary>
55 public partial class ClientView : ClientViewBase, IClientAPI
56 {
57 public static TerrainManager TerrainManager;
58
59 protected static Dictionary<PacketType, PacketMethod> PacketHandlers = new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients
60 protected Dictionary<PacketType, PacketMethod> m_packetHandlers = new Dictionary<PacketType, PacketMethod>(); //local handlers for this instance
61
62 public LLUUID AgentID;
63 public LLUUID SessionID;
64 public LLUUID SecureSessionID = LLUUID.Zero;
65 public string firstName;
66 public string lastName;
67 public bool m_child = false;
68 private UseCircuitCodePacket cirpack;
69 public Thread ClientThread;
70 public LLVector3 startpos;
71
72 private AgentAssetUpload UploadAssets;
73 private LLUUID newAssetFolder = LLUUID.Zero;
74 private bool debug = false;
75 protected IWorld m_world;
76 private Dictionary<uint, ClientView> m_clientThreads;
77 private AssetCache m_assetCache;
78 private InventoryCache m_inventoryCache;
79 private int cachedtextureserial = 0;
80 private RegionInfo m_regionData;
81 protected AuthenticateSessionsBase m_authenticateSessionsHandler;
82
83 public ClientView(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, Dictionary<uint, ClientView> clientThreads, IWorld world, AssetCache assetCache, PacketServer packServer, InventoryCache inventoryCache, AuthenticateSessionsBase authenSessions )
84 {
85 m_world = world;
86 m_clientThreads = clientThreads;
87 m_assetCache = assetCache;
88
89 m_networkServer = packServer;
90 m_inventoryCache = inventoryCache;
91 m_authenticateSessionsHandler = authenSessions;
92
93 OpenSim.Framework.Console.MainLog.Instance.Verbose( "OpenSimClient.cs - Started up new client thread to handle incoming request");
94 cirpack = initialcirpack;
95 userEP = remoteEP;
96
97 this.startpos = m_authenticateSessionsHandler.GetPosition(initialcirpack.CircuitCode.Code);
98
99 PacketQueue = new BlockingQueue<QueItem>();
100
101 this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache);
102 AckTimer = new System.Timers.Timer(500);
103 AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
104 AckTimer.Start();
105
106 this.RegisterLocalPacketHandlers();
107
108 ClientThread = new Thread(new ThreadStart(AuthUser));
109 ClientThread.IsBackground = true;
110 ClientThread.Start();
111 }
112
113 # region Client Methods
114
115 public void KillClient()
116 {
117 KillObjectPacket kill = new KillObjectPacket();
118 kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
119 kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
120 //kill.ObjectData[0].ID = this.ClientAvatar.localid;
121 foreach (ClientView client in m_clientThreads.Values)
122 {
123 client.OutPacket(kill);
124 }
125
126 this.m_inventoryCache.ClientLeaving(this.AgentID, null);
127 m_world.RemoveClient(this.AgentId);
128
129 m_clientThreads.Remove(this.CircuitCode);
130 m_networkServer.RemoveClientCircuit(this.CircuitCode);
131 this.ClientThread.Abort();
132 }
133 #endregion
134
135 # region Packet Handling
136 public static bool AddPacketHandler(PacketType packetType, PacketMethod handler)
137 {
138 bool result = false;
139 lock (PacketHandlers)
140 {
141 if (!PacketHandlers.ContainsKey(packetType))
142 {
143 PacketHandlers.Add(packetType, handler);
144 result = true;
145 }
146 }
147 return result;
148 }
149
150 public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler)
151 {
152 bool result = false;
153 lock (m_packetHandlers)
154 {
155 if (!m_packetHandlers.ContainsKey(packetType))
156 {
157 m_packetHandlers.Add(packetType, handler);
158 result = true;
159 }
160 }
161 return result;
162 }
163
164 protected virtual bool ProcessPacketMethod(Packet packet)
165 {
166 bool result = false;
167 bool found = false;
168 PacketMethod method;
169 if (m_packetHandlers.TryGetValue(packet.Type, out method))
170 {
171 //there is a local handler for this packet type
172 result = method(this, packet);
173 }
174 else
175 {
176 //there is not a local handler so see if there is a Global handler
177 lock (PacketHandlers)
178 {
179 found = PacketHandlers.TryGetValue(packet.Type, out method);
180 }
181 if (found)
182 {
183 result = method(this, packet);
184 }
185 }
186 return result;
187 }
188
189 protected virtual void ClientLoop()
190 {
191 OpenSim.Framework.Console.MainLog.Instance.Verbose( "OpenSimClient.cs:ClientLoop() - Entered loop");
192 while (true)
193 {
194 QueItem nextPacket = PacketQueue.Dequeue();
195 if (nextPacket.Incoming)
196 {
197 //is a incoming packet
198 ProcessInPacket(nextPacket.Packet);
199 }
200 else
201 {
202 //is a out going packet
203 ProcessOutPacket(nextPacket.Packet);
204 }
205 }
206 }
207 # endregion
208
209 # region Setup
210
211 protected virtual void InitNewClient()
212 {
213 OpenSim.Framework.Console.MainLog.Instance.Verbose( "OpenSimClient.cs:InitNewClient() - Adding viewer agent to world");
214 this.m_world.AddNewClient(this, this.AgentID, false);
215 }
216
217 protected virtual void AuthUser()
218 {
219 // AuthenticateResponse sessionInfo = m_gridServer.AuthenticateSession(cirpack.CircuitCode.SessionID, cirpack.CircuitCode.ID, cirpack.CircuitCode.Code);
220 AuthenticateResponse sessionInfo = this.m_authenticateSessionsHandler.AuthenticateSession(cirpack.CircuitCode.SessionID, cirpack.CircuitCode.ID, cirpack.CircuitCode.Code);
221 if (!sessionInfo.Authorised)
222 {
223 //session/circuit not authorised
224 OpenSim.Framework.Console.MainLog.Instance.Notice("OpenSimClient.cs:AuthUser() - New user request denied to " + userEP.ToString());
225 ClientThread.Abort();
226 }
227 else
228 {
229 OpenSim.Framework.Console.MainLog.Instance.Notice("OpenSimClient.cs:AuthUser() - Got authenticated connection from " + userEP.ToString());
230 //session is authorised
231 this.AgentID = cirpack.CircuitCode.ID;
232 this.SessionID = cirpack.CircuitCode.SessionID;
233 this.CircuitCode = cirpack.CircuitCode.Code;
234 this.firstName = sessionInfo.LoginInfo.First;
235 this.lastName = sessionInfo.LoginInfo.Last;
236
237 if (sessionInfo.LoginInfo.SecureSession != LLUUID.Zero)
238 {
239 this.SecureSessionID = sessionInfo.LoginInfo.SecureSession;
240 }
241 InitNewClient();
242
243 ClientLoop();
244 }
245 }
246 # endregion
247
248
249 protected override void KillThread()
250 {
251 this.ClientThread.Abort();
252 }
253
254 #region Inventory Creation
255 private void SetupInventory(AuthenticateResponse sessionInfo)
256 {
257
258 }
259 private AgentInventory CreateInventory(LLUUID baseFolder)
260 {
261 AgentInventory inventory = null;
262
263 return inventory;
264 }
265
266 private void CreateInventoryItem(CreateInventoryItemPacket packet)
267 {
268
269 }
270 #endregion
271
272 }
273}
diff --git a/OpenSim/Region/ClientStack/ClientViewBase.cs b/OpenSim/Region/ClientStack/ClientViewBase.cs
new file mode 100644
index 0000000..7d39405
--- /dev/null
+++ b/OpenSim/Region/ClientStack/ClientViewBase.cs
@@ -0,0 +1,327 @@
1
2/*
3* Copyright (c) Contributors, http://www.openmetaverse.org/
4* See CONTRIBUTORS.TXT for a full list of copyright holders.
5*
6* Redistribution and use in source and binary forms, with or without
7* modification, are permitted provided that the following conditions are met:
8* * Redistributions of source code must retain the above copyright
9* notice, this list of conditions and the following disclaimer.
10* * Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* * Neither the name of the OpenSim Project nor the
14* names of its contributors may be used to endorse or promote products
15* derived from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
18* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
21* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*
28*/
29using System;
30using System.Collections;
31using System.Collections.Generic;
32using libsecondlife;
33using libsecondlife.Packets;
34using System.Net;
35using System.Net.Sockets;
36using System.IO;
37using System.Threading;
38using System.Timers;
39using OpenSim.Framework.Utilities;
40using OpenSim.Framework.Interfaces;
41
42namespace OpenSim.Region.ClientStack
43{
44 public class ClientViewBase
45 {
46 protected BlockingQueue<QueItem> PacketQueue;
47 protected Dictionary<uint, uint> PendingAcks = new Dictionary<uint, uint>();
48 protected Dictionary<uint, Packet> NeedAck = new Dictionary<uint, Packet>();
49
50 protected System.Timers.Timer AckTimer;
51 protected uint Sequence = 0;
52 protected object SequenceLock = new object();
53 protected const int MAX_APPENDED_ACKS = 10;
54 protected const int RESEND_TIMEOUT = 4000;
55 protected const int MAX_SEQUENCE = 0xFFFFFF;
56
57 public uint CircuitCode;
58 public EndPoint userEP;
59
60 protected PacketServer m_networkServer;
61
62 public ClientViewBase()
63 {
64
65 }
66
67 protected virtual void ProcessInPacket(Packet Pack)
68 {
69
70 }
71
72 protected virtual void ProcessOutPacket(Packet Pack)
73 {
74 // Keep track of when this packet was sent out
75 Pack.TickCount = Environment.TickCount;
76
77 if (!Pack.Header.Resent)
78 {
79 // Set the sequence number
80 lock (SequenceLock)
81 {
82 if (Sequence >= MAX_SEQUENCE)
83 Sequence = 1;
84 else
85 Sequence++;
86 Pack.Header.Sequence = Sequence;
87 }
88
89 if (Pack.Header.Reliable) //DIRTY HACK
90 {
91 lock (NeedAck)
92 {
93 if (!NeedAck.ContainsKey(Pack.Header.Sequence))
94 {
95 try
96 {
97 NeedAck.Add(Pack.Header.Sequence, Pack);
98 }
99 catch (Exception e) // HACKY
100 {
101 e.ToString();
102 // Ignore
103 // Seems to throw a exception here occasionally
104 // of 'duplicate key' despite being locked.
105 // !?!?!?
106 }
107 }
108 else
109 {
110 // Client.Log("Attempted to add a duplicate sequence number (" +
111 // packet.Header.Sequence + ") to the NeedAck dictionary for packet type " +
112 // packet.Type.ToString(), Helpers.LogLevel.Warning);
113 }
114 }
115
116 // Don't append ACKs to resent packets, in case that's what was causing the
117 // delivery to fail
118 if (!Pack.Header.Resent)
119 {
120 // Append any ACKs that need to be sent out to this packet
121 lock (PendingAcks)
122 {
123 if (PendingAcks.Count > 0 && PendingAcks.Count < MAX_APPENDED_ACKS &&
124 Pack.Type != PacketType.PacketAck &&
125 Pack.Type != PacketType.LogoutRequest)
126 {
127 Pack.Header.AckList = new uint[PendingAcks.Count];
128 int i = 0;
129
130 foreach (uint ack in PendingAcks.Values)
131 {
132 Pack.Header.AckList[i] = ack;
133 i++;
134 }
135
136 PendingAcks.Clear();
137 Pack.Header.AppendedAcks = true;
138 }
139 }
140 }
141 }
142 }
143
144 byte[] ZeroOutBuffer = new byte[4096];
145 byte[] sendbuffer;
146 sendbuffer = Pack.ToBytes();
147
148 try
149 {
150 if (Pack.Header.Zerocoded)
151 {
152 int packetsize = Helpers.ZeroEncode(sendbuffer, sendbuffer.Length, ZeroOutBuffer);
153 m_networkServer.SendPacketTo(ZeroOutBuffer, packetsize, SocketFlags.None, CircuitCode);//userEP);
154 }
155 else
156 {
157 m_networkServer.SendPacketTo(sendbuffer, sendbuffer.Length, SocketFlags.None, CircuitCode); //userEP);
158 }
159 }
160 catch (Exception)
161 {
162 OpenSim.Framework.Console.MainLog.Instance.Warn("OpenSimClient.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection " + userEP.ToString() + " - killing thread");
163 this.KillThread();
164 }
165
166 }
167
168 public virtual void InPacket(Packet NewPack)
169 {
170 // Handle appended ACKs
171 if (NewPack.Header.AppendedAcks)
172 {
173 lock (NeedAck)
174 {
175 foreach (uint ack in NewPack.Header.AckList)
176 {
177 NeedAck.Remove(ack);
178 }
179 }
180 }
181
182 // Handle PacketAck packets
183 if (NewPack.Type == PacketType.PacketAck)
184 {
185 PacketAckPacket ackPacket = (PacketAckPacket)NewPack;
186
187 lock (NeedAck)
188 {
189 foreach (PacketAckPacket.PacketsBlock block in ackPacket.Packets)
190 {
191 NeedAck.Remove(block.ID);
192 }
193 }
194 }
195 else if ((NewPack.Type == PacketType.StartPingCheck))
196 {
197 //reply to pingcheck
198 libsecondlife.Packets.StartPingCheckPacket startPing = (libsecondlife.Packets.StartPingCheckPacket)NewPack;
199 libsecondlife.Packets.CompletePingCheckPacket endPing = new CompletePingCheckPacket();
200 endPing.PingID.PingID = startPing.PingID.PingID;
201 OutPacket(endPing);
202 }
203 else
204 {
205 QueItem item = new QueItem();
206 item.Packet = NewPack;
207 item.Incoming = true;
208 this.PacketQueue.Enqueue(item);
209 }
210
211 }
212
213 public virtual void OutPacket(Packet NewPack)
214 {
215 QueItem item = new QueItem();
216 item.Packet = NewPack;
217 item.Incoming = false;
218 this.PacketQueue.Enqueue(item);
219 }
220
221 # region Low Level Packet Methods
222
223 protected void ack_pack(Packet Pack)
224 {
225 if (Pack.Header.Reliable)
226 {
227 libsecondlife.Packets.PacketAckPacket ack_it = new PacketAckPacket();
228 ack_it.Packets = new PacketAckPacket.PacketsBlock[1];
229 ack_it.Packets[0] = new PacketAckPacket.PacketsBlock();
230 ack_it.Packets[0].ID = Pack.Header.Sequence;
231 ack_it.Header.Reliable = false;
232
233 OutPacket(ack_it);
234
235 }
236 /*
237 if (Pack.Header.Reliable)
238 {
239 lock (PendingAcks)
240 {
241 uint sequence = (uint)Pack.Header.Sequence;
242 if (!PendingAcks.ContainsKey(sequence)) { PendingAcks[sequence] = sequence; }
243 }
244 }*/
245 }
246
247 protected void ResendUnacked()
248 {
249 int now = Environment.TickCount;
250
251 lock (NeedAck)
252 {
253 foreach (Packet packet in NeedAck.Values)
254 {
255 if ((now - packet.TickCount > RESEND_TIMEOUT) && (!packet.Header.Resent))
256 {
257 OpenSim.Framework.Console.MainLog.Instance.Verbose( "Resending " + packet.Type.ToString() + " packet, " +
258 (now - packet.TickCount) + "ms have passed");
259
260 packet.Header.Resent = true;
261 OutPacket(packet);
262 }
263 }
264 }
265 }
266
267 protected void SendAcks()
268 {
269 lock (PendingAcks)
270 {
271 if (PendingAcks.Count > 0)
272 {
273 if (PendingAcks.Count > 250)
274 {
275 // FIXME: Handle the odd case where we have too many pending ACKs queued up
276 OpenSim.Framework.Console.MainLog.Instance.Verbose( "Too many ACKs queued up!");
277 return;
278 }
279
280 //OpenSim.Framework.Console.MainLog.Instance.WriteLine("Sending PacketAck");
281
282
283 int i = 0;
284 PacketAckPacket acks = new PacketAckPacket();
285 acks.Packets = new PacketAckPacket.PacketsBlock[PendingAcks.Count];
286
287 foreach (uint ack in PendingAcks.Values)
288 {
289 acks.Packets[i] = new PacketAckPacket.PacketsBlock();
290 acks.Packets[i].ID = ack;
291 i++;
292 }
293
294 acks.Header.Reliable = false;
295 OutPacket(acks);
296
297 PendingAcks.Clear();
298 }
299 }
300 }
301
302 protected void AckTimer_Elapsed(object sender, ElapsedEventArgs ea)
303 {
304 SendAcks();
305 ResendUnacked();
306 }
307 #endregion
308
309 protected virtual void KillThread()
310 {
311
312 }
313
314 #region Nested Classes
315
316 public class QueItem
317 {
318 public QueItem()
319 {
320 }
321
322 public Packet Packet;
323 public bool Incoming;
324 }
325 #endregion
326 }
327}
diff --git a/OpenSim/Region/ClientStack/OpenSim.Region.ClientStack.csproj b/OpenSim/Region/ClientStack/OpenSim.Region.ClientStack.csproj
new file mode 100644
index 0000000..3093eb0
--- /dev/null
+++ b/OpenSim/Region/ClientStack/OpenSim.Region.ClientStack.csproj
@@ -0,0 +1,166 @@
1<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <PropertyGroup>
3 <ProjectType>Local</ProjectType>
4 <ProductVersion>8.0.50727</ProductVersion>
5 <SchemaVersion>2.0</SchemaVersion>
6 <ProjectGuid>{DC3698B2-0000-0000-0000-000000000000}</ProjectGuid>
7 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
8 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
9 <ApplicationIcon></ApplicationIcon>
10 <AssemblyKeyContainerName>
11 </AssemblyKeyContainerName>
12 <AssemblyName>OpenSim.Region.ClientStack</AssemblyName>
13 <DefaultClientScript>JScript</DefaultClientScript>
14 <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
15 <DefaultTargetSchema>IE50</DefaultTargetSchema>
16 <DelaySign>false</DelaySign>
17 <OutputType>Library</OutputType>
18 <AppDesignerFolder></AppDesignerFolder>
19 <RootNamespace>OpenSim.Region.ClientStack</RootNamespace>
20 <StartupObject></StartupObject>
21 <FileUpgradeFlags>
22 </FileUpgradeFlags>
23 </PropertyGroup>
24 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
25 <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
26 <BaseAddress>285212672</BaseAddress>
27 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
28 <ConfigurationOverrideFile>
29 </ConfigurationOverrideFile>
30 <DefineConstants>TRACE;DEBUG</DefineConstants>
31 <DocumentationFile></DocumentationFile>
32 <DebugSymbols>True</DebugSymbols>
33 <FileAlignment>4096</FileAlignment>
34 <Optimize>False</Optimize>
35 <OutputPath>..\..\..\bin\</OutputPath>
36 <RegisterForComInterop>False</RegisterForComInterop>
37 <RemoveIntegerChecks>False</RemoveIntegerChecks>
38 <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
39 <WarningLevel>4</WarningLevel>
40 <NoWarn></NoWarn>
41 </PropertyGroup>
42 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
43 <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
44 <BaseAddress>285212672</BaseAddress>
45 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
46 <ConfigurationOverrideFile>
47 </ConfigurationOverrideFile>
48 <DefineConstants>TRACE</DefineConstants>
49 <DocumentationFile></DocumentationFile>
50 <DebugSymbols>False</DebugSymbols>
51 <FileAlignment>4096</FileAlignment>
52 <Optimize>True</Optimize>
53 <OutputPath>..\..\..\bin\</OutputPath>
54 <RegisterForComInterop>False</RegisterForComInterop>
55 <RemoveIntegerChecks>False</RemoveIntegerChecks>
56 <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
57 <WarningLevel>4</WarningLevel>
58 <NoWarn></NoWarn>
59 </PropertyGroup>
60 <ItemGroup>
61 <Reference Include="Axiom.MathLib.dll" >
62 <HintPath>..\..\..\bin\Axiom.MathLib.dll</HintPath>
63 <Private>False</Private>
64 </Reference>
65 <Reference Include="Db4objects.Db4o.dll" >
66 <HintPath>..\..\..\bin\Db4objects.Db4o.dll</HintPath>
67 <Private>False</Private>
68 </Reference>
69 <Reference Include="libsecondlife.dll" >
70 <HintPath>..\..\..\bin\libsecondlife.dll</HintPath>
71 <Private>False</Private>
72 </Reference>
73 <Reference Include="System" >
74 <HintPath>System.dll</HintPath>
75 <Private>False</Private>
76 </Reference>
77 <Reference Include="System.Xml" >
78 <HintPath>System.Xml.dll</HintPath>
79 <Private>False</Private>
80 </Reference>
81 <Reference Include="XMLRPC.dll" >
82 <HintPath>..\..\..\bin\XMLRPC.dll</HintPath>
83 <Private>False</Private>
84 </Reference>
85 </ItemGroup>
86 <ItemGroup>
87 <ProjectReference Include="..\..\Framework\General\OpenSim.Framework.csproj">
88 <Name>OpenSim.Framework</Name>
89 <Project>{8ACA2445-0000-0000-0000-000000000000}</Project>
90 <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
91 <Private>False</Private>
92 </ProjectReference>
93 <ProjectReference Include="..\..\Framework\Console\OpenSim.Framework.Console.csproj">
94 <Name>OpenSim.Framework.Console</Name>
95 <Project>{A7CD0630-0000-0000-0000-000000000000}</Project>
96 <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
97 <Private>False</Private>
98 </ProjectReference>
99 <ProjectReference Include="..\..\Framework\Servers\OpenSim.Framework.Servers.csproj">
100 <Name>OpenSim.Framework.Servers</Name>
101 <Project>{2CC71860-0000-0000-0000-000000000000}</Project>
102 <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
103 <Private>False</Private>
104 </ProjectReference>
105 <ProjectReference Include="..\Caches\OpenSim.Region.Caches.csproj">
106 <Name>OpenSim.Region.Caches</Name>
107 <Project>{61FCCDB3-0000-0000-0000-000000000000}</Project>
108 <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
109 <Private>False</Private>
110 </ProjectReference>
111 <ProjectReference Include="..\Physics\Manager\OpenSim.Region.Physics.Manager.csproj">
112 <Name>OpenSim.Region.Physics.Manager</Name>
113 <Project>{F4FF31EB-0000-0000-0000-000000000000}</Project>
114 <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
115 <Private>False</Private>
116 </ProjectReference>
117 <ProjectReference Include="..\Terrain.BasicTerrain\OpenSim.Region.Terrain.BasicTerrain.csproj">
118 <Name>OpenSim.Region.Terrain.BasicTerrain</Name>
119 <Project>{C9E0F891-0000-0000-0000-000000000000}</Project>
120 <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
121 <Private>False</Private>
122 </ProjectReference>
123 </ItemGroup>
124 <ItemGroup>
125 <Compile Include="ClientStackNetworkHandler.cs">
126 <SubType>Code</SubType>
127 </Compile>
128 <Compile Include="ClientView.AgentAssetUpload.cs">
129 <SubType>Code</SubType>
130 </Compile>
131 <Compile Include="ClientView.API.cs">
132 <SubType>Code</SubType>
133 </Compile>
134 <Compile Include="ClientView.cs">
135 <SubType>Code</SubType>
136 </Compile>
137 <Compile Include="ClientView.PacketHandlers.cs">
138 <SubType>Code</SubType>
139 </Compile>
140 <Compile Include="ClientView.ProcessPackets.cs">
141 <SubType>Code</SubType>
142 </Compile>
143 <Compile Include="ClientViewBase.cs">
144 <SubType>Code</SubType>
145 </Compile>
146 <Compile Include="PacketServer.cs">
147 <SubType>Code</SubType>
148 </Compile>
149 <Compile Include="RegionApplicationBase.cs">
150 <SubType>Code</SubType>
151 </Compile>
152 <Compile Include="UDPServer.cs">
153 <SubType>Code</SubType>
154 </Compile>
155 <Compile Include="Assets\InventoryCache.cs">
156 <SubType>Code</SubType>
157 </Compile>
158 </ItemGroup>
159 <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
160 <PropertyGroup>
161 <PreBuildEvent>
162 </PreBuildEvent>
163 <PostBuildEvent>
164 </PostBuildEvent>
165 </PropertyGroup>
166</Project>
diff --git a/OpenSim/Region/ClientStack/OpenSim.Region.ClientStack.dll.build b/OpenSim/Region/ClientStack/OpenSim.Region.ClientStack.dll.build
new file mode 100644
index 0000000..f76a4c8
--- /dev/null
+++ b/OpenSim/Region/ClientStack/OpenSim.Region.ClientStack.dll.build
@@ -0,0 +1,60 @@
1<?xml version="1.0" ?>
2<project name="OpenSim.Region.ClientStack" default="build">
3 <target name="build">
4 <echo message="Build Directory is ${project::get-base-directory()}/${build.dir}" />
5 <mkdir dir="${project::get-base-directory()}/${build.dir}" />
6 <copy todir="${project::get-base-directory()}/${build.dir}">
7 <fileset basedir="${project::get-base-directory()}">
8 </fileset>
9 </copy>
10 <csc target="library" debug="${build.debug}" unsafe="False" define="TRACE;DEBUG" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.dll">
11 <resources prefix="OpenSim.Region.ClientStack" dynamicprefix="true" >
12 </resources>
13 <sources failonempty="true">
14 <include name="ClientStackNetworkHandler.cs" />
15 <include name="ClientView.AgentAssetUpload.cs" />
16 <include name="ClientView.API.cs" />
17 <include name="ClientView.cs" />
18 <include name="ClientView.PacketHandlers.cs" />
19 <include name="ClientView.ProcessPackets.cs" />
20 <include name="ClientViewBase.cs" />
21 <include name="PacketServer.cs" />
22 <include name="RegionApplicationBase.cs" />
23 <include name="UDPServer.cs" />
24 <include name="Assets/InventoryCache.cs" />
25 </sources>
26 <references basedir="${project::get-base-directory()}">
27 <lib>
28 <include name="${project::get-base-directory()}" />
29 <include name="${project::get-base-directory()}/${build.dir}" />
30 </lib>
31 <include name="../../../bin/Axiom.MathLib.dll" />
32 <include name="../../../bin/Db4objects.Db4o.dll" />
33 <include name="../../../bin/libsecondlife.dll" />
34 <include name="../../../bin/OpenSim.Framework.dll" />
35 <include name="../../../bin/OpenSim.Framework.Console.dll" />
36 <include name="../../../bin/OpenSim.Framework.Servers.dll" />
37 <include name="../../../bin/OpenSim.Region.Caches.dll" />
38 <include name="../../../bin/OpenSim.Region.Physics.Manager.dll" />
39 <include name="../../../bin/OpenSim.Region.Terrain.BasicTerrain.dll" />
40 <include name="System.dll" />
41 <include name="System.Xml.dll" />
42 <include name="../../../bin/XMLRPC.dll" />
43 </references>
44 </csc>
45 <echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../../../bin/" />
46 <mkdir dir="${project::get-base-directory()}/../../../bin/"/>
47 <copy todir="${project::get-base-directory()}/../../../bin/">
48 <fileset basedir="${project::get-base-directory()}/${build.dir}/" >
49 <include name="*.dll"/>
50 <include name="*.exe"/>
51 </fileset>
52 </copy>
53 </target>
54 <target name="clean">
55 <delete dir="${bin.dir}" failonerror="false" />
56 <delete dir="${obj.dir}" failonerror="false" />
57 </target>
58 <target name="doc" description="Creates documentation.">
59 </target>
60</project>
diff --git a/OpenSim/Region/ClientStack/PacketServer.cs b/OpenSim/Region/ClientStack/PacketServer.cs
new file mode 100644
index 0000000..ffd254e
--- /dev/null
+++ b/OpenSim/Region/ClientStack/PacketServer.cs
@@ -0,0 +1,183 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using libsecondlife.Packets;
32using OpenSim.Framework.Interfaces;
33using OpenSim.Framework;
34using System.Net;
35using System.Net.Sockets;
36using OpenSim.Assets;
37using OpenSim.Region.Caches;
38
39namespace OpenSim.Region.ClientStack
40{
41 public class PacketServer
42 {
43 private ClientStackNetworkHandler _networkHandler;
44 private IWorld _localWorld;
45 public Dictionary<uint, ClientView> ClientThreads = new Dictionary<uint, ClientView>();
46 public Dictionary<uint, IClientAPI> ClientAPIs = new Dictionary<uint, IClientAPI>();
47 protected uint serverPort;
48
49 public PacketServer(ClientStackNetworkHandler networkHandler, uint port)
50 {
51 _networkHandler = networkHandler;
52 this.serverPort = port;
53 _networkHandler.RegisterPacketServer(this);
54 }
55
56 public IWorld LocalWorld
57 {
58 set
59 {
60 this._localWorld = value;
61 }
62 }
63
64 /// <summary>
65 ///
66 /// </summary>
67 /// <param name="circuitCode"></param>
68 /// <param name="packet"></param>
69 public virtual void ClientInPacket(uint circuitCode, Packet packet)
70 {
71 if (this.ClientThreads.ContainsKey(circuitCode))
72 {
73 ClientThreads[circuitCode].InPacket(packet);
74 }
75 }
76
77 /// <summary>
78 ///
79 /// </summary>
80 /// <param name="circuitCode"></param>
81 /// <returns></returns>
82 public virtual bool AddNewCircuitCodeClient(uint circuitCode)
83 {
84 return false;
85 }
86
87 /// <summary>
88 ///
89 /// </summary>
90 /// <param name="packet"></param>
91 public virtual void SendPacketToAllClients(Packet packet)
92 {
93
94 }
95
96 /// <summary>
97 ///
98 /// </summary>
99 /// <param name="packet"></param>
100 /// <param name="simClient"></param>
101 public virtual void SendPacketToAllExcept(Packet packet, ClientView simClient)
102 {
103
104 }
105
106 /// <summary>
107 ///
108 /// </summary>
109 /// <param name="packetType"></param>
110 /// <param name="handler"></param>
111 public virtual void AddClientPacketHandler(PacketType packetType, PacketMethod handler)
112 {
113
114 }
115
116 /// <summary>
117 ///
118 /// </summary>
119 public virtual void RegisterClientPacketHandlers()
120 {
121
122 }
123
124 /// <summary>
125 ///
126 /// </summary>
127 /// <param name="remoteEP"></param>
128 /// <param name="initialcirpack"></param>
129 /// <param name="clientThreads"></param>
130 /// <param name="world"></param>
131 /// <param name="assetCache"></param>
132 /// <param name="packServer"></param>
133 /// <param name="inventoryCache"></param>
134 /// <param name="authenSessions"></param>
135 /// <returns></returns>
136 protected virtual ClientView CreateNewClient(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, Dictionary<uint, ClientView> clientThreads, IWorld world, AssetCache assetCache, PacketServer packServer, InventoryCache inventoryCache, AuthenticateSessionsBase authenSessions)
137 {
138 return new ClientView(remoteEP, initialcirpack, clientThreads, world, assetCache, packServer, inventoryCache, authenSessions );
139 }
140
141 /// <summary>
142 ///
143 /// </summary>
144 /// <param name="epSender"></param>
145 /// <param name="useCircuit"></param>
146 /// <param name="assetCache"></param>
147 /// <param name="inventoryCache"></param>
148 /// <param name="authenticateSessionsClass"></param>
149 /// <returns></returns>
150 public virtual bool AddNewClient(EndPoint epSender, UseCircuitCodePacket useCircuit, AssetCache assetCache, InventoryCache inventoryCache, AuthenticateSessionsBase authenticateSessionsClass)
151 {
152 ClientView newuser =
153 CreateNewClient(epSender, useCircuit, ClientThreads, _localWorld, assetCache, this, inventoryCache,
154 authenticateSessionsClass);
155
156 this.ClientThreads.Add(useCircuit.CircuitCode.Code, newuser);
157 this.ClientAPIs.Add(useCircuit.CircuitCode.Code, (IClientAPI)newuser);
158
159 return true;
160 }
161
162 /// <summary>
163 ///
164 /// </summary>
165 /// <param name="buffer"></param>
166 /// <param name="size"></param>
167 /// <param name="flags"></param>
168 /// <param name="circuitcode"></param>
169 public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)
170 {
171 this._networkHandler.SendPacketTo(buffer, size, flags, circuitcode);
172 }
173
174 /// <summary>
175 ///
176 /// </summary>
177 /// <param name="circuitcode"></param>
178 public virtual void RemoveClientCircuit(uint circuitcode)
179 {
180 this._networkHandler.RemoveClientCircuit(circuitcode);
181 }
182 }
183}
diff --git a/OpenSim/Region/ClientStack/RegionApplicationBase.cs b/OpenSim/Region/ClientStack/RegionApplicationBase.cs
new file mode 100644
index 0000000..94db8ee
--- /dev/null
+++ b/OpenSim/Region/ClientStack/RegionApplicationBase.cs
@@ -0,0 +1,128 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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*/
28using System;
29using System.Text;
30using System.IO;
31using System.Threading;
32using System.Net;
33using System.Net.Sockets;
34using System.Timers;
35using System.Reflection;
36using System.Collections;
37using System.Collections.Generic;
38using libsecondlife;
39using libsecondlife.Packets;
40using OpenSim.Region.Terrain;
41using OpenSim.Framework.Interfaces;
42using OpenSim.Framework.Types;
43using OpenSim.Framework;
44using OpenSim.Assets;
45using OpenSim.Region.Caches;
46using OpenSim.Framework.Console;
47using OpenSim.Physics.Manager;
48using Nwc.XmlRpc;
49using OpenSim.Framework.Servers;
50
51namespace OpenSim.Region.ClientStack
52{
53 public class RegionApplicationBase
54 {
55 protected IGenericConfig localConfig;
56 protected PhysicsManager physManager;
57 protected AssetCache AssetCache;
58 protected InventoryCache InventoryCache;
59 protected Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>();
60 protected DateTime startuptime;
61 protected NetworkServersInfo serversData;
62
63 public string m_physicsEngine;
64 public bool m_sandbox = false;
65 public bool m_loginserver;
66 public bool user_accounts = false;
67 public bool gridLocalAsset = false;
68 protected bool configFileSetup = false;
69 public string m_config;
70
71 protected List<UDPServer> m_udpServer = new List<UDPServer>();
72 protected List<RegionInfo> regionData = new List<RegionInfo>();
73 protected List<IWorld> m_localWorld = new List<IWorld>();
74 protected BaseHttpServer httpServer;
75 protected List<AuthenticateSessionsBase> AuthenticateSessionsHandler = new List<AuthenticateSessionsBase>();
76
77 protected LogBase m_log;
78
79 public RegionApplicationBase()
80 {
81
82 }
83
84 public RegionApplicationBase(bool sandBoxMode, bool startLoginServer, string physicsEngine, bool useConfigFile, bool silent, string configFile)
85 {
86 this.configFileSetup = useConfigFile;
87 m_sandbox = sandBoxMode;
88 m_loginserver = startLoginServer;
89 m_physicsEngine = physicsEngine;
90 m_config = configFile;
91 }
92
93 /*protected World m_localWorld;
94 public World LocalWorld
95 {
96 get { return m_localWorld; }
97 }*/
98
99 /// <summary>
100 /// Performs initialisation of the world, such as loading configuration from disk.
101 /// </summary>
102 public virtual void StartUp()
103 {
104 }
105
106 protected virtual void SetupLocalGridServers()
107 {
108 }
109
110 protected virtual void SetupRemoteGridServers()
111 {
112
113 }
114
115 protected virtual void SetupWorld()
116 {
117 }
118
119 protected virtual void SetupHttpListener()
120 {
121 }
122
123 protected virtual void ConnectToRemoteGridServer()
124 {
125
126 }
127 }
128}
diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs
new file mode 100644
index 0000000..259352c
--- /dev/null
+++ b/OpenSim/Region/ClientStack/UDPServer.cs
@@ -0,0 +1,207 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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*/
28using System;
29using System.Text;
30using System.IO;
31using System.Threading;
32using System.Net;
33using System.Net.Sockets;
34using System.Timers;
35using System.Reflection;
36using System.Collections;
37using System.Collections.Generic;
38using libsecondlife;
39using libsecondlife.Packets;
40using OpenSim.Region.Terrain;
41using OpenSim.Framework.Interfaces;
42using OpenSim.Framework.Types;
43using OpenSim.Assets;
44using OpenSim.Region.Caches;
45using OpenSim.Framework.Console;
46using OpenSim.Framework;
47using Nwc.XmlRpc;
48using OpenSim.Framework.Servers;
49
50namespace OpenSim.Region.ClientStack
51{
52
53 public class UDPServer : ClientStackNetworkHandler
54 {
55 protected Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>();
56 public Socket Server;
57 protected IPEndPoint ServerIncoming;
58 protected byte[] RecvBuffer = new byte[4096];
59 protected byte[] ZeroBuffer = new byte[8192];
60 protected IPEndPoint ipeSender;
61 protected EndPoint epSender;
62 protected AsyncCallback ReceivedData;
63 protected PacketServer _packetServer;
64
65 protected int listenPort;
66 protected IWorld m_localWorld;
67 protected AssetCache m_assetCache;
68 protected InventoryCache m_inventoryCache;
69 protected LogBase m_log;
70 protected AuthenticateSessionsBase m_authenticateSessionsClass;
71
72 public PacketServer PacketServer
73 {
74 get
75 {
76 return _packetServer;
77 }
78 set
79 {
80 _packetServer = value;
81 }
82 }
83
84 public IWorld LocalWorld
85 {
86 set
87 {
88 this.m_localWorld = value;
89 this._packetServer.LocalWorld = this.m_localWorld;
90 }
91 }
92
93 public UDPServer()
94 {
95 }
96
97 public UDPServer(int port, AssetCache assetCache, InventoryCache inventoryCache, LogBase console, AuthenticateSessionsBase authenticateClass)
98 {
99 listenPort = port;
100 this.m_assetCache = assetCache;
101 this.m_inventoryCache = inventoryCache;
102 this.m_log = console;
103 this.m_authenticateSessionsClass = authenticateClass;
104 this.CreatePacketServer();
105
106 }
107
108 protected virtual void CreatePacketServer()
109 {
110 PacketServer packetServer = new PacketServer(this, (uint) listenPort);
111 }
112
113 protected virtual void OnReceivedData(IAsyncResult result)
114 {
115 ipeSender = new IPEndPoint(IPAddress.Any, 0);
116 epSender = (EndPoint)ipeSender;
117 Packet packet = null;
118 int numBytes = Server.EndReceiveFrom(result, ref epSender);
119 int packetEnd = numBytes - 1;
120
121 packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
122
123 // do we already have a circuit for this endpoint
124 if (this.clientCircuits.ContainsKey(epSender))
125 {
126 //if so then send packet to the packetserver
127 this._packetServer.ClientInPacket(this.clientCircuits[epSender], packet);
128 }
129 else if (packet.Type == PacketType.UseCircuitCode)
130 {
131 // new client
132 this.AddNewClient(packet);
133 }
134 else
135 { // invalid client
136 m_log.Warn("UDPServer.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString());
137 }
138
139 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
140 }
141
142 protected virtual void AddNewClient(Packet packet)
143 {
144 UseCircuitCodePacket useCircuit = (UseCircuitCodePacket)packet;
145 this.clientCircuits.Add(epSender, useCircuit.CircuitCode.Code);
146
147 this.PacketServer.AddNewClient(epSender, useCircuit, m_assetCache, m_inventoryCache, m_authenticateSessionsClass);
148 }
149
150 public void ServerListener()
151 {
152 m_log.Status("UDPServer.cs:ServerListener() - Opening UDP socket on " + listenPort);
153
154 ServerIncoming = new IPEndPoint(IPAddress.Any, listenPort);
155 Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
156 Server.Bind(ServerIncoming);
157
158 m_log.Verbose("UDPServer.cs:ServerListener() - UDP socket bound, getting ready to listen");
159
160 ipeSender = new IPEndPoint(IPAddress.Any, 0);
161 epSender = (EndPoint)ipeSender;
162 ReceivedData = new AsyncCallback(this.OnReceivedData);
163 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
164
165 m_log.Verbose("UDPServer.cs:ServerListener() - Listening...");
166
167 }
168
169 public virtual void RegisterPacketServer(PacketServer server)
170 {
171 this._packetServer = server;
172 }
173
174 public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)//EndPoint packetSender)
175 {
176 // find the endpoint for this circuit
177 EndPoint sendto = null;
178 foreach (KeyValuePair<EndPoint, uint> p in this.clientCircuits)
179 {
180 if (p.Value == circuitcode)
181 {
182 sendto = p.Key;
183 break;
184 }
185 }
186 if (sendto != null)
187 {
188 //we found the endpoint so send the packet to it
189 this.Server.SendTo(buffer, size, flags, sendto);
190 }
191 }
192
193 public virtual void RemoveClientCircuit(uint circuitcode)
194 {
195 foreach (KeyValuePair<EndPoint, uint> p in this.clientCircuits)
196 {
197 if (p.Value == circuitcode)
198 {
199 this.clientCircuits.Remove(p.Key);
200 break;
201 }
202 }
203 }
204
205
206 }
207} \ No newline at end of file