mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
Refactoring Settings.cs
This commit is contained in:
parent
f16b1c118b
commit
16c1d1fd77
59 changed files with 3425 additions and 2180 deletions
|
|
@ -61,7 +61,7 @@ namespace MinecraftClient.Protocol.Handlers.PacketPalettes
|
|||
}
|
||||
else if (forgeEnabled)
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLogLine("Ignoring unknown packet ID of 0x" + packetId.ToString("X2"));
|
||||
return PacketTypesIn.Unknown;
|
||||
}
|
||||
|
|
@ -92,7 +92,7 @@ namespace MinecraftClient.Protocol.Handlers.PacketPalettes
|
|||
}
|
||||
else if (forgeEnabled)
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLogLine("Ignoring unknown packet ID of 0x" + packetId.ToString("X2"));
|
||||
return PacketTypesOut.Unknown;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ using MinecraftClient.Protocol.Keys;
|
|||
using MinecraftClient.Protocol.Message;
|
||||
using MinecraftClient.Protocol.Session;
|
||||
using MinecraftClient.Proxy;
|
||||
using static MinecraftClient.Settings;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers
|
||||
{
|
||||
|
|
@ -494,7 +495,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
|
||||
if (serverID == "-")
|
||||
Translations.WriteLineFormatted("mcc.server_offline");
|
||||
else if (Settings.DebugMessages)
|
||||
else if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("mcc.handshake", serverID));
|
||||
|
||||
return StartEncryption(uuid, username, sessionID, token, serverID, PublicServerkey, session);
|
||||
|
|
@ -511,7 +512,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
RSACryptoServiceProvider RSAService = CryptoHandler.DecodeRSAPublicKey(serverPublicKey)!;
|
||||
byte[] secretKey = CryptoHandler.ClientAESPrivateKey ?? CryptoHandler.GenerateAESPrivateKey();
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
Translations.WriteLineFormatted("debug.crypto");
|
||||
|
||||
if (serverIDhash != "-")
|
||||
|
|
@ -534,7 +535,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
{
|
||||
session.ServerIDhash = serverIDhash;
|
||||
session.ServerPublicKey = serverPublicKey;
|
||||
SessionCache.Store(Settings.Login.ToLower(), session);
|
||||
SessionCache.Store(Config.Main.General.Account.Login.ToLower(), session);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -862,7 +863,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
Protocol16Handler ComTmp = new(tcp);
|
||||
string result = ComTmp.ReadNextString();
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
// May contain formatting codes, cannot use WriteLineFormatted
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ using MinecraftClient.Protocol.Keys;
|
|||
using MinecraftClient.Protocol.Message;
|
||||
using MinecraftClient.Protocol.Session;
|
||||
using MinecraftClient.Proxy;
|
||||
using static MinecraftClient.Settings;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers
|
||||
{
|
||||
|
|
@ -461,8 +462,8 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
{
|
||||
//Hide system messages or xp bar messages?
|
||||
messageType = dataTypes.ReadNextByte(packetData);
|
||||
if ((messageType == 1 && !Settings.DisplaySystemMessages)
|
||||
|| (messageType == 2 && !Settings.DisplayXPBarMessages))
|
||||
if ((messageType == 1 && !Config.Main.Advanced.ShowSystemMessages)
|
||||
|| (messageType == 2 && !Config.Main.Advanced.ShowSystemMessages))
|
||||
break;
|
||||
|
||||
if (protocolVersion >= MC_1_16_5_Version)
|
||||
|
|
@ -482,8 +483,8 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
string? unsignedChatContent = hasUnsignedChatContent ? dataTypes.ReadNextString(packetData) : null;
|
||||
|
||||
messageType = dataTypes.ReadNextVarInt(packetData);
|
||||
if ((messageType == 1 && !Settings.DisplaySystemMessages)
|
||||
|| (messageType == 2 && !Settings.DisplayXPBarMessages))
|
||||
if ((messageType == 1 && !Config.Main.Advanced.ShowSystemMessages)
|
||||
|| (messageType == 2 && !Config.Main.Advanced.ShowXPBarMessages))
|
||||
break;
|
||||
|
||||
Guid senderUUID = dataTypes.ReadNextUUID(packetData);
|
||||
|
|
@ -1603,7 +1604,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
case PacketTypesIn.SystemChat:
|
||||
string systemMessage = dataTypes.ReadNextString(packetData);
|
||||
int msgType = dataTypes.ReadNextVarInt(packetData);
|
||||
if ((msgType == 1 && !Settings.DisplaySystemMessages))
|
||||
if ((msgType == 1 && !Config.Main.Advanced.ShowSystemMessages))
|
||||
break;
|
||||
handler.OnTextReceived(new(systemMessage, true, msgType, Guid.Empty, true));
|
||||
break;
|
||||
|
|
@ -1925,7 +1926,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
{
|
||||
session.ServerIDhash = serverIDhash;
|
||||
session.ServerPublicKey = serverPublicKey;
|
||||
SessionCache.Store(Settings.Login.ToLower(), session);
|
||||
SessionCache.Store(Config.Main.General.Account.Login.ToLower(), session);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -2119,7 +2120,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
{
|
||||
string result = dataTypes.ReadNextString(packetData); //Get the Json data
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Config.Logging.DebugMessages)
|
||||
{
|
||||
// May contain formatting codes, cannot use WriteLineFormatted
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
|
|
@ -2230,7 +2231,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// <returns> List< Argument Name, Argument Value > </returns>
|
||||
private List<Tuple<string, string>>? CollectCommandArguments(string command)
|
||||
{
|
||||
if (!isOnlineMode || !Settings.SignMessageInCommand)
|
||||
if (!isOnlineMode || !Config.Signature.SignMessageInCommand)
|
||||
return null;
|
||||
|
||||
List<Tuple<string, string>> needSigned = new();
|
||||
|
|
@ -2371,7 +2372,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
DateTimeOffset timeNow = DateTimeOffset.UtcNow;
|
||||
fields.AddRange(dataTypes.GetLong(timeNow.ToUnixTimeMilliseconds()));
|
||||
|
||||
if (!isOnlineMode || playerKeyPair == null || !Settings.SignChat)
|
||||
if (!isOnlineMode || playerKeyPair == null || !Config.Signature.SignChat)
|
||||
{
|
||||
fields.AddRange(dataTypes.GetLong(0)); // Salt: Long
|
||||
fields.AddRange(dataTypes.GetVarInt(0)); // Signature Length: VarInt
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
|
||||
byte fmlProtocolVersion = dataTypes.ReadNextByte(packetData);
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("forge.version", fmlProtocolVersion));
|
||||
|
||||
if (fmlProtocolVersion >= 1)
|
||||
|
|
@ -140,7 +140,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
SendForgeHandshakePacket(FMLHandshakeDiscriminator.ClientHello, new byte[] { fmlProtocolVersion });
|
||||
|
||||
// Then tell the server that we're running the same mods.
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
Translations.WriteLineFormatted("forge.send_mod");
|
||||
byte[][] mods = new byte[forgeInfo.Mods.Count][];
|
||||
for (int i = 0; i < forgeInfo.Mods.Count; i++)
|
||||
|
|
@ -160,7 +160,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
|
||||
Thread.Sleep(2000);
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
Translations.WriteLineFormatted("forge.accept");
|
||||
// Tell the server that yes, we are OK with the mods it has
|
||||
// even though we don't actually care what mods it has.
|
||||
|
|
@ -182,7 +182,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
// with blocks and items.
|
||||
int registrySize = dataTypes.ReadNextVarInt(packetData);
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("forge.registry", registrySize));
|
||||
|
||||
fmlHandshakeState = FMLHandshakeClientState.PENDINGCOMPLETE;
|
||||
|
|
@ -194,7 +194,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
bool hasNextRegistry = dataTypes.ReadNextBool(packetData);
|
||||
string registryName = dataTypes.ReadNextString(packetData);
|
||||
int registrySize = dataTypes.ReadNextVarInt(packetData);
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("forge.registry_2", registryName, registrySize));
|
||||
if (!hasNextRegistry)
|
||||
fmlHandshakeState = FMLHandshakeClientState.PENDINGCOMPLETE;
|
||||
|
|
@ -206,7 +206,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
// Just say yes.
|
||||
if (discriminator != FMLHandshakeDiscriminator.HandshakeAck)
|
||||
return false;
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
Translations.WriteLineFormatted("forge.accept_registry");
|
||||
SendForgeHandshakePacket(FMLHandshakeDiscriminator.HandshakeAck,
|
||||
new byte[] { (byte)FMLHandshakeClientState.PENDINGCOMPLETE });
|
||||
|
|
@ -220,7 +220,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
|
||||
SendForgeHandshakePacket(FMLHandshakeDiscriminator.HandshakeAck,
|
||||
new byte[] { (byte)FMLHandshakeClientState.COMPLETE });
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
Translations.WriteLine("forge.complete");
|
||||
fmlHandshakeState = FMLHandshakeClientState.DONE;
|
||||
return true;
|
||||
|
|
@ -300,7 +300,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
//
|
||||
// [1]: Version is usually set to "FML2" for FML stuff and "1" for mods
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
Translations.WriteLineFormatted("forge.fml2.mod");
|
||||
|
||||
List<string> mods = new();
|
||||
|
|
@ -332,7 +332,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
// We are supposed to validate server info against our set of installed mods, then reply with our list
|
||||
// In MCC, we just want to send a valid response so we'll reply back with data collected from the server.
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
Translations.WriteLineFormatted("forge.fml2.mod_send");
|
||||
|
||||
// Packet ID 2: Client to Server Mod List
|
||||
|
|
@ -368,7 +368,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
// Registry Snapshot: ForgeRegistry.java > Snapshot > read(PacketBuffer)
|
||||
// Not documented yet. We're ignoring this packet in MCC
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
string registryName = dataTypes.ReadNextString(packetData);
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("forge.fml2.registry", registryName));
|
||||
|
|
@ -387,7 +387,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
// [1] Config data may containt a standard Minecraft string readable with dataTypes.readNextString()
|
||||
// We're ignoring this packet in MCC
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
string configName = dataTypes.ReadNextString(packetData);
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("forge.fml2.config", configName));
|
||||
|
|
@ -398,7 +398,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
break;
|
||||
|
||||
default:
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("forge.fml2.unknown", packetID));
|
||||
break;
|
||||
}
|
||||
|
|
@ -413,7 +413,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
return true;
|
||||
}
|
||||
}
|
||||
else if (Settings.DebugMessages)
|
||||
else if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("forge.fml2.unknown_channel", fmlChannel));
|
||||
}
|
||||
|
|
@ -505,7 +505,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
if (forgeInfo.Mods.Any())
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("forge.with_mod", forgeInfo.Mods.Count));
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
Translations.WriteLineFormatted("forge.mod_list");
|
||||
foreach (ForgeInfo.ForgeMod mod in forgeInfo.Mods)
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ using System.Net.Http;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MinecraftClient.Protocol.Message;
|
||||
using static MinecraftClient.Settings;
|
||||
|
||||
namespace MinecraftClient.Protocol
|
||||
{
|
||||
/// <summary>
|
||||
/// This class parses JSON chat data from MC 1.6+ and returns the appropriate string to be printed.
|
||||
/// </summary>
|
||||
|
||||
static class ChatParser
|
||||
{
|
||||
public enum MessageType
|
||||
|
|
@ -47,7 +47,7 @@ namespace MinecraftClient.Protocol
|
|||
/// <returns>Returns the translated text</returns>
|
||||
public static string ParseSignedChat(ChatMessage message, List<string>? links = null)
|
||||
{
|
||||
string chatContent = Settings.ShowModifiedChat && message.unsignedContent != null ? message.unsignedContent : message.content;
|
||||
string chatContent = Config.Signature.ShowModifiedChat && message.unsignedContent != null ? message.unsignedContent : message.content;
|
||||
string content = message.isJson ? ParseText(chatContent, links) : chatContent;
|
||||
string sender = message.displayName!;
|
||||
|
||||
|
|
@ -107,27 +107,27 @@ namespace MinecraftClient.Protocol
|
|||
string color = string.Empty;
|
||||
if (message.isSystemChat)
|
||||
{
|
||||
if (Settings.MarkSystemMessage)
|
||||
if (Config.Signature.MarkSystemMessage)
|
||||
color = "§z §r "; // Custom color code §z : Background Gray
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((bool)message.isSignatureLegal!)
|
||||
{
|
||||
if (Settings.ShowModifiedChat && message.unsignedContent != null)
|
||||
if (Config.Signature.ShowModifiedChat && message.unsignedContent != null)
|
||||
{
|
||||
if (Settings.MarkModifiedMsg)
|
||||
if (Config.Signature.MarkModifiedMsg)
|
||||
color = "§x §r "; // Custom color code §x : Background Yellow
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Settings.MarkLegallySignedMsg)
|
||||
if (Config.Signature.MarkLegallySignedMsg)
|
||||
color = "§y §r "; // Custom color code §y : Background Green
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Settings.MarkIllegallySignedMsg)
|
||||
if (Config.Signature.MarkIllegallySignedMsg)
|
||||
color = "§w §r "; // Custom color code §w : Background Red
|
||||
}
|
||||
}
|
||||
|
|
@ -203,12 +203,12 @@ namespace MinecraftClient.Protocol
|
|||
if (!Directory.Exists("lang"))
|
||||
Directory.CreateDirectory("lang");
|
||||
|
||||
string Language_File = "lang" + Path.DirectorySeparatorChar + Settings.Language + ".lang";
|
||||
string Language_File = "lang" + Path.DirectorySeparatorChar + Config.Main.Advanced.Language + ".lang";
|
||||
|
||||
//File not found? Try downloading language file from Mojang's servers?
|
||||
if (!File.Exists(Language_File))
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("chat.download", Settings.Language));
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("chat.download", Config.Main.Advanced.Language));
|
||||
HttpClient httpClient = new();
|
||||
try
|
||||
{
|
||||
|
|
@ -217,11 +217,11 @@ namespace MinecraftClient.Protocol
|
|||
string assets_index = fetch_index.Result;
|
||||
fetch_index.Dispose();
|
||||
|
||||
string[] tmp = assets_index.Split(new string[] { "minecraft/lang/" + Settings.Language.ToLower() + ".json" }, StringSplitOptions.None);
|
||||
string[] tmp = assets_index.Split(new string[] { "minecraft/lang/" + Config.Main.Advanced.Language.ToLower() + ".json" }, StringSplitOptions.None);
|
||||
tmp = tmp[1].Split(new string[] { "hash\": \"" }, StringSplitOptions.None);
|
||||
string hash = tmp[1].Split('"')[0]; //Translations file identifier on Mojang's servers
|
||||
string translation_file_location = Settings.TranslationsFile_Website_Download + '/' + hash[..2] + '/' + hash;
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("chat.request", translation_file_location));
|
||||
|
||||
Task<string> fetch_file = httpClient.GetStringAsync(translation_file_location);
|
||||
|
|
@ -266,7 +266,7 @@ namespace MinecraftClient.Protocol
|
|||
}
|
||||
}
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
Translations.WriteLineFormatted("chat.loaded");
|
||||
}
|
||||
else //No external dictionnary found.
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ using System.Globalization;
|
|||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using static MinecraftClient.Settings;
|
||||
using static MinecraftClient.Settings.MainConfigHealper.MainConfig.GeneralConfig;
|
||||
|
||||
namespace MinecraftClient.Protocol
|
||||
{
|
||||
|
|
@ -204,7 +206,7 @@ namespace MinecraftClient.Protocol
|
|||
|
||||
var response = request.Post("application/x-www-form-urlencoded", postData);
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLine(response.ToString());
|
||||
}
|
||||
|
|
@ -271,7 +273,7 @@ namespace MinecraftClient.Protocol
|
|||
request.Headers.Add("x-xbl-contract-version", "0");
|
||||
|
||||
var accessToken = loginResponse.AccessToken;
|
||||
if (Settings.LoginMethod == "browser")
|
||||
if (Config.Main.General.Method == LoginMethod.browser)
|
||||
{
|
||||
// Our own client ID must have d= in front of the token or HTTP status 400
|
||||
// "Stolen" client ID must not have d= in front of the token or HTTP status 400
|
||||
|
|
@ -288,7 +290,7 @@ namespace MinecraftClient.Protocol
|
|||
+ "\"TokenType\": \"JWT\""
|
||||
+ "}";
|
||||
var response = request.Post("application/json", payload);
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLine(response.ToString());
|
||||
}
|
||||
|
|
@ -338,7 +340,7 @@ namespace MinecraftClient.Protocol
|
|||
+ "\"TokenType\": \"JWT\""
|
||||
+ "}";
|
||||
var response = request.Post("application/json", payload);
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLine(response.ToString());
|
||||
}
|
||||
|
|
@ -418,7 +420,7 @@ namespace MinecraftClient.Protocol
|
|||
string payload = "{\"identityToken\": \"XBL3.0 x=" + userHash + ";" + xstsToken + "\"}";
|
||||
var response = request.Post("application/json", payload);
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLine(response.ToString());
|
||||
}
|
||||
|
|
@ -440,7 +442,7 @@ namespace MinecraftClient.Protocol
|
|||
request.Headers.Add("Authorization", string.Format("Bearer {0}", accessToken));
|
||||
var response = request.Get();
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLine(response.ToString());
|
||||
}
|
||||
|
|
@ -456,7 +458,7 @@ namespace MinecraftClient.Protocol
|
|||
request.Headers.Add("Authorization", string.Format("Bearer {0}", accessToken));
|
||||
var response = request.Get();
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLine(response.ToString());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace MinecraftClient.Protocol.Keys
|
|||
|
||||
response = request.Post("application/json", "");
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLine(response.Body.ToString());
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ namespace MinecraftClient.Protocol.Keys
|
|||
{
|
||||
int code = (response == null) ? 0 : response.StatusCode;
|
||||
ConsoleIO.WriteLineFormatted("§cFetch profile key failed: HttpCode = " + code + ", Error = " + e.Message);
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§c" + e.StackTrace);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ using System.IO;
|
|||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Timers;
|
||||
using MinecraftClient.Protocol.Session;
|
||||
using static MinecraftClient.Settings;
|
||||
using static MinecraftClient.Settings.MainConfigHealper.MainConfig.AdvancedConfig;
|
||||
|
||||
namespace MinecraftClient.Protocol.Keys
|
||||
{
|
||||
|
|
@ -46,11 +48,11 @@ namespace MinecraftClient.Protocol.Keys
|
|||
keys.Add(login, playerKeyPair);
|
||||
}
|
||||
|
||||
if (Settings.ProfileKeyCaching == CacheType.Disk && updatetimer.Enabled == true)
|
||||
if (Config.Main.Advanced.ProfileKeyCache == CacheType.disk && updatetimer.Enabled == true)
|
||||
{
|
||||
pendingadds.Add(new KeyValuePair<string, PlayerKeyPair>(login, playerKeyPair));
|
||||
}
|
||||
else if (Settings.ProfileKeyCaching == CacheType.Disk)
|
||||
else if (Config.Main.Advanced.ProfileKeyCache == CacheType.disk)
|
||||
{
|
||||
SaveToDisk();
|
||||
}
|
||||
|
|
@ -114,7 +116,7 @@ namespace MinecraftClient.Protocol.Keys
|
|||
//User-editable keys cache file in text format
|
||||
if (File.Exists(KeysCacheFilePlaintext))
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("cache.loading_keys", KeysCacheFilePlaintext));
|
||||
|
||||
try
|
||||
|
|
@ -133,27 +135,27 @@ namespace MinecraftClient.Protocol.Keys
|
|||
{
|
||||
PlayerKeyPair playerKeyPair = PlayerKeyPair.FromString(value);
|
||||
keys[login] = playerKeyPair;
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("cache.loaded_keys", playerKeyPair.ExpiresAt.ToString()));
|
||||
}
|
||||
catch (InvalidDataException e)
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("cache.ignore_string_keys", value, e.Message));
|
||||
}
|
||||
catch (FormatException e)
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("cache.ignore_string_keys", value, e.Message));
|
||||
}
|
||||
catch (ArgumentNullException e)
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("cache.ignore_string_keys", value, e.Message));
|
||||
|
||||
}
|
||||
}
|
||||
else if (Settings.DebugMessages)
|
||||
else if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("cache.ignore_line_keys", line));
|
||||
}
|
||||
|
|
@ -174,7 +176,7 @@ namespace MinecraftClient.Protocol.Keys
|
|||
/// </summary>
|
||||
private static void SaveToDisk()
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Config.Logging.DebugMessages)
|
||||
Translations.WriteLineFormatted("cache.saving_keys");
|
||||
|
||||
List<string> KeysCacheLines = new()
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ using MinecraftClient.Protocol.Handlers;
|
|||
using MinecraftClient.Protocol.Handlers.Forge;
|
||||
using MinecraftClient.Protocol.Session;
|
||||
using MinecraftClient.Proxy;
|
||||
using static MinecraftClient.Settings;
|
||||
using static MinecraftClient.Settings.MainConfigHealper.MainConfig.GeneralConfig;
|
||||
|
||||
namespace MinecraftClient.Protocol
|
||||
{
|
||||
|
|
@ -64,7 +66,7 @@ namespace MinecraftClient.Protocol
|
|||
{
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("mcc.not_found", domainVal, e.GetType().FullName, e.Message));
|
||||
}
|
||||
}, TimeSpan.FromSeconds(Settings.ResolveSrvRecordsShortTimeout ? 10 : 30));
|
||||
}, TimeSpan.FromSeconds(Config.Main.Advanced.ResolveSrvRecords == MainConfigHealper.MainConfig.AdvancedConfig.ResolveSrvRecordType.fast ? 10 : 30));
|
||||
}
|
||||
|
||||
domain = domainVal;
|
||||
|
|
@ -99,7 +101,7 @@ namespace MinecraftClient.Protocol
|
|||
{
|
||||
ConsoleIO.WriteLineFormatted(String.Format("§8{0}: {1}", e.GetType().FullName, e.Message));
|
||||
}
|
||||
}, TimeSpan.FromSeconds(Settings.ResolveSrvRecordsShortTimeout ? 10 : 30)))
|
||||
}, TimeSpan.FromSeconds(Config.Main.Advanced.ResolveSrvRecords == MainConfigHealper.MainConfig.AdvancedConfig.ResolveSrvRecordType.fast ? 10 : 30)))
|
||||
{
|
||||
if (protocolversion != 0 && protocolversion != protocolversionTmp)
|
||||
Translations.WriteLineFormatted("error.version_different");
|
||||
|
|
@ -420,16 +422,16 @@ namespace MinecraftClient.Protocol
|
|||
/// <param name="pass">Password</param>
|
||||
/// <param name="session">In case of successful login, will contain session information for multiplayer</param>
|
||||
/// <returns>Returns the status of the login (Success, Failure, etc.)</returns>
|
||||
public static LoginResult GetLogin(string user, string pass, AccountType type, out SessionToken session)
|
||||
public static LoginResult GetLogin(string user, string pass, LoginType type, out SessionToken session)
|
||||
{
|
||||
if (type == AccountType.Microsoft)
|
||||
if (type == LoginType.microsoft)
|
||||
{
|
||||
if (Settings.LoginMethod == "mcc")
|
||||
if (Config.Main.General.Method == LoginMethod.mcc)
|
||||
return MicrosoftMCCLogin(user, pass, out session);
|
||||
else
|
||||
return MicrosoftBrowserLogin(out session, user);
|
||||
}
|
||||
else if (type == AccountType.Mojang)
|
||||
else if (type == LoginType.mojang)
|
||||
{
|
||||
return MojangLogin(user, pass, out session);
|
||||
}
|
||||
|
|
@ -494,7 +496,7 @@ namespace MinecraftClient.Protocol
|
|||
}
|
||||
catch (System.Security.Authentication.AuthenticationException e)
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8" + e.ToString());
|
||||
}
|
||||
|
|
@ -502,7 +504,7 @@ namespace MinecraftClient.Protocol
|
|||
}
|
||||
catch (System.IO.IOException e)
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8" + e.ToString());
|
||||
}
|
||||
|
|
@ -514,7 +516,7 @@ namespace MinecraftClient.Protocol
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8" + e.ToString());
|
||||
}
|
||||
|
|
@ -543,7 +545,7 @@ namespace MinecraftClient.Protocol
|
|||
{
|
||||
session = new SessionToken() { ClientID = Guid.NewGuid().ToString().Replace("-", "") };
|
||||
ConsoleIO.WriteLineFormatted("§cMicrosoft authenticate failed: " + e.Message);
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§c" + e.StackTrace);
|
||||
}
|
||||
|
|
@ -601,7 +603,7 @@ namespace MinecraftClient.Protocol
|
|||
session.PlayerID = profile.UUID;
|
||||
session.ID = accessToken;
|
||||
session.RefreshToken = msaResponse.RefreshToken;
|
||||
Settings.Login = msaResponse.Email;
|
||||
Config.Main.General.Account.Login = msaResponse.Email;
|
||||
return LoginResult.Success;
|
||||
}
|
||||
else
|
||||
|
|
@ -612,7 +614,7 @@ namespace MinecraftClient.Protocol
|
|||
catch (Exception e)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§cMicrosoft authenticate failed: " + e.Message);
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§c" + e.StackTrace);
|
||||
}
|
||||
|
|
@ -632,7 +634,7 @@ namespace MinecraftClient.Protocol
|
|||
var expTimestamp = long.Parse(json.Properties["exp"].StringValue, NumberStyles.Any, CultureInfo.CurrentCulture);
|
||||
var now = DateTime.Now;
|
||||
var tokenExp = UnixTimeStampToDateTime(expTimestamp);
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLine("Access token expiration time is " + tokenExp.ToString());
|
||||
}
|
||||
|
|
@ -772,7 +774,7 @@ namespace MinecraftClient.Protocol
|
|||
catch (Exception e)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8" + e.GetType().ToString() + ": " + e.Message);
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8" + e.StackTrace);
|
||||
}
|
||||
|
|
@ -815,7 +817,7 @@ namespace MinecraftClient.Protocol
|
|||
catch (Exception e)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8" + e.GetType().ToString() + ": " + e.Message);
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8" + e.StackTrace);
|
||||
}
|
||||
|
|
@ -890,14 +892,14 @@ namespace MinecraftClient.Protocol
|
|||
{
|
||||
try
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("debug.request", host));
|
||||
|
||||
TcpClient client = ProxyHandler.NewTcpClient(host, 443, true);
|
||||
SslStream stream = new(client.GetStream());
|
||||
stream.AuthenticateAsClient(host, null, SslProtocols.Tls12, true); // Enable TLS 1.2. Hotfix for #1780
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
foreach (string line in headers)
|
||||
ConsoleIO.WriteLineFormatted("§8> " + line);
|
||||
|
||||
|
|
@ -905,7 +907,7 @@ namespace MinecraftClient.Protocol
|
|||
System.IO.StreamReader sr = new(stream);
|
||||
string raw_result = sr.ReadToEnd();
|
||||
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLine("");
|
||||
foreach (string line in raw_result.Split('\n'))
|
||||
|
|
@ -915,7 +917,7 @@ namespace MinecraftClient.Protocol
|
|||
if (raw_result.StartsWith("HTTP/1.1"))
|
||||
{
|
||||
postResult = raw_result[(raw_result.IndexOf("\r\n\r\n") + 4)..];
|
||||
statusCode = Settings.str2int(raw_result.Split(' ')[1]);
|
||||
statusCode = int.Parse(raw_result.Split(' ')[1], NumberStyles.Any, CultureInfo.CurrentCulture);
|
||||
}
|
||||
else statusCode = 520; //Web server is returning an unknown error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ namespace MinecraftClient.Protocol
|
|||
requestMessage.Add(body);
|
||||
}
|
||||
else requestMessage.Add(""); // <CR><LF>
|
||||
if (Settings.DebugMessages)
|
||||
if (Settings.Config.Logging.DebugMessages)
|
||||
{
|
||||
foreach (string l in requestMessage)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -398,7 +398,7 @@ namespace MinecraftClient.Protocol
|
|||
|
||||
private static void WriteDebugLog(string t)
|
||||
{
|
||||
if (Settings.DebugMessages && logOutput)
|
||||
if (Settings.Config.Logging.DebugMessages && logOutput)
|
||||
WriteLog(t);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
namespace MinecraftClient.Protocol.Session
|
||||
{
|
||||
public enum CacheType
|
||||
{
|
||||
/// <summary>
|
||||
/// Do not perform any session caching, always perform login requests from scratch.
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// Cache session information in memory to reuse session tokens across server joins.
|
||||
/// </summary>
|
||||
Memory,
|
||||
|
||||
/// <summary>
|
||||
/// Cache session information in a SessionCache file to share session tokens between different MCC instances.
|
||||
/// </summary>
|
||||
Disk
|
||||
};
|
||||
}
|
||||
|
|
@ -4,6 +4,8 @@ using System.IO;
|
|||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Timers;
|
||||
using static MinecraftClient.Settings;
|
||||
using static MinecraftClient.Settings.MainConfigHealper.MainConfig.AdvancedConfig;
|
||||
|
||||
namespace MinecraftClient.Protocol.Session
|
||||
{
|
||||
|
|
@ -54,11 +56,11 @@ namespace MinecraftClient.Protocol.Session
|
|||
sessions.Add(login, session);
|
||||
}
|
||||
|
||||
if (Settings.SessionCaching == CacheType.Disk && updatetimer.Enabled == true)
|
||||
if (Config.Main.Advanced.SessionCache == CacheType.disk && updatetimer.Enabled == true)
|
||||
{
|
||||
pendingadds.Add(new KeyValuePair<string, SessionToken>(login, session));
|
||||
}
|
||||
else if (Settings.SessionCaching == CacheType.Disk)
|
||||
else if (Config.Main.Advanced.SessionCache == CacheType.disk)
|
||||
{
|
||||
SaveToDisk();
|
||||
}
|
||||
|
|
@ -122,7 +124,7 @@ namespace MinecraftClient.Protocol.Session
|
|||
//Grab sessions in the Minecraft directory
|
||||
if (File.Exists(SessionCacheFileMinecraft))
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("cache.loading", Path.GetFileName(SessionCacheFileMinecraft)));
|
||||
Json.JSONData mcSession = new(Json.JSONData.DataType.String);
|
||||
try
|
||||
|
|
@ -155,7 +157,7 @@ namespace MinecraftClient.Protocol.Session
|
|||
sessionItem["uuid"].StringValue.Replace("-", ""),
|
||||
clientID
|
||||
));
|
||||
if (Settings.DebugMessages)
|
||||
if (Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("cache.loaded", login, session.ID));
|
||||
sessions[login] = session;
|
||||
}
|
||||
|
|
@ -169,7 +171,7 @@ namespace MinecraftClient.Protocol.Session
|
|||
//Serialized session cache file in binary format
|
||||
if (File.Exists(SessionCacheFileSerialized))
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("cache.converting", SessionCacheFileSerialized));
|
||||
|
||||
try
|
||||
|
|
@ -181,7 +183,7 @@ namespace MinecraftClient.Protocol.Session
|
|||
#pragma warning restore SYSLIB0011 // BinaryFormatter.Deserialize() is obsolete
|
||||
foreach (KeyValuePair<string, SessionToken> item in sessionsTemp)
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("cache.loaded", item.Key, item.Value.ID));
|
||||
sessions[item.Key] = item.Value;
|
||||
}
|
||||
|
|
@ -199,7 +201,7 @@ namespace MinecraftClient.Protocol.Session
|
|||
//User-editable session cache file in text format
|
||||
if (File.Exists(SessionCacheFilePlaintext))
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("cache.loading_session", SessionCacheFilePlaintext));
|
||||
|
||||
try
|
||||
|
|
@ -215,17 +217,17 @@ namespace MinecraftClient.Protocol.Session
|
|||
{
|
||||
string login = Settings.ToLowerIfNeed(keyValue[0]);
|
||||
SessionToken session = SessionToken.FromString(keyValue[1]);
|
||||
if (Settings.DebugMessages)
|
||||
if (Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("cache.loaded", login, session.ID));
|
||||
sessions[login] = session;
|
||||
}
|
||||
catch (InvalidDataException e)
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Config.Logging.DebugMessages)
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("cache.ignore_string", keyValue[1], e.Message));
|
||||
}
|
||||
}
|
||||
else if (Settings.DebugMessages)
|
||||
else if (Config.Logging.DebugMessages)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted(Translations.Get("cache.ignore_line", line));
|
||||
}
|
||||
|
|
@ -246,7 +248,7 @@ namespace MinecraftClient.Protocol.Session
|
|||
/// </summary>
|
||||
private static void SaveToDisk()
|
||||
{
|
||||
if (Settings.DebugMessages)
|
||||
if (Config.Logging.DebugMessages)
|
||||
Translations.WriteLineFormatted("cache.saving");
|
||||
|
||||
List<string> sessionCacheLines = new()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue