How to properly organise net code?

Hello all! I’m building an item-based multiplayer game where everything revolves around gear (like Diablo 2 without leveling up). I’ve written countless amounts of net demos and stuff but nothing ever seems to feel organized. I’m using libgdx w/ WebSockets. Here are some things that get very messy in my code.

  • Packets. I usually create a package for packets but how much is okay to send per second seems to be hard to detect.
  • Handlers. After sending a packet between the server and client I’m never sure how I should structure things. Should there be a handler class within the Server class?
  • Should I have methods dedicated to sending packets instead of initiating packet objects in the player’s logical loop?
  • How on God’s green earth should I handle events? Things like… attacking another player, initiating a multiplayer cutscene, etc? Should I be using a scripting language or is that really overcomplicating things?

Here’s a video showing what I made last year. Runs well, but of course the code behind is a complete mess.

XAVIXiPokBg

This time around I want to keep the netcode a priority. Thanks in advance!