NetMauMau  0.17.1
Client API
Public Types | Public Member Functions | Protected Member Functions | List of all members
NetMauMau::Client::AbstractClientV11 Class Referenceabstract

#include <abstractclient.h>

Detailed Description

Client interface to communicate with the server

Since
0.11
Inheritance diagram for NetMauMau::Client::AbstractClientV11:
[legend]

Public Types

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

Server query methods

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

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. More...
 
Server query methods
SCORES getScores (SCORE_TYPE::_scoreType type=SCORE_TYPE::ABS, std::size_t limit=10, timeval *timeout=0L) throw (NetMauMau::Common::Exception::SocketException)
 Gets the scores from the server. More...
 
SCORES getScores (timeval *timeout) throw (NetMauMau::Common::Exception::SocketException)
 

Static Public Member Functions

Server query methods
static bool isPlayerImageUploadable (const unsigned char *pngData, std::size_t pngDataLen, const IBase64 *base64)
 Checks if an player image is uploadable to the server. More...
 

Protected Member Functions

 AbstractClientV11 (const std::string &player, const std::string &server, uint16_t port, uint32_t clientVersion)
 Creates an AbstractClientV11 instance. More...
 
 AbstractClientV11 (const std::string &player, const std::string &server, uint16_t port, uint32_t clientVersion, const IBase64 *base64)
 Creates an AbstractClientV11 instance. More...
 
 AbstractClientV11 (const std::string &player, const unsigned char *pngData, std::size_t pngDataLen, const std::string &server, uint16_t port, uint32_t clientVersion, const IBase64 *base64)
 Creates an AbstractClientV11 instance. More...
 
 AbstractClientV11 (const std::string &player, const unsigned char *pngData, std::size_t pngDataLen, const std::string &server, uint16_t port, uint32_t clientVersion)
 Creates an AbstractClientV11 instance. More...
 
virtual Common::ICardplayCard (const CARDS &cards) const
 The server requests a card to play. More...
 
virtual void unknownServerMessage (const std::string &msg) const =0
 The server sent a message not understood by the client. More...
 
Server requests
virtual Common::ICardplayCard (const CARDS &cards, std::size_t takeCount) const =0
 The server requests a card to play. More...
 
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. More...
 
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. More...
 
virtual void aceRoundEnded (const std::string &player) const =0
 An ace round was ended by a player. More...
 
Server requests
virtual Common::ICard::SUIT getJackSuitChoice () const =0
 Gets the current Jack suit. More...
 
Server events
virtual void message (const std::string &msg) const =0
 The server send a general message. More...
 
virtual void error (const std::string &msg) const =0
 The server send a error message. More...
 
virtual void turn (std::size_t turn) const =0
 A new turn has started. More...
 
virtual void stats (const STATS &stats) const =0
 The server sent statistics about the other player's card count. More...
 
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. More...
 
virtual void playerRejected (const std::string &player) const =0
 A player got rejected to join the game. More...
 
virtual void playerSuspends (const std::string &player) const =0
 A player suspends this turn. More...
 
virtual void playedCard (const std::string &player, const Common::ICard *card) const =0
 A player played a card. More...
 
virtual void playerWins (const std::string &player, std::size_t turn) const =0
 A player has won the game. More...
 
virtual void playerLost (const std::string &player, std::size_t turn, std::size_t points) const =0
 A player has lost the game. More...
 
virtual void playerPicksCard (const std::string &player, const Common::ICard *card) const =0
 A player picks up a card. More...
 
virtual void playerPicksCard (const std::string &player, std::size_t count) const =0
 A player picks up an amount of cards. More...
 
virtual void nextPlayer (const std::string &player) const =0
 Name of the next player. More...
 
virtual void enableSuspend (bool enable) const =0
 Notes if suspending and taking a card possible. More...
 
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. More...
 
virtual void initialCard (const Common::ICard *card) const =0
 The initial card. More...
 
virtual void openCard (const Common::ICard *card, const std::string &jackSuit) const =0
 The current open card. More...
 
virtual void talonShuffled () const =0
 The talon was empty and shuffled anew. More...
 
virtual void cardRejected (const std::string &player, const Common::ICard *card) const =0
 The player's played card got rejected. More...
 
virtual void cardAccepted (const Common::ICard *card) const =0
 The player's played card got accepted. More...
 
virtual void jackSuit (Common::ICard::SUIT suit) const =0
 The server announces a Jack suit. More...
 
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. More...
 
virtual void endReceivePlayerPicture (const std::string &player) const throw ()
 A download of a player image has ended. More...
 
virtual void uploadSucceded (const std::string &player) const throw ()
 The upload of the player image has succeded. More...
 
virtual void uploadFailed (const std::string &player) const throw ()
 The upload of the player image has failed. More...
 

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

List of currently registered player infos.

List of currently registered player names.

the score

The type of scores.

a vector of scores

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

AbstractClientV11::AbstractClientV11 ( const std::string &  player,
const std::string &  server,
uint16_t  port,
uint32_t  clientVersion 
)
explicitprotected

Creates an AbstractClientV11 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
clientVersionthe protocol version the client understands
Since
0.8
AbstractClientV11::AbstractClientV11 ( const std::string &  player,
const std::string &  server,
uint16_t  port,
uint32_t  clientVersion,
const IBase64 base64 
)
explicitprotected

Creates an AbstractClientV11 instance.

Sets up all information to connect to a server. Additionally a player picture can be submitted

See also
play
Parameters
playerthe player's name
pngDatapointer to a buffer containg PNG image data or NULL
pngDataLenlength of the data in the buffer pointed to by pngData
serverthe server to connect to
portthe server port to connect to
Since
0.4
Parameters
clientVersionthe protocol version the client understands
Since
0.9
Parameters
base64interface to a custom implementation of IBase64
Since
0.11
AbstractClientV11::AbstractClientV11 ( const std::string &  player,
const unsigned char *  pngData,
std::size_t  pngDataLen,
const std::string &  server,
uint16_t  port,
uint32_t  clientVersion,
const IBase64 base64 
)
explicitprotected

Creates an AbstractClientV11 instance.

Sets up all information to connect to a server. Additionally a player picture can be submitted

See also
play
Parameters
playerthe player's name
pngDatapointer to a buffer containg PNG image data or NULL
pngDataLenlength of the data in the buffer pointed to by pngData
serverthe server to connect to
portthe server port to connect to
Since
0.4
Parameters
clientVersionthe protocol version the client understands
Since
0.9
Parameters
base64interface to a custom implementation of IBase64
Since
0.11
AbstractClientV11::AbstractClientV11 ( const std::string &  player,
const unsigned char *  pngData,
std::size_t  pngDataLen,
const std::string &  server,
uint16_t  port,
uint32_t  clientVersion 
)
protected

Creates an AbstractClientV11 instance.

Sets up all information to connect to a server. Additionally a player picture can be submitted

See also
play
Parameters
playerthe player's name
pngDatapointer to a buffer containg PNG image data or NULL
pngDataLenlength of the data in the buffer pointed to by pngData
serverthe server to connect to
portthe server port to connect to
Since
0.4
Parameters
clientVersionthe protocol version the client understands
Since
0.9

Member Function Documentation

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

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 virtualinherited

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 virtualinherited

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
AbstractClientV09::SCORES AbstractClientV09::getScores ( SCORE_TYPE::_scoreType  type = SCORE_TYPE::ABS,
std::size_t  limit = 10,
timeval *  timeout = 0L 
)
throw (NetMauMau::Common::Exception::SocketException
)
inherited

Gets the scores from the server.

Example usage code:

// ...
MyClient *m_client = new MyClient(); // subclass of AbstractClient
// for the top 5 normal scores (including scores below 0)
const MyClient::SCORES &scores(m_client->getScores(MyClient::SCORE_TYPE::NORM, 5));
for(MyClient::SCORES::const_iterator i(scores.begin()); i != scores.end(); ++i) {
// do something with i->name and i->score
}
// ...
Note
if no scores are available (currently Windows servers) or the server never served a game, the scores vector is empty
Exceptions
Exception::ScoresExceptionif the scores couldn't get received or called within a running game
Parameters
typetype of scores
limitlimit the result, 0 disables the limit
timeoutthrow a Exception::TimeoutException on exceeding timeout
Returns
the scores
Since
0.9
AbstractClientV09::SCORES AbstractClientV09::getScores ( timeval *  timeout)
throw (NetMauMau::Common::Exception::SocketException
)
inherited

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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
NetMauMau::Common::ICard * AbstractClientV08::playCard ( const CARDS cards) const
protectedvirtualinherited

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

Implements NetMauMau::Client::AbstractClientV05.

virtual Common::ICard* NetMauMau::Client::AbstractClientV08::playCard ( const CARDS cards,
std::size_t  takeCount 
) const
protectedpure virtualinherited

The server requests a card to play.

If takeCount is > 0 the client can use Common::getIllegalCard to retrive the cards first

Parameters
takeCountthe amount of cards the player has to take
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 loosing 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 succeded.

Parameters
playerthe player the image is uploaded for
Since
0.4