diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Grid/MessagingServer/MessageUserServerModule.cs | 185 |
1 files changed, 185 insertions, 0 deletions
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 | } | ||