diff options
author | UbitUmarov | 2015-09-01 11:43:07 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 11:43:07 +0100 |
commit | fb78b182520fc9bb0f971afd0322029c70278ea6 (patch) | |
tree | b4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Framework/Client | |
parent | lixo (diff) | |
parent | Mantis #7713: fixed bug introduced by 1st MOSES patch. (diff) | |
download | opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2 opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz |
Merge remote-tracking branch 'os/master'
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Client/IClientChat.cs | 40 | ||||
-rw-r--r-- | OpenSim/Framework/Client/IClientCore.cs | 44 | ||||
-rw-r--r-- | OpenSim/Framework/Client/IClientIM.cs | 68 | ||||
-rw-r--r-- | OpenSim/Framework/Client/IClientIPEndpoint.cs | 39 | ||||
-rw-r--r-- | OpenSim/Framework/Client/IClientInventory.cs | 40 | ||||
-rw-r--r-- | OpenSim/Framework/ClientInfo.cs | 67 | ||||
-rw-r--r-- | OpenSim/Framework/ClientManager.cs | 225 |
7 files changed, 523 insertions, 0 deletions
diff --git a/OpenSim/Framework/Client/IClientChat.cs b/OpenSim/Framework/Client/IClientChat.cs new file mode 100644 index 0000000..86b1faa --- /dev/null +++ b/OpenSim/Framework/Client/IClientChat.cs | |||
@@ -0,0 +1,40 @@ | |||
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 OpenMetaverse; | ||
29 | |||
30 | namespace OpenSim.Framework.Client | ||
31 | { | ||
32 | public interface IClientChat | ||
33 | { | ||
34 | event ChatMessage OnChatFromClient; | ||
35 | |||
36 | void SendChatMessage( | ||
37 | string message, byte type, Vector3 fromPos, string fromName, UUID fromAgentID, UUID ownerID, byte source, | ||
38 | byte audible); | ||
39 | } | ||
40 | } \ No newline at end of file | ||
diff --git a/OpenSim/Framework/Client/IClientCore.cs b/OpenSim/Framework/Client/IClientCore.cs new file mode 100644 index 0000000..1d08fb9 --- /dev/null +++ b/OpenSim/Framework/Client/IClientCore.cs | |||
@@ -0,0 +1,44 @@ | |||
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 OpenMetaverse; | ||
29 | |||
30 | namespace OpenSim.Framework.Client | ||
31 | { | ||
32 | public interface IClientCore | ||
33 | { | ||
34 | bool TryGet<T>(out T iface); | ||
35 | T Get<T>(); | ||
36 | |||
37 | // Basic Interfaces | ||
38 | UUID AgentId { get; } | ||
39 | |||
40 | void Disconnect(string reason); | ||
41 | void Disconnect(); | ||
42 | |||
43 | } | ||
44 | } \ No newline at end of file | ||
diff --git a/OpenSim/Framework/Client/IClientIM.cs b/OpenSim/Framework/Client/IClientIM.cs new file mode 100644 index 0000000..3df86d0 --- /dev/null +++ b/OpenSim/Framework/Client/IClientIM.cs | |||
@@ -0,0 +1,68 @@ | |||
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; | ||
29 | using OpenMetaverse; | ||
30 | |||
31 | namespace OpenSim.Framework.Client | ||
32 | { | ||
33 | public class ClientInstantMessageArgs : EventArgs | ||
34 | { | ||
35 | public IClientCore client; | ||
36 | public string message; | ||
37 | public DateTime time; | ||
38 | public ClientInstantMessageSender sender; | ||
39 | } | ||
40 | |||
41 | public class ClientInstantMessageSender | ||
42 | { | ||
43 | public UUID ID; | ||
44 | public bool online; | ||
45 | public string name; | ||
46 | public Vector3 position; | ||
47 | public UUID regionID; | ||
48 | } | ||
49 | |||
50 | public delegate void ClientInstantMessage(Object sender, ClientInstantMessageArgs e); | ||
51 | |||
52 | public class ClientInstantMessageParms | ||
53 | { | ||
54 | public ClientInstantMessageSender senderInfo; | ||
55 | } | ||
56 | |||
57 | // Porting Guide from old IM | ||
58 | // SendIM(...) | ||
59 | // Loses FromAgentSession - this should be added by implementers manually. | ||
60 | // | ||
61 | |||
62 | public interface IClientIM | ||
63 | { | ||
64 | void SendInstantMessage(GridInstantMessage im); | ||
65 | |||
66 | event ImprovedInstantMessage OnInstantMessage; | ||
67 | } | ||
68 | } | ||
diff --git a/OpenSim/Framework/Client/IClientIPEndpoint.cs b/OpenSim/Framework/Client/IClientIPEndpoint.cs new file mode 100644 index 0000000..2b99bf0 --- /dev/null +++ b/OpenSim/Framework/Client/IClientIPEndpoint.cs | |||
@@ -0,0 +1,39 @@ | |||
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; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace OpenSim.Framework.Client | ||
34 | { | ||
35 | public interface IClientIPEndpoint | ||
36 | { | ||
37 | IPAddress EndPoint { get; } | ||
38 | } | ||
39 | } | ||
diff --git a/OpenSim/Framework/Client/IClientInventory.cs b/OpenSim/Framework/Client/IClientInventory.cs new file mode 100644 index 0000000..a6e0510 --- /dev/null +++ b/OpenSim/Framework/Client/IClientInventory.cs | |||
@@ -0,0 +1,40 @@ | |||
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; | ||
29 | using OpenMetaverse; | ||
30 | using OpenSim.Framework; | ||
31 | |||
32 | namespace OpenSim.Framework.Client | ||
33 | { | ||
34 | public interface IClientInventory | ||
35 | { | ||
36 | void SendRemoveInventoryFolders(UUID[] folders); | ||
37 | void SendRemoveInventoryItems(UUID[] folders); | ||
38 | void SendBulkUpdateInventory(InventoryFolderBase[] folders, InventoryItemBase[] items); | ||
39 | } | ||
40 | } | ||
diff --git a/OpenSim/Framework/ClientInfo.cs b/OpenSim/Framework/ClientInfo.cs new file mode 100644 index 0000000..98e4465 --- /dev/null +++ b/OpenSim/Framework/ClientInfo.cs | |||
@@ -0,0 +1,67 @@ | |||
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; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | |||
32 | namespace OpenSim.Framework | ||
33 | { | ||
34 | public class ClientInfo | ||
35 | { | ||
36 | public readonly DateTime StartedTime = DateTime.Now; | ||
37 | public AgentCircuitData agentcircuit = null; | ||
38 | |||
39 | public Dictionary<uint, byte[]> needAck; | ||
40 | |||
41 | public List<byte[]> out_packets = new List<byte[]>(); | ||
42 | public Dictionary<uint, uint> pendingAcks = new Dictionary<uint,uint>(); | ||
43 | public EndPoint proxyEP; | ||
44 | |||
45 | public uint sequence; | ||
46 | public byte[] usecircuit; | ||
47 | public EndPoint userEP; | ||
48 | |||
49 | public int resendThrottle; | ||
50 | public int landThrottle; | ||
51 | public int windThrottle; | ||
52 | public int cloudThrottle; | ||
53 | public int taskThrottle; | ||
54 | public int assetThrottle; | ||
55 | public int textureThrottle; | ||
56 | public int totalThrottle; | ||
57 | |||
58 | // Used by adaptive only | ||
59 | public int targetThrottle; | ||
60 | |||
61 | public int maxThrottle; | ||
62 | |||
63 | public Dictionary<string, int> SyncRequests = new Dictionary<string,int>(); | ||
64 | public Dictionary<string, int> AsyncRequests = new Dictionary<string,int>(); | ||
65 | public Dictionary<string, int> GenericRequests = new Dictionary<string,int>(); | ||
66 | } | ||
67 | } | ||
diff --git a/OpenSim/Framework/ClientManager.cs b/OpenSim/Framework/ClientManager.cs new file mode 100644 index 0000000..baff2f4 --- /dev/null +++ b/OpenSim/Framework/ClientManager.cs | |||
@@ -0,0 +1,225 @@ | |||
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; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Net; | ||
32 | using OpenMetaverse; | ||
33 | using OpenMetaverse.Packets; | ||
34 | |||
35 | namespace OpenSim.Framework | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Maps from client AgentID and RemoteEndPoint values to IClientAPI | ||
39 | /// references for all of the connected clients | ||
40 | /// </summary> | ||
41 | public class ClientManager | ||
42 | { | ||
43 | /// <summary>A dictionary mapping from <seealso cref="UUID"/> | ||
44 | /// to <seealso cref="IClientAPI"/> references</summary> | ||
45 | private Dictionary<UUID, IClientAPI> m_dict1; | ||
46 | /// <summary>A dictionary mapping from <seealso cref="IPEndPoint"/> | ||
47 | /// to <seealso cref="IClientAPI"/> references</summary> | ||
48 | private Dictionary<IPEndPoint, IClientAPI> m_dict2; | ||
49 | /// <summary>An immutable collection of <seealso cref="IClientAPI"/> | ||
50 | /// references</summary> | ||
51 | private IClientAPI[] m_array; | ||
52 | /// <summary>Synchronization object for writing to the collections</summary> | ||
53 | private object m_syncRoot = new object(); | ||
54 | |||
55 | /// <summary>Number of clients in the collection</summary> | ||
56 | public int Count { get { return m_dict1.Count; } } | ||
57 | |||
58 | /// <summary> | ||
59 | /// Default constructor | ||
60 | /// </summary> | ||
61 | public ClientManager() | ||
62 | { | ||
63 | m_dict1 = new Dictionary<UUID, IClientAPI>(); | ||
64 | m_dict2 = new Dictionary<IPEndPoint, IClientAPI>(); | ||
65 | m_array = new IClientAPI[0]; | ||
66 | } | ||
67 | |||
68 | /// <summary> | ||
69 | /// Add a client reference to the collection if it does not already | ||
70 | /// exist | ||
71 | /// </summary> | ||
72 | /// <param name="value">Reference to the client object</param> | ||
73 | /// <returns>True if the client reference was successfully added, | ||
74 | /// otherwise false if the given key already existed in the collection</returns> | ||
75 | public bool Add(IClientAPI value) | ||
76 | { | ||
77 | lock (m_syncRoot) | ||
78 | { | ||
79 | if (m_dict1.ContainsKey(value.AgentId) || m_dict2.ContainsKey(value.RemoteEndPoint)) | ||
80 | return false; | ||
81 | |||
82 | m_dict1[value.AgentId] = value; | ||
83 | m_dict2[value.RemoteEndPoint] = value; | ||
84 | |||
85 | IClientAPI[] oldArray = m_array; | ||
86 | int oldLength = oldArray.Length; | ||
87 | |||
88 | IClientAPI[] newArray = new IClientAPI[oldLength + 1]; | ||
89 | for (int i = 0; i < oldLength; i++) | ||
90 | newArray[i] = oldArray[i]; | ||
91 | newArray[oldLength] = value; | ||
92 | |||
93 | m_array = newArray; | ||
94 | } | ||
95 | |||
96 | return true; | ||
97 | } | ||
98 | |||
99 | /// <summary> | ||
100 | /// Remove a client from the collection | ||
101 | /// </summary> | ||
102 | /// <param name="key">UUID of the client to remove</param> | ||
103 | /// <returns>True if a client was removed, or false if the given UUID | ||
104 | /// was not present in the collection</returns> | ||
105 | public bool Remove(UUID key) | ||
106 | { | ||
107 | lock (m_syncRoot) | ||
108 | { | ||
109 | IClientAPI value; | ||
110 | if (m_dict1.TryGetValue(key, out value)) | ||
111 | { | ||
112 | m_dict1.Remove(key); | ||
113 | m_dict2.Remove(value.RemoteEndPoint); | ||
114 | |||
115 | IClientAPI[] oldArray = m_array; | ||
116 | int oldLength = oldArray.Length; | ||
117 | |||
118 | IClientAPI[] newArray = new IClientAPI[oldLength - 1]; | ||
119 | int j = 0; | ||
120 | for (int i = 0; i < oldLength; i++) | ||
121 | { | ||
122 | if (oldArray[i] != value) | ||
123 | newArray[j++] = oldArray[i]; | ||
124 | } | ||
125 | |||
126 | m_array = newArray; | ||
127 | return true; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | return false; | ||
132 | } | ||
133 | |||
134 | /// <summary> | ||
135 | /// Resets the client collection | ||
136 | /// </summary> | ||
137 | public void Clear() | ||
138 | { | ||
139 | lock (m_syncRoot) | ||
140 | { | ||
141 | m_dict1.Clear(); | ||
142 | m_dict2.Clear(); | ||
143 | m_array = new IClientAPI[0]; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | /// <summary> | ||
148 | /// Checks if a UUID is in the collection | ||
149 | /// </summary> | ||
150 | /// <param name="key">UUID to check for</param> | ||
151 | /// <returns>True if the UUID was found in the collection, otherwise false</returns> | ||
152 | public bool ContainsKey(UUID key) | ||
153 | { | ||
154 | return m_dict1.ContainsKey(key); | ||
155 | } | ||
156 | |||
157 | /// <summary> | ||
158 | /// Checks if an endpoint is in the collection | ||
159 | /// </summary> | ||
160 | /// <param name="key">Endpoint to check for</param> | ||
161 | /// <returns>True if the endpoint was found in the collection, otherwise false</returns> | ||
162 | public bool ContainsKey(IPEndPoint key) | ||
163 | { | ||
164 | return m_dict2.ContainsKey(key); | ||
165 | } | ||
166 | |||
167 | /// <summary> | ||
168 | /// Attempts to fetch a value out of the collection | ||
169 | /// </summary> | ||
170 | /// <param name="key">UUID of the client to retrieve</param> | ||
171 | /// <param name="value">Retrieved client, or null on lookup failure</param> | ||
172 | /// <returns>True if the lookup succeeded, otherwise false</returns> | ||
173 | public bool TryGetValue(UUID key, out IClientAPI value) | ||
174 | { | ||
175 | try { return m_dict1.TryGetValue(key, out value); } | ||
176 | catch (Exception) | ||
177 | { | ||
178 | value = null; | ||
179 | return false; | ||
180 | } | ||
181 | } | ||
182 | |||
183 | /// <summary> | ||
184 | /// Attempts to fetch a value out of the collection | ||
185 | /// </summary> | ||
186 | /// <param name="key">Endpoint of the client to retrieve</param> | ||
187 | /// <param name="value">Retrieved client, or null on lookup failure</param> | ||
188 | /// <returns>True if the lookup succeeded, otherwise false</returns> | ||
189 | public bool TryGetValue(IPEndPoint key, out IClientAPI value) | ||
190 | { | ||
191 | try { return m_dict2.TryGetValue(key, out value); } | ||
192 | catch (Exception) | ||
193 | { | ||
194 | value = null; | ||
195 | return false; | ||
196 | } | ||
197 | } | ||
198 | |||
199 | /// <summary> | ||
200 | /// Performs a given task in parallel for each of the elements in the | ||
201 | /// collection | ||
202 | /// </summary> | ||
203 | /// <param name="action">Action to perform on each element</param> | ||
204 | public void ForEach(Action<IClientAPI> action) | ||
205 | { | ||
206 | IClientAPI[] localArray = m_array; | ||
207 | Parallel.For(0, localArray.Length, | ||
208 | delegate(int i) | ||
209 | { action(localArray[i]); } | ||
210 | ); | ||
211 | } | ||
212 | |||
213 | /// <summary> | ||
214 | /// Performs a given task synchronously for each of the elements in | ||
215 | /// the collection | ||
216 | /// </summary> | ||
217 | /// <param name="action">Action to perform on each element</param> | ||
218 | public void ForEachSync(Action<IClientAPI> action) | ||
219 | { | ||
220 | IClientAPI[] localArray = m_array; | ||
221 | for (int i = 0; i < localArray.Length; i++) | ||
222 | action(localArray[i]); | ||
223 | } | ||
224 | } | ||
225 | } | ||