Skip to content

Commit 558b383

Browse files
committed
add Server-Authoritative movement system
If your plugins depends on legacy movement packets and stopped working, set ServerAuthoritativeMovement to false in server.conf.
1 parent 3ed5f1a commit 558b383

File tree

8 files changed

+271
-170
lines changed

8 files changed

+271
-170
lines changed

src/MiNET/MiNET.Console/server.conf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ ForceResourcePacks=false
8989
# ======================================= ADVANCED =======================================
9090
# Change this only on purpose. Don't touch if you are not sure.
9191

92+
#Use Server-Authoritative movement system.
93+
ServerAuthoritativeMovement=true
94+
9295
#Should server check if player is logged in Xbox Live? In public server this should be true to avoid fake usernames.
9396
ForceXBLAuthentication=true
9497

@@ -122,7 +125,7 @@ ResourceDirectory=ResourcePacks
122125

123126
# REGEX docs! https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx
124127
#TracePackets.Include=Mcpe.*
125-
TracePackets.Exclude=McpeWrapper|McpeBatch|McpeFullChunkData|McpeMoveEntity|McpeMoveEntityDelta|McpeUpdateBlock
128+
TracePackets.Exclude=McpeWrapper|McpeBatch|McpeFullChunkData|McpeMoveEntity|McpeMoveEntityDelta|McpeUpdateBlock|McpePlayerAuthInput
126129
TracePackets.Verbosity=0
127130
TracePackets.Verbosity.McpeClientToServerHandshake=0
128131
TracePackets.Verbosity.McpeAddEntity=0

src/MiNET/MiNET/Net/AuthInputFlags.cs

Lines changed: 15 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,122 +5,57 @@ namespace MiNET.Net;
55
[Flags]
66
public enum AuthInputFlags : long
77
{
8-
/// <summary>
9-
/// Pressing the "fly up" key when using touch.
10-
/// </summary>
118
Ascend = 1L <<0,
12-
/// <summary>
13-
/// Pressing the "fly down" key when using touch.
14-
/// </summary>
159
Descend = 1L <<1,
16-
/// <summary>
17-
/// Pressing (and optionally holding) the jump key (while not flying).
18-
/// </summary>
1910
NorthJump = 1L <<2,
20-
/// <summary>
21-
/// Pressing (and optionally holding) the jump key (including while flying).
22-
/// </summary>
2311
JumpDown = 1L <<3,
24-
/// <summary>
25-
/// Pressing (and optionally holding) the sprint key (typically the CTRL key). Does not include double-pressing the forward key.
26-
/// </summary>
2712
SprintDown = 1L <<4,
28-
/// <summary>
29-
/// Pressing (and optionally holding) the fly button ONCE when in flight mode when using touch. This has no obvious use.
30-
/// </summary>
3113
ChangeHeight = 1L <<5,
32-
/// <summary>
33-
/// Pressing (and optionally holding) the jump key (including while flying), and also auto-jumping.
34-
/// </summary>
3514
Jumping = 1L <<6,
36-
/// <summary>
37-
/// Auto-swimming upwards while pressing forwards with auto-jump enabled.
38-
/// </summary>
3915
AutoJumpingInWater = 1L <<7,
40-
/// <summary>
41-
/// Sneaking, and pressing the "fly down" key or "sneak" key (including while flying).
42-
/// </summary>
4316
Sneaking = 1L <<8,
44-
/// <summary>
45-
/// Pressing (and optionally holding) the sneak key (including while flying). This includes when the sneak button is toggled ON with touch controls.
46-
/// </summary>
4717
SneakDown = 1L <<9,
48-
49-
/// <summary>
50-
/// Pressing the forward key (typically W on keyboard).
51-
/// </summary>
5218
WalkForwards = 1L <<10,
53-
/// <summary>
54-
/// Pressing the backward key (typically S on keyboard).
55-
/// </summary>
5619
WalkBackwards = 1L <<11,
57-
/// <summary>
58-
/// Pressing the left key (typically A on keyboard).
59-
/// </summary>
6020
StrafeLeft = 1L <<12,
61-
/// <summary>
62-
/// Pressing the right key (typically D on keyboard).
63-
/// </summary>
6421
StrafeRight = 1L <<13,
65-
6622
UpLeft = 1L <<14,
6723
UpRight = 1L <<15,
68-
69-
/// <summary>
70-
/// Client wants to go upwards. Sent when Ascend or Jump is pressed, irrespective of whether flight is enabled
71-
/// </summary>
7224
WantUp = 1L <<16,
73-
74-
/// <summary>
75-
/// Client wants to go downwards. Sent when Descend or Sneak is pressed, irrespective of whether flight is enabled
76-
/// </summary>
7725
WantDown = 1L <<17,
7826
WantDownSlow = 1L <<18,
7927
WantUpSlow = 1L <<19,
80-
8128
Sprinting = 1L <<20,
8229
AscendBlock = 1L <<21,
8330
DescendBlock = 1L <<22,
84-
85-
/// <summary>
86-
/// Toggling the sneak button on touch when the button enters the "enabled" state.
87-
/// </summary>
8831
SneakToggleDown = 1L <<23,
8932
PersistSneak = 1L <<24,
90-
91-
/// <summary>
92-
/// Pressing the sprint toggle while NOT sprinting.
93-
/// </summary>
9433
StartSprinting = 1L <<25,
95-
96-
/// <summary>
97-
/// Pressing the sprint toggle while sprinting.
98-
/// </summary>
9934
StopSprinting = 1L <<26,
100-
101-
/// <summary>
102-
/// Pressing the sneak toggle while NOT sneaking.
103-
/// </summary>
10435
StartSneaking = 1L <<27,
105-
106-
/// <summary>
107-
/// Pressing the sneak toggle while sneaking.
108-
/// </summary>
10936
StopSneaking = 1L <<28,
110-
11137
StartSwimming = 1L <<29,
11238
StopSwimming = 1L <<30,
113-
114-
/// <summary>
115-
/// Initiating a new jump. Sent every time the client leaves the ground due to jumping, including auto jumps.
116-
/// </summary>
11739
StartJumping = 1L <<31,
11840
StartGliding = 1L <<32,
11941
StopGliding = 1L <<33,
120-
12142
PerformItemInteraction = 1L <<34,
12243
PerformBlockActions = 1L <<35,
12344
PerformItemStackRequest = 1L <<36,
12445
HandledTeleport = 1L << 37,
125-
Emoting = 1L << 38
46+
Emoting = 1L << 38,
47+
MissedSwing = 1L << 39,
48+
StartCrawling = 1L << 40,
49+
StopCrawling = 1L << 41,
50+
StartFying = 1L << 42,
51+
StopFying = 1L << 43,
52+
IsInClientPredictedVehicle = 1L << 45,
53+
PaddlingLeft = 1L << 46,
54+
PaddlingRight = 1L << 47,
55+
BlockBreakingDelayEnabled = 1L << 48,
56+
HorizontalCollision = 1L << 49,
57+
VerticalCollision = 1L << 50,
58+
DownLeft = 1L << 51,
59+
DownRight = 1L << 52,
60+
INPUT_NUM = 1L << 53
12661
}

src/MiNET/MiNET/Net/BedrockMessageHandler.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ private void HandleBedrockMessage(IMcpeMessageHandler handler, Packet message)
246246
case McpeAnvilDamage msg:
247247
handler.HandleMcpeAnvilDamage(msg);
248248
break;
249+
case McpePlayerAuthInput msg:
250+
handler.HandleMcpePlayerAuthInput(msg);
251+
break;
249252

250253
default:
251254
{

src/MiNET/MiNET/Net/MCPE Protocol.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10608,7 +10608,7 @@ public partial class McpeEmotePacket : Packet<McpeEmotePacket>
1060810608
public string platformId; // = null;
1060910609
public string emoteId; // = null;
1061010610
public byte flags; // = null;
10611-
public long tick; // = null;
10611+
public uint tick; // = null;
1061210612

1061310613
public McpeEmotePacket()
1061410614
{
@@ -10624,10 +10624,10 @@ protected override void EncodePacket()
1062410624

1062510625
WriteUnsignedVarLong(runtimeEntityId);
1062610626
Write(emoteId);
10627+
WriteUnsignedVarInt(tick);
1062710628
Write(xuid);
1062810629
Write(platformId);
1062910630
Write(flags);
10630-
Write(tick);
1063110631

1063210632
AfterEncode();
1063310633
}
@@ -10643,10 +10643,10 @@ protected override void DecodePacket()
1064310643

1064410644
runtimeEntityId = ReadUnsignedVarLong();
1064510645
emoteId = ReadString();
10646+
tick = ReadUnsignedVarInt();
1064610647
xuid = ReadString();
1064710648
platformId = ReadString();
1064810649
flags = ReadByte();
10649-
tick = ReadLong();
1065010650

1065110651
AfterDecode();
1065210652
}
@@ -10662,7 +10662,7 @@ protected override void ResetPacket()
1066210662
xuid = default(string);
1066310663
platformId = default(string);
1066410664
emoteId = default(string);
10665-
tick = default(long);
10665+
tick = default(uint);
1066610666
flags = default(byte);
1066710667
}
1066810668

Lines changed: 26 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,30 @@
1-
using System.Numerics;
1+
using System.Collections.Generic;
2+
using System.Numerics;
3+
using MiNET.Utils.Vectors;
24

35
namespace MiNET.Net;
46

57
public partial class McpePlayerAuthInput : Packet<McpePlayerAuthInput>
68
{
7-
/// <summary>
8-
/// Pitch and Yaw hold the rotation that the player reports it has.
9-
/// </summary>
10-
public float Pitch;
11-
12-
/// <summary>
13-
/// Pitch and Yaw hold the rotation that the player reports it has.
14-
/// </summary>
15-
public float Yaw;
16-
17-
/// <summary>
18-
/// Pitch and Yaw hold the rotation that the player reports it has.
19-
/// </summary>
20-
public float HeadYaw;
21-
22-
/// <summary>
23-
/// Position holds the position that the player reports it has.
24-
/// </summary>
25-
public Vector3 Position;
26-
27-
/// <summary>
28-
/// MoveVector is a Vec2 that specifies the direction in which the player moved, as a combination of X/Z
29-
/// values which are created using the WASD/controller stick state.
30-
/// </summary>
31-
public Vector2 MoveVector;
32-
33-
/// <summary>
34-
/// InputData is a combination of bit flags that together specify the way the player moved last tick.
35-
/// </summary>
9+
public PlayerLocation Position;
3610
public AuthInputFlags InputFlags;
37-
38-
/// <summary>
39-
/// InputMode specifies the way that the client inputs data to the screen.
40-
/// </summary>
4111
public PlayerInputMode InputMode;
42-
43-
/// <summary>
44-
/// PlayMode specifies the way that the player is playing.
45-
/// </summary>
4612
public PlayerPlayMode PlayMode;
47-
48-
/// <summary>
49-
/// InteractionModel is a constant representing the interaction model the player is using.
50-
/// </summary>
5113
public PlayerInteractionModel InteractionModel;
52-
53-
/// <summary>
54-
/// GazeDirection is the direction in which the player is gazing, when the PlayMode is PlayModeReality: In other words, when the player is playing in virtual reality.
55-
/// </summary>
5614
public Vector3 GazeDirection;
57-
58-
/// <summary>
59-
/// Tick is the server tick at which the packet was sent. It is used in relation to CorrectPlayerMovePrediction.
60-
/// </summary>
6115
public long Tick;
62-
63-
/// <summary>
64-
/// Delta was the delta between the old and the new position.
65-
/// </summary>
6616
public Vector3 Delta;
17+
public PlayerBlockActions Actions;
6718

6819
public Vector2 AnalogMoveVector;
6920

7021
partial void AfterDecode()
7122
{
72-
Pitch = ReadFloat();
73-
Yaw = ReadFloat();
74-
Position = ReadVector3();
75-
MoveVector = ReadVector2();
76-
HeadYaw = ReadFloat();
23+
var Rot = ReadVector2();
24+
var Pos = ReadVector3();
25+
ReadVector2(); // what move vector?
26+
var HeadYaw = ReadFloat();
27+
Position = new PlayerLocation(Pos.X, Pos.Y, Pos.Z, HeadYaw, Rot.Y, Rot.X);
7728
InputFlags = (AuthInputFlags)ReadUnsignedVarLong();
7829
InputMode = (PlayerInputMode)ReadUnsignedVarInt();
7930
PlayMode = (PlayerPlayMode)ReadUnsignedVarInt();
@@ -87,24 +38,19 @@ partial void AfterDecode()
8738
Tick = ReadUnsignedVarLong();
8839
Delta = ReadVector3();
8940

90-
if ((InputFlags & AuthInputFlags.PerformItemInteraction) != 0)
41+
if ((InputFlags & AuthInputFlags.PerformBlockActions) != 0)
9142
{
92-
43+
Actions = ReadPlayerBlockActions();
9344
}
9445

9546
AnalogMoveVector = ReadVector2();
9647
}
9748

9849
partial void AfterEncode()
9950
{
100-
Write(Pitch);
101-
Write(Yaw);
102-
Write(Position);
103-
Write(MoveVector);
104-
Write(HeadYaw);
10551
WriteUnsignedVarLong((long)InputFlags);
10652
WriteUnsignedVarInt((uint)InputMode);
107-
WriteUnsignedVarInt((uint) PlayMode);
53+
WriteUnsignedVarInt((uint)PlayMode);
10854
WriteUnsignedVarInt((uint)InteractionModel);
10955

11056
if (PlayMode == PlayerPlayMode.VR)
@@ -117,13 +63,10 @@ partial void AfterEncode()
11763
Write(AnalogMoveVector);
11864
}
11965

120-
/// <inheritdoc />
12166
public override void Reset()
12267
{
12368
base.Reset();
124-
Pitch = Yaw = HeadYaw = 0f;
125-
MoveVector = Vector2.Zero;
126-
Position = Vector3.Zero;
69+
Position = default(PlayerLocation);
12770
InputFlags = 0;
12871
InputMode = PlayerInputMode.Mouse;
12972
PlayMode = PlayerPlayMode.Normal;
@@ -160,4 +103,16 @@ public enum PlayerInteractionModel
160103
Crosshair = 1,
161104
Classic = 2
162105
}
106+
107+
public class PlayerBlockActions
108+
{
109+
public List<PlayerBlockActionData> PlayerBlockAction = new List<PlayerBlockActionData>();
110+
}
111+
112+
public class PlayerBlockActionData
113+
{
114+
public PlayerAction PlayerActionType;
115+
public BlockCoordinates BlockCoordinates;
116+
public int Facing;
117+
}
163118
}

src/MiNET/MiNET/Net/Packet.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
using MiNET.Utils.Skins;
5050
using MiNET.Utils.Vectors;
5151
using Newtonsoft.Json;
52+
using static MiNET.Net.McpePlayerAuthInput;
5253

5354
namespace MiNET.Net
5455
{
@@ -3884,6 +3885,26 @@ public void Write(EmoteIds Ids)
38843885
}
38853886
}
38863887

3888+
public PlayerBlockActions ReadPlayerBlockActions()
3889+
{
3890+
PlayerBlockActions actions = new PlayerBlockActions();
3891+
var actionCount = ReadSignedVarInt();
3892+
for (int i = 0; i < actionCount; i++)
3893+
{
3894+
var actionType = (PlayerAction) ReadSignedVarInt();
3895+
if (actionType is PlayerAction.StartBreak or PlayerAction.AbortBreak or PlayerAction.StopBreak or PlayerAction.Breaking or PlayerAction.PredictDestroyBlock or PlayerAction.ContinueDestroyBlock)
3896+
{
3897+
actions.PlayerBlockAction.Add(new PlayerBlockActionData() { PlayerActionType = actionType, BlockCoordinates = new BlockCoordinates(ReadSignedVarInt(), ReadSignedVarInt(), ReadSignedVarInt()), Facing = ReadVarInt() });
3898+
}
3899+
else
3900+
{
3901+
actions.PlayerBlockAction.Add(new PlayerBlockActionData() { PlayerActionType = actionType});
3902+
3903+
}
3904+
}
3905+
return actions;
3906+
}
3907+
38873908
public fogStack Read()
38883909
{
38893910
fogStack stack = new fogStack();

0 commit comments

Comments
 (0)