GameLayer is the main interface to the higher layer of libtpproto-cpp. More...
#include <gamelayer.h>
Public Member Functions | |
| GameLayer () | |
| Constructs object and sets up defaults. | |
| ~GameLayer () | |
| Destructor. | |
| void | setClientString (const std::string &name) |
| Sets the client string. | |
| void | setLogger (Logger *nlog) |
| Sets the Logger to use. | |
| void | setGameStatusListener (GameStatusListener *gsl) |
| Sets the GameStatusListener to use. | |
| void | setCacheMethod (CacheMethod *prototype) |
| Sets the CacheMethod for the caches to use. Changes the default CacheMethod used, defaults to CacheNoneMethod. | |
| void | setEventLoop (EventLoop *el) |
| Sets the EventLoop abstraction to use. Sets which implementation of EventLoop to use. | |
| GameStatus | getStatus () |
| Gets the state of the game. | |
| ProtocolLayer * | getProtocolLayer () const |
| Gets the ProtocolLayer being used. This could be used to do low level calls to the protocol itself, or more importantly, set the FrameFactory, FrameBuilder and/or FrameCodec classes in the ProtocolLayer. | |
| bool | connect (const std::string &address) |
| Connects to the given address url This method connects to the server given as the address. The types of url supported are tp, tps, https and http. Tps and https depend on TLS being enabled. | |
| bool | connect (TPSocket *nsock) |
| Connects using a given TPSocket. Connects to a server using a given TPSocket. | |
| bool | createAccount (const std::string &user, const std::string &password, const std::string &game, const std::string &email, const std::string &comment) |
| Creates an account on the server. | |
| bool | login (const std::string &user, const std::string &password, const std::string &game) |
| Logs in to the server. | |
| void | disconnect () |
| Disconnects from server. | |
| void | updateCaches () |
| Tells all the caches to update. Called automatically after logged in, and after EOT has finished. Call if you want the caches to be updated. | |
| ObjectDescCache * | getObjectDescCache () const |
| Gets the ObjectDescCache. | |
| ObjectCache * | getObjectCache () const |
| Gets the ObjectCache. | |
| OrderDescCache * | getOrderDescCache () const |
| Gets the OrderDescCache. | |
| std::list< Order * > | getOrders (uint32_t obid, uint32_t num) |
| Gets Orders from the server. | |
| Order * | getOrder (uint32_t obid, uint32_t slot) |
| Gets an Orders from the server. | |
| Order * | createOrderFrame (int type) |
| Creates an Order Frame of a given type. | |
| bool | insertOrder (Order *frame) |
| Inserts an Order into the objects order queue. | |
| bool | replaceOrder (Order *frame) |
| Replaces a current Order with a new one. | |
| Order * | probeOrder (Order *frame) |
| Probes an Order. | |
| bool | removeOrder (uint32_t obid, uint32_t slot) |
| Removes an Order from the server. | |
| BoardCache * | getBoardCache () const |
| Gets the BoardCache. | |
| std::list< Message * > | getMessages (uint32_t boardid, uint32_t num) |
| Gets Messages from the server. | |
| Message * | createMessage () |
| Creates a Message object. | |
| Message * | getMessage (uint32_t boardid, uint32_t slot) |
| Gets a Message from the server. | |
| bool | postMessage (Message *frame) |
| Posts a Message to the server. | |
| bool | removeMessage (uint32_t boardid, uint32_t slot) |
| Removes messages from the server. | |
| ResourceCache * | getResourceCache () const |
| Gets the ResourceCache. | |
| PlayerCache * | getPlayerCache () const |
| Gets the PlayerCache. | |
| CategoryCache * | getCategoryCache () const |
| Gets the CategoryCache. | |
| DesignCache * | getDesignCache () const |
| Gets the DesignCache. | |
| ComponentCache * | getComponentCache () const |
| Gets the ComponentCache. | |
| PropertyCache * | getPropertyCache () const |
| Gets the PropertyCache. | |
| void | getTimeRemaining () |
| Gets the time remaining before the end of turn. | |
| void | finishedTurn () |
| Tells the server that the player has finished their turn. | |
| std::set< GameInfo * > | getAvailableGames () const |
| GameInfo * | getActiveGame () const |
Friends | |
| class | GameLayerAsyncFrameListener |
GameLayer is the main interface to the higher layer of libtpproto-cpp.
GameLayer abstracts away most of the underlying details of how Objects and Orders are requested and received.
| TPProto::GameLayer::GameLayer | ( | ) |
Constructs object and sets up defaults.
Defaults are
References TPProto::ProtocolLayer::getFrameBuilder(), TPProto::ProtocolLayer::getFrameCodec(), TPProto::FrameCodec::setAsyncFrameListener(), TPProto::GameLayerAsyncFrameListener::setGameLayer(), TPProto::FrameBuilder::setObjectDescCache(), TPProto::FrameBuilder::setOrderDescCache(), and TPProto::Cache::setProtocolLayer().
| bool TPProto::GameLayer::connect | ( | TPSocket * | nsock | ) |
Connects using a given TPSocket. Connects to a server using a given TPSocket.
| nsock | The TPSocket to connect using. |
References TPProto::TPSocket::connect(), TPProto::FrameFactory::createConnect(), TPProto::Logger::debug(), TPProto::Logger::error(), TPProto::ProtocolLayer::getFrameCodec(), TPProto::ProtocolLayer::getFrameFactory(), TPProto::EventLoop::listenForSocketRead(), TPProto::FrameCodec::sendFrame(), TPProto::Connect::setClientString(), TPProto::TPSocket::setConnection(), and TPProto::Logger::warning().
| bool TPProto::GameLayer::connect | ( | const std::string & | address | ) |
Connects to the given address url This method connects to the server given as the address. The types of url supported are tp, tps, https and http. Tps and https depend on TLS being enabled.
| address | The URL to connect to. |
References TPProto::Logger::error(), and TPProto::Logger::warning().
| bool TPProto::GameLayer::createAccount | ( | const std::string & | user, | |
| const std::string & | password, | |||
| const std::string & | game, | |||
| const std::string & | email, | |||
| const std::string & | comment | |||
| ) |
Creates an account on the server.
Sends a AccountCreate Frame to the server and waits for a reply.
| user | The username to use. | |
| password | The password for the account. | |
| game | The name of the game to create the account on. | |
| The user's email address. | ||
| comment | A comment to send. |
References TPProto::FrameFactory::createAccountCreate(), TPProto::GameStatusListener::disconnected(), TPProto::Logger::error(), TPProto::ProtocolLayer::getFrameCodec(), TPProto::ProtocolLayer::getFrameFactory(), TPProto::TPSocket::isConnected(), TPProto::FrameCodec::sendFrame(), TPProto::AccountCreate::setComment(), TPProto::AccountCreate::setEmail(), TPProto::AccountCreate::setPass(), TPProto::AccountCreate::setUser(), and TPProto::Features::supportsAccountCreation().
| Message * TPProto::GameLayer::createMessage | ( | ) |
Creates a Message object.
References TPProto::FrameFactory::createMessage(), and TPProto::ProtocolLayer::getFrameFactory().
| Order * TPProto::GameLayer::createOrderFrame | ( | int | type | ) |
| void TPProto::GameLayer::disconnect | ( | ) |
Disconnects from server.
Closes the underlying TPSocket.
References TPProto::TPSocket::disconnect(), TPProto::GameStatusListener::disconnected(), and TPProto::Logger::info().
| void TPProto::GameLayer::finishedTurn | ( | ) |
Tells the server that the player has finished their turn.
Sends a FinishedFrame to the server.
References TPProto::FrameFactory::createFinished(), TPProto::ProtocolLayer::getFrameCodec(), TPProto::ProtocolLayer::getFrameFactory(), TPProto::FrameFactory::getProtocolVersion(), and TPProto::FrameCodec::sendFrame().
| GameInfo * TPProto::GameLayer::getActiveGame | ( | ) | const |
| std::set< GameInfo * > TPProto::GameLayer::getAvailableGames | ( | ) | const |
| BoardCache * TPProto::GameLayer::getBoardCache | ( | ) | const |
Gets the BoardCache.
| CategoryCache * TPProto::GameLayer::getCategoryCache | ( | ) | const |
Gets the CategoryCache.
| ComponentCache * TPProto::GameLayer::getComponentCache | ( | ) | const |
Gets the ComponentCache.
| DesignCache * TPProto::GameLayer::getDesignCache | ( | ) | const |
Gets the DesignCache.
| Message * TPProto::GameLayer::getMessage | ( | uint32_t | boardid, | |
| uint32_t | slot | |||
| ) |
Gets a Message from the server.
Sends the GetMessage Frame and receives the Message frame.
| boardid | The board ID of the board to get the message from. | |
| slot | The slot number of the message to get. |
| std::list< Message * > TPProto::GameLayer::getMessages | ( | uint32_t | boardid, | |
| uint32_t | num | |||
| ) |
Gets Messages from the server.
Sends the GetMessage Frame and receives the Message frames.
| boardid | The board ID of the board to get the messages from. | |
| num | The number of messages to get. |
| ObjectCache * TPProto::GameLayer::getObjectCache | ( | ) | const |
Gets the ObjectCache.
| ObjectDescCache * TPProto::GameLayer::getObjectDescCache | ( | ) | const |
Gets the ObjectDescCache.
| Order * TPProto::GameLayer::getOrder | ( | uint32_t | obid, | |
| uint32_t | slot | |||
| ) |
| OrderDescCache * TPProto::GameLayer::getOrderDescCache | ( | ) | const |
Gets the OrderDescCache.
| std::list< Order * > TPProto::GameLayer::getOrders | ( | uint32_t | obid, | |
| uint32_t | num | |||
| ) |
| PlayerCache * TPProto::GameLayer::getPlayerCache | ( | ) | const |
Gets the PlayerCache.
| PropertyCache * TPProto::GameLayer::getPropertyCache | ( | ) | const |
Gets the PropertyCache.
| ProtocolLayer * TPProto::GameLayer::getProtocolLayer | ( | ) | const |
Gets the ProtocolLayer being used. This could be used to do low level calls to the protocol itself, or more importantly, set the FrameFactory, FrameBuilder and/or FrameCodec classes in the ProtocolLayer.
| ResourceCache * TPProto::GameLayer::getResourceCache | ( | ) | const |
Gets the ResourceCache.
| GameStatus TPProto::GameLayer::getStatus | ( | ) |
Gets the state of the game.
References TPProto::GameStatusListener::disconnected(), and TPProto::TPSocket::isConnected().
| void TPProto::GameLayer::getTimeRemaining | ( | ) |
Gets the time remaining before the end of turn.
Fetches the time remaining till the end of turn from the server. The actual value is returned through the GameStatusListener::timeToEoT().
References TPProto::FrameFactory::createGetTimeRemaining(), TPProto::ProtocolLayer::getFrameCodec(), TPProto::ProtocolLayer::getFrameFactory(), and TPProto::FrameCodec::sendFrame().
| bool TPProto::GameLayer::insertOrder | ( | Order * | frame | ) |
Inserts an Order into the objects order queue.
| frame | The Order to insert. |
Referenced by replaceOrder().
| bool TPProto::GameLayer::login | ( | const std::string & | username, | |
| const std::string & | password, | |||
| const std::string & | game | |||
| ) |
Logs in to the server.
Sends a Login Frame to the server and waits for a reply.
| username | The username to connect as. | |
| password | The password of the account of the username. | |
| game | The name of the game to log into. |
References TPProto::FrameFactory::createLogin(), TPProto::GameStatusListener::disconnected(), TPProto::ProtocolLayer::getFrameCodec(), TPProto::ProtocolLayer::getFrameFactory(), TPProto::TPSocket::isConnected(), TPProto::FrameCodec::sendFrame(), TPProto::Login::setPass(), and TPProto::Login::setUser().
| bool TPProto::GameLayer::postMessage | ( | Message * | frame | ) |
| bool TPProto::GameLayer::removeMessage | ( | uint32_t | boardid, | |
| uint32_t | slot | |||
| ) |
Removes messages from the server.
Sends the RemoveMessage frame and receives the replies.
| boardid | The board id of the board to remove the message from. | |
| slot | The slot to remove the message from. |
| bool TPProto::GameLayer::removeOrder | ( | uint32_t | obid, | |
| uint32_t | slot | |||
| ) |
Removes an Order from the server.
Sends the RemoveOrder frame to the server and receives reply.
| obid | The Object to remove the order from. | |
| slot | The slot that should have it's order removed. |
Referenced by replaceOrder().
| bool TPProto::GameLayer::replaceOrder | ( | Order * | frame | ) |
Replaces a current Order with a new one.
First inserts the new Order, then removes the old one. Can fail with or without the new order in the order queue.
| frame | The Order that will replace the current one. |
References TPProto::Order::getObjectId(), TPProto::Order::getSlot(), insertOrder(), and removeOrder().
| void TPProto::GameLayer::setCacheMethod | ( | CacheMethod * | prototype | ) |
Sets the CacheMethod for the caches to use. Changes the default CacheMethod used, defaults to CacheNoneMethod.
| prototype | A CacheMethod that will be cloned for each Cache to use. |
References TPProto::CacheMethod::clone(), and TPProto::Cache::setCacheMethod().
| void TPProto::GameLayer::setClientString | ( | const std::string & | name | ) |
Sets the client string.
The client string can be set to anything. The perferred format is "name/version". The library name and version is added the the client string later.
| name | The client name string. |
| void TPProto::GameLayer::setEventLoop | ( | EventLoop * | el | ) |
Sets the EventLoop abstraction to use. Sets which implementation of EventLoop to use.
Must be set before connecting to a server.
| el | The implementation of the EventLoop to use. |
References TPProto::ProtocolLayer::getFrameCodec(), and TPProto::Connection::setEventLoop().
| void TPProto::GameLayer::setGameStatusListener | ( | GameStatusListener * | gsl | ) |
Sets the GameStatusListener to use.
| gsl | The new GameStatusListener to use. |
| void TPProto::GameLayer::setLogger | ( | Logger * | nlog | ) |
Sets the Logger to use.
| nlog | The new Logger to use. |
References TPProto::ProtocolLayer::getFrameCodec(), and TPProto::FrameCodec::setLogger().
1.6.1