aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/ClientManager.cs163
-rw-r--r--OpenSim/Framework/IScene.cs1
2 files changed, 13 insertions, 151 deletions
diff --git a/OpenSim/Framework/ClientManager.cs b/OpenSim/Framework/ClientManager.cs
index 094a3ff..5ebbbc1 100644
--- a/OpenSim/Framework/ClientManager.cs
+++ b/OpenSim/Framework/ClientManager.cs
@@ -34,120 +34,33 @@ using OpenMetaverse.Packets;
34 34
35namespace OpenSim.Framework 35namespace OpenSim.Framework
36{ 36{
37 public delegate void ForEachClientDelegate(IClientAPI client);
38
39 public class ClientManager 37 public class ClientManager
40 { 38 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 39 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42 40
43 private Dictionary<uint, IClientAPI> m_clients; 41 private Dictionary<uint, IClientAPI> m_clients = new Dictionary<uint, IClientAPI>();
44
45 public ClientManager()
46 {
47 m_clients = new Dictionary<uint, IClientAPI>();
48 }
49 42
50 public void ForEachClient(ForEachClientDelegate whatToDo) 43 public void Add(uint circuitCode, IClientAPI client)
51 { 44 {
52 IClientAPI[] LocalClients;
53 lock (m_clients) 45 lock (m_clients)
54 { 46 m_clients.Add(circuitCode, client);
55 LocalClients = new IClientAPI[m_clients.Count];
56 m_clients.Values.CopyTo(LocalClients, 0);
57 }
58
59 for (int i = 0; i < LocalClients.Length; i++)
60 {
61 try
62 {
63 whatToDo(LocalClients[i]);
64 }
65 catch (Exception e)
66 {
67 m_log.Warn("[CLIENT]: Unable to do ForEachClient for one of the clients" + "\n Reason: " + e.ToString());
68 }
69 }
70 } 47 }
71 48
72 public void Remove(uint id) 49 public bool Remove(uint circuitCode)
73 { 50 {
74 lock (m_clients) 51 lock (m_clients)
75 { 52 return m_clients.Remove(circuitCode);
76 m_clients.Remove(id);
77 }
78 }
79
80 public void Add(uint id, IClientAPI client)
81 {
82 lock (m_clients)
83 {
84 m_clients.Add(id, client);
85 }
86 }
87
88 /// <summary>
89 /// Pass incoming packet to client.
90 /// </summary>
91 /// <param name="circuitCode">uint identifying the connection/client.</param>
92 /// <param name="packet">object containing the packet.</param>
93 public void InPacket(uint circuitCode, object packet)
94 {
95 IClientAPI client;
96 bool tryGetRet = false;
97
98 lock (m_clients)
99 tryGetRet = m_clients.TryGetValue(circuitCode, out client);
100
101 if (tryGetRet)
102 {
103 client.InPacket(packet);
104 }
105 } 53 }
106 54
107 public void CloseAllAgents(uint circuitCode) 55 public bool TryGetClient(uint circuitCode, out IClientAPI user)
108 { 56 {
109 IClientAPI client;
110 bool tryGetRet = false;
111 lock (m_clients) 57 lock (m_clients)
112 tryGetRet = m_clients.TryGetValue(circuitCode, out client); 58 return m_clients.TryGetValue(circuitCode, out user);
113 if (tryGetRet)
114 {
115 CloseAllCircuits(client.AgentId);
116 }
117 }
118
119 public void CloseAllCircuits(UUID agentId)
120 {
121 uint[] circuits = GetAllCircuits(agentId);
122 // We're using a for loop here so changes to the circuits don't cause it to completely fail.
123
124 for (int i = 0; i < circuits.Length; i++)
125 {
126 IClientAPI client;
127 try
128 {
129 bool tryGetRet = false;
130 lock (m_clients)
131 tryGetRet = m_clients.TryGetValue(circuits[i], out client);
132 if (tryGetRet)
133 {
134 Remove(client.CircuitCode);
135 client.Close(false);
136 }
137 }
138 catch (Exception e)
139 {
140 m_log.Error(string.Format("[CLIENT]: Unable to shutdown circuit for: {0}\n Reason: {1}", agentId, e));
141 }
142 }
143 } 59 }
144 60
145 // [Obsolete("Using Obsolete to drive development is invalid. Obsolete presumes that something new has already been created to replace this.")] 61 public void ForEachClient(Action<IClientAPI> action)
146 public uint[] GetAllCircuits(UUID agentId)
147 { 62 {
148 List<uint> circuits = new List<uint>(); 63 IClientAPI[] LocalClients;
149 // Wasteful, I know
150 IClientAPI[] LocalClients = new IClientAPI[0];
151 lock (m_clients) 64 lock (m_clients)
152 { 65 {
153 LocalClients = new IClientAPI[m_clients.Count]; 66 LocalClients = new IClientAPI[m_clients.Count];
@@ -156,65 +69,15 @@ namespace OpenSim.Framework
156 69
157 for (int i = 0; i < LocalClients.Length; i++) 70 for (int i = 0; i < LocalClients.Length; i++)
158 { 71 {
159 if (LocalClients[i].AgentId == agentId) 72 try
160 { 73 {
161 circuits.Add(LocalClients[i].CircuitCode); 74 action(LocalClients[i]);
162 } 75 }
163 } 76 catch (Exception e)
164 return circuits.ToArray();
165 }
166
167 public List<uint> GetAllCircuitCodes()
168 {
169 List<uint> circuits;
170
171 lock (m_clients)
172 {
173 circuits = new List<uint>(m_clients.Keys);
174 }
175
176 return circuits;
177 }
178
179 public void ViewerEffectHandler(IClientAPI sender, List<ViewerEffectEventHandlerArg> args)
180 {
181 // TODO: don't create new blocks if recycling an old packet
182 List<ViewerEffectPacket.EffectBlock> effectBlock = new List<ViewerEffectPacket.EffectBlock>();
183 for (int i = 0; i < args.Count; i++)
184 {
185 ViewerEffectPacket.EffectBlock effect = new ViewerEffectPacket.EffectBlock();
186 effect.AgentID = args[i].AgentID;
187 effect.Color = args[i].Color;
188 effect.Duration = args[i].Duration;
189 effect.ID = args[i].ID;
190 effect.Type = args[i].Type;
191 effect.TypeData = args[i].TypeData;
192 effectBlock.Add(effect);
193 }
194 ViewerEffectPacket.EffectBlock[] effectBlockArray = effectBlock.ToArray();
195
196 IClientAPI[] LocalClients;
197 lock (m_clients)
198 {
199 LocalClients = new IClientAPI[m_clients.Count];
200 m_clients.Values.CopyTo(LocalClients, 0);
201 }
202
203 for (int i = 0; i < LocalClients.Length; i++)
204 {
205 if (LocalClients[i].AgentId != sender.AgentId)
206 { 77 {
207 LocalClients[i].SendViewerEffect(effectBlockArray); 78 m_log.Warn("[CLIENT]: Unable to do ForEachClient for one of the clients" + "\n Reason: " + e.ToString());
208 } 79 }
209 } 80 }
210 } 81 }
211
212 public bool TryGetClient(uint circuitId, out IClientAPI user)
213 {
214 lock (m_clients)
215 {
216 return m_clients.TryGetValue(circuitId, out user);
217 }
218 }
219 } 82 }
220} 83}
diff --git a/OpenSim/Framework/IScene.cs b/OpenSim/Framework/IScene.cs
index 489653f..f34027d 100644
--- a/OpenSim/Framework/IScene.cs
+++ b/OpenSim/Framework/IScene.cs
@@ -71,7 +71,6 @@ namespace OpenSim.Framework
71 71
72 void AddNewClient(IClientAPI client); 72 void AddNewClient(IClientAPI client);
73 void RemoveClient(UUID agentID); 73 void RemoveClient(UUID agentID);
74 void CloseAllAgents(uint circuitcode);
75 74
76 void Restart(int seconds); 75 void Restart(int seconds);
77 //RegionInfo OtherRegionUp(RegionInfo thisRegion); 76 //RegionInfo OtherRegionUp(RegionInfo thisRegion);