aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/ClientView.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim.RegionServer/ClientView.cs')
-rw-r--r--OpenSim.RegionServer/ClientView.cs440
1 files changed, 0 insertions, 440 deletions
diff --git a/OpenSim.RegionServer/ClientView.cs b/OpenSim.RegionServer/ClientView.cs
deleted file mode 100644
index ccea2f3..0000000
--- a/OpenSim.RegionServer/ClientView.cs
+++ /dev/null
@@ -1,440 +0,0 @@
1/*
2Copyright (c) OpenSim project, http://osgrid.org/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
10* documentation and/or other materials provided with the distribution.
11* * Neither the name of the <organization> nor the
12* names of its contributors may be used to endorse or promote products
13* derived from this software without specific prior written permission.
14*
15* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
16* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
19* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*/
26
27using System;
28using System.Collections;
29using System.Collections.Generic;
30using libsecondlife;
31using libsecondlife.Packets;
32using Nwc.XmlRpc;
33using System.Net;
34using System.Net.Sockets;
35using System.IO;
36using System.Threading;
37using System.Timers;
38using OpenSim.Framework.Interfaces;
39using OpenSim.Framework.Types;
40using OpenSim.Framework.Inventory;
41using OpenSim.Framework.Utilities;
42using OpenSim.world;
43using OpenSim.Assets;
44
45namespace OpenSim
46{
47 public delegate bool PacketMethod(ClientView simClient, Packet packet);
48
49 /// <summary>
50 /// Handles new client connections
51 /// Constructor takes a single Packet and authenticates everything
52 /// </summary>
53 public partial class ClientView : ClientViewBase
54 {
55 protected static Dictionary<PacketType, PacketMethod> PacketHandlers = new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients
56 protected Dictionary<PacketType, PacketMethod> m_packetHandlers = new Dictionary<PacketType, PacketMethod>(); //local handlers for this instance
57
58 public LLUUID AgentID;
59 public LLUUID SessionID;
60 public LLUUID SecureSessionID = LLUUID.Zero;
61 public bool m_child;
62 public world.Avatar ClientAvatar;
63 private UseCircuitCodePacket cirpack;
64 public Thread ClientThread;
65 public LLVector3 startpos;
66
67 private AgentAssetUpload UploadAssets;
68 private LLUUID newAssetFolder = LLUUID.Zero;
69 private bool debug = false;
70 private World m_world;
71 private Dictionary<uint, ClientView> m_clientThreads;
72 private AssetCache m_assetCache;
73 private IGridServer m_gridServer;
74 private IUserServer m_userServer = null;
75 private InventoryCache m_inventoryCache;
76 public bool m_sandboxMode;
77 private int cachedtextureserial = 0;
78 private RegionInfo m_regionData;
79 protected AuthenticateSessionsBase m_authenticateSessionsHandler;
80
81 public IUserServer UserServer
82 {
83 set
84 {
85 this.m_userServer = value;
86 }
87 }
88
89 public ClientView(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, World world, Dictionary<uint, ClientView> clientThreads, AssetCache assetCache, IGridServer gridServer, OpenSimNetworkHandler application, InventoryCache inventoryCache, bool sandboxMode, bool child, RegionInfo regionDat, AuthenticateSessionsBase authenSessions)
90 {
91 m_world = world;
92 m_clientThreads = clientThreads;
93 m_assetCache = assetCache;
94 m_gridServer = gridServer;
95 m_networkServer = application;
96 m_inventoryCache = inventoryCache;
97 m_sandboxMode = sandboxMode;
98 m_child = child;
99 m_regionData = regionDat;
100 m_authenticateSessionsHandler = authenSessions;
101
102 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "OpenSimClient.cs - Started up new client thread to handle incoming request");
103 cirpack = initialcirpack;
104 userEP = remoteEP;
105
106 if (m_gridServer.GetName() == "Remote")
107 {
108 this.m_child = m_authenticateSessionsHandler.GetAgentChildStatus(initialcirpack.CircuitCode.Code);
109 this.startpos = m_authenticateSessionsHandler.GetPosition(initialcirpack.CircuitCode.Code);
110 //Console.WriteLine("start pos is " + this.startpos.X + " , " + this.startpos.Y + " , " + this.startpos.Z);
111 }
112 else
113 {
114 this.startpos = new LLVector3(128, 128, m_world.Terrain[(int)128, (int)128] + 15.0f); // new LLVector3(128.0f, 128.0f, 60f);
115 }
116
117 PacketQueue = new BlockingQueue<QueItem>();
118
119 this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache);
120 AckTimer = new System.Timers.Timer(500);
121 AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
122 AckTimer.Start();
123
124 this.RegisterLocalPacketHandlers();
125
126 ClientThread = new Thread(new ThreadStart(AuthUser));
127 ClientThread.IsBackground = true;
128 ClientThread.Start();
129 }
130
131 # region Client Methods
132 public void UpgradeClient()
133 {
134 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "SimClient.cs:UpgradeClient() - upgrading child to full agent");
135 this.m_child = false;
136 this.m_world.RemoveViewerAgent(this);
137 if (!this.m_sandboxMode)
138 {
139 this.startpos = m_authenticateSessionsHandler.GetPosition(CircuitCode);
140 m_authenticateSessionsHandler.UpdateAgentChildStatus(CircuitCode, false);
141 //Console.WriteLine("upgrade start pos is " + this.startpos.X + " , " + this.startpos.Y + " , " + this.startpos.Z);
142 }
143 this.InitNewClient();
144 }
145
146 public void DowngradeClient()
147 {
148 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "SimClient.cs:UpgradeClient() - changing full agent to child");
149 this.m_child = true;
150 this.m_world.RemoveViewerAgent(this);
151 this.m_world.AddViewerAgent(this);
152 }
153
154 public void KillClient()
155 {
156 KillObjectPacket kill = new KillObjectPacket();
157 kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
158 kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
159 kill.ObjectData[0].ID = this.ClientAvatar.localid;
160 foreach (ClientView client in m_clientThreads.Values)
161 {
162 client.OutPacket(kill);
163 }
164 if (this.m_userServer != null)
165 {
166 this.m_inventoryCache.ClientLeaving(this.AgentID, this.m_userServer);
167 }
168 else
169 {
170 this.m_inventoryCache.ClientLeaving(this.AgentID, null);
171 }
172
173 m_world.RemoveViewerAgent(this);
174
175 m_clientThreads.Remove(this.CircuitCode);
176 m_networkServer.RemoveClientCircuit(this.CircuitCode);
177 this.ClientThread.Abort();
178 }
179 #endregion
180
181 # region Packet Handling
182 public static bool AddPacketHandler(PacketType packetType, PacketMethod handler)
183 {
184 bool result = false;
185 lock (PacketHandlers)
186 {
187 if (!PacketHandlers.ContainsKey(packetType))
188 {
189 PacketHandlers.Add(packetType, handler);
190 result = true;
191 }
192 }
193 return result;
194 }
195
196 public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler)
197 {
198 bool result = false;
199 lock (m_packetHandlers)
200 {
201 if (!m_packetHandlers.ContainsKey(packetType))
202 {
203 m_packetHandlers.Add(packetType, handler);
204 result = true;
205 }
206 }
207 return result;
208 }
209
210 protected virtual bool ProcessPacketMethod(Packet packet)
211 {
212 bool result = false;
213 bool found = false;
214 PacketMethod method;
215 if (m_packetHandlers.TryGetValue(packet.Type, out method))
216 {
217 //there is a local handler for this packet type
218 result = method(this, packet);
219 }
220 else
221 {
222 //there is not a local handler so see if there is a Global handler
223 lock (PacketHandlers)
224 {
225 found = PacketHandlers.TryGetValue(packet.Type, out method);
226 }
227 if (found)
228 {
229 result = method(this, packet);
230 }
231 }
232 return result;
233 }
234
235 protected virtual void ClientLoop()
236 {
237 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "OpenSimClient.cs:ClientLoop() - Entered loop");
238 while (true)
239 {
240 QueItem nextPacket = PacketQueue.Dequeue();
241 if (nextPacket.Incoming)
242 {
243 //is a incoming packet
244 ProcessInPacket(nextPacket.Packet);
245 }
246 else
247 {
248 //is a out going packet
249 ProcessOutPacket(nextPacket.Packet);
250 }
251 }
252 }
253 # endregion
254
255 # region Setup
256
257 protected virtual void InitNewClient()
258 {
259 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "OpenSimClient.cs:InitNewClient() - Adding viewer agent to world");
260
261 m_world.AddViewerAgent(this);
262 world.Entity tempent = m_world.Entities[this.AgentID];
263
264 this.ClientAvatar = (world.Avatar)tempent;
265 }
266
267 protected virtual void AuthUser()
268 {
269 // AuthenticateResponse sessionInfo = m_gridServer.AuthenticateSession(cirpack.CircuitCode.SessionID, cirpack.CircuitCode.ID, cirpack.CircuitCode.Code);
270 AuthenticateResponse sessionInfo = this.m_networkServer.AuthenticateSession(cirpack.CircuitCode.SessionID, cirpack.CircuitCode.ID, cirpack.CircuitCode.Code);
271 if (!sessionInfo.Authorised)
272 {
273 //session/circuit not authorised
274 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.NORMAL, "OpenSimClient.cs:AuthUser() - New user request denied to " + userEP.ToString());
275 ClientThread.Abort();
276 }
277 else
278 {
279 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.NORMAL, "OpenSimClient.cs:AuthUser() - Got authenticated connection from " + userEP.ToString());
280 //session is authorised
281 this.AgentID = cirpack.CircuitCode.ID;
282 this.SessionID = cirpack.CircuitCode.SessionID;
283 this.CircuitCode = cirpack.CircuitCode.Code;
284 InitNewClient(); //shouldn't be called here as we might be a child agent and not want a full avatar
285 this.ClientAvatar.firstname = sessionInfo.LoginInfo.First;
286 this.ClientAvatar.lastname = sessionInfo.LoginInfo.Last;
287 if (sessionInfo.LoginInfo.SecureSession != LLUUID.Zero)
288 {
289 this.SecureSessionID = sessionInfo.LoginInfo.SecureSession;
290 }
291
292 // Create Inventory, currently only works for sandbox mode
293 if (m_sandboxMode)
294 {
295 this.SetupInventory(sessionInfo);
296 }
297
298 ClientLoop();
299 }
300 }
301 # endregion
302
303
304 protected override void KillThread()
305 {
306 this.ClientThread.Abort();
307 }
308
309 #region World/Avatar To Viewer Methods
310
311 public void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
312 {
313 System.Text.Encoding enc = System.Text.Encoding.ASCII;
314 libsecondlife.Packets.ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket();
315 reply.ChatData.Audible = 1;
316 reply.ChatData.Message = message;
317 reply.ChatData.ChatType = type;
318 reply.ChatData.SourceType = 1;
319 reply.ChatData.Position = fromPos;
320 reply.ChatData.FromName = enc.GetBytes(fromName + "\0");
321 reply.ChatData.OwnerID = fromAgentID;
322 reply.ChatData.SourceID = fromAgentID;
323
324 this.OutPacket(reply);
325 }
326
327 public void SendAppearance(AvatarWearable[] wearables)
328 {
329 AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket();
330 aw.AgentData.AgentID = this.AgentID;
331 aw.AgentData.SerialNum = 0;
332 aw.AgentData.SessionID = this.SessionID;
333
334 aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13];
335 AgentWearablesUpdatePacket.WearableDataBlock awb;
336 for (int i = 0; i < wearables.Length; i++)
337 {
338 awb = new AgentWearablesUpdatePacket.WearableDataBlock();
339 awb.WearableType = (byte)i;
340 awb.AssetID = wearables[i].AssetID;
341 awb.ItemID = wearables[i].ItemID;
342 aw.WearableData[i] = awb;
343 }
344
345 this.OutPacket(aw);
346 }
347 #endregion
348
349 #region Inventory Creation
350 private void SetupInventory(AuthenticateResponse sessionInfo)
351 {
352 AgentInventory inventory = null;
353 if (sessionInfo.LoginInfo.InventoryFolder != null)
354 {
355 inventory = this.CreateInventory(sessionInfo.LoginInfo.InventoryFolder);
356 if (sessionInfo.LoginInfo.BaseFolder != null)
357 {
358 if (!inventory.HasFolder(sessionInfo.LoginInfo.BaseFolder))
359 {
360 m_inventoryCache.CreateNewInventoryFolder(this, sessionInfo.LoginInfo.BaseFolder);
361 }
362 this.newAssetFolder = sessionInfo.LoginInfo.BaseFolder;
363 AssetBase[] inventorySet = m_assetCache.CreateNewInventorySet(this.AgentID);
364 if (inventorySet != null)
365 {
366 for (int i = 0; i < inventorySet.Length; i++)
367 {
368 if (inventorySet[i] != null)
369 {
370 m_inventoryCache.AddNewInventoryItem(this, sessionInfo.LoginInfo.BaseFolder, inventorySet[i]);
371 }
372 }
373 }
374 }
375 }
376 }
377 private AgentInventory CreateInventory(LLUUID baseFolder)
378 {
379 AgentInventory inventory = null;
380 if (this.m_userServer != null)
381 {
382 // a user server is set so request the inventory from it
383 Console.WriteLine("getting inventory from user server");
384 inventory = m_inventoryCache.FetchAgentsInventory(this.AgentID, m_userServer);
385 }
386 else
387 {
388 inventory = new AgentInventory();
389 inventory.AgentID = this.AgentID;
390 inventory.CreateRootFolder(this.AgentID, false);
391 m_inventoryCache.AddNewAgentsInventory(inventory);
392 m_inventoryCache.CreateNewInventoryFolder(this, baseFolder);
393 }
394 return inventory;
395 }
396
397 private void CreateInventoryItem(CreateInventoryItemPacket packet)
398 {
399 if (!(packet.InventoryBlock.Type == 3 || packet.InventoryBlock.Type == 7))
400 {
401 System.Console.WriteLine("Attempted to create " + Util.FieldToString(packet.InventoryBlock.Name) + " in inventory. Unsupported type");
402 return;
403 }
404
405 //lets try this out with creating a notecard
406 AssetBase asset = new AssetBase();
407
408 asset.Name = Util.FieldToString(packet.InventoryBlock.Name);
409 asset.Description = Util.FieldToString(packet.InventoryBlock.Description);
410 asset.InvType = packet.InventoryBlock.InvType;
411 asset.Type = packet.InventoryBlock.Type;
412 asset.FullID = LLUUID.Random();
413
414 switch (packet.InventoryBlock.Type)
415 {
416 case 7: // Notecard
417 asset.Data = new byte[0];
418 break;
419
420 case 3: // Landmark
421 String content;
422 content = "Landmark version 2\n";
423 content += "region_id " + m_regionData.SimUUID + "\n";
424 String strPos = String.Format("%.2f %.2f %.2f>",
425 this.ClientAvatar.Pos.X,
426 this.ClientAvatar.Pos.Y,
427 this.ClientAvatar.Pos.Z);
428 content += "local_pos " + strPos + "\n";
429 asset.Data = (new System.Text.ASCIIEncoding()).GetBytes(content);
430 break;
431 default:
432 break;
433 }
434 m_assetCache.AddAsset(asset);
435 m_inventoryCache.AddNewInventoryItem(this, packet.InventoryBlock.FolderID, asset);
436 }
437 #endregion
438
439 }
440}