mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Add basic location handling
- Retrieve player location from the server - Send back player location from the server - Requires that a specific setting is enabled - Should allow items to be picked up by the player - May also trigger some anti chead plugins
This commit is contained in:
parent
5654871a57
commit
72bd485e67
11 changed files with 319 additions and 17 deletions
|
|
@ -7,6 +7,7 @@ using System.Threading;
|
|||
using MinecraftClient.Crypto;
|
||||
using MinecraftClient.Proxy;
|
||||
using System.Security.Cryptography;
|
||||
using MinecraftClient.Mapping;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers
|
||||
{
|
||||
|
|
@ -615,6 +616,11 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
return false; //Only supported since MC 1.7
|
||||
}
|
||||
|
||||
public bool SendLocationUpdate(Location location, bool onGround)
|
||||
{
|
||||
return false; //Currently not implemented
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a plugin channel packet to the server.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using MinecraftClient.Crypto;
|
|||
using MinecraftClient.Proxy;
|
||||
using System.Security.Cryptography;
|
||||
using MinecraftClient.Protocol.Handlers.Forge;
|
||||
using MinecraftClient.Mapping;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers
|
||||
{
|
||||
|
|
@ -162,6 +163,23 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
catch (IndexOutOfRangeException) { /* No message type */ }
|
||||
handler.OnTextReceived(ChatParser.ParseText(message));
|
||||
break;
|
||||
case 0x08:
|
||||
if (Settings.TerrainAndMovements)
|
||||
{
|
||||
double x = readNextDouble(ref packetData);
|
||||
double y = readNextDouble(ref packetData);
|
||||
double z = readNextDouble(ref packetData);
|
||||
|
||||
byte locMask = readNextByte(ref packetData);
|
||||
Location location = handler.GetCurrentLocation();
|
||||
|
||||
location.X = (locMask & 1 << 0) != 0 ? location.X + x : x;
|
||||
location.Y = (locMask & 1 << 1) != 0 ? location.Y + y : y;
|
||||
location.Z = (locMask & 1 << 2) != 0 ? location.Z + z : z;
|
||||
|
||||
handler.UpdateLocation(location);
|
||||
}
|
||||
break;
|
||||
case 0x38: //Player List update
|
||||
if (protocolversion >= MC18Version)
|
||||
{
|
||||
|
|
@ -509,6 +527,18 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
return readData(len, ref cache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a double from a cache of bytes and remove it from the cache
|
||||
/// </summary>
|
||||
/// <returns>The double value</returns>
|
||||
|
||||
private static double readNextDouble(ref byte[] cache)
|
||||
{
|
||||
byte[] rawValue = readData(8, ref cache);
|
||||
Array.Reverse(rawValue); //Endianness
|
||||
return BitConverter.ToDouble(rawValue, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read an integer from the network
|
||||
/// </summary>
|
||||
|
|
@ -602,6 +632,19 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
return bytes.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get byte array representing a double
|
||||
/// </summary>
|
||||
/// <param name="array">Array to process</param>
|
||||
/// <returns>Array ready to send</returns>
|
||||
|
||||
private byte[] getDouble(double number)
|
||||
{
|
||||
byte[] theDouble = BitConverter.GetBytes(number);
|
||||
Array.Reverse(theDouble); //Endianness
|
||||
return theDouble;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get byte array with length information prepended to it
|
||||
/// </summary>
|
||||
|
|
@ -931,6 +974,29 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
return SendPluginChannelPacket("MC|Brand", getString(brandInfo));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a location update to the server
|
||||
/// </summary>
|
||||
/// <param name="location">The new location of the player</param>
|
||||
/// <param name="onGround">True if the player is on the ground</param>
|
||||
/// <returns>True if the location update was successfully sent</returns>
|
||||
|
||||
public bool SendLocationUpdate(Location location, bool onGround)
|
||||
{
|
||||
if (Settings.TerrainAndMovements)
|
||||
{
|
||||
try
|
||||
{
|
||||
SendPacket(0x04, concatBytes(
|
||||
getDouble(location.X), getDouble(location.X), getDouble(location.X),
|
||||
new byte[] { onGround ? (byte)1 : (byte)0 }));
|
||||
return true;
|
||||
}
|
||||
catch (SocketException) { return false; }
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a plugin channel packet (0x17) to the server, compression and encryption will be handled automatically
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using MinecraftClient.Crypto;
|
||||
using MinecraftClient.Mapping;
|
||||
|
||||
namespace MinecraftClient.Protocol
|
||||
{
|
||||
|
|
@ -45,7 +46,7 @@ namespace MinecraftClient.Protocol
|
|||
bool SendRespawnPacket();
|
||||
|
||||
/// <summary>
|
||||
/// Tell the server what client is being used to connect to the server
|
||||
/// Inform the server of the client being used to connect
|
||||
/// </summary>
|
||||
/// <param name="brandInfo">Client string describing the client</param>
|
||||
/// <returns>True if brand info was successfully sent</returns>
|
||||
|
|
@ -53,10 +54,17 @@ namespace MinecraftClient.Protocol
|
|||
bool SendBrandInfo(string brandInfo);
|
||||
|
||||
/// <summary>
|
||||
/// Send a plugin channel packet to the server.
|
||||
///
|
||||
/// http://dinnerbone.com/blog/2012/01/13/minecraft-plugin-channels-messaging/
|
||||
/// Send a location update telling that we moved to that location
|
||||
/// </summary>
|
||||
/// <param name="location">The new location</param>
|
||||
/// <returns>True if packet was successfully sent</returns>
|
||||
|
||||
bool SendLocationUpdate(Location location, bool onGround);
|
||||
|
||||
/// <summary>
|
||||
/// Send a plugin channel packet to the server.
|
||||
/// </summary>
|
||||
/// <see href="http://dinnerbone.com/blog/2012/01/13/minecraft-plugin-channels-messaging/" />
|
||||
/// <param name="channel">Channel to send packet on</param>
|
||||
/// <param name="data">packet Data</param>
|
||||
/// <returns>True if message was successfully sent</returns>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MinecraftClient.Mapping;
|
||||
|
||||
namespace MinecraftClient.Protocol
|
||||
{
|
||||
|
|
@ -22,6 +23,7 @@ namespace MinecraftClient.Protocol
|
|||
string GetUserUUID();
|
||||
string GetSessionID();
|
||||
string[] GetOnlinePlayers();
|
||||
Location GetCurrentLocation();
|
||||
|
||||
/// <summary>
|
||||
/// Called when a server was successfully joined
|
||||
|
|
@ -50,6 +52,13 @@ namespace MinecraftClient.Protocol
|
|||
|
||||
void OnPlayerLeave(Guid uuid);
|
||||
|
||||
/// <summary>
|
||||
/// Called when the server sets the new location for the player
|
||||
/// </summary>
|
||||
/// <param name="location">New location of the player</param>
|
||||
|
||||
void UpdateLocation(Location location);
|
||||
|
||||
/// <summary>
|
||||
/// This method is called when the connection has been lost
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue