aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
diff options
context:
space:
mode:
authorAdam Frisby2007-12-03 07:06:46 +0000
committerAdam Frisby2007-12-03 07:06:46 +0000
commit981c97502a25c12473328e332bb0505f8c779d73 (patch)
treef60cf6bfad1350ab5f64dbb68bd2720ed74e20a0 /OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
parent* Applied a few commits left on my laptop to OpenSimController. (diff)
downloadopensim-SC_OLD-981c97502a25c12473328e332bb0505f8c779d73.zip
opensim-SC_OLD-981c97502a25c12473328e332bb0505f8c779d73.tar.gz
opensim-SC_OLD-981c97502a25c12473328e332bb0505f8c779d73.tar.bz2
opensim-SC_OLD-981c97502a25c12473328e332bb0505f8c779d73.tar.xz
* Moved XMLRPC Controller to a Application Plugin. Requires testing.
Diffstat (limited to 'OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs')
-rw-r--r--OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs139
1 files changed, 139 insertions, 0 deletions
diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
new file mode 100644
index 0000000..2566a6b
--- /dev/null
+++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs
@@ -0,0 +1,139 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Net;
5using OpenSim;
6using OpenSim.Framework.Console;
7using OpenSim.Framework;
8using OpenSim.Framework.Servers;
9using Mono.Addins;
10using Mono.Addins.Description;
11using Nini;
12using Nini.Config;
13using Nwc.XmlRpc;
14using System.Collections;
15using System.Timers;
16
17[assembly: Addin]
18[assembly: AddinDependency("OpenSim", "0.4")]
19
20namespace OpenSim.ApplicationPlugins.LoadRegions
21{
22 [Extension("/OpenSim/Startup")]
23 public class RemoteAdminPlugin : IApplicationPlugin
24 {
25 private OpenSimMain m_app;
26 private BaseHttpServer m_httpd;
27
28 public void Initialise(OpenSimMain openSim)
29 {
30 if (openSim.ConfigSource.Configs["RemoteAdmin"].GetBoolean("enabled", false))
31 {
32 System.Console.WriteLine("RADMIN","Remote Admin Plugin Enabled");
33
34 m_app = openSim;
35 m_httpd = openSim.HttpServer;
36
37 m_httpd.AddXmlRPCHandler("admin_create_region", XmlRpcCreateRegionMethod);
38 m_httpd.AddXmlRPCHandler("admin_shutdown", XmlRpcShutdownMethod);
39 }
40 }
41
42 public XmlRpcResponse XmlRpcShutdownMethod(XmlRpcRequest request)
43 {
44 MainLog.Instance.Verbose("CONTROLLER", "Recieved Shutdown Administrator Request");
45 XmlRpcResponse response = new XmlRpcResponse();
46 Hashtable requestData = (Hashtable)request.Params[0];
47
48 if ((string)requestData["shutdown"] == "delayed")
49 {
50 int timeout = (Int32)requestData["milliseconds"];
51
52 Hashtable responseData = new Hashtable();
53 responseData["accepted"] = "true";
54 response.Value = responseData;
55
56 m_app.SceneManager.SendGeneralMessage("Region is going down in " + ((int)(timeout / 1000)).ToString() +
57 " second(s). Please save what you are doing and log out.");
58
59 // Perform shutdown
60 Timer shutdownTimer = new Timer(timeout); // Wait before firing
61 shutdownTimer.AutoReset = false;
62 shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed);
63 shutdownTimer.Start();
64
65 return response;
66 }
67 else
68 {
69 Hashtable responseData = new Hashtable();
70 responseData["accepted"] = "true";
71 response.Value = responseData;
72
73 m_app.SceneManager.SendGeneralMessage("Region is going down now.");
74
75 // Perform shutdown
76 Timer shutdownTimer = new Timer(2000); // Wait 2 seconds before firing
77 shutdownTimer.AutoReset = false;
78 shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed);
79 shutdownTimer.Start();
80
81 return response;
82 }
83 }
84
85 private void shutdownTimer_Elapsed(object sender, ElapsedEventArgs e)
86 {
87 m_app.Shutdown();
88 }
89
90 public XmlRpcResponse XmlRpcCreateRegionMethod(XmlRpcRequest request)
91 {
92 MainLog.Instance.Verbose("CONTROLLER", "Recieved Create Region Administrator Request");
93 XmlRpcResponse response = new XmlRpcResponse();
94 Hashtable requestData = (Hashtable)request.Params[0];
95
96 RegionInfo newRegionData = new RegionInfo();
97
98 try
99 {
100 newRegionData.RegionID = (string)requestData["region_id"];
101 newRegionData.RegionName = (string)requestData["region_name"];
102 newRegionData.RegionLocX = Convert.ToUInt32((Int32)requestData["region_x"]);
103 newRegionData.RegionLocY = Convert.ToUInt32((Int32)requestData["region_y"]);
104
105 // Security risk
106 newRegionData.DataStore = (string)requestData["datastore"];
107
108 newRegionData.InternalEndPoint = new IPEndPoint(
109 IPAddress.Parse((string)requestData["listen_ip"]), 0);
110
111 newRegionData.InternalEndPoint.Port = (Int32)requestData["listen_port"];
112 newRegionData.ExternalHostName = (string)requestData["external_address"];
113
114 newRegionData.MasterAvatarFirstName = (string)requestData["region_master_first"];
115 newRegionData.MasterAvatarLastName = (string)requestData["region_master_last"];
116
117 m_app.CreateRegion(newRegionData);
118
119 Hashtable responseData = new Hashtable();
120 responseData["created"] = "true";
121 response.Value = responseData;
122 }
123 catch (Exception e)
124 {
125 Hashtable responseData = new Hashtable();
126 responseData["created"] = "false";
127 responseData["error"] = e.ToString();
128 response.Value = responseData;
129 }
130
131 return response;
132 }
133
134 public void Close()
135 {
136
137 }
138 }
139} \ No newline at end of file