mirror of
https://github.com/opensim/opensim.git
synced 2026-08-07 01:35:46 +08:00
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
This commit is contained in:
@@ -1678,5 +1678,10 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
|
||||
public void SendPlacesReply(UUID queryID, UUID transactionID, PlacesReplyData[] data)
|
||||
{
|
||||
}
|
||||
|
||||
public void SendPartPhysicsProprieties(ISceneEntity entity)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSimulator Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using OpenSim.Framework.Servers;
|
||||
using Mono.Addins;
|
||||
using log4net;
|
||||
using Nini.Config;
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
|
||||
using OpenSim.Framework.Servers.HttpServer;
|
||||
|
||||
|
||||
namespace OpenSim.Region.OptionalModules.WebSocketEchoModule
|
||||
{
|
||||
|
||||
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "WebSocketEchoModule")]
|
||||
public class WebSocketEchoModule : ISharedRegionModule
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
private bool enabled;
|
||||
public string Name { get { return "WebSocketEchoModule"; } }
|
||||
|
||||
public Type ReplaceableInterface { get { return null; } }
|
||||
|
||||
|
||||
private HashSet<WebSocketHttpServerHandler> _activeHandlers = new HashSet<WebSocketHttpServerHandler>();
|
||||
|
||||
public void Initialise(IConfigSource pConfig)
|
||||
{
|
||||
enabled =(pConfig.Configs["WebSocketEcho"] != null);
|
||||
if (enabled)
|
||||
m_log.DebugFormat("[WebSocketEchoModule]: INITIALIZED MODULE");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method sets up the callback to WebSocketHandlerCallback below when a HTTPRequest comes in for /echo
|
||||
/// </summary>
|
||||
public void PostInitialise()
|
||||
{
|
||||
if (enabled)
|
||||
MainServer.Instance.AddWebSocketHandler("/echo", WebSocketHandlerCallback);
|
||||
}
|
||||
|
||||
// This gets called by BaseHttpServer and gives us an opportunity to set things on the WebSocket handler before we turn it on
|
||||
public void WebSocketHandlerCallback(string path, WebSocketHttpServerHandler handler)
|
||||
{
|
||||
SubscribeToEvents(handler);
|
||||
handler.SetChunksize(8192);
|
||||
handler.NoDelay_TCP_Nagle = true;
|
||||
handler.HandshakeAndUpgrade();
|
||||
}
|
||||
|
||||
//These are our normal events
|
||||
public void SubscribeToEvents(WebSocketHttpServerHandler handler)
|
||||
{
|
||||
handler.OnClose += HandlerOnOnClose;
|
||||
handler.OnText += HandlerOnOnText;
|
||||
handler.OnUpgradeCompleted += HandlerOnOnUpgradeCompleted;
|
||||
handler.OnData += HandlerOnOnData;
|
||||
handler.OnPong += HandlerOnOnPong;
|
||||
}
|
||||
|
||||
public void UnSubscribeToEvents(WebSocketHttpServerHandler handler)
|
||||
{
|
||||
handler.OnClose -= HandlerOnOnClose;
|
||||
handler.OnText -= HandlerOnOnText;
|
||||
handler.OnUpgradeCompleted -= HandlerOnOnUpgradeCompleted;
|
||||
handler.OnData -= HandlerOnOnData;
|
||||
handler.OnPong -= HandlerOnOnPong;
|
||||
}
|
||||
|
||||
private void HandlerOnOnPong(object sender, PongEventArgs pongdata)
|
||||
{
|
||||
m_log.Info("[WebSocketEchoModule]: Got a pong.. ping time: " + pongdata.PingResponseMS);
|
||||
}
|
||||
|
||||
private void HandlerOnOnData(object sender, WebsocketDataEventArgs data)
|
||||
{
|
||||
WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;
|
||||
obj.SendData(data.Data);
|
||||
m_log.Info("[WebSocketEchoModule]: We received a bunch of ugly non-printable bytes");
|
||||
obj.SendPingCheck();
|
||||
}
|
||||
|
||||
|
||||
private void HandlerOnOnUpgradeCompleted(object sender, UpgradeCompletedEventArgs completeddata)
|
||||
{
|
||||
WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;
|
||||
_activeHandlers.Add(obj);
|
||||
}
|
||||
|
||||
private void HandlerOnOnText(object sender, WebsocketTextEventArgs text)
|
||||
{
|
||||
WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;
|
||||
obj.SendMessage(text.Data);
|
||||
m_log.Info("[WebSocketEchoModule]: We received this: " + text.Data);
|
||||
}
|
||||
|
||||
// Remove the references to our handler
|
||||
private void HandlerOnOnClose(object sender, CloseEventArgs closedata)
|
||||
{
|
||||
WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;
|
||||
UnSubscribeToEvents(obj);
|
||||
|
||||
lock (_activeHandlers)
|
||||
_activeHandlers.Remove(obj);
|
||||
obj.Dispose();
|
||||
}
|
||||
|
||||
// Shutting down.. so shut down all sockets.
|
||||
// Note.. this should be done outside of an ienumerable if you're also hook to the close event.
|
||||
public void Close()
|
||||
{
|
||||
if (!enabled)
|
||||
return;
|
||||
|
||||
// We convert this to a for loop so we're not in in an IEnumerable when the close
|
||||
//call triggers an event which then removes item from _activeHandlers that we're enumerating
|
||||
WebSocketHttpServerHandler[] items = new WebSocketHttpServerHandler[_activeHandlers.Count];
|
||||
_activeHandlers.CopyTo(items);
|
||||
|
||||
for (int i = 0; i < items.Length; i++)
|
||||
{
|
||||
items[i].Close(string.Empty);
|
||||
items[i].Dispose();
|
||||
}
|
||||
_activeHandlers.Clear();
|
||||
MainServer.Instance.RemoveWebSocketHandler("/echo");
|
||||
}
|
||||
|
||||
public void AddRegion(Scene scene)
|
||||
{
|
||||
m_log.DebugFormat("[WebSocketEchoModule]: REGION {0} ADDED", scene.RegionInfo.RegionName);
|
||||
}
|
||||
|
||||
public void RemoveRegion(Scene scene)
|
||||
{
|
||||
m_log.DebugFormat("[WebSocketEchoModule]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
|
||||
}
|
||||
|
||||
public void RegionLoaded(Scene scene)
|
||||
{
|
||||
m_log.DebugFormat("[WebSocketEchoModule]: REGION {0} LOADED", scene.RegionInfo.RegionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,7 +146,7 @@ namespace OpenSim.Region.OptionalModules.PhysicsParameters
|
||||
{
|
||||
foreach (PhysParameterEntry ppe in physScene.GetParameterList())
|
||||
{
|
||||
float val = 0.0f;
|
||||
string val = string.Empty;
|
||||
if (physScene.GetPhysicsParameter(ppe.name, out val))
|
||||
{
|
||||
WriteOut(" {0}/{1} = {2}", scene.RegionInfo.RegionName, ppe.name, val);
|
||||
@@ -159,7 +159,7 @@ namespace OpenSim.Region.OptionalModules.PhysicsParameters
|
||||
}
|
||||
else
|
||||
{
|
||||
float val = 0.0f;
|
||||
string val = string.Empty;
|
||||
if (physScene.GetPhysicsParameter(parm, out val))
|
||||
{
|
||||
WriteOut(" {0}/{1} = {2}", scene.RegionInfo.RegionName, parm, val);
|
||||
@@ -185,21 +185,12 @@ namespace OpenSim.Region.OptionalModules.PhysicsParameters
|
||||
return;
|
||||
}
|
||||
string parm = "xxx";
|
||||
float val = 0f;
|
||||
string valparm = String.Empty;
|
||||
uint localID = (uint)PhysParameterEntry.APPLY_TO_NONE; // set default value
|
||||
try
|
||||
{
|
||||
parm = cmdparms[2];
|
||||
string valparm = cmdparms[3].ToLower();
|
||||
if (valparm == "true")
|
||||
val = PhysParameterEntry.NUMERIC_TRUE;
|
||||
else
|
||||
{
|
||||
if (valparm == "false")
|
||||
val = PhysParameterEntry.NUMERIC_FALSE;
|
||||
else
|
||||
val = float.Parse(valparm, Culture.NumberFormatInfo);
|
||||
}
|
||||
valparm = cmdparms[3].ToLower();
|
||||
if (cmdparms.Length > 4)
|
||||
{
|
||||
if (cmdparms[4].ToLower() == "all")
|
||||
@@ -224,7 +215,7 @@ namespace OpenSim.Region.OptionalModules.PhysicsParameters
|
||||
IPhysicsParameters physScene = scene.PhysicsScene as IPhysicsParameters;
|
||||
if (physScene != null)
|
||||
{
|
||||
if (!physScene.SetPhysicsParameter(parm, val, localID))
|
||||
if (!physScene.SetPhysicsParameter(parm, valparm, localID))
|
||||
{
|
||||
WriteError("Failed set of parameter '{0}' for region '{1}'", parm, scene.RegionInfo.RegionName);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,22 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
|
||||
private MockScriptEngine m_engine;
|
||||
private ScriptModuleCommsModule m_smcm;
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void FixtureInit()
|
||||
{
|
||||
// Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
|
||||
Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
|
||||
}
|
||||
|
||||
[TestFixtureTearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
// We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
|
||||
// threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
|
||||
// tests really shouldn't).
|
||||
Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public override void SetUp()
|
||||
{
|
||||
@@ -85,7 +101,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
|
||||
|
||||
private object InvokeOp(string name, params object[] args)
|
||||
{
|
||||
return m_smcm.InvokeOperation(UUID.Zero, UUID.Zero, name, args);
|
||||
return InvokeOpOnHost(name, UUID.Zero, args);
|
||||
}
|
||||
|
||||
private object InvokeOpOnHost(string name, UUID hostId, params object[] args)
|
||||
{
|
||||
return m_smcm.InvokeOperation(hostId, UUID.Zero, name, args);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -193,6 +214,44 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
|
||||
Assert.That(value, Is.EqualTo("Times"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for reading and writing json to a notecard
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// TODO: Really needs to test correct receipt of the link_message event. Could do this by directly fetching
|
||||
/// it via the MockScriptEngine or perhaps by a dummy script instance.
|
||||
/// </remarks>
|
||||
[Test]
|
||||
public void TestJsonWriteReadNotecard()
|
||||
{
|
||||
TestHelpers.InMethod();
|
||||
TestHelpers.EnableLogging();
|
||||
|
||||
string notecardName = "nc1";
|
||||
|
||||
SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, TestHelpers.ParseTail(0x1));
|
||||
m_scene.AddSceneObject(so);
|
||||
|
||||
UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello':'World' }");
|
||||
|
||||
// Write notecard
|
||||
UUID writeNotecardRequestId = (UUID)InvokeOpOnHost("JsonWriteNotecard", so.UUID, storeId, "/", notecardName);
|
||||
Assert.That(writeNotecardRequestId, Is.Not.EqualTo(UUID.Zero));
|
||||
|
||||
TaskInventoryItem nc1Item = so.RootPart.Inventory.GetInventoryItem(notecardName);
|
||||
Assert.That(nc1Item, Is.Not.Null);
|
||||
|
||||
// TODO: Should probably independently check the contents.
|
||||
|
||||
// Read notecard
|
||||
UUID receivingStoreId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello':'World' }");
|
||||
UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, receivingStoreId, "/", notecardName);
|
||||
Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero));
|
||||
|
||||
string value = (string)InvokeOp("JsonGetValue", storeId, "Hello");
|
||||
Assert.That(value, Is.EqualTo("World"));
|
||||
}
|
||||
|
||||
public object DummyTestMethod(object o1, object o2, object o3, object o4, object o5) { return null; }
|
||||
}
|
||||
}
|
||||
@@ -1234,5 +1234,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||
public void SendPlacesReply(UUID queryID, UUID transactionID, PlacesReplyData[] data)
|
||||
{
|
||||
}
|
||||
|
||||
public void SendPartPhysicsProprieties(ISceneEntity entity)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user