diff options
Diffstat (limited to 'src/Main.cs')
-rw-r--r-- | src/Main.cs | 159 |
1 files changed, 0 insertions, 159 deletions
diff --git a/src/Main.cs b/src/Main.cs deleted file mode 100644 index f3fa609..0000000 --- a/src/Main.cs +++ /dev/null | |||
@@ -1,159 +0,0 @@ | |||
1 | /* | ||
2 | Copyright (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 | |||
30 | using System; | ||
31 | using System.Text; | ||
32 | using System.IO; | ||
33 | using System.Threading; | ||
34 | using System.Net; | ||
35 | using System.Net.Sockets; | ||
36 | using System.Collections; | ||
37 | using System.Collections.Generic; | ||
38 | using libsecondlife; | ||
39 | using libsecondlife.Packets; | ||
40 | using OpenSim.world; | ||
41 | |||
42 | namespace OpenSim | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// Description of MainForm. | ||
46 | /// </summary> | ||
47 | public class OpenSim_Main | ||
48 | { | ||
49 | public static DateTime startuptime; | ||
50 | public static OpenSim_Main sim; | ||
51 | public static SimConfig cfg; | ||
52 | public static World local_world; | ||
53 | public static ServerConsole localcons; | ||
54 | private static Thread MainListener; | ||
55 | public static Socket Server; | ||
56 | private static IPEndPoint ServerIncoming; | ||
57 | private static byte[] RecvBuffer = new byte[4096]; | ||
58 | private byte[] ZeroBuffer = new byte[8192]; | ||
59 | private static IPEndPoint ipeSender; | ||
60 | private static EndPoint epSender; | ||
61 | private static AsyncCallback ReceivedData; | ||
62 | public Dictionary<EndPoint, OpenSimClient> ClientThreads = new Dictionary<EndPoint, OpenSimClient>(); | ||
63 | |||
64 | [STAThread] | ||
65 | public static void Main( string[] args ) | ||
66 | { | ||
67 | Console.WriteLine("OpenSim " + VersionInfo.Version + "\n"); | ||
68 | Console.WriteLine("Starting...\n"); | ||
69 | sim = new OpenSim_Main(); | ||
70 | sim.Startup(); | ||
71 | while(true) { | ||
72 | localcons.MainConsolePrompt(); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | private OpenSim_Main() { | ||
77 | } | ||
78 | |||
79 | public static void Shutdown() { | ||
80 | localcons.WriteLine("Main.cs:Shutdown() - Closing all threads"); | ||
81 | localcons.WriteLine("Main.cs:Shutdown() - Killing listener thread"); | ||
82 | MainListener.Abort(); | ||
83 | localcons.WriteLine("Main.cs:Shutdown() - Killing clients"); | ||
84 | // IMPLEMENT THIS | ||
85 | localcons.WriteLine("Main.cs:Shutdown() - Closing console and terminating"); | ||
86 | localcons.Close(); | ||
87 | Environment.Exit(0); | ||
88 | } | ||
89 | |||
90 | private void Startup() { | ||
91 | startuptime=DateTime.Now; | ||
92 | localcons=new ServerConsole(ServerConsole.ConsoleType.Local,"",0); | ||
93 | // We check our local database first, then the grid for config options | ||
94 | localcons.WriteLine("Main.cs:Startup() - Loading configuration"); | ||
95 | cfg = new SimConfig(); | ||
96 | cfg.InitConfig(); | ||
97 | localcons.WriteLine("Main.cs:Startup() - Contacting gridserver"); | ||
98 | cfg.LoadFromGrid(); | ||
99 | |||
100 | localcons.WriteLine("Main.cs:Startup() - We are " + cfg.RegionName + " at " + cfg.RegionLocX.ToString() + "," + cfg.RegionLocY.ToString()); | ||
101 | localcons.WriteLine("Initialising world"); | ||
102 | local_world = cfg.LoadWorld(); | ||
103 | |||
104 | localcons.WriteLine("Main.cs:Startup() - Starting up main world loop"); | ||
105 | local_world.InitLoop(); | ||
106 | |||
107 | localcons.WriteLine("Main.cs:Startup() - Starting up messaging system"); | ||
108 | MainListener = new Thread(new ThreadStart(MainServerListener)); | ||
109 | MainListener.Start(); | ||
110 | |||
111 | Thread.Sleep(500); // give other threads a chance to catch up | ||
112 | string[] noparams = new string[1]; | ||
113 | noparams[0]=""; | ||
114 | localcons.WriteLine("\nOpenSim ready\nType help for list of commands"); | ||
115 | } | ||
116 | |||
117 | private void OnReceivedData(IAsyncResult result) { | ||
118 | ipeSender = new IPEndPoint(IPAddress.Any, 0); | ||
119 | epSender = (EndPoint)ipeSender; | ||
120 | Packet packet = null; | ||
121 | int numBytes = Server.EndReceiveFrom(result, ref epSender); | ||
122 | int packetEnd = numBytes - 1; | ||
123 | packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer); | ||
124 | |||
125 | // This is either a new client or a packet to send to an old one | ||
126 | if(ClientThreads.ContainsKey(epSender)) { | ||
127 | ClientThreads[epSender].InPacket(packet); | ||
128 | } else if( packet.Type == PacketType.UseCircuitCode ) { // new client | ||
129 | OpenSimClient newuser = new OpenSimClient(epSender,(UseCircuitCodePacket)packet); | ||
130 | ClientThreads.Add(epSender, newuser); | ||
131 | } else { // invalid client | ||
132 | Console.Error.WriteLine("Main.cs:OnReceivedData() - WARNING: Got a packet from an invalid client - " + epSender.ToString()); | ||
133 | } | ||
134 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | ||
135 | } | ||
136 | |||
137 | private void MainServerListener() { | ||
138 | localcons.WriteLine("Main.cs:MainServerListener() - New thread started"); | ||
139 | localcons.WriteLine("Main.cs:MainServerListener() - Opening UDP socket on " + cfg.IPListenAddr + ":" + cfg.IPListenPort); | ||
140 | |||
141 | ServerIncoming = new IPEndPoint(IPAddress.Any, cfg.IPListenPort); | ||
142 | Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); | ||
143 | Server.Bind(ServerIncoming); | ||
144 | |||
145 | localcons.WriteLine("Main.cs:MainServerListener() - UDP socket bound, getting ready to listen"); | ||
146 | |||
147 | ipeSender = new IPEndPoint(IPAddress.Any, 0); | ||
148 | epSender = (EndPoint) ipeSender; | ||
149 | ReceivedData = new AsyncCallback(this.OnReceivedData); | ||
150 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | ||
151 | |||
152 | localcons.WriteLine("Main.cs:MainServerListener() - Listening..."); | ||
153 | while(true) { | ||
154 | Thread.Sleep(100); | ||
155 | local_world.DoStuff(); | ||
156 | } | ||
157 | } | ||
158 | } | ||
159 | } | ||