diff options
Diffstat (limited to 'OpenSim/Grid/GridServer/Main.cs')
-rw-r--r-- | OpenSim/Grid/GridServer/Main.cs | 258 |
1 files changed, 258 insertions, 0 deletions
diff --git a/OpenSim/Grid/GridServer/Main.cs b/OpenSim/Grid/GridServer/Main.cs new file mode 100644 index 0000000..dc5e4fa --- /dev/null +++ b/OpenSim/Grid/GridServer/Main.cs | |||
@@ -0,0 +1,258 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 | |||
29 | using System; | ||
30 | using System.Reflection; | ||
31 | using System.Threading; | ||
32 | using System.Timers; | ||
33 | using OpenSim.Framework.Console; | ||
34 | using OpenSim.Framework.Interfaces; | ||
35 | using OpenSim.Framework.Servers; | ||
36 | using OpenSim.GenericConfig; | ||
37 | using Timer=System.Timers.Timer; | ||
38 | |||
39 | namespace OpenSim.Grid.GridServer | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// </summary> | ||
43 | public class OpenGrid_Main : conscmd_callback | ||
44 | { | ||
45 | private string ConfigDll = "OpenSim.Grid.GridServer.Config.dll"; | ||
46 | private string GridDll = "OpenSim.Framework.Data.MySQL.dll"; | ||
47 | public GridConfig Cfg; | ||
48 | |||
49 | public static OpenGrid_Main thegrid; | ||
50 | protected IGenericConfig localXMLConfig; | ||
51 | |||
52 | public static bool setuponly; | ||
53 | |||
54 | //public LLUUID highestUUID; | ||
55 | |||
56 | // private SimProfileManager m_simProfileManager; | ||
57 | |||
58 | private GridManager m_gridManager; | ||
59 | |||
60 | private LogBase m_console; | ||
61 | |||
62 | [STAThread] | ||
63 | public static void Main(string[] args) | ||
64 | { | ||
65 | if (args.Length > 0) | ||
66 | { | ||
67 | if (args[0] == "-setuponly") setuponly = true; | ||
68 | } | ||
69 | Console.WriteLine("Starting...\n"); | ||
70 | |||
71 | thegrid = new OpenGrid_Main(); | ||
72 | thegrid.Startup(); | ||
73 | |||
74 | thegrid.Work(); | ||
75 | } | ||
76 | |||
77 | private void Work() | ||
78 | { | ||
79 | m_console.Notice("Enter help for a list of commands\n"); | ||
80 | |||
81 | while (true) | ||
82 | { | ||
83 | m_console.MainLogPrompt(); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | private OpenGrid_Main() | ||
88 | { | ||
89 | m_console = new LogBase("opengrid-gridserver-console.log", "OpenGrid", this, false); | ||
90 | MainLog.Instance = m_console; | ||
91 | |||
92 | |||
93 | } | ||
94 | |||
95 | public void managercallback(string cmd) | ||
96 | { | ||
97 | switch (cmd) | ||
98 | { | ||
99 | case "shutdown": | ||
100 | RunCmd("shutdown", new string[0]); | ||
101 | break; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | |||
106 | public void Startup() | ||
107 | { | ||
108 | this.localXMLConfig = new XmlConfig("GridServerConfig.xml"); | ||
109 | this.localXMLConfig.LoadData(); | ||
110 | this.ConfigDB(this.localXMLConfig); | ||
111 | this.localXMLConfig.Close(); | ||
112 | |||
113 | m_console.Verbose( "Main.cs:Startup() - Loading configuration"); | ||
114 | Cfg = this.LoadConfigDll(this.ConfigDll); | ||
115 | Cfg.InitConfig(); | ||
116 | if (setuponly) Environment.Exit(0); | ||
117 | |||
118 | m_console.Verbose( "Main.cs:Startup() - Connecting to Storage Server"); | ||
119 | m_gridManager = new GridManager(); | ||
120 | m_gridManager.AddPlugin(GridDll); // Made of win | ||
121 | m_gridManager.config = Cfg; | ||
122 | |||
123 | m_console.Verbose( "Main.cs:Startup() - Starting HTTP process"); | ||
124 | BaseHttpServer httpServer = new BaseHttpServer(8001); | ||
125 | //GridManagementAgent GridManagerAgent = new GridManagementAgent(httpServer, "gridserver", Cfg.SimSendKey, Cfg.SimRecvKey, managercallback); | ||
126 | |||
127 | httpServer.AddXmlRPCHandler("simulator_login", m_gridManager.XmlRpcSimulatorLoginMethod); | ||
128 | httpServer.AddXmlRPCHandler("simulator_data_request", m_gridManager.XmlRpcSimulatorDataRequestMethod); | ||
129 | httpServer.AddXmlRPCHandler("map_block", m_gridManager.XmlRpcMapBlockMethod); | ||
130 | |||
131 | httpServer.AddStreamHandler(new RestStreamHandler("GET", "/sims/", m_gridManager.RestGetSimMethod )); | ||
132 | httpServer.AddStreamHandler(new RestStreamHandler("POST", "/sims/", m_gridManager.RestSetSimMethod )); | ||
133 | |||
134 | httpServer.AddStreamHandler( new RestStreamHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod )); | ||
135 | httpServer.AddStreamHandler( new RestStreamHandler("POST","/regions/", m_gridManager.RestSetRegionMethod )); | ||
136 | |||
137 | //httpServer.AddRestHandler("GET", "/sims/", m_gridManager.RestGetSimMethod); | ||
138 | //httpServer.AddRestHandler("POST", "/sims/", m_gridManager.RestSetSimMethod); | ||
139 | //httpServer.AddRestHandler("GET", "/regions/", m_gridManager.RestGetRegionMethod); | ||
140 | //httpServer.AddRestHandler("POST", "/regions/", m_gridManager.RestSetRegionMethod); | ||
141 | |||
142 | httpServer.Start(); | ||
143 | |||
144 | m_console.Verbose( "Main.cs:Startup() - Starting sim status checker"); | ||
145 | |||
146 | Timer simCheckTimer = new Timer(3600000 * 3); // 3 Hours between updates. | ||
147 | simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims); | ||
148 | simCheckTimer.Enabled = true; | ||
149 | } | ||
150 | |||
151 | private GridConfig LoadConfigDll(string dllName) | ||
152 | { | ||
153 | Assembly pluginAssembly = Assembly.LoadFrom(dllName); | ||
154 | GridConfig config = null; | ||
155 | |||
156 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
157 | { | ||
158 | if (pluginType.IsPublic) | ||
159 | { | ||
160 | if (!pluginType.IsAbstract) | ||
161 | { | ||
162 | Type typeInterface = pluginType.GetInterface("IGridConfig", true); | ||
163 | |||
164 | if (typeInterface != null) | ||
165 | { | ||
166 | IGridConfig plug = (IGridConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
167 | config = plug.GetConfigObject(); | ||
168 | break; | ||
169 | } | ||
170 | |||
171 | typeInterface = null; | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | pluginAssembly = null; | ||
176 | return config; | ||
177 | } | ||
178 | |||
179 | public void CheckSims(object sender, ElapsedEventArgs e) | ||
180 | { | ||
181 | /* | ||
182 | foreach (SimProfileBase sim in m_simProfileManager.SimProfiles.Values) | ||
183 | { | ||
184 | string SimResponse = ""; | ||
185 | try | ||
186 | { | ||
187 | WebRequest CheckSim = WebRequest.Create("http://" + sim.sim_ip + ":" + sim.sim_port.ToString() + "/checkstatus/"); | ||
188 | CheckSim.Method = "GET"; | ||
189 | CheckSim.ContentType = "text/plaintext"; | ||
190 | CheckSim.ContentLength = 0; | ||
191 | |||
192 | StreamWriter stOut = new StreamWriter(CheckSim.GetRequestStream(), System.Text.Encoding.ASCII); | ||
193 | stOut.Write(""); | ||
194 | stOut.Close(); | ||
195 | |||
196 | StreamReader stIn = new StreamReader(CheckSim.GetResponse().GetResponseStream()); | ||
197 | SimResponse = stIn.ReadToEnd(); | ||
198 | stIn.Close(); | ||
199 | } | ||
200 | catch | ||
201 | { | ||
202 | } | ||
203 | |||
204 | if (SimResponse == "OK") | ||
205 | { | ||
206 | m_simProfileManager.SimProfiles[sim.UUID].online = true; | ||
207 | } | ||
208 | else | ||
209 | { | ||
210 | m_simProfileManager.SimProfiles[sim.UUID].online = false; | ||
211 | } | ||
212 | } | ||
213 | */ | ||
214 | } | ||
215 | |||
216 | public void RunCmd(string cmd, string[] cmdparams) | ||
217 | { | ||
218 | switch (cmd) | ||
219 | { | ||
220 | case "help": | ||
221 | m_console.Notice("shutdown - shutdown the grid (USE CAUTION!)"); | ||
222 | break; | ||
223 | |||
224 | case "shutdown": | ||
225 | m_console.Close(); | ||
226 | Environment.Exit(0); | ||
227 | break; | ||
228 | } | ||
229 | } | ||
230 | |||
231 | public void Show(string ShowWhat) | ||
232 | { | ||
233 | } | ||
234 | |||
235 | private void ConfigDB(IGenericConfig configData) | ||
236 | { | ||
237 | try | ||
238 | { | ||
239 | string attri = ""; | ||
240 | attri = configData.GetAttribute("DataBaseProvider"); | ||
241 | if (attri == "") | ||
242 | { | ||
243 | GridDll = "OpenSim.Framework.Data.DB4o.dll"; | ||
244 | configData.SetAttribute("DataBaseProvider", "OpenSim.Framework.Data.DB4o.dll"); | ||
245 | } | ||
246 | else | ||
247 | { | ||
248 | GridDll = attri; | ||
249 | } | ||
250 | configData.Commit(); | ||
251 | } | ||
252 | catch | ||
253 | { | ||
254 | |||
255 | } | ||
256 | } | ||
257 | } | ||
258 | } | ||