vexyl / MCHawk

A Minecraft classic server
MIT License
8 stars 4 forks source link

Generic protocols #44

Open vexyl opened 6 years ago

vexyl commented 6 years ago

Protocols should be more generic. Keep it all in C++ (could be done in Lua, but no reason to do so). Protocol base class/interface? It should at least register itself with the server and worlds can check if a given protocol is available and do whatever it wants based on that. E.g., worlds could choose whether to use CPE or not and players could create entirely classic worlds (no CPE).

Example idea:

class IProtocol {
    virtual bool IsValidBlock(int type) = 0;
    virtual GetName() = 0;
};

...

class CPE : public IProtocol
{
    // implement the above virtual functions
    /// ...
}

CPE::CPE()
{
    Server::GetInstance()->RegisterProtocol("CPE", this);
}

/* ...
 * Server/World use the above for whatever
*/
GiantCrocodile commented 6 years ago

A protocol should also report its version and if it's deprecated (can be checked by the server).