diff options
Diffstat (limited to 'OpenSim/Grid/MessagingServer/MessageRegionModule.cs')
-rw-r--r-- | OpenSim/Grid/MessagingServer/MessageRegionModule.cs | 424 |
1 files changed, 212 insertions, 212 deletions
diff --git a/OpenSim/Grid/MessagingServer/MessageRegionModule.cs b/OpenSim/Grid/MessagingServer/MessageRegionModule.cs index b3fd7ae..a2a7ade 100644 --- a/OpenSim/Grid/MessagingServer/MessageRegionModule.cs +++ b/OpenSim/Grid/MessagingServer/MessageRegionModule.cs | |||
@@ -1,212 +1,212 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Net; | 31 | using System.Net; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using System.Threading; | 33 | using System.Threading; |
34 | using System.Timers; | 34 | using System.Timers; |
35 | using log4net; | 35 | using log4net; |
36 | using Nwc.XmlRpc; | 36 | using Nwc.XmlRpc; |
37 | using OpenMetaverse; | 37 | using OpenMetaverse; |
38 | using OpenSim.Data; | 38 | using OpenSim.Data; |
39 | using OpenSim.Framework; | 39 | using OpenSim.Framework; |
40 | using Timer = System.Timers.Timer; | 40 | using Timer = System.Timers.Timer; |
41 | 41 | ||
42 | namespace OpenSim.Grid.MessagingServer | 42 | namespace OpenSim.Grid.MessagingServer |
43 | { | 43 | { |
44 | public class MessageRegionModule : IMessageRegionService | 44 | public class MessageRegionModule : IMessageRegionService |
45 | { | 45 | { |
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
47 | 47 | ||
48 | private MessageServerConfig m_cfg; | 48 | private MessageServerConfig m_cfg; |
49 | 49 | ||
50 | private IMessageUserServerService m_userServerModule; | 50 | private IMessageUserServerService m_userServerModule; |
51 | 51 | ||
52 | private IUGAIMCore m_messageCore; | 52 | private IUGAIMCore m_messageCore; |
53 | 53 | ||
54 | // a dictionary of all current regions this server knows about | 54 | // a dictionary of all current regions this server knows about |
55 | private Dictionary<ulong, RegionProfileData> m_regionInfoCache = new Dictionary<ulong, RegionProfileData>(); | 55 | private Dictionary<ulong, RegionProfileData> m_regionInfoCache = new Dictionary<ulong, RegionProfileData>(); |
56 | 56 | ||
57 | public MessageRegionModule(MessageServerConfig config, IUGAIMCore messageCore) | 57 | public MessageRegionModule(MessageServerConfig config, IUGAIMCore messageCore) |
58 | { | 58 | { |
59 | m_cfg = config; | 59 | m_cfg = config; |
60 | m_messageCore = messageCore; | 60 | m_messageCore = messageCore; |
61 | } | 61 | } |
62 | 62 | ||
63 | public void Initialise() | 63 | public void Initialise() |
64 | { | 64 | { |
65 | m_messageCore.RegisterInterface<IMessageRegionService>(this); | 65 | m_messageCore.RegisterInterface<IMessageRegionService>(this); |
66 | } | 66 | } |
67 | 67 | ||
68 | public void PostInitialise() | 68 | public void PostInitialise() |
69 | { | 69 | { |
70 | IMessageUserServerService messageUserServer; | 70 | IMessageUserServerService messageUserServer; |
71 | if (m_messageCore.TryGet<IMessageUserServerService>(out messageUserServer)) | 71 | if (m_messageCore.TryGet<IMessageUserServerService>(out messageUserServer)) |
72 | { | 72 | { |
73 | m_userServerModule = messageUserServer; | 73 | m_userServerModule = messageUserServer; |
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | public void RegisterHandlers() | 77 | public void RegisterHandlers() |
78 | { | 78 | { |
79 | //have these in separate method as some servers restart the http server and reregister all the handlers. | 79 | //have these in separate method as some servers restart the http server and reregister all the handlers. |
80 | 80 | ||
81 | } | 81 | } |
82 | 82 | ||
83 | /// <summary> | 83 | /// <summary> |
84 | /// Gets and caches a RegionInfo object from the gridserver based on regionhandle | 84 | /// Gets and caches a RegionInfo object from the gridserver based on regionhandle |
85 | /// if the regionhandle is already cached, use the cached values | 85 | /// if the regionhandle is already cached, use the cached values |
86 | /// Gets called by lots of threads!!!!! | 86 | /// Gets called by lots of threads!!!!! |
87 | /// </summary> | 87 | /// </summary> |
88 | /// <param name="regionhandle">handle to the XY of the region we're looking for</param> | 88 | /// <param name="regionhandle">handle to the XY of the region we're looking for</param> |
89 | /// <returns>A RegionInfo object to stick in the presence info</returns> | 89 | /// <returns>A RegionInfo object to stick in the presence info</returns> |
90 | public RegionProfileData GetRegionInfo(ulong regionhandle) | 90 | public RegionProfileData GetRegionInfo(ulong regionhandle) |
91 | { | 91 | { |
92 | RegionProfileData regionInfo = null; | 92 | RegionProfileData regionInfo = null; |
93 | 93 | ||
94 | lock (m_regionInfoCache) | 94 | lock (m_regionInfoCache) |
95 | { | 95 | { |
96 | m_regionInfoCache.TryGetValue(regionhandle, out regionInfo); | 96 | m_regionInfoCache.TryGetValue(regionhandle, out regionInfo); |
97 | } | 97 | } |
98 | 98 | ||
99 | if (regionInfo == null) // not found in cache | 99 | if (regionInfo == null) // not found in cache |
100 | { | 100 | { |
101 | regionInfo = RequestRegionInfo(regionhandle); | 101 | regionInfo = RequestRegionInfo(regionhandle); |
102 | 102 | ||
103 | if (regionInfo != null) // lookup was successful | 103 | if (regionInfo != null) // lookup was successful |
104 | { | 104 | { |
105 | lock (m_regionInfoCache) | 105 | lock (m_regionInfoCache) |
106 | { | 106 | { |
107 | m_regionInfoCache[regionhandle] = regionInfo; | 107 | m_regionInfoCache[regionhandle] = regionInfo; |
108 | } | 108 | } |
109 | } | 109 | } |
110 | } | 110 | } |
111 | 111 | ||
112 | return regionInfo; | 112 | return regionInfo; |
113 | } | 113 | } |
114 | 114 | ||
115 | public int ClearRegionCache() | 115 | public int ClearRegionCache() |
116 | { | 116 | { |
117 | int cachecount = 0; | 117 | int cachecount = 0; |
118 | 118 | ||
119 | lock (m_regionInfoCache) | 119 | lock (m_regionInfoCache) |
120 | { | 120 | { |
121 | cachecount = m_regionInfoCache.Count; | 121 | cachecount = m_regionInfoCache.Count; |
122 | m_regionInfoCache.Clear(); | 122 | m_regionInfoCache.Clear(); |
123 | } | 123 | } |
124 | 124 | ||
125 | return cachecount; | 125 | return cachecount; |
126 | } | 126 | } |
127 | 127 | ||
128 | /// <summary> | 128 | /// <summary> |
129 | /// Get RegionProfileData from the GridServer. | 129 | /// Get RegionProfileData from the GridServer. |
130 | /// We'll cache this information in GetRegionInfo and use it for presence updates | 130 | /// We'll cache this information in GetRegionInfo and use it for presence updates |
131 | /// </summary> | 131 | /// </summary> |
132 | /// <param name="regionHandle"></param> | 132 | /// <param name="regionHandle"></param> |
133 | /// <returns></returns> | 133 | /// <returns></returns> |
134 | public RegionProfileData RequestRegionInfo(ulong regionHandle) | 134 | public RegionProfileData RequestRegionInfo(ulong regionHandle) |
135 | { | 135 | { |
136 | RegionProfileData regionProfile = null; | 136 | RegionProfileData regionProfile = null; |
137 | try | 137 | try |
138 | { | 138 | { |
139 | Hashtable requestData = new Hashtable(); | 139 | Hashtable requestData = new Hashtable(); |
140 | requestData["region_handle"] = regionHandle.ToString(); | 140 | requestData["region_handle"] = regionHandle.ToString(); |
141 | requestData["authkey"] = m_cfg.GridSendKey; | 141 | requestData["authkey"] = m_cfg.GridSendKey; |
142 | 142 | ||
143 | ArrayList SendParams = new ArrayList(); | 143 | ArrayList SendParams = new ArrayList(); |
144 | SendParams.Add(requestData); | 144 | SendParams.Add(requestData); |
145 | 145 | ||
146 | XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams); | 146 | XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams); |
147 | 147 | ||
148 | XmlRpcResponse GridResp = GridReq.Send(m_cfg.GridServerURL, 3000); | 148 | XmlRpcResponse GridResp = GridReq.Send(m_cfg.GridServerURL, 3000); |
149 | 149 | ||
150 | Hashtable responseData = (Hashtable)GridResp.Value; | 150 | Hashtable responseData = (Hashtable)GridResp.Value; |
151 | 151 | ||
152 | if (responseData.ContainsKey("error")) | 152 | if (responseData.ContainsKey("error")) |
153 | { | 153 | { |
154 | m_log.Error("[GRID]: error received from grid server" + responseData["error"]); | 154 | m_log.Error("[GRID]: error received from grid server" + responseData["error"]); |
155 | return null; | 155 | return null; |
156 | } | 156 | } |
157 | 157 | ||
158 | uint regX = Convert.ToUInt32((string)responseData["region_locx"]); | 158 | uint regX = Convert.ToUInt32((string)responseData["region_locx"]); |
159 | uint regY = Convert.ToUInt32((string)responseData["region_locy"]); | 159 | uint regY = Convert.ToUInt32((string)responseData["region_locy"]); |
160 | string internalIpStr = (string)responseData["sim_ip"]; | 160 | string internalIpStr = (string)responseData["sim_ip"]; |
161 | 161 | ||
162 | regionProfile = new RegionProfileData(); | 162 | regionProfile = new RegionProfileData(); |
163 | regionProfile.httpPort = (uint)Convert.ToInt32((string)responseData["http_port"]); | 163 | regionProfile.httpPort = (uint)Convert.ToInt32((string)responseData["http_port"]); |
164 | regionProfile.httpServerURI = "http://" + internalIpStr + ":" + regionProfile.httpPort + "/"; | 164 | regionProfile.httpServerURI = "http://" + internalIpStr + ":" + regionProfile.httpPort + "/"; |
165 | regionProfile.regionHandle = Utils.UIntsToLong((regX * Constants.RegionSize), (regY * Constants.RegionSize)); | 165 | regionProfile.regionHandle = Utils.UIntsToLong((regX * Constants.RegionSize), (regY * Constants.RegionSize)); |
166 | regionProfile.regionLocX = regX; | 166 | regionProfile.regionLocX = regX; |
167 | regionProfile.regionLocY = regY; | 167 | regionProfile.regionLocY = regY; |
168 | 168 | ||
169 | regionProfile.remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]); | 169 | regionProfile.remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]); |
170 | regionProfile.UUID = new UUID((string)responseData["region_UUID"]); | 170 | regionProfile.UUID = new UUID((string)responseData["region_UUID"]); |
171 | regionProfile.regionName = (string)responseData["region_name"]; | 171 | regionProfile.regionName = (string)responseData["region_name"]; |
172 | } | 172 | } |
173 | catch (WebException) | 173 | catch (WebException) |
174 | { | 174 | { |
175 | m_log.Error("[GRID]: " + | 175 | m_log.Error("[GRID]: " + |
176 | "Region lookup failed for: " + regionHandle.ToString() + | 176 | "Region lookup failed for: " + regionHandle.ToString() + |
177 | " - Is the GridServer down?"); | 177 | " - Is the GridServer down?"); |
178 | } | 178 | } |
179 | 179 | ||
180 | return regionProfile; | 180 | return regionProfile; |
181 | } | 181 | } |
182 | 182 | ||
183 | public XmlRpcResponse RegionStartup(XmlRpcRequest request) | 183 | public XmlRpcResponse RegionStartup(XmlRpcRequest request) |
184 | { | 184 | { |
185 | Hashtable requestData = (Hashtable)request.Params[0]; | 185 | Hashtable requestData = (Hashtable)request.Params[0]; |
186 | Hashtable result = new Hashtable(); | 186 | Hashtable result = new Hashtable(); |
187 | result["success"] = "FALSE"; | 187 | result["success"] = "FALSE"; |
188 | 188 | ||
189 | if (m_userServerModule.SendToUserServer(requestData, "region_startup")) | 189 | if (m_userServerModule.SendToUserServer(requestData, "region_startup")) |
190 | result["success"] = "TRUE"; | 190 | result["success"] = "TRUE"; |
191 | 191 | ||
192 | XmlRpcResponse response = new XmlRpcResponse(); | 192 | XmlRpcResponse response = new XmlRpcResponse(); |
193 | response.Value = result; | 193 | response.Value = result; |
194 | return response; | 194 | return response; |
195 | } | 195 | } |
196 | 196 | ||
197 | public XmlRpcResponse RegionShutdown(XmlRpcRequest request) | 197 | public XmlRpcResponse RegionShutdown(XmlRpcRequest request) |
198 | { | 198 | { |
199 | Hashtable requestData = (Hashtable)request.Params[0]; | 199 | Hashtable requestData = (Hashtable)request.Params[0]; |
200 | Hashtable result = new Hashtable(); | 200 | Hashtable result = new Hashtable(); |
201 | result["success"] = "FALSE"; | 201 | result["success"] = "FALSE"; |
202 | 202 | ||
203 | if (m_userServerModule.SendToUserServer(requestData, "region_shutdown")) | 203 | if (m_userServerModule.SendToUserServer(requestData, "region_shutdown")) |
204 | result["success"] = "TRUE"; | 204 | result["success"] = "TRUE"; |
205 | 205 | ||
206 | XmlRpcResponse response = new XmlRpcResponse(); | 206 | XmlRpcResponse response = new XmlRpcResponse(); |
207 | response.Value = result; | 207 | response.Value = result; |
208 | return response; | 208 | return response; |
209 | } | 209 | } |
210 | 210 | ||
211 | } | 211 | } |
212 | } | 212 | } |