diff options
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/ClientManager.cs | 75 |
1 files changed, 60 insertions, 15 deletions
diff --git a/OpenSim/Framework/ClientManager.cs b/OpenSim/Framework/ClientManager.cs index 629aab5..698171d 100644 --- a/OpenSim/Framework/ClientManager.cs +++ b/OpenSim/Framework/ClientManager.cs | |||
@@ -40,9 +40,25 @@ namespace OpenSim.Framework | |||
40 | 40 | ||
41 | public void ForEachClient(ForEachClientDelegate whatToDo) | 41 | public void ForEachClient(ForEachClientDelegate whatToDo) |
42 | { | 42 | { |
43 | foreach (IClientAPI client in m_clients.Values) | 43 | |
44 | // Wasteful, I know | ||
45 | IClientAPI[] LocalClients = new IClientAPI[0]; | ||
46 | lock (m_clients) | ||
44 | { | 47 | { |
45 | whatToDo(client); | 48 | LocalClients = new IClientAPI[m_clients.Count]; |
49 | m_clients.Values.CopyTo(LocalClients, 0); | ||
50 | } | ||
51 | |||
52 | for (int i = 0; i < LocalClients.Length; i++) | ||
53 | { | ||
54 | try | ||
55 | { | ||
56 | whatToDo(LocalClients[i]); | ||
57 | } | ||
58 | catch (System.Exception e) | ||
59 | { | ||
60 | OpenSim.Framework.Console.MainLog.Instance.Warn("CLIENT", "Unable to do ForEachClient for one of the clients" + "\n Reason: " + e.ToString()); | ||
61 | } | ||
46 | } | 62 | } |
47 | } | 63 | } |
48 | 64 | ||
@@ -84,29 +100,48 @@ namespace OpenSim.Framework | |||
84 | public void CloseAllCircuits(LLUUID agentId) | 100 | public void CloseAllCircuits(LLUUID agentId) |
85 | { | 101 | { |
86 | uint[] circuits = GetAllCircuits(agentId); | 102 | uint[] circuits = GetAllCircuits(agentId); |
87 | foreach (uint circuit in circuits) | 103 | // We're using a for loop here so changes to the circuits don't cause it to completely fail. |
104 | |||
105 | for (int i = 0; i < circuits.Length; i++) | ||
88 | { | 106 | { |
89 | IClientAPI client; | 107 | IClientAPI client; |
90 | if (m_clients.TryGetValue(circuit, out client)) | 108 | try |
109 | { | ||
110 | |||
111 | if (m_clients.TryGetValue(circuits[i], out client)) | ||
112 | { | ||
113 | Remove(client.CircuitCode); | ||
114 | client.Close(); | ||
115 | } | ||
116 | } | ||
117 | catch (System.Exception e) | ||
91 | { | 118 | { |
92 | Remove(circuit); | 119 | OpenSim.Framework.Console.MainLog.Instance.Error("CLIENT", "Unable to shutdown circuit for: " + agentId.ToString() + "\n Reason: " + e.ToString()); |
93 | client.Close(); | ||
94 | } | 120 | } |
95 | } | 121 | } |
122 | |||
123 | |||
96 | } | 124 | } |
97 | 125 | ||
98 | private uint[] GetAllCircuits(LLUUID agentId) | 126 | private uint[] GetAllCircuits(LLUUID agentId) |
99 | { | 127 | { |
100 | List<uint> circuits = new List<uint>(); | 128 | List<uint> circuits = new List<uint>(); |
129 | // Wasteful, I know | ||
130 | IClientAPI[] LocalClients = new IClientAPI[0]; | ||
131 | lock (m_clients) | ||
132 | { | ||
133 | LocalClients = new IClientAPI[m_clients.Count]; | ||
134 | m_clients.Values.CopyTo(LocalClients, 0); | ||
135 | } | ||
136 | |||
101 | 137 | ||
102 | foreach (KeyValuePair<uint, IClientAPI> pair in m_clients) | 138 | for (int i = 0; i < LocalClients.Length; i++ ) |
103 | { | 139 | { |
104 | if (pair.Value.AgentId == agentId) | 140 | if (LocalClients[i].AgentId == agentId) |
105 | { | 141 | { |
106 | circuits.Add(pair.Key); | 142 | circuits.Add(LocalClients[i].CircuitCode); |
107 | } | 143 | } |
108 | } | 144 | } |
109 | |||
110 | return circuits.ToArray(); | 145 | return circuits.ToArray(); |
111 | } | 146 | } |
112 | 147 | ||
@@ -116,14 +151,24 @@ namespace OpenSim.Framework | |||
116 | ViewerEffectPacket packet = new ViewerEffectPacket(); | 151 | ViewerEffectPacket packet = new ViewerEffectPacket(); |
117 | packet.Effect = effectBlock; | 152 | packet.Effect = effectBlock; |
118 | 153 | ||
119 | foreach (IClientAPI client in m_clients.Values) | 154 | // Wasteful, I know |
155 | IClientAPI[] LocalClients = new IClientAPI[0]; | ||
156 | lock (m_clients) | ||
120 | { | 157 | { |
121 | if (client.AgentId != sender.AgentId) | 158 | LocalClients = new IClientAPI[m_clients.Count]; |
159 | m_clients.Values.CopyTo(LocalClients, 0); | ||
160 | } | ||
161 | |||
162 | |||
163 | for (int i = 0; i < LocalClients.Length; i++) | ||
164 | { | ||
165 | if (LocalClients[i].AgentId != sender.AgentId) | ||
122 | { | 166 | { |
123 | packet.AgentData.AgentID = client.AgentId; | 167 | packet.AgentData.AgentID = LocalClients[i].AgentId; |
124 | packet.AgentData.SessionID = client.SessionId; | 168 | packet.AgentData.SessionID = LocalClients[i].SessionId; |
125 | client.OutPacket(packet,ThrottleOutPacketType.Task); | 169 | LocalClients[i].OutPacket(packet, ThrottleOutPacketType.Task); |
126 | } | 170 | } |
171 | |||
127 | } | 172 | } |
128 | } | 173 | } |
129 | 174 | ||