aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/ClientView.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/ClientView.cs')
-rw-r--r--OpenSim/Region/ClientStack/ClientView.cs273
1 files changed, 273 insertions, 0 deletions
diff --git a/OpenSim/Region/ClientStack/ClientView.cs b/OpenSim/Region/ClientStack/ClientView.cs
new file mode 100644
index 0000000..312da9d
--- /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.Caches;
46
47namespace OpenSim
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}