Commit Graph

92 Commits

Author SHA1 Message Date
9f0a184a5d Packet: Remove mayHaveUnreadBytes()
this was an old hack to prevent debug spam being emitted when we halted decoding of logins over breaking protocol changes. Since then, we've gone back to trying to decode the packet regardless, so this property is useless.
2019-06-05 15:37:35 +01:00
287c8c2dd4 Added static create() functions for many packets
There are a few motivations here:
1) Less boilerplate code (this can be written inline)
2) It's possible to provide multiple constructors for different packet variations to reduce the chance of errors.
3) It makes things catch fire on updates in ways that static analysers can understand.
2019-06-05 15:00:08 +01:00
cda565ba8c Merge branch 'stable'
# Conflicts:
#	resources/vanilla
#	src/pocketmine/inventory/ArmorInventory.php
2019-06-04 18:19:47 +01:00
6f29fe063f move PlayerListPacket sending responsibility to NetworkSession 2019-06-04 18:02:36 +01:00
33d1203bfd Player: move sendAllInventories() to network layer 2019-05-26 15:58:03 +01:00
85718e2750 Clean up a bunch of garbage in Furnace 2019-05-26 15:43:46 +01:00
3ea8da2dd3 Use EnumTrait->equals() instead of direct comparison
It's not guaranteed that objects provided are the same as those in the enum registry, so they can't be directly compared.

Implementing comparison with === would require some kind of __equals() implementation or an extension to hook into such functionality.
2019-05-24 17:21:44 +01:00
bca0833035 Clean up handling of armour sync 2019-05-19 16:56:10 +01:00
67affcea32 move more packet logic to net session
it seems like net session is turning into a giant dumping ground for sending API ... this needs to be cleaned up somehow.
2019-05-19 15:48:01 +01:00
c3c2dd3988 Rename SimpleSessionHandler -> InGameSessionHandler
the "simple" name comes from the early days of this refactor before I started splitting everything up into their own units. This handler is now in good enough condition to have a proper name.
2019-05-18 19:13:41 +01:00
c1a483a36d move entity spawning logic back to Player 2019-05-07 18:35:04 +01:00
d7a7ab5102 Move Entity despawn logic back to Player
this is not network-session specific, and different implementations will need to do this.
2019-05-07 18:01:23 +01:00
3cd6e12e71 Renaming "Level" -> "World" (#2907)
This has been a pain point for a long time due to the misleading nature of the name "level". It's also confusing when trying to do things like getting the XP level of the player or such, and also does not translate well to other languages.

This transition was already executed on the UI some time ago (language strings) and now it's time for the same change to occur on the API.

This will burn a lot of plugins, but they'll acclimatize. Despite the scary size of this PR, there isn't actually so many changes to make. Most of this came from renaming `Position->getLevel()` to `Position->getWorld()`, or cosmetic changes like changing variable names or doc comments.
2019-05-07 14:47:28 +01:00
427e334426 rename PacketStream to PacketBatch 2019-05-06 19:58:02 +01:00
c2771eba88 use the appropriate API for decoding packet batches 2019-05-06 17:46:17 +01:00
82974e0271 NullSessionHandler: possibly premature optimization 2019-05-06 17:28:56 +01:00
685481b172 NetworkSession: improve GC performance without crashing everything
this is necessary because some handlers have circular references to the session, which causes GC lag collecting them. This change allows them to be collected immediately without nuking internal state.
2019-05-06 16:43:05 +01:00
5250a432d1 NetworkSession: add a dedicated PrefixedLogger, clean up some boilerplate code 2019-05-06 16:32:34 +01:00
793f93afdb NetworkSession: sync with latest code generation changes 2019-04-25 14:49:20 +01:00
fa70127241 1.11.0 protocol changes 2019-04-24 19:54:16 +01:00
0dac982f16 Merge branch 'stable' 2019-04-21 16:56:53 +01:00
939dfd9269 First look at separating chunk sending from Level 2019-04-17 19:33:37 +01:00
0e3e984db9 Player: Disconnects no longer nuke player internals, (mostly) fixes #1239
there are some problems that haven't been accounted for yet, but this fixes all the direct crashes.
2019-04-03 17:44:34 +01:00
e5756dbf0b Move a whole bunch of packet crap to NetworkSession 2019-04-02 18:31:16 +01:00
9ec62643d5 Player construction now happens when we're ready to create the player entity
this fixes a wide range of bugs with the initial spawn sequence, and allows to simplify a whole lot of player setup logic.
2019-03-23 10:13:14 +00:00
433dab078b DataPacket events now use network sessions instead of players 2019-03-23 09:52:03 +00:00
cce99b07af 1.10.0 updates 2019-03-20 19:17:41 +00:00
ebfe9caca3 Move too-early-send check to NetworkSession 2019-03-14 14:45:30 +00:00
26a5d97499 Some cleanup to player net session handling for connect/disconnect 2019-03-14 14:32:43 +00:00
f680a239f7 NetworkSession: some exception handling cleanup 2019-02-28 16:36:03 +00:00
19f0d7f336 NetworkSession: Don't apply handlers to a disconnected session
closes #2756
2019-02-15 10:11:31 +00:00
b8703d5dff Protocol changes for 1.9.0 2019-02-07 21:56:42 +00:00
467caf347d NetworkSession: Consistently don't use 0x prefix 2019-01-20 11:06:47 +00:00
5d8568b1a4 Add NetworkSession->getDisplayName(), clean up ip/port ad-hoc usages 2019-01-20 11:05:12 +00:00
76f1ee1827 Add restrictions on packet send directions with interfaces
This prevents plugins sending wrong packets at the compiler level (or would, if we had a compiler). It's more robust than a getter for client/server and throwing an exception since a static analysis tool can detect faults created by sending wrong packets from the server. This is also used to deny service to dodgy clients which send wrong packets to the server to attack it.
2019-01-17 12:51:24 +00:00
b82e00ffdf Extract a Packet interface from DataPacket
this is in preparation for clientbound/serverbound packet separation. I did this already on another branch, but the changeset was dependent on a massive refactor to split apart packets and binarystream which i'm still not fully happy with.
2019-01-17 12:21:56 +00:00
23269da1a6 Fixed the disaster of packet receive error handling 2019-01-16 19:53:48 +00:00
728bc95d73 NetworkSession: remove premature GC optimization
The only cyclic references here are both destroyed during normal collection directly (net interface removes from sessions array, player destroys its session reference), so there's no need to destroy them again here. This just causes a giant swathe of potential crashes for no real benefit.

close #2669
2019-01-16 16:50:16 +00:00
acdd0fec5f NetworkSession: player may be null 2019-01-16 16:19:39 +00:00
adc1069ed2 Merge branch '3.5' 2019-01-04 23:28:44 +00:00
f81bbd60e8 Avoid use of internal fields in BinaryStream 2019-01-01 16:42:14 +00:00
30f5a8fac6 Protocol changes for 1.8.0 release 2018-12-11 21:05:03 +00:00
839d5eab7b Protocol changes for 1.7
there's also some new cases in stats, but we don't care about those anyway.
2018-10-16 17:13:52 +01:00
4608ecde9b Merge branch 'release/3.3' 2018-10-05 18:29:37 +01:00
535d4e2c9b Added NetworkSession->getPlayer() 2018-09-12 10:51:37 +01:00
986077e03c Protocol changes for 1.6.0.1 2018-08-21 17:14:53 +01:00
15bac8c58a Implement send buffering and queuing for network sessions (#2358)
Async compression and broadcasts are now reliable and don't have race condition bugs.
This features improved performance and significantly reduced bandwidth wastage.

Reduce Level broadcast latency by ticking network after levels. This ensures that session buffers get flushed as soon as possible after level tick, if level broadcasts were done.
2018-08-13 14:37:18 +01:00
a5383b4a82 Use SetLocalPlayerAsInitializedPacket for spawning, fixed a bunch of bugs
this should fix forms not working during PlayerJoinEvent, and also removes the spurious PlayerItemHeldEvent firing on spawn bug.

The player MUST now send this packet. Bots take note.
2018-08-05 10:45:41 +01:00
10ba3d6359 Network: add ability to tick sessions
moved responsibility for login timeout checks to NetworkSession instead of Server
2018-08-02 17:39:09 +01:00
7560880168 Added DataPacketBroadcastEvent, refactor broadcast handling, close #1521
batchPackets() is now considered internal and shouldn't be used by plugins.

Added Server->broadcastPackets(Player[], DataPacket[]) : bool
2018-08-02 15:54:30 +01:00