OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
AgentCircuitManager.cs
Go to the documentation of this file.
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 {
36  public class AgentCircuitManager
37  {
44  private Dictionary<uint, AgentCircuitData> m_agentCircuits = new Dictionary<uint, AgentCircuitData>();
45 
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 
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 
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 
151  {
152  AgentCircuitData agentCircuit = null;
153 
154  lock (m_agentCircuits)
155  m_agentCircuitsByUUID.TryGetValue(agentID, out agentCircuit);
156 
157  return agentCircuit;
158  }
159 
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 
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 }
uint circuitcode
Number given to the client when they log-in that they provide as credentials to the UDP server ...
AgentCircuitData GetAgentCircuitData(uint circuitCode)
virtual void AddNewCircuit(uint circuitCode, AgentCircuitData agentData)
Add information about a new circuit so that later on we can authenticate a new client session...
Vector3 startpos
Position the Agent's Avatar starts in the region
virtual void RemoveCircuit(UUID agentID)
AgentCircuitData GetAgentCircuitData(UUID agentID)
bool TryChangeCiruitCode(uint circuitcode, uint newcircuitcode)
Sometimes the circuitcode may not be known before setting up the connection
virtual AuthenticateResponse AuthenticateSession(UUID sessionID, UUID agentID, uint circuitcode)
UUID SessionID
Non secure Session ID
string firstname
Agent's account first name
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
Dictionary< UUID, AgentCircuitData > GetAgentCircuits()
Get all current agent circuits indexed by agent UUID.
UUID AgentID
Avatar Unique Agent Identifier
virtual void RemoveCircuit(uint circuitCode)
void UpdateAgentData(AgentCircuitData agentData)
void UpdateAgentChildStatus(uint circuitcode, bool childstatus)