aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Application/OpenSimController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Application/OpenSimController.cs')
-rw-r--r--OpenSim/Region/Application/OpenSimController.cs132
1 files changed, 132 insertions, 0 deletions
diff --git a/OpenSim/Region/Application/OpenSimController.cs b/OpenSim/Region/Application/OpenSimController.cs
new file mode 100644
index 0000000..14e4a4c
--- /dev/null
+++ b/OpenSim/Region/Application/OpenSimController.cs
@@ -0,0 +1,132 @@
1using System;
2using System.Collections.Generic;
3using System.Collections;
4using System.IO;
5using System.Text;
6using Nini.Config;
7using OpenSim.Framework.Communications.Cache;
8using OpenSim.Framework.Console;
9using OpenSim.Framework.Interfaces;
10using OpenSim.Framework.Servers;
11using OpenSim.Framework.Types;
12using OpenSim.Framework.Utilities;
13using OpenSim.Region.ClientStack;
14using OpenSim.Region.Communications.Local;
15using OpenSim.Region.Communications.OGS1;
16using OpenSim.Region.Environment;
17using OpenSim.Region.Environment.Scenes;
18using OpenSim.Region.Physics.Manager;
19using System.Globalization;
20using Nwc.XmlRpc;
21using RegionInfo = OpenSim.Framework.Types.RegionInfo;
22
23namespace OpenSim
24{
25 class OpenSimController
26 {
27 private OpenSimMain m_app;
28 private BaseHttpServer m_httpServer;
29 private const bool m_enablexmlrpc = false;
30
31 public OpenSimController(OpenSimMain core, BaseHttpServer httpd)
32 {
33 m_app = core;
34 m_httpServer = httpd;
35
36 if (m_enablexmlrpc)
37 {
38 m_httpServer.AddXmlRPCHandler("admin_create_region", XmlRpcCreateRegionMethod);
39 m_httpServer.AddXmlRPCHandler("admin_shutdown", XmlRpcShutdownMethod);
40 }
41 }
42
43 public XmlRpcResponse XmlRpcShutdownMethod(XmlRpcRequest request)
44 {
45 MainLog.Instance.Verbose("CONTROLLER", "Recieved Shutdown Administrator Request");
46 XmlRpcResponse response = new XmlRpcResponse();
47 Hashtable requestData = (Hashtable)request.Params[0];
48
49 if ((string)requestData["shutdown"] == "delayed")
50 {
51 int timeout = Convert.ToInt32((string)requestData["milliseconds"]);
52
53 Hashtable responseData = new Hashtable();
54 responseData["accepted"] = "true";
55 response.Value = responseData;
56
57 m_app.SceneManager.SendGeneralMessage("Region is going down in " + ((int)(timeout / 1000)).ToString() + " second(s). Please save what you are doing and log out.");
58
59 // Perform shutdown
60 System.Timers.Timer shutdownTimer = new System.Timers.Timer(timeout); // Wait before firing
61 shutdownTimer.AutoReset = false;
62 shutdownTimer.Elapsed += new System.Timers.ElapsedEventHandler(shutdownTimer_Elapsed);
63
64 return response;
65 }
66 else
67 {
68 Hashtable responseData = new Hashtable();
69 responseData["accepted"] = "true";
70 response.Value = responseData;
71
72 m_app.SceneManager.SendGeneralMessage("Region is going down now.");
73
74 // Perform shutdown
75 System.Timers.Timer shutdownTimer = new System.Timers.Timer(2000); // Wait 2 seconds before firing
76 shutdownTimer.AutoReset = false;
77 shutdownTimer.Elapsed += new System.Timers.ElapsedEventHandler(shutdownTimer_Elapsed);
78
79 return response;
80 }
81 }
82
83 void shutdownTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
84 {
85 m_app.Shutdown();
86 }
87
88 public XmlRpcResponse XmlRpcCreateRegionMethod(XmlRpcRequest request)
89 {
90 MainLog.Instance.Verbose("CONTROLLER", "Recieved Create Region Administrator Request");
91 XmlRpcResponse response = new XmlRpcResponse();
92 Hashtable requestData = (Hashtable)request.Params[0];
93
94 RegionInfo newRegionData = new RegionInfo();
95
96 try
97 {
98 newRegionData.RegionID = (string)requestData["region_id"];
99 newRegionData.RegionName = (string)requestData["region_name"];
100 newRegionData.RegionLocX = Convert.ToUInt32((string)requestData["region_x"]);
101 newRegionData.RegionLocY = Convert.ToUInt32((string)requestData["region_y"]);
102
103 // Security risk
104 newRegionData.DataStore = (string)requestData["datastore"];
105
106 newRegionData.InternalEndPoint = new System.Net.IPEndPoint(
107 System.Net.IPAddress.Parse((string)requestData["listen_ip"]), 0);
108
109 newRegionData.InternalEndPoint.Port = Convert.ToInt32((string)requestData["listen_port"]);
110 newRegionData.ExternalHostName = (string)requestData["external_address"];
111
112 newRegionData.MasterAvatarFirstName = (string)requestData["region_master_first"];
113 newRegionData.MasterAvatarLastName = (string)requestData["region_master_last"];
114
115 m_app.CreateRegion(newRegionData);
116
117 Hashtable responseData = new Hashtable();
118 responseData["created"] = "true";
119 response.Value = responseData;
120 }
121 catch (Exception e)
122 {
123 Hashtable responseData = new Hashtable();
124 responseData["created"] = "false";
125 responseData["error"] = e.ToString();
126 response.Value = responseData;
127 }
128
129 return response;
130 }
131 }
132}