#ifndef MESSAGE_H #define MESSAGE_H #include #include using boost::make_shared; using boost::dynamic_pointer_cast; #include #include #include #include #include #include "action.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; // Player contents. struct Player { //! Concealed tiles in hand. Tiles hand; //! Open tiles in hand. Tilegroups open; //! Discarded tiles. Tiles pond; template void serialize(Archive & ar, const unsigned int version) { ar & hand; ar & open; ar & pond; } }; RoundState(); RoundState(const Player& pl_d, const Player& pl_r, const Player& pl_u, const Player& pl_l, const Tiles& d, const Actions& a); Player players[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