#ifndef MESSAGE_H #define MESSAGE_H #include #include using boost::make_shared; using boost::dynamic_pointer_cast; #include #include #include #include #include #include "state.h" #include "tile.h" namespace Message { namespace Types { //! Message types. enum Type { Undefined, Hello, Login, LoginResponse, LobbyStatus, LobbyAction, GameStart, Ready, RoundStart, RoundState, RoundAction, RoundEnd, GameEnd }; } using Types::Type; class Base { protected: Base(Type t); public: const Type type; virtual std::pair serialize() = 0; virtual void deserialize(uint8_t* data, std::size_t bytes) = 0; }; class NullBase : public Base { protected: NullBase(Type t); public: virtual std::pair serialize(); virtual void deserialize(uint8_t* data, std::size_t bytes); }; class BoostBase : public Base { protected: BoostBase(Type t); public: virtual std::pair serialize(); virtual void deserialize(uint8_t* data, std::size_t bytes); virtual void serialize(boost::archive::text_oarchive& ar) = 0; virtual void deserialize(boost::archive::text_iarchive& ar) = 0; }; class Hello : public Base { public: typedef boost::shared_ptr p; Hello(); Hello(const std::string& v); std::string version; virtual std::pair serialize(); virtual void deserialize(uint8_t* data, std::size_t bytes); }; class Login : public Base { public: typedef boost::shared_ptr p; Login(); Login(const std::string& n); std::string nick; virtual std::pair serialize(); virtual void deserialize(uint8_t* data, std::size_t bytes); }; class LoginResponse : public Base { public: typedef boost::shared_ptr p; LoginResponse(); LoginResponse(bool ok); bool login_ok; virtual std::pair serialize(); virtual void deserialize(uint8_t* data, std::size_t bytes); }; class GameStart : public BoostBase { public: typedef boost::shared_ptr p; GameStart(); std::vector players; int player_id; virtual void serialize(boost::archive::text_oarchive& ar); virtual void deserialize(boost::archive::text_iarchive& ar); }; class Ready : public NullBase { public: typedef boost::shared_ptr p; Ready(); }; class RoundStart : public NullBase { public: typedef boost::shared_ptr p; RoundStart(); }; class RoundState : public BoostBase { public: typedef boost::shared_ptr p; RoundState(); RoundState(State state); Tiles hand[4]; Tiles open[4]; Tiles pond[4]; Tiles dora; Actions possible_actions; virtual void serialize(boost::archive::text_oarchive& ar); virtual void deserialize(boost::archive::text_iarchive& ar); }; class RoundAction : public BoostBase { public: typedef boost::shared_ptr p; RoundAction(); Action action; virtual void serialize(boost::archive::text_oarchive& ar); virtual void deserialize(boost::archive::text_iarchive& ar); }; class RoundEnd : public NullBase { public: typedef boost::shared_ptr p; RoundEnd(); }; typedef boost::shared_ptr p; }; #endif