markiodev / Networker

A simple to use TCP and UDP networking library for .NET. Compatible with Unity.
MIT License
477 stars 77 forks source link

Suggestion: Decouple packet handler from packet serializer #34

Closed snarlynarwhal closed 5 years ago

snarlynarwhal commented 5 years ago

If an application has a lot of packets and the developer must create a handler for each packet, it might get tedious, especially if a group of packet handlers have the same dependencies.

Ideally, related packets that require similar dependencies would get processed by the same handler. For example, in a game, all combat packets could get handled by CombatHandler. Of course if this class grows unwieldy, a developer could always break it all the way down to the traditional 1:1 relationship, if desired.

If the packet processor handled deserialization and the handler just processed the packet, then PacketHandlerBase<T> could get replaced by IPacketHandler<T> which would just require the Process method. This way, a concrete implementation could implement any number of IPacketHandler<T> interfaces.

What do you think?

markiodev commented 5 years ago

👍 That sounds like a good idea to me. Would you like to have a go at it? :)

snarlynarwhal commented 5 years ago

Certainly, I'll give it a go over the weekend :)

markiodev commented 5 years ago

Supported in 3.0, documentation to follow.