aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/Main.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Main.cs338
1 files changed, 0 insertions, 338 deletions
diff --git a/src/Main.cs b/src/Main.cs
deleted file mode 100644
index a738d03..0000000
--- a/src/Main.cs
+++ /dev/null
@@ -1,338 +0,0 @@
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.Text;
32using System.IO;
33using System.Threading;
34using System.Net;
35using System.Net.Sockets;
36using System.Timers;
37using System.Reflection;
38using System.Collections;
39using System.Collections.Generic;
40using libsecondlife;
41using libsecondlife.Packets;
42using OpenSim.world;
43using OpenSim.GridServers;
44using OpenSim.Assets;
45using ServerConsole;
46using PhysicsSystem;
47
48namespace OpenSim
49{
50 /// <summary>
51 /// Description of MainForm.
52 /// </summary>
53 public class OpenSim_Main
54 {
55 public static OpenSim_Main sim;
56 public static SimConfig cfg;
57 public static World local_world;
58 public static Grid gridServers;
59 public static SimCAPSHTTPServer http_server;
60
61 public static Socket Server;
62 private static IPEndPoint ServerIncoming;
63 private static byte[] RecvBuffer = new byte[4096];
64 private byte[] ZeroBuffer = new byte[8192];
65 private static IPEndPoint ipeSender;
66 private static EndPoint epSender;
67 private static AsyncCallback ReceivedData;
68
69 public AssetCache assetCache;
70 public DateTime startuptime;
71 public Dictionary<EndPoint, OpenSimClient> ClientThreads = new Dictionary<EndPoint, OpenSimClient>();
72 private PhysicsManager physManager;
73 private System.Timers.Timer timer1 = new System.Timers.Timer();
74 private string ConfigDll = "SimConfig.dll";
75 private string _physicsEngine = "PhysX";
76 public bool sandbox = false;
77 public bool loginserver = false;
78
79 [STAThread]
80 public static void Main( string[] args )
81 {
82 Console.WriteLine("OpenSim " + VersionInfo.Version + "\n");
83 Console.WriteLine("Starting...\n");
84 ServerConsole.MainConsole.Instance = new MServerConsole(ServerConsole.ConsoleBase.ConsoleType.Local,"",0);
85
86 sim = new OpenSim_Main();
87
88 sim.sandbox = false;
89 sim.loginserver = false;
90 sim._physicsEngine = "PhysX";
91
92 for (int i = 0; i < args.Length; i++)
93 {
94 if(args[i] == "-sandbox")
95 {
96 sim.sandbox = true;
97 }
98
99 if(args[i] == "-loginserver")
100 {
101 sim.loginserver = true;
102 }
103 if(args[i] == "-realphysx")
104 {
105 sim._physicsEngine = "RealPhysX";
106 OpenSim.world.Avatar.PhysicsEngineFlying = true;
107 }
108 }
109
110 OpenSim_Main.gridServers = new Grid();
111 if(sim.sandbox)
112 {
113 OpenSim_Main.gridServers.AssetDll = "LocalGridServers.dll";
114 OpenSim_Main.gridServers.GridDll = "LocalGridServers.dll";
115 OpenSim_Main.gridServers.LoadPlugins();
116 ServerConsole.MainConsole.Instance.WriteLine("Starting in Sandbox mode");
117 }
118 else
119 {
120 OpenSim_Main.gridServers.AssetDll = "RemoteGridServers.dll";
121 OpenSim_Main.gridServers.GridDll = "RemoteGridServers.dll";
122 OpenSim_Main.gridServers.LoadPlugins();
123 ServerConsole.MainConsole.Instance.WriteLine("Starting in Grid mode");
124 }
125
126 if(sim.loginserver && sim.sandbox)
127 {
128 LoginServer loginServer = new LoginServer(OpenSim_Main.gridServers.GridServer);
129 loginServer.Startup();
130 }
131 sim.assetCache = new AssetCache(OpenSim_Main.gridServers.AssetServer);
132
133 sim.Startup();
134
135 while(true) {
136 ServerConsole.MainConsole.Instance.MainConsolePrompt();
137 }
138 }
139
140 private OpenSim_Main() {
141 }
142
143 private void Startup() {
144 startuptime=DateTime.Now;
145
146 // We check our local database first, then the grid for config options
147 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Loading configuration");
148 cfg = this.LoadConfigDll(this.ConfigDll);
149 cfg.InitConfig();
150 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Contacting gridserver");
151 cfg.LoadFromGrid();
152
153 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - We are " + cfg.RegionName + " at " + cfg.RegionLocX.ToString() + "," + cfg.RegionLocY.ToString());
154 ServerConsole.MainConsole.Instance.WriteLine("Initialising world");
155 local_world = cfg.LoadWorld();
156
157 this.physManager = new PhysicsSystem.PhysicsManager();
158 this.physManager.LoadPlugins();
159 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting up messaging system");
160 local_world.PhysScene = this.physManager.GetPhysicsScene(this._physicsEngine); //should be reading from the config file what physics engine to use
161 local_world.PhysScene.SetTerrain(local_world.LandMap);
162
163 OpenSim_Main.gridServers.AssetServer.SetServerInfo(OpenSim_Main.cfg.AssetURL, OpenSim_Main.cfg.AssetSendKey);
164 OpenSim_Main.gridServers.GridServer.SetServerInfo(OpenSim_Main.cfg.GridURL, OpenSim_Main.cfg.GridSendKey, OpenSim_Main.cfg.GridRecvKey, OpenSim_Main.cfg.UserURL, OpenSim_Main.cfg.UserSendKey, OpenSim_Main.cfg.UserRecvKey);
165
166 local_world.LoadStorageDLL("Db4LocalStorage.dll"); //all these dll names shouldn't be hard coded.
167 local_world.LoadPrimsFromStorage();
168
169 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting CAPS HTTP server");
170 http_server = new SimCAPSHTTPServer();
171
172 timer1.Enabled = true;
173 timer1.Interval = 100;
174 timer1.Elapsed += new ElapsedEventHandler(this.Timer1Tick);
175
176 MainServerListener();
177
178 }
179
180 private SimConfig LoadConfigDll(string dllName)
181 {
182 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
183 SimConfig config = null;
184
185 foreach (Type pluginType in pluginAssembly.GetTypes())
186 {
187 if (pluginType.IsPublic)
188 {
189 if (!pluginType.IsAbstract)
190 {
191 Type typeInterface = pluginType.GetInterface("ISimConfig", true);
192
193 if (typeInterface != null)
194 {
195 ISimConfig plug = (ISimConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
196 config = plug.GetConfigObject();
197 break;
198 }
199
200 typeInterface = null;
201 }
202 }
203 }
204 pluginAssembly = null;
205 return config;
206 }
207
208 private void OnReceivedData(IAsyncResult result) {
209 ipeSender = new IPEndPoint(IPAddress.Any, 0);
210 epSender = (EndPoint)ipeSender;
211 Packet packet = null;
212 int numBytes = Server.EndReceiveFrom(result, ref epSender);
213 int packetEnd = numBytes - 1;
214 packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
215
216 // This is either a new client or a packet to send to an old one
217 if(ClientThreads.ContainsKey(epSender)) {
218 ClientThreads[epSender].InPacket(packet);
219 } else if( packet.Type == PacketType.UseCircuitCode ) { // new client
220 OpenSimClient newuser = new OpenSimClient(epSender,(UseCircuitCodePacket)packet);
221 ClientThreads.Add(epSender, newuser);
222 } else { // invalid client
223 Console.Error.WriteLine("Main.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString());
224 }
225 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
226 }
227
228 private void MainServerListener() {
229 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - New thread started");
230 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - Opening UDP socket on " + cfg.IPListenAddr + ":" + cfg.IPListenPort);
231
232 ServerIncoming = new IPEndPoint(IPAddress.Any, cfg.IPListenPort);
233 Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
234 Server.Bind(ServerIncoming);
235
236 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - UDP socket bound, getting ready to listen");
237
238 ipeSender = new IPEndPoint(IPAddress.Any, 0);
239 epSender = (EndPoint) ipeSender;
240 ReceivedData = new AsyncCallback(this.OnReceivedData);
241 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
242
243 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - Listening...");
244
245 }
246
247 public static void Shutdown() {
248 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Closing all threads");
249 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Killing listener thread");
250 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Killing clients");
251 // IMPLEMENT THIS
252 ServerConsole.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Closing console and terminating");
253 OpenSim_Main.local_world.Close();
254 ServerConsole.MainConsole.Instance.Close();
255 Environment.Exit(0);
256 }
257
258 void Timer1Tick( object sender, System.EventArgs e )
259 {
260
261 local_world.Update();
262 }
263 }
264
265 public class Grid
266 {
267 public IAssetServer AssetServer;
268 public IGridServer GridServer;
269 public string AssetDll = "";
270 public string GridDll = "";
271
272 public Grid()
273 {
274 }
275
276 public void LoadPlugins()
277 {
278 this.AssetServer = this.LoadAssetDll(this.AssetDll);
279 this.GridServer = this.LoadGridDll(this.GridDll);
280 }
281
282 private IAssetServer LoadAssetDll(string dllName)
283 {
284 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
285 IAssetServer server = null;
286
287 foreach (Type pluginType in pluginAssembly.GetTypes())
288 {
289 if (pluginType.IsPublic)
290 {
291 if (!pluginType.IsAbstract)
292 {
293 Type typeInterface = pluginType.GetInterface("IAssetPlugin", true);
294
295 if (typeInterface != null)
296 {
297 IAssetPlugin plug = (IAssetPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
298 server = plug.GetAssetServer();
299 break;
300 }
301
302 typeInterface = null;
303 }
304 }
305 }
306 pluginAssembly = null;
307 return server;
308 }
309
310 private IGridServer LoadGridDll(string dllName)
311 {
312 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
313 IGridServer server = null;
314
315 foreach (Type pluginType in pluginAssembly.GetTypes())
316 {
317 if (pluginType.IsPublic)
318 {
319 if (!pluginType.IsAbstract)
320 {
321 Type typeInterface = pluginType.GetInterface("IGridPlugin", true);
322
323 if (typeInterface != null)
324 {
325 IGridPlugin plug = (IGridPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
326 server = plug.GetGridServer();
327 break;
328 }
329
330 typeInterface = null;
331 }
332 }
333 }
334 pluginAssembly = null;
335 return server;
336 }
337 }
338}