Realms API: Handle HTTP request failure (#1921)

This commit is contained in:
ORelio 2022-01-31 20:56:37 +01:00
parent 0e2ebf484b
commit ed452cf632

View file

@ -659,12 +659,14 @@ namespace MinecraftClient.Protocol
/// <param name="accesstoken">Access token</param>
/// <returns>List of ID of available Realms worlds</returns>
public static List<string> RealmsListWorlds(string username, string uuid, string accesstoken)
{
List<string> realmsWorldsResult = new List<string>(); // Store world ID
try
{
string result = "";
string cookies = String.Format("sid=token:{0}:{1};user={2};version={3}", accesstoken, uuid, username, Program.MCHighestVersion);
DoHTTPSGet("pc.realms.minecraft.net", "/worlds", cookies, ref result);
Json.JSONData realmsWorlds = Json.ParseJson(result);
List<string> realmsWorldsResult = new List<string>(); // Store world ID
if (realmsWorlds.Properties.ContainsKey("servers")
&& realmsWorlds.Properties["servers"].Type == Json.JSONData.DataType.Array
&& realmsWorlds.Properties["servers"].DataArray.Count > 0)
@ -697,6 +699,16 @@ namespace MinecraftClient.Protocol
Translations.WriteLine("mcc.realms_join");
}
}
}
catch (Exception e)
{
ConsoleIO.WriteLineFormatted("§8" + e.GetType().ToString() + ": " + e.Message);
if (Settings.DebugMessages)
{
ConsoleIO.WriteLineFormatted("§8" + e.StackTrace);
}
}
return realmsWorldsResult;
}
@ -709,6 +721,8 @@ namespace MinecraftClient.Protocol
/// <param name="accesstoken">Access token</param>
/// <returns>Server address (host:port) or empty string if failure</returns>
public static string GetRealmsWorldServerAddress(string worldId, string username, string uuid, string accesstoken)
{
try
{
string result = "";
string cookies = String.Format("sid=token:{0}:{1};user={2};version={3}", accesstoken, uuid, username, Program.MCHighestVersion);
@ -730,6 +744,16 @@ namespace MinecraftClient.Protocol
return "";
}
}
catch (Exception e)
{
ConsoleIO.WriteLineFormatted("§8" + e.GetType().ToString() + ": " + e.Message);
if (Settings.DebugMessages)
{
ConsoleIO.WriteLineFormatted("§8" + e.StackTrace);
}
return "";
}
}
/// <summary>
/// Make a HTTPS GET request to the specified endpoint of the Mojang API