Skip to content

Commit

Permalink
player picture receive listener
Browse files Browse the repository at this point in the history
  • Loading branch information
velnias75 committed Dec 4, 2014
1 parent 83e5afc commit 2a8085c
Show file tree
Hide file tree
Showing 10 changed files with 1,471 additions and 196 deletions.
1 change: 1 addition & 0 deletions doc/client.dox.in
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ EXCLUDE = "@abs_top_srcdir@/src/client/interceptederrorexception.
"@abs_top_srcdir@/src/test" \
"@abs_top_srcdir@/src/include/abstractsocket.h" \
"@abs_top_srcdir@/src/include/linkercontrol.h" \
"@abs_top_srcdir@/src/include/iplayerpiclistener.h" \
"@abs_top_srcdir@/src/common/icardfactory.h" \
"@abs_top_srcdir@/src/common/iplayer.h" \
"@abs_top_srcdir@/src/common/stdplayer.h" \
Expand Down
21 changes: 15 additions & 6 deletions src/client/abstractclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ struct cardEqualsDescription : public std::binary_function < NetMauMau::Common::
using namespace NetMauMau::Client;

AbstractClient::AbstractClient(const std::string &pName, const unsigned char *data, std::size_t len,
const std::string &server, uint16_t port) : m_connection(pName,
server, port), m_pName(pName), m_pngData(data),
m_pngDataLen(len), m_cards(), m_openCard(0L), m_disconnectNow(false) {}
const std::string &server, uint16_t port) : IPlayerPicListener(),
m_connection(pName, server, port), m_pName(pName), m_pngData(data), m_pngDataLen(len),
m_cards(), m_openCard(0L), m_disconnectNow(false) {}

AbstractClient::AbstractClient(const std::string &pName, const std::string &server, uint16_t port)
: m_connection(pName, server, port), m_pName(pName), m_pngData(0L), m_pngDataLen(0), m_cards(),
m_openCard(0L), m_disconnectNow(false) {}
: IPlayerPicListener(), m_connection(pName, server, port), m_pName(pName), m_pngData(0L),
m_pngDataLen(0), m_cards(), m_openCard(0L), m_disconnectNow(false) {}

AbstractClient::~AbstractClient() {

Expand Down Expand Up @@ -121,7 +121,7 @@ throw(NetMauMau::Common::Exception::SocketException) {
Connection::PLAYERINFOS AbstractClient::playerList(bool playerPNG, timeval *timeout)
throw(NetMauMau::Common::Exception::SocketException) {
m_connection.setTimeout(timeout);
return m_connection.playerList(playerPNG);
return m_connection.playerList(this, playerPNG);
}

void AbstractClient::play(timeval *timeout) throw(NetMauMau::Common::Exception::SocketException) {
Expand Down Expand Up @@ -184,11 +184,16 @@ void AbstractClient::play(timeval *timeout) throw(NetMauMau::Common::Exception::
std::string plPic;

m_connection >> msg;

beginReceivePlayerPicture(msg);

m_connection >> plPic;

const std::vector<NetMauMau::Common::BYTE>
&plPicPng(NetMauMau::Common::base64_decode(plPic));

endReceivePlayerPicture(msg);

playerJoined(msg, plPic == "-" ? 0L : plPicPng.data(),
plPic == "-" ? 0 : plPicPng.size());

Expand Down Expand Up @@ -406,4 +411,8 @@ uint16_t AbstractClient::getDefaultPort() {
return SERVER_PORT;
}

void AbstractClient::beginReceivePlayerPicture(const std::string &) const throw() {}

void AbstractClient::endReceivePlayerPicture(const std::string &) const throw() {}

// kate: indent-mode cstyle; indent-width 4; replace-tabs off; tab-width 4;
17 changes: 14 additions & 3 deletions src/client/clientconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ throw(NetMauMau::Common::Exception::SocketException) {
}
#pragma GCC diagnostic pop

Connection::PLAYERINFOS Connection::playerList(bool playerPNG)
Connection::PLAYERINFOS Connection::playerList(const IPlayerPicListener *hdl, bool playerPNG)
throw(NetMauMau::Common::Exception::SocketException) {

PLAYERINFOS plv;
Expand All @@ -121,12 +121,17 @@ throw(NetMauMau::Common::Exception::SocketException) {

*this >> pl;

if(playerPNG) *this >> pic;
if(playerPNG) {
hdl->beginReceivePlayerPicture(pl);
*this >> pic;
}

while(pl != "PLAYERLISTEND") {

const std::vector<NetMauMau::Common::BYTE> &pp(NetMauMau::Common::base64_decode(pic));

if(playerPNG) hdl->endReceivePlayerPicture(pl);

NetMauMau::Common::BYTE *ppd = 0L;

if(!pic.empty() && pic != "-") {
Expand All @@ -140,7 +145,13 @@ throw(NetMauMau::Common::Exception::SocketException) {

*this >> pl;

if(playerPNG) *this >> pic;
const bool ple = (pl == "PLAYERLISTEND");

if(playerPNG) {
if(!ple) hdl->beginReceivePlayerPicture(pl);

*this >> pic;
}
}

} else {
Expand Down
3 changes: 2 additions & 1 deletion src/include/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pkginclude_HEADERS = abstractclient.h clientconnection.h timeoutexception.h icard.h \
linkercontrol.h abstractconnection.h abstractsocket.h socketexception.h cardtools.h \
shutdownexception.h playerlistexception.h capabilitiesexception.h protocolerrorexception.h \
connectionrejectedexception.h versionmismatchexception.h nonetmaumauserverexception.h
connectionrejectedexception.h versionmismatchexception.h nonetmaumauserverexception.h \
iplayerpiclistener.h
8 changes: 6 additions & 2 deletions src/include/abstractclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@

#include <vector>

#include "icard.h"
#include "iplayerpiclistener.h"
#include "clientconnection.h"
#include "icard.h"

namespace NetMauMau {

Expand Down Expand Up @@ -135,7 +136,7 @@ namespace Client {
*
* @note All data is transferred as UTF-8 encoded byte strings
*/
class _EXPORT AbstractClient {
class _EXPORT AbstractClient : protected IPlayerPicListener {
DISALLOW_COPY_AND_ASSIGN(AbstractClient)
public:
/// @copydoc Connection::CAPABILITIES
Expand Down Expand Up @@ -390,6 +391,9 @@ class _EXPORT AbstractClient {
virtual void playerJoined(const std::string &player, const unsigned char *pngData,
std::size_t len) const = 0;

virtual void beginReceivePlayerPicture(const std::string &player) const throw() _CONST;
virtual void endReceivePlayerPicture(const std::string &player) const throw() _CONST;

/**
* @brief A player got rejected to join the game
*
Expand Down
5 changes: 4 additions & 1 deletion src/include/clientconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace NetMauMau {

namespace Client {

class IPlayerPicListener;

/**
* @brief Handles the connection from the client to a server
*/
Expand Down Expand Up @@ -65,7 +67,8 @@ class _EXPORT Connection : public Common::AbstractConnection {
virtual void connect(const unsigned char *pngData,
std::size_t pngDataLen) throw(Common::Exception::SocketException);
CAPABILITIES capabilities() throw(NetMauMau::Common::Exception::SocketException);
PLAYERINFOS playerList(bool playerPNG) throw(Common::Exception::SocketException);
PLAYERINFOS playerList(const IPlayerPicListener *hdl,
bool playerPNG) throw(Common::Exception::SocketException);

void setTimeout(struct timeval *timeout);

Expand Down
49 changes: 49 additions & 0 deletions src/include/iplayerpiclistener.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2014 by Heiko Schäfer <heiko@rangun.de>
*
* This file is part of NetMauMau.
*
* NetMauMau is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* NetMauMau is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with NetMauMau. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef NETMAUMAU_IPLAYERPICHANDLER_H
#define NETMAUMAU_IPLAYERPICHANDLER_H

#include <string>

#include "linkercontrol.h"

namespace NetMauMau {

namespace Client {

class IPlayerPicListener {
DISALLOW_COPY_AND_ASSIGN(IPlayerPicListener)
public:
virtual ~IPlayerPicListener() {}

virtual void beginReceivePlayerPicture(const std::string &player) const throw() = 0;
virtual void endReceivePlayerPicture(const std::string &player) const throw() = 0;

protected:
IPlayerPicListener() {}
};

}

}

#endif /* NETMAUMAU_IPLAYERPICHANDLER_H */

// kate: indent-mode cstyle; indent-width 4; replace-tabs off; tab-width 4;
2 changes: 1 addition & 1 deletion src/server/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ endif
DISTCLEANFILES = $(man1_MANS)

noinst_HEADERS = serverconnection.h serverplayer.h servereventhandler.h game.h \
serverplayerexception.h
serverplayerexception.h ai-icon.h

if PIDFILE
nmm_server_CPPFLAGS = -DPIDFILE="\"$(localstatedir)/run/$(PACKAGE).pid\""
Expand Down
Loading

0 comments on commit 2a8085c

Please sign in to comment.