From 76636ecbb9c6fd312cc450fcb82c4e7a0b67639e Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Wed, 1 Dec 2010 14:04:55 +0100 Subject: Made Client a child of abstract ClientBase. --- server/client.h | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'server') diff --git a/server/client.h b/server/client.h index cbb588f..ed3a47b 100644 --- a/server/client.h +++ b/server/client.h @@ -9,7 +9,37 @@ #include "connection.h" -class Client : public boost::enable_shared_from_this { +//! Abstract client base class. +class ClientBase { + public: + typedef boost::shared_ptr p; + + virtual ~ClientBase() {} + + //! Return client's nick. + virtual std::string nick() = 0; + + //! Notify client of a game start. + virtual void game_start(boost::function callback, std::vector players) = 0; + + //! Notify client of a round start. + virtual void round_start() = 0; + + typedef Message::RoundState::Player PlayerState; + + //! Send round state. + virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a) = 0; + + //! Send round end. + virtual void round_end(boost::function callback) = 0; + + //! Get action. Upon connection error, last element of expected_actions will be provided. + virtual void get_action(boost::function callback, Actions expected_actions) = 0; + +}; + +//! Class implementing ClientBase for real clients. +class Client : public ClientBase, public boost::enable_shared_from_this { public: typedef boost::shared_ptr p; @@ -44,24 +74,22 @@ class Client : public boost::enable_shared_from_this { void lobby_status(const std::vector& game_modes, boost::function callback); //! Return client's nick. - std::string nick(); + virtual std::string nick(); //! Notify client of a game start. - void game_start(boost::function callback, std::vector players); + virtual void game_start(boost::function callback, std::vector players); //! Notify client of a round start. - void round_start(); - - typedef Message::RoundState::Player PlayerState; + virtual void round_start(); //! Send round state. - void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a); + virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a); //! Send round end. - void round_end(boost::function callback); + virtual void round_end(boost::function callback); //! Get action. Upon connection error, last element of expected_actions will be provided. - void get_action(boost::function callback, Actions expected_actions); + virtual void get_action(boost::function callback, Actions expected_actions); }; typedef std::vector Clients; -- cgit v1.2.3