aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/GridServer/GridServerBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Grid/GridServer/GridServerBase.cs')
-rw-r--r--OpenSim/Grid/GridServer/GridServerBase.cs179
1 files changed, 179 insertions, 0 deletions
diff --git a/OpenSim/Grid/GridServer/GridServerBase.cs b/OpenSim/Grid/GridServer/GridServerBase.cs
new file mode 100644
index 0000000..592883a
--- /dev/null
+++ b/OpenSim/Grid/GridServer/GridServerBase.cs
@@ -0,0 +1,179 @@
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 OpenSim 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*/
28
29using System;
30using System.IO;
31using System.Timers;
32using OpenSim.Framework;
33using OpenSim.Framework.Console;
34using OpenSim.Framework.Servers;
35
36namespace OpenSim.Grid.GridServer
37{
38 /// <summary>
39 /// </summary>
40 public class GridServerBase : BaseOpenSimServer, conscmd_callback
41 {
42 private GridConfig m_config;
43 private GridManager m_gridManager;
44
45 public void Work()
46 {
47 m_console.Notice("Enter help for a list of commands\n");
48
49 while (true)
50 {
51 m_console.Prompt();
52 }
53 }
54
55 public GridServerBase( )
56 {
57 m_console = new ConsoleBase("OpenGrid", this);
58 MainConsole.Instance = m_console;
59 }
60
61 public void managercallback(string cmd)
62 {
63 switch (cmd)
64 {
65 case "shutdown":
66 RunCmd("shutdown", new string[0]);
67 break;
68 }
69 }
70
71 public void Startup()
72 {
73 m_console.Status("Starting...\n");
74
75 Config();
76
77 SetupGridManager();
78
79 m_console.Status("[GRID]: Starting HTTP process");
80 BaseHttpServer httpServer = new BaseHttpServer(m_config.HttpPort);
81 //GridManagementAgent GridManagerAgent = new GridManagementAgent(httpServer, "gridserver", m_config.SimSendKey, m_config.SimRecvKey, managercallback);
82
83 httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcSimulatorLoginMethod);
84 httpServer.AddXmlRPCHandler("simulator_data_request", m_gridManager.XmlRpcSimulatorDataRequestMethod);
85 httpServer.AddXmlRPCHandler("simulator_after_region_moved", m_gridManager.XmlRpcDeleteRegionMethod);
86 httpServer.AddXmlRPCHandler("map_block", m_gridManager.XmlRpcMapBlockMethod);
87
88 // Message Server ---> Grid Server
89 httpServer.AddXmlRPCHandler("register_messageserver", m_gridManager.XmlRPCRegisterMessageServer);
90 httpServer.AddXmlRPCHandler("deregister_messageserver", m_gridManager.XmlRPCDeRegisterMessageServer);
91
92 httpServer.AddStreamHandler(new RestStreamHandler("GET", "/sims/", m_gridManager.RestGetSimMethod));
93 httpServer.AddStreamHandler(new RestStreamHandler("POST", "/sims/", m_gridManager.RestSetSimMethod));
94
95 httpServer.AddStreamHandler(new RestStreamHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod));
96 httpServer.AddStreamHandler(new RestStreamHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod));
97
98 //httpServer.AddRestHandler("GET", "/sims/", m_gridManager.RestGetSimMethod);
99 //httpServer.AddRestHandler("POST", "/sims/", m_gridManager.RestSetSimMethod);
100 //httpServer.AddRestHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod);
101 //httpServer.AddRestHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod);
102
103 httpServer.Start();
104
105 m_console.Status("[GRID]: Starting sim status checker");
106
107 Timer simCheckTimer = new Timer(3600000*3); // 3 Hours between updates.
108 simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims);
109 simCheckTimer.Enabled = true;
110 }
111
112 protected virtual void SetupGridManager()
113 {
114 m_console.Status("[GRID]: Connecting to Storage Server");
115 m_gridManager = new GridManager();
116 m_gridManager.AddPlugin(m_config.DatabaseProvider);
117 m_gridManager.Config = m_config;
118 }
119
120 public void Config()
121 {
122 m_config = new GridConfig("GRID SERVER", (Path.Combine(Util.configDir(), "GridServer_Config.xml")));
123 }
124
125 public void CheckSims(object sender, ElapsedEventArgs e)
126 {
127 /*
128 foreach (SimProfileBase sim in m_simProfileManager.SimProfiles.Values)
129 {
130 string SimResponse = String.Empty;
131 try
132 {
133 WebRequest CheckSim = WebRequest.Create("http://" + sim.sim_ip + ":" + sim.sim_port.ToString() + "/checkstatus/");
134 CheckSim.Method = "GET";
135 CheckSim.ContentType = "text/plaintext";
136 CheckSim.ContentLength = 0;
137
138 StreamWriter stOut = new StreamWriter(CheckSim.GetRequestStream(), System.Text.Encoding.ASCII);
139 stOut.Write(String.Empty);
140 stOut.Close();
141
142 StreamReader stIn = new StreamReader(CheckSim.GetResponse().GetResponseStream());
143 SimResponse = stIn.ReadToEnd();
144 stIn.Close();
145 }
146 catch
147 {
148 }
149
150 if (SimResponse == "OK")
151 {
152 m_simProfileManager.SimProfiles[sim.UUID].online = true;
153 }
154 else
155 {
156 m_simProfileManager.SimProfiles[sim.UUID].online = false;
157 }
158 }
159 */
160 }
161
162 public override void RunCmd(string cmd, string[] cmdparams)
163 {
164 base.RunCmd(cmd, cmdparams);
165
166 switch (cmd)
167 {
168 case "help":
169 m_console.Notice("shutdown - shutdown the grid (USE CAUTION!)");
170 break;
171
172 case "shutdown":
173 m_console.Close();
174 Environment.Exit(0);
175 break;
176 }
177 }
178 }
179}