diff options
author | MW | 2009-02-22 19:19:24 +0000 |
---|---|---|
committer | MW | 2009-02-22 19:19:24 +0000 |
commit | f3a24e432f214f6b3484b620fabc058966628836 (patch) | |
tree | 30b1c2784f2ca6ea20c53ea8ee531984c0c54be7 /OpenSim/Grid | |
parent | * MXP Clients are now treated as full root agents - including being given a d... (diff) | |
download | opensim-SC-f3a24e432f214f6b3484b620fabc058966628836.zip opensim-SC-f3a24e432f214f6b3484b620fabc058966628836.tar.gz opensim-SC-f3a24e432f214f6b3484b620fabc058966628836.tar.bz2 opensim-SC-f3a24e432f214f6b3484b620fabc058966628836.tar.xz |
First step in giving the messaging server the modular refactoring treatment. As with the other two servers, this is very much a work in progress.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Grid/MessagingServer/IMessageRegionService.cs | 11 | ||||
-rw-r--r-- | OpenSim/Grid/MessagingServer/IMessageUserServerService.cs | 8 | ||||
-rw-r--r-- | OpenSim/Grid/MessagingServer/IUGAIMCore.cs | 15 | ||||
-rw-r--r-- | OpenSim/Grid/MessagingServer/Main.cs | 127 | ||||
-rw-r--r-- | OpenSim/Grid/MessagingServer/MessageRegionModule.cs | 212 | ||||
-rw-r--r-- | OpenSim/Grid/MessagingServer/MessageService.cs | 299 | ||||
-rw-r--r-- | OpenSim/Grid/MessagingServer/MessageUserServerModule.cs | 185 | ||||
-rw-r--r-- | OpenSim/Grid/MessagingServer/UserDataBaseService.cs | 75 |
8 files changed, 643 insertions, 289 deletions
diff --git a/OpenSim/Grid/MessagingServer/IMessageRegionService.cs b/OpenSim/Grid/MessagingServer/IMessageRegionService.cs new file mode 100644 index 0000000..907e89d --- /dev/null +++ b/OpenSim/Grid/MessagingServer/IMessageRegionService.cs | |||
@@ -0,0 +1,11 @@ | |||
1 | using System; | ||
2 | using OpenSim.Data; | ||
3 | |||
4 | namespace OpenSim.Grid.MessagingServer | ||
5 | { | ||
6 | public interface IMessageRegionService | ||
7 | { | ||
8 | int ClearRegionCache(); | ||
9 | RegionProfileData GetRegionInfo(ulong regionhandle); | ||
10 | } | ||
11 | } | ||
diff --git a/OpenSim/Grid/MessagingServer/IMessageUserServerService.cs b/OpenSim/Grid/MessagingServer/IMessageUserServerService.cs new file mode 100644 index 0000000..dff2052 --- /dev/null +++ b/OpenSim/Grid/MessagingServer/IMessageUserServerService.cs | |||
@@ -0,0 +1,8 @@ | |||
1 | using System; | ||
2 | namespace OpenSim.Grid.MessagingServer | ||
3 | { | ||
4 | public interface IMessageUserServerService | ||
5 | { | ||
6 | bool SendToUserServer(System.Collections.Hashtable request, string method); | ||
7 | } | ||
8 | } | ||
diff --git a/OpenSim/Grid/MessagingServer/IUGAIMCore.cs b/OpenSim/Grid/MessagingServer/IUGAIMCore.cs new file mode 100644 index 0000000..5ab1166 --- /dev/null +++ b/OpenSim/Grid/MessagingServer/IUGAIMCore.cs | |||
@@ -0,0 +1,15 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenSim.Framework.Servers; | ||
5 | |||
6 | namespace OpenSim.Grid.MessagingServer | ||
7 | { | ||
8 | public interface IUGAIMCore | ||
9 | { | ||
10 | T Get<T>(); | ||
11 | void RegisterInterface<T>(T iface); | ||
12 | bool TryGet<T>(out T iface); | ||
13 | BaseHttpServer GetHttpServer(); | ||
14 | } | ||
15 | } | ||
diff --git a/OpenSim/Grid/MessagingServer/Main.cs b/OpenSim/Grid/MessagingServer/Main.cs index 2f63ee9..f09d360 100644 --- a/OpenSim/Grid/MessagingServer/Main.cs +++ b/OpenSim/Grid/MessagingServer/Main.cs | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | ||
29 | using System.IO; | 30 | using System.IO; |
30 | using System.Reflection; | 31 | using System.Reflection; |
31 | using log4net; | 32 | using log4net; |
@@ -38,13 +39,18 @@ namespace OpenSim.Grid.MessagingServer | |||
38 | { | 39 | { |
39 | /// <summary> | 40 | /// <summary> |
40 | /// </summary> | 41 | /// </summary> |
41 | public class OpenMessage_Main : BaseOpenSimServer | 42 | public class OpenMessage_Main : BaseOpenSimServer , IUGAIMCore |
42 | { | 43 | { |
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
44 | 45 | ||
45 | private MessageServerConfig Cfg; | 46 | private MessageServerConfig Cfg; |
46 | private MessageService msgsvc; | 47 | private MessageService msgsvc; |
47 | 48 | ||
49 | private MessageRegionModule m_regionModule; | ||
50 | private MessageUserServerModule m_userServerModule; | ||
51 | |||
52 | private UserDataBaseService m_userDataBaseService; | ||
53 | |||
48 | // private UUID m_lastCreatedUser = UUID.Random(); | 54 | // private UUID m_lastCreatedUser = UUID.Random(); |
49 | 55 | ||
50 | public static void Main(string[] args) | 56 | public static void Main(string[] args) |
@@ -77,7 +83,7 @@ namespace OpenSim.Grid.MessagingServer | |||
77 | 83 | ||
78 | private void registerWithUserServer() | 84 | private void registerWithUserServer() |
79 | { | 85 | { |
80 | if (msgsvc.registerWithUserServer()) | 86 | if (m_userServerModule.registerWithUserServer()) |
81 | { | 87 | { |
82 | m_log.Info("[SERVER]: Starting HTTP process"); | 88 | m_log.Info("[SERVER]: Starting HTTP process"); |
83 | m_httpServer = new BaseHttpServer(Cfg.HttpPort); | 89 | m_httpServer = new BaseHttpServer(Cfg.HttpPort); |
@@ -85,12 +91,13 @@ namespace OpenSim.Grid.MessagingServer | |||
85 | m_httpServer.AddXmlRPCHandler("login_to_simulator", msgsvc.UserLoggedOn); | 91 | m_httpServer.AddXmlRPCHandler("login_to_simulator", msgsvc.UserLoggedOn); |
86 | m_httpServer.AddXmlRPCHandler("logout_of_simulator", msgsvc.UserLoggedOff); | 92 | m_httpServer.AddXmlRPCHandler("logout_of_simulator", msgsvc.UserLoggedOff); |
87 | m_httpServer.AddXmlRPCHandler("get_presence_info_bulk", msgsvc.GetPresenceInfoBulk); | 93 | m_httpServer.AddXmlRPCHandler("get_presence_info_bulk", msgsvc.GetPresenceInfoBulk); |
88 | m_httpServer.AddXmlRPCHandler("region_startup", msgsvc.RegionStartup); | ||
89 | m_httpServer.AddXmlRPCHandler("region_shutdown", msgsvc.RegionShutdown); | ||
90 | m_httpServer.AddXmlRPCHandler("process_region_shutdown", msgsvc.ProcessRegionShutdown); | 94 | m_httpServer.AddXmlRPCHandler("process_region_shutdown", msgsvc.ProcessRegionShutdown); |
91 | m_httpServer.AddXmlRPCHandler("agent_location", msgsvc.AgentLocation); | 95 | m_httpServer.AddXmlRPCHandler("agent_location", msgsvc.AgentLocation); |
92 | m_httpServer.AddXmlRPCHandler("agent_leaving", msgsvc.AgentLeaving); | 96 | m_httpServer.AddXmlRPCHandler("agent_leaving", msgsvc.AgentLeaving); |
93 | 97 | ||
98 | m_httpServer.AddXmlRPCHandler("region_startup", m_regionModule.RegionStartup); | ||
99 | m_httpServer.AddXmlRPCHandler("region_shutdown", m_regionModule.RegionShutdown); | ||
100 | |||
94 | m_httpServer.Start(); | 101 | m_httpServer.Start(); |
95 | m_log.Info("[SERVER]: Userserver registration was successful"); | 102 | m_log.Info("[SERVER]: Userserver registration was successful"); |
96 | } | 103 | } |
@@ -103,7 +110,7 @@ namespace OpenSim.Grid.MessagingServer | |||
103 | 110 | ||
104 | private void deregisterFromUserServer() | 111 | private void deregisterFromUserServer() |
105 | { | 112 | { |
106 | msgsvc.deregisterWithUserServer(); | 113 | m_userServerModule.deregisterWithUserServer(); |
107 | if (m_httpServer != null) | 114 | if (m_httpServer != null) |
108 | { | 115 | { |
109 | // try a completely fresh registration, with fresh handlers, too | 116 | // try a completely fresh registration, with fresh handlers, too |
@@ -117,9 +124,24 @@ namespace OpenSim.Grid.MessagingServer | |||
117 | { | 124 | { |
118 | Cfg = new MessageServerConfig("MESSAGING SERVER", (Path.Combine(Util.configDir(), "MessagingServer_Config.xml"))); | 125 | Cfg = new MessageServerConfig("MESSAGING SERVER", (Path.Combine(Util.configDir(), "MessagingServer_Config.xml"))); |
119 | 126 | ||
120 | msgsvc = new MessageService(Cfg); | 127 | m_userDataBaseService = new UserDataBaseService(); |
128 | m_userDataBaseService.AddPlugin(Cfg.DatabaseProvider, Cfg.DatabaseConnect); | ||
129 | |||
130 | m_userServerModule = new MessageUserServerModule(Cfg, this); | ||
131 | m_userServerModule.Initialise(); | ||
132 | |||
133 | msgsvc = new MessageService(Cfg, this, m_userDataBaseService); | ||
134 | msgsvc.Initialise(); | ||
135 | |||
136 | m_regionModule = new MessageRegionModule(Cfg, this); | ||
137 | m_regionModule.Initialise(); | ||
138 | |||
121 | registerWithUserServer(); | 139 | registerWithUserServer(); |
122 | 140 | ||
141 | m_userServerModule.PostInitialise(); | ||
142 | msgsvc.PostInitialise(); | ||
143 | m_regionModule.PostInitialise(); | ||
144 | |||
123 | m_log.Info("[SERVER]: Messageserver 0.5 - Startup complete"); | 145 | m_log.Info("[SERVER]: Messageserver 0.5 - Startup complete"); |
124 | 146 | ||
125 | base.StartupSpecific(); | 147 | base.StartupSpecific(); |
@@ -135,35 +157,35 @@ namespace OpenSim.Grid.MessagingServer | |||
135 | 157 | ||
136 | public void do_create(string what) | 158 | public void do_create(string what) |
137 | { | 159 | { |
138 | switch (what) | 160 | //switch (what) |
139 | { | 161 | //{ |
140 | case "user": | 162 | // case "user": |
141 | try | 163 | // try |
142 | { | 164 | // { |
143 | //userID = | 165 | // //userID = |
144 | //m_userManager.AddUserProfile(tempfirstname, templastname, tempMD5Passwd, regX, regY); | 166 | // //m_userManager.AddUserProfile(tempfirstname, templastname, tempMD5Passwd, regX, regY); |
145 | } catch (Exception ex) | 167 | // } catch (Exception ex) |
146 | { | 168 | // { |
147 | m_console.Error("[SERVER]: Error creating user: {0}", ex.ToString()); | 169 | // m_console.Error("[SERVER]: Error creating user: {0}", ex.ToString()); |
148 | } | 170 | // } |
149 | 171 | ||
150 | try | 172 | // try |
151 | { | 173 | // { |
152 | //RestObjectPoster.BeginPostObject<Guid>(m_userManager._config.InventoryUrl + "CreateInventory/", | 174 | // //RestObjectPoster.BeginPostObject<Guid>(m_userManager._config.InventoryUrl + "CreateInventory/", |
153 | //userID.Guid); | 175 | // //userID.Guid); |
154 | } | 176 | // } |
155 | catch (Exception ex) | 177 | // catch (Exception ex) |
156 | { | 178 | // { |
157 | m_console.Error("[SERVER]: Error creating inventory for user: {0}", ex.ToString()); | 179 | // m_console.Error("[SERVER]: Error creating inventory for user: {0}", ex.ToString()); |
158 | } | 180 | // } |
159 | // m_lastCreatedUser = userID; | 181 | // // m_lastCreatedUser = userID; |
160 | break; | 182 | // break; |
161 | } | 183 | //} |
162 | } | 184 | } |
163 | 185 | ||
164 | private void HandleClearCache(string module, string[] cmd) | 186 | private void HandleClearCache(string module, string[] cmd) |
165 | { | 187 | { |
166 | int entries = msgsvc.ClearRegionCache(); | 188 | int entries = m_regionModule.ClearRegionCache(); |
167 | m_console.Notice("Region cache cleared! Cleared " + | 189 | m_console.Notice("Region cache cleared! Cleared " + |
168 | entries.ToString() + " entries"); | 190 | entries.ToString() + " entries"); |
169 | } | 191 | } |
@@ -176,7 +198,48 @@ namespace OpenSim.Grid.MessagingServer | |||
176 | 198 | ||
177 | public override void ShutdownSpecific() | 199 | public override void ShutdownSpecific() |
178 | { | 200 | { |
179 | msgsvc.deregisterWithUserServer(); | 201 | m_userServerModule.deregisterWithUserServer(); |
202 | } | ||
203 | |||
204 | #region IUGAIMCore | ||
205 | private readonly Dictionary<Type, object> m_moduleInterfaces = new Dictionary<Type, object>(); | ||
206 | |||
207 | /// <summary> | ||
208 | /// Register an Module interface. | ||
209 | /// </summary> | ||
210 | /// <typeparam name="T"></typeparam> | ||
211 | /// <param name="iface"></param> | ||
212 | public void RegisterInterface<T>(T iface) | ||
213 | { | ||
214 | lock (m_moduleInterfaces) | ||
215 | { | ||
216 | if (!m_moduleInterfaces.ContainsKey(typeof(T))) | ||
217 | { | ||
218 | m_moduleInterfaces.Add(typeof(T), iface); | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | |||
223 | public bool TryGet<T>(out T iface) | ||
224 | { | ||
225 | if (m_moduleInterfaces.ContainsKey(typeof(T))) | ||
226 | { | ||
227 | iface = (T)m_moduleInterfaces[typeof(T)]; | ||
228 | return true; | ||
229 | } | ||
230 | iface = default(T); | ||
231 | return false; | ||
232 | } | ||
233 | |||
234 | public T Get<T>() | ||
235 | { | ||
236 | return (T)m_moduleInterfaces[typeof(T)]; | ||
237 | } | ||
238 | |||
239 | public BaseHttpServer GetHttpServer() | ||
240 | { | ||
241 | return m_httpServer; | ||
180 | } | 242 | } |
243 | #endregion | ||
181 | } | 244 | } |
182 | } | 245 | } |
diff --git a/OpenSim/Grid/MessagingServer/MessageRegionModule.cs b/OpenSim/Grid/MessagingServer/MessageRegionModule.cs new file mode 100644 index 0000000..b3fd7ae --- /dev/null +++ b/OpenSim/Grid/MessagingServer/MessageRegionModule.cs | |||
@@ -0,0 +1,212 @@ | |||
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 OpenSim 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; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Threading; | ||
34 | using System.Timers; | ||
35 | using log4net; | ||
36 | using Nwc.XmlRpc; | ||
37 | using OpenMetaverse; | ||
38 | using OpenSim.Data; | ||
39 | using OpenSim.Framework; | ||
40 | using Timer = System.Timers.Timer; | ||
41 | |||
42 | namespace OpenSim.Grid.MessagingServer | ||
43 | { | ||
44 | public class MessageRegionModule : IMessageRegionService | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private MessageServerConfig m_cfg; | ||
49 | |||
50 | private IMessageUserServerService m_userServerModule; | ||
51 | |||
52 | private IUGAIMCore m_messageCore; | ||
53 | |||
54 | // a dictionary of all current regions this server knows about | ||
55 | private Dictionary<ulong, RegionProfileData> m_regionInfoCache = new Dictionary<ulong, RegionProfileData>(); | ||
56 | |||
57 | public MessageRegionModule(MessageServerConfig config, IUGAIMCore messageCore) | ||
58 | { | ||
59 | m_cfg = config; | ||
60 | m_messageCore = messageCore; | ||
61 | } | ||
62 | |||
63 | public void Initialise() | ||
64 | { | ||
65 | m_messageCore.RegisterInterface<IMessageRegionService>(this); | ||
66 | } | ||
67 | |||
68 | public void PostInitialise() | ||
69 | { | ||
70 | IMessageUserServerService messageUserServer; | ||
71 | if (m_messageCore.TryGet<IMessageUserServerService>(out messageUserServer)) | ||
72 | { | ||
73 | m_userServerModule = messageUserServer; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | public void RegisterHandlers() | ||
78 | { | ||
79 | //have these in separate method as some servers restart the http server and reregister all the handlers. | ||
80 | |||
81 | } | ||
82 | |||
83 | /// <summary> | ||
84 | /// Gets and caches a RegionInfo object from the gridserver based on regionhandle | ||
85 | /// if the regionhandle is already cached, use the cached values | ||
86 | /// Gets called by lots of threads!!!!! | ||
87 | /// </summary> | ||
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> | ||
90 | public RegionProfileData GetRegionInfo(ulong regionhandle) | ||
91 | { | ||
92 | RegionProfileData regionInfo = null; | ||
93 | |||
94 | lock (m_regionInfoCache) | ||
95 | { | ||
96 | m_regionInfoCache.TryGetValue(regionhandle, out regionInfo); | ||
97 | } | ||
98 | |||
99 | if (regionInfo == null) // not found in cache | ||
100 | { | ||
101 | regionInfo = RequestRegionInfo(regionhandle); | ||
102 | |||
103 | if (regionInfo != null) // lookup was successful | ||
104 | { | ||
105 | lock (m_regionInfoCache) | ||
106 | { | ||
107 | m_regionInfoCache[regionhandle] = regionInfo; | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | |||
112 | return regionInfo; | ||
113 | } | ||
114 | |||
115 | public int ClearRegionCache() | ||
116 | { | ||
117 | int cachecount = 0; | ||
118 | |||
119 | lock (m_regionInfoCache) | ||
120 | { | ||
121 | cachecount = m_regionInfoCache.Count; | ||
122 | m_regionInfoCache.Clear(); | ||
123 | } | ||
124 | |||
125 | return cachecount; | ||
126 | } | ||
127 | |||
128 | /// <summary> | ||
129 | /// Get RegionProfileData from the GridServer. | ||
130 | /// We'll cache this information in GetRegionInfo and use it for presence updates | ||
131 | /// </summary> | ||
132 | /// <param name="regionHandle"></param> | ||
133 | /// <returns></returns> | ||
134 | public RegionProfileData RequestRegionInfo(ulong regionHandle) | ||
135 | { | ||
136 | RegionProfileData regionProfile = null; | ||
137 | try | ||
138 | { | ||
139 | Hashtable requestData = new Hashtable(); | ||
140 | requestData["region_handle"] = regionHandle.ToString(); | ||
141 | requestData["authkey"] = m_cfg.GridSendKey; | ||
142 | |||
143 | ArrayList SendParams = new ArrayList(); | ||
144 | SendParams.Add(requestData); | ||
145 | |||
146 | XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams); | ||
147 | |||
148 | XmlRpcResponse GridResp = GridReq.Send(m_cfg.GridServerURL, 3000); | ||
149 | |||
150 | Hashtable responseData = (Hashtable)GridResp.Value; | ||
151 | |||
152 | if (responseData.ContainsKey("error")) | ||
153 | { | ||
154 | m_log.Error("[GRID]: error received from grid server" + responseData["error"]); | ||
155 | return null; | ||
156 | } | ||
157 | |||
158 | uint regX = Convert.ToUInt32((string)responseData["region_locx"]); | ||
159 | uint regY = Convert.ToUInt32((string)responseData["region_locy"]); | ||
160 | string internalIpStr = (string)responseData["sim_ip"]; | ||
161 | |||
162 | regionProfile = new RegionProfileData(); | ||
163 | regionProfile.httpPort = (uint)Convert.ToInt32((string)responseData["http_port"]); | ||
164 | regionProfile.httpServerURI = "http://" + internalIpStr + ":" + regionProfile.httpPort + "/"; | ||
165 | regionProfile.regionHandle = Utils.UIntsToLong((regX * Constants.RegionSize), (regY * Constants.RegionSize)); | ||
166 | regionProfile.regionLocX = regX; | ||
167 | regionProfile.regionLocY = regY; | ||
168 | |||
169 | regionProfile.remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]); | ||
170 | regionProfile.UUID = new UUID((string)responseData["region_UUID"]); | ||
171 | regionProfile.regionName = (string)responseData["region_name"]; | ||
172 | } | ||
173 | catch (WebException) | ||
174 | { | ||
175 | m_log.Error("[GRID]: " + | ||
176 | "Region lookup failed for: " + regionHandle.ToString() + | ||
177 | " - Is the GridServer down?"); | ||
178 | } | ||
179 | |||
180 | return regionProfile; | ||
181 | } | ||
182 | |||
183 | public XmlRpcResponse RegionStartup(XmlRpcRequest request) | ||
184 | { | ||
185 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
186 | Hashtable result = new Hashtable(); | ||
187 | result["success"] = "FALSE"; | ||
188 | |||
189 | if (m_userServerModule.SendToUserServer(requestData, "region_startup")) | ||
190 | result["success"] = "TRUE"; | ||
191 | |||
192 | XmlRpcResponse response = new XmlRpcResponse(); | ||
193 | response.Value = result; | ||
194 | return response; | ||
195 | } | ||
196 | |||
197 | public XmlRpcResponse RegionShutdown(XmlRpcRequest request) | ||
198 | { | ||
199 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
200 | Hashtable result = new Hashtable(); | ||
201 | result["success"] = "FALSE"; | ||
202 | |||
203 | if (m_userServerModule.SendToUserServer(requestData, "region_shutdown")) | ||
204 | result["success"] = "TRUE"; | ||
205 | |||
206 | XmlRpcResponse response = new XmlRpcResponse(); | ||
207 | response.Value = result; | ||
208 | return response; | ||
209 | } | ||
210 | |||
211 | } | ||
212 | } | ||
diff --git a/OpenSim/Grid/MessagingServer/MessageService.cs b/OpenSim/Grid/MessagingServer/MessageService.cs index 36f8b91..75fb969 100644 --- a/OpenSim/Grid/MessagingServer/MessageService.cs +++ b/OpenSim/Grid/MessagingServer/MessageService.cs | |||
@@ -46,30 +46,53 @@ namespace OpenSim.Grid.MessagingServer | |||
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 | private UserManager m_userManager; | 49 | private UserDataBaseService m_userDataBaseService; |
50 | 50 | ||
51 | // a dictionary of all current presences this server knows about | 51 | private IUGAIMCore m_messageCore; |
52 | private Dictionary<UUID, UserPresenceData> m_presences = new Dictionary<UUID,UserPresenceData>(); | ||
53 | 52 | ||
54 | // a dictionary of all current regions this server knows about | 53 | private IMessageUserServerService m_userServerModule; |
55 | private Dictionary<ulong, RegionProfileData> m_regionInfoCache = new Dictionary<ulong,RegionProfileData>(); | 54 | private IMessageRegionService m_regionModule; |
56 | 55 | ||
57 | private Timer reconnectTimer = new Timer(300000); // 5 mins | 56 | // a dictionary of all current presences this server knows about |
57 | private Dictionary<UUID, UserPresenceData> m_presences = new Dictionary<UUID,UserPresenceData>(); | ||
58 | 58 | ||
59 | public MessageService(MessageServerConfig cfg) | 59 | public MessageService(MessageServerConfig cfg, IUGAIMCore messageCore, UserDataBaseService userDataBaseService) |
60 | { | 60 | { |
61 | m_cfg = cfg; | 61 | m_cfg = cfg; |
62 | m_userManager = new UserManager(); | 62 | m_messageCore = messageCore; |
63 | |||
64 | m_userDataBaseService = userDataBaseService; | ||
65 | |||
66 | //??? | ||
63 | UserConfig uc = new UserConfig(); | 67 | UserConfig uc = new UserConfig(); |
64 | uc.DatabaseConnect = cfg.DatabaseConnect; | 68 | uc.DatabaseConnect = cfg.DatabaseConnect; |
65 | uc.DatabaseProvider = cfg.DatabaseProvider; | 69 | uc.DatabaseProvider = cfg.DatabaseProvider; |
70 | } | ||
66 | 71 | ||
67 | m_userManager.AddPlugin(cfg.DatabaseProvider, cfg.DatabaseConnect); | 72 | public void Initialise() |
73 | { | ||
74 | } | ||
75 | |||
76 | public void PostInitialise() | ||
77 | { | ||
78 | IMessageUserServerService messageUserServer; | ||
79 | if (m_messageCore.TryGet<IMessageUserServerService>(out messageUserServer)) | ||
80 | { | ||
81 | m_userServerModule = messageUserServer; | ||
82 | } | ||
68 | 83 | ||
69 | reconnectTimer.Elapsed += registerWithUserServer; | 84 | IMessageRegionService messageRegion; |
70 | reconnectTimer.Start(); | 85 | if (m_messageCore.TryGet<IMessageRegionService>(out messageRegion)) |
86 | { | ||
87 | m_regionModule = messageRegion; | ||
88 | } | ||
71 | } | 89 | } |
72 | 90 | ||
91 | public void RegisterHandlers() | ||
92 | { | ||
93 | //have these in separate method as some servers restart the http server and reregister all the handlers. | ||
94 | |||
95 | } | ||
73 | 96 | ||
74 | #region FriendList Methods | 97 | #region FriendList Methods |
75 | 98 | ||
@@ -107,7 +130,7 @@ namespace OpenSim.Grid.MessagingServer | |||
107 | /// <param name="receiver">We are sending the presence update to this user</param> | 130 | /// <param name="receiver">We are sending the presence update to this user</param> |
108 | private void enqueuePresenceUpdate(UserPresenceData talkingAbout, UserPresenceData receiver) | 131 | private void enqueuePresenceUpdate(UserPresenceData talkingAbout, UserPresenceData receiver) |
109 | { | 132 | { |
110 | UserAgentData p2Handle = m_userManager.GetUserAgentData(receiver.agentData.AgentID); | 133 | UserAgentData p2Handle = m_userDataBaseService.GetUserAgentData(receiver.agentData.AgentID); |
111 | if (p2Handle != null) | 134 | if (p2Handle != null) |
112 | { | 135 | { |
113 | if (receiver.lookupUserRegionYN) | 136 | if (receiver.lookupUserRegionYN) |
@@ -122,7 +145,7 @@ namespace OpenSim.Grid.MessagingServer | |||
122 | PresenceInformer friendlistupdater = new PresenceInformer(); | 145 | PresenceInformer friendlistupdater = new PresenceInformer(); |
123 | friendlistupdater.presence1 = talkingAbout; | 146 | friendlistupdater.presence1 = talkingAbout; |
124 | friendlistupdater.presence2 = receiver; | 147 | friendlistupdater.presence2 = receiver; |
125 | friendlistupdater.OnGetRegionData += GetRegionInfo; | 148 | friendlistupdater.OnGetRegionData += m_regionModule.GetRegionInfo; |
126 | friendlistupdater.OnDone += PresenceUpdateDone; | 149 | friendlistupdater.OnDone += PresenceUpdateDone; |
127 | WaitCallback cb = new WaitCallback(friendlistupdater.go); | 150 | WaitCallback cb = new WaitCallback(friendlistupdater.go); |
128 | ThreadPool.QueueUserWorkItem(cb); | 151 | ThreadPool.QueueUserWorkItem(cb); |
@@ -225,7 +248,7 @@ namespace OpenSim.Grid.MessagingServer | |||
225 | 248 | ||
226 | private void PresenceUpdateDone(PresenceInformer obj) | 249 | private void PresenceUpdateDone(PresenceInformer obj) |
227 | { | 250 | { |
228 | obj.OnGetRegionData -= GetRegionInfo; | 251 | obj.OnGetRegionData -= m_regionModule.GetRegionInfo; |
229 | obj.OnDone -= PresenceUpdateDone; | 252 | obj.OnDone -= PresenceUpdateDone; |
230 | } | 253 | } |
231 | 254 | ||
@@ -332,7 +355,7 @@ namespace OpenSim.Grid.MessagingServer | |||
332 | UserPresenceData up = new UserPresenceData(); | 355 | UserPresenceData up = new UserPresenceData(); |
333 | up.agentData = agentData; | 356 | up.agentData = agentData; |
334 | up.friendData = GetUserFriendList(agentData.AgentID); | 357 | up.friendData = GetUserFriendList(agentData.AgentID); |
335 | up.regionData = GetRegionInfo(regionHandle); | 358 | up.regionData = m_regionModule.GetRegionInfo(regionHandle); |
336 | up.OnlineYN = true; | 359 | up.OnlineYN = true; |
337 | up.lookupUserRegionYN = false; | 360 | up.lookupUserRegionYN = false; |
338 | ProcessFriendListSubscriptions(up); | 361 | ProcessFriendListSubscriptions(up); |
@@ -380,7 +403,7 @@ namespace OpenSim.Grid.MessagingServer | |||
380 | } | 403 | } |
381 | 404 | ||
382 | try { | 405 | try { |
383 | Dictionary<UUID, FriendRegionInfo> infos = m_userManager.GetFriendRegionInfos(uuids); | 406 | Dictionary<UUID, FriendRegionInfo> infos = m_userDataBaseService.GetFriendRegionInfos(uuids); |
384 | m_log.DebugFormat("[FRIEND]: Got {0} region entries back.", infos.Count); | 407 | m_log.DebugFormat("[FRIEND]: Got {0} region entries back.", infos.Count); |
385 | int count = 0; | 408 | int count = 0; |
386 | foreach (KeyValuePair<UUID, FriendRegionInfo> pair in infos) | 409 | foreach (KeyValuePair<UUID, FriendRegionInfo> pair in infos) |
@@ -402,251 +425,13 @@ namespace OpenSim.Grid.MessagingServer | |||
402 | } | 425 | } |
403 | } | 426 | } |
404 | 427 | ||
405 | #region regioninfo gathering | ||
406 | |||
407 | /// <summary> | ||
408 | /// Gets and caches a RegionInfo object from the gridserver based on regionhandle | ||
409 | /// if the regionhandle is already cached, use the cached values | ||
410 | /// Gets called by lots of threads!!!!! | ||
411 | /// </summary> | ||
412 | /// <param name="regionhandle">handle to the XY of the region we're looking for</param> | ||
413 | /// <returns>A RegionInfo object to stick in the presence info</returns> | ||
414 | public RegionProfileData GetRegionInfo(ulong regionhandle) | ||
415 | { | ||
416 | RegionProfileData regionInfo = null; | ||
417 | |||
418 | lock (m_regionInfoCache) | ||
419 | { | ||
420 | m_regionInfoCache.TryGetValue(regionhandle, out regionInfo); | ||
421 | } | ||
422 | |||
423 | if (regionInfo == null) // not found in cache | ||
424 | { | ||
425 | regionInfo = RequestRegionInfo(regionhandle); | ||
426 | |||
427 | if (regionInfo != null) // lookup was successful | ||
428 | { | ||
429 | lock (m_regionInfoCache) | ||
430 | { | ||
431 | m_regionInfoCache[regionhandle] = regionInfo; | ||
432 | } | ||
433 | } | ||
434 | } | ||
435 | |||
436 | return regionInfo; | ||
437 | } | ||
438 | |||
439 | public int ClearRegionCache() | ||
440 | { | ||
441 | int cachecount = 0; | ||
442 | |||
443 | lock (m_regionInfoCache) | ||
444 | { | ||
445 | cachecount = m_regionInfoCache.Count; | ||
446 | m_regionInfoCache.Clear(); | ||
447 | } | ||
448 | |||
449 | return cachecount; | ||
450 | } | ||
451 | |||
452 | /// <summary> | ||
453 | /// Get RegionProfileData from the GridServer. | ||
454 | /// We'll cache this information in GetRegionInfo and use it for presence updates | ||
455 | /// </summary> | ||
456 | /// <param name="regionHandle"></param> | ||
457 | /// <returns></returns> | ||
458 | public RegionProfileData RequestRegionInfo(ulong regionHandle) | ||
459 | { | ||
460 | RegionProfileData regionProfile = null; | ||
461 | try | ||
462 | { | ||
463 | Hashtable requestData = new Hashtable(); | ||
464 | requestData["region_handle"] = regionHandle.ToString(); | ||
465 | requestData["authkey"] = m_cfg.GridSendKey; | ||
466 | |||
467 | ArrayList SendParams = new ArrayList(); | ||
468 | SendParams.Add(requestData); | ||
469 | |||
470 | XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams); | ||
471 | |||
472 | XmlRpcResponse GridResp = GridReq.Send(m_cfg.GridServerURL, 3000); | ||
473 | |||
474 | Hashtable responseData = (Hashtable)GridResp.Value; | ||
475 | |||
476 | if (responseData.ContainsKey("error")) | ||
477 | { | ||
478 | m_log.Error("[GRID]: error received from grid server" + responseData["error"]); | ||
479 | return null; | ||
480 | } | ||
481 | |||
482 | uint regX = Convert.ToUInt32((string)responseData["region_locx"]); | ||
483 | uint regY = Convert.ToUInt32((string)responseData["region_locy"]); | ||
484 | string internalIpStr = (string)responseData["sim_ip"]; | ||
485 | |||
486 | regionProfile = new RegionProfileData(); | ||
487 | regionProfile.httpPort = (uint)Convert.ToInt32((string)responseData["http_port"]); | ||
488 | regionProfile.httpServerURI = "http://" + internalIpStr + ":" + regionProfile.httpPort + "/"; | ||
489 | regionProfile.regionHandle = Utils.UIntsToLong((regX * Constants.RegionSize), (regY * Constants.RegionSize)); | ||
490 | regionProfile.regionLocX = regX; | ||
491 | regionProfile.regionLocY = regY; | ||
492 | |||
493 | regionProfile.remotingPort = Convert.ToUInt32((string)responseData["remoting_port"]); | ||
494 | regionProfile.UUID = new UUID((string)responseData["region_UUID"]); | ||
495 | regionProfile.regionName = (string)responseData["region_name"]; | ||
496 | } | ||
497 | catch (WebException) | ||
498 | { | ||
499 | m_log.Error("[GRID]: " + | ||
500 | "Region lookup failed for: " + regionHandle.ToString() + | ||
501 | " - Is the GridServer down?"); | ||
502 | } | ||
503 | |||
504 | return regionProfile; | ||
505 | } | ||
506 | |||
507 | public void registerWithUserServer(object sender, ElapsedEventArgs e) | ||
508 | { | ||
509 | registerWithUserServer(); | ||
510 | } | ||
511 | |||
512 | public bool registerWithUserServer () | ||
513 | { | ||
514 | Hashtable UserParams = new Hashtable(); | ||
515 | // Login / Authentication | ||
516 | |||
517 | if (m_cfg.HttpSSL) | ||
518 | { | ||
519 | UserParams["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; | ||
520 | } | ||
521 | else | ||
522 | { | ||
523 | UserParams["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; | ||
524 | } | ||
525 | |||
526 | UserParams["recvkey"] = m_cfg.UserRecvKey; | ||
527 | UserParams["sendkey"] = m_cfg.UserRecvKey; | ||
528 | |||
529 | // Package into an XMLRPC Request | ||
530 | ArrayList SendParams = new ArrayList(); | ||
531 | SendParams.Add(UserParams); | ||
532 | |||
533 | bool success = true; | ||
534 | string[] servers = m_cfg.UserServerURL.Split(' '); | ||
535 | |||
536 | foreach (string srv in servers) | ||
537 | { | ||
538 | // Send Request | ||
539 | try | ||
540 | { | ||
541 | XmlRpcRequest UserReq = new XmlRpcRequest("register_messageserver", SendParams); | ||
542 | XmlRpcResponse UserResp = UserReq.Send(srv, 16000); | ||
543 | |||
544 | // Process Response | ||
545 | Hashtable GridRespData = (Hashtable)UserResp.Value; | ||
546 | // if we got a response, we were successful | ||
547 | if (!GridRespData.ContainsKey("responsestring")) | ||
548 | success = false; | ||
549 | else | ||
550 | m_log.InfoFormat("[SERVER] Registered with {0}", srv); | ||
551 | } | ||
552 | catch | ||
553 | { | ||
554 | m_log.ErrorFormat("Unable to connect to server {0}. Server not running?", srv); | ||
555 | success = false; | ||
556 | } | ||
557 | } | ||
558 | return success; | ||
559 | } | ||
560 | |||
561 | public bool deregisterWithUserServer() | ||
562 | { | ||
563 | Hashtable request = new Hashtable(); | ||
564 | |||
565 | return SendToUserServer(request, "deregister_messageserver"); | ||
566 | } | ||
567 | |||
568 | public bool SendToUserServer(Hashtable request, string method) | ||
569 | { | ||
570 | // Login / Authentication | ||
571 | |||
572 | if (m_cfg.HttpSSL) | ||
573 | { | ||
574 | request["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; | ||
575 | } | ||
576 | else | ||
577 | { | ||
578 | request["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; | ||
579 | } | ||
580 | |||
581 | request["recvkey"] = m_cfg.UserRecvKey; | ||
582 | request["sendkey"] = m_cfg.UserRecvKey; | ||
583 | |||
584 | // Package into an XMLRPC Request | ||
585 | ArrayList SendParams = new ArrayList(); | ||
586 | SendParams.Add(request); | ||
587 | |||
588 | bool success = true; | ||
589 | string[] servers = m_cfg.UserServerURL.Split(' '); | ||
590 | |||
591 | // Send Request | ||
592 | foreach (string srv in servers) | ||
593 | { | ||
594 | try | ||
595 | { | ||
596 | XmlRpcRequest UserReq = new XmlRpcRequest(method, SendParams); | ||
597 | XmlRpcResponse UserResp = UserReq.Send(m_cfg.UserServerURL, 16000); | ||
598 | // Process Response | ||
599 | Hashtable UserRespData = (Hashtable)UserResp.Value; | ||
600 | // if we got a response, we were successful | ||
601 | if (!UserRespData.ContainsKey("responsestring")) | ||
602 | success = false; | ||
603 | } | ||
604 | catch | ||
605 | { | ||
606 | m_log.ErrorFormat("Unable to connect to server {0}. Server not running?", srv); | ||
607 | success = false; | ||
608 | } | ||
609 | } | ||
610 | return success; | ||
611 | } | ||
612 | |||
613 | #endregion | ||
614 | |||
615 | public XmlRpcResponse RegionStartup(XmlRpcRequest request) | ||
616 | { | ||
617 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
618 | Hashtable result = new Hashtable(); | ||
619 | result["success"] = "FALSE"; | ||
620 | |||
621 | if (SendToUserServer(requestData, "region_startup")) | ||
622 | result["success"] = "TRUE"; | ||
623 | |||
624 | XmlRpcResponse response = new XmlRpcResponse(); | ||
625 | response.Value = result; | ||
626 | return response; | ||
627 | } | ||
628 | |||
629 | public XmlRpcResponse RegionShutdown(XmlRpcRequest request) | ||
630 | { | ||
631 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
632 | Hashtable result = new Hashtable(); | ||
633 | result["success"] = "FALSE"; | ||
634 | |||
635 | if (SendToUserServer(requestData, "region_shutdown")) | ||
636 | result["success"] = "TRUE"; | ||
637 | |||
638 | XmlRpcResponse response = new XmlRpcResponse(); | ||
639 | response.Value = result; | ||
640 | return response; | ||
641 | } | ||
642 | |||
643 | public XmlRpcResponse AgentLocation(XmlRpcRequest request) | 428 | public XmlRpcResponse AgentLocation(XmlRpcRequest request) |
644 | { | 429 | { |
645 | Hashtable requestData = (Hashtable)request.Params[0]; | 430 | Hashtable requestData = (Hashtable)request.Params[0]; |
646 | Hashtable result = new Hashtable(); | 431 | Hashtable result = new Hashtable(); |
647 | result["success"] = "FALSE"; | 432 | result["success"] = "FALSE"; |
648 | 433 | ||
649 | if (SendToUserServer(requestData, "agent_location")) | 434 | if (m_userServerModule.SendToUserServer(requestData, "agent_location")) |
650 | result["success"] = "TRUE"; | 435 | result["success"] = "TRUE"; |
651 | 436 | ||
652 | 437 | ||
@@ -661,7 +446,7 @@ namespace OpenSim.Grid.MessagingServer | |||
661 | Hashtable result = new Hashtable(); | 446 | Hashtable result = new Hashtable(); |
662 | result["success"] = "FALSE"; | 447 | result["success"] = "FALSE"; |
663 | 448 | ||
664 | if (SendToUserServer(requestData, "agent_leaving")) | 449 | if (m_userServerModule.SendToUserServer(requestData, "agent_leaving")) |
665 | result["success"] = "TRUE"; | 450 | result["success"] = "TRUE"; |
666 | 451 | ||
667 | XmlRpcResponse response = new XmlRpcResponse(); | 452 | XmlRpcResponse response = new XmlRpcResponse(); |
@@ -699,4 +484,4 @@ namespace OpenSim.Grid.MessagingServer | |||
699 | return response; | 484 | return response; |
700 | } | 485 | } |
701 | } | 486 | } |
702 | } | 487 | } \ No newline at end of file |
diff --git a/OpenSim/Grid/MessagingServer/MessageUserServerModule.cs b/OpenSim/Grid/MessagingServer/MessageUserServerModule.cs new file mode 100644 index 0000000..904674f --- /dev/null +++ b/OpenSim/Grid/MessagingServer/MessageUserServerModule.cs | |||
@@ -0,0 +1,185 @@ | |||
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 OpenSim 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; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using System.Threading; | ||
34 | using System.Timers; | ||
35 | using log4net; | ||
36 | using Nwc.XmlRpc; | ||
37 | using OpenMetaverse; | ||
38 | using OpenSim.Data; | ||
39 | using OpenSim.Framework; | ||
40 | using Timer = System.Timers.Timer; | ||
41 | |||
42 | namespace OpenSim.Grid.MessagingServer | ||
43 | { | ||
44 | public class MessageUserServerModule : IMessageUserServerService | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private MessageServerConfig m_cfg; | ||
49 | |||
50 | private IUGAIMCore m_messageCore; | ||
51 | |||
52 | private Timer reconnectTimer = new Timer(300000); // 5 mins | ||
53 | |||
54 | public MessageUserServerModule(MessageServerConfig config, IUGAIMCore messageCore) | ||
55 | { | ||
56 | m_cfg = config; | ||
57 | m_messageCore = messageCore; | ||
58 | |||
59 | reconnectTimer.Elapsed += registerWithUserServer; | ||
60 | reconnectTimer.Start(); | ||
61 | } | ||
62 | |||
63 | public void Initialise() | ||
64 | { | ||
65 | m_messageCore.RegisterInterface<IMessageUserServerService>(this); | ||
66 | } | ||
67 | |||
68 | public void PostInitialise() | ||
69 | { | ||
70 | |||
71 | } | ||
72 | |||
73 | public void RegisterHandlers() | ||
74 | { | ||
75 | //have these in separate method as some servers restart the http server and reregister all the handlers. | ||
76 | |||
77 | } | ||
78 | |||
79 | public void registerWithUserServer(object sender, ElapsedEventArgs e) | ||
80 | { | ||
81 | registerWithUserServer(); | ||
82 | } | ||
83 | |||
84 | public bool registerWithUserServer() | ||
85 | { | ||
86 | Hashtable UserParams = new Hashtable(); | ||
87 | // Login / Authentication | ||
88 | |||
89 | if (m_cfg.HttpSSL) | ||
90 | { | ||
91 | UserParams["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | UserParams["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; | ||
96 | } | ||
97 | |||
98 | UserParams["recvkey"] = m_cfg.UserRecvKey; | ||
99 | UserParams["sendkey"] = m_cfg.UserRecvKey; | ||
100 | |||
101 | // Package into an XMLRPC Request | ||
102 | ArrayList SendParams = new ArrayList(); | ||
103 | SendParams.Add(UserParams); | ||
104 | |||
105 | bool success = true; | ||
106 | string[] servers = m_cfg.UserServerURL.Split(' '); | ||
107 | |||
108 | foreach (string srv in servers) | ||
109 | { | ||
110 | // Send Request | ||
111 | try | ||
112 | { | ||
113 | XmlRpcRequest UserReq = new XmlRpcRequest("register_messageserver", SendParams); | ||
114 | XmlRpcResponse UserResp = UserReq.Send(srv, 16000); | ||
115 | |||
116 | // Process Response | ||
117 | Hashtable GridRespData = (Hashtable)UserResp.Value; | ||
118 | // if we got a response, we were successful | ||
119 | if (!GridRespData.ContainsKey("responsestring")) | ||
120 | success = false; | ||
121 | else | ||
122 | m_log.InfoFormat("[SERVER] Registered with {0}", srv); | ||
123 | } | ||
124 | catch | ||
125 | { | ||
126 | m_log.ErrorFormat("Unable to connect to server {0}. Server not running?", srv); | ||
127 | success = false; | ||
128 | } | ||
129 | } | ||
130 | return success; | ||
131 | } | ||
132 | |||
133 | public bool deregisterWithUserServer() | ||
134 | { | ||
135 | Hashtable request = new Hashtable(); | ||
136 | |||
137 | return SendToUserServer(request, "deregister_messageserver"); | ||
138 | } | ||
139 | |||
140 | public bool SendToUserServer(Hashtable request, string method) | ||
141 | { | ||
142 | // Login / Authentication | ||
143 | |||
144 | if (m_cfg.HttpSSL) | ||
145 | { | ||
146 | request["uri"] = "https://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; | ||
147 | } | ||
148 | else | ||
149 | { | ||
150 | request["uri"] = "http://" + m_cfg.MessageServerIP + ":" + m_cfg.HttpPort; | ||
151 | } | ||
152 | |||
153 | request["recvkey"] = m_cfg.UserRecvKey; | ||
154 | request["sendkey"] = m_cfg.UserRecvKey; | ||
155 | |||
156 | // Package into an XMLRPC Request | ||
157 | ArrayList SendParams = new ArrayList(); | ||
158 | SendParams.Add(request); | ||
159 | |||
160 | bool success = true; | ||
161 | string[] servers = m_cfg.UserServerURL.Split(' '); | ||
162 | |||
163 | // Send Request | ||
164 | foreach (string srv in servers) | ||
165 | { | ||
166 | try | ||
167 | { | ||
168 | XmlRpcRequest UserReq = new XmlRpcRequest(method, SendParams); | ||
169 | XmlRpcResponse UserResp = UserReq.Send(m_cfg.UserServerURL, 16000); | ||
170 | // Process Response | ||
171 | Hashtable UserRespData = (Hashtable)UserResp.Value; | ||
172 | // if we got a response, we were successful | ||
173 | if (!UserRespData.ContainsKey("responsestring")) | ||
174 | success = false; | ||
175 | } | ||
176 | catch | ||
177 | { | ||
178 | m_log.ErrorFormat("Unable to connect to server {0}. Server not running?", srv); | ||
179 | success = false; | ||
180 | } | ||
181 | } | ||
182 | return success; | ||
183 | } | ||
184 | } | ||
185 | } | ||
diff --git a/OpenSim/Grid/MessagingServer/UserDataBaseService.cs b/OpenSim/Grid/MessagingServer/UserDataBaseService.cs new file mode 100644 index 0000000..f554cc2 --- /dev/null +++ b/OpenSim/Grid/MessagingServer/UserDataBaseService.cs | |||
@@ -0,0 +1,75 @@ | |||
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 OpenSim 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 | using OpenSim.Framework; | ||
30 | using OpenSim.Framework.Communications; | ||
31 | |||
32 | namespace OpenSim.Grid.MessagingServer | ||
33 | { | ||
34 | public class UserDataBaseService : UserManagerBase | ||
35 | { | ||
36 | /// <summary> | ||
37 | /// Constructor. | ||
38 | /// </summary> | ||
39 | /// Passing null to parent because we never use any function that requires an interservice inventory call. | ||
40 | public UserDataBaseService() | ||
41 | : base(null) | ||
42 | { | ||
43 | } | ||
44 | |||
45 | public UserAgentData GetUserAgentData(UUID AgentID) | ||
46 | { | ||
47 | UserProfileData userProfile = GetUserProfile(AgentID); | ||
48 | |||
49 | if (userProfile != null) | ||
50 | { | ||
51 | return userProfile.CurrentAgent; | ||
52 | } | ||
53 | |||
54 | return null; | ||
55 | } | ||
56 | |||
57 | public override UserProfileData SetupMasterUser(string firstName, string lastName) | ||
58 | { | ||
59 | //throw new Exception("The method or operation is not implemented."); | ||
60 | return null; | ||
61 | } | ||
62 | |||
63 | public override UserProfileData SetupMasterUser(string firstName, string lastName, string password) | ||
64 | { | ||
65 | //throw new Exception("The method or operation is not implemented."); | ||
66 | return null; | ||
67 | } | ||
68 | |||
69 | public override UserProfileData SetupMasterUser(UUID uuid) | ||
70 | { | ||
71 | //throw new Exception("The method or operation is not implemented."); | ||
72 | return null; | ||
73 | } | ||
74 | } | ||
75 | } | ||