Beispiel #1
0
        /// <summary>
        /// Load an OAR file into a region..
        /// <summary>
        /// <param name="request">incoming XML RPC request</param>
        /// <remarks>
        /// XmlRpcLoadOARMethod takes the following XMLRPC parameters
        /// <list type="table">
        /// <listheader><term>parameter name</term><description>description</description></listheader>
        /// <item><term>session</term>
        ///       <description>An authenticated session ID</description></item>
        /// <item><term>region_name</term>
        ///       <description>Name of the region</description></item>
        /// <item><term>filename</term>
        ///       <description>file name of the OAR file</description></item>
        /// </list>
        ///
        /// Returns
        /// <list type="table">
        /// <listheader><term>name</term><description>description</description></listheader>
        /// <item><term>success</term>
        ///       <description>true or false</description></item>
        /// </list>
        /// </remarks>
        public object RegionRestoreHandler(IList args, IPEndPoint remoteClient)
        {
            m_admin.CheckSessionValid(new UUID((string)args[0]));

            Scene scene;

            if (!m_app.SceneManager.TryGetScene((string)args[1], out scene))
            {
                throw new Exception("region not found");
            }

            String filename = (string)args[2];
            bool   allowUserReassignment = Convert.ToBoolean(args[3]);
            bool   skipErrorGroups       = Convert.ToBoolean(args[4]);

            m_log.Info("[RADMIN]: Received Region Restore Administrator Request");

            lock (rslock)
            {
                try
                {
                    IRegionArchiverModule archiver = scene.RequestModuleInterface <IRegionArchiverModule>();
                    if (archiver != null)
                    {
                        archiver.DearchiveRegion(filename, allowUserReassignment, skipErrorGroups);
                    }
                    else
                    {
                        throw new Exception("Archiver module not present for scene");
                    }

                    m_log.Info("[RADMIN]: Load OAR Administrator Request complete");
                    return(true);
                }
                catch (Exception e)
                {
                    m_log.InfoFormat("[RADMIN] LoadOAR: {0}", e.Message);
                    m_log.DebugFormat("[RADMIN] LoadOAR: {0}", e.ToString());
                }

                return(false);
            }
        }
Beispiel #2
0
 void OnChat(Object sender, OSChatMessage chat)
 {
     if ((chat.Channel != m_listenChannel) || (m_resetRequested))
     {
         return;
     }
     else if (chat.Message.ToLower() == "kill")
     {
         //Immediately stop accepting commands from the simulation
         m_resetRequested = true;
         m_dialogmod.SendGeneralAlert("Manager Module: Deleting all objects and resetting module.  Please be patient...");
         //Remove all objects, clear the list of recyclables and reset the population size limit.
         m_scene.DeleteAllSceneObjects();
         m_overLimit   = false;
         m_recyclables = new Queue <ScriptAndHostPair>();
         if (m_dialogmod != null)
         {
             m_dialogmod.SendGeneralAlert("Manager Module: Cleared old population.  Reloading region with default objects...");
         }
         //Start accepting commands from the simulation again
         m_resetRequested = false;
         //Reload content from the default oar file
         try
         {
             IRegionArchiverModule archivermod = m_scene.RequestModuleInterface <IRegionArchiverModule>();
             if (archivermod != null)
             {
                 string oarFilePath = System.IO.Path.Combine(m_oarPath, "vpgsim_default_content.oar");
                 archivermod.DearchiveRegion(oarFilePath);
                 m_dialogmod.SendGeneralAlert("Manager Module: Loaded default objects...");
             }
         }
         catch
         {
             m_dialogmod.SendGeneralAlert("Manager Module: Couldn't load default objects!");
             m_log.WarnFormat("[vpgManager] Couldn't load default objects...");
         }
     }
     else if (chat.Message.Length > 9)
     {
         if (chat.Message.Substring(0, 3).ToLower() == "oar")
         {
             IRegionArchiverModule archivermod = m_scene.RequestModuleInterface <IRegionArchiverModule>();
             if (chat.Message.Substring(3, 5).ToLower() == "-load")
             {
                 //Load the specified oar file
                 if (archivermod != null)
                 {
                     //Immediately stop accepting commands from the simulation
                     m_resetRequested = true;
                     m_dialogmod.SendGeneralAlert("Manager Module: Loading archive file.  Please be patient...");
                     //Remove all objects from the scene.  The Archiver Module does this anyway,
                     //but we need to be able to reset the list of recyclables after the scene
                     //objects are deleted but before the new objects start to load, so the module
                     //is ready to receive registration requests from recyclables in the oar.
                     m_scene.DeleteAllSceneObjects();
                     m_overLimit   = false;
                     m_recyclables = new Queue <ScriptAndHostPair>();
                     //Start accepting commands from the simulation again
                     m_resetRequested = false;
                     try
                     {
                         string oarFilePath = System.IO.Path.Combine(m_oarPath, chat.Message.Substring(9));
                         archivermod.DearchiveRegion(oarFilePath);
                         m_dialogmod.SendGeneralAlert("Manager Module: Loaded archive file...");
                     }
                     catch
                     {
                         m_dialogmod.SendGeneralAlert("Manager Module: Couldn't load archive file!");
                         m_log.WarnFormat("[vpgManager] Couldn't load archive file...");
                     }
                 }
             }
             else if (chat.Message.Substring(3, 5).ToLower() == "-save")
             {
                 //Save the specified oar file
                 if (archivermod != null)
                 {
                     m_dialogmod.SendGeneralAlert("Manager Module: Saving archive file.  Please be patient...");
                     try
                     {
                         string oarFilePath = System.IO.Path.Combine(m_oarPath, chat.Message.Substring(9));
                         archivermod.ArchiveRegion(oarFilePath, new Dictionary <string, object>());
                         if (m_dialogmod != null)
                         {
                             m_dialogmod.SendGeneralAlert("Manager Module: Saved archive file...");
                         }
                     }
                     catch
                     {
                         m_dialogmod.SendGeneralAlert("Manager Module: Couldn't save archive file!");
                         m_log.WarnFormat("[vpgManager] Couldn't save archive file..");
                     }
                 }
             }
         }
         else
         {
             //Try to parse the string as a new plant generation command
             string[] parsedMessage = chat.Message.Split(',');
             if (parsedMessage.Length != 7)
             {
                 //Invalid message string
                 m_log.WarnFormat("[vpgManager] Invalid new plant generation string...");
                 m_dialogmod.SendGeneralAlert("Manager Module: Invalid command - wrong number of arguments.  No new plants generated...");
             }
             else
             {
                 m_dialogmod.SendGeneralAlert("Manager Module: Processing request.  Please be patient...");
                 string geneticInfo    = parsedMessage[0];
                 int    xMin           = int.Parse(parsedMessage[1]);
                 int    xMax           = int.Parse(parsedMessage[2]);
                 int    yMin           = int.Parse(parsedMessage[3]);
                 int    yMax           = int.Parse(parsedMessage[4]);
                 int    quantity       = int.Parse(parsedMessage[5]);
                 int    strictQuantity = int.Parse(parsedMessage[6]);
                 bool   errorStatus    = false;
                 int    failureCount   = 0;
                 int    successCount   = 0;
                 //The webform already checks these same things before creating the input string, but check them again in case the user manually edits the input string
                 if ((xMin < 0) || (xMin > 256) || (xMax < 0) || (xMax > 256) || (yMin < 0) || (yMin > 256) || (yMax < 0) || (yMax > 256) || (xMin >= xMax) || (yMin >= yMax) || (quantity <= 0) || (quantity > 500) || !((geneticInfo.Length == 5) || (geneticInfo.Length == 10)))
                 {
                     m_dialogmod.SendGeneralAlert("Manager Module: Invalid command string.");
                     errorStatus = true;
                 }
                 while ((quantity > 0) && (!errorStatus) && (failureCount < m_maxFailures))
                 {
                     int     randomGenotype = GenerateGenotype(geneticInfo);
                     Vector3 randomLocation = GenerateRandomLocation(xMin, xMax, yMin, yMax);
                     if (randomGenotype < 0)
                     {
                         m_dialogmod.SendGeneralAlert("Manager Module: Invalid command - Incorrect genotype format.  No new plants generated...");
                         errorStatus = true;
                     }
                     else if (randomLocation.Z > WaterLevel(randomLocation))
                     {
                         ScriptAndHostPair messageTarget = new ScriptAndHostPair();
                         lock (m_recyclables)
                         {
                             if (m_recyclables.Count == 0) //Nothing available to recycle
                             {
                                 //Nothing available to recycle. vpgPlanter will need to rez a new one
                                 messageTarget.scriptUUID = m_vpgPlanter.scriptUUID;
                             }
                             else
                             {
                                 //There are objects available to recycle.  Recycle one from the queue
                                 messageTarget = m_recyclables.Dequeue();
                             }
                         }
                         //Format the coordinates in the vector format expected by the LSL script
                         string coordinates = '<' + randomLocation.X.ToString() + ',' + randomLocation.Y.ToString() + ',' + randomLocation.Z.ToString() + '>';
                         //Send message to vpgPlanter or plant to be recycled
                         m_scriptmod.DispatchReply(messageTarget.scriptUUID, randomGenotype, coordinates, "");
                         //We have to pause between messages or the vpgPlanter gets overloaded and puts all the plants in the same location.
                         Thread.Sleep(50);
                         successCount++;
                         quantity--;
                     }
                     else if (strictQuantity == 0)
                     {
                         failureCount++;
                         quantity--;
                     }
                     else
                     {
                         failureCount++;
                         if (failureCount == m_maxFailures)
                         {
                             m_dialogmod.SendGeneralAlert("Manager Module: Too many failed attempts.  Are you sure there is dry land in the selected range? Successfully planted:" + successCount.ToString() + "  Failures:" + failureCount.ToString());
                             errorStatus = true;
                         }
                     }
                 }
                 if (m_dialogmod != null)
                 {
                     if (errorStatus == false)
                     {
                         m_dialogmod.SendGeneralAlert("Manager Module: Successfully planted:" + successCount.ToString() + "  Failures:" + failureCount.ToString());
                     }
                 }
             }
         }
     }
 }