aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices/OpenGridServices.GridServer/Main.cs
diff options
context:
space:
mode:
authorMW2007-05-24 12:35:32 +0000
committerMW2007-05-24 12:35:32 +0000
commitf95b6081cba084d1b067acea99c0effa2b3bf42c (patch)
tree7a7ab4aa037f75afa54f403c701a735acb101575 /OpenGridServices/OpenGridServices.GridServer/Main.cs
parentDie ServiceManager! (Not really Gareth, just the old directory, new directory... (diff)
downloadopensim-SC-f95b6081cba084d1b067acea99c0effa2b3bf42c.zip
opensim-SC-f95b6081cba084d1b067acea99c0effa2b3bf42c.tar.gz
opensim-SC-f95b6081cba084d1b067acea99c0effa2b3bf42c.tar.bz2
opensim-SC-f95b6081cba084d1b067acea99c0effa2b3bf42c.tar.xz
Renamed the new Directories. (removed the "-Source" from the end of them)
Diffstat (limited to 'OpenGridServices/OpenGridServices.GridServer/Main.cs')
-rw-r--r--OpenGridServices/OpenGridServices.GridServer/Main.cs239
1 files changed, 239 insertions, 0 deletions
diff --git a/OpenGridServices/OpenGridServices.GridServer/Main.cs b/OpenGridServices/OpenGridServices.GridServer/Main.cs
new file mode 100644
index 0000000..cad5fae
--- /dev/null
+++ b/OpenGridServices/OpenGridServices.GridServer/Main.cs
@@ -0,0 +1,239 @@
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;
44
45namespace OpenGridServices.GridServer
46{
47 /// <summary>
48 /// </summary>
49 public class OpenGrid_Main : BaseServer, conscmd_callback
50 {
51 private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll";
52 private string GridDll = "OpenGrid.Framework.Data.MySQL.dll";
53 public GridConfig Cfg;
54
55 public static OpenGrid_Main thegrid;
56 public static bool setuponly;
57
58 //public LLUUID highestUUID;
59
60// private SimProfileManager m_simProfileManager;
61
62 private GridManager m_gridManager;
63
64 private ConsoleBase m_console;
65
66 [STAThread]
67 public static void Main(string[] args)
68 {
69 if (args.Length > 0)
70 {
71 if (args[0] == "-setuponly") setuponly = true;
72 }
73 Console.WriteLine("Starting...\n");
74
75 thegrid = new OpenGrid_Main();
76 thegrid.Startup();
77
78 thegrid.Work();
79 }
80
81 private void Work()
82 {
83 while (true)
84 {
85 Thread.Sleep(5000);
86 // should flush the DB etc here
87 }
88 }
89
90 private OpenGrid_Main()
91 {
92 m_console = new ConsoleBase("opengrid-gridserver-console.log", "OpenGrid", this, false);
93 MainConsole.Instance = m_console;
94
95
96 }
97
98 public void managercallback(string cmd) {
99 switch(cmd) {
100 case "shutdown":
101 RunCmd("shutdown",new string[0]);
102 break;
103 }
104 }
105
106
107 public void Startup()
108 {
109 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Loading configuration");
110 Cfg = this.LoadConfigDll(this.ConfigDll);
111 Cfg.InitConfig();
112 if(setuponly) Environment.Exit(0);
113
114 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Connecting to Storage Server");
115 m_gridManager = new GridManager();
116 m_gridManager.AddPlugin(GridDll); // Made of win
117 m_gridManager.config = Cfg;
118
119 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Starting HTTP process");
120 BaseHttpServer httpServer = new BaseHttpServer(8001);
121 GridManagementAgent GridManagerAgent = new GridManagementAgent(httpServer,"gridserver",Cfg.SimSendKey,Cfg.SimRecvKey,managercallback);
122
123 httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcLoginToSimulatorMethod);
124 httpServer.AddXmlRPCHandler("map_block", m_gridManager.XmlRpcMapBlockMethod);
125
126 httpServer.AddRestHandler("GET", "/sims/", m_gridManager.RestGetSimMethod);
127 httpServer.AddRestHandler("POST", "/sims/", m_gridManager.RestSetSimMethod);
128 httpServer.AddRestHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod);
129 httpServer.AddRestHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod);
130
131
132 // lbsa71 : This code snippet taken from old http server.
133 // I have no idea what this was supposed to do - looks like an infinite recursion to me.
134 // case "regions":
135 //// DIRTY HACK ALERT
136 //Console.WriteLine("/regions/ accessed");
137 //TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle((ulong)Convert.ToUInt64(rest_params[1]));
138 //respstring = ParseREST("/regions/" + rest_params[1], requestBody, HTTPmethod);
139 //break;
140
141 // lbsa71 : I guess these were never used?
142 //Listener.Prefixes.Add("http://+:8001/gods/");
143 //Listener.Prefixes.Add("http://+:8001/highestuuid/");
144 //Listener.Prefixes.Add("http://+:8001/uuidblocks/");
145
146 httpServer.Start();
147
148 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.LOW,"Main.cs:Startup() - Starting sim status checker");
149
150 System.Timers.Timer simCheckTimer = new System.Timers.Timer( 300000 ); // 5 minutes
151 simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims);
152 simCheckTimer.Enabled = true;
153 }
154
155 private GridConfig LoadConfigDll(string dllName)
156 {
157 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
158 GridConfig config = null;
159
160 foreach (Type pluginType in pluginAssembly.GetTypes())
161 {
162 if (pluginType.IsPublic)
163 {
164 if (!pluginType.IsAbstract)
165 {
166 Type typeInterface = pluginType.GetInterface("IGridConfig", true);
167
168 if (typeInterface != null)
169 {
170 IGridConfig plug = (IGridConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
171 config = plug.GetConfigObject();
172 break;
173 }
174
175 typeInterface = null;
176 }
177 }
178 }
179 pluginAssembly = null;
180 return config;
181 }
182
183 public void CheckSims(object sender, ElapsedEventArgs e)
184 {
185 /*
186 foreach (SimProfileBase sim in m_simProfileManager.SimProfiles.Values)
187 {
188 string SimResponse = "";
189 try
190 {
191 WebRequest CheckSim = WebRequest.Create("http://" + sim.sim_ip + ":" + sim.sim_port.ToString() + "/checkstatus/");
192 CheckSim.Method = "GET";
193 CheckSim.ContentType = "text/plaintext";
194 CheckSim.ContentLength = 0;
195
196 StreamWriter stOut = new StreamWriter(CheckSim.GetRequestStream(), System.Text.Encoding.ASCII);
197 stOut.Write("");
198 stOut.Close();
199
200 StreamReader stIn = new StreamReader(CheckSim.GetResponse().GetResponseStream());
201 SimResponse = stIn.ReadToEnd();
202 stIn.Close();
203 }
204 catch
205 {
206 }
207
208 if (SimResponse == "OK")
209 {
210 m_simProfileManager.SimProfiles[sim.UUID].online = true;
211 }
212 else
213 {
214 m_simProfileManager.SimProfiles[sim.UUID].online = false;
215 }
216 }
217 */
218 }
219
220 public void RunCmd(string cmd, string[] cmdparams)
221 {
222 switch (cmd)
223 {
224 case "help":
225 m_console.WriteLine(OpenSim.Framework.Console.LogPriority.HIGH,"shutdown - shutdown the grid (USE CAUTION!)");
226 break;
227
228 case "shutdown":
229 m_console.Close();
230 Environment.Exit(0);
231 break;
232 }
233 }
234
235 public void Show(string ShowWhat)
236 {
237 }
238 }
239}