29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Collections.Specialized;
33 using System.Drawing.Imaging;
34 using System.Reflection;
41 using OpenMetaverse.StructuredData;
42 using OpenMetaverse.Imaging;
43 using OpenSim.Framework;
44 using OpenSim.Framework.Console;
45 using OpenSim.Framework.Servers;
46 using OpenSim.Framework.Servers.HttpServer;
47 using OpenSim.Region.Framework.Interfaces;
48 using OpenSim.Region.Framework.Scenes;
49 using OpenSim.Services.Interfaces;
51 using OpenSim.Capabilities.Handlers;
53 namespace OpenSim.
Region.ClientStack.Linden
56 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"RegionConsoleModule")]
62 private Scene m_scene;
71 m_commands.AddCommand(
"Help",
false,
"help",
"help [<item>]",
"Display help on a particular command or on a list of commands in a category", Help);
82 m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
88 m_scene.EventManager.OnRegisterCaps += RegisterCaps;
89 m_eventQueue = m_scene.RequestModuleInterface<
IEventQueue>();
98 public string Name {
get {
return "RegionConsoleModule"; } }
100 public Type ReplaceableInterface
107 if (!m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(agentID) && !m_scene.Permissions.IsGod(agentID))
110 UUID capID = UUID.Random();
113 caps.RegisterHandler(
115 new ConsoleHandler(
"/CAPS/" + capID +
"/",
"SimConsoleAsync", agentID,
this, m_scene));
120 OSD osd = OSD.FromString(message);
122 m_eventQueue.Enqueue(EventQueueHelper.BuildEvent(
"SimConsoleResponse", osd), agentID);
126 if (handlerConsoleMessage != null)
127 handlerConsoleMessage( agentID, message);
132 string[] parts = Parser.Parse(command);
133 Array.Resize(ref parts, parts.Length + 1);
134 parts[parts.Length - 1] = invokerID.ToString();
136 if (m_commands.Resolve(parts).Length == 0)
142 private void Help(
string module,
string[] cmd)
144 UUID agentID =
new UUID(cmd[cmd.Length - 1]);
145 Array.Resize(ref cmd, cmd.Length - 1);
147 List<string> help = Commands.GetHelp(cmd);
149 string reply = String.Empty;
151 foreach (
string s
in help)
156 SendConsoleOutput(agentID, reply);
161 m_commands.AddCommand(module, shared, command, help, longhelp, fn);
171 private UUID m_agentID;
172 private bool m_isGod;
173 private Scene m_scene;
174 private bool m_consoleIsOn =
false;
177 :base(
"POST", path, name, agentID.ToString())
180 m_consoleModule = module;
183 m_isGod = m_scene.Permissions.IsGod(agentID);
188 StreamReader reader =
new StreamReader(request);
189 string message = reader.ReadToEnd();
191 OSD osd = OSDParser.DeserializeLLSDXml(message);
193 string cmd = osd.AsString();
194 if (cmd ==
"set console on")
198 MainConsole.Instance.OnOutput += ConsoleSender;
199 m_consoleIsOn =
true;
200 m_consoleModule.SendConsoleOutput(m_agentID,
"Console is now on");
204 else if (cmd ==
"set console off")
206 MainConsole.Instance.OnOutput -= ConsoleSender;
207 m_consoleIsOn =
false;
208 m_consoleModule.SendConsoleOutput(m_agentID,
"Console is now off");
212 if (m_consoleIsOn ==
false && m_consoleModule.RunCommand(osd.AsString().Trim(), m_agentID))
215 if (m_isGod && m_consoleIsOn)
217 MainConsole.Instance.RunCommand(osd.AsString().Trim());
221 m_consoleModule.SendConsoleOutput(m_agentID,
"Unknown command");
227 private void ConsoleSender(
string text)
229 m_consoleModule.SendConsoleOutput(m_agentID, text);
234 if (presence.
UUID == m_agentID)
236 MainConsole.Instance.OnOutput -= ConsoleSender;
237 m_consoleIsOn =
false;
void AddCommand(string module, bool shared, string command, string help, string longhelp, CommandDelegate fn)
override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
delegate void CommandDelegate(string module, string[] cmd)
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
ConsoleMessage OnConsoleMessage
Base streamed request handler.
OpenSim.Framework.Capabilities.Caps Caps
void RemoveRegion(Scene s)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
ConsoleHandler(string path, string name, UUID agentID, RegionConsoleModule module, Scene scene)
bool RunCommand(string command, UUID invokerID)
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
OpenMetaverse.StructuredData.OSD OSD
void RegionLoaded(Scene s)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
OpenSim.Framework.Capabilities.Caps Caps
void AddRegion(Scene s)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void SendConsoleOutput(UUID agentID, string message)
delegate void ConsoleMessage(UUID toAgentID, string message)
void RegisterCaps(UUID agentID, Caps caps)