Added code to propagate OnNewScript event, when client sends in RezScript request (e.g. add new script to a prim).
parent
69476339df
commit
719f59db3f
|
@ -91,6 +91,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
|
|||
m_scene.EventManager.OnPostSceneCreation += OnPostSceneCreation;
|
||||
//m_scene.EventManager.OnObjectBeingRemovedFromScene += new EventManager.ObjectBeingRemovedFromScene(RegionSyncModule_OnObjectBeingRemovedFromScene);
|
||||
|
||||
LogHeader += "-" + scene.RegionInfo.RegionName;
|
||||
}
|
||||
|
||||
//Called after AddRegion() has been called for all region modules of the scene
|
||||
|
@ -882,6 +883,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
|
|||
return;
|
||||
}
|
||||
//EVENTS PROCESSING
|
||||
case SymmetricSyncMessage.MsgType.NewScript:
|
||||
case SymmetricSyncMessage.MsgType.UpdateScript:
|
||||
case SymmetricSyncMessage.MsgType.ScriptReset:
|
||||
case SymmetricSyncMessage.MsgType.ChatFromClient:
|
||||
|
@ -1040,6 +1042,9 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
|
|||
|
||||
switch (msg.Type)
|
||||
{
|
||||
case SymmetricSyncMessage.MsgType.NewScript:
|
||||
HandleRemoteEvent_OnNewScript(init_actorID, evSeqNum, data);
|
||||
break;
|
||||
case SymmetricSyncMessage.MsgType.UpdateScript:
|
||||
HandleRemoteEvent_OnUpdateScript(init_actorID, evSeqNum, data);
|
||||
break;
|
||||
|
@ -1070,9 +1075,54 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="actorID">the ID of the actor that initiates the event</param>
|
||||
/// <param name="evSeqNum">sequence num of the event from the actor</param>
|
||||
/// <param name="data">OSDMap data of event args</param>
|
||||
private void HandleRemoteEvent_OnNewScript(string actorID, ulong evSeqNum, OSDMap data)
|
||||
{
|
||||
m_log.Debug(LogHeader + ", " + m_actorID + ": received NewScript");
|
||||
|
||||
UUID agentID = data["agentID"].AsUUID();
|
||||
UUID primID = data["primID"].AsUUID();
|
||||
UUID itemID = data["itemID"].AsUUID();
|
||||
|
||||
string sogXml = data["sog"].AsString();
|
||||
SceneObjectGroup sog = SceneObjectSerializer.FromXml2Format(sogXml);
|
||||
SceneObjectPart part = null;
|
||||
|
||||
foreach (SceneObjectPart prim in sog.Parts)
|
||||
{
|
||||
if(prim.UUID.Equals(primID)){
|
||||
part = prim;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(part == null)
|
||||
{
|
||||
m_log.Warn(LogHeader+": part "+primID+" not exist in the serialized object, do nothing");
|
||||
return;
|
||||
}
|
||||
//Update the object first
|
||||
Scene.ObjectUpdateResult updateResult = m_scene.AddOrUpdateObjectBySynchronization(sog);
|
||||
|
||||
if (updateResult == Scene.ObjectUpdateResult.Updated || updateResult == Scene.ObjectUpdateResult.New)
|
||||
{
|
||||
m_log.Debug(LogHeader + ": TriggerNewScriptLocally");
|
||||
//Next, trigger creating the new script
|
||||
SceneObjectPart localPart = m_scene.GetSceneObjectPart(primID);
|
||||
m_scene.EventManager.TriggerNewScriptLocally(agentID, localPart, itemID);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Special actions for remote event UpdateScript
|
||||
/// </summary>
|
||||
/// <param name="actorID">the ID of the actor that initiates the event</param>
|
||||
/// <param name="evSeqNum">sequence num of the event from the actor</param>
|
||||
/// <param name="data">OSDMap data of event args</param>
|
||||
private void HandleRemoteEvent_OnUpdateScript(string actorID, ulong evSeqNum, OSDMap data)
|
||||
{
|
||||
|
@ -1089,7 +1139,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Special actions for remote event UpdateScript
|
||||
/// Special actions for remote event ScriptReset
|
||||
/// </summary>
|
||||
/// <param name="data">OSDMap data of event args</param>
|
||||
private void HandleRemoteEvent_OnScriptReset(string actorID, ulong evSeqNum, OSDMap data)
|
||||
|
@ -1296,13 +1346,20 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
|
|||
{
|
||||
switch (ev)
|
||||
{
|
||||
case EventManager.EventNames.NewScript:
|
||||
if (evArgs.Length < 3)
|
||||
{
|
||||
m_log.Error(LogHeader + " not enough event args for NewScript");
|
||||
return;
|
||||
}
|
||||
OnLocalNewScript((UUID)evArgs[0], (SceneObjectPart)evArgs[1], (UUID)evArgs[2]);
|
||||
return;
|
||||
case EventManager.EventNames.UpdateScript:
|
||||
if (evArgs.Length < 5)
|
||||
{
|
||||
m_log.Error(LogHeader + " not enough event args for UpdateScript");
|
||||
return;
|
||||
}
|
||||
m_log.Debug(LogHeader + " PublishSceneEvent UpdateScript");
|
||||
OnLocalUpdateScript((UUID)evArgs[0], (UUID)evArgs[1], (UUID)evArgs[2], (bool)evArgs[3], (UUID)evArgs[4]);
|
||||
return;
|
||||
case EventManager.EventNames.ScriptReset:
|
||||
|
@ -1343,6 +1400,32 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The handler for (locally initiated) event OnNewScript: triggered by client's RezSript packet, publish it to other actors.
|
||||
/// </summary>
|
||||
/// <param name="clientID">ID of the client who creates the new script</param>
|
||||
/// <param name="part">the prim that contains the new script</param>
|
||||
private void OnLocalNewScript(UUID clientID, SceneObjectPart part, UUID itemID)
|
||||
{
|
||||
m_log.Debug(LogHeader + " RegionSyncModule_OnLocalNewScript");
|
||||
|
||||
SceneObjectGroup sog = part.ParentGroup;
|
||||
if(sog==null){
|
||||
m_log.Warn(LogHeader + ": part " + part.UUID + " not in an SceneObjectGroup yet. Will not propagating new script event");
|
||||
//sog = new SceneObjectGroup(part);
|
||||
return;
|
||||
}
|
||||
//For simplicity, we just leverage a SOP's serialization method to transmit the information of new inventory item for the script).
|
||||
//This can certainly be optimized later (e.g. only sending serialization of the inventory item)
|
||||
OSDMap data = new OSDMap();
|
||||
data["agentID"] = OSD.FromUUID(clientID);
|
||||
data["primID"] = OSD.FromUUID(part.UUID);
|
||||
data["itemID"] = OSD.FromUUID(itemID); //id of the new inventory item of the part
|
||||
data["sog"] = OSD.FromString(SceneObjectSerializer.ToXml2Format(sog));
|
||||
|
||||
SendSceneEvent(SymmetricSyncMessage.MsgType.NewScript, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The handler for (locally initiated) event OnUpdateScript: publish it to other actors.
|
||||
/// </summary>
|
||||
|
|
|
@ -89,8 +89,11 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
|
|||
|
||||
//for local OnUpdateScript, we'll handle it the same way as a remove OnUpdateScript.
|
||||
//RegionSyncModule will capture a locally initiated OnUpdateScript event and publish it to other actors.
|
||||
m_scene.EventManager.OnNewScript += ScriptEngine_OnNewScript;
|
||||
m_scene.EventManager.OnUpdateScript += ScriptEngine_OnUpdateScript;
|
||||
//m_scene.EventManager.OnUpdateScriptBySync += ScriptEngine_OnUpdateScript;
|
||||
|
||||
LogHeader += "-" + m_actorID + "-" + m_scene.RegionInfo.RegionName;
|
||||
}
|
||||
|
||||
//Called after AddRegion() has been called for all region modules of the scene.
|
||||
|
@ -182,6 +185,13 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
|
|||
m_scene.DeleteAllSceneObjects();
|
||||
}
|
||||
|
||||
public void ScriptEngine_OnNewScript(UUID agentID, SceneObjectPart part, UUID itemID)
|
||||
{
|
||||
m_log.Debug(LogHeader + " ScriptEngine_OnUpdateScript");
|
||||
|
||||
m_scene.SymSync_OnNewScript(agentID, itemID, part);
|
||||
}
|
||||
|
||||
//Assumption, when this function is triggered, the new script asset has already been saved.
|
||||
public void ScriptEngine_OnUpdateScript(UUID agentID, UUID itemID, UUID primID, bool isScriptRunning, UUID newAssetID)
|
||||
{
|
||||
|
|
|
@ -34,6 +34,7 @@ namespace OpenSim.Region.CoreModules.RegionSync.RegionSyncModule
|
|||
//RegionStatus,
|
||||
ActorID,
|
||||
//events
|
||||
NewScript,
|
||||
UpdateScript,
|
||||
ScriptReset,
|
||||
ChatFromClient,
|
||||
|
|
|
@ -50,6 +50,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
//the events that we'll handle specially in sym-sync
|
||||
public enum EventNames
|
||||
{
|
||||
NewScript,
|
||||
UpdateScript,
|
||||
ScriptReset,
|
||||
ChatFromClient, //chats from avatars
|
||||
|
@ -65,6 +66,30 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
m_scene = scene;
|
||||
}
|
||||
|
||||
#region UpdateScript
|
||||
//triggered by client.OnRezScript
|
||||
public override void TriggerNewScript(UUID clientID, SceneObjectPart part, UUID itemID)
|
||||
{
|
||||
//publish the event to other actors who are intersted in it
|
||||
if (m_scene.RegionSyncModule != null)
|
||||
{
|
||||
Object[] eventArgs = new Object[3];
|
||||
eventArgs[0] = (Object)clientID;
|
||||
eventArgs[1] = (Object)part;
|
||||
eventArgs[2] = (Object)itemID;
|
||||
m_scene.RegionSyncModule.PublishSceneEvent(EventNames.NewScript, eventArgs);
|
||||
}
|
||||
|
||||
//trigger event locally,
|
||||
TriggerNewScriptLocally(clientID, part, itemID);
|
||||
}
|
||||
//public void TriggerNewScriptLocally(UUID clientID, UUID itemId, UUID primId, UUID newAssetID)
|
||||
public void TriggerNewScriptLocally(UUID clientID, SceneObjectPart part, UUID itemID)
|
||||
{
|
||||
base.TriggerNewScript(clientID, part, itemID);
|
||||
}
|
||||
#endregion //UpdateScript
|
||||
|
||||
#region UpdateScript
|
||||
public override void TriggerUpdateScript(UUID clientId, UUID itemId, UUID primId, bool isScriptRunning, UUID newAssetID)
|
||||
{
|
||||
|
@ -80,7 +105,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
m_scene.RegionSyncModule.PublishSceneEvent(EventNames.UpdateScript, eventArgs);
|
||||
}
|
||||
|
||||
//trigger event locally, as the legacy code does
|
||||
//trigger event locally,
|
||||
TriggerUpdateScriptLocally(clientId, itemId, primId, isScriptRunning, newAssetID);
|
||||
}
|
||||
public void TriggerUpdateScriptLocally(UUID clientId, UUID itemId, UUID primId, bool isScriptRunning, UUID newAssetID)
|
||||
|
@ -2378,8 +2403,32 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//OnUpdateTaskInventoryScriptAsset: triggered after Scene receives client's upload of updated script and stores it as asset
|
||||
|
||||
public delegate void NewScript(UUID clientID, SceneObjectPart part, UUID itemID);
|
||||
public event NewScript OnNewScript;
|
||||
public virtual void TriggerNewScript(UUID clientID, SceneObjectPart part, UUID itemID)
|
||||
{
|
||||
NewScript handlerNewScript = OnNewScript;
|
||||
if (handlerNewScript != null)
|
||||
{
|
||||
foreach (NewScript d in handlerNewScript.GetInvocationList())
|
||||
{
|
||||
try
|
||||
{
|
||||
d(clientID, part, itemID);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.ErrorFormat(
|
||||
"[EVENT MANAGER]: Delegate for TriggerNewScript failed - continuing. {0} {1}",
|
||||
e.Message, e.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TriggerUpdateScript: triggered after Scene receives client's upload of updated script and stores it as asset
|
||||
public delegate void UpdateScript(UUID clientID, UUID itemId, UUID primId, bool isScriptRunning, UUID newAssetID);
|
||||
public event UpdateScript OnUpdateScript;
|
||||
public virtual void TriggerUpdateScript(UUID clientId, UUID itemId, UUID primId, bool isScriptRunning, UUID newAssetID)
|
||||
|
|
|
@ -310,7 +310,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
* */
|
||||
|
||||
//SYMMETRIC SYNC: Distributed Scene Graph implementation
|
||||
m_log.Debug("Scene.Inventory: to call EventManager.TriggerUpdateTaskInventoryScriptAsset, agentID: " + remoteClient.AgentId);
|
||||
m_log.Debug("Scene.Inventory: to call EventManager.TriggerUpdateScript, agentID: " + remoteClient.AgentId);
|
||||
//Trigger OnUpdateScript event.
|
||||
EventManager.TriggerUpdateScript(remoteClient.AgentId, itemId, primId, isScriptRunning, item.AssetID);
|
||||
|
||||
|
@ -369,6 +369,14 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
#endregion
|
||||
|
||||
#region SYMMETRIC SYNC
|
||||
public void SymSync_OnNewScript(UUID avatarID, UUID itemID, SceneObjectPart part)
|
||||
{
|
||||
TaskInventoryItem item = part.Inventory.GetInventoryItem(itemID);
|
||||
|
||||
part.Inventory.CreateScriptInstance(item, 0, false, DefaultScriptEngine, 0);
|
||||
part.ParentGroup.ResumeScripts();
|
||||
}
|
||||
|
||||
//only a script engine actor is supposed to call this function
|
||||
public ArrayList SymSync_OnUpdateScript(UUID avatarID, UUID itemID, UUID primID, bool isScriptRunning, UUID newAssetID)
|
||||
{
|
||||
|
@ -1663,6 +1671,10 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
return;
|
||||
|
||||
part.ParentGroup.AddInventoryItem(remoteClient, localID, item, copyID);
|
||||
part.GetProperties(remoteClient);
|
||||
|
||||
//SYMMETRIC SYNC
|
||||
/* Original OpenSim code, commented out
|
||||
// TODO: switch to posting on_rez here when scripts
|
||||
// have state in inventory
|
||||
part.Inventory.CreateScriptInstance(copyID, 0, false, DefaultScriptEngine, 0);
|
||||
|
@ -1670,8 +1682,26 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
// m_log.InfoFormat("[PRIMINVENTORY]: " +
|
||||
// "Rezzed script {0} into prim local ID {1} for user {2}",
|
||||
// item.inventoryName, localID, remoteClient.Name);
|
||||
part.GetProperties(remoteClient);
|
||||
//part.GetProperties(remoteClient);
|
||||
part.ParentGroup.ResumeScripts();
|
||||
* */
|
||||
if (RegionSyncModule != null)
|
||||
{
|
||||
part.SyncInfoUpdate();
|
||||
EventManager.TriggerNewScript(remoteClient.AgentId, part, copyID);
|
||||
}
|
||||
else
|
||||
{
|
||||
part.Inventory.CreateScriptInstance(copyID, 0, false, DefaultScriptEngine, 0);
|
||||
|
||||
// m_log.InfoFormat("[PRIMINVENTORY]: " +
|
||||
// "Rezzed script {0} into prim local ID {1} for user {2}",
|
||||
// item.inventoryName, localID, remoteClient.Name);
|
||||
//part.GetProperties(remoteClient);
|
||||
part.ParentGroup.ResumeScripts();
|
||||
}
|
||||
//end of SYMMETRIC SYNC
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1730,8 +1760,25 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
part.Inventory.AddInventoryItem(taskItem, false);
|
||||
part.GetProperties(remoteClient);
|
||||
|
||||
part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0);
|
||||
part.ParentGroup.ResumeScripts();
|
||||
//SYMMETRIC SYNC
|
||||
//part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0);
|
||||
//part.ParentGroup.ResumeScripts();
|
||||
if (RegionSyncModule != null)
|
||||
{
|
||||
part.SyncInfoUpdate();
|
||||
EventManager.TriggerNewScript(remoteClient.AgentId, part, taskItem.ItemID);
|
||||
}
|
||||
else
|
||||
{
|
||||
part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0);
|
||||
|
||||
// m_log.InfoFormat("[PRIMINVENTORY]: " +
|
||||
// "Rezzed script {0} into prim local ID {1} for user {2}",
|
||||
// item.inventoryName, localID, remoteClient.Name);
|
||||
//part.GetProperties(remoteClient);
|
||||
part.ParentGroup.ResumeScripts();
|
||||
}
|
||||
//end of SYMMETRIC SYNC
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,8 +69,6 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
EventManager.TriggerOnChatBroadcast(this, args);
|
||||
else
|
||||
EventManager.TriggerOnChatFromWorld(this, args);
|
||||
|
||||
m_log.Debug("end of SimChat");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue