void OnModSendCommand(UUID messageSourceScript, string messageId, string messageDestinationModule, string command, string coordinates)
 {
     if ((messageDestinationModule != Name) || (m_resetRequested))
     {
         //Message is not intended for this module
         return;
     }
     else if (command == "xxdeadxx")
     {
         //message from a dying plant.  Add it to the list of recyclables.
         ScriptAndHostPair scriptAndHost = new ScriptAndHostPair(messageSourceScript, coordinates);
         lock (m_recyclables)
         {
             m_recyclables.Enqueue(scriptAndHost);
         }
     }
     else if (command.Substring(0, 10) == "xxgenomexx")
     {
         //message from parent plant wanting to reproduce (or vpgPlanter passing along a reproduction request heard on IRC)
         ScriptAndHostPair messageTarget = new ScriptAndHostPair();
         bool isRecycled = false;
         lock (m_recyclables)
         {
             if (m_recyclables.Count == 0)
             {
                 //Nothing available to recycle so the parent plant or vpgPlanter will be the target of our message
                 messageTarget.scriptUUID = messageSourceScript;
             }
             else
             {
                 //There are objects available to recycle so the plant that will be recycled will be the target of our message
                 messageTarget = m_recyclables.Dequeue();
                 isRecycled = true;
             }
         }
         if (isRecycled)
         {
             int genome = Int32.Parse(command.Substring(10));
             //Send message to Recycled plant
             m_scriptmod.DispatchReply(messageTarget.scriptUUID, genome, coordinates, "");
             if (genome >= Convert.ToInt32(Math.Pow(2, m_loci * 2)))
             {
                 //The recycled plant became a sporophyte so we need to pass its key to its mother
                 m_scriptmod.DispatchReply(messageSourceScript, -1, "", messageTarget.hostUUID);
             }
         }
         else if (!m_overLimit)
         {
             if (m_scene.GetEntities().Length < m_populationLimit)
             {
                 int genome = Int32.Parse(command.Substring(10));
                 //Send message to parent plant, vpgPlanter
                 m_scriptmod.DispatchReply(messageTarget.scriptUUID, genome, coordinates, "");
             }
             else
             {
                 //Population size limit reached.  Don't rez any more new plants!
                 m_log.Info("[vpgManager] Population limit reached...");
                 m_overLimit = true;
             }
         }
     }
     else if (command == "xxregisterxx")
     {
         //message from vpgPlanter registering with the module
         //Possible problem: If more than one is rezzed in the region, only the last one registered will be used. So if there is more than one vpgPlanter in the region and you delete the last one that registered, this module will not recognize that the others are still there.
         m_vpgPlanter.scriptUUID = messageSourceScript;
         m_log.Info("[vpgManager] Registered a vpgPlanter...");
     }
     else
     {
         m_log.Warn("[vpgManager] Unexpected modSendCommand received!"); //Debug
     }
 }
Esempio n. 2
0
 void OnModSendCommand(UUID messageSourceScript, string messageId, string messageDestinationModule, string command, string coordinates)
 {
     if ((messageDestinationModule != Name) || (m_resetRequested))
     {
         //Message is not intended for this module
         return;
     }
     else if (command == "xxdeadxx")
     {
         //message from a dying plant.  Add it to the list of recyclables.
         ScriptAndHostPair scriptAndHost = new ScriptAndHostPair(messageSourceScript, coordinates);
         lock (m_recyclables)
         {
             m_recyclables.Enqueue(scriptAndHost);
         }
     }
     else if (command.Substring(0, 10) == "xxgenomexx")
     {
         //message from parent plant wanting to reproduce (or vpgPlanter passing along a reproduction request heard on IRC)
         ScriptAndHostPair messageTarget = new ScriptAndHostPair();
         bool isRecycled = false;
         lock (m_recyclables)
         {
             if (m_recyclables.Count == 0)
             {
                 //Nothing available to recycle so the parent plant or vpgPlanter will be the target of our message
                 messageTarget.scriptUUID = messageSourceScript;
             }
             else
             {
                 //There are objects available to recycle so the plant that will be recycled will be the target of our message
                 messageTarget = m_recyclables.Dequeue();
                 isRecycled    = true;
             }
         }
         if (isRecycled)
         {
             int genome = Int32.Parse(command.Substring(10));
             //Send message to Recycled plant
             m_scriptmod.DispatchReply(messageTarget.scriptUUID, genome, coordinates, "");
             if (genome >= Convert.ToInt32(Math.Pow(2, m_loci * 2)))
             {
                 //The recycled plant became a sporophyte so we need to pass its key to its mother
                 m_scriptmod.DispatchReply(messageSourceScript, -1, "", messageTarget.hostUUID);
             }
         }
         else if (!m_overLimit)
         {
             if (m_scene.GetEntities().Length < m_populationLimit)
             {
                 int genome = Int32.Parse(command.Substring(10));
                 //Send message to parent plant, vpgPlanter
                 m_scriptmod.DispatchReply(messageTarget.scriptUUID, genome, coordinates, "");
             }
             else
             {
                 //Population size limit reached.  Don't rez any more new plants!
                 m_log.Info("[vpgManager] Population limit reached...");
                 m_overLimit = true;
             }
         }
     }
     else if (command == "xxregisterxx")
     {
         //message from vpgPlanter registering with the module
         //Possible problem: If more than one is rezzed in the region, only the last one registered will be used. So if there is more than one vpgPlanter in the region and you delete the last one that registered, this module will not recognize that the others are still there.
         m_vpgPlanter.scriptUUID = messageSourceScript;
         m_log.Info("[vpgManager] Registered a vpgPlanter...");
     }
     else
     {
         m_log.Warn("[vpgManager] Unexpected modSendCommand received!"); //Debug
     }
 }
 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());
                     }
                 }
             }
         }
     }
 }
Esempio n. 4
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());
                     }
                 }
             }
         }
     }
 }