/// <summary> /// Emits events of the kind event|AvatarArrived|<LocalTP_TrueFalse>, avatar_id /// </summary> /// <param name="sp"></param> void OnMakeRootAgent(ScenePresence sp) { //sp.ControllingClient.OnAddPrim += ControllingClient_OnAddPrim; if (m_EventSubscribers.ContainsKey(VOEvents.AvatarArrived) && m_EventSubscribers[VOEvents.AvatarArrived].Count > 0) { Util.FireAndForget(delegate { bool localTP = ((sp.TeleportFlags & Constants.TeleportFlags.ViaHGLogin) == 0); List <UUID> subs = m_EventSubscribers[VOEvents.AvatarArrived]; foreach (UUID script in subs) { m_ScriptComms.DispatchReply(script, 0, "event|" + VOEvents.AvatarArrived + "|" + localTP, sp.UUID.ToString()); } }); } }
private void Publish(string event_name, string[] args, string key) { if (m_EventSubscribers.ContainsKey(event_name) && m_EventSubscribers[event_name].Count > 0) { Util.FireAndForget(delegate { string message = "event|" + event_name + ((args != null && args.Length > 0) ? "|" + string.Join("|", args) : string.Empty); foreach (UUID script in m_EventSubscribers[event_name]) { m_ScriptComms.DispatchReply(script, 0, message, key); } }); } if (m_SimEventSubscribers.ContainsKey(event_name) && m_SimEventSubscribers[event_name].Count > 0) { Util.FireAndForget(delegate { string message = "event|" + event_name + ((args != null && args.Length > 0) ? "|" + string.Join("|", args) : string.Empty); foreach (IScriptModuleComms m in m_ScriptModules) { foreach (UUID script in m_SimEventSubscribers[event_name]) { m.DispatchReply(script, 0, message, key); } } }); } }
// ----------------------------------------------------------------- /// <summary> /// /// </summary> // ----------------------------------------------------------------- protected void DispatchValue(UUID scriptID, UUID reqID, string value) { m_comms.DispatchReply(scriptID, 1, value, reqID.ToString()); }
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()); } } } } } }