Implement Realms support (#1533)

Resolve #51 

* Realms: update to new API; fix HTTP Get

* Realms: suggested changes

Co-authored-by: ORelio <ORelio@users.noreply.github.com>

* Realms: suggested changes

Co-authored-by: ORelio <ORelio@users.noreply.github.com>

* Add negative number support for JSON parser

* Nice print realms worlds result

* Option to join Realms world with world ID

* Suggested changes

Co-authored-by: ORelio <ORelio@users.noreply.github.com>

* Failure handle

Co-authored-by: ORelio <ORelio@users.noreply.github.com>

* world id paired with index

* fix text

* Clean up the code a bit

* Add setting for displaying Realms worlds

* Rename Realms worlds setting

* Put messages into translation file

Co-authored-by: Zizhen Lian <zizhlian@umd.edu>
Co-authored-by: ORelio <ORelio@users.noreply.github.com>
Co-authored-by: ReinforceZwei <39955851+ReinforceZwei@users.noreply.github.com>
This commit is contained in:
LesterLian 2021-04-12 07:46:33 -04:00 committed by GitHub
parent d7089c534f
commit 621e5e2200
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 129 additions and 11 deletions

View file

@ -219,6 +219,7 @@ namespace MinecraftClient
if (result == ProtocolHandler.LoginResult.Success)
{
Settings.Username = session.PlayerName;
bool isRealms = false;
if (Settings.ConsoleTitle != "")
Console.Title = Settings.ExpandVars(Settings.ConsoleTitle);
@ -229,12 +230,45 @@ namespace MinecraftClient
if (Settings.DebugMessages)
Translations.WriteLine("debug.session_id", session.ID);
//ProtocolHandler.RealmsListWorlds(Settings.Username, PlayerID, sessionID); //TODO REMOVE
List<string> availableWorlds = new List<string>();
if (Settings.MinecraftRealmsEnabled && !String.IsNullOrEmpty(session.ID))
availableWorlds = ProtocolHandler.RealmsListWorlds(Settings.Username, session.PlayerID, session.ID);
if (Settings.ServerIP == "")
{
Translations.Write("mcc.ip");
Settings.SetServerIP(Console.ReadLine());
string addressInput = Console.ReadLine();
if (addressInput.StartsWith("realms:"))
{
if (Settings.MinecraftRealmsEnabled)
{
if (availableWorlds.Count == 0)
{
HandleFailure(Translations.Get("error.realms.access_denied"), false, ChatBot.DisconnectReason.LoginRejected);
return;
}
int worldIndex = Convert.ToUInt16(addressInput.Split(':')[1]);
string worldId = availableWorlds[worldIndex];
string RealmsAddress = ProtocolHandler.GetRealmsWorldServerAddress(worldId, Settings.Username, session.PlayerID, session.ID);
if (RealmsAddress != "")
{
addressInput = RealmsAddress;
isRealms = true;
Settings.ServerVersion = MCHighestVersion;
}
else
{
HandleFailure(Translations.Get("error.realms.server_unavailable"), false, ChatBot.DisconnectReason.LoginRejected);
return;
}
}
else
{
HandleFailure(Translations.Get("error.realms.disabled"), false, null);
return;
}
}
Settings.SetServerIP(addressInput);
}
//Get server version
@ -259,7 +293,7 @@ namespace MinecraftClient
}
//Retrieve server info if version is not manually set OR if need to retrieve Forge information
if (protocolversion == 0 || Settings.ServerAutodetectForge || (Settings.ServerForceForge && !ProtocolHandler.ProtocolMayForceForge(protocolversion)))
if (!isRealms && (protocolversion == 0 || Settings.ServerAutodetectForge || (Settings.ServerForceForge && !ProtocolHandler.ProtocolMayForceForge(protocolversion))))
{
if (protocolversion != 0)
Translations.WriteLine("mcc.forge");
@ -272,7 +306,7 @@ namespace MinecraftClient
}
//Force-enable Forge support?
if (Settings.ServerForceForge && forgeInfo == null)
if (!isRealms && Settings.ServerForceForge && forgeInfo == null)
{
if (ProtocolHandler.ProtocolMayForceForge(protocolversion))
{