From 279e0061c515ee0a03036bef68eea9738273d785 Mon Sep 17 00:00:00 2001
From: Johan Berntsson
Date: Tue, 4 Mar 2008 05:31:54 +0000
Subject: Merged 3Di code that provides scene and avatar serialization, and
 plugin support for region move/split/merge. See ThirdParty/3Di/README.txt.
 Unless the new modules are used there should be no noticeable changes when
 running OpenSim.

---
 OpenSim/Grid/GridServer/GridManager.cs      | 76 +++++++++++++++++++++++++++--
 OpenSim/Grid/GridServer/Main.cs             |  1 +
 OpenSim/Grid/UserServer/UserLoginService.cs |  8 +--
 3 files changed, 77 insertions(+), 8 deletions(-)

(limited to 'OpenSim/Grid')

diff --git a/OpenSim/Grid/GridServer/GridManager.cs b/OpenSim/Grid/GridServer/GridManager.cs
index e32f551..2e6a892 100644
--- a/OpenSim/Grid/GridServer/GridManager.cs
+++ b/OpenSim/Grid/GridServer/GridManager.cs
@@ -37,6 +37,7 @@ using OpenSim.Framework;
 using OpenSim.Framework.Console;
 using OpenSim.Framework.Data;
 using OpenSim.Framework.Servers;
+using OpenSim.Framework.Data.MySQL;
 
 namespace OpenSim.Grid.GridServer
 {
@@ -301,16 +302,20 @@ namespace OpenSim.Grid.GridServer
             catch (KeyNotFoundException) { }
 
             TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * Constants.RegionSize), (TheSim.regionLocY * Constants.RegionSize));
-            TheSim.serverURI = "http://" + TheSim.serverIP + ":" + TheSim.serverPort + "/";
+			TheSim.serverURI = (string)requestData["server_uri"];
+			Console.WriteLine("adding region " + TheSim.regionLocX + " , " + TheSim.regionLocY + " , " +
+                              TheSim.serverURI);
 
             TheSim.httpServerURI = "http://" + TheSim.serverIP + ":" + TheSim.httpPort + "/";
 
             TheSim.regionName = (string)requestData["sim_name"];
             TheSim.UUID = new LLUUID((string)requestData["UUID"]);
+            TheSim.originUUID = new LLUUID((string) requestData["originUUID"]);
 
             //make sure there is not an existing region at this location
             OldSim = getRegion(TheSim.regionHandle);
-            if (OldSim == null || OldSim.UUID == TheSim.UUID)
+            //if (OldSim == null || OldSim.UUID == TheSim.UUID)
+            if (OldSim == null || OldSim.UUID == TheSim.UUID || TheSim.UUID != TheSim.originUUID)
             {
                 bool brandNew = ( OldSim == null && TheSim.regionRecvKey == config.SimSendKey &&
                                  TheSim.regionSendKey == config.SimRecvKey);
@@ -502,6 +507,69 @@ namespace OpenSim.Grid.GridServer
 
         /// <summary>
         /// Returns an XML RPC response to a simulator profile request
+        /// Performed after moving a region.
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        /// <param name="request">The XMLRPC Request</param>
+        /// <returns>Processing parameters</returns>
+        public XmlRpcResponse XmlRpcDeleteRegionMethod(XmlRpcRequest request)
+        {
+            XmlRpcResponse response = new XmlRpcResponse();
+            Hashtable responseData = new Hashtable();
+            response.Value = responseData;
+
+            //RegionProfileData TheSim = null;
+            string uuid = String.Empty;;
+            Hashtable requestData = (Hashtable) request.Params[0];
+            string myword;
+            if (requestData.ContainsKey("UUID")) {
+                //TheSim = getRegion(new LLUUID((string) requestData["UUID"]));
+                uuid = requestData["UUID"].ToString();
+				Console.WriteLine("deleting region " + uuid);
+//                logToDB((new LLUUID((string)requestData["UUID"])).ToString(),"XmlRpcDeleteRegionMethod","", 5,"Attempting delete with UUID.");
+            }
+            else {
+                responseData["error"] = "No UUID or region_handle passed to grid server - unable to delete";
+                return response;
+            }
+
+            foreach (KeyValuePair<string, IGridData> kvp in _plugins) {
+            //OpenSim.Framework.Data.MySQL.MySQLGridData dbengine = new OpenSim.Framework.Data.MySQL.MySQLGridData();
+                try {
+					OpenSim.Framework.Data.MySQL.MySQLGridData mysqldata = (OpenSim.Framework.Data.MySQL.MySQLGridData)(kvp.Value);
+					//DataResponse insertResponse = mysqldata.DeleteProfile(TheSim);
+					DataResponse insertResponse = mysqldata.DeleteProfile(uuid);
+                    switch (insertResponse) {
+                        case DataResponse.RESPONSE_OK:
+                            //MainLog.Instance.Verbose("grid", "Deleting region successful: " + uuid);
+                            responseData["status"] = "Deleting region successful: " + uuid;
+                            break;
+                        case DataResponse.RESPONSE_ERROR:
+                            //MainLog.Instance.Warn("storage", "Deleting region failed (Error): " + uuid);
+                            responseData["status"] = "Deleting region failed (Error): " + uuid;
+                            break;
+                        case DataResponse.RESPONSE_INVALIDCREDENTIALS:
+                            //MainLog.Instance.Warn("storage", "Deleting region failed (Invalid Credentials): " + uuid);
+                            responseData["status"] = "Deleting region (Invalid Credentials): " + uuid;
+                            break;
+                        case DataResponse.RESPONSE_AUTHREQUIRED:
+                            //MainLog.Instance.Warn("storage", "Deleting region failed (Authentication Required): " + uuid);
+                            responseData["status"] = "Deleting region (Authentication Required): " + uuid;
+                            break;
+                    }
+                }
+                catch (Exception e) {
+                    m_log.Error("storage Unable to delete region " + uuid + " via MySQL");
+                    //MainLog.Instance.Warn("storage", e.ToString());
+                }
+            }
+
+            return response;
+        }
+
+        /// <summary>
+        /// Returns an XML RPC response to a simulator profile request
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
@@ -533,6 +601,7 @@ namespace OpenSim.Grid.GridServer
                                                  (string) requestData["region_handle"]);
                 responseData["sim_ip"] = Util.GetHostFromDNS(simData.serverIP).ToString();
                 responseData["sim_port"] = simData.serverPort.ToString();
+				responseData["server_uri"] = simData.serverURI;
                 responseData["http_port"] = simData.httpPort.ToString();
                 responseData["remoting_port"] = simData.remotingPort.ToString();
                 responseData["region_locx"] = simData.regionLocX.ToString();
@@ -798,8 +867,7 @@ namespace OpenSim.Grid.GridServer
                 }
             }
 
-            TheSim.serverURI = "http://" + TheSim.serverIP + ":" + TheSim.serverPort + "/";
-
+			TheSim.serverURI = "http://" + TheSim.serverIP + ":" + TheSim.serverPort + "/";
             bool requirePublic = false;
             bool requireValid = true;
 
diff --git a/OpenSim/Grid/GridServer/Main.cs b/OpenSim/Grid/GridServer/Main.cs
index ff4a888..ff4cfa2 100644
--- a/OpenSim/Grid/GridServer/Main.cs
+++ b/OpenSim/Grid/GridServer/Main.cs
@@ -113,6 +113,7 @@ namespace OpenSim.Grid.GridServer
 
             httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcSimulatorLoginMethod);
             httpServer.AddXmlRPCHandler("simulator_data_request", m_gridManager.XmlRpcSimulatorDataRequestMethod);
+            httpServer.AddXmlRPCHandler("simulator_after_region_moved", m_gridManager.XmlRpcDeleteRegionMethod);
             httpServer.AddXmlRPCHandler("map_block", m_gridManager.XmlRpcMapBlockMethod);
 
             // Message Server ---> Grid Server
diff --git a/OpenSim/Grid/UserServer/UserLoginService.cs b/OpenSim/Grid/UserServer/UserLoginService.cs
index 0b832f4..e03ac3a 100644
--- a/OpenSim/Grid/UserServer/UserLoginService.cs
+++ b/OpenSim/Grid/UserServer/UserLoginService.cs
@@ -99,8 +99,8 @@ namespace OpenSim.Grid.UserServer
                 //CFK: the next one for X & Y and comment this one.
                 //CFK: m_log.Info("[LOGIN]: CUSTOMISERESPONSE: Region X: " + SimInfo.regionLocX + 
                 //CFK: "; Region Y: " + SimInfo.regionLocY);
-                response.SimAddress = Util.GetHostFromDNS(SimInfo.serverIP).ToString();
-                response.SimPort = (uint) SimInfo.serverPort;
+                response.SimAddress = Util.GetHostFromDNS(SimInfo.serverURI.Split(new char[] { '/', ':' })[3]).ToString();
+                response.SimPort = uint.Parse(SimInfo.serverURI.Split(new char[] { '/', ':' })[4]);
                 response.RegionX = SimInfo.regionLocX;
                 response.RegionY = SimInfo.regionLocY;
 
@@ -190,8 +190,8 @@ namespace OpenSim.Grid.UserServer
                     m_log.Info("[LOGIN]: " +
                                "CUSTOMISERESPONSE: Region X: " + SimInfo.regionLocX + "; Region Y: " +
                                SimInfo.regionLocY);
-                    response.SimAddress = Util.GetHostFromDNS(SimInfo.serverIP).ToString();
-                    response.SimPort = (uint) SimInfo.serverPort;
+                    response.SimAddress = Util.GetHostFromDNS(SimInfo.serverURI.Split(new char[] { '/', ':' })[3]).ToString();
+                    response.SimPort = uint.Parse(SimInfo.serverURI.Split(new char[] { '/', ':' })[4]);
                     response.RegionX = SimInfo.regionLocX;
                     response.RegionY = SimInfo.regionLocY;
 
-- 
cgit v1.1