diff options
author | MW | 2009-03-03 15:45:52 +0000 |
---|---|---|
committer | MW | 2009-03-03 15:45:52 +0000 |
commit | 7a3bb77df98b41e12abb100e4ea821c37ba29db9 (patch) | |
tree | 370fe7f47b0d66a4f9f91a3ed7426df057737e81 /OpenSim/Client/Linden | |
parent | Moved Linden protocol login handling to modules in OpenSim.Client.Linden. The... (diff) | |
download | opensim-SC-7a3bb77df98b41e12abb100e4ea821c37ba29db9.zip opensim-SC-7a3bb77df98b41e12abb100e4ea821c37ba29db9.tar.gz opensim-SC-7a3bb77df98b41e12abb100e4ea821c37ba29db9.tar.bz2 opensim-SC-7a3bb77df98b41e12abb100e4ea821c37ba29db9.tar.xz |
forgotten files
Diffstat (limited to 'OpenSim/Client/Linden')
-rw-r--r-- | OpenSim/Client/Linden/LLProxyLoginModule.cs | 300 |
1 files changed, 300 insertions, 0 deletions
diff --git a/OpenSim/Client/Linden/LLProxyLoginModule.cs b/OpenSim/Client/Linden/LLProxyLoginModule.cs new file mode 100644 index 0000000..67d5f4c --- /dev/null +++ b/OpenSim/Client/Linden/LLProxyLoginModule.cs | |||
@@ -0,0 +1,300 @@ | |||
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; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using Nwc.XmlRpc; | ||
33 | using System.Net; | ||
34 | using System.Net.Sockets; | ||
35 | using System.Reflection; | ||
36 | using System.Security.Authentication; | ||
37 | using log4net; | ||
38 | using Nini.Config; | ||
39 | using OpenMetaverse; | ||
40 | using OpenSim.Framework; | ||
41 | using OpenSim.Framework.Communications; | ||
42 | using OpenSim.Framework.Servers; | ||
43 | using OpenSim.Region.Framework.Interfaces; | ||
44 | using OpenSim.Region.Framework.Scenes; | ||
45 | |||
46 | namespace OpenSim.Client.Linden | ||
47 | { | ||
48 | /// <summary> | ||
49 | /// Handles login user (expect user) and logoff user messages from the remote LL login server | ||
50 | /// </summary> | ||
51 | public class LLProxyLoginModule : IRegionModule | ||
52 | { | ||
53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | |||
55 | protected bool RegionLoginsEnabled | ||
56 | { | ||
57 | get | ||
58 | { | ||
59 | if (m_firstScene != null) | ||
60 | { | ||
61 | return m_firstScene.CommsManager.GridService.RegionLoginsEnabled; | ||
62 | } | ||
63 | else | ||
64 | { | ||
65 | return false; | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | |||
70 | protected List<Scene> m_scenes = new List<Scene>(); | ||
71 | protected Scene m_firstScene; | ||
72 | |||
73 | protected bool m_enabled = false; // Module is only enabled if running in grid mode | ||
74 | |||
75 | #region IRegionModule Members | ||
76 | |||
77 | public void Initialise(Scene scene, IConfigSource source) | ||
78 | { | ||
79 | if (m_firstScene == null) | ||
80 | { | ||
81 | m_firstScene = scene; | ||
82 | |||
83 | IConfig startupConfig = source.Configs["Startup"]; | ||
84 | if (startupConfig != null) | ||
85 | { | ||
86 | m_enabled = startupConfig.GetBoolean("gridmode", false); | ||
87 | } | ||
88 | |||
89 | if (m_enabled) | ||
90 | { | ||
91 | AddHttpHandlers(); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | if (m_enabled) | ||
96 | { | ||
97 | AddScene(scene); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | public void PostInitialise() | ||
102 | { | ||
103 | |||
104 | } | ||
105 | |||
106 | public void Close() | ||
107 | { | ||
108 | |||
109 | } | ||
110 | |||
111 | public string Name | ||
112 | { | ||
113 | get { return "LLProxyLoginModule"; } | ||
114 | } | ||
115 | |||
116 | public bool IsSharedModule | ||
117 | { | ||
118 | get { return true; } | ||
119 | } | ||
120 | |||
121 | #endregion | ||
122 | |||
123 | /// <summary> | ||
124 | /// Adds "expect_user" and "logoff_user" xmlrpc method handlers | ||
125 | /// </summary> | ||
126 | protected void AddHttpHandlers() | ||
127 | { | ||
128 | //we will add our handlers to the first scene we received, as all scenes share a http server. But will this ever change? | ||
129 | m_firstScene.CommsManager.HttpServer.AddXmlRPCHandler("expect_user", ExpectUser); | ||
130 | m_firstScene.CommsManager.HttpServer.AddXmlRPCHandler("logoff_user", LogOffUser); | ||
131 | } | ||
132 | |||
133 | protected void AddScene(Scene scene) | ||
134 | { | ||
135 | lock (m_scenes) | ||
136 | { | ||
137 | if (!m_scenes.Contains(scene)) | ||
138 | { | ||
139 | m_scenes.Add(scene); | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | /// <summary> | ||
144 | /// Received from the user server when a user starts logging in. This call allows | ||
145 | /// the region to prepare for direct communication from the client. Sends back an empty | ||
146 | /// xmlrpc response on completion. | ||
147 | /// </summary> | ||
148 | /// <param name="request"></param> | ||
149 | /// <returns></returns> | ||
150 | public XmlRpcResponse ExpectUser(XmlRpcRequest request) | ||
151 | { | ||
152 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
153 | AgentCircuitData agentData = new AgentCircuitData(); | ||
154 | agentData.SessionID = new UUID((string)requestData["session_id"]); | ||
155 | agentData.SecureSessionID = new UUID((string)requestData["secure_session_id"]); | ||
156 | agentData.firstname = (string)requestData["firstname"]; | ||
157 | agentData.lastname = (string)requestData["lastname"]; | ||
158 | agentData.AgentID = new UUID((string)requestData["agent_id"]); | ||
159 | agentData.circuitcode = Convert.ToUInt32(requestData["circuit_code"]); | ||
160 | agentData.CapsPath = (string)requestData["caps_path"]; | ||
161 | ulong regionHandle = Convert.ToUInt64((string)requestData["regionhandle"]); | ||
162 | |||
163 | // Appearance | ||
164 | if (requestData["appearance"] != null) | ||
165 | agentData.Appearance = new AvatarAppearance((Hashtable)requestData["appearance"]); | ||
166 | |||
167 | m_log.DebugFormat( | ||
168 | "[CLIENT]: Told by user service to prepare for a connection from {0} {1} {2}, circuit {3}", | ||
169 | agentData.firstname, agentData.lastname, agentData.AgentID, agentData.circuitcode); | ||
170 | |||
171 | if (requestData.ContainsKey("child_agent") && requestData["child_agent"].Equals("1")) | ||
172 | { | ||
173 | //m_log.Debug("[CLIENT]: Child agent detected"); | ||
174 | agentData.child = true; | ||
175 | } | ||
176 | else | ||
177 | { | ||
178 | //m_log.Debug("[CLIENT]: Main agent detected"); | ||
179 | agentData.startpos = | ||
180 | new Vector3((float)Convert.ToDecimal((string)requestData["startpos_x"]), | ||
181 | (float)Convert.ToDecimal((string)requestData["startpos_y"]), | ||
182 | (float)Convert.ToDecimal((string)requestData["startpos_z"])); | ||
183 | agentData.child = false; | ||
184 | } | ||
185 | |||
186 | XmlRpcResponse resp = new XmlRpcResponse(); | ||
187 | |||
188 | if (!RegionLoginsEnabled) | ||
189 | { | ||
190 | m_log.InfoFormat( | ||
191 | "[CLIENT]: Denying access for user {0} {1} because region login is currently disabled", | ||
192 | agentData.firstname, agentData.lastname); | ||
193 | |||
194 | Hashtable respdata = new Hashtable(); | ||
195 | respdata["success"] = "FALSE"; | ||
196 | respdata["reason"] = "region login currently disabled"; | ||
197 | resp.Value = respdata; | ||
198 | } | ||
199 | else | ||
200 | { | ||
201 | bool success = false; | ||
202 | string denyMess = ""; | ||
203 | |||
204 | Scene scene; | ||
205 | if (TryGetRegion(regionHandle, out scene)) | ||
206 | { | ||
207 | if (scene.RegionInfo.EstateSettings.IsBanned(agentData.AgentID)) | ||
208 | { | ||
209 | denyMess = "User is banned from this region"; | ||
210 | m_log.InfoFormat( | ||
211 | "[CLIENT]: Denying access for user {0} {1} because user is banned", | ||
212 | agentData.firstname, agentData.lastname); | ||
213 | } | ||
214 | else | ||
215 | { | ||
216 | if (scene.NewUserConnection(agentData)) | ||
217 | { | ||
218 | success = true; | ||
219 | } | ||
220 | else | ||
221 | { | ||
222 | denyMess = "Login refused by region"; | ||
223 | m_log.InfoFormat( | ||
224 | "[CLIENT]: Denying access for user {0} {1} because user connection was refused by the region", | ||
225 | agentData.firstname, agentData.lastname); | ||
226 | } | ||
227 | } | ||
228 | |||
229 | } | ||
230 | else | ||
231 | { | ||
232 | denyMess = "Region not found"; | ||
233 | } | ||
234 | |||
235 | if (success) | ||
236 | { | ||
237 | Hashtable respdata = new Hashtable(); | ||
238 | respdata["success"] = "TRUE"; | ||
239 | resp.Value = respdata; | ||
240 | } | ||
241 | else | ||
242 | { | ||
243 | Hashtable respdata = new Hashtable(); | ||
244 | respdata["success"] = "FALSE"; | ||
245 | respdata["reason"] = denyMess; | ||
246 | resp.Value = respdata; | ||
247 | } | ||
248 | } | ||
249 | |||
250 | return resp; | ||
251 | } | ||
252 | |||
253 | // Grid Request Processing | ||
254 | /// <summary> | ||
255 | /// Ooops, our Agent must be dead if we're getting this request! | ||
256 | /// </summary> | ||
257 | /// <param name="request"></param> | ||
258 | /// <returns></returns> | ||
259 | public XmlRpcResponse LogOffUser(XmlRpcRequest request) | ||
260 | { | ||
261 | m_log.Debug("[CONNECTION DEBUGGING]: LogOff User Called"); | ||
262 | |||
263 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
264 | string message = (string)requestData["message"]; | ||
265 | UUID agentID = UUID.Zero; | ||
266 | UUID RegionSecret = UUID.Zero; | ||
267 | UUID.TryParse((string)requestData["agent_id"], out agentID); | ||
268 | UUID.TryParse((string)requestData["region_secret"], out RegionSecret); | ||
269 | |||
270 | ulong regionHandle = Convert.ToUInt64((string)requestData["regionhandle"]); | ||
271 | |||
272 | Scene scene; | ||
273 | if (TryGetRegion(regionHandle, out scene)) | ||
274 | { | ||
275 | scene.HandleLogOffUserFromGrid(agentID, RegionSecret, message); | ||
276 | } | ||
277 | |||
278 | return new XmlRpcResponse(); | ||
279 | } | ||
280 | |||
281 | protected bool TryGetRegion(ulong regionHandle, out Scene scene) | ||
282 | { | ||
283 | lock (m_scenes) | ||
284 | { | ||
285 | foreach (Scene nextScene in m_scenes) | ||
286 | { | ||
287 | if (nextScene.RegionInfo.RegionHandle == regionHandle) | ||
288 | { | ||
289 | scene = nextScene; | ||
290 | return true; | ||
291 | } | ||
292 | } | ||
293 | } | ||
294 | |||
295 | scene = null; | ||
296 | return false; | ||
297 | } | ||
298 | |||
299 | } | ||
300 | } | ||