// ProxyLogin: proxy a login request private void ProxyLogin(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); XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(new String(content)); if (request.MethodName == "login_to_simulator") { Hashtable requestData = (Hashtable)request.Params[0]; string first; string last; string passwd; LLUUID Agent; LLUUID Session; //get login name if (requestData.Contains("first")) { first = (string)requestData["first"]; } else { first = "test"; } if (requestData.Contains("last")) { last = (string)requestData["last"]; } else { last = "User" + NumClients.ToString(); } if (requestData.Contains("passwd")) { passwd = (string)requestData["passwd"]; } else { passwd = "notfound"; } if (!Authenticate(first, last, passwd)) { // Fail miserably writer.WriteLine("HTTP/1.0 403 Authentication Forbidden"); writer.WriteLine(); return; } NumClients++; //create a agent and session LLUUID Agent = GetAgentId(first, last); int SessionRand = this.RandomClass.Next(1, 999); Session = new LLUUID("aaaabbbb-0200-" + SessionRand.ToString("0000") + "-8664-58f53e442797"); XmlRpcResponse response = (XmlRpcResponse)(new XmlRpcResponseDeserializer()).Deserialize(this._defaultResponse); Hashtable responseData = (Hashtable)response.Value; responseData["sim_port"] = Globals.Instance.SimPort; responseData["sim_ip"] = Globals.Instance.SimIPAddress; responseData["agent_id"] = Agent.ToStringHyphenated(); responseData["session_id"] = Session.ToStringHyphenated(); ArrayList InventoryList = (ArrayList)responseData["inventory-skeleton"]; Hashtable Inventory1 = (Hashtable)InventoryList[0]; Hashtable Inventory2 = (Hashtable)InventoryList[1]; LLUUID BaseFolderID = LLUUID.Random(); LLUUID InventoryFolderID = LLUUID.Random(); Inventory2["name"] = "Base"; Inventory2["folder_id"] = BaseFolderID.ToStringHyphenated(); Inventory2["type_default"] = 6; Inventory1["folder_id"] = InventoryFolderID.ToStringHyphenated(); ArrayList InventoryRoot = (ArrayList)responseData["inventory-root"]; Hashtable Inventoryroot = (Hashtable)InventoryRoot[0]; Inventoryroot["folder_id"] = InventoryFolderID.ToStringHyphenated(); CustomiseLoginResponse(responseData, first, last); this._login = new Logon(); //copy data to login object _login.First = first; _login.Last = last; _login.Agent = Agent; _login.Session = Session; _login.BaseFolder = BaseFolderID; _login.InventoryFolder = InventoryFolderID; lock (Globals.Instance.IncomingLogins) { Globals.Instance.IncomingLogins.Add(_login); } // 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(); } else { writer.WriteLine("HTTP/1.0 403 Authentication Forbidden"); writer.WriteLine(); } } }
// ProxyLogin: proxy a login request private void ProxyLogin(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); XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(new String(content)); if(request.MethodName == "login_to_simulator") { Hashtable requestData = (Hashtable)request.Params[0]; string first; string last; string passwd; LLUUID Agent; LLUUID Session; //get login name if(requestData.Contains("first")) { first = (string)requestData["first"]; } else { first = "test"; } if(requestData.Contains("last")) { last = (string)requestData["last"]; } else { last = "User"+NumClients.ToString(); } if(requestData.Contains("passwd")) { passwd = (string)requestData["passwd"]; } else { passwd = "notfound"; } if( !Authenticate(first, last, passwd)) { // Fail miserably writer.WriteLine("HTTP/1.0 403 Authentication Forbidden"); writer.WriteLine(); return; } NumClients++; //create a agent and session LLUUID Agent = GetAgentId( first, last ); int SessionRand = this.RandomClass.Next(1,999); Session = new LLUUID("aaaabbbb-0200-"+SessionRand.ToString("0000")+"-8664-58f53e442797"); XmlRpcResponse response =(XmlRpcResponse)(new XmlRpcResponseDeserializer()).Deserialize(this._defaultResponse); Hashtable responseData = (Hashtable)response.Value; responseData["sim_port"] = Globals.Instance.SimPort; responseData["sim_ip"] = Globals.Instance.SimIPAddress; responseData["agent_id"] = Agent.ToStringHyphenated(); responseData["session_id"] = Session.ToStringHyphenated(); ArrayList InventoryList = (ArrayList) responseData["inventory-skeleton"]; Hashtable Inventory1 = (Hashtable)InventoryList[0]; Hashtable Inventory2 = (Hashtable)InventoryList[1]; LLUUID BaseFolderID = LLUUID.Random(); LLUUID InventoryFolderID = LLUUID.Random(); Inventory2["name"] = "Base"; Inventory2["folder_id"] = BaseFolderID.ToStringHyphenated(); Inventory2["type_default"] =6; Inventory1["folder_id"] = InventoryFolderID.ToStringHyphenated(); ArrayList InventoryRoot = (ArrayList) responseData["inventory-root"]; Hashtable Inventoryroot = (Hashtable)InventoryRoot[0]; Inventoryroot["folder_id"] = InventoryFolderID.ToStringHyphenated(); CustomiseLoginResponse( responseData, first, last ); this._login = new Logon(); //copy data to login object _login.First = first; _login.Last = last; _login.Agent = Agent; _login.Session = Session; _login.BaseFolder = BaseFolderID; _login.InventoryFolder = InventoryFolderID; lock(Globals.Instance.IncomingLogins) { Globals.Instance.IncomingLogins.Add(_login); } // 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(); } else { writer.WriteLine("HTTP/1.0 403 Authentication Forbidden"); writer.WriteLine(); } } }