252 Commits

Author SHA1 Message Date
Dylan K. Taylor
df33e179e5
Player: fixed chat newlines denial-of-service vulnerability
irresponsibly reported in #4974

closes #4974
2022-04-20 13:01:05 +01:00
Dylan K. Taylor
901449b0b1
Player: simplify PlayerItemHeldEvent calling on content change
the second parameter to this callback is the OLD slots, not the changed slots. This means that ALL slots are included, including empty and unchanged slots.
2022-03-23 13:47:01 +00:00
Dylan K. Taylor
ea33a04d00
Player: ensure that PlayerItemHeldEvent is called when the contents of the held slot changes
in PM3, this was done by implicitly relying on the client to send a MobEquipmentPacket selecting the same hotbar slot when the slot contents changes.
In PM4, we avoid relying on this, and fire the event directly when the listener detects a held slot change.
This ensures that the behaviour remains consistent regardless of what the client starts doing in the future.

closes #4905
2022-03-22 16:53:02 +00:00
Dylan K. Taylor
856fd2a33b
fix PHPStan failures 2022-03-09 17:26:05 +00:00
ShockedPlot7560
b9f1bcf0e4
Implement PlayerViewDistanceChangeEvent (#4749)
closes #4550
2022-01-25 18:00:26 +00:00
Dylan K. Taylor
419bb9eba6
Player: fixed parameter name inconsistency 2022-01-22 01:33:31 +00:00
Dylan K. Taylor
373880e582
Replace disallowed operators in src/player/ 2022-01-20 19:16:00 +00:00
Dylan K. Taylor
e04dfe96af
Merge branch 'stable' into next-minor 2022-01-01 17:55:17 +00:00
Dylan K. Taylor
c8247786d7
Player: check chat length check with strlen() before mb_strlen()
mb_strlen() is O(n), whereas strlen() is O(1). If we receive very large chat messages (e.g. 2 MB), mb_strlen() will take a very long time to return a result (around 8ms on my machine).
Since the max size of a UTF-8 character is 4 bytes (according to standard), we can use strlen() with 4x the char limit to gate it and prevent this from happening.
2022-01-01 16:46:00 +00:00
Dylan T
f486b5f4a7
Player: fixed fall damage when sprinting down stairs (#4685)
Due to the way positions are updated over the network, we only see the end result of a movement and not its preceding actions. In addition, we don't know for sure whether the MCPE collision checks work the same exact way as PM.

TL;DR: It's possible for the client to capture and send a movement frame after they collided with a step and then already moved forward from it some distance, resulting in a weird arc pattern.

This PR checks the range between the old and new positions for collision boxes to ensure that all possible areas are checked for detecting fall damage.

This has been tested and successfully resolves various issues involving running down stairs:
- missing sounds
- random fall damage
2022-01-01 15:41:19 +00:00
Dylan K. Taylor
207f7ec309
Player: avoid unnecessary network updates on repeated calls to setAllowFLight(), setHasBlockCollision() and setAutoJump() 2021-12-29 20:22:16 +00:00
Dylan K. Taylor
5c994e4a24
Player: removed an old hack for setFlying() feedback loop
this is no longer a concern, since we now check if the sent state matches the current state before doing anything, at multiple layers.
2021-12-29 18:41:11 +00:00
Dylan K. Taylor
d94578a420
Player: remove dead TODO comment 2021-12-29 18:32:53 +00:00
Dylan K. Taylor
7124d44b92
Player: prevent PlayerToggle(Sprint|Sneak|Fly|Glide|Swim)Events from firing multiple times with the same value
this happens with swimming due to bugs in the client.
2021-12-29 17:24:49 +00:00
Dylan K. Taylor
87170ab067
Player: move reach distances to constants 2021-12-27 17:32:04 +00:00
Dylan K. Taylor
74ac0f5862
Player: move max chat length to constant 2021-12-27 17:06:19 +00:00
Dylan K. Taylor
f5144d49b1
Merge branch 'stable' into next-minor 2021-12-27 16:52:22 +00:00
Dylan K. Taylor
8943d8a2a7
Player: fixed maximum message size limits to match vanilla bugrock 2021-12-27 16:51:47 +00:00
XenialDan
d41f933e7b
Implement swimming/gliding including AABB recalculation (#4446)
- The following events have been added:
  - PlayerToggleGlideEvent
  - PlayerToggleSwimEvent
- The following API methods have been added:
  - Entity->getSize()
  - Living->isSwimming()
  - Living->setSwimming()
  - Living->isGliding()
  - Living->setSwimming()
  - Player->toggleSwim()
  - Player->toggleGlide()
2021-12-19 17:10:41 +00:00
Dylan K. Taylor
4b06fe73f2
Merge branch 'stable' into next-minor 2021-12-14 22:54:39 +00:00
Dylan K. Taylor
45c4a9673d
Player: fixed arm swing animation not showing during attack cooldown of victim
closes #4650
2021-12-14 19:03:42 +00:00
Drew B
ce54d268f2
Player: allow controlling client-sided block collisions irrespective of Spectator Mode (#4563)
- Added the following API methods:
  - `Player::hasBlockCollision()`
  - `Player::setHasBlockCollision()`

This enables spectator-like noclip behaviour in other gamemodes (could be useful for builders).
2021-12-06 21:14:22 +00:00
Dylan K. Taylor
c7beb0a702
Clean up inventory auto close mess from PM3
on PM3 there was no concept of 'current window', we had no idea which window the player was actually looking at.
2021-11-08 23:51:25 +00:00
Dylan K. Taylor
5be429a8c4
Ensure inventories get evacuated on server-side window close 2021-11-08 23:48:05 +00:00
Dylan K. Taylor
ab002ca06d
Improved handling of temporary inventory windows
evacuation behaviour is now consistent regardless of who is doing it
2021-11-08 23:36:58 +00:00
Dylan K. Taylor
45edb94607
Crafting tables now work the same way as anvils and enchanting tables
Removing almost all special-case logic for crafting tables.
2021-11-07 16:20:07 +00:00
Dylan K. Taylor
b8523f7a18
Player: fix the fix which just degraded performance
if a chunk was requested for generation, count++ and count(activeRequests)++, which means that we would only get to submit half as many generation requests as we're allowed to.
Calculate the limit at the start and remember it instead.
2021-11-06 01:00:35 +00:00
Dylan K. Taylor
640e88009b
Player: fixed a mistake in generation rate limit
we don't want to allow sending further chunks when we haven't generated near ones, because we won't be able to see them anyway, and we might end up not needing them.
This now fully matches the results of PM3.
2021-11-06 00:57:37 +00:00
Dylan K. Taylor
dbf9a33160
ChunkSelector: Improve algorithm to send chunks in proper circles, instead of squares
this ensures that the edge of loaded terain is always the same distance
away in any direction. This also means that when flying parallel to X or
Z axes, you now have about 12% more chunks directly in front of you,
instead of to your left and right, which gives the impression that
chunks are loading faster (they aren't, they are just being ordered in a
more sensible way).
2021-11-06 00:15:04 +00:00
Dylan K. Taylor
0989c77037
Player: check that horizontal distance travelled is > 0 before adding exhaustion, or triggering a new chunk order
closes #4548
2021-11-05 15:46:55 +00:00
Dylan K. Taylor
5107d0df4e
Player: cap maximum number of active generation requests
this fixes the horrible spotty chunk loading seen in https://twitter.com/dktapps/status/1456397007946461190?s=20.
In practice, this made chunks invisible on teleport for several tens of seconds after teleporting. Having a larger chunks-per-tick with large render distance compounded to worsen the problem.
It wasn't really noticeable on small render distances, but very obvious on large ones with fast chunk sending and slow generation.

This also fixes #4187 (at least to the extent that it works on PM3, anyway).
2021-11-05 15:09:42 +00:00
Dylan K. Taylor
2405e45b35
Player: mark as not using item when held item slot is changed
closes #4538
2021-11-03 21:26:20 +00:00
Dylan K. Taylor
ef82a2cd79
Fixed PlayerEmoteEvent::setEmoteId() being useless 2021-11-02 23:10:26 +00:00
Dylan K. Taylor
87031627bf
Do not call PlayerEmoteEvent if rate limit was reached 2021-11-02 23:09:43 +00:00
Hashim
f066199971
Implement emote support (#4523) 2021-11-02 23:04:55 +00:00
Dylan K. Taylor
e34364412b
Replace InvalidStateException usages with InvalidArgument or LogicException 2021-11-02 16:05:54 +00:00
Rush2929
ede4157814
Check to see if the player can start using the Releasable item. (#4532) 2021-11-02 14:36:16 +00:00
Dylan K. Taylor
804fb3f603
Merge commit 141fbde6604da5001b73db0dae86fc6f397939e0 2021-11-01 17:39:40 +00:00
Dylan K. Taylor
46b7d35cd3
Player: return from callback if used chunk status is not REQUESTED_GENERATION()
this can happen especially on large render distances when flying fast and changing direction - we decide we don't want the chunk, then, after changing direction and re-ordering chunks, we decide we do want it again, and end up registering a second callback. In this case, we need to ensure that only one of the callbacks gets executed (it doesn't matter which one).
2021-11-01 01:45:49 +00:00
Dylan K. Taylor
bd60e41268
Revert "Revert "Player: do not re-request the same ungenerated chunks multiple times""
This reverts commit 3265d3f6b4d6705276b56fab5f765e2f97b5d992.
2021-10-31 22:57:56 +00:00
Dylan K. Taylor
3265d3f6b4
Revert "Player: do not re-request the same ungenerated chunks multiple times"
This reverts commit 866020dfdb06434b4f361a4a0f0faf7a89c30ed2.

For some fucking reason this broke resending chunks in some cases (and
sending chunks at all in others). I don't have time to debug this right
now, so it's going to have to remain broken, infuriatingly enough.
2021-10-31 21:25:21 +00:00
Dylan K. Taylor
866020dfdb
Player: do not re-request the same ungenerated chunks multiple times
this doesn't affect chunk resends, since they'll be kicked back to NEEDED, which is detected by orderChunks().
2021-10-31 18:52:37 +00:00
Dylan K. Taylor
4f816d03a7
SurvivalBlockBreakHandler: remove useless code 2021-10-30 21:35:58 +01:00
Dylan K. Taylor
1d22761d27
Remove useless newline 2021-10-30 21:25:47 +01:00
Dylan K. Taylor
8a2ecfe1d4
Merge branch 'stable' 2021-10-29 19:04:01 +01:00
Dylan K. Taylor
6d89265510
Player: reduce code duplication
back when this was just hardcoded >> 4 everywhere, nobody thought anything of it, but now it uses constants, it's easy to cross-reference and see where the duplicates are.
2021-10-26 23:02:50 +01:00
Dylan K. Taylor
04aedc6494
Updated BedrockProtocol 2021-10-23 23:54:49 +01:00
Dylan K. Taylor
c773e43eda
Updated BedrockProtocol to pmmp/BedrockProtocol@97fa88e9ef 2021-10-23 01:16:45 +01:00
Dylan K. Taylor
bb6ea8cbdc
Do not call PlayerLoginEvent during the Player constructor
this closes a lot of loopholes in the login sequence that plugins were using to cause crashes.
2021-10-04 22:36:50 +01:00
Dylan K. Taylor
3836a57ba6
Player: add getPlayerInfo(), closes #4450 2021-09-17 22:17:36 +01:00