View of /trunk/GridServer/OpenSimGridComm.cs
Parent Directory
|
Revision Log
Revision 65 -
(download)
(annotate)
Fri Jan 9 02:24:28 2009 UTC (4 years, 4 months ago) by jhurliman
File size: 13261 byte(s)
Fri Jan 9 02:24:28 2009 UTC (4 years, 4 months ago) by jhurliman
File size: 13261 byte(s)
Replaced UserServer project with GridServer * Broke inventory classes in AssetServer out into a separate source file * Updated HttpServer.dll to a new version that supports IHttpRequest.RemoteEndPoint
/*
* Copyright (c) 2008 Intel Corporation
* 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 Intel Corporation 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``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 THE INTEL OR ITS
* CONTRIBUTORS 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.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
using Nwc.XmlRpc;
using OpenMetaverse;
namespace GridServer
{
public class RegionProfileData
{
public string RegionName;
public UUID ID;
public uint LocationX;
public uint LocationY;
public ulong Handle;
public string ServerIP;
public uint ServerPort;
public uint HttpPort;
public uint RemotingPort;
public string ServerURI;
public string HttpServerURI;
}
public static class OpenSimGridComm
{
/// <summary>
/// Request sim data based on arbitrary key/value
/// </summary>
private static RegionProfileData RequestSimData(Uri gridServer, string sendkey, string keyField, string keyValue)
{
RegionProfileData simData = null;
Hashtable requestData = new Hashtable();
requestData[keyField] = keyValue;
requestData["authkey"] = sendkey;
ArrayList sendParams = new ArrayList();
sendParams.Add(requestData);
try
{
XmlRpcRequest gridRequest = new XmlRpcRequest("simulator_data_request", sendParams);
XmlRpcResponse gridResponse = gridRequest.Send(gridServer.ToString(), 3000);
Hashtable responseData = gridResponse.Value as Hashtable;
if (!responseData.ContainsKey("error"))
{
simData = new RegionProfileData();
simData.LocationX = Convert.ToUInt32((string)responseData["region_locx"]);
simData.LocationY = Convert.ToUInt32((string)responseData["region_locy"]);
simData.Handle = Utils.UIntsToLong(simData.LocationX * 256, simData.LocationY * 256);
simData.ServerIP = (string)responseData["sim_ip"];
simData.ServerPort = Convert.ToUInt32((string)responseData["sim_port"]);
simData.HttpPort = Convert.ToUInt32((string)responseData["http_port"]);
simData.RemotingPort = Convert.ToUInt32((string)responseData["remoting_port"]);
simData.ServerURI = (string)responseData["server_uri"];
simData.HttpServerURI = String.Format("http://{0}:{1}/", simData.ServerIP, simData.HttpPort);
simData.ID = new UUID((string)responseData["region_UUID"]);
simData.RegionName = (string)responseData["region_name"];
}
}
catch (Exception ex)
{
Logger.Log.ErrorFormat("simulator_data_request to {0} with key {1} and value {2} failed: {3}",
gridServer, keyField, keyValue, ex.Message);
return null;
}
return simData;
}
/// <summary>
/// Request sim profile information from a grid server by region UUID
/// </summary>
public static RegionProfileData RequestSimProfileData(UUID region_uuid, Uri gridserver_url,
string gridserver_sendkey, string gridserver_recvkey)
{
return RequestSimData(gridserver_url, gridserver_sendkey, "region_UUID", region_uuid.Guid.ToString());
}
/// <summary>
/// Request sim profile information from a grid server by region handle
/// </summary>
public static RegionProfileData RequestSimProfileData(ulong region_handle, Uri gridserver_url,
string gridserver_sendkey, string gridserver_recvkey)
{
return RequestSimData(gridserver_url, gridserver_sendkey, "region_handle", region_handle.ToString());
}
/// <summary>
/// Request sim profile information from a grid server by region location
/// </summary>
public static RegionProfileData RequestSimProfileData(uint regionX, uint regionY, Uri gridserver_url,
string gridserver_sendkey, string gridserver_recvkey)
{
ulong handle = Utils.UIntsToLong(regionX * 256, regionY * 256);
return RequestSimData(gridserver_url, gridserver_sendkey, "region_handle", handle.ToString());
}
/// <summary>
/// Request sim profile information from a grid server by region name
/// </summary>
public static RegionProfileData RequestSimProfileData(string regionName, Uri gridserver_url,
string gridserver_sendkey, string gridserver_recvkey)
{
return RequestSimData(gridserver_url, gridserver_sendkey, "region_name_search", regionName);
}
/// <summary>
/// Notify a simulator of a new avatar logging in
/// </summary>
public static bool NotifySimulatorOfLogin(RegionProfileData regionInfo, UUID sessionID, UUID secureSessionID,
string firstName, string lastName, UUID agentID, int circuitCode, Vector3 position, string capsPath)
{
Logger.Log.InfoFormat("Notifying {0} @ {1},{2} ({3} to prepare for client connection",
regionInfo.RegionName, regionInfo.LocationX, regionInfo.LocationY, regionInfo.HttpServerURI);
// Prepare notification
Hashtable loginParams = new Hashtable();
loginParams["session_id"] = sessionID.ToString();
loginParams["secure_session_id"] = secureSessionID.ToString();
loginParams["firstname"] = firstName;
loginParams["lastname"] = lastName;
loginParams["agent_id"] = agentID.ToString();
loginParams["circuit_code"] = circuitCode;
loginParams["startpos_x"] = position.X.ToString();
loginParams["startpos_y"] = position.Y.ToString();
loginParams["startpos_z"] = position.Z.ToString();
loginParams["regionhandle"] = regionInfo.Handle.ToString();
loginParams["caps_path"] = capsPath;
ArrayList SendParams = new ArrayList();
SendParams.Add(loginParams);
// Send
XmlRpcRequest gridRequest = new XmlRpcRequest("expect_user", SendParams);
XmlRpcResponse gridResponse = gridRequest.Send(regionInfo.HttpServerURI, 6000);
if (!gridResponse.IsFault)
{
if (gridResponse.Value != null)
{
Hashtable response = (Hashtable)gridResponse.Value;
if (response.ContainsKey("success") && (string)response["success"] == "TRUE")
return true;
}
}
return false;
}
public static bool CreateInventory(Uri inventoryServer, UUID avatarID)
{
Uri method = new Uri(inventoryServer, "CreateInventory/");
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(method);
request.Method = "POST";
SerializeUUID(request.GetRequestStream(), avatarID);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
return DeserializeBoolean(new XmlTextReader(response.GetResponseStream()));
}
catch (WebException ex)
{
Logger.Log.ErrorFormat("Call to {0} failed: {1}", method, ex.Message);
return false;
}
}
public static List<InventoryItem> GetActiveGestures(Uri inventoryServer, UUID avatarID)
{
Uri method = new Uri(inventoryServer, "ActiveGestures/");
// FIXME:
return new List<InventoryItem>();
}
public static List<InventoryFolder> GetInventoryFolders(Uri inventoryServer, UUID avatarID)
{
Uri method = new Uri(inventoryServer, "RootFolders/");
// FIXME:
return new List<InventoryFolder>();
}
/*public static UUID ReadUUID(XmlReader reader, string name)
{
UUID value;
reader.ReadStartElement(name);
UUID.TryParse(reader.ReadElementContentAsString("Guid", String.Empty), out value);
reader.ReadEndElement();
return value;
}*/
public static bool DeserializeBoolean(XmlReader reader)
{
bool value;
reader.MoveToContent();
value = reader.ReadElementContentAsBoolean("boolean", String.Empty);
return value;
}
public static void SerializeUUID(Stream stream, UUID value)
{
using (XmlWriter writer = XmlWriter.Create(stream))
{
writer.WriteStartDocument();
writer.WriteStartElement("guid");
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
writer.WriteString(value.ToString());
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
}
stream.Flush();
stream.Close();
}
public static void SerializeBool(Stream stream, bool value)
{
using (XmlWriter writer = XmlWriter.Create(stream))
{
writer.WriteStartDocument();
writer.WriteStartElement("boolean");
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
writer.WriteString(value.ToString().ToLower());
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
}
stream.Flush();
stream.Close();
}
public static IPAddress GetIPFromURL(string url)
{
string[] urlSplit = url.Split(new char[] { '/', ':' });
if (urlSplit.Length >= 4)
{
return GetIPFromHostname(urlSplit[3]);
}
else
{
Logger.Log.Error("Failed to parse hostname from URL " + url);
return null;
}
}
public static IPAddress GetIPFromHostname(string dnsAddress)
{
// Is it already a valid IP? No need to look it up.
IPAddress ipa;
if (IPAddress.TryParse(dnsAddress, out ipa))
return ipa;
IPAddress[] hosts = null;
// Not an IP, lookup required
try { hosts = Dns.GetHostEntry(dnsAddress).AddressList; }
catch (Exception ex)
{
Logger.Log.ErrorFormat("Failed to resolve hostname {0}: {1}", dnsAddress, ex.Message);
return null;
}
foreach (IPAddress host in hosts)
{
if (host.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
return host;
}
if (hosts.Length > 0)
return hosts[0];
else
return null;
}
}
}
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

