more stable master server system

This commit is contained in:
Bitl 2022-08-03 09:55:27 -07:00
parent 6c39820272
commit 255aaaf677
1 changed files with 34 additions and 14 deletions

View File

@ -2396,9 +2396,9 @@ public class GlobalFuncs
#endif #endif
string response = HttpGet(pingURL); string response = HttpGet(pingURL);
#if LAUNCHER #if LAUNCHER
ConsolePrint(!response.Contains("ERROR:") ? "Pinging was successful." : "Unable to connect to the master server. " + response, response.Contains("ERROR:") ? 2 : 4, box); ConsolePrint(response, response.Contains("ERROR:") ? 2 : 4, box);
#elif CMD #elif CMD
ConsolePrint(!response.Contains("ERROR:") ? "Pinging was successful." : "Unable to connect to the master server. " + response, response.Contains("ERROR:") ? 2 : 4); ConsolePrint(response, response.Contains("ERROR:") ? 2 : 4);
#endif #endif
} }
@ -2811,27 +2811,47 @@ public class GlobalFuncs
#endif #endif
//https://stackoverflow.com/questions/27108264/how-to-properly-make-a-http-web-get-request //https://stackoverflow.com/questions/27108264/how-to-properly-make-a-http-web-get-request
public static string HttpGet(string uri)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) private static string HttpGetInternal(string uri)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream stream = response.GetResponseStream()) using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{ {
return reader.ReadToEnd(); using (StreamReader reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
} }
} }
catch (Exception ex) }
public static string HttpGet(string uri)
{
int tries = 0;
int triesMax = 5;
string exceptionMessage = "";
while (tries < triesMax)
{ {
tries++;
try
{
return HttpGetInternal(uri);
}
catch (Exception ex)
{
#if URI || LAUNCHER || CMD || BASICLAUNCHER #if URI || LAUNCHER || CMD || BASICLAUNCHER
LogExceptions(ex); LogExceptions(ex);
#endif #endif
return "ERROR: " + ex.Message; exceptionMessage = ex.Message;
continue;
}
} }
return "ERROR: " + exceptionMessage;
} }
public static void DrawBorderSimple(Graphics graphics, Rectangle bounds, Color color, ButtonBorderStyle style, int width) public static void DrawBorderSimple(Graphics graphics, Rectangle bounds, Color color, ButtonBorderStyle style, int width)