* tourmaline

tourmaline
lbsa71 2007-03-28 18:18:59 +00:00
parent 7d04714690
commit 934ae00051
16 changed files with 626 additions and 621 deletions

View File

@ -84,18 +84,18 @@ namespace OpenGridServices.GridServer
public void Startup()
{
m_console.WriteLine("Main.cs:Startup() - Please press enter to retain default settings");
m_console.WriteLine("Main.cs:Startup() - Please press enter for default settings");
this.GridOwner = m_console.CmdPrompt("Grid owner [OGS development team]: ", "OGS development team");
this.DefaultStartupMsg = m_console.CmdPrompt("Default startup message for clients [Welcome to OGS!]: ", "Welcome to OGS!");
this.GridOwner = m_console.CmdPrompt("Grid owner", "OGS development team");
this.DefaultStartupMsg = m_console.CmdPrompt("Default startup message for clients", "Welcome to OGS!");
this.DefaultAssetServer = m_console.CmdPrompt("Default asset server [no default]: ");
this.AssetSendKey = m_console.CmdPrompt("Key to send to asset server: ");
this.AssetRecvKey = m_console.CmdPrompt("Key to expect from asset server: ");
this.DefaultAssetServer = m_console.CmdPrompt("Default asset server");
this.AssetSendKey = m_console.CmdPrompt("Key to send to asset server");
this.AssetRecvKey = m_console.CmdPrompt("Key to expect from asset server");
this.DefaultUserServer = m_console.CmdPrompt("Default user server [no default]: ");
this.UserSendKey = m_console.CmdPrompt("Key to send to user server: ");
this.UserRecvKey = m_console.CmdPrompt("Key to expect from user server: ");
this.DefaultUserServer = m_console.CmdPrompt("Default user server", "http://localhost:8002/userserver");
this.UserSendKey = m_console.CmdPrompt("Key to send to user server");
this.UserRecvKey = m_console.CmdPrompt("Key to expect from user server");
m_console.WriteLine("Main.cs:Startup() - Starting HTTP process");
_httpd = new GridHTTPServer();

View File

@ -87,11 +87,11 @@ namespace OpenGridServices.UserServer
}
public void Startup() {
MainConsole.Instance.WriteLine("Main.cs:Startup() - Please press enter to retain default settings");
MainConsole.Instance.WriteLine("Main.cs:Startup() - Please press enter for default settings");
this.GridURL=MainConsole.Instance.CmdPrompt("Grid URL: ");
this.GridSendKey=MainConsole.Instance.CmdPrompt("Key to send to grid: ");
this.GridRecvKey=MainConsole.Instance.CmdPrompt("Key to expect from grid: ");
this.GridURL = MainConsole.Instance.CmdPrompt("Grid URL", "http://localhost:8001/gridserver");
this.GridSendKey=MainConsole.Instance.CmdPrompt("Key to send to grid");
this.GridRecvKey=MainConsole.Instance.CmdPrompt("Key to expect from grid");
this.DefaultStartupMsg=MainConsole.Instance.CmdPrompt("Default startup message for clients [Welcome to OGS!] :","Welcome to OGS!");
@ -105,9 +105,9 @@ namespace OpenGridServices.UserServer
string templastname;
string tempMD5Passwd;
MainConsole.Instance.WriteLine("Main.cs:Startup() - Please configure the grid god user:");
tempfirstname=MainConsole.Instance.CmdPrompt("First name: ");
templastname=MainConsole.Instance.CmdPrompt("Last name: ");
tempMD5Passwd=MainConsole.Instance.PasswdPrompt("Password: ");
tempfirstname=MainConsole.Instance.CmdPrompt("First name", "God");
templastname=MainConsole.Instance.CmdPrompt("Last name", "User");
tempMD5Passwd=MainConsole.Instance.PasswdPrompt("Password");
System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bs = System.Text.Encoding.UTF8.GetBytes(tempMD5Passwd);

View File

@ -52,22 +52,22 @@ namespace OpenSim.Config.SimConfigDb4o
public void LoadDefaults() {
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Config.cs:LoadDefaults() - Please press enter to retain default or enter new settings");
this.RegionName=OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Name [OpenSim test]: ","OpenSim test");
this.RegionLocX=(uint)Convert.ToInt32(OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Grid Location X [997]: ","997"));
this.RegionLocY=(uint)Convert.ToInt32(OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Grid Location Y [996]: ","996"));
this.IPListenPort=Convert.ToInt32(OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("UDP port for client connections [9000]: ","9000"));
this.IPListenAddr=OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("IP Address to listen on for client connections [127.0.0.1]: ","127.0.0.1");
this.RegionName=OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Name","OpenSim test");
this.RegionLocX=(uint)Convert.ToInt32(OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Grid Location X","997"));
this.RegionLocY=(uint)Convert.ToInt32(OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Grid Location Y","996"));
this.IPListenPort=Convert.ToInt32(OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("UDP port for client connections","9000"));
this.IPListenAddr=OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("IP Address to listen on for client connections","127.0.0.1");
if(!isSandbox)
{
this.AssetURL=OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Asset server URL: ");
this.AssetSendKey=OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Asset server key: ");
this.GridURL=OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Grid server URL: ");
this.GridSendKey = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Key to send to grid server: ");
this.GridRecvKey = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Key to expect from grid server: ");
this.UserURL = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("User server URL: ");
this.UserSendKey = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Key to send to user server: ");
this.UserRecvKey = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Key to expect from user server: ");
this.AssetURL=OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Asset server URL");
this.AssetSendKey=OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Asset server key");
this.GridURL = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Grid server URL", "http://localhost:8002/userserver");
this.GridSendKey = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Key to send to grid server");
this.GridRecvKey = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Key to expect from grid server");
this.UserURL = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("User server URL", "http://localhost:8001/gridserver");
this.UserSendKey = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Key to send to user server");
this.UserRecvKey = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Key to expect from user server");
}
this.RegionHandle = Util.UIntsToLong((RegionLocX*256), (RegionLocY*256));
}

View File

@ -84,14 +84,14 @@ namespace OpenSim.Framework.Console
// Displays a command prompt and waits for the user to enter a string, then returns that string
public string CmdPrompt(string prompt)
{
this.Write(prompt);
this.Write("{0}: ", prompt);
return this.ReadLine();
}
// Displays a command prompt and returns a default value if the user simply presses enter
public string CmdPrompt(string prompt, string defaultresponse)
{
string temp = CmdPrompt(prompt);
string temp = CmdPrompt( String.Format("{0} [{1}]", prompt, defaultresponse ));
if (temp == "")
{
return defaultresponse;

View File

@ -34,62 +34,63 @@ namespace OpenSim.Framework.User
public virtual string ParseXMLRPC(string requestBody)
{
XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
Hashtable requestData = (Hashtable)request.Params[0];
switch (request.MethodName)
{
case "login_to_simulator":
bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd"));
bool GoodLogin = false;
string firstname = "";
string lastname = "";
string passwd = "";
XmlRpcResponse response = XmlRpcLoginMethod(request);
if (GoodXML)
{
firstname = (string)requestData["first"];
lastname = (string)requestData["last"];
passwd = (string)requestData["passwd"];
GoodLogin = AuthenticateUser(firstname, lastname, passwd);
}
return (Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(response), "utf-16", "utf-8"));
}
return "";
}
public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable requestData = (Hashtable)request.Params[0];
bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd"));
bool GoodLogin = false;
string firstname = "";
string lastname = "";
string passwd = "";
if (GoodXML)
{
firstname = (string)requestData["first"];
lastname = (string)requestData["last"];
passwd = (string)requestData["passwd"];
GoodLogin = AuthenticateUser(firstname, lastname, passwd);
}
if (!(GoodXML && GoodLogin))
{
XmlRpcResponse LoginErrorResp = new XmlRpcResponse();
Hashtable ErrorRespData = new Hashtable();
ErrorRespData["reason"] = "key";
ErrorRespData["message"] = "Error connecting to grid. Please double check your login details and check with the grid owner if you are sure these are correct";
ErrorRespData["login"] = "false";
LoginErrorResp.Value = ErrorRespData;
return (Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(LoginErrorResp), " encoding=\"utf-16\"", ""));
}
UserProfile TheUser = GetProfileByName(firstname, lastname);
/*
if (!((TheUser.CurrentSessionID == null) && (TheUser.CurrentSecureSessionID == null)))
{
XmlRpcResponse PresenceErrorResp = new XmlRpcResponse();
Hashtable PresenceErrorRespData = new Hashtable();
PresenceErrorRespData["reason"] = "presence";
PresenceErrorRespData["message"] = "You appear to be already logged in, if this is not the case please wait for your session to timeout, if this takes longer than a few minutes please contact the grid owner";
PresenceErrorRespData["login"] = "false";
PresenceErrorResp.Value = PresenceErrorRespData;
return (Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(PresenceErrorResp), " encoding=\"utf-16\"", ""));
}*/
if (!(GoodXML && GoodLogin))
{
response = CreateErrorConnectingToGridResponse();
}
else
{
UserProfile TheUser = GetProfileByName(firstname, lastname);
if (!((TheUser.CurrentSessionID == null) && (TheUser.CurrentSecureSessionID == null)))
{
response = CreateAlreadyLoggedInResponse();
}
else
{
try
{
Hashtable responseData = new Hashtable();
LLUUID AgentID = TheUser.UUID;
TheUser.InitSessionData();
// SimProfile SimInfo = new SimProfile();
// SimInfo = SimInfo.LoadFromGrid(TheUser.homeregionhandle, GridURL, GridSendKey, GridRecvKey);
// SimProfile SimInfo = new SimProfile();
// SimInfo = SimInfo.LoadFromGrid(TheUser.homeregionhandle, GridURL, GridSendKey, GridRecvKey);
XmlRpcResponse LoginGoodResp = new XmlRpcResponse();
Hashtable LoginGoodData = new Hashtable();
Hashtable GlobalT = new Hashtable();
GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271";
@ -117,7 +118,6 @@ namespace OpenSim.Framework.User
ArrayList ClassifiedCategories = new ArrayList();
ClassifiedCategories.Add(ClassifiedCategoriesHash);
Console.WriteLine("copying inventory data to response");
ArrayList AgentInventory = new ArrayList();
foreach (InventoryFolder InvFolder in TheUser.Inventory.InventoryFolders.Values)
{
@ -144,52 +144,73 @@ namespace OpenSim.Framework.User
uint circode = (uint)(Util.RandomClass.Next());
//TheUser.AddSimCircuit(circode, SimInfo.UUID);
LoginGoodData["last_name"] = "\"" + TheUser.lastname + "\"";
LoginGoodData["ui-config"] = ui_config;
LoginGoodData["sim_ip"] = "127.0.0.1"; //SimInfo.sim_ip.ToString();
LoginGoodData["login-flags"] = LoginFlags;
LoginGoodData["global-textures"] = GlobalTextures;
LoginGoodData["classified_categories"] = ClassifiedCategories;
LoginGoodData["event_categories"] = new ArrayList();
LoginGoodData["inventory-skeleton"] = AgentInventory;
LoginGoodData["inventory-skel-lib"] = new ArrayList();
LoginGoodData["inventory-root"] = InventoryRoot;
LoginGoodData["event_notifications"] = new ArrayList();
LoginGoodData["gestures"] = new ArrayList();
LoginGoodData["inventory-lib-owner"] = new ArrayList();
LoginGoodData["initial-outfit"] = InitialOutfit;
LoginGoodData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
LoginGoodData["start_location"] = "last";
LoginGoodData["home"] = "{'region_handle':[r" + (997 * 256).ToString() + ",r" + (996 * 256).ToString() + "], 'position':[r" + TheUser.homepos.X.ToString() + ",r" + TheUser.homepos.Y.ToString() + ",r" + TheUser.homepos.Z.ToString() + "], 'look_at':[r" + TheUser.homelookat.X.ToString() + ",r" + TheUser.homelookat.Y.ToString() + ",r" + TheUser.homelookat.Z.ToString() + "]}";
LoginGoodData["message"] = DefaultStartupMsg;
LoginGoodData["first_name"] = "\"" + TheUser.firstname + "\"";
LoginGoodData["circuit_code"] = (Int32)circode;
LoginGoodData["sim_port"] = 9000; //(Int32)SimInfo.sim_port;
LoginGoodData["secure_session_id"] = TheUser.CurrentSecureSessionID.ToStringHyphenated();
LoginGoodData["look_at"] = "\n[r" + TheUser.homelookat.X.ToString() + ",r" + TheUser.homelookat.Y.ToString() + ",r" + TheUser.homelookat.Z.ToString() + "]\n";
LoginGoodData["agent_id"] = AgentID.ToStringHyphenated();
LoginGoodData["region_y"] = (Int32) 996 * 256; // (Int32)SimInfo.RegionLocY * 256;
LoginGoodData["region_x"] = (Int32) 997 * 256; //SimInfo.RegionLocX * 256;
LoginGoodData["seed_capability"] = null;
LoginGoodData["agent_access"] = "M";
LoginGoodData["session_id"] = TheUser.CurrentSessionID.ToStringHyphenated();
LoginGoodData["login"] = "true";
responseData["last_name"] = "\"" + TheUser.firstname + "\"";
responseData["ui-config"] = ui_config;
responseData["sim_ip"] = "127.0.0.1"; //SimInfo.sim_ip.ToString();
responseData["login-flags"] = LoginFlags;
responseData["global-textures"] = GlobalTextures;
responseData["classified_categories"] = ClassifiedCategories;
responseData["event_categories"] = new ArrayList();
responseData["inventory-skeleton"] = AgentInventory;
responseData["inventory-skel-lib"] = new ArrayList();
responseData["inventory-root"] = InventoryRoot;
responseData["event_notifications"] = new ArrayList();
responseData["gestures"] = new ArrayList();
responseData["inventory-lib-owner"] = new ArrayList();
responseData["initial-outfit"] = InitialOutfit;
responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
responseData["start_location"] = "last";
responseData["home"] = "{'region_handle':[r" + (997 * 256).ToString() + ",r" + (996 * 256).ToString() + "], 'position':[r" + TheUser.homepos.X.ToString() + ",r" + TheUser.homepos.Y.ToString() + ",r" + TheUser.homepos.Z.ToString() + "], 'look_at':[r" + TheUser.homelookat.X.ToString() + ",r" + TheUser.homelookat.Y.ToString() + ",r" + TheUser.homelookat.Z.ToString() + "]}";
responseData["message"] = DefaultStartupMsg;
responseData["first_name"] = "\"" + firstname + "\"";
responseData["circuit_code"] = (Int32)circode;
responseData["sim_port"] = 9000; //(Int32)SimInfo.sim_port;
responseData["secure_session_id"] = TheUser.CurrentSecureSessionID.ToStringHyphenated();
responseData["look_at"] = "\n[r" + TheUser.homelookat.X.ToString() + ",r" + TheUser.homelookat.Y.ToString() + ",r" + TheUser.homelookat.Z.ToString() + "]\n";
responseData["agent_id"] = AgentID.ToStringHyphenated();
responseData["region_y"] = (Int32)996 * 256; // (Int32)SimInfo.RegionLocY * 256;
responseData["region_x"] = (Int32)997 * 256; //SimInfo.RegionLocX * 256;
responseData["seed_capability"] = null;
responseData["agent_access"] = "M";
responseData["session_id"] = TheUser.CurrentSessionID.ToStringHyphenated();
responseData["login"] = "true";
this.CustomiseResponse(ref LoginGoodData, TheUser);
LoginGoodResp.Value = LoginGoodData;
this.CustomiseResponse(ref responseData, TheUser);
response.Value = responseData;
//TheUser.SendDataToSim(SimInfo);
return (Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(LoginGoodResp), "utf-16", "utf-8"));
}
catch (Exception E)
{
Console.WriteLine(E.ToString());
}
break;
}
}
return response;
}
return "";
private static XmlRpcResponse CreateErrorConnectingToGridResponse()
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable ErrorRespData = new Hashtable();
ErrorRespData["reason"] = "key";
ErrorRespData["message"] = "Error connecting to grid. Please double check your login details and check with the grid owner if you are sure these are correct";
ErrorRespData["login"] = "false";
response.Value = ErrorRespData;
return response;
}
private static XmlRpcResponse CreateAlreadyLoggedInResponse()
{
XmlRpcResponse response = new XmlRpcResponse();
Hashtable PresenceErrorRespData = new Hashtable();
PresenceErrorRespData["reason"] = "presence";
PresenceErrorRespData["message"] = "You appear to be already logged in, if this is not the case please wait for your session to timeout, if this takes longer than a few minutes please contact the grid owner";
PresenceErrorRespData["login"] = "false";
response.Value = PresenceErrorRespData;
return response;
}
public virtual void CustomiseResponse(ref Hashtable response, UserProfile theUser)
@ -198,8 +219,8 @@ namespace OpenSim.Framework.User
SimProfile SimInfo = new SimProfile();
//get siminfo from grid server
SimInfo = SimInfo.LoadFromGrid(theUser.homeregionhandle, GridURL, GridSendKey, GridRecvKey);
Int32 circode = (Int32)response["circuit_code"];
theUser.AddSimCircuit((uint)circode, SimInfo.UUID);
uint circode = (uint)response["circuit_code"];
theUser.AddSimCircuit(circode, SimInfo.UUID);
response["home"] = "{'region_handle':[r" + (SimInfo.RegionLocX * 256).ToString() + ",r" + (SimInfo.RegionLocY * 256).ToString() + "], 'position':[r" + theUser.homepos.X.ToString() + ",r" + theUser.homepos.Y.ToString() + ",r" + theUser.homepos.Z.ToString() + "], 'look_at':[r" + theUser.homelookat.X.ToString() + ",r" + theUser.homelookat.Y.ToString() + ",r" + theUser.homelookat.Z.ToString() + "]}";
response["sim_ip"] = SimInfo.sim_ip.ToString();
response["sim_port"] = (Int32)SimInfo.sim_port;

View File

@ -1,11 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.CAPS
{
public interface IXmlRPCHandler
{
string HandleRPC(string requestBody);
}
}

View File

@ -1,241 +0,0 @@
/*
Copyright (c) OpenSimCAPS project, http://osgrid.org/
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Text;
using Nwc.XmlRpc;
using System.Threading;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using libsecondlife;
using OpenSim.Framework.Console;
using OpenSim.Framework.Interfaces;
using OpenSim.Servers;
namespace OpenSim.CAPS
{
// Dummy HTTP server, does nothing useful for now
public class SimCAPSHTTPServer : BaseHttpServer
{
private Thread m_workerThread;
private HttpListener m_httpListener;
private Dictionary<string, IRestHandler> m_restHandlers = new Dictionary<string, IRestHandler>();
private Dictionary<string, IXmlRPCHandler> RPCHandlers = new Dictionary<string, IXmlRPCHandler>();
private IGridServer m_gridServer;
private int m_port;
public SimCAPSHTTPServer(IGridServer gridServer, int port)
{
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting up HTTP Server");
m_workerThread = new Thread(new ThreadStart(StartHTTP));
m_workerThread.Start();
m_gridServer = gridServer;
m_port = port;
}
public void StartHTTP()
{
try
{
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("SimHttp.cs:StartHTTP() - Spawned main thread OK");
m_httpListener = new HttpListener();
m_httpListener.Prefixes.Add("http://+:" + m_port + "/");
m_httpListener.Start();
HttpListenerContext context;
while (true)
{
context = m_httpListener.GetContext();
ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context);
}
}
catch (Exception e)
{
OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.Message);
}
}
public bool AddRestHandler(string path, IRestHandler handler)
{
if (!this.m_restHandlers.ContainsKey(path))
{
this.m_restHandlers.Add(path, handler);
return true;
}
//must already have a handler for that path so return false
return false;
}
public bool AddXmlRPCHandler(string method, IXmlRPCHandler handler)
{
if (!this.RPCHandlers.ContainsKey(method))
{
this.RPCHandlers.Add(method, handler);
return true;
}
//must already have a handler for that path so return false
return false;
}
protected virtual string ParseXMLRPC(string requestBody)
{
string responseString = "";
try
{
XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
Hashtable requestData = (Hashtable)request.Params[0];
switch (request.MethodName)
{
case "expect_user":
AgentCircuitData agent_data = new AgentCircuitData();
agent_data.SessionID = new LLUUID((string)requestData["session_id"]);
agent_data.SecureSessionID = new LLUUID((string)requestData["secure_session_id"]);
agent_data.firstname = (string)requestData["firstname"];
agent_data.lastname = (string)requestData["lastname"];
agent_data.AgentID = new LLUUID((string)requestData["agent_id"]);
agent_data.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
if (m_gridServer.GetName() == "Remote")
{
((RemoteGridBase) m_gridServer).agentcircuits.Add((uint)agent_data.circuitcode, agent_data);
}
responseString = "<?xml version=\"1.0\"?><methodResponse><params /></methodResponse>";
break;
default:
if (this.RPCHandlers.ContainsKey(request.MethodName))
{
//responseString = this.RPCHandlers[request.MethodName]
}
break;
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
return responseString;
}
protected virtual string ParseREST(string requestBody, string requestURL, string requestMethod)
{
string[] path;
string pathDelimStr = "/";
char[] pathDelimiter = pathDelimStr.ToCharArray();
path = requestURL.Split(pathDelimiter);
string responseString = "";
//path[0] should be empty so we are interested in path[1]
if (path.Length > 1)
{
if ((path[1] != "") && (this.m_restHandlers.ContainsKey(path[1])))
{
responseString = this.m_restHandlers[path[1]].HandleREST(requestBody, requestURL, requestMethod);
}
}
return responseString;
}
protected virtual string ParseLLSDXML(string requestBody)
{
// dummy function for now - IMPLEMENT ME!
return "";
}
public virtual void HandleRequest(Object stateinfo)
{
// Console.WriteLine("new http incoming");
HttpListenerContext context = (HttpListenerContext)stateinfo;
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
response.KeepAlive = false;
response.SendChunked = false;
System.IO.Stream body = request.InputStream;
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
string requestBody = reader.ReadToEnd();
body.Close();
reader.Close();
//Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType);
//Console.WriteLine(requestBody);
string responseString = "";
switch (request.ContentType)
{
case "text/xml":
// must be XML-RPC, so pass to the XML-RPC parser
responseString = ParseXMLRPC(requestBody);
response.AddHeader("Content-type", "text/xml");
break;
case "application/xml":
// probably LLSD we hope, otherwise it should be ignored by the parser
responseString = ParseLLSDXML(requestBody);
response.AddHeader("Content-type", "application/xml");
break;
case "application/x-www-form-urlencoded":
// a form data POST so send to the REST parser
responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
response.AddHeader("Content-type", "text/html");
break;
case null:
// must be REST or invalid crap, so pass to the REST parser
responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
response.AddHeader("Content-type", "text/html");
break;
}
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
System.IO.Stream output = response.OutputStream;
response.SendChunked = false;
response.ContentLength64 = buffer.Length;
output.Write(buffer, 0, buffer.Length);
output.Close();
}
}
}

View File

@ -117,7 +117,6 @@
<Compile Include="AgentAssetUpload.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="CAPS\IXmlRPCHandler.cs" />
<Compile Include="ConsoleCmds.cs">
<SubType>Code</SubType>
</Compile>
@ -151,9 +150,6 @@
<Compile Include="CAPS\AdminWebFront.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="CAPS\IRestHandler.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="CAPS\SimHttp.cs">
<SubType>Code</SubType>
</Compile>

View File

@ -45,6 +45,8 @@ using OpenSim.Assets;
using OpenSim.CAPS;
using OpenSim.Framework.Console;
using OpenSim.Physics.Manager;
using Nwc.XmlRpc;
using OpenSim.Servers;
namespace OpenSim
{
@ -54,7 +56,7 @@ namespace OpenSim
private World LocalWorld;
private Grid GridServers;
private SimConfig Cfg;
private SimCAPSHTTPServer HttpServer;
private BaseHttpServer HttpServer;
private AssetCache AssetCache;
private InventoryCache InventoryCache;
//public Dictionary<EndPoint, SimClient> ClientThreads = new Dictionary<EndPoint, SimClient>();
@ -75,11 +77,10 @@ namespace OpenSim
public string m_physicsEngine;
public bool m_sandbox = false;
public bool m_loginserver;
public bool user_accounts = false;
protected ConsoleBase m_console;
public OpenSimMain( bool sandBoxMode, bool startLoginServer, string physicsEngine )
public OpenSimMain(bool sandBoxMode, bool startLoginServer, string physicsEngine)
{
m_sandbox = sandBoxMode;
m_loginserver = startLoginServer;
@ -92,7 +93,7 @@ namespace OpenSim
public virtual void StartUp()
{
GridServers = new Grid();
if ( m_sandbox )
if (m_sandbox)
{
GridServers.AssetDll = "OpenSim.GridInterfaces.Local.dll";
GridServers.GridDll = "OpenSim.GridInterfaces.Local.dll";
@ -134,34 +135,59 @@ namespace OpenSim
LocalWorld.PhysScene.SetTerrain(LocalWorld.LandMap);
GridServers.AssetServer.SetServerInfo(Cfg.AssetURL, Cfg.AssetSendKey);
GridServers.GridServer.SetServerInfo(Cfg.GridURL, Cfg.GridSendKey, Cfg.GridRecvKey);
IGridServer gridServer = GridServers.GridServer;
gridServer.SetServerInfo(Cfg.GridURL, Cfg.GridSendKey, Cfg.GridRecvKey);
LocalWorld.LoadStorageDLL("OpenSim.Storage.LocalStorageDb4o.dll"); //all these dll names shouldn't be hard coded.
LocalWorld.LoadPrimsFromStorage();
if ( m_sandbox)
if (m_sandbox)
{
AssetCache.LoadDefaultTextureSet();
}
m_console.WriteLine("Main.cs:Startup() - Starting CAPS HTTP server");
HttpServer = new SimCAPSHTTPServer(GridServers.GridServer, Cfg.IPListenPort);
LoginServer loginServer = null;
HttpServer = new BaseHttpServer( Cfg.IPListenPort );
if (gridServer.GetName() == "Remote")
{
HttpServer.AddXmlRPCHandler("expect_user",
delegate(XmlRpcRequest request)
{
Hashtable requestData = (Hashtable)request.Params[0];
AgentCircuitData agent_data = new AgentCircuitData();
agent_data.SessionID = new LLUUID((string)requestData["session_id"]);
agent_data.SecureSessionID = new LLUUID((string)requestData["secure_session_id"]);
agent_data.firstname = (string)requestData["firstname"];
agent_data.lastname = (string)requestData["lastname"];
agent_data.AgentID = new LLUUID((string)requestData["agent_id"]);
agent_data.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
((RemoteGridBase)gridServer).agentcircuits.Add((uint)agent_data.circuitcode, agent_data);
return new XmlRpcResponse();
});
}
HttpServer.AddRestHandler("Admin", new AdminWebFront("Admin", LocalWorld));
HttpServer.Start();
if (m_loginserver && m_sandbox)
{
loginServer = new LoginServer(GridServers.GridServer, Cfg.IPListenAddr, Cfg.IPListenPort, this.user_accounts);
LoginServer loginServer = new LoginServer(gridServer, Cfg.IPListenAddr, Cfg.IPListenPort);
loginServer.Startup();
}
if((m_loginserver) && (m_sandbox) && (user_accounts))
{
this.GridServers.UserServer = loginServer;
HttpServer.AddRestHandler("Admin", new AdminWebFront("Admin", LocalWorld, loginServer));
}
else
{
HttpServer.AddRestHandler("Admin", new AdminWebFront("Admin", LocalWorld, null));
if (loginServer.userAccounts)
{
// Actually, this is never tru as of now, but if it were, we'd do something like
HttpServer.AddXmlRPCHandler("login_to_simulator", loginServer.LocalUserManager.XmlRpcLoginMethod);
}
else
{
HttpServer.AddXmlRPCHandler("login_to_simulator", loginServer.XmlRpcLoginMethod);
}
}
MainServerListener();
@ -209,10 +235,10 @@ namespace OpenSim
packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
// This is either a new client or a packet to send to an old one
// if (OpenSimRoot.Instance.ClientThreads.ContainsKey(epSender))
// if (OpenSimRoot.Instance.ClientThreads.ContainsKey(epSender))
// do we already have a circuit for this endpoint
if(this.clientCircuits.ContainsKey(epSender))
if (this.clientCircuits.ContainsKey(epSender))
{
ClientThreads[this.clientCircuits[epSender]].InPacket(packet);
}
@ -221,11 +247,6 @@ namespace OpenSim
UseCircuitCodePacket useCircuit = (UseCircuitCodePacket)packet;
this.clientCircuits.Add(epSender, useCircuit.CircuitCode.Code);
SimClient newuser = new SimClient(epSender, useCircuit, LocalWorld, ClientThreads, AssetCache, GridServers.GridServer, this, InventoryCache, m_sandbox);
if ((this.GridServers.UserServer != null) && (user_accounts))
{
Console.WriteLine("setting userserver");
newuser.UserServer = this.GridServers.UserServer;
}
//OpenSimRoot.Instance.ClientThreads.Add(epSender, newuser);
ClientThreads.Add(useCircuit.CircuitCode.Code, newuser);
}
@ -256,11 +277,11 @@ namespace OpenSim
}
public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode )//EndPoint packetSender)
public virtual void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode)//EndPoint packetSender)
{
// find the endpoint for this circuit
EndPoint sendto = null;
foreach(KeyValuePair<EndPoint, uint> p in this.clientCircuits)
foreach (KeyValuePair<EndPoint, uint> p in this.clientCircuits)
{
if (p.Value == circuitcode)
{

View File

@ -10,7 +10,7 @@ using libsecondlife;
namespace OpenSim.UserServer
{
class LocalUserProfileManager : UserProfileManager
public class LocalUserProfileManager : UserProfileManager
{
private IGridServer m_gridServer;
private int m_port;

View File

@ -50,7 +50,7 @@ namespace OpenSim.UserServer
/// <summary>
/// When running in local (default) mode , handles client logins.
/// </summary>
public class LoginServer : LoginService , IUserServer
public class LoginServer : LoginService, IUserServer
{
private IGridServer m_gridServer;
private ushort _loginPort = 8080;
@ -59,19 +59,34 @@ namespace OpenSim.UserServer
private Socket loginServer;
private int NumClients;
private string _defaultResponse;
private bool userAccounts = false;
public bool userAccounts = false;
private string _mpasswd;
private bool _needPasswd = false;
private LocalUserProfileManager userManager;
private LocalUserProfileManager m_localUserManager;
private int m_simPort;
private string m_simAddr;
public LoginServer(IGridServer gridServer, string simAddr, int simPort , bool useAccounts)
public LocalUserProfileManager LocalUserManager
{
get
{
return m_localUserManager;
}
}
public LoginServer(IGridServer gridServer, string simAddr, int simPort)
{
m_gridServer = gridServer;
m_simPort = simPort;
m_simAddr = simAddr;
this.userAccounts = useAccounts;
}
public void Startup()
{
this.InitializeLogin();
//Thread runLoginProxy = new Thread(new ThreadStart(RunLogin));
//runLoginProxy.IsBackground = true;
//runLoginProxy.Start();
}
// InitializeLogin: initialize the login
@ -94,128 +109,132 @@ namespace OpenSim.UserServer
SR.Close();
this._mpasswd = EncodePassword("testpass");
userManager = new LocalUserProfileManager(this.m_gridServer, m_simPort, m_simAddr );
userManager.InitUserProfiles();
userManager.SetKeys("", "", "", "Welcome to OpenSim");
m_localUserManager = new LocalUserProfileManager(this.m_gridServer, m_simPort, m_simAddr);
m_localUserManager.InitUserProfiles();
m_localUserManager.SetKeys("", "", "", "Welcome to OpenSim");
loginServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
loginServer.Bind(new IPEndPoint(remoteAddress, _loginPort));
loginServer.Listen(1);
//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;
//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);
// 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);
}
// try
// {
// LoginRequest(networkReader, networkWriter);
// }
// catch (Exception e)
// {
// Console.WriteLine(e.Message);
// }
networkWriter.Close();
networkReader.Close();
networkStream.Close();
// networkWriter.Close();
// networkReader.Close();
// networkStream.Close();
client.Close();
// client.Close();
// send any packets queued for injection
// // send any packets queued for injection
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
}
// }
// }
// 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();
//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");
// // 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 != "");
// // 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);
// // 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);
}
}
}
}
// 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
// {
public bool ProcessXmlRequest(XmlRpcRequest request, StreamWriter writer)
// 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)
//{
// XmlRpcResponse response = XmlRpcLoginMethod(request);
// // 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();
// return true;
//}
public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
{
Hashtable requestData = (Hashtable)request.Params[0];
string first;
@ -224,6 +243,8 @@ namespace OpenSim.UserServer
LLUUID Agent;
LLUUID Session;
XmlRpcResponse response = new XmlRpcResponse();
//get login name
if (requestData.Contains("first"))
{
@ -254,99 +275,84 @@ 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;
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++;
//create a agent and session LLUUID
Agent = GetAgentId(first, last);
int SessionRand = Util.RandomClass.Next(1, 999);
Session = new LLUUID("aaaabbbb-0200-" + SessionRand.ToString("0000") + "-8664-58f53e442797");
LLUUID secureSess = LLUUID.Random();
//create some login info
Hashtable LoginFlagsHash = new Hashtable();
LoginFlagsHash["daylight_savings"] = "N";
LoginFlagsHash["stipend_since_login"] = "N";
LoginFlagsHash["gendered"] = "Y";
LoginFlagsHash["ever_logged_in"] = "Y";
ArrayList LoginFlags = new ArrayList();
LoginFlags.Add(LoginFlagsHash);
Hashtable GlobalT = new Hashtable();
GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271";
GlobalT["cloud_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
GlobalT["moon_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
ArrayList GlobalTextures = new ArrayList();
GlobalTextures.Add(GlobalT);
XmlRpcResponse 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["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
responseData["login-flags"] = LoginFlags;
responseData["global-textures"] = GlobalTextures;
//inventory
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"] = "Textures";
Inventory2["folder_id"] = BaseFolderID.ToStringHyphenated();
Inventory2["type_default"] = 0;
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);
Login _login = new Login();
//copy data to login object
_login.First = first;
_login.Last = last;
_login.Agent = Agent;
_login.Session = Session;
_login.SecureSession = secureSess;
_login.BaseFolder = BaseFolderID;
_login.InventoryFolder = InventoryFolderID;
//working on local computer if so lets add to the gridserver's list of sessions?
if (m_gridServer.GetName() == "Local")
else
{
((LocalGridBase)m_gridServer).AddNewSession(_login);
NumClients++;
//create a agent and session LLUUID
Agent = GetAgentId(first, last);
int SessionRand = Util.RandomClass.Next(1, 999);
Session = new LLUUID("aaaabbbb-0200-" + SessionRand.ToString("0000") + "-8664-58f53e442797");
LLUUID secureSess = LLUUID.Random();
//create some login info
Hashtable LoginFlagsHash = new Hashtable();
LoginFlagsHash["daylight_savings"] = "N";
LoginFlagsHash["stipend_since_login"] = "N";
LoginFlagsHash["gendered"] = "Y";
LoginFlagsHash["ever_logged_in"] = "Y";
ArrayList LoginFlags = new ArrayList();
LoginFlags.Add(LoginFlagsHash);
Hashtable GlobalT = new Hashtable();
GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271";
GlobalT["cloud_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
GlobalT["moon_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
ArrayList GlobalTextures = new ArrayList();
GlobalTextures.Add(GlobalT);
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["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
responseData["login-flags"] = LoginFlags;
responseData["global-textures"] = GlobalTextures;
//inventory
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"] = "Textures";
Inventory2["folder_id"] = BaseFolderID.ToStringHyphenated();
Inventory2["type_default"] = 0;
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);
Login _login = new Login();
//copy data to login object
_login.First = first;
_login.Last = last;
_login.Agent = Agent;
_login.Session = Session;
_login.SecureSession = secureSess;
_login.BaseFolder = BaseFolderID;
_login.InventoryFolder = InventoryFolderID;
//working on local computer if so lets add to the gridserver's list of sessions?
if (m_gridServer.GetName() == "Local")
{
((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();
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)
@ -396,32 +402,18 @@ namespace OpenSim.UserServer
return Regex.Replace(BitConverter.ToString(encodedBytes), "-", "").ToLower();
}
public bool CreateUserAccount(string firstName, string lastName, string password)
{
Console.WriteLine("creating new user account");
string mdPassword = EncodePassword(password);
Console.WriteLine("with password: " + mdPassword);
this.userManager.CreateNewProfile(firstName, lastName, mdPassword);
return true;
}
//IUserServer implementation
public AgentInventory RequestAgentsInventory(LLUUID agentID)
{
AgentInventory aInventory = null;
if (this.userAccounts)
{
aInventory = this.userManager.GetUsersInventory(agentID);
aInventory = this.m_localUserManager.GetUsersInventory(agentID);
}
return aInventory;
}
public bool UpdateAgentsInventory(LLUUID agentID, AgentInventory inventory)
{
return true;
}
public void SetServerInfo(string ServerUrl, string SendKey, string RecvKey)
{

View File

@ -54,3 +54,19 @@ nant - to generate new nant build scripts
Remember to run prebuild whenever you've added or removed files as well.
=== Local Set up of OGS config ===
**NOTE: At the moment OGS is non-functionable, so this won't work **NOTE
* start up bin/OpenGridServices.GridServer.exe (listens on http://localhost:8001/gridserver)
* just press enter to keep the defaults
* start up bin/OpenGridServices.UserServer.exe (listens on http://localhost:8002/userserver)
* just press enter to keep the defaults
* start up bin/OpenSim.exe ( listens for udp on port 9000 )
* just press enter to keep the defaults
* start the secondlife viewer with -loginuri http://localhost:8080/

View File

@ -1,10 +1,212 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Threading;
using OpenSim.CAPS;
using Nwc.XmlRpc;
using System.Collections;
namespace OpenSim.Servers
{
public class BaseHttpServer
{
protected Thread m_workerThread;
protected HttpListener m_httpListener;
protected Dictionary<string, IRestHandler> m_restHandlers = new Dictionary<string, IRestHandler>();
protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>();
protected int m_port;
public BaseHttpServer(int port)
{
m_port = port;
}
public bool AddRestHandler(string path, IRestHandler handler)
{
if (!this.m_restHandlers.ContainsKey(path))
{
this.m_restHandlers.Add(path, handler);
return true;
}
//must already have a handler for that path so return false
return false;
}
public bool AddXmlRPCHandler(string method, XmlRpcMethod handler)
{
if (!this.m_rpcHandlers.ContainsKey(method))
{
this.m_rpcHandlers.Add(method, handler);
return true;
}
//must already have a handler for that path so return false
return false;
}
protected virtual string ProcessXMLRPCMethod(string methodName, XmlRpcRequest request)
{
XmlRpcResponse response;
XmlRpcMethod method;
if( this.m_rpcHandlers.TryGetValue( methodName, out method ) )
{
response = method(request);
}
else
{
response = new XmlRpcResponse();
Hashtable unknownMethodError = new Hashtable();
unknownMethodError["reason"] = "XmlRequest"; ;
unknownMethodError["message"] = "Unknown Rpc request";
unknownMethodError["login"] = "false";
response.Value = unknownMethodError;
}
return XmlRpcResponseSerializer.Singleton.Serialize(response);
}
protected virtual string ParseREST(string requestBody, string requestURL, string requestMethod)
{
string[] path;
string pathDelimStr = "/";
char[] pathDelimiter = pathDelimStr.ToCharArray();
path = requestURL.Split(pathDelimiter);
string responseString = "";
//path[0] should be empty so we are interested in path[1]
if (path.Length > 1)
{
if ((path[1] != "") && (this.m_restHandlers.ContainsKey(path[1])))
{
responseString = this.m_restHandlers[path[1]].HandleREST(requestBody, requestURL, requestMethod);
}
}
return responseString;
}
protected virtual string ParseLLSDXML(string requestBody)
{
// dummy function for now - IMPLEMENT ME!
return "";
}
protected virtual string ParseXMLRPC(string requestBody)
{
string responseString = String.Empty;
try
{
XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
string methodName = request.MethodName;
responseString = ProcessXMLRPCMethod(methodName, request );
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
return responseString;
}
public virtual void HandleRequest(Object stateinfo)
{
// Console.WriteLine("new http incoming");
HttpListenerContext context = (HttpListenerContext)stateinfo;
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
response.KeepAlive = false;
response.SendChunked = false;
System.IO.Stream body = request.InputStream;
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
string requestBody = reader.ReadToEnd();
body.Close();
reader.Close();
//Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType);
//Console.WriteLine(requestBody);
string responseString = "";
switch (request.ContentType)
{
case "text/xml":
// must be XML-RPC, so pass to the XML-RPC parser
responseString = ParseXMLRPC(requestBody);
// If you wanna do voodoo like this, this is the place... but this example is rotten.
// (Regex.Replace(responseString, "utf-16", "utf-8"));
response.AddHeader("Content-type", "text/xml");
break;
case "application/xml":
// probably LLSD we hope, otherwise it should be ignored by the parser
responseString = ParseLLSDXML(requestBody);
response.AddHeader("Content-type", "application/xml");
break;
case "application/x-www-form-urlencoded":
// a form data POST so send to the REST parser
responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
response.AddHeader("Content-type", "text/html");
break;
case null:
// must be REST or invalid crap, so pass to the REST parser
responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
response.AddHeader("Content-type", "text/html");
break;
}
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
System.IO.Stream output = response.OutputStream;
response.SendChunked = false;
response.ContentLength64 = buffer.Length;
output.Write(buffer, 0, buffer.Length);
output.Close();
}
public void Start()
{
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting up HTTP Server");
m_workerThread = new Thread(new ThreadStart(StartHTTP));
m_workerThread.Start();
}
private void StartHTTP()
{
try
{
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("SimHttp.cs:StartHTTP() - Spawned main thread OK");
m_httpListener = new HttpListener();
m_httpListener.Prefixes.Add("http://+:" + m_port + "/");
m_httpListener.Start();
HttpListenerContext context;
while (true)
{
context = m_httpListener.GetContext();
ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context);
}
}
catch (Exception e)
{
OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.Message);
}
}
}
}

View File

@ -96,6 +96,8 @@
<Compile Include="BaseHttpServer.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="IRestHandler.cs" />
<Compile Include="XmlRpcMethod.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
<PropertyGroup>

7
Servers/XmlRpcMethod.cs Normal file
View File

@ -0,0 +1,7 @@
using System;
using Nwc.XmlRpc;
namespace OpenSim.Servers
{
public delegate XmlRpcResponse XmlRpcMethod( XmlRpcRequest request );
}