From 35472b36663fba7528358daa65e029d41ecde206 Mon Sep 17 00:00:00 2001
From: Brian McBee
Date: Sun, 25 Nov 2007 21:21:44 +0000
Subject: Added new configuration item to User Server: X and Y of region to
 send user to if their logon region is down. Known good region, sort of.

---
 OpenSim/Framework/UserConfig.cs                    |  12 ++
 OpenSim/Grid/UserServer/UserLoginService.cs        | 185 ++++++++++++++-------
 .../Region/ClientStack/ClientView.PacketQueue.cs   |   3 +-
 3 files changed, 138 insertions(+), 62 deletions(-)

diff --git a/OpenSim/Framework/UserConfig.cs b/OpenSim/Framework/UserConfig.cs
index fdb8f82..d4ee62f 100644
--- a/OpenSim/Framework/UserConfig.cs
+++ b/OpenSim/Framework/UserConfig.cs
@@ -42,6 +42,8 @@ namespace OpenSim.Framework
 
         public static uint DefaultHttpPort = 8002;
         public uint HttpPort = DefaultHttpPort;
+        public uint DefaultX = 1000;
+        public uint DefaultY = 1000;
 
         private ConfigurationMember configMember;
 
@@ -71,6 +73,10 @@ namespace OpenSim.Framework
 
             configMember.addConfigurationOption("http_port", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
                                                 "Http Listener port", DefaultHttpPort.ToString(), false);
+            configMember.addConfigurationOption("default_X", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
+                                                "Known good region X", "1000", false);
+            configMember.addConfigurationOption("default_Y", ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
+                                                "Known good region Y", "1000", false);
         }
 
         public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
@@ -95,6 +101,12 @@ namespace OpenSim.Framework
                 case "http_port":
                     HttpPort = (uint) configuration_result;
                     break;
+                case "default_X":
+                    DefaultX = (uint)configuration_result;
+                    break;
+                case "default_Y":
+                    DefaultY = (uint)configuration_result;
+                    break;
             }
 
             return true;
diff --git a/OpenSim/Grid/UserServer/UserLoginService.cs b/OpenSim/Grid/UserServer/UserLoginService.cs
index bbef4b2..0af5790 100644
--- a/OpenSim/Grid/UserServer/UserLoginService.cs
+++ b/OpenSim/Grid/UserServer/UserLoginService.cs
@@ -54,76 +54,139 @@ namespace OpenSim.Grid.UserServer
         /// <param name="theUser">The user profile</param>
         public override void CustomiseResponse(LoginResponse response, UserProfileData theUser)
         {
-            // Load information from the gridserver
+            bool tryDefault = false;
+            System.Console.WriteLine("Load information from the gridserver");
             RegionProfileData SimInfo = new RegionProfileData();
-            SimInfo =
-                SimInfo.RequestSimProfileData(theUser.currentAgent.currentHandle, m_config.GridServerURL,
-                                              m_config.GridSendKey, m_config.GridRecvKey);
-
-            // Customise the response
-            // Home Location
-            response.Home = "{'region_handle':[r" + (SimInfo.regionLocX*256).ToString() + ",r" +
-                            (SimInfo.regionLocY*256).ToString() + "], " +
-                            "'position':[r" + theUser.homeLocation.X.ToString() + ",r" +
-                            theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "], " +
-                            "'look_at':[r" + theUser.homeLocation.X.ToString() + ",r" +
-                            theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "]}";
-
-            // Destination
-            MainLog.Instance.Verbose("CUSTOMISERESPONSE: Region X: " + SimInfo.regionLocX + "; Region Y: " +
-                                     SimInfo.regionLocY);
-            response.SimAddress = Util.GetHostFromDNS(SimInfo.serverIP).ToString();
-            response.SimPort = (Int32) SimInfo.serverPort;
-            response.RegionX = SimInfo.regionLocX;
-            response.RegionY = SimInfo.regionLocY;
-
-            //Not sure if the + "/CAPS/" should in fact be +"CAPS/" depending if there is already a / as part of httpServerURI
-            string capsPath = Util.GetRandomCapsPath();
-            response.SeedCapability = SimInfo.httpServerURI + "CAPS/" + capsPath + "0000/";
-
-            // Notify the target of an incoming user
-            MainLog.Instance.Verbose("Notifying " + SimInfo.regionName + " (" + SimInfo.serverURI + ")");
-
-            // Prepare notification
-            Hashtable SimParams = new Hashtable();
-            SimParams["session_id"] = theUser.currentAgent.sessionID.ToString();
-            SimParams["secure_session_id"] = theUser.currentAgent.secureSessionID.ToString();
-            SimParams["firstname"] = theUser.username;
-            SimParams["lastname"] = theUser.surname;
-            SimParams["agent_id"] = theUser.UUID.ToString();
-            SimParams["circuit_code"] = (Int32) Convert.ToUInt32(response.CircuitCode);
-            SimParams["startpos_x"] = theUser.currentAgent.currentPos.X.ToString();
-            SimParams["startpos_y"] = theUser.currentAgent.currentPos.Y.ToString();
-            SimParams["startpos_z"] = theUser.currentAgent.currentPos.Z.ToString();
-            SimParams["regionhandle"] = theUser.currentAgent.currentHandle.ToString();
-            SimParams["caps_path"] = capsPath;
-            ArrayList SendParams = new ArrayList();
-            SendParams.Add(SimParams);
-
-            // Update agent with target sim
-            theUser.currentAgent.currentRegion = SimInfo.UUID;
-            theUser.currentAgent.currentHandle = SimInfo.regionHandle;
-
-            MainLog.Instance.Verbose("Informing region --> " + SimInfo.httpServerURI);
-            // Send
             try
             {
+                SimInfo =
+                    SimInfo.RequestSimProfileData(theUser.currentAgent.currentHandle, m_config.GridServerURL,
+                                                  m_config.GridSendKey, m_config.GridRecvKey);
+
+                // Customise the response
+                System.Console.WriteLine("Home Location");
+                response.Home = "{'region_handle':[r" + (SimInfo.regionLocX * 256).ToString() + ",r" +
+                                (SimInfo.regionLocY * 256).ToString() + "], " +
+                                "'position':[r" + theUser.homeLocation.X.ToString() + ",r" +
+                                theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "], " +
+                                "'look_at':[r" + theUser.homeLocation.X.ToString() + ",r" +
+                                theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "]}";
+
+                // Destination
+                MainLog.Instance.Verbose("CUSTOMISERESPONSE: Region X: " + SimInfo.regionLocX + "; Region Y: " +
+                                         SimInfo.regionLocY);
+                response.SimAddress = Util.GetHostFromDNS(SimInfo.serverIP).ToString();
+                response.SimPort = (Int32)SimInfo.serverPort;
+                response.RegionX = SimInfo.regionLocX;
+                response.RegionY = SimInfo.regionLocY;
+
+                //Not sure if the + "/CAPS/" should in fact be +"CAPS/" depending if there is already a / as part of httpServerURI
+                string capsPath = Util.GetRandomCapsPath();
+                response.SeedCapability = SimInfo.httpServerURI + "CAPS/" + capsPath + "0000/";
+
+                // Notify the target of an incoming user
+                MainLog.Instance.Verbose("Notifying " + SimInfo.regionName + " (" + SimInfo.serverURI + ")");
+
+                // Prepare notification
+                Hashtable SimParams = new Hashtable();
+                SimParams["session_id"] = theUser.currentAgent.sessionID.ToString();
+                SimParams["secure_session_id"] = theUser.currentAgent.secureSessionID.ToString();
+                SimParams["firstname"] = theUser.username;
+                SimParams["lastname"] = theUser.surname;
+                SimParams["agent_id"] = theUser.UUID.ToString();
+                SimParams["circuit_code"] = (Int32)Convert.ToUInt32(response.CircuitCode);
+                SimParams["startpos_x"] = theUser.currentAgent.currentPos.X.ToString();
+                SimParams["startpos_y"] = theUser.currentAgent.currentPos.Y.ToString();
+                SimParams["startpos_z"] = theUser.currentAgent.currentPos.Z.ToString();
+                SimParams["regionhandle"] = theUser.currentAgent.currentHandle.ToString();
+                SimParams["caps_path"] = capsPath;
+                ArrayList SendParams = new ArrayList();
+                SendParams.Add(SimParams);
+
+                // Update agent with target sim
+                theUser.currentAgent.currentRegion = SimInfo.UUID;
+                theUser.currentAgent.currentHandle = SimInfo.regionHandle;
+
+                MainLog.Instance.Verbose("Informing region --> " + SimInfo.httpServerURI);
+                // Send
+
                 XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams);
                 XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000);
             }
-            catch (WebException e)
+            catch (Exception e)
             {
-                switch (e.Status)
+                tryDefault = true;
+            }
+            if(tryDefault)
+            {
+                // Send him to default region instead
+                // Load information from the gridserver
+
+                ulong defaultHandle = (((ulong)m_config.DefaultX * 256) << 32) | ((ulong) m_config.DefaultY * 256);
+                MainLog.Instance.Warn("Home region not available: sending to default region " + defaultHandle.ToString());
+                SimInfo = new RegionProfileData();
+                try
                 {
-                    case WebExceptionStatus.Timeout:
-                        //TODO: Send him to nearby or default region instead
-                        MainLog.Instance.Verbose("Unable to connect to " + SimInfo.regionName + " (" + SimInfo.serverURI +
-                                                 ")");
-                        break;
-
-                    default:
-                        throw;
+                    SimInfo =
+                        SimInfo.RequestSimProfileData(defaultHandle, m_config.GridServerURL,
+                                                      m_config.GridSendKey, m_config.GridRecvKey);
+
+                    // Customise the response
+                    System.Console.WriteLine("Home Location");
+                    response.Home = "{'region_handle':[r" + (SimInfo.regionLocX * 256).ToString() + ",r" +
+                                    (SimInfo.regionLocY * 256).ToString() + "], " +
+                                    "'position':[r" + theUser.homeLocation.X.ToString() + ",r" +
+                                    theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "], " +
+                                    "'look_at':[r" + theUser.homeLocation.X.ToString() + ",r" +
+                                    theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "]}";
+
+                    // Destination
+                    MainLog.Instance.Verbose("CUSTOMISERESPONSE: Region X: " + SimInfo.regionLocX + "; Region Y: " +
+                                             SimInfo.regionLocY);
+                    response.SimAddress = Util.GetHostFromDNS(SimInfo.serverIP).ToString();
+                    response.SimPort = (Int32)SimInfo.serverPort;
+                    response.RegionX = SimInfo.regionLocX;
+                    response.RegionY = SimInfo.regionLocY;
+
+                    //Not sure if the + "/CAPS/" should in fact be +"CAPS/" depending if there is already a / as part of httpServerURI
+                    string capsPath = Util.GetRandomCapsPath();
+                    response.SeedCapability = SimInfo.httpServerURI + "CAPS/" + capsPath + "0000/";
+
+                    // Notify the target of an incoming user
+                    MainLog.Instance.Verbose("Notifying " + SimInfo.regionName + " (" + SimInfo.serverURI + ")");
+
+                    // Update agent with target sim
+                    theUser.currentAgent.currentRegion = SimInfo.UUID;
+                    theUser.currentAgent.currentHandle = SimInfo.regionHandle;
+
+                    // Prepare notification
+                    Hashtable SimParams = new Hashtable();
+                    SimParams["session_id"] = theUser.currentAgent.sessionID.ToString();
+                    SimParams["secure_session_id"] = theUser.currentAgent.secureSessionID.ToString();
+                    SimParams["firstname"] = theUser.username;
+                    SimParams["lastname"] = theUser.surname;
+                    SimParams["agent_id"] = theUser.UUID.ToString();
+                    SimParams["circuit_code"] = (Int32)Convert.ToUInt32(response.CircuitCode);
+                    SimParams["startpos_x"] = theUser.currentAgent.currentPos.X.ToString();
+                    SimParams["startpos_y"] = theUser.currentAgent.currentPos.Y.ToString();
+                    SimParams["startpos_z"] = theUser.currentAgent.currentPos.Z.ToString();
+                    SimParams["regionhandle"] = theUser.currentAgent.currentHandle.ToString();
+                    SimParams["caps_path"] = capsPath;
+                    ArrayList SendParams = new ArrayList();
+                    SendParams.Add(SimParams);
+
+                    MainLog.Instance.Verbose("Informing region --> " + SimInfo.httpServerURI);
+                    // Send
+                    XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams);
+                    XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000);
                 }
+
+                catch (Exception e)
+                {
+                    MainLog.Instance.Warn("Default region also not available");
+                    MainLog.Instance.Verbose(e.ToString());
+                }
+
             }
         }
     }
diff --git a/OpenSim/Region/ClientStack/ClientView.PacketQueue.cs b/OpenSim/Region/ClientStack/ClientView.PacketQueue.cs
index 1904bfa..4ca7bd9 100644
--- a/OpenSim/Region/ClientStack/ClientView.PacketQueue.cs
+++ b/OpenSim/Region/ClientStack/ClientView.PacketQueue.cs
@@ -166,11 +166,12 @@ namespace OpenSim.Region.ClientStack
                     //userEP);
                 }
             }
-            catch (Exception)
+            catch (Exception e)
             {
                 MainLog.Instance.Warn("client",
                                       "ClientView.PacketQueue.cs:ProcessOutPacket() - WARNING: Socket exception occurred on connection " +
                                       userEP.ToString() + " - killing thread");
+                MainLog.Instance.Error(e.ToString());
                 KillThread();
             }
         }
-- 
cgit v1.1