NetMauMau  0.24.0
Client API
Public Types | Public Member Functions | Protected Member Functions | List of all members
NetMauMau::Client::AbstractClientV07 Class Reference

#include <abstractclient.h>

Detailed Description

Client interface to communicate with the server

Since
0.7
Inheritance diagram for NetMauMau::Client::AbstractClientV07:
[legend]

Public Types

typedef Connection::CAPABILITIES CAPABILITIES
 Key/value map of the server capabilities.
typedef std::vector
< Common::ICard * > 
CARDS
 A vector of Common::ICard pointers.
typedef Connection::PLAYERINFOS PLAYERINFOS
 List of currently registered player infos.
typedef Connection::PLAYERLIST PLAYERLIST
 List of currently registered player names.
typedef std::vector< STATSTATS
 A vector with statistics about the other player's card count.

Server query methods

CAPABILITIES capabilities (timeval *timeout=NULL) throw (NetMauMau::Common::Exception::SocketException)
 Returns the server capabilities.
PLAYERINFOS playerList (bool playerPNG, timeval *timeout=NULL) throw (NetMauMau::Common::Exception::SocketException)
 Returns the list of currently registered player names.
PLAYERLIST playerList (timeval *timeout=NULL) throw (NetMauMau::Common::Exception::SocketException)
 Returns the list of currently registered player names.
std::string getPlayerName () const
 Gets the player's name.
static uint32_t getClientProtocolVersion ()
 Returns the version of the client's implemented protocol.
static uint32_t getClientLibraryVersion ()
 Returns the version of the client library.
static uint32_t parseProtocolVersion (const std::string &version)
 Parses a version string and returns the resulting protocol version.
static bool isPlayerImageUploadable (const unsigned char *pngData, std::size_t pngDataLen)
 Checks if an player image is uploadable to the server.
static uint16_t getDefaultPort ()
 Gets the default port of the server.
static const char * getDefaultAIName ()
 Gets the compiled in default AI player name.

Public Member Functions

void disconnect ()
 Disconnects the client from the server.
void play (timeval *timeout=NULL) throw (NetMauMau::Common::Exception::SocketException)
 Attempt to start a game on the servers.

Protected Member Functions

 AbstractClientV07 (const std::string &player, const std::string &server, uint16_t port)
 Creates an AbstractClientV07 instance.
 AbstractClientV07 (const std::string &player, const unsigned char *pngData, std::size_t pngDataLen, const std::string &server, uint16_t port)
 Creates an AbstractClientV07 instance.
virtual void unknownServerMessage (const std::string &msg) const =0
 The server sent a message not understood by the client.
Server requests

This requests require a client of at least version 0.7

virtual bool getAceRoundChoice () const =0
 Gets the choice if an ace round should be started.
Server events

This events require a client of at least version 0.7

virtual void aceRoundStarted (const std::string &player) const =0
 An ace round was started by a player.
virtual void aceRoundEnded (const std::string &player) const =0
 An ace round was ended by a player.
Server requests
virtual Common::ICardplayCard (const CARDS &cards) const =0
 The server requests a card to play.
virtual Common::ICard::SUIT getJackSuitChoice () const =0
 Gets the current Jack suit.
Server events
virtual void message (const std::string &msg) const =0
 The server send a general message.
virtual void error (const std::string &msg) const =0
 The server send a error message.
virtual void turn (std::size_t turn) const =0
 A new turn has started.
virtual void stats (const STATS &stats) const =0
 The server sent statistics about the other player's card count.
virtual void gameOver () const =0
 The server announced the game is over.
virtual void playerJoined (const std::string &player, const unsigned char *pngData, std::size_t len) const =0
 A new player joined the game.
virtual void playerRejected (const std::string &player) const =0
 A player got rejected to join the game.
virtual void playerSuspends (const std::string &player) const =0
 A player suspends this turn.
virtual void playedCard (const std::string &player, const Common::ICard *card) const =0
 A player played a card.
virtual void playerWins (const std::string &player, std::size_t turn) const =0
 A player has won the game.
virtual void playerLost (const std::string &player, std::size_t turn, std::size_t points) const =0
 A player has lost the game.
virtual void playerPicksCard (const std::string &player, const Common::ICard *card) const =0
 A player picks up a card.
virtual void playerPicksCard (const std::string &player, std::size_t count) const =0
 A player picks up an amount of cards.
virtual void nextPlayer (const std::string &player) const =0
 Name of the next player.
virtual void enableSuspend (bool enable) const =0
 Notes if suspending and taking a card possible.
virtual void cardSet (const CARDS &cards) const =0
 The card set distributed to the player, or if the player picked up cards off the talon.
virtual void initialCard (const Common::ICard *card) const =0
 The initial card.
virtual void openCard (const Common::ICard *card, const std::string &jackSuit) const =0
 The current open card.
virtual void talonShuffled () const =0
 The talon was empty and shuffled anew.
virtual void cardRejected (const std::string &player, const Common::ICard *card) const =0
 The player's played card got rejected.
virtual void cardAccepted (const Common::ICard *card) const =0
 The player's played card got accepted.
virtual void jackSuit (Common::ICard::SUIT suit) const =0
 The server announces a Jack suit.
Player image notifications

The notifications can be overloaded if the client is interested in events regarding the player pictures.

This functions all do nothing at default.

virtual void beginReceivePlayerPicture (const std::string &player) const throw ()
 A download of a player image has started.
virtual void endReceivePlayerPicture (const std::string &player) const throw ()
 A download of a player image has ended.
virtual void uploadSucceded (const std::string &player) const throw ()
 The upload of the player image has succeeded.
virtual void uploadFailed (const std::string &player) const throw ()
 The upload of the player image has failed.

Member Typedef Documentation

Key/value map of the server capabilities.

Key Value
ACEROUND false if no ace rounds are enabled, else A, Q or K for the rank
AI_NAME name of the first AI player
AI_OPPONENT true if the AI opponent is enabled
CUR_PLAYERS amount of current players joined
DIRCHANGE true if direction changes are allowed, false otherwise
HAVE_SCORES true if the server can provide scores, false otherwise
INITIAL_CARDS if played with an amount of initial cards not equal to 5 contains the number of cards
MAX_PLAYERS amount of players needed to start the game
MIN_VERSION minimum version of client that can connect
SERVER_VERSION version of the server
SERVER_VERSION_REL version of the server (including release)
TALON if played with more than 1 card deck contains the number of cards
ULTIMATE true if running in ultimate mode, false otherwise
WEBSERVER_URL if the webserver is started it contains the URL of it

List of currently registered player infos.

List of currently registered player names.

typedef std::vector<STAT> NetMauMau::Client::AbstractClientV05::STATS
inherited

A vector with statistics about the other player's card count.

See Also
STAT

Constructor & Destructor Documentation

AbstractClientV07::AbstractClientV07 ( const std::string &  player,
const std::string &  server,
uint16_t  port 
)
explicitprotected

Creates an AbstractClientV07 instance.

Sets up all information to connect to a server

See Also
play
Parameters
playerthe player's name
serverthe server to connect to
portthe server port to connect to

AbstractClientV07::AbstractClientV07 ( const std::string &  player,
const unsigned char *  pngData,
std::size_t  pngDataLen,
const std::string &  server,
uint16_t  port 
)
explicitprotected

Creates an AbstractClientV07 instance.

Sets up all information to connect to a server

See Also
play
Parameters
playerthe player's name
serverthe server to connect to
portthe server port to connect to
(const std::string &, const unsigned char *, std::size_t, const std::string &, uint16_t)

Member Function Documentation

virtual void NetMauMau::Client::AbstractClientV07::aceRoundEnded ( const std::string &  player) const
protectedpure virtual

An ace round was ended by a player.

See Also
CAPABILITIES for getting the ace round rank
Parameters
playerthe player ending the ace round
Since
0.7
virtual void NetMauMau::Client::AbstractClientV07::aceRoundStarted ( const std::string &  player) const
protectedpure virtual

An ace round was started by a player.

See Also
CAPABILITIES for getting the ace round rank
Parameters
playerthe player starting the ace round
Since
0.7
void AbstractClientV05::beginReceivePlayerPicture ( const std::string &  player) const throw ()
protectedvirtualinherited

A download of a player image has started.

Parameters
playerthe player the image is downloaded for
Since
0.4
virtual void NetMauMau::Client::AbstractClientV05::cardAccepted ( const Common::ICard card) const
protectedpure virtualinherited

The player's played card got accepted.

Parameters
cardthe accepted card
virtual void NetMauMau::Client::AbstractClientV05::cardRejected ( const std::string &  player,
const Common::ICard card 
) const
protectedpure virtualinherited

The player's played card got rejected.

Parameters
playerthe player's name
cardthe rejected card
virtual void NetMauMau::Client::AbstractClientV05::cardSet ( const CARDS cards) const
protectedpure virtualinherited

The card set distributed to the player, or if the player picked up cards off the talon.

Parameters
cardsthe card set given to the player
virtual void NetMauMau::Client::AbstractClientV05::enableSuspend ( bool  enable) const
protectedpure virtualinherited

Notes if suspending and taking a card possible.

If there are no more cards on the talon, except the open card, suspending and taking card a is not possible

Parameters
enabletrue if it is possible to take a card, false otherwise
void AbstractClientV05::endReceivePlayerPicture ( const std::string &  player) const throw ()
protectedvirtualinherited

A download of a player image has ended.

Parameters
playerthe player the image is downloaded for
Since
0.4
virtual void NetMauMau::Client::AbstractClientV05::error ( const std::string &  msg) const
protectedpure virtualinherited

The server send a error message.

Parameters
msgthe error message
virtual bool NetMauMau::Client::AbstractClientV07::getAceRoundChoice ( ) const
protectedpure virtual

Gets the choice if an ace round should be started.

Returns
true to start an ace round, false otherwise
Since
0.7
virtual Common::ICard::SUIT NetMauMau::Client::AbstractClientV05::getJackSuitChoice ( ) const
protectedpure virtualinherited

Gets the current Jack suit.

Returns
the current Jack suit
virtual void NetMauMau::Client::AbstractClientV05::initialCard ( const Common::ICard card) const
protectedpure virtualinherited

The initial card.

Parameters
cardthe initial card
virtual void NetMauMau::Client::AbstractClientV05::jackSuit ( Common::ICard::SUIT  suit) const
protectedpure virtualinherited

The server announces a Jack suit.

Parameters
suitthe current Jack suit
virtual void NetMauMau::Client::AbstractClientV05::message ( const std::string &  msg) const
protectedpure virtualinherited

The server send a general message.

Parameters
msgthe general message
virtual void NetMauMau::Client::AbstractClientV05::nextPlayer ( const std::string &  player) const
protectedpure virtualinherited

Name of the next player.

Parameters
playerthe next player's name
virtual void NetMauMau::Client::AbstractClientV05::openCard ( const Common::ICard card,
const std::string &  jackSuit 
) const
protectedpure virtualinherited

The current open card.

If there is a suit chosen by a Jack the jackSuit contains it and can get converted to NetMauMau::Common::ICard::SUIT by NetMauMau::Common::symbolToSuit, else it will be a empty string.

See Also
NetMauMau::Common::symbolToSuit
Parameters
cardthe current open card
jackSuitthe current jack suit
void AbstractClientV05::play ( timeval *  timeout = NULL) throw (NetMauMau::Common::Exception::SocketException)
inherited

Attempt to start a game on the servers.

Parameters
timeoutthe time to wait for a connection, if NULL there will be no timeout
Exceptions
Common::Exception::SocketExceptionif the connection failed
Client::Exception::TimeoutExceptionif the connection attempt timed out
Client::Exception::ProtocolErrorExceptionif there was a aprotocol error
Client::Exception::ConnectionRejectedExceptionif the connection got rejected
Client::Exception::NoNetMauMauServerExceptionif the remote host is no NetMauMau server
Client::Exception::ShutdownExceptionif the server is shutting down
Client::Exception::VersionMismatchExceptionif the client is not supported
virtual Common::ICard* NetMauMau::Client::AbstractClientV05::playCard ( const CARDS cards) const
protectedpure virtualinherited

The server requests a card to play.

Note
If the client send an illegal card the client will be requsted to choose a card again. Before the client will receive the amount of extra cards to take by played out SEVEN rank cards.
See Also
Common::getIllegalCard
Parameters
cardsplayable cards, which will get accepted by the server
Returns
the card the player wants to play or NULL if the player cannot play a card and/or suspends the turn or the illegal card

Implemented in NetMauMau::Client::AbstractClientV08.

virtual void NetMauMau::Client::AbstractClientV05::playedCard ( const std::string &  player,
const Common::ICard card 
) const
protectedpure virtualinherited

A player played a card.

Parameters
playerthe player's name
cardthe card the player played
virtual void NetMauMau::Client::AbstractClientV05::playerJoined ( const std::string &  player,
const unsigned char *  pngData,
std::size_t  len 
) const
protectedpure virtualinherited

A new player joined the game.

Transmits a PNG picture of the player if available

Parameters
playerthe new player's name
pngDataPNG data of the players picture or 0L
pngDataLenlength of the PNG data
virtual void NetMauMau::Client::AbstractClientV05::playerLost ( const std::string &  player,
std::size_t  turn,
std::size_t  points 
) const
protectedpure virtualinherited

A player has lost the game.

Parameters
playerthe player's name
turnthe number of the turn the player has lost
pointsthe points the losing player had in hand
virtual void NetMauMau::Client::AbstractClientV05::playerPicksCard ( const std::string &  player,
const Common::ICard card 
) const
protectedpure virtualinherited

A player picks up a card.

Note
The card is NULL if the player is a remote player
Parameters
playerthe player's name
cardthe card the player picked up
virtual void NetMauMau::Client::AbstractClientV05::playerPicksCard ( const std::string &  player,
std::size_t  count 
) const
protectedpure virtualinherited

A player picks up an amount of cards.

Parameters
playerthe player's name
countthe count of picked up cards
virtual void NetMauMau::Client::AbstractClientV05::playerRejected ( const std::string &  player) const
protectedpure virtualinherited

A player got rejected to join the game.

Parameters
playerthe rejected player's name
virtual void NetMauMau::Client::AbstractClientV05::playerSuspends ( const std::string &  player) const
protectedpure virtualinherited

A player suspends this turn.

Parameters
playerthe suspending player's name
virtual void NetMauMau::Client::AbstractClientV05::playerWins ( const std::string &  player,
std::size_t  turn 
) const
protectedpure virtualinherited

A player has won the game.

Parameters
playerthe player's name
turnthe number of the turn the player has won
virtual void NetMauMau::Client::AbstractClientV05::stats ( const STATS stats) const
protectedpure virtualinherited

The server sent statistics about the other player's card count.

Parameters
statsthe statistics about the other player's card count
virtual void NetMauMau::Client::AbstractClientV05::talonShuffled ( ) const
protectedpure virtualinherited

The talon was empty and shuffled anew.

All played cards, except the open top card are shuffled and added to the Talon.

This event can be used for displaying an shuffle animation.

virtual void NetMauMau::Client::AbstractClientV05::turn ( std::size_t  turn) const
protectedpure virtualinherited

A new turn has started.

Parameters
turnnumber of the current turn
virtual void NetMauMau::Client::AbstractClientV05::unknownServerMessage ( const std::string &  msg) const
protectedpure virtualinherited

The server sent a message not understood by the client.

Parameters
messagethe unknown message
void AbstractClientV05::uploadFailed ( const std::string &  player) const throw ()
protectedvirtualinherited

The upload of the player image has failed.

Parameters
playerthe player the image is uploaded for
Since
0.4
void AbstractClientV05::uploadSucceded ( const std::string &  player) const throw ()
protectedvirtualinherited

The upload of the player image has succeeded.

Parameters
playerthe player the image is uploaded for
Since
0.4