clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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.IO;
31 using System.Reflection;
32 using System.Net;
33 using System.Text;
34  
35 using OpenSim.Server.Base;
36 using OpenSim.Server.Handlers.Base;
37 using OpenSim.Services.Interfaces;
38 using OpenSim.Framework;
39 using OpenSim.Framework.Servers.HttpServer;
40  
41 using OpenMetaverse;
42 using OpenMetaverse.StructuredData;
43 using Nwc.XmlRpc;
44 using Nini.Config;
45 using log4net;
46  
47  
48 namespace OpenSim.Server.Handlers.Login
49 {
50 public class LLLoginHandlers
51 {
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53  
54 private ILoginService m_LocalService;
55 private bool m_Proxy;
56  
57  
58 public LLLoginHandlers(ILoginService service, bool hasProxy)
59 {
60 m_LocalService = service;
61 m_Proxy = hasProxy;
62 }
63  
64 public XmlRpcResponse HandleXMLRPCLogin(XmlRpcRequest request, IPEndPoint remoteClient)
65 {
66 Hashtable requestData = (Hashtable)request.Params[0];
67 if (m_Proxy && request.Params[3] != null)
68 {
69 IPEndPoint ep = Util.GetClientIPFromXFF((string)request.Params[3]);
70 if (ep != null)
71 // Bang!
72 remoteClient = ep;
73 }
74  
75 if (requestData != null)
76 {
77 // Debug code to show exactly what login parameters the viewer is sending us.
78 // TODO: Extract into a method that can be generally applied if one doesn't already exist.
79 // foreach (string key in requestData.Keys)
80 // {
81 // object value = requestData[key];
82 // Console.WriteLine("{0}:{1}", key, value);
83 // if (value is ArrayList)
84 // {
85 // ICollection col = value as ICollection;
86 // foreach (object item in col)
87 // Console.WriteLine(" {0}", item);
88 // }
89 // }
90  
91 if (requestData.ContainsKey("first") && requestData["first"] != null &&
92 requestData.ContainsKey("last") && requestData["last"] != null && (
93 (requestData.ContainsKey("passwd") && requestData["passwd"] != null) ||
94 (!requestData.ContainsKey("passwd") && requestData.ContainsKey("web_login_key") && requestData["web_login_key"] != null && requestData["web_login_key"].ToString() != UUID.Zero.ToString())
95 ))
96 {
97 string first = requestData["first"].ToString();
98 string last = requestData["last"].ToString();
99 string passwd = null;
100 if (requestData.ContainsKey("passwd"))
101 {
102 passwd = requestData["passwd"].ToString();
103 }
104 else if (requestData.ContainsKey("web_login_key"))
105 {
106 passwd = "$1$" + requestData["web_login_key"].ToString();
107 m_log.InfoFormat("[LOGIN]: XMLRPC Login Req key {0}", passwd);
108 }
109 string startLocation = string.Empty;
110 UUID scopeID = UUID.Zero;
111 if (requestData["scope_id"] != null)
112 scopeID = new UUID(requestData["scope_id"].ToString());
113 if (requestData.ContainsKey("start"))
114 startLocation = requestData["start"].ToString();
115  
116 string clientVersion = "Unknown";
117 if (requestData.Contains("version") && requestData["version"] != null)
118 clientVersion = requestData["version"].ToString();
119 // We should do something interesting with the client version...
120  
121 string channel = "Unknown";
122 if (requestData.Contains("channel") && requestData["channel"] != null)
123 channel = requestData["channel"].ToString();
124  
125 string mac = "Unknown";
126 if (requestData.Contains("mac") && requestData["mac"] != null)
127 mac = requestData["mac"].ToString();
128  
129 string id0 = "Unknown";
130 if (requestData.Contains("id0") && requestData["id0"] != null)
131 id0 = requestData["id0"].ToString();
132  
133 //m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion);
134  
135 LoginResponse reply = null;
136 reply = m_LocalService.Login(first, last, passwd, startLocation, scopeID, clientVersion, channel, mac, id0, remoteClient);
137  
138 XmlRpcResponse response = new XmlRpcResponse();
139 response.Value = reply.ToHashtable();
140 return response;
141  
142 }
143 }
144  
145 return FailedXMLRPCResponse();
146  
147 }
148 public XmlRpcResponse HandleXMLRPCLoginBlocked(XmlRpcRequest request, IPEndPoint client)
149 {
150 XmlRpcResponse response = new XmlRpcResponse();
151 Hashtable resp = new Hashtable();
152  
153 resp["reason"] = "presence";
154 resp["message"] = "Logins are currently restricted. Please try again later.";
155 resp["login"] = "false";
156 response.Value = resp;
157 return response;
158 }
159  
160 public XmlRpcResponse HandleXMLRPCSetLoginLevel(XmlRpcRequest request, IPEndPoint remoteClient)
161 {
162 Hashtable requestData = (Hashtable)request.Params[0];
163  
164 if (requestData != null)
165 {
166 if (requestData.ContainsKey("first") && requestData["first"] != null &&
167 requestData.ContainsKey("last") && requestData["last"] != null &&
168 requestData.ContainsKey("level") && requestData["level"] != null &&
169 requestData.ContainsKey("passwd") && requestData["passwd"] != null)
170 {
171 string first = requestData["first"].ToString();
172 string last = requestData["last"].ToString();
173 string passwd = requestData["passwd"].ToString();
174 int level = Int32.Parse(requestData["level"].ToString());
175  
176 m_log.InfoFormat("[LOGIN]: XMLRPC Set Level to {2} Requested by {0} {1}", first, last, level);
177  
178 Hashtable reply = m_LocalService.SetLevel(first, last, passwd, level, remoteClient);
179  
180 XmlRpcResponse response = new XmlRpcResponse();
181 response.Value = reply;
182  
183 return response;
184  
185 }
186 }
187  
188 XmlRpcResponse failResponse = new XmlRpcResponse();
189 Hashtable failHash = new Hashtable();
190 failHash["success"] = "false";
191 failResponse.Value = failHash;
192  
193 return failResponse;
194  
195 }
196  
197 public OSD HandleLLSDLogin(OSD request, IPEndPoint remoteClient)
198 {
199 if (request.Type == OSDType.Map)
200 {
201 OSDMap map = (OSDMap)request;
202  
203 if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd"))
204 {
205 string startLocation = string.Empty;
206  
207 if (map.ContainsKey("start"))
208 startLocation = map["start"].AsString();
209  
210 UUID scopeID = UUID.Zero;
211  
212 if (map.ContainsKey("scope_id"))
213 scopeID = new UUID(map["scope_id"].AsString());
214  
215 m_log.Info("[LOGIN]: LLSD Login Requested for: '" + map["first"].AsString() + "' '" + map["last"].AsString() + "' / " + startLocation);
216  
217 LoginResponse reply = null;
218 reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation, scopeID,
219 map["version"].AsString(), map["channel"].AsString(), map["mac"].AsString(), map["id0"].AsString(), remoteClient);
220 return reply.ToOSDMap();
221  
222 }
223 }
224  
225 return FailedOSDResponse();
226 }
227  
228 public void HandleWebSocketLoginEvents(string path, WebSocketHttpServerHandler sock)
229 {
230 sock.MaxPayloadSize = 16384; //16 kb payload
231 sock.InitialMsgTimeout = 5000; //5 second first message to trigger at least one of these events
232 sock.NoDelay_TCP_Nagle = true;
233 sock.OnData += delegate(object sender, WebsocketDataEventArgs data) { sock.Close("fail"); };
234 sock.OnPing += delegate(object sender, PingEventArgs pingdata) { sock.Close("fail"); };
235 sock.OnPong += delegate(object sender, PongEventArgs pongdata) { sock.Close("fail"); };
236 sock.OnText += delegate(object sender, WebsocketTextEventArgs text)
237 {
238 OSD request = null;
239 try
240 {
241 request = OSDParser.DeserializeJson(text.Data);
242 if (!(request is OSDMap))
243 {
244 sock.SendMessage(OSDParser.SerializeJsonString(FailedOSDResponse()));
245 }
246 else
247 {
248 OSDMap req = request as OSDMap;
249 string first = req["firstname"].AsString();
250 string last = req["lastname"].AsString();
251 string passwd = req["passwd"].AsString();
252 string start = req["startlocation"].AsString();
253 string version = req["version"].AsString();
254 string channel = req["channel"].AsString();
255 string mac = req["mac"].AsString();
256 string id0 = req["id0"].AsString();
257 UUID scope = UUID.Zero;
258 IPEndPoint endPoint =
259 (sender as WebSocketHttpServerHandler).GetRemoteIPEndpoint();
260 LoginResponse reply = null;
261 reply = m_LocalService.Login(first, last, passwd, start, scope, version,
262 channel, mac, id0, endPoint);
263 sock.SendMessage(OSDParser.SerializeJsonString(reply.ToOSDMap()));
264  
265 }
266  
267 }
268 catch (Exception)
269 {
270 sock.SendMessage(OSDParser.SerializeJsonString(FailedOSDResponse()));
271 }
272 finally
273 {
274 sock.Close("success");
275 }
276 };
277  
278 sock.HandshakeAndUpgrade();
279  
280 }
281  
282  
283 private XmlRpcResponse FailedXMLRPCResponse()
284 {
285 Hashtable hash = new Hashtable();
286 hash["reason"] = "key";
287 hash["message"] = "Incomplete login credentials. Check your username and password.";
288 hash["login"] = "false";
289  
290 XmlRpcResponse response = new XmlRpcResponse();
291 response.Value = hash;
292  
293 return response;
294 }
295  
296 private OSD FailedOSDResponse()
297 {
298 OSDMap map = new OSDMap();
299  
300 map["reason"] = OSD.FromString("key");
301 map["message"] = OSD.FromString("Invalid login credentials. Check your username and passwd.");
302 map["login"] = OSD.FromString("false");
303  
304 return map;
305 }
306  
307 }
308  
309 }