aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/Linden
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden')
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/RegionConsoleModule.cs234
1 files changed, 234 insertions, 0 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/RegionConsoleModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/RegionConsoleModule.cs
new file mode 100644
index 0000000..36af55f
--- /dev/null
+++ b/OpenSim/Region/ClientStack/Linden/Caps/RegionConsoleModule.cs
@@ -0,0 +1,234 @@
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;
30using System.Collections.Generic;
31using System.Collections.Specialized;
32using System.Drawing;
33using System.Drawing.Imaging;
34using System.Reflection;
35using System.IO;
36using System.Web;
37using log4net;
38using Nini.Config;
39using Mono.Addins;
40using OpenMetaverse;
41using OpenMetaverse.StructuredData;
42using OpenMetaverse.Imaging;
43using OpenSim.Framework;
44using OpenSim.Framework.Console;
45using OpenSim.Framework.Servers;
46using OpenSim.Framework.Servers.HttpServer;
47using OpenSim.Region.Framework.Interfaces;
48using OpenSim.Region.Framework.Scenes;
49using OpenSim.Services.Interfaces;
50using Caps = OpenSim.Framework.Capabilities.Caps;
51using OpenSim.Capabilities.Handlers;
52
53namespace OpenSim.Region.ClientStack.Linden
54{
55
56 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RegionConsoleModule")]
57 public class RegionConsoleModule : INonSharedRegionModule, IRegionConsole
58 {
59 private static readonly ILog m_log =
60 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
61
62 private Scene m_scene;
63 private IEventQueue m_eventQueue;
64 private Commands m_commands = new Commands();
65 public ICommands Commands { get { return m_commands; } }
66
67 public void Initialise(IConfigSource source)
68 {
69 m_commands.AddCommand( "Help", false, "help", "help [<item>]", "Display help on a particular command or on a list of commands in a category", Help);
70 }
71
72 public void AddRegion(Scene s)
73 {
74 m_scene = s;
75 m_scene.RegisterModuleInterface<IRegionConsole>(this);
76 }
77
78 public void RemoveRegion(Scene s)
79 {
80 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
81 m_scene = null;
82 }
83
84 public void RegionLoaded(Scene s)
85 {
86 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
87 m_eventQueue = m_scene.RequestModuleInterface<IEventQueue>();
88 }
89
90 public void PostInitialise()
91 {
92 }
93
94 public void Close() { }
95
96 public string Name { get { return "RegionConsoleModule"; } }
97
98 public Type ReplaceableInterface
99 {
100 get { return null; }
101 }
102
103 public void RegisterCaps(UUID agentID, Caps caps)
104 {
105 if (!m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(agentID))
106 return;
107
108 UUID capID = UUID.Random();
109
110 m_log.DebugFormat("[REGION CONSOLE]: /CAPS/{0} in region {1}", capID, m_scene.RegionInfo.RegionName);
111 caps.RegisterHandler(
112 "SimConsoleAsync",
113 new ConsoleHandler("/CAPS/" + capID + "/", "SimConsoleAsync", agentID, this, m_scene));
114 }
115
116 public void SendConsoleOutput(UUID agentID, string message)
117 {
118 OSD osd = OSD.FromString(message);
119
120 m_eventQueue.Enqueue(EventQueueHelper.BuildEvent("SimConsoleResponse", osd), agentID);
121 }
122
123 public bool RunCommand(string command, UUID invokerID)
124 {
125 string[] parts = Parser.Parse(command);
126 Array.Resize(ref parts, parts.Length + 1);
127 parts[parts.Length - 1] = invokerID.ToString();
128
129 if (m_commands.Resolve(parts).Length == 0)
130 return false;
131
132 return true;
133 }
134
135 private void Help(string module, string[] cmd)
136 {
137 UUID agentID = new UUID(cmd[cmd.Length - 1]);
138 Array.Resize(ref cmd, cmd.Length - 1);
139
140 List<string> help = Commands.GetHelp(cmd);
141
142 string reply = String.Empty;
143
144 foreach (string s in help)
145 {
146 reply += s + "\n";
147 }
148
149 SendConsoleOutput(agentID, reply);
150 }
151
152 public void AddCommand(string module, bool shared, string command, string help, string longhelp, CommandDelegate fn)
153 {
154 m_commands.AddCommand(module, shared, command, help, longhelp, fn);
155 }
156 }
157
158 public class ConsoleHandler : BaseStreamHandler
159 {
160 private static readonly ILog m_log =
161 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
162
163 private RegionConsoleModule m_consoleModule;
164 private UUID m_agentID;
165 private bool m_isGod;
166 private Scene m_scene;
167 private bool m_consoleIsOn = false;
168
169 public ConsoleHandler(string path, string name, UUID agentID, RegionConsoleModule module, Scene scene)
170 :base("POST", path, name, agentID.ToString())
171 {
172 m_agentID = agentID;
173 m_consoleModule = module;
174 m_scene = scene;
175
176 m_isGod = m_scene.Permissions.IsGod(agentID);
177 }
178
179 public override byte[] Handle(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
180 {
181 StreamReader reader = new StreamReader(request);
182 string message = reader.ReadToEnd();
183
184 OSD osd = OSDParser.DeserializeLLSDXml(message);
185
186 string cmd = osd.AsString();
187 if (cmd == "set console on")
188 {
189 if (m_isGod)
190 {
191 MainConsole.Instance.OnOutput += ConsoleSender;
192 m_consoleIsOn = true;
193 m_consoleModule.SendConsoleOutput(m_agentID, "Console is now on");
194 }
195 return new byte[0];
196 }
197 else if (cmd == "set console off")
198 {
199 MainConsole.Instance.OnOutput -= ConsoleSender;
200 m_consoleIsOn = false;
201 m_consoleModule.SendConsoleOutput(m_agentID, "Console is now off");
202 return new byte[0];
203 }
204
205 if (m_consoleIsOn == false && m_consoleModule.RunCommand(osd.AsString().Trim(), m_agentID))
206 return new byte[0];
207
208 if (m_isGod && m_consoleIsOn)
209 {
210 MainConsole.Instance.RunCommand(osd.AsString().Trim());
211 }
212 else
213 {
214 m_consoleModule.SendConsoleOutput(m_agentID, "Unknown command");
215 }
216
217 return new byte[0];
218 }
219
220 private void ConsoleSender(string text)
221 {
222 m_consoleModule.SendConsoleOutput(m_agentID, text);
223 }
224
225 private void OnMakeChildAgent(ScenePresence presence)
226 {
227 if (presence.UUID == m_agentID)
228 {
229 MainConsole.Instance.OnOutput -= ConsoleSender;
230 m_consoleIsOn = false;
231 }
232 }
233 }
234}