From 17b00785ee10a71d290cbcddca9b0152fdf60c8f Mon Sep 17 00:00:00 2001 From: MW Date: Thu, 29 Mar 2007 11:08:42 +0000 Subject: Added lbsa71's http server changes. So it now has a single http listener that passes incoming requests to the correct handler. This means that logins (in sandbox mode) now go through this listener, which for now is listening on the port you set in startup (default 9000). (This needs changing so that the http listener and udp server are not using the same port) --- .../UserServer/LocalUserProfileManager.cs | 2 +- OpenSim.RegionServer/UserServer/LoginServer.cs | 303 +++++++++++---------- 2 files changed, 162 insertions(+), 143 deletions(-) (limited to 'OpenSim.RegionServer/UserServer') diff --git a/OpenSim.RegionServer/UserServer/LocalUserProfileManager.cs b/OpenSim.RegionServer/UserServer/LocalUserProfileManager.cs index b31feda..3ae7878 100644 --- a/OpenSim.RegionServer/UserServer/LocalUserProfileManager.cs +++ b/OpenSim.RegionServer/UserServer/LocalUserProfileManager.cs @@ -10,7 +10,7 @@ using libsecondlife; namespace OpenSim.UserServer { - class LocalUserProfileManager : UserProfileManager + public class LocalUserProfileManager : UserProfileManager { private IGridServer m_gridServer; private int m_port; diff --git a/OpenSim.RegionServer/UserServer/LoginServer.cs b/OpenSim.RegionServer/UserServer/LoginServer.cs index 7b4c1f0..a68e013 100644 --- a/OpenSim.RegionServer/UserServer/LoginServer.cs +++ b/OpenSim.RegionServer/UserServer/LoginServer.cs @@ -50,7 +50,7 @@ namespace OpenSim.UserServer /// /// When running in local (default) mode , handles client logins. /// - public class LoginServer : LoginService , IUserServer + public class LoginServer : LoginService, IUserServer { private IGridServer m_gridServer; private ushort _loginPort = 8080; @@ -66,7 +66,15 @@ namespace OpenSim.UserServer private int m_simPort; private string m_simAddr; - public LoginServer(IGridServer gridServer, string simAddr, int simPort , bool useAccounts) + public LocalUserProfileManager LocalUserManager + { + get + { + return userManager; + } + } + + public LoginServer(IGridServer gridServer, string simAddr, int simPort, bool useAccounts) { m_gridServer = gridServer; m_simPort = simPort; @@ -74,6 +82,14 @@ namespace OpenSim.UserServer this.userAccounts = useAccounts; } + public void Startup() + { + this.InitializeLogin(); + //Thread runLoginProxy = new Thread(new ThreadStart(RunLogin)); + //runLoginProxy.IsBackground = true; + //runLoginProxy.Start(); + } + // InitializeLogin: initialize the login private void InitializeLogin() { @@ -94,129 +110,124 @@ namespace OpenSim.UserServer SR.Close(); this._mpasswd = EncodePassword("testpass"); - userManager = new LocalUserProfileManager(this.m_gridServer, m_simPort, m_simAddr ); + userManager = new LocalUserProfileManager(this.m_gridServer, m_simPort, m_simAddr); userManager.InitUserProfiles(); userManager.SetKeys("", "", "", "Welcome to OpenSim"); - loginServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - loginServer.Bind(new IPEndPoint(remoteAddress, _loginPort)); - loginServer.Listen(1); - } - - public void Startup() - { - this.InitializeLogin(); - Thread runLoginProxy = new Thread(new ThreadStart(RunLogin)); - runLoginProxy.IsBackground = true; - runLoginProxy.Start(); - } - - private void RunLogin() - { - Console.WriteLine("Starting Login Server"); - try - { - for (; ; ) - { - Socket client = loginServer.Accept(); - IPEndPoint clientEndPoint = (IPEndPoint)client.RemoteEndPoint; - - - NetworkStream networkStream = new NetworkStream(client); - StreamReader networkReader = new StreamReader(networkStream); - StreamWriter networkWriter = new StreamWriter(networkStream); - - try - { - LoginRequest(networkReader, networkWriter); - } - catch (Exception e) - { - Console.WriteLine(e.Message); - } - - networkWriter.Close(); - networkReader.Close(); - networkStream.Close(); - - client.Close(); - - // send any packets queued for injection - - } - } - catch (Exception e) - { - Console.WriteLine(e.Message); - Console.WriteLine(e.StackTrace); - } - } - - // ProxyLogin: proxy a login request - private void LoginRequest(StreamReader reader, StreamWriter writer) - { - lock (this) - { - string line; - int contentLength = 0; - // read HTTP header - do - { - // read one line of the header - line = reader.ReadLine(); - - // check for premature EOF - if (line == null) - throw new Exception("EOF in client HTTP header"); - - // look for Content-Length - Match match = (new Regex(@"Content-Length: (\d+)$")).Match(line); - if (match.Success) - contentLength = Convert.ToInt32(match.Groups[1].Captures[0].ToString()); - } while (line != ""); - - // read the HTTP body into a buffer - char[] content = new char[contentLength]; - reader.Read(content, 0, contentLength); - - if (this.userAccounts) - { - //ask the UserProfile Manager to process the request - string reply = this.userManager.ParseXMLRPC(new String(content)); - // forward the XML-RPC response to the client - writer.WriteLine("HTTP/1.0 200 OK"); - writer.WriteLine("Content-type: text/xml"); - writer.WriteLine(); - writer.WriteLine(reply); - } - else - { - //handle ourselves - XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(new String(content)); - if (request.MethodName == "login_to_simulator") - { - this.ProcessXmlRequest(request, writer); - } - else - { - XmlRpcResponse PresenceErrorResp = new XmlRpcResponse(); - Hashtable PresenceErrorRespData = new Hashtable(); - PresenceErrorRespData["reason"] = "XmlRequest"; ; - PresenceErrorRespData["message"] = "Unknown Rpc request"; - PresenceErrorRespData["login"] = "false"; - PresenceErrorResp.Value = PresenceErrorRespData; - string reply = Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(PresenceErrorResp), " encoding=\"utf-16\"", ""); - writer.WriteLine("HTTP/1.0 200 OK"); - writer.WriteLine("Content-type: text/xml"); - writer.WriteLine(); - writer.WriteLine(reply); - } - } - } + //loginServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + // loginServer.Bind(new IPEndPoint(remoteAddress, _loginPort)); + //loginServer.Listen(1); } - public bool ProcessXmlRequest(XmlRpcRequest request, StreamWriter writer) + /* private void RunLogin() + { + Console.WriteLine("Starting Login Server"); + try + { + for (; ; ) + { + Socket client = loginServer.Accept(); + IPEndPoint clientEndPoint = (IPEndPoint)client.RemoteEndPoint; + + + NetworkStream networkStream = new NetworkStream(client); + StreamReader networkReader = new StreamReader(networkStream); + StreamWriter networkWriter = new StreamWriter(networkStream); + + try + { + LoginRequest(networkReader, networkWriter); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + + networkWriter.Close(); + networkReader.Close(); + networkStream.Close(); + + client.Close(); + + // send any packets queued for injection + + } + } + catch (Exception e) + { + Console.WriteLine(e.Message); + Console.WriteLine(e.StackTrace); + } + } + + // ProxyLogin: proxy a login request + private void LoginRequest(StreamReader reader, StreamWriter writer) + { + lock (this) + { + string line; + int contentLength = 0; + // read HTTP header + do + { + // read one line of the header + line = reader.ReadLine(); + + // check for premature EOF + if (line == null) + throw new Exception("EOF in client HTTP header"); + + // look for Content-Length + Match match = (new Regex(@"Content-Length: (\d+)$")).Match(line); + if (match.Success) + contentLength = Convert.ToInt32(match.Groups[1].Captures[0].ToString()); + } while (line != ""); + + // read the HTTP body into a buffer + char[] content = new char[contentLength]; + reader.Read(content, 0, contentLength); + + if (this.userAccounts) + { + //ask the UserProfile Manager to process the request + string reply = this.userManager.ParseXMLRPC(new String(content)); + // forward the XML-RPC response to the client + writer.WriteLine("HTTP/1.0 200 OK"); + writer.WriteLine("Content-type: text/xml"); + writer.WriteLine(); + writer.WriteLine(reply); + } + else + { + //handle ourselves + XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(new String(content)); + if (request.MethodName == "login_to_simulator") + { + this.ProcessXmlRequest(request, writer); + } + else + { + XmlRpcResponse PresenceErrorResp = new XmlRpcResponse(); + Hashtable PresenceErrorRespData = new Hashtable(); + PresenceErrorRespData["reason"] = "XmlRequest"; ; + PresenceErrorRespData["message"] = "Unknown Rpc request"; + PresenceErrorRespData["login"] = "false"; + PresenceErrorResp.Value = PresenceErrorRespData; + string reply = Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(PresenceErrorResp), " encoding=\"utf-16\"", ""); + writer.WriteLine("HTTP/1.0 200 OK"); + writer.WriteLine("Content-type: text/xml"); + writer.WriteLine(); + writer.WriteLine(reply); + } + } + } + } + */ + //public bool ProcessXmlRequest(XmlRpcRequest request, StreamWriter writer) + + public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request) { + Console.WriteLine("login attempt"); Hashtable requestData = (Hashtable)request.Params[0]; string first; string last; @@ -224,6 +235,8 @@ namespace OpenSim.UserServer LLUUID Agent; LLUUID Session; + XmlRpcResponse response = new XmlRpcResponse(); + //get login name if (requestData.Contains("first")) { @@ -254,18 +267,24 @@ namespace OpenSim.UserServer if (!Authenticate(first, last, passwd)) { - XmlRpcResponse PresenceErrorResp = new XmlRpcResponse(); - Hashtable PresenceErrorRespData = new Hashtable(); - PresenceErrorRespData["reason"] = "key"; ; - PresenceErrorRespData["message"] = "You have entered an invalid name/password combination. Check Caps/lock."; - PresenceErrorRespData["login"] = "false"; - PresenceErrorResp.Value = PresenceErrorRespData; - string reply = Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(PresenceErrorResp), " encoding=\"utf-16\"", ""); - writer.WriteLine("HTTP/1.0 200 OK"); - writer.WriteLine("Content-type: text/xml"); - writer.WriteLine(); - writer.WriteLine(reply); - return false; + /* XmlRpcResponse PresenceErrorResp = new XmlRpcResponse(); + Hashtable PresenceErrorRespData = new Hashtable(); + PresenceErrorRespData["reason"] = "key"; ; + PresenceErrorRespData["message"] = "You have entered an invalid name/password combination. Check Caps/lock."; + PresenceErrorRespData["login"] = "false"; + PresenceErrorResp.Value = PresenceErrorRespData; + string reply = Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(PresenceErrorResp), " encoding=\"utf-16\"", ""); + writer.WriteLine("HTTP/1.0 200 OK"); + writer.WriteLine("Content-type: text/xml"); + writer.WriteLine(); + writer.WriteLine(reply); + return false;*/ + + Hashtable loginError = new Hashtable(); + loginError["reason"] = "key"; ; + loginError["message"] = "You have entered an invalid name/password combination. Check Caps/lock."; + loginError["login"] = "false"; + response.Value = loginError; } NumClients++; @@ -291,15 +310,15 @@ namespace OpenSim.UserServer ArrayList GlobalTextures = new ArrayList(); GlobalTextures.Add(GlobalT); - XmlRpcResponse response = (XmlRpcResponse)(new XmlRpcResponseDeserializer()).Deserialize(this._defaultResponse); + response = (XmlRpcResponse)(new XmlRpcResponseDeserializer()).Deserialize(this._defaultResponse); Hashtable responseData = (Hashtable)response.Value; responseData["sim_port"] = m_simPort; responseData["sim_ip"] = m_simAddr; responseData["agent_id"] = Agent.ToStringHyphenated(); responseData["session_id"] = Session.ToStringHyphenated(); - responseData["secure_session_id"]= secureSess.ToStringHyphenated(); - responseData["circuit_code"] = (Int32)(Util.RandomClass.Next()); + responseData["secure_session_id"] = secureSess.ToStringHyphenated(); + responseData["circuit_code"] = (Int32)(Util.RandomClass.Next()); responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; responseData["login-flags"] = LoginFlags; responseData["global-textures"] = GlobalTextures; @@ -337,16 +356,16 @@ namespace OpenSim.UserServer ((LocalGridBase)m_gridServer).AddNewSession(_login); } - // forward the XML-RPC response to the client - writer.WriteLine("HTTP/1.0 200 OK"); - writer.WriteLine("Content-type: text/xml"); - writer.WriteLine(); + /* // forward the XML-RPC response to the client + writer.WriteLine("HTTP/1.0 200 OK"); + writer.WriteLine("Content-type: text/xml"); + writer.WriteLine(); - XmlTextWriter responseWriter = new XmlTextWriter(writer); - XmlRpcResponseSerializer.Singleton.Serialize(responseWriter, response); - responseWriter.Close(); + XmlTextWriter responseWriter = new XmlTextWriter(writer); + XmlRpcResponseSerializer.Singleton.Serialize(responseWriter, response); + responseWriter.Close();*/ - return true; + return response; } protected virtual void CustomiseLoginResponse(Hashtable responseData, string first, string last) -- cgit v1.1