aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/RegionProfileService.cs
blob: 0cd40212b2211f35f581b989243d89ea2b1d421e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Nwc.XmlRpc;
using OpenMetaverse;
using OpenSim.Framework;

namespace OpenSim.Data
{
    public class RegionProfileService
    {
        /// <summary>
        /// Request sim data based on arbitrary key/value
        /// </summary>
        private RegionProfileData RequestSimData(Uri gridserverUrl, string gridserverSendkey, string keyField, string keyValue)
        {
            Hashtable requestData = new Hashtable();
            requestData[keyField] = keyValue;
            requestData["authkey"] = gridserverSendkey;
            ArrayList SendParams = new ArrayList();
            SendParams.Add(requestData);
            XmlRpcRequest GridReq = new XmlRpcRequest("simulator_data_request", SendParams);
            XmlRpcResponse GridResp = GridReq.Send(gridserverUrl.ToString(), 3000);

            Hashtable responseData = (Hashtable) GridResp.Value;

            RegionProfileData simData = null;

            if (!responseData.ContainsKey("error"))
            {
                simData = new RegionProfileData();
                simData.regionLocX = Convert.ToUInt32((string) responseData["region_locx"]);
                simData.regionLocY = Convert.ToUInt32((string) responseData["region_locy"]);
                simData.regionHandle =
                    Utils.UIntsToLong((simData.regionLocX * Constants.RegionSize),
                                      (simData.regionLocY*Constants.RegionSize));
                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 = "http://" + (string)responseData["sim_ip"] + ":" + simData.httpPort.ToString() + "/";
                simData.UUID = new UUID((string) responseData["region_UUID"]);
                simData.regionName = (string) responseData["region_name"];
            }

            return simData;
        }

        /// <summary>
        /// Request sim profile information from a grid server, by Region UUID
        /// </summary>
        /// <param name="regionId">The region UUID to look for</param>
        /// <param name="gridserverUrl"></param>
        /// <param name="gridserverSendkey"></param>
        /// <param name="gridserverRecvkey"></param>
        /// <returns>The sim profile.  Null if there was a request failure</returns>
        /// <remarks>This method should be statics</remarks>
        public RegionProfileData RequestSimProfileData(UUID regionId, Uri gridserverUrl,
                                                              string gridserverSendkey, string gridserverRecvkey)
        {
            return RequestSimData(gridserverUrl, gridserverSendkey, "region_UUID", regionId.Guid.ToString());
        }

        /// <summary>
        /// Request sim profile information from a grid server, by Region Handle
        /// </summary>
        /// <param name="region_handle">the region handle to look for</param>
        /// <param name="gridserver_url"></param>
        /// <param name="gridserver_sendkey"></param>
        /// <param name="gridserver_recvkey"></param>
        /// <returns>The sim profile.  Null if there was a request failure</returns>
        public 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 Name
        /// </summary>
        /// <param name="regionName">the region name to look for</param>
        /// <param name="gridserverUrl"></param>
        /// <param name="gridserverSendkey"></param>
        /// <param name="gridserverRecvkey"></param>
        /// <returns>The sim profile.  Null if there was a request failure</returns>
        public RegionProfileData RequestSimProfileData(string regionName, Uri gridserverUrl,
                                                              string gridserverSendkey, string gridserverRecvkey)
        {
            return RequestSimData(gridserverUrl, gridserverSendkey, "region_name_search", regionName );
        }
    }
}