This is a very complicated question. Reverse engineering a public game server via network traffic sniffing is legal in the general sense because you’re doing it without direct knowledge of the server code. However many game EULAs forbid exactly this, or even forbid playing on private servers. And you have to agree to the EULA in order to use the game client. When in doubt, read the EULA.
However, speaking practically, many game companies don’t enforce this.