aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/Client/ClientView.cs
diff options
context:
space:
mode:
authorAdam Frisby2007-07-11 08:02:47 +0000
committerAdam Frisby2007-07-11 08:02:47 +0000
commit5c7ffdde0b9642a42e8f5987e06eb01220ff7776 (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /OpenSim/OpenSim.RegionServer/Client/ClientView.cs
parentWho would have known that the only way of specifying utf-8 without preamble, ... (diff)
downloadopensim-SC_OLD-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.zip
opensim-SC_OLD-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.tar.gz
opensim-SC_OLD-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.tar.bz2
opensim-SC_OLD-5c7ffdde0b9642a42e8f5987e06eb01220ff7776.tar.xz
* Wiping trunk in prep for Sugilite
Diffstat (limited to 'OpenSim/OpenSim.RegionServer/Client/ClientView.cs')
-rw-r--r--OpenSim/OpenSim.RegionServer/Client/ClientView.cs461
1 files changed, 0 insertions, 461 deletions
diff --git a/OpenSim/OpenSim.RegionServer/Client/ClientView.cs b/OpenSim/OpenSim.RegionServer/Client/ClientView.cs
deleted file mode 100644
index 29efcc9..0000000
--- a/OpenSim/OpenSim.RegionServer/Client/ClientView.cs
+++ /dev/null
@@ -1,461 +0,0 @@
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;
31using System.Collections.Generic;
32using libsecondlife;
33using libsecondlife.Packets;
34using Nwc.XmlRpc;
35using System.Net;
36using System.Net.Sockets;
37using System.IO;
38using System.Threading;
39using System.Timers;
40using OpenSim.Framework.Interfaces;
41using OpenSim.Framework.Types;
42using OpenSim.Framework.Inventory;
43using OpenSim.Framework.Utilities;
44using OpenSim.RegionServer.Simulator;
45using OpenSim.RegionServer.Assets;
46using OpenSim.Framework.Console;
47
48namespace OpenSim.RegionServer.Client
49{
50 public delegate bool PacketMethod(ClientView simClient, Packet packet);
51
52 /// <summary>
53 /// Handles new client connections
54 /// Constructor takes a single Packet and authenticates everything
55 /// </summary>
56 public partial class ClientView : ClientViewBase, IClientAPI
57 {
58 protected static Dictionary<PacketType, PacketMethod> PacketHandlers = new Dictionary<PacketType, PacketMethod>(); //Global/static handlers for all clients
59 protected Dictionary<PacketType, PacketMethod> m_packetHandlers = new Dictionary<PacketType, PacketMethod>(); //local handlers for this instance
60
61 public LLUUID AgentID;
62 public LLUUID SessionID;
63 public LLUUID SecureSessionID = LLUUID.Zero;
64 public bool m_child;
65 public Simulator.Avatar ClientAvatar;
66 private UseCircuitCodePacket cirpack;
67 public Thread ClientThread;
68 public LLVector3 startpos;
69
70 private AgentAssetUpload UploadAssets;
71 private LLUUID newAssetFolder = LLUUID.Zero;
72 private bool debug = false;
73 private World m_world;
74 private Dictionary<uint, ClientView> m_clientThreads;
75 private AssetCache m_assetCache;
76 private IGridServer m_gridServer;
77 private IUserServer m_userServer = null;
78 private InventoryCache m_inventoryCache;
79 public bool m_sandboxMode;
80 private int cachedtextureserial = 0;
81 private RegionInfo m_regionData;
82 protected AuthenticateSessionsBase m_authenticateSessionsHandler;
83
84 public IUserServer UserServer
85 {
86 set
87 {
88 this.m_userServer = value;
89 }
90 }
91
92 public LLVector3 StartPos
93 {
94 get
95 {
96 return startpos;
97 }
98 set
99 {
100 startpos = value;
101 }
102 }
103
104 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)
105 {
106 m_world = world;
107 m_clientThreads = clientThreads;
108 m_assetCache = assetCache;
109 m_gridServer = gridServer;
110 m_networkServer = application;
111 m_inventoryCache = inventoryCache;
112 m_sandboxMode = sandboxMode;
113 m_child = child;
114 m_regionData = regionDat;
115 m_authenticateSessionsHandler = authenSessions;
116 MainConsole.Instance.Notice("OpenSimClient.cs - Started up new client thread to handle incoming request");
117 cirpack = initialcirpack;
118 userEP = remoteEP;
119
120 if (m_gridServer.GetName() == "Remote")
121 {
122 this.m_child = m_authenticateSessionsHandler.GetAgentChildStatus(initialcirpack.CircuitCode.Code);
123 this.startpos = m_authenticateSessionsHandler.GetPosition(initialcirpack.CircuitCode.Code);
124
125 // Dont rez new users underground
126 float aboveGround = 3.0f; // rez at least 3 meters above ground
127 if (this.startpos.Z < (m_world.Terrain[(int)this.startpos.X, (int)this.startpos.Y] + aboveGround))
128 this.startpos.Z = m_world.Terrain[(int)this.startpos.X, (int)this.startpos.Y] + aboveGround;
129
130 }
131 else
132 {
133 this.startpos = new LLVector3(128, 128, m_world.Terrain[(int)128, (int)128] + 15.0f); // new LLVector3(128.0f, 128.0f, 60f);
134 }
135
136 PacketQueue = new BlockingQueue<QueItem>();
137
138 this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache);
139 AckTimer = new System.Timers.Timer(500);
140 AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
141 AckTimer.Start();
142
143 this.RegisterLocalPacketHandlers();
144
145
146
147 ClientThread = new Thread(new ThreadStart(AuthUser));
148 ClientThread.IsBackground = true;
149 ClientThread.Start();
150 }
151
152 # region Client Methods
153 public void UpgradeClient()
154 {
155 MainConsole.Instance.Notice("SimClient.cs:UpgradeClient() - upgrading child to full agent");
156 this.m_child = false;
157 //this.m_world.RemoveViewerAgent(this);
158 if (!this.m_sandboxMode)
159 {
160 this.startpos = m_authenticateSessionsHandler.GetPosition(CircuitCode);
161 m_authenticateSessionsHandler.UpdateAgentChildStatus(CircuitCode, false);
162 }
163 OnChildAgentStatus(this.m_child);
164 //this.InitNewClient();
165 }
166
167 public void DowngradeClient()
168 {
169 MainConsole.Instance.Notice("SimClient.cs:UpgradeClient() - changing full agent to child");
170 this.m_child = true;
171 OnChildAgentStatus(this.m_child);
172 //this.m_world.RemoveViewerAgent(this);
173 //this.m_world.AddViewerAgent(this);
174 }
175
176 public void KillClient()
177 {
178 KillObjectPacket kill = new KillObjectPacket();
179 kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
180 kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
181 kill.ObjectData[0].ID = this.ClientAvatar.localid;
182 foreach (ClientView client in m_clientThreads.Values)
183 {
184 client.OutPacket(kill);
185 }
186 if (this.m_userServer != null)
187 {
188 this.m_inventoryCache.ClientLeaving(this.AgentID, this.m_userServer);
189 }
190 else
191 {
192 this.m_inventoryCache.ClientLeaving(this.AgentID, null);
193 }
194
195 m_world.RemoveViewerAgent(this);
196
197 m_clientThreads.Remove(this.CircuitCode);
198 m_networkServer.RemoveClientCircuit(this.CircuitCode);
199 this.ClientThread.Abort();
200 }
201 #endregion
202
203 # region Packet Handling
204 public static bool AddPacketHandler(PacketType packetType, PacketMethod handler)
205 {
206 bool result = false;
207 lock (PacketHandlers)
208 {
209 if (!PacketHandlers.ContainsKey(packetType))
210 {
211 PacketHandlers.Add(packetType, handler);
212 result = true;
213 }
214 }
215 return result;
216 }
217
218 public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler)
219 {
220 bool result = false;
221 lock (m_packetHandlers)
222 {
223 if (!m_packetHandlers.ContainsKey(packetType))
224 {
225 m_packetHandlers.Add(packetType, handler);
226 result = true;
227 }
228 }
229 return result;
230 }
231
232 protected virtual bool ProcessPacketMethod(Packet packet)
233 {
234 bool result = false;
235 bool found = false;
236 PacketMethod method;
237 if (m_packetHandlers.TryGetValue(packet.Type, out method))
238 {
239 //there is a local handler for this packet type
240 result = method(this, packet);
241 }
242 else
243 {
244 //there is not a local handler so see if there is a Global handler
245 lock (PacketHandlers)
246 {
247 found = PacketHandlers.TryGetValue(packet.Type, out method);
248 }
249 if (found)
250 {
251 result = method(this, packet);
252 }
253 }
254 return result;
255 }
256
257 protected virtual void ClientLoop()
258 {
259 MainConsole.Instance.Notice("OpenSimClient.cs:ClientLoop() - Entered loop");
260 while (true)
261 {
262 QueItem nextPacket = PacketQueue.Dequeue();
263 if (nextPacket.Incoming)
264 {
265 //is a incoming packet
266 ProcessInPacket(nextPacket.Packet);
267 }
268 else
269 {
270 //is a out going packet
271 ProcessOutPacket(nextPacket.Packet);
272 }
273 }
274 }
275 # endregion
276
277 # region Setup
278
279 protected virtual void InitNewClient()
280 {
281 MainConsole.Instance.Notice("OpenSimClient.cs:InitNewClient() - Adding viewer agent to world");
282 this.ClientAvatar = m_world.AddViewerAgent(this);
283 }
284
285 protected virtual void AuthUser()
286 {
287 // AuthenticateResponse sessionInfo = m_gridServer.AuthenticateSession(cirpack.CircuitCode.SessionID, cirpack.CircuitCode.ID, cirpack.CircuitCode.Code);
288 AuthenticateResponse sessionInfo = this.m_networkServer.AuthenticateSession(cirpack.CircuitCode.SessionID, cirpack.CircuitCode.ID, cirpack.CircuitCode.Code);
289 if (!sessionInfo.Authorised)
290 {
291 //session/circuit not authorised
292 OpenSim.Framework.Console.MainConsole.Instance.Notice("OpenSimClient.cs:AuthUser() - New user request denied to " + userEP.ToString());
293 ClientThread.Abort();
294 }
295 else
296 {
297 OpenSim.Framework.Console.MainConsole.Instance.Notice("OpenSimClient.cs:AuthUser() - Got authenticated connection from " + userEP.ToString());
298 //session is authorised
299 this.AgentID = cirpack.CircuitCode.ID;
300 this.SessionID = cirpack.CircuitCode.SessionID;
301 this.CircuitCode = cirpack.CircuitCode.Code;
302 InitNewClient();
303 this.ClientAvatar.firstname = sessionInfo.LoginInfo.First;
304 this.ClientAvatar.lastname = sessionInfo.LoginInfo.Last;
305 if (sessionInfo.LoginInfo.SecureSession != LLUUID.Zero)
306 {
307 this.SecureSessionID = sessionInfo.LoginInfo.SecureSession;
308 }
309
310 // Create Inventory, currently only works for sandbox mode
311 if (m_sandboxMode)
312 {
313 this.SetupInventory(sessionInfo);
314 }
315
316 //m_world.parcelManager.sendParcelOverlay(this);
317 m_world.estateManager.sendRegionInfoPacket(this);
318
319 ClientLoop();
320 }
321 }
322 # endregion
323
324
325 protected override void KillThread()
326 {
327 this.ClientThread.Abort();
328 }
329
330 #region World/Avatar To Viewer Methods
331
332 public void SendChatMessage(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
333 {
334 System.Text.Encoding enc = System.Text.Encoding.ASCII;
335 libsecondlife.Packets.ChatFromSimulatorPacket reply = new ChatFromSimulatorPacket();
336 reply.ChatData.Audible = 1;
337 reply.ChatData.Message = message;
338 reply.ChatData.ChatType = type;
339 reply.ChatData.SourceType = 1;
340 reply.ChatData.Position = fromPos;
341 reply.ChatData.FromName = enc.GetBytes(fromName + "\0");
342 reply.ChatData.OwnerID = fromAgentID;
343 reply.ChatData.SourceID = fromAgentID;
344
345 this.OutPacket(reply);
346 }
347
348 public void SendAppearance(AvatarWearable[] wearables)
349 {
350 AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket();
351 aw.AgentData.AgentID = this.AgentID;
352 aw.AgentData.SerialNum = 0;
353 aw.AgentData.SessionID = this.SessionID;
354
355 aw.WearableData = new AgentWearablesUpdatePacket.WearableDataBlock[13];
356 AgentWearablesUpdatePacket.WearableDataBlock awb;
357 for (int i = 0; i < wearables.Length; i++)
358 {
359 awb = new AgentWearablesUpdatePacket.WearableDataBlock();
360 awb.WearableType = (byte)i;
361 awb.AssetID = wearables[i].AssetID;
362 awb.ItemID = wearables[i].ItemID;
363 aw.WearableData[i] = awb;
364 }
365
366 this.OutPacket(aw);
367 }
368 #endregion
369
370 #region Inventory Creation
371 private void SetupInventory(AuthenticateResponse sessionInfo)
372 {
373 AgentInventory inventory = null;
374 if (sessionInfo.LoginInfo.InventoryFolder != null)
375 {
376 inventory = this.CreateInventory(sessionInfo.LoginInfo.InventoryFolder);
377 if (sessionInfo.LoginInfo.BaseFolder != null)
378 {
379 if (!inventory.HasFolder(sessionInfo.LoginInfo.BaseFolder))
380 {
381 m_inventoryCache.CreateNewInventoryFolder(this, sessionInfo.LoginInfo.BaseFolder);
382 }
383 this.newAssetFolder = sessionInfo.LoginInfo.BaseFolder;
384 AssetBase[] inventorySet = m_assetCache.CreateNewInventorySet(this.AgentID);
385 if (inventorySet != null)
386 {
387 for (int i = 0; i < inventorySet.Length; i++)
388 {
389 if (inventorySet[i] != null)
390 {
391 m_inventoryCache.AddNewInventoryItem(this, sessionInfo.LoginInfo.BaseFolder, inventorySet[i]);
392 }
393 }
394 }
395 }
396 }
397 }
398 private AgentInventory CreateInventory(LLUUID baseFolder)
399 {
400 AgentInventory inventory = null;
401 if (this.m_userServer != null)
402 {
403 // a user server is set so request the inventory from it
404 MainConsole.Instance.Verbose("getting inventory from user server");
405 inventory = m_inventoryCache.FetchAgentsInventory(this.AgentID, m_userServer);
406 }
407 else
408 {
409 inventory = new AgentInventory();
410 inventory.AgentID = this.AgentID;
411 inventory.CreateRootFolder(this.AgentID, false);
412 m_inventoryCache.AddNewAgentsInventory(inventory);
413 m_inventoryCache.CreateNewInventoryFolder(this, baseFolder);
414 }
415 return inventory;
416 }
417
418 private void CreateInventoryItem(CreateInventoryItemPacket packet)
419 {
420 if (!(packet.InventoryBlock.Type == 3 || packet.InventoryBlock.Type == 7))
421 {
422 MainConsole.Instance.Warn("Attempted to create " + Util.FieldToString(packet.InventoryBlock.Name) + " in inventory. Unsupported type");
423 return;
424 }
425
426 //lets try this out with creating a notecard
427 AssetBase asset = new AssetBase();
428
429 asset.Name = Util.FieldToString(packet.InventoryBlock.Name);
430 asset.Description = Util.FieldToString(packet.InventoryBlock.Description);
431 asset.InvType = packet.InventoryBlock.InvType;
432 asset.Type = packet.InventoryBlock.Type;
433 asset.FullID = LLUUID.Random();
434
435 switch (packet.InventoryBlock.Type)
436 {
437 case 7: // Notecard
438 asset.Data = new byte[0];
439 break;
440
441 case 3: // Landmark
442 String content;
443 content = "Landmark version 2\n";
444 content += "region_id " + m_regionData.SimUUID + "\n";
445 String strPos = String.Format("%.2f %.2f %.2f>",
446 this.ClientAvatar.Pos.X,
447 this.ClientAvatar.Pos.Y,
448 this.ClientAvatar.Pos.Z);
449 content += "local_pos " + strPos + "\n";
450 asset.Data = (new System.Text.ASCIIEncoding()).GetBytes(content);
451 break;
452 default:
453 break;
454 }
455 m_assetCache.AddAsset(asset);
456 m_inventoryCache.AddNewInventoryItem(this, packet.InventoryBlock.FolderID, asset);
457 }
458 #endregion
459
460 }
461}