ethanmoffat / EndlessClient

An open source client for Endless Online written in C#
MIT License
34 stars 16 forks source link

EOLib.Net - generated packet code #268

Closed ethanmoffat closed 1 month ago

ethanmoffat commented 1 year ago

Cirras wrote a complete documentation of the EO protocol in XML format: https://github.com/Cirras/eo-protocol. It would be great to use this for automatic code gen of packet handlers and structures.

Pros

Cons

Some thoughts:

  1. Create EOLib.Net.Protocol project
  2. Add eo-protocol as a submodule of EndlessClient
  3. Code generation using Roslyn generators, similar to how [Record] works
    • Take eo-protocol net directory as an input
  4. Structures from eo-protocol get turned into class files
  5. Packet specs from eo-protocol get turned into "parsers"
    • Each parser takes a Packet input and spits out a parsed object
  6. Existing handlers take a parsed object as a parameter and no longer do parsing (data handling only)
  7. Incoming packets are fed through a top-level parser object that finds the appropriate packet parser based on Family/Action
  8. Once parsed, just need to find a handler based on the object type instead of looking up based on family/action again

Still need to figure out what the interface for the parsers/handlers will look like. Ideally the parsed objects would be strongly-typed classes with each of the fields defined as properties. This makes it a bit difficult to define a single interface since each of the object types is different.