mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
Close Window & Toggle Setting
This commit is contained in:
parent
5895a4161f
commit
9c0e3f3bcb
6 changed files with 75 additions and 21 deletions
|
|
@ -26,12 +26,14 @@ namespace MinecraftClient
|
||||||
|
|
||||||
private readonly List<ChatBot> bots = new List<ChatBot>();
|
private readonly List<ChatBot> bots = new List<ChatBot>();
|
||||||
private static readonly List<ChatBot> botsOnHold = new List<ChatBot>();
|
private static readonly List<ChatBot> botsOnHold = new List<ChatBot>();
|
||||||
|
private static List<Inventory> inventories = new List<Inventory>();
|
||||||
|
|
||||||
private readonly Dictionary<string, List<ChatBot>> registeredBotPluginChannels = new Dictionary<string, List<ChatBot>>();
|
private readonly Dictionary<string, List<ChatBot>> registeredBotPluginChannels = new Dictionary<string, List<ChatBot>>();
|
||||||
private readonly List<string> registeredServerPluginChannels = new List<String>();
|
private readonly List<string> registeredServerPluginChannels = new List<String>();
|
||||||
|
|
||||||
private bool terrainAndMovementsEnabled;
|
private bool terrainAndMovementsEnabled;
|
||||||
private bool terrainAndMovementsRequested = false;
|
private bool terrainAndMovementsRequested = false;
|
||||||
|
private bool inventoryHandling;
|
||||||
private object locationLock = new object();
|
private object locationLock = new object();
|
||||||
private bool locationReceived = false;
|
private bool locationReceived = false;
|
||||||
private World world = new World();
|
private World world = new World();
|
||||||
|
|
@ -47,8 +49,7 @@ namespace MinecraftClient
|
||||||
private string username;
|
private string username;
|
||||||
private string uuid;
|
private string uuid;
|
||||||
private string sessionid;
|
private string sessionid;
|
||||||
private Inventory inventory;
|
private Inventory playerInventory;
|
||||||
|
|
||||||
|
|
||||||
public int GetServerPort() { return port; }
|
public int GetServerPort() { return port; }
|
||||||
public string GetServerHost() { return host; }
|
public string GetServerHost() { return host; }
|
||||||
|
|
@ -105,6 +106,7 @@ namespace MinecraftClient
|
||||||
private void StartClient(string user, string uuid, string sessionID, string server_ip, ushort port, int protocolversion, ForgeInfo forgeInfo, bool singlecommand, string command)
|
private void StartClient(string user, string uuid, string sessionID, string server_ip, ushort port, int protocolversion, ForgeInfo forgeInfo, bool singlecommand, string command)
|
||||||
{
|
{
|
||||||
terrainAndMovementsEnabled = Settings.TerrainAndMovements;
|
terrainAndMovementsEnabled = Settings.TerrainAndMovements;
|
||||||
|
inventoryHandling = Settings.InventoryHandling;
|
||||||
|
|
||||||
bool retry = false;
|
bool retry = false;
|
||||||
this.sessionid = sessionID;
|
this.sessionid = sessionID;
|
||||||
|
|
@ -419,6 +421,14 @@ namespace MinecraftClient
|
||||||
return terrainAndMovementsEnabled;
|
return terrainAndMovementsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get Inventory Handling Mode
|
||||||
|
/// </summary>
|
||||||
|
public bool GetInventoryEnabled()
|
||||||
|
{
|
||||||
|
return inventoryHandling;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enable or disable Terrain and Movements.
|
/// Enable or disable Terrain and Movements.
|
||||||
/// Please note that Enabling will be deferred until next relog, respawn or world change.
|
/// Please note that Enabling will be deferred until next relog, respawn or world change.
|
||||||
|
|
@ -598,6 +608,28 @@ namespace MinecraftClient
|
||||||
public void onInventoryOpen(Inventory inventory)
|
public void onInventoryOpen(Inventory inventory)
|
||||||
{
|
{
|
||||||
//TODO: Handle Inventory
|
//TODO: Handle Inventory
|
||||||
|
if (!inventories.Contains(inventory))
|
||||||
|
{
|
||||||
|
inventories.Add(inventory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// When an inventory is close
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="inventoryID">Location to reach</param>
|
||||||
|
public void onInventoryClose(byte inventoryID)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < inventories.Count; i++)
|
||||||
|
{
|
||||||
|
Inventory inventory = inventories[i];
|
||||||
|
if (inventory == null) continue;
|
||||||
|
if (inventory.id == inventoryID)
|
||||||
|
{
|
||||||
|
inventories.Remove(inventory);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
KickPacket,
|
KickPacket,
|
||||||
NetworkCompressionTreshold,
|
NetworkCompressionTreshold,
|
||||||
ResourcePackSend,
|
ResourcePackSend,
|
||||||
|
CloseWindow,
|
||||||
OpenWindow,
|
OpenWindow,
|
||||||
WindowItems,
|
WindowItems,
|
||||||
SetSlot,
|
SetSlot,
|
||||||
|
|
|
||||||
|
|
@ -465,7 +465,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
compression_treshold = dataTypes.ReadNextVarInt(packetData);
|
compression_treshold = dataTypes.ReadNextVarInt(packetData);
|
||||||
break;
|
break;
|
||||||
case PacketIncomingType.OpenWindow:
|
case PacketIncomingType.OpenWindow:
|
||||||
if (protocolversion < MC1141Version)
|
if (protocolversion < MC1141Version && handler.GetInventoryEnabled())
|
||||||
{
|
{
|
||||||
byte windowID = dataTypes.ReadNextByte(packetData);
|
byte windowID = dataTypes.ReadNextByte(packetData);
|
||||||
string type = dataTypes.ReadNextString(packetData).Replace("minecraft:", "").ToUpper();
|
string type = dataTypes.ReadNextString(packetData).Replace("minecraft:", "").ToUpper();
|
||||||
|
|
@ -474,12 +474,19 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
byte slots = dataTypes.ReadNextByte(packetData);
|
byte slots = dataTypes.ReadNextByte(packetData);
|
||||||
Inventory inventory = new Inventory(windowID, inventoryType, title, slots);
|
Inventory inventory = new Inventory(windowID, inventoryType, title, slots);
|
||||||
|
|
||||||
|
|
||||||
handler.onInventoryOpen(inventory);
|
handler.onInventoryOpen(inventory);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case PacketIncomingType.CloseWindow:
|
||||||
|
if (protocolversion < MC1141Version && handler.GetInventoryEnabled())
|
||||||
|
{
|
||||||
|
byte windowID = dataTypes.ReadNextByte(packetData);
|
||||||
|
|
||||||
|
handler.onInventoryClose(windowID);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case PacketIncomingType.WindowItems:
|
case PacketIncomingType.WindowItems:
|
||||||
if (protocolversion < MC1141Version)
|
if (protocolversion < MC1141Version && handler.GetInventoryEnabled())
|
||||||
{
|
{
|
||||||
byte id = dataTypes.ReadNextByte(packetData);
|
byte id = dataTypes.ReadNextByte(packetData);
|
||||||
short elements = dataTypes.ReadNextShort(packetData);
|
short elements = dataTypes.ReadNextShort(packetData);
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
case 0x22: return PacketIncomingType.MultiBlockChange;
|
case 0x22: return PacketIncomingType.MultiBlockChange;
|
||||||
case 0x23: return PacketIncomingType.BlockChange;
|
case 0x23: return PacketIncomingType.BlockChange;
|
||||||
case 0x26: return PacketIncomingType.MapChunkBulk;
|
case 0x26: return PacketIncomingType.MapChunkBulk;
|
||||||
|
case 0x30: return PacketIncomingType.WindowItems;
|
||||||
//UnloadChunk does not exists prior to 1.9
|
//UnloadChunk does not exists prior to 1.9
|
||||||
case 0x38: return PacketIncomingType.PlayerListUpdate;
|
case 0x38: return PacketIncomingType.PlayerListUpdate;
|
||||||
case 0x3A: return PacketIncomingType.TabCompleteResult;
|
case 0x3A: return PacketIncomingType.TabCompleteResult;
|
||||||
|
|
@ -39,7 +40,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
case 0x46: return PacketIncomingType.NetworkCompressionTreshold;
|
case 0x46: return PacketIncomingType.NetworkCompressionTreshold;
|
||||||
case 0x48: return PacketIncomingType.ResourcePackSend;
|
case 0x48: return PacketIncomingType.ResourcePackSend;
|
||||||
case 0x2D: return PacketIncomingType.OpenWindow;
|
case 0x2D: return PacketIncomingType.OpenWindow;
|
||||||
case 0x30: return PacketIncomingType.WindowItems;
|
case 0x2E: return PacketIncomingType.CloseWindow;
|
||||||
case 0x2F: return PacketIncomingType.SetSlot;
|
case 0x2F: return PacketIncomingType.SetSlot;
|
||||||
default: return PacketIncomingType.UnknownPacket;
|
default: return PacketIncomingType.UnknownPacket;
|
||||||
}
|
}
|
||||||
|
|
@ -62,6 +63,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
case 0x0E: return PacketIncomingType.TabCompleteResult;
|
case 0x0E: return PacketIncomingType.TabCompleteResult;
|
||||||
case 0x18: return PacketIncomingType.PluginMessage;
|
case 0x18: return PacketIncomingType.PluginMessage;
|
||||||
case 0x1A: return PacketIncomingType.KickPacket;
|
case 0x1A: return PacketIncomingType.KickPacket;
|
||||||
|
case 0x12: return PacketIncomingType.CloseWindow;
|
||||||
case 0x13: return PacketIncomingType.OpenWindow;
|
case 0x13: return PacketIncomingType.OpenWindow;
|
||||||
case 0x14: return PacketIncomingType.WindowItems;
|
case 0x14: return PacketIncomingType.WindowItems;
|
||||||
case 0x16: return PacketIncomingType.SetSlot;
|
case 0x16: return PacketIncomingType.SetSlot;
|
||||||
|
|
@ -81,16 +83,17 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
case 0x2E: return PacketIncomingType.PlayerPositionAndLook;
|
case 0x2E: return PacketIncomingType.PlayerPositionAndLook;
|
||||||
case 0x20: return PacketIncomingType.ChunkData;
|
case 0x20: return PacketIncomingType.ChunkData;
|
||||||
case 0x10: return PacketIncomingType.MultiBlockChange;
|
case 0x10: return PacketIncomingType.MultiBlockChange;
|
||||||
|
case 0x14: return PacketIncomingType.WindowItems;
|
||||||
|
case 0x16: return PacketIncomingType.SetSlot;
|
||||||
case 0x0B: return PacketIncomingType.BlockChange;
|
case 0x0B: return PacketIncomingType.BlockChange;
|
||||||
case 0x1D: return PacketIncomingType.UnloadChunk;
|
case 0x1D: return PacketIncomingType.UnloadChunk;
|
||||||
case 0x2D: return PacketIncomingType.PlayerListUpdate;
|
case 0x2D: return PacketIncomingType.PlayerListUpdate;
|
||||||
case 0x0E: return PacketIncomingType.TabCompleteResult;
|
case 0x0E: return PacketIncomingType.TabCompleteResult;
|
||||||
case 0x18: return PacketIncomingType.PluginMessage;
|
case 0x18: return PacketIncomingType.PluginMessage;
|
||||||
case 0x1A: return PacketIncomingType.KickPacket;
|
case 0x1A: return PacketIncomingType.KickPacket;
|
||||||
|
case 0x12: return PacketIncomingType.CloseWindow;
|
||||||
case 0x13: return PacketIncomingType.OpenWindow;
|
case 0x13: return PacketIncomingType.OpenWindow;
|
||||||
case 0x33: return PacketIncomingType.ResourcePackSend;
|
case 0x33: return PacketIncomingType.ResourcePackSend;
|
||||||
case 0x14: return PacketIncomingType.WindowItems;
|
|
||||||
case 0x16: return PacketIncomingType.SetSlot;
|
|
||||||
default: return PacketIncomingType.UnknownPacket;
|
default: return PacketIncomingType.UnknownPacket;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -111,6 +114,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
case 0x0E: return PacketIncomingType.TabCompleteResult;
|
case 0x0E: return PacketIncomingType.TabCompleteResult;
|
||||||
case 0x18: return PacketIncomingType.PluginMessage;
|
case 0x18: return PacketIncomingType.PluginMessage;
|
||||||
case 0x1A: return PacketIncomingType.KickPacket;
|
case 0x1A: return PacketIncomingType.KickPacket;
|
||||||
|
case 0x12: return PacketIncomingType.CloseWindow;
|
||||||
case 0x13: return PacketIncomingType.OpenWindow;
|
case 0x13: return PacketIncomingType.OpenWindow;
|
||||||
case 0x14: return PacketIncomingType.WindowItems;
|
case 0x14: return PacketIncomingType.WindowItems;
|
||||||
case 0x16: return PacketIncomingType.SetSlot;
|
case 0x16: return PacketIncomingType.SetSlot;
|
||||||
|
|
@ -136,6 +140,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
case 0x19: return PacketIncomingType.PluginMessage;
|
case 0x19: return PacketIncomingType.PluginMessage;
|
||||||
case 0x1B: return PacketIncomingType.KickPacket;
|
case 0x1B: return PacketIncomingType.KickPacket;
|
||||||
case 0x37: return PacketIncomingType.ResourcePackSend;
|
case 0x37: return PacketIncomingType.ResourcePackSend;
|
||||||
|
case 0x13: return PacketIncomingType.CloseWindow;
|
||||||
case 0x14: return PacketIncomingType.OpenWindow;
|
case 0x14: return PacketIncomingType.OpenWindow;
|
||||||
case 0x15: return PacketIncomingType.WindowItems;
|
case 0x15: return PacketIncomingType.WindowItems;
|
||||||
case 0x17: return PacketIncomingType.SetSlot;
|
case 0x17: return PacketIncomingType.SetSlot;
|
||||||
|
|
@ -161,6 +166,7 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
case 0x1A: return PacketIncomingType.KickPacket;
|
case 0x1A: return PacketIncomingType.KickPacket;
|
||||||
case 0x39: return PacketIncomingType.ResourcePackSend;
|
case 0x39: return PacketIncomingType.ResourcePackSend;
|
||||||
case 0x2E: return PacketIncomingType.OpenWindow;
|
case 0x2E: return PacketIncomingType.OpenWindow;
|
||||||
|
case 0x13: return PacketIncomingType.CloseWindow;
|
||||||
case 0x14: return PacketIncomingType.WindowItems;
|
case 0x14: return PacketIncomingType.WindowItems;
|
||||||
case 0x16: return PacketIncomingType.SetSlot;
|
case 0x16: return PacketIncomingType.SetSlot;
|
||||||
default: return PacketIncomingType.UnknownPacket;
|
default: return PacketIncomingType.UnknownPacket;
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ namespace MinecraftClient.Protocol
|
||||||
World GetWorld();
|
World GetWorld();
|
||||||
bool GetTerrainEnabled();
|
bool GetTerrainEnabled();
|
||||||
bool SetTerrainEnabled(bool enabled);
|
bool SetTerrainEnabled(bool enabled);
|
||||||
|
bool GetInventoryEnabled();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when a server was successfully joined
|
/// Called when a server was successfully joined
|
||||||
|
|
@ -42,11 +43,15 @@ namespace MinecraftClient.Protocol
|
||||||
void OnTextReceived(string text, bool isJson);
|
void OnTextReceived(string text, bool isJson);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method is called when an inventory is opened
|
/// Called when an inventory is opened
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inventory">Inventory that was opened</param>
|
|
||||||
void onInventoryOpen(Inventory inventory);
|
void onInventoryOpen(Inventory inventory);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when an inventory is closed
|
||||||
|
/// </summary>
|
||||||
|
void onInventoryClose(byte inventoryID);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when the player respawns, which happens on login, respawn and world change.
|
/// Called when the player respawns, which happens on login, respawn and world change.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ namespace MinecraftClient
|
||||||
public static bool DisplayXPBarMessages = true;
|
public static bool DisplayXPBarMessages = true;
|
||||||
public static bool DisplayChatLinks = true;
|
public static bool DisplayChatLinks = true;
|
||||||
public static bool TerrainAndMovements = false;
|
public static bool TerrainAndMovements = false;
|
||||||
|
public static bool InventoryHandling = false;
|
||||||
public static string PrivateMsgsCmdName = "tell";
|
public static string PrivateMsgsCmdName = "tell";
|
||||||
public static CacheType SessionCaching = CacheType.Disk;
|
public static CacheType SessionCaching = CacheType.Disk;
|
||||||
public static bool DebugMessages = false;
|
public static bool DebugMessages = false;
|
||||||
|
|
@ -224,6 +225,7 @@ namespace MinecraftClient
|
||||||
case "showxpbarmessages": DisplayXPBarMessages = str2bool(argValue); break;
|
case "showxpbarmessages": DisplayXPBarMessages = str2bool(argValue); break;
|
||||||
case "showchatlinks": DisplayChatLinks = str2bool(argValue); break;
|
case "showchatlinks": DisplayChatLinks = str2bool(argValue); break;
|
||||||
case "terrainandmovements": TerrainAndMovements = str2bool(argValue); break;
|
case "terrainandmovements": TerrainAndMovements = str2bool(argValue); break;
|
||||||
|
case "inventoryhandling": InventoryHandling = str2bool(argValue); break;
|
||||||
case "privatemsgscmdname": PrivateMsgsCmdName = argValue.ToLower().Trim(); break;
|
case "privatemsgscmdname": PrivateMsgsCmdName = argValue.ToLower().Trim(); break;
|
||||||
case "botmessagedelay": botMessageDelay = TimeSpan.FromSeconds(str2int(argValue)); break;
|
case "botmessagedelay": botMessageDelay = TimeSpan.FromSeconds(str2int(argValue)); break;
|
||||||
case "debugmessages": DebugMessages = str2bool(argValue); break;
|
case "debugmessages": DebugMessages = str2bool(argValue); break;
|
||||||
|
|
@ -538,6 +540,7 @@ namespace MinecraftClient
|
||||||
+ "showxpbarmessages=true # Messages displayed above xp bar\r\n"
|
+ "showxpbarmessages=true # Messages displayed above xp bar\r\n"
|
||||||
+ "showchatlinks=true # Show links embedded in chat messages\r\n"
|
+ "showchatlinks=true # Show links embedded in chat messages\r\n"
|
||||||
+ "terrainandmovements=false # Uses more ram, cpu, bandwidth\r\n"
|
+ "terrainandmovements=false # Uses more ram, cpu, bandwidth\r\n"
|
||||||
|
+ "inventoryhandling=false # Toggle inventory handling\r\n"
|
||||||
+ "sessioncache=disk # How to retain session tokens. Use 'none', 'memory' or 'disk'\r\n"
|
+ "sessioncache=disk # How to retain session tokens. Use 'none', 'memory' or 'disk'\r\n"
|
||||||
+ "resolvesrvrecords=fast # Use 'false', 'fast' (5s timeout), or 'true'. Required for joining some servers.\r\n"
|
+ "resolvesrvrecords=fast # Use 'false', 'fast' (5s timeout), or 'true'. Required for joining some servers.\r\n"
|
||||||
+ "accountlist=accounts.txt # See README > 'Servers and Accounts file' for more info about this file\r\n"
|
+ "accountlist=accounts.txt # See README > 'Servers and Accounts file' for more info about this file\r\n"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue