aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.RegionServer/OpenSimMain.cs
diff options
context:
space:
mode:
authorgareth2007-03-22 10:11:15 +0000
committergareth2007-03-22 10:11:15 +0000
commit7daa3955bc3a1918e40962851f9e8d38597a245e (patch)
treebee3e1372a7eed0c1b220a8a49f7bee7d29a6b91 /OpenSim.RegionServer/OpenSimMain.cs
parentLoad XML for neighbourinfo from grid (diff)
downloadopensim-SC-7daa3955bc3a1918e40962851f9e8d38597a245e.zip
opensim-SC-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.gz
opensim-SC-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.bz2
opensim-SC-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.xz
brought zircon branch into trunk
Diffstat (limited to 'OpenSim.RegionServer/OpenSimMain.cs')
-rw-r--r--OpenSim.RegionServer/OpenSimMain.cs320
1 files changed, 320 insertions, 0 deletions
diff --git a/OpenSim.RegionServer/OpenSimMain.cs b/OpenSim.RegionServer/OpenSimMain.cs
new file mode 100644
index 0000000..b2bc0b3
--- /dev/null
+++ b/OpenSim.RegionServer/OpenSimMain.cs
@@ -0,0 +1,320 @@
1/*
2Copyright (c) OpenSim project, http://osgrid.org/
3
4* All rights reserved.
5*
6* Redistribution and use in source and binary forms, with or without
7* modification, are permitted provided that the following conditions are met:
8* * Redistributions of source code must retain the above copyright
9* notice, this list of conditions and the following disclaimer.
10* * Redistributions in binary form must reproduce the above copyright
11* notice, this list of conditions and the following disclaimer in the
12* documentation and/or other materials provided with the distribution.
13* * Neither the name of the <organization> nor the
14* names of its contributors may be used to endorse or promote products
15* derived from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
18* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
21* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29using System;
30using System.Text;
31using System.IO;
32using System.Threading;
33using System.Net;
34using System.Net.Sockets;
35using System.Timers;
36using System.Reflection;
37using System.Collections;
38using System.Collections.Generic;
39using libsecondlife;
40using libsecondlife.Packets;
41using OpenSim.world;
42using OpenSim.Framework.Interfaces;
43using OpenSim.UserServer;
44using OpenSim.Assets;
45using OpenSim.CAPS;
46using OpenSim.Framework.Console;
47using OpenSim.Physics.Manager;
48
49namespace OpenSim
50{
51 /// <summary>
52 ///
53 /// </summary>
54 public class OpenSimMain : OpenSimApplication
55 {
56 private Dictionary<EndPoint, uint> clientCircuits = new Dictionary<EndPoint, uint>();
57 private PhysicsManager physManager;
58
59 public Socket Server;
60 private IPEndPoint ServerIncoming;
61 private byte[] RecvBuffer = new byte[4096];
62 private byte[] ZeroBuffer = new byte[8192];
63 private IPEndPoint ipeSender;
64 private EndPoint epSender;
65 private AsyncCallback ReceivedData;
66
67 private System.Timers.Timer timer1 = new System.Timers.Timer();
68 private string ConfigDll = "OpenSim.Config.SimConfigDb4o.dll";
69 private string _physicsEngine = "basicphysics";
70 public bool sandbox = false;
71 public bool loginserver = false;
72
73 [STAThread]
74 public static void Main(string[] args)
75 {
76 Console.WriteLine("OpenSim " + VersionInfo.Version + "\n");
77 Console.WriteLine("Starting...\n");
78 OpenSim.Framework.Console.MainConsole.Instance = new SimConsole(OpenSim.Framework.Console.ConsoleBase.ConsoleType.Local, "", 0);
79
80 //OpenSimRoot.instance = new OpenSimRoot();
81 OpenSimMain sim = new OpenSimMain();
82 OpenSimRoot.Instance.Application = sim;
83
84 sim.sandbox = false;
85 sim.loginserver = false;
86 sim._physicsEngine = "basicphysics";
87
88 for (int i = 0; i < args.Length; i++)
89 {
90 if (args[i] == "-sandbox")
91 {
92 sim.sandbox = true;
93 OpenSimRoot.Instance.Sandbox = true;
94 }
95
96 if (args[i] == "-loginserver")
97 {
98 sim.loginserver = true;
99 }
100 if (args[i] == "-realphysx")
101 {
102 sim._physicsEngine = "RealPhysX";
103 OpenSim.world.Avatar.PhysicsEngineFlying = true;
104 }
105 }
106
107
108 OpenSimRoot.Instance.GridServers = new Grid();
109 if (sim.sandbox)
110 {
111 OpenSimRoot.Instance.GridServers.AssetDll = "OpenSim.GridInterfaces.Local.dll";
112 OpenSimRoot.Instance.GridServers.GridDll = "OpenSim.GridInterfaces.Local.dll";
113 OpenSimRoot.Instance.GridServers.Initialise();
114 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting in Sandbox mode");
115 }
116 else
117 {
118 OpenSimRoot.Instance.GridServers.AssetDll = "OpenSim.GridInterfaces.Remote.dll";
119 OpenSimRoot.Instance.GridServers.GridDll = "OpenSim.GridInterfaces.Remote.dll";
120 OpenSimRoot.Instance.GridServers.Initialise();
121 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting in Grid mode");
122 }
123
124 if (sim.loginserver && sim.sandbox)
125 {
126 LoginServer loginServer = new LoginServer(OpenSimRoot.Instance.GridServers.GridServer);
127 loginServer.Startup();
128 }
129
130 OpenSimRoot.Instance.StartUp();
131
132 while (true)
133 {
134 OpenSim.Framework.Console.MainConsole.Instance.MainConsolePrompt();
135 }
136 }
137
138 private OpenSimMain()
139 {
140 }
141
142 public override void StartUp()
143 {
144 OpenSimRoot.Instance.startuptime = DateTime.Now;
145
146 OpenSimRoot.Instance.AssetCache = new AssetCache(OpenSimRoot.Instance.GridServers.AssetServer);
147 OpenSimRoot.Instance.InventoryCache = new InventoryCache();
148
149 // We check our local database first, then the grid for config options
150 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Startup() - Loading configuration");
151 OpenSimRoot.Instance.Cfg = this.LoadConfigDll(this.ConfigDll);
152 OpenSimRoot.Instance.Cfg.InitConfig(this.sandbox);
153 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Startup() - Contacting gridserver");
154 OpenSimRoot.Instance.Cfg.LoadFromGrid();
155
156 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Startup() - We are " + OpenSimRoot.Instance.Cfg.RegionName + " at " + OpenSimRoot.Instance.Cfg.RegionLocX.ToString() + "," + OpenSimRoot.Instance.Cfg.RegionLocY.ToString());
157 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Initialising world");
158 OpenSimRoot.Instance.LocalWorld = new World();
159 OpenSimRoot.Instance.LocalWorld.LandMap = OpenSimRoot.Instance.Cfg.LoadWorld();
160
161 this.physManager = new OpenSim.Physics.Manager.PhysicsManager();
162 this.physManager.LoadPlugins();
163
164 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting up messaging system");
165 OpenSimRoot.Instance.LocalWorld.PhysScene = this.physManager.GetPhysicsScene(this._physicsEngine); //should be reading from the config file what physics engine to use
166 OpenSimRoot.Instance.LocalWorld.PhysScene.SetTerrain(OpenSimRoot.Instance.LocalWorld.LandMap);
167
168 OpenSimRoot.Instance.GridServers.AssetServer.SetServerInfo(OpenSimRoot.Instance.Cfg.AssetURL, OpenSimRoot.Instance.Cfg.AssetSendKey);
169 OpenSimRoot.Instance.GridServers.GridServer.SetServerInfo(OpenSimRoot.Instance.Cfg.GridURL, OpenSimRoot.Instance.Cfg.GridSendKey, OpenSimRoot.Instance.Cfg.GridRecvKey);
170
171 OpenSimRoot.Instance.LocalWorld.LoadStorageDLL("OpenSim.Storage.LocalStorageDb4o.dll"); //all these dll names shouldn't be hard coded.
172 OpenSimRoot.Instance.LocalWorld.LoadPrimsFromStorage();
173
174 if (this.sandbox)
175 {
176 OpenSimRoot.Instance.AssetCache.LoadDefaultTextureSet();
177 }
178
179 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting CAPS HTTP server");
180 OpenSimRoot.Instance.HttpServer = new SimCAPSHTTPServer();
181
182 timer1.Enabled = true;
183 timer1.Interval = 100;
184 timer1.Elapsed += new ElapsedEventHandler(this.Timer1Tick);
185
186 MainServerListener();
187 }
188
189 private SimConfig LoadConfigDll(string dllName)
190 {
191 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
192 SimConfig config = null;
193
194 foreach (Type pluginType in pluginAssembly.GetTypes())
195 {
196 if (pluginType.IsPublic)
197 {
198 if (!pluginType.IsAbstract)
199 {
200 Type typeInterface = pluginType.GetInterface("ISimConfig", true);
201
202 if (typeInterface != null)
203 {
204 ISimConfig plug = (ISimConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
205 config = plug.GetConfigObject();
206 break;
207 }
208
209 typeInterface = null;
210 }
211 }
212 }
213 pluginAssembly = null;
214 return config;
215 }
216
217 private void OnReceivedData(IAsyncResult result)
218 {
219 ipeSender = new IPEndPoint(IPAddress.Any, 0);
220 epSender = (EndPoint)ipeSender;
221 Packet packet = null;
222 int numBytes = Server.EndReceiveFrom(result, ref epSender);
223 int packetEnd = numBytes - 1;
224 packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer);
225
226 // This is either a new client or a packet to send to an old one
227 // if (OpenSimRoot.Instance.ClientThreads.ContainsKey(epSender))
228
229 // do we already have a circuit for this endpoint
230 if(this.clientCircuits.ContainsKey(epSender))
231 {
232 OpenSimRoot.Instance.ClientThreads[this.clientCircuits[epSender]].InPacket(packet);
233 }
234 else if (packet.Type == PacketType.UseCircuitCode)
235 { // new client
236 UseCircuitCodePacket useCircuit = (UseCircuitCodePacket)packet;
237 this.clientCircuits.Add(epSender, useCircuit.CircuitCode.Code);
238 SimClient newuser = new SimClient(epSender, useCircuit);
239 //OpenSimRoot.Instance.ClientThreads.Add(epSender, newuser);
240 OpenSimRoot.Instance.ClientThreads.Add(useCircuit.CircuitCode.Code, newuser);
241 }
242 else
243 { // invalid client
244 Console.Error.WriteLine("Main.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString());
245 }
246 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
247 }
248
249 private void MainServerListener()
250 {
251 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - New thread started");
252 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - Opening UDP socket on " + OpenSimRoot.Instance.Cfg.IPListenAddr + ":" + OpenSimRoot.Instance.Cfg.IPListenPort);
253
254 ServerIncoming = new IPEndPoint(IPAddress.Any, OpenSimRoot.Instance.Cfg.IPListenPort);
255 Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
256 Server.Bind(ServerIncoming);
257
258 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - UDP socket bound, getting ready to listen");
259
260 ipeSender = new IPEndPoint(IPAddress.Any, 0);
261 epSender = (EndPoint)ipeSender;
262 ReceivedData = new AsyncCallback(this.OnReceivedData);
263 Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null);
264
265 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:MainServerListener() - Listening...");
266
267 }
268
269 public override void SendPacketTo(byte[] buffer, int size, SocketFlags flags, uint circuitcode )//EndPoint packetSender)
270 {
271 // find the endpoint for this circuit
272 EndPoint sendto = null;
273 foreach(KeyValuePair<EndPoint, uint> p in this.clientCircuits)
274 {
275 if (p.Value == circuitcode)
276 {
277 sendto = p.Key;
278 break;
279 }
280 }
281 if (sendto != null)
282 {
283 //we found the endpoint so send the packet to it
284 this.Server.SendTo(buffer, size, flags, sendto);
285 }
286 }
287
288 public override void RemoveClientCircuit(uint circuitcode)
289 {
290 foreach (KeyValuePair<EndPoint, uint> p in this.clientCircuits)
291 {
292 if (p.Value == circuitcode)
293 {
294 this.clientCircuits.Remove(p.Key);
295 break;
296 }
297 }
298 }
299
300 public override void Shutdown()
301 {
302 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Closing all threads");
303 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Killing listener thread");
304 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Killing clients");
305 // IMPLEMENT THIS
306 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Shutdown() - Closing console and terminating");
307 OpenSimRoot.Instance.LocalWorld.Close();
308 OpenSimRoot.Instance.GridServers.Close();
309 OpenSim.Framework.Console.MainConsole.Instance.Close();
310 Environment.Exit(0);
311 }
312
313 void Timer1Tick(object sender, System.EventArgs e)
314 {
315 OpenSimRoot.Instance.LocalWorld.Update();
316 }
317 }
318
319
320}