aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices.AssetServer/Main.cs
diff options
context:
space:
mode:
authorgareth2007-04-29 23:58:57 +0000
committergareth2007-04-29 23:58:57 +0000
commit328c9ccb24053b6e8d9d4bba82cec2b433db7bcd (patch)
tree1a9c74e69d3d244b0c58a786296d743aef2572e6 /OpenGridServices.AssetServer/Main.cs
parentBugfixes (diff)
downloadopensim-SC_OLD-328c9ccb24053b6e8d9d4bba82cec2b433db7bcd.zip
opensim-SC_OLD-328c9ccb24053b6e8d9d4bba82cec2b433db7bcd.tar.gz
opensim-SC_OLD-328c9ccb24053b6e8d9d4bba82cec2b433db7bcd.tar.bz2
opensim-SC_OLD-328c9ccb24053b6e8d9d4bba82cec2b433db7bcd.tar.xz
Copied gridserver ready to convert to asset server
I'M THAT NUTS!!!!!!!!
Diffstat (limited to '')
-rw-r--r--OpenGridServices.AssetServer/Main.cs213
1 files changed, 213 insertions, 0 deletions
diff --git a/OpenGridServices.AssetServer/Main.cs b/OpenGridServices.AssetServer/Main.cs
new file mode 100644
index 0000000..69cba9c
--- /dev/null
+++ b/OpenGridServices.AssetServer/Main.cs
@@ -0,0 +1,213 @@
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.Reflection;
36using libsecondlife;
37using OpenSim.Framework;
38using OpenSim.Framework.Sims;
39using OpenSim.Framework.Console;
40using OpenSim.Framework.Interfaces;
41using OpenSim.Servers;
42
43namespace OpenGridServices.GridServer
44{
45 /// <summary>
46 /// </summary>
47 public class OpenGrid_Main : BaseServer, conscmd_callback
48 {
49 private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll";
50 public GridConfig Cfg;
51
52 public static OpenGrid_Main thegrid;
53
54 //public LLUUID highestUUID;
55
56 private SimProfileManager m_simProfileManager;
57
58 private ConsoleBase m_console;
59
60 [STAThread]
61 public static void Main(string[] args)
62 {
63 Console.WriteLine("Starting...\n");
64
65 thegrid = new OpenGrid_Main();
66 thegrid.Startup();
67
68 thegrid.Work();
69 }
70
71 private void Work()
72 {
73 m_console.WriteLine("\nEnter help for a list of commands\n");
74
75 while (true)
76 {
77 m_console.MainConsolePrompt();
78 }
79 }
80
81 private OpenGrid_Main()
82 {
83 m_console = new ConsoleBase("opengrid-gridserver-console.log", "OpenGrid", this, false);
84 MainConsole.Instance = m_console;
85 }
86
87 public void Startup()
88 {
89 m_console.WriteLine("Main.cs:Startup() - Loading configuration");
90 Cfg = this.LoadConfigDll(this.ConfigDll);
91 Cfg.InitConfig();
92
93 m_console.WriteLine("Main.cs:Startup() - Loading sim profiles from database");
94 m_simProfileManager = new SimProfileManager( this );
95 m_simProfileManager.LoadProfiles();
96
97 m_console.WriteLine("Main.cs:Startup() - Starting HTTP process");
98 BaseHttpServer httpServer = new BaseHttpServer(8001);
99
100 httpServer.AddXmlRPCHandler("simulator_login", m_simProfileManager.XmlRpcLoginToSimulatorMethod);
101
102 httpServer.AddRestHandler("GET", "/sims/", m_simProfileManager.RestGetSimMethod);
103 httpServer.AddRestHandler("POST", "/sims/", m_simProfileManager.RestSetSimMethod);
104 httpServer.AddRestHandler("GET", "/regions/", m_simProfileManager.RestGetRegionMethod);
105 httpServer.AddRestHandler("POST", "/regions/", m_simProfileManager.RestSetRegionMethod);
106
107
108 // lbsa71 : This code snippet taken from old http server.
109 // I have no idea what this was supposed to do - looks like an infinite recursion to me.
110 // case "regions":
111 //// DIRTY HACK ALERT
112 //Console.WriteLine("/regions/ accessed");
113 //TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle((ulong)Convert.ToUInt64(rest_params[1]));
114 //respstring = ParseREST("/regions/" + rest_params[1], requestBody, HTTPmethod);
115 //break;
116
117 // lbsa71 : I guess these were never used?
118 //Listener.Prefixes.Add("http://+:8001/gods/");
119 //Listener.Prefixes.Add("http://+:8001/highestuuid/");
120 //Listener.Prefixes.Add("http://+:8001/uuidblocks/");
121
122 httpServer.Start();
123
124 m_console.WriteLine("Main.cs:Startup() - Starting sim status checker");
125
126 Timer simCheckTimer = new Timer( 300000 ); // 5 minutes
127 simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims);
128 simCheckTimer.Enabled = true;
129 }
130
131 private GridConfig LoadConfigDll(string dllName)
132 {
133 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
134 GridConfig config = null;
135
136 foreach (Type pluginType in pluginAssembly.GetTypes())
137 {
138 if (pluginType.IsPublic)
139 {
140 if (!pluginType.IsAbstract)
141 {
142 Type typeInterface = pluginType.GetInterface("IGridConfig", true);
143
144 if (typeInterface != null)
145 {
146 IGridConfig plug = (IGridConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
147 config = plug.GetConfigObject();
148 break;
149 }
150
151 typeInterface = null;
152 }
153 }
154 }
155 pluginAssembly = null;
156 return config;
157 }
158
159 public void CheckSims(object sender, ElapsedEventArgs e)
160 {
161 foreach (SimProfileBase sim in m_simProfileManager.SimProfiles.Values)
162 {
163 string SimResponse = "";
164 try
165 {
166 WebRequest CheckSim = WebRequest.Create("http://" + sim.sim_ip + ":" + sim.sim_port.ToString() + "/checkstatus/");
167 CheckSim.Method = "GET";
168 CheckSim.ContentType = "text/plaintext";
169 CheckSim.ContentLength = 0;
170
171 StreamWriter stOut = new StreamWriter(CheckSim.GetRequestStream(), System.Text.Encoding.ASCII);
172 stOut.Write("");
173 stOut.Close();
174
175 StreamReader stIn = new StreamReader(CheckSim.GetResponse().GetResponseStream());
176 SimResponse = stIn.ReadToEnd();
177 stIn.Close();
178 }
179 catch
180 {
181 }
182
183 if (SimResponse == "OK")
184 {
185 m_simProfileManager.SimProfiles[sim.UUID].online = true;
186 }
187 else
188 {
189 m_simProfileManager.SimProfiles[sim.UUID].online = false;
190 }
191 }
192 }
193
194 public void RunCmd(string cmd, string[] cmdparams)
195 {
196 switch (cmd)
197 {
198 case "help":
199 m_console.WriteLine("shutdown - shutdown the grid (USE CAUTION!)");
200 break;
201
202 case "shutdown":
203 m_console.Close();
204 Environment.Exit(0);
205 break;
206 }
207 }
208
209 public void Show(string ShowWhat)
210 {
211 }
212 }
213}