LLLoginHandlers.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. using System;
  28. using System.Collections;
  29. using System.IO;
  30. using System.Reflection;
  31. using System.Net;
  32. using System.Text;
  33. using OpenSim.Server.Base;
  34. using OpenSim.Server.Handlers.Base;
  35. using OpenSim.Services.Interfaces;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Servers.HttpServer;
  38. using OpenMetaverse;
  39. using OpenMetaverse.StructuredData;
  40. using Nwc.XmlRpc;
  41. using Nini.Config;
  42. using log4net;
  43. namespace OpenSim.Server.Handlers.Login
  44. {
  45. public class LLLoginHandlers
  46. {
  47. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. private ILoginService m_LocalService;
  49. public LLLoginHandlers(ILoginService service)
  50. {
  51. m_LocalService = service;
  52. }
  53. public XmlRpcResponse HandleXMLRPCLogin(XmlRpcRequest request, IPEndPoint remoteClient)
  54. {
  55. Hashtable requestData = (Hashtable)request.Params[0];
  56. if (requestData != null)
  57. {
  58. if (requestData.ContainsKey("first") && requestData["first"] != null &&
  59. requestData.ContainsKey("last") && requestData["last"] != null &&
  60. requestData.ContainsKey("passwd") && requestData["passwd"] != null)
  61. {
  62. string first = requestData["first"].ToString();
  63. string last = requestData["last"].ToString();
  64. string passwd = requestData["passwd"].ToString();
  65. string startLocation = string.Empty;
  66. UUID scopeID = UUID.Zero;
  67. if (requestData["scope_id"] != null)
  68. scopeID = new UUID(requestData["scope_id"].ToString());
  69. if (requestData.ContainsKey("start"))
  70. startLocation = requestData["start"].ToString();
  71. string clientVersion = "Unknown";
  72. if (requestData.Contains("version"))
  73. clientVersion = requestData["version"].ToString();
  74. // We should do something interesting with the client version...
  75. //m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion);
  76. LoginResponse reply = null;
  77. reply = m_LocalService.Login(first, last, passwd, startLocation, scopeID, clientVersion, remoteClient);
  78. XmlRpcResponse response = new XmlRpcResponse();
  79. response.Value = reply.ToHashtable();
  80. return response;
  81. }
  82. }
  83. return FailedXMLRPCResponse();
  84. }
  85. public XmlRpcResponse HandleXMLRPCSetLoginLevel(XmlRpcRequest request, IPEndPoint remoteClient)
  86. {
  87. Hashtable requestData = (Hashtable)request.Params[0];
  88. if (requestData != null)
  89. {
  90. if (requestData.ContainsKey("first") && requestData["first"] != null &&
  91. requestData.ContainsKey("last") && requestData["last"] != null &&
  92. requestData.ContainsKey("level") && requestData["level"] != null &&
  93. requestData.ContainsKey("passwd") && requestData["passwd"] != null)
  94. {
  95. string first = requestData["first"].ToString();
  96. string last = requestData["last"].ToString();
  97. string passwd = requestData["passwd"].ToString();
  98. int level = Int32.Parse(requestData["level"].ToString());
  99. m_log.InfoFormat("[LOGIN]: XMLRPC Set Level to {2} Requested by {0} {1}", first, last, level);
  100. Hashtable reply = m_LocalService.SetLevel(first, last, passwd, level, remoteClient);
  101. XmlRpcResponse response = new XmlRpcResponse();
  102. response.Value = reply;
  103. return response;
  104. }
  105. }
  106. XmlRpcResponse failResponse = new XmlRpcResponse();
  107. Hashtable failHash = new Hashtable();
  108. failHash["success"] = "false";
  109. failResponse.Value = failHash;
  110. return failResponse;
  111. }
  112. public OSD HandleLLSDLogin(OSD request, IPEndPoint remoteClient)
  113. {
  114. if (request.Type == OSDType.Map)
  115. {
  116. OSDMap map = (OSDMap)request;
  117. if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd"))
  118. {
  119. string startLocation = string.Empty;
  120. if (map.ContainsKey("start"))
  121. startLocation = map["start"].AsString();
  122. UUID scopeID = UUID.Zero;
  123. if (map.ContainsKey("scope_id"))
  124. scopeID = new UUID(map["scope_id"].AsString());
  125. m_log.Info("[LOGIN]: LLSD Login Requested for: '" + map["first"].AsString() + "' '" + map["last"].AsString() + "' / " + startLocation);
  126. LoginResponse reply = null;
  127. reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation, scopeID, String.Empty, remoteClient);
  128. return reply.ToOSDMap();
  129. }
  130. }
  131. return FailedOSDResponse();
  132. }
  133. private XmlRpcResponse FailedXMLRPCResponse()
  134. {
  135. Hashtable hash = new Hashtable();
  136. hash["reason"] = "key";
  137. hash["message"] = "Incomplete login credentials. Check your username and password.";
  138. hash["login"] = "false";
  139. XmlRpcResponse response = new XmlRpcResponse();
  140. response.Value = hash;
  141. return response;
  142. }
  143. private OSD FailedOSDResponse()
  144. {
  145. OSDMap map = new OSDMap();
  146. map["reason"] = OSD.FromString("key");
  147. map["message"] = OSD.FromString("Invalid login credentials. Check your username and passwd.");
  148. map["login"] = OSD.FromString("false");
  149. return map;
  150. }
  151. }
  152. }