//============================================================================================================== // Log update //============================================================================================================== public static void OnPilotLog(HttpListenerRequest request, HttpListenerResponse response) { string responseString = ""; try { // Parsing arguments Dictionary <string, string> postArguments = WebReader.GetPostArgs(request); string sessionKey = postArguments["sessionKey"]; // Looking for player session Player player = Authorization.FindBySession(sessionKey); // Session found - send the log if (player != null) { responseString = WebConstructor.GetShipLog(player.ship); } // No session found else { responseString = "<p>Authorization error.</p>"; } } // Something went wrong (typically, argument parsing error) catch (Exception ex) { responseString = WebConstructor.defaultHeader; responseString += "<h1>Unknown error:</h1><h2>" + ex.Message + "</h2>"; responseString += WebConstructor.defaultFooter; } // Send the message WebWriter.Reply(response, responseString); }
public static void ThreadMain() { while (threadState != ThreadState.Stopping) { List <PlayerResponsePair> servedPlayers = new List <PlayerResponsePair>(); // Serving foreach (PlayerResponsePair data in waitingPlayers) { if (data.player.isWaitingForUpdate) { WebWriter.Reply(data.response, WebConstructor.GetShipLog(data.player.ship)); data.player.NotifyOnFlush(); servedPlayers.Add(data); } } if (servedPlayers.Count > 0) { ConsoleEx.Log("Served updates to " + servedPlayers.Count + " player(s)."); } // Cleaning up foreach (PlayerResponsePair data in servedPlayers) { waitingPlayers.Remove(data); } // Waiting System.Threading.Thread.Sleep(1000); } }