aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices/OpenGridServices.GridServer/Main.cs
diff options
context:
space:
mode:
authorMW2007-05-26 13:40:19 +0000
committerMW2007-05-26 13:40:19 +0000
commit3436961bb5c01d659d09be134368f4f69460cef9 (patch)
tree3753ba4d7818df2a6bce0bbe863ff033cdfd568a /OpenGridServices/OpenGridServices.GridServer/Main.cs
downloadopensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.zip
opensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.tar.gz
opensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.tar.bz2
opensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.tar.xz
Start of rewrite 5279!
Diffstat (limited to 'OpenGridServices/OpenGridServices.GridServer/Main.cs')
-rw-r--r--OpenGridServices/OpenGridServices.GridServer/Main.cs272
1 files changed, 272 insertions, 0 deletions
diff --git a/OpenGridServices/OpenGridServices.GridServer/Main.cs b/OpenGridServices/OpenGridServices.GridServer/Main.cs
new file mode 100644
index 0000000..8baf293
--- /dev/null
+++ b/OpenGridServices/OpenGridServices.GridServer/Main.cs
@@ -0,0 +1,272 @@
1/*
2Copyright (c) OpenSim project, http://osgrid.org/
3
4
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30using System;
31using System.IO;
32using System.Text;
33using System.Timers;
34using System.Net;
35using System.Threading;
36using System.Reflection;
37using libsecondlife;
38using OpenGrid.Framework.Manager;
39using OpenSim.Framework;
40using OpenSim.Framework.Sims;
41using OpenSim.Framework.Console;
42using OpenSim.Framework.Interfaces;
43using OpenSim.Servers;
44using OpenSim.GenericConfig;
45
46namespace OpenGridServices.GridServer
47{
48 /// <summary>
49 /// </summary>
50 public class OpenGrid_Main : BaseServer, conscmd_callback
51 {
52 private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll";
53 private string GridDll = "OpenGrid.Framework.Data.DB4o.dll";
54 public GridConfig Cfg;
55
56 public static OpenGrid_Main thegrid;
57 protected IGenericConfig localXMLConfig;
58
59 public static bool setuponly;
60
61 //public LLUUID highestUUID;
62
63 // private SimProfileManager m_simProfileManager;
64
65 private GridManager m_gridManager;
66
67 private ConsoleBase m_console;
68
69 [STAThread]
70 public static void Main(string[] args)
71 {
72 if (args.Length > 0)
73 {
74 if (args[0] == "-setuponly") setuponly = true;
75 }
76 Console.WriteLine("Starting...\n");
77
78 thegrid = new OpenGrid_Main();
79 thegrid.Startup();
80
81 thegrid.Work();
82 }
83
84 private void Work()
85 {
86 while (true)
87 {
88 Thread.Sleep(5000);
89 // should flush the DB etc here
90 }
91 }
92
93 private OpenGrid_Main()
94 {
95 m_console = new ConsoleBase("opengrid-gridserver-console.log", "OpenGrid", this, false);
96 MainConsole.Instance = m_console;
97
98
99 }
100
101 public void managercallback(string cmd)
102 {
103 switch (cmd)
104 {
105 case "shutdown":
106 RunCmd("shutdown", new string[0]);
107 break;
108 }
109 }
110
111
112 public void Startup()
113 {
114 this.localXMLConfig = new XmlConfig("GridServerConfig.xml");
115 this.localXMLConfig.LoadData();
116 this.ConfigDB(this.localXMLConfig);
117 this.localXMLConfig.Close();
118
119 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Loading configuration");
120 Cfg = this.LoadConfigDll(this.ConfigDll);
121 Cfg.InitConfig();
122 if (setuponly) Environment.Exit(0);
123
124 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Connecting to Storage Server");
125 m_gridManager = new GridManager();
126 m_gridManager.AddPlugin(GridDll); // Made of win
127 m_gridManager.config = Cfg;
128
129 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Starting HTTP process");
130 BaseHttpServer httpServer = new BaseHttpServer(8001);
131 GridManagementAgent GridManagerAgent = new GridManagementAgent(httpServer, "gridserver", Cfg.SimSendKey, Cfg.SimRecvKey, managercallback);
132
133 httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcLoginToSimulatorMethod);
134 httpServer.AddXmlRPCHandler("map_block", m_gridManager.XmlRpcMapBlockMethod);
135
136 httpServer.AddRestHandler("GET", "/sims/", m_gridManager.RestGetSimMethod);
137 httpServer.AddRestHandler("POST", "/sims/", m_gridManager.RestSetSimMethod);
138 httpServer.AddRestHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod);
139 httpServer.AddRestHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod);
140
141
142 // lbsa71 : This code snippet taken from old http server.
143 // I have no idea what this was supposed to do - looks like an infinite recursion to me.
144 // case "regions":
145 //// DIRTY HACK ALERT
146 //Console.WriteLine("/regions/ accessed");
147 //TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle((ulong)Convert.ToUInt64(rest_params[1]));
148 //respstring = ParseREST("/regions/" + rest_params[1], requestBody, HTTPmethod);
149 //break;
150
151 // lbsa71 : I guess these were never used?
152 //Listener.Prefixes.Add("http://+:8001/gods/");
153 //Listener.Prefixes.Add("http://+:8001/highestuuid/");
154 //Listener.Prefixes.Add("http://+:8001/uuidblocks/");
155
156 httpServer.Start();
157
158 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW, "Main.cs:Startup() - Starting sim status checker");
159
160 System.Timers.Timer simCheckTimer = new System.Timers.Timer(300000); // 5 minutes
161 simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims);
162 simCheckTimer.Enabled = true;
163 }
164
165 private GridConfig LoadConfigDll(string dllName)
166 {
167 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
168 GridConfig config = null;
169
170 foreach (Type pluginType in pluginAssembly.GetTypes())
171 {
172 if (pluginType.IsPublic)
173 {
174 if (!pluginType.IsAbstract)
175 {
176 Type typeInterface = pluginType.GetInterface("IGridConfig", true);
177
178 if (typeInterface != null)
179 {
180 IGridConfig plug = (IGridConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
181 config = plug.GetConfigObject();
182 break;
183 }
184
185 typeInterface = null;
186 }
187 }
188 }
189 pluginAssembly = null;
190 return config;
191 }
192
193 public void CheckSims(object sender, ElapsedEventArgs e)
194 {
195 /*
196 foreach (SimProfileBase sim in m_simProfileManager.SimProfiles.Values)
197 {
198 string SimResponse = "";
199 try
200 {
201 WebRequest CheckSim = WebRequest.Create("http://" + sim.sim_ip + ":" + sim.sim_port.ToString() + "/checkstatus/");
202 CheckSim.Method = "GET";
203 CheckSim.ContentType = "text/plaintext";
204 CheckSim.ContentLength = 0;
205
206 StreamWriter stOut = new StreamWriter(CheckSim.GetRequestStream(), System.Text.Encoding.ASCII);
207 stOut.Write("");
208 stOut.Close();
209
210 StreamReader stIn = new StreamReader(CheckSim.GetResponse().GetResponseStream());
211 SimResponse = stIn.ReadToEnd();
212 stIn.Close();
213 }
214 catch
215 {
216 }
217
218 if (SimResponse == "OK")
219 {
220 m_simProfileManager.SimProfiles[sim.UUID].online = true;
221 }
222 else
223 {
224 m_simProfileManager.SimProfiles[sim.UUID].online = false;
225 }
226 }
227 */
228 }
229
230 public void RunCmd(string cmd, string[] cmdparams)
231 {
232 switch (cmd)
233 {
234 case "help":
235 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH, "shutdown - shutdown the grid (USE CAUTION!)");
236 break;
237
238 case "shutdown":
239 m_console.Close();
240 Environment.Exit(0);
241 break;
242 }
243 }
244
245 public void Show(string ShowWhat)
246 {
247 }
248
249 private void ConfigDB(IGenericConfig configData)
250 {
251 try
252 {
253 string attri = "";
254 attri = configData.GetAttribute("DataBaseProvider");
255 if (attri == "")
256 {
257 GridDll = "OpenGrid.Framework.Data.DB4o.dll";
258 configData.SetAttribute("DataBaseProvider", "OpenGrid.Framework.Data.DB4o.dll");
259 }
260 else
261 {
262 GridDll = attri;
263 }
264 configData.Commit();
265 }
266 catch (Exception e)
267 {
268
269 }
270 }
271 }
272}