aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/ClientView.cs
diff options
context:
space:
mode:
authorMW2007-06-12 18:11:14 +0000
committerMW2007-06-12 18:11:14 +0000
commitd8f232c8b05a7f1954737c5f43be9da04a9844dd (patch)
treeac49fdeaeaee02da9099480d389d0fe83d9dcb71 /OpenSim/OpenSim.RegionServer/ClientView.cs
parentRenamed World class to Scene class (diff)
downloadopensim-SC-d8f232c8b05a7f1954737c5f43be9da04a9844dd.zip
opensim-SC-d8f232c8b05a7f1954737c5f43be9da04a9844dd.tar.gz
opensim-SC-d8f232c8b05a7f1954737c5f43be9da04a9844dd.tar.bz2
opensim-SC-d8f232c8b05a7f1954737c5f43be9da04a9844dd.tar.xz
Diffstat (limited to 'OpenSim/OpenSim.RegionServer/ClientView.cs')
-rw-r--r--OpenSim/OpenSim.RegionServer/ClientView.cs293
1 files changed, 293 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.RegionServer/ClientView.cs b/OpenSim/OpenSim.RegionServer/ClientView.cs
new file mode 100644
index 0000000..e9c1f2d
--- /dev/null
+++ b/OpenSim/OpenSim.RegionServer/ClientView.cs
@@ -0,0 +1,293 @@
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 IGridServer m_gridServer;
79 private InventoryCache m_inventoryCache;
80 private int cachedtextureserial = 0;
81 private RegionInfo m_regionData;
82 protected AuthenticateSessionsBase m_authenticateSessionsHandler;
83
84 public ClientView(EndPoint remoteEP, UseCircuitCodePacket initialcirpack, Dictionary<uint, ClientView> clientThreads, IWorld world, AssetCache assetCache, PacketServer packServer, InventoryCache inventoryCache, AuthenticateSessionsBase authenSessions )
85 {
86 m_world = world;
87 m_clientThreads = clientThreads;
88 m_assetCache = assetCache;
89
90 m_networkServer = packServer;
91 m_inventoryCache = inventoryCache;
92 m_authenticateSessionsHandler = authenSessions;
93
94 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "OpenSimClient.cs - Started up new client thread to handle incoming request");
95 cirpack = initialcirpack;
96 userEP = remoteEP;
97
98 this.m_child = m_authenticateSessionsHandler.GetAgentChildStatus(initialcirpack.CircuitCode.Code);
99 this.startpos = m_authenticateSessionsHandler.GetPosition(initialcirpack.CircuitCode.Code);
100
101 PacketQueue = new BlockingQueue<QueItem>();
102
103 this.UploadAssets = new AgentAssetUpload(this, m_assetCache, m_inventoryCache);
104 AckTimer = new System.Timers.Timer(500);
105 AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed);
106 AckTimer.Start();
107
108 this.RegisterLocalPacketHandlers();
109
110 ClientThread = new Thread(new ThreadStart(AuthUser));
111 ClientThread.IsBackground = true;
112 ClientThread.Start();
113 }
114
115 # region Client Methods
116 public void UpgradeClient()
117 {
118 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "SimClient.cs:UpgradeClient() - upgrading child to full agent");
119 this.m_child = false;
120 this.startpos = m_authenticateSessionsHandler.GetPosition(CircuitCode);
121 m_authenticateSessionsHandler.UpdateAgentChildStatus(CircuitCode, false);
122 OnChildAgentStatus(this.m_child);
123 }
124
125 public void DowngradeClient()
126 {
127 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "SimClient.cs:UpgradeClient() - changing full agent to child");
128 this.m_child = true;
129 OnChildAgentStatus(this.m_child);
130
131 }
132
133 public void KillClient()
134 {
135 KillObjectPacket kill = new KillObjectPacket();
136 kill.ObjectData = new KillObjectPacket.ObjectDataBlock[1];
137 kill.ObjectData[0] = new KillObjectPacket.ObjectDataBlock();
138 //kill.ObjectData[0].ID = this.ClientAvatar.localid;
139 foreach (ClientView client in m_clientThreads.Values)
140 {
141 client.OutPacket(kill);
142 }
143
144 this.m_inventoryCache.ClientLeaving(this.AgentID, null);
145
146
147 // m_world.RemoveViewerAgent(this);
148
149 m_clientThreads.Remove(this.CircuitCode);
150 m_networkServer.RemoveClientCircuit(this.CircuitCode);
151 this.ClientThread.Abort();
152 }
153 #endregion
154
155 # region Packet Handling
156 public static bool AddPacketHandler(PacketType packetType, PacketMethod handler)
157 {
158 bool result = false;
159 lock (PacketHandlers)
160 {
161 if (!PacketHandlers.ContainsKey(packetType))
162 {
163 PacketHandlers.Add(packetType, handler);
164 result = true;
165 }
166 }
167 return result;
168 }
169
170 public bool AddLocalPacketHandler(PacketType packetType, PacketMethod handler)
171 {
172 bool result = false;
173 lock (m_packetHandlers)
174 {
175 if (!m_packetHandlers.ContainsKey(packetType))
176 {
177 m_packetHandlers.Add(packetType, handler);
178 result = true;
179 }
180 }
181 return result;
182 }
183
184 protected virtual bool ProcessPacketMethod(Packet packet)
185 {
186 bool result = false;
187 bool found = false;
188 PacketMethod method;
189 if (m_packetHandlers.TryGetValue(packet.Type, out method))
190 {
191 //there is a local handler for this packet type
192 result = method(this, packet);
193 }
194 else
195 {
196 //there is not a local handler so see if there is a Global handler
197 lock (PacketHandlers)
198 {
199 found = PacketHandlers.TryGetValue(packet.Type, out method);
200 }
201 if (found)
202 {
203 result = method(this, packet);
204 }
205 }
206 return result;
207 }
208
209 protected virtual void ClientLoop()
210 {
211 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "OpenSimClient.cs:ClientLoop() - Entered loop");
212 while (true)
213 {
214 QueItem nextPacket = PacketQueue.Dequeue();
215 if (nextPacket.Incoming)
216 {
217 //is a incoming packet
218 ProcessInPacket(nextPacket.Packet);
219 }
220 else
221 {
222 //is a out going packet
223 ProcessOutPacket(nextPacket.Packet);
224 }
225 }
226 }
227 # endregion
228
229 # region Setup
230
231 protected virtual void InitNewClient()
232 {
233 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "OpenSimClient.cs:InitNewClient() - Adding viewer agent to world");
234 this.m_world.AddNewAvatar(this, this.AgentID, false);
235 }
236
237 protected virtual void AuthUser()
238 {
239 // AuthenticateResponse sessionInfo = m_gridServer.AuthenticateSession(cirpack.CircuitCode.SessionID, cirpack.CircuitCode.ID, cirpack.CircuitCode.Code);
240 AuthenticateResponse sessionInfo = this.m_authenticateSessionsHandler.AuthenticateSession(cirpack.CircuitCode.SessionID, cirpack.CircuitCode.ID, cirpack.CircuitCode.Code);
241 if (!sessionInfo.Authorised)
242 {
243 //session/circuit not authorised
244 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.NORMAL, "OpenSimClient.cs:AuthUser() - New user request denied to " + userEP.ToString());
245 ClientThread.Abort();
246 }
247 else
248 {
249 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(OpenSim.Framework.Console.LogPriority.NORMAL, "OpenSimClient.cs:AuthUser() - Got authenticated connection from " + userEP.ToString());
250 //session is authorised
251 this.AgentID = cirpack.CircuitCode.ID;
252 this.SessionID = cirpack.CircuitCode.SessionID;
253 this.CircuitCode = cirpack.CircuitCode.Code;
254 this.firstName = sessionInfo.LoginInfo.First;
255 this.lastName = sessionInfo.LoginInfo.Last;
256
257 if (sessionInfo.LoginInfo.SecureSession != LLUUID.Zero)
258 {
259 this.SecureSessionID = sessionInfo.LoginInfo.SecureSession;
260 }
261 InitNewClient();
262
263 ClientLoop();
264 }
265 }
266 # endregion
267
268
269 protected override void KillThread()
270 {
271 this.ClientThread.Abort();
272 }
273
274 #region Inventory Creation
275 private void SetupInventory(AuthenticateResponse sessionInfo)
276 {
277
278 }
279 private AgentInventory CreateInventory(LLUUID baseFolder)
280 {
281 AgentInventory inventory = null;
282
283 return inventory;
284 }
285
286 private void CreateInventoryItem(CreateInventoryItemPacket packet)
287 {
288
289 }
290 #endregion
291
292 }
293}