aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Example
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Region/OptionalModules/Example
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/OptionalModules/Example/BareBonesNonShared/BareBonesNonSharedModule.cs6
-rw-r--r--OpenSim/Region/OptionalModules/Example/BareBonesShared/BareBonesSharedModule.cs6
-rw-r--r--OpenSim/Region/OptionalModules/Example/WebSocketEchoTest/WebSocketEchoModule.cs175
3 files changed, 187 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Example/BareBonesNonShared/BareBonesNonSharedModule.cs b/OpenSim/Region/OptionalModules/Example/BareBonesNonShared/BareBonesNonSharedModule.cs
index 7d37135..bbf7168 100644
--- a/OpenSim/Region/OptionalModules/Example/BareBonesNonShared/BareBonesNonSharedModule.cs
+++ b/OpenSim/Region/OptionalModules/Example/BareBonesNonShared/BareBonesNonSharedModule.cs
@@ -33,6 +33,12 @@ using Nini.Config;
33using OpenSim.Region.Framework.Interfaces; 33using OpenSim.Region.Framework.Interfaces;
34using OpenSim.Region.Framework.Scenes; 34using OpenSim.Region.Framework.Scenes;
35 35
36// You will need to uncomment these lines if you are adding a region module to some other assembly which does not already
37// specify its assembly. Otherwise, the region modules in the assembly will not be picked up when OpenSimulator scans
38// the available DLLs
39//[assembly: Addin("MyModule", "1.0")]
40//[assembly: AddinDependency("OpenSim", "0.8.1")]
41
36namespace OpenSim.Region.OptionalModules.Example.BareBonesNonShared 42namespace OpenSim.Region.OptionalModules.Example.BareBonesNonShared
37{ 43{
38 /// <summary> 44 /// <summary>
diff --git a/OpenSim/Region/OptionalModules/Example/BareBonesShared/BareBonesSharedModule.cs b/OpenSim/Region/OptionalModules/Example/BareBonesShared/BareBonesSharedModule.cs
index 781fe95..46fea3e 100644
--- a/OpenSim/Region/OptionalModules/Example/BareBonesShared/BareBonesSharedModule.cs
+++ b/OpenSim/Region/OptionalModules/Example/BareBonesShared/BareBonesSharedModule.cs
@@ -33,6 +33,12 @@ using Nini.Config;
33using OpenSim.Region.Framework.Interfaces; 33using OpenSim.Region.Framework.Interfaces;
34using OpenSim.Region.Framework.Scenes; 34using OpenSim.Region.Framework.Scenes;
35 35
36// You will need to uncomment these lines if you are adding a region module to some other assembly which does not already
37// specify its assembly. Otherwise, the region modules in the assembly will not be picked up when OpenSimulator scans
38// the available DLLs
39//[assembly: Addin("MyModule", "1.0")]
40//[assembly: AddinDependency("OpenSim", "0.8.1")]
41
36namespace OpenSim.Region.OptionalModules.Example.BareBonesShared 42namespace OpenSim.Region.OptionalModules.Example.BareBonesShared
37{ 43{
38 /// <summary> 44 /// <summary>
diff --git a/OpenSim/Region/OptionalModules/Example/WebSocketEchoTest/WebSocketEchoModule.cs b/OpenSim/Region/OptionalModules/Example/WebSocketEchoTest/WebSocketEchoModule.cs
new file mode 100644
index 0000000..5bf0ed4
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Example/WebSocketEchoTest/WebSocketEchoModule.cs
@@ -0,0 +1,175 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using OpenSim.Framework.Servers;
32using Mono.Addins;
33using log4net;
34using Nini.Config;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes;
37
38using OpenSim.Framework.Servers.HttpServer;
39
40
41namespace OpenSim.Region.OptionalModules.WebSocketEchoModule
42{
43
44 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "WebSocketEchoModule")]
45 public class WebSocketEchoModule : ISharedRegionModule
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private bool enabled;
50 public string Name { get { return "WebSocketEchoModule"; } }
51
52 public Type ReplaceableInterface { get { return null; } }
53
54
55 private HashSet<WebSocketHttpServerHandler> _activeHandlers = new HashSet<WebSocketHttpServerHandler>();
56
57 public void Initialise(IConfigSource pConfig)
58 {
59 enabled = (pConfig.Configs["WebSocketEcho"] != null);
60// if (enabled)
61// m_log.DebugFormat("[WebSocketEchoModule]: INITIALIZED MODULE");
62 }
63
64 /// <summary>
65 /// This method sets up the callback to WebSocketHandlerCallback below when a HTTPRequest comes in for /echo
66 /// </summary>
67 public void PostInitialise()
68 {
69 if (enabled)
70 MainServer.Instance.AddWebSocketHandler("/echo", WebSocketHandlerCallback);
71 }
72
73 // This gets called by BaseHttpServer and gives us an opportunity to set things on the WebSocket handler before we turn it on
74 public void WebSocketHandlerCallback(string path, WebSocketHttpServerHandler handler)
75 {
76 SubscribeToEvents(handler);
77 handler.SetChunksize(8192);
78 handler.NoDelay_TCP_Nagle = true;
79 handler.HandshakeAndUpgrade();
80 }
81
82 //These are our normal events
83 public void SubscribeToEvents(WebSocketHttpServerHandler handler)
84 {
85 handler.OnClose += HandlerOnOnClose;
86 handler.OnText += HandlerOnOnText;
87 handler.OnUpgradeCompleted += HandlerOnOnUpgradeCompleted;
88 handler.OnData += HandlerOnOnData;
89 handler.OnPong += HandlerOnOnPong;
90 }
91
92 public void UnSubscribeToEvents(WebSocketHttpServerHandler handler)
93 {
94 handler.OnClose -= HandlerOnOnClose;
95 handler.OnText -= HandlerOnOnText;
96 handler.OnUpgradeCompleted -= HandlerOnOnUpgradeCompleted;
97 handler.OnData -= HandlerOnOnData;
98 handler.OnPong -= HandlerOnOnPong;
99 }
100
101 private void HandlerOnOnPong(object sender, PongEventArgs pongdata)
102 {
103 m_log.Info("[WebSocketEchoModule]: Got a pong.. ping time: " + pongdata.PingResponseMS);
104 }
105
106 private void HandlerOnOnData(object sender, WebsocketDataEventArgs data)
107 {
108 WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;
109 obj.SendData(data.Data);
110 m_log.Info("[WebSocketEchoModule]: We received a bunch of ugly non-printable bytes");
111 obj.SendPingCheck();
112 }
113
114
115 private void HandlerOnOnUpgradeCompleted(object sender, UpgradeCompletedEventArgs completeddata)
116 {
117 WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;
118 _activeHandlers.Add(obj);
119 }
120
121 private void HandlerOnOnText(object sender, WebsocketTextEventArgs text)
122 {
123 WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;
124 obj.SendMessage(text.Data);
125 m_log.Info("[WebSocketEchoModule]: We received this: " + text.Data);
126 }
127
128 // Remove the references to our handler
129 private void HandlerOnOnClose(object sender, CloseEventArgs closedata)
130 {
131 WebSocketHttpServerHandler obj = sender as WebSocketHttpServerHandler;
132 UnSubscribeToEvents(obj);
133
134 lock (_activeHandlers)
135 _activeHandlers.Remove(obj);
136 obj.Dispose();
137 }
138
139 // Shutting down.. so shut down all sockets.
140 // Note.. this should be done outside of an ienumerable if you're also hook to the close event.
141 public void Close()
142 {
143 if (!enabled)
144 return;
145
146 // We convert this to a for loop so we're not in in an IEnumerable when the close
147 //call triggers an event which then removes item from _activeHandlers that we're enumerating
148 WebSocketHttpServerHandler[] items = new WebSocketHttpServerHandler[_activeHandlers.Count];
149 _activeHandlers.CopyTo(items);
150
151 for (int i = 0; i < items.Length; i++)
152 {
153 items[i].Close(string.Empty);
154 items[i].Dispose();
155 }
156 _activeHandlers.Clear();
157 MainServer.Instance.RemoveWebSocketHandler("/echo");
158 }
159
160 public void AddRegion(Scene scene)
161 {
162// m_log.DebugFormat("[WebSocketEchoModule]: REGION {0} ADDED", scene.RegionInfo.RegionName);
163 }
164
165 public void RemoveRegion(Scene scene)
166 {
167// m_log.DebugFormat("[WebSocketEchoModule]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
168 }
169
170 public void RegionLoaded(Scene scene)
171 {
172// m_log.DebugFormat("[WebSocketEchoModule]: REGION {0} LOADED", scene.RegionInfo.RegionName);
173 }
174 }
175} \ No newline at end of file