diff options
author | gareth | 2007-03-06 15:57:36 +0000 |
---|---|---|
committer | gareth | 2007-03-06 15:57:36 +0000 |
commit | d828af7036fd11a4a1f678b2b7e51bdb6380087a (patch) | |
tree | 99544eb8c363afeccd0da17ba67970b8cc505d14 /src/Main.cs | |
parent | Added sandbox mode and setup facility (diff) | |
download | opensim-SC_OLD-d828af7036fd11a4a1f678b2b7e51bdb6380087a.zip opensim-SC_OLD-d828af7036fd11a4a1f678b2b7e51bdb6380087a.tar.gz opensim-SC_OLD-d828af7036fd11a4a1f678b2b7e51bdb6380087a.tar.bz2 opensim-SC_OLD-d828af7036fd11a4a1f678b2b7e51bdb6380087a.tar.xz |
Implemented local console and VERY rough skeleton for TCP/Worldchat console
Implemented seperate logging (but no packetlog or chat yet)
Diffstat (limited to 'src/Main.cs')
-rw-r--r-- | src/Main.cs | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/src/Main.cs b/src/Main.cs index fe2183b..f3fa609 100644 --- a/src/Main.cs +++ b/src/Main.cs | |||
@@ -46,9 +46,11 @@ namespace OpenSim | |||
46 | /// </summary> | 46 | /// </summary> |
47 | public class OpenSim_Main | 47 | public class OpenSim_Main |
48 | { | 48 | { |
49 | public static DateTime startuptime; | ||
49 | public static OpenSim_Main sim; | 50 | public static OpenSim_Main sim; |
50 | public static SimConfig cfg; | 51 | public static SimConfig cfg; |
51 | public static World local_world; | 52 | public static World local_world; |
53 | public static ServerConsole localcons; | ||
52 | private static Thread MainListener; | 54 | private static Thread MainListener; |
53 | public static Socket Server; | 55 | public static Socket Server; |
54 | private static IPEndPoint ServerIncoming; | 56 | private static IPEndPoint ServerIncoming; |
@@ -67,32 +69,49 @@ namespace OpenSim | |||
67 | sim = new OpenSim_Main(); | 69 | sim = new OpenSim_Main(); |
68 | sim.Startup(); | 70 | sim.Startup(); |
69 | while(true) { | 71 | while(true) { |
70 | local_world.DoStuff(); | 72 | localcons.MainConsolePrompt(); |
71 | Thread.Sleep(100); | ||
72 | } | 73 | } |
73 | } | 74 | } |
74 | 75 | ||
75 | private OpenSim_Main() { | 76 | private OpenSim_Main() { |
76 | } | 77 | } |
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 | |||
78 | private void Startup() { | 90 | private void Startup() { |
91 | startuptime=DateTime.Now; | ||
92 | localcons=new ServerConsole(ServerConsole.ConsoleType.Local,"",0); | ||
79 | // We check our local database first, then the grid for config options | 93 | // We check our local database first, then the grid for config options |
80 | Console.WriteLine("Main.cs:Startup() - Loading configuration"); | 94 | localcons.WriteLine("Main.cs:Startup() - Loading configuration"); |
81 | cfg = new SimConfig(); | 95 | cfg = new SimConfig(); |
82 | cfg.InitConfig(); | 96 | cfg.InitConfig(); |
83 | Console.WriteLine("Main.cs:Startup() - Contacting gridserver"); | 97 | localcons.WriteLine("Main.cs:Startup() - Contacting gridserver"); |
84 | cfg.LoadFromGrid(); | 98 | cfg.LoadFromGrid(); |
85 | 99 | ||
86 | Console.WriteLine("Main.cs:Startup() - We are " + cfg.RegionName + " at " + cfg.RegionLocX.ToString() + "," + cfg.RegionLocY.ToString()); | 100 | localcons.WriteLine("Main.cs:Startup() - We are " + cfg.RegionName + " at " + cfg.RegionLocX.ToString() + "," + cfg.RegionLocY.ToString()); |
87 | Console.WriteLine("Initialising world"); | 101 | localcons.WriteLine("Initialising world"); |
88 | local_world = cfg.LoadWorld(); | 102 | local_world = cfg.LoadWorld(); |
89 | 103 | ||
90 | Console.WriteLine("Main.cs:Startup() - Starting up messaging system"); | 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"); | ||
91 | MainListener = new Thread(new ThreadStart(MainServerListener)); | 108 | MainListener = new Thread(new ThreadStart(MainServerListener)); |
92 | MainListener.Start(); | 109 | MainListener.Start(); |
93 | 110 | ||
94 | Console.WriteLine("Main.cs:Startup() - Starting up main world loop"); | 111 | Thread.Sleep(500); // give other threads a chance to catch up |
95 | local_world.InitLoop(); | 112 | string[] noparams = new string[1]; |
113 | noparams[0]=""; | ||
114 | localcons.WriteLine("\nOpenSim ready\nType help for list of commands"); | ||
96 | } | 115 | } |
97 | 116 | ||
98 | private void OnReceivedData(IAsyncResult result) { | 117 | private void OnReceivedData(IAsyncResult result) { |
@@ -102,7 +121,6 @@ namespace OpenSim | |||
102 | int numBytes = Server.EndReceiveFrom(result, ref epSender); | 121 | int numBytes = Server.EndReceiveFrom(result, ref epSender); |
103 | int packetEnd = numBytes - 1; | 122 | int packetEnd = numBytes - 1; |
104 | packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer); | 123 | packet = Packet.BuildPacket(RecvBuffer, ref packetEnd, ZeroBuffer); |
105 | Console.Error.WriteLine(packet.ToString()); | ||
106 | 124 | ||
107 | // This is either a new client or a packet to send to an old one | 125 | // This is either a new client or a packet to send to an old one |
108 | if(ClientThreads.ContainsKey(epSender)) { | 126 | if(ClientThreads.ContainsKey(epSender)) { |
@@ -117,23 +135,24 @@ namespace OpenSim | |||
117 | } | 135 | } |
118 | 136 | ||
119 | private void MainServerListener() { | 137 | private void MainServerListener() { |
120 | Console.WriteLine("Main.cs:MainServerListener() - New thread started"); | 138 | localcons.WriteLine("Main.cs:MainServerListener() - New thread started"); |
121 | Console.WriteLine("Main.cs:MainServerListener() - Opening UDP socket on " + cfg.IPListenAddr + ":" + cfg.IPListenPort); | 139 | localcons.WriteLine("Main.cs:MainServerListener() - Opening UDP socket on " + cfg.IPListenAddr + ":" + cfg.IPListenPort); |
122 | 140 | ||
123 | ServerIncoming = new IPEndPoint(IPAddress.Any, cfg.IPListenPort); | 141 | ServerIncoming = new IPEndPoint(IPAddress.Any, cfg.IPListenPort); |
124 | Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); | 142 | Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); |
125 | Server.Bind(ServerIncoming); | 143 | Server.Bind(ServerIncoming); |
126 | 144 | ||
127 | Console.WriteLine("Main.cs:MainServerListener() - UDP socket bound, getting ready to listen"); | 145 | localcons.WriteLine("Main.cs:MainServerListener() - UDP socket bound, getting ready to listen"); |
128 | 146 | ||
129 | ipeSender = new IPEndPoint(IPAddress.Any, 0); | 147 | ipeSender = new IPEndPoint(IPAddress.Any, 0); |
130 | epSender = (EndPoint) ipeSender; | 148 | epSender = (EndPoint) ipeSender; |
131 | ReceivedData = new AsyncCallback(this.OnReceivedData); | 149 | ReceivedData = new AsyncCallback(this.OnReceivedData); |
132 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); | 150 | Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); |
133 | 151 | ||
134 | Console.WriteLine("Main.cs:MainServerListener() - Listening..."); | 152 | localcons.WriteLine("Main.cs:MainServerListener() - Listening..."); |
135 | while(true) { | 153 | while(true) { |
136 | Thread.Sleep(1000); | 154 | Thread.Sleep(100); |
155 | local_world.DoStuff(); | ||
137 | } | 156 | } |
138 | } | 157 | } |
139 | } | 158 | } |