diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/AgentCircuitManager.cs | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/OpenSim/Framework/AgentCircuitManager.cs b/OpenSim/Framework/AgentCircuitManager.cs new file mode 100644 index 0000000..b6e48b4 --- /dev/null +++ b/OpenSim/Framework/AgentCircuitManager.cs | |||
@@ -0,0 +1,229 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.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 OpenSimulator 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 | using System.Collections.Generic; | ||
29 | using OpenMetaverse; | ||
30 | |||
31 | namespace OpenSim.Framework | ||
32 | { | ||
33 | /// <summary> | ||
34 | /// Manage client circuits | ||
35 | /// </summary> | ||
36 | public class AgentCircuitManager | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// Agent circuits indexed by circuit code. | ||
40 | /// </summary> | ||
41 | /// <remarks> | ||
42 | /// We lock this for operations both on this dictionary and on m_agentCircuitsByUUID | ||
43 | /// </remarks> | ||
44 | private Dictionary<uint, AgentCircuitData> m_agentCircuits = new Dictionary<uint, AgentCircuitData>(); | ||
45 | |||
46 | /// <summary> | ||
47 | /// Agent circuits indexed by agent UUID. | ||
48 | /// </summary> | ||
49 | private Dictionary<UUID, AgentCircuitData> m_agentCircuitsByUUID = new Dictionary<UUID, AgentCircuitData>(); | ||
50 | |||
51 | public virtual AuthenticateResponse AuthenticateSession(UUID sessionID, UUID agentID, uint circuitcode) | ||
52 | { | ||
53 | AgentCircuitData validcircuit = null; | ||
54 | |||
55 | lock (m_agentCircuits) | ||
56 | { | ||
57 | if (m_agentCircuits.ContainsKey(circuitcode)) | ||
58 | validcircuit = m_agentCircuits[circuitcode]; | ||
59 | } | ||
60 | |||
61 | AuthenticateResponse user = new AuthenticateResponse(); | ||
62 | |||
63 | if (validcircuit == null) | ||
64 | { | ||
65 | //don't have this circuit code in our list | ||
66 | user.Authorised = false; | ||
67 | return user; | ||
68 | } | ||
69 | |||
70 | if ((sessionID == validcircuit.SessionID) && (agentID == validcircuit.AgentID)) | ||
71 | { | ||
72 | user.Authorised = true; | ||
73 | user.LoginInfo = new Login(); | ||
74 | user.LoginInfo.Agent = agentID; | ||
75 | user.LoginInfo.Session = sessionID; | ||
76 | user.LoginInfo.SecureSession = validcircuit.SecureSessionID; | ||
77 | user.LoginInfo.First = validcircuit.firstname; | ||
78 | user.LoginInfo.Last = validcircuit.lastname; | ||
79 | user.LoginInfo.InventoryFolder = validcircuit.InventoryFolder; | ||
80 | user.LoginInfo.BaseFolder = validcircuit.BaseFolder; | ||
81 | user.LoginInfo.StartPos = validcircuit.startpos; | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | // Invalid | ||
86 | user.Authorised = false; | ||
87 | } | ||
88 | |||
89 | return user; | ||
90 | } | ||
91 | |||
92 | /// <summary> | ||
93 | /// Add information about a new circuit so that later on we can authenticate a new client session. | ||
94 | /// </summary> | ||
95 | /// <param name="circuitCode"></param> | ||
96 | /// <param name="agentData"></param> | ||
97 | public virtual void AddNewCircuit(uint circuitCode, AgentCircuitData agentData) | ||
98 | { | ||
99 | lock (m_agentCircuits) | ||
100 | { | ||
101 | if (m_agentCircuits.ContainsKey(circuitCode)) | ||
102 | { | ||
103 | m_agentCircuits[circuitCode] = agentData; | ||
104 | m_agentCircuitsByUUID[agentData.AgentID] = agentData; | ||
105 | } | ||
106 | else | ||
107 | { | ||
108 | m_agentCircuits.Add(circuitCode, agentData); | ||
109 | m_agentCircuitsByUUID[agentData.AgentID] = agentData; | ||
110 | } | ||
111 | } | ||
112 | } | ||
113 | |||
114 | public virtual void RemoveCircuit(uint circuitCode) | ||
115 | { | ||
116 | lock (m_agentCircuits) | ||
117 | { | ||
118 | if (m_agentCircuits.ContainsKey(circuitCode)) | ||
119 | { | ||
120 | UUID agentID = m_agentCircuits[circuitCode].AgentID; | ||
121 | m_agentCircuits.Remove(circuitCode); | ||
122 | m_agentCircuitsByUUID.Remove(agentID); | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | |||
127 | public virtual void RemoveCircuit(UUID agentID) | ||
128 | { | ||
129 | lock (m_agentCircuits) | ||
130 | { | ||
131 | if (m_agentCircuitsByUUID.ContainsKey(agentID)) | ||
132 | { | ||
133 | uint circuitCode = m_agentCircuitsByUUID[agentID].circuitcode; | ||
134 | m_agentCircuits.Remove(circuitCode); | ||
135 | m_agentCircuitsByUUID.Remove(agentID); | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | |||
140 | public AgentCircuitData GetAgentCircuitData(uint circuitCode) | ||
141 | { | ||
142 | AgentCircuitData agentCircuit = null; | ||
143 | |||
144 | lock (m_agentCircuits) | ||
145 | m_agentCircuits.TryGetValue(circuitCode, out agentCircuit); | ||
146 | |||
147 | return agentCircuit; | ||
148 | } | ||
149 | |||
150 | public AgentCircuitData GetAgentCircuitData(UUID agentID) | ||
151 | { | ||
152 | AgentCircuitData agentCircuit = null; | ||
153 | |||
154 | lock (m_agentCircuits) | ||
155 | m_agentCircuitsByUUID.TryGetValue(agentID, out agentCircuit); | ||
156 | |||
157 | return agentCircuit; | ||
158 | } | ||
159 | |||
160 | /// <summary> | ||
161 | /// Get all current agent circuits indexed by agent UUID. | ||
162 | /// </summary> | ||
163 | /// <returns></returns> | ||
164 | public Dictionary<UUID, AgentCircuitData> GetAgentCircuits() | ||
165 | { | ||
166 | lock (m_agentCircuits) | ||
167 | return new Dictionary<UUID, AgentCircuitData>(m_agentCircuitsByUUID); | ||
168 | } | ||
169 | |||
170 | public void UpdateAgentData(AgentCircuitData agentData) | ||
171 | { | ||
172 | lock (m_agentCircuits) | ||
173 | { | ||
174 | if (m_agentCircuits.ContainsKey((uint) agentData.circuitcode)) | ||
175 | { | ||
176 | m_agentCircuits[(uint) agentData.circuitcode].firstname = agentData.firstname; | ||
177 | m_agentCircuits[(uint) agentData.circuitcode].lastname = agentData.lastname; | ||
178 | m_agentCircuits[(uint) agentData.circuitcode].startpos = agentData.startpos; | ||
179 | |||
180 | // Updated for when we don't know them before calling Scene.NewUserConnection | ||
181 | m_agentCircuits[(uint) agentData.circuitcode].SecureSessionID = agentData.SecureSessionID; | ||
182 | m_agentCircuits[(uint) agentData.circuitcode].SessionID = agentData.SessionID; | ||
183 | |||
184 | // m_log.Debug("update user start pos is " + agentData.startpos.X + " , " + agentData.startpos.Y + " , " + agentData.startpos.Z); | ||
185 | } | ||
186 | } | ||
187 | } | ||
188 | |||
189 | /// <summary> | ||
190 | /// Sometimes the circuitcode may not be known before setting up the connection | ||
191 | /// </summary> | ||
192 | /// <param name="circuitcode"></param> | ||
193 | /// <param name="newcircuitcode"></param> | ||
194 | public bool TryChangeCiruitCode(uint circuitcode, uint newcircuitcode) | ||
195 | { | ||
196 | lock (m_agentCircuits) | ||
197 | { | ||
198 | if (m_agentCircuits.ContainsKey((uint)circuitcode) && !m_agentCircuits.ContainsKey((uint)newcircuitcode)) | ||
199 | { | ||
200 | AgentCircuitData agentData = m_agentCircuits[(uint)circuitcode]; | ||
201 | |||
202 | agentData.circuitcode = newcircuitcode; | ||
203 | |||
204 | m_agentCircuits.Remove((uint)circuitcode); | ||
205 | m_agentCircuits.Add(newcircuitcode, agentData); | ||
206 | return true; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | return false; | ||
211 | } | ||
212 | |||
213 | public void UpdateAgentChildStatus(uint circuitcode, bool childstatus) | ||
214 | { | ||
215 | lock (m_agentCircuits) | ||
216 | if (m_agentCircuits.ContainsKey(circuitcode)) | ||
217 | m_agentCircuits[circuitcode].child = childstatus; | ||
218 | } | ||
219 | |||
220 | public bool GetAgentChildStatus(uint circuitcode) | ||
221 | { | ||
222 | lock (m_agentCircuits) | ||
223 | if (m_agentCircuits.ContainsKey(circuitcode)) | ||
224 | return m_agentCircuits[circuitcode].child; | ||
225 | |||
226 | return false; | ||
227 | } | ||
228 | } | ||
229 | } \ No newline at end of file | ||