Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions RetroChessPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "gui/RetroChessChatWidgetHolder.h"
#include <retroshare-gui/RsAutoUpdatePage.h>

#include <retroshare/rsgxstunnel.h>
#include <retroshare/rsplugin.h>
#include <retroshare/rsversion.h>

Expand Down Expand Up @@ -90,6 +91,7 @@ RetroChessPlugin::RetroChessPlugin()
void RetroChessPlugin::setInterfaces(RsPlugInInterfaces &interfaces)
{
mPeers = interfaces.mPeers;
mGxsTunnels = interfaces.mGxsTunnels;
}

/*ConfigPage *RetroChessPlugin::qt_config_page() const
Expand Down Expand Up @@ -128,6 +130,7 @@ ChatWidgetHolder *RetroChessPlugin::qt_get_chat_widget_holder(ChatWidget *chatWi
case ChatWidget::CHATTYPE_UNKNOWN:
case ChatWidget::CHATTYPE_LOBBY:
case ChatWidget::CHATTYPE_DISTANT:
return new RetroChessChatWidgetHolder(chatWidget, mRetroChessNotify);
break;
}

Expand All @@ -136,15 +139,23 @@ ChatWidgetHolder *RetroChessPlugin::qt_get_chat_widget_holder(ChatWidget *chatWi

p3Service *RetroChessPlugin::p3_service() const
{
if(mRetroChess == NULL)
rsRetroChess = mRetroChess = new p3RetroChess(mPlugInHandler,mRetroChessNotify) ; // , 3600 * 24 * 30 * 6); // 6 Months

return mRetroChess ;
if(mRetroChess == NULL)
{
// Create the service
rsRetroChess = mRetroChess = new p3RetroChess(mPlugInHandler, mRetroChessNotify);

// Register it for GXS Tunnels immediately if the interface is available
if (mGxsTunnels) {
mGxsTunnels->registerClientService(RETRO_CHESS_GXS_TUNNEL_SERVICE_ID, mRetroChess);
}
}
return mRetroChess;
}

void RetroChessPlugin::setPlugInHandler(RsPluginHandler *pgHandler)
{
mPlugInHandler = pgHandler;
mPlugInHandler = pgHandler;
// No need to register here if done in p3_service
}

QIcon *RetroChessPlugin::qt_icon() const
Expand Down
3 changes: 3 additions & 0 deletions RetroChessPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

/*libretroshare"*/
#include <retroshare/rsplugin.h>
#include <retroshare/rsgxstunnel.h>

#include "gui/NEMainpage.h"

Expand Down Expand Up @@ -76,6 +77,8 @@ class RetroChessPlugin: public RsPlugin
mutable QIcon *mIcon;
mutable MainPage* mainpage ;

RsGxsTunnelService *mGxsTunnels;
RsGxsTunnelService::RsGxsTunnelClientService *mGxsTunnelClient;
RetroChessNotify *mRetroChessNotify ;
RetroChessGUIHandler *mRetroChessGUIHandler ;
};
Expand Down
40 changes: 24 additions & 16 deletions gui/RetroChessChatWidgetHolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "RetroChessChatWidgetHolder.h"

#include <retroshare/rsidentity.h>
#include <retroshare/rsstatus.h>
#include <retroshare/rspeers.h>

Expand All @@ -41,7 +42,6 @@ RetroChessChatWidgetHolder::RetroChessChatWidgetHolder(ChatWidget *chatWidget, R
QIcon icon ;
icon.addPixmap(QPixmap(IMAGE_RetroChess)) ;


playChessButton = new QToolButton ;
playChessButton->setIcon(icon) ;
playChessButton->setToolTip(tr("Invite Friend to Chess"));
Expand Down Expand Up @@ -111,29 +111,37 @@ void RetroChessChatWidgetHolder::chessnotify(RsPeerId from_peer_id)

void RetroChessChatWidgetHolder::chessPressed()
{
RsPeerId peer_id = mChatWidget->getChatId().toPeerId();//TODO support GXSID
if (rsRetroChess->hasInviteFrom(peer_id))
{
ChatId chatId = mChatWidget->getChatId();
if (chatId.isDistantChatId()) {
rsRetroChess->sendGxsInvite(RsGxsId(chatId.toDistantChatId().toStdString()));
} else {
RsPeerId peer_id = chatId.toPeerId();

if (rsRetroChess->hasInviteFrom(peer_id)){
rsRetroChess->acceptedInvite(peer_id);
mRetroChessNotify->notifyChessStart(peer_id);
return;
}

rsRetroChess->acceptedInvite(peer_id);
mRetroChessNotify->notifyChessStart(peer_id);
return;
rsRetroChess->sendInvite(peer_id);

}
rsRetroChess->sendInvite(peer_id);

QString peerName = QString::fromUtf8(rsPeers->getPeerName(peer_id).c_str());
mChatWidget->addChatMsg(true, tr("Chess Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime()
QString peerName = QString::fromUtf8(rsPeers->getPeerName(peer_id).c_str());
mChatWidget->addChatMsg(true, tr("Chess Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime()
, tr("You're now inviting %1 to play Chess").arg(peerName), ChatWidget::MSGTYPE_SYSTEM);
}

}

void RetroChessChatWidgetHolder::chessStart()
{
RsPeerId peer_id = mChatWidget->getChatId().toPeerId();//TODO support GXSID

rsRetroChess->acceptedInvite(peer_id);
mRetroChessNotify->notifyChessStart(peer_id);
ChatId chatId = mChatWidget->getChatId();
if (chatId.isDistantChatId()) {
rsRetroChess->acceptedInviteGxs(RsGxsId(chatId.toDistantChatId().toStdString()));
} else {
RsPeerId peer_id = chatId.toPeerId();
rsRetroChess->acceptedInvite(peer_id);
mRetroChessNotify->notifyChessStart(peer_id);
}
return;
}

Expand Down
10 changes: 10 additions & 0 deletions gui/RetroChessNotify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@ void RetroChessNotify::notifyChessInvite(const RsPeerId &peer_id)
emit chessInvited(peer_id) ;

}

void RetroChessNotify::notifyChessMoveGxs(const RsGxsId &gxs_id, int col, int row, int count)
{
emit chessMoveGxs(gxs_id, col, row, count);
}

void RetroChessNotify::notifyGxsTunnelReady(const RsGxsId &gxs_id)
{
emit gxsTunnelReady(gxs_id);
}
8 changes: 8 additions & 0 deletions gui/RetroChessNotify.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ class RetroChessNotify : public QObject
void notifyReceivedMsg(const RsPeerId &peer_id, QString str) ;
void notifyChessStart(const RsPeerId &peer_id) ;
void notifyChessInvite(const RsPeerId &peer_id) ;
/** Notify the UI of a chess move received via a GXS tunnel */
void notifyChessMoveGxs(const RsGxsId &gxs_id, int col, int row, int count);

/** Notify the UI that a GXS tunnel is now ready for use */
void notifyGxsTunnelReady(const RsGxsId &gxs_id);

signals:
void NeMsgArrived(const RsPeerId &peer_id, QString str) ; // emitted when the peer gets a msg

void chessStart(const RsPeerId &peer_id) ;
void chessInvited(const RsPeerId &peer_id) ;

void chessMoveGxs(const RsGxsId &gxs_id, int col, int row, int count);
void gxsTunnelReady(const RsGxsId &gxs_id);

public slots:
};

Expand Down
94 changes: 88 additions & 6 deletions gui/chess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,76 @@
#include "gui/common/AvatarDefs.h"
#include "../services/p3RetroChess.h"

// NEW: Constructor for Distant GXS Identity
RetroChessWindow::RetroChessWindow(const RsGxsId &gxsId, int player, QWidget *parent) :
QWidget(parent),
m_ui(new Ui::RetroChessWindow),
mGxsId(gxsId),
mIsGxs(true)
{
QString player_str;
if (player == 1) {
player_str = " (1)";
} else if (player == 2) {
player_str = " (2)";
}

m_ui->setupUi(this);
mPeerId = gxsId.toStdString(); // Use string representation for internal tracking

m_ui->m_player1_result->hide();
m_ui->m_player2_result->hide();
m_ui->m_status_bar->hide();

m_flag_finished = 0; // set as unfinish

//tile = { { NULL } };
count=0;
turn=1; // white first
max=0;
texp = new int[60];

setGeometry(0,0,1370,700);

// Resolve our own primary GXS ID
std::list<RsGxsId> ownIds;
rsIdentity->getOwnIds(ownIds);
RsGxsId myGxsId = ownIds.empty() ? RsGxsId() : ownIds.front();

if (player) { // local player as black
// Note: For GXS we track identities rather than PeerIds
player_str = " (1)";
m_localplayer_turn = 0;

RsIdentityDetails d1, d2;
rsIdentity->getIdDetails(myGxsId, d1);
rsIdentity->getIdDetails(gxsId, d2);
p1name = d1.mNickname;
p2name = d2.mNickname;
} else { // local player as white
player_str = " (2)";
m_localplayer_turn = 1;

RsIdentityDetails d1, d2;
rsIdentity->getIdDetails(gxsId, d1);
rsIdentity->getIdDetails(myGxsId, d2);
p1name = d1.mNickname;
p2name = d2.mNickname;
}

QString title = QString::fromUtf8(p2name.c_str()) + " Playing Chess against " + QString::fromUtf8(p1name.c_str()) + player_str;

setWindowTitle(title);
initAccessories();
playerTurnNotice();
initChessBoard();
}

RetroChessWindow::RetroChessWindow(std::string peerid, int player, QWidget *parent) :
QWidget(parent),
m_ui( new Ui::RetroChessWindow() ),
mPeerId(peerid)
mPeerId(peerid),
mIsGxs(false)
//ui(new Ui::RetroChessWindow)
{
m_ui->setupUi( this );
Expand Down Expand Up @@ -125,7 +191,11 @@ void RetroChessWindow::initAccessories()
void RetroChessWindow::closeEvent(QCloseEvent *event)
{
// send leave message
rsRetroChess->player_leave(this->mPeerId);
if (mIsGxs) {
rsRetroChess->player_leave_gxs(this->mGxsId);
} else {
rsRetroChess->player_leave(mPeerId);
}

QWidget::closeEvent(event);
}
Expand Down Expand Up @@ -998,10 +1068,22 @@ int RetroChessWindow::resultJudge()

void RetroChessWindow::showPlayerLeaveMsg()
{
std::string player_name = rsPeers->getPeerName( RsPeerId(mPeerId ));
QString status_msg(player_name.c_str());
status_msg += " has left";
m_ui->m_status_bar->setText( status_msg );
QString name;
if (mIsGxs) {
// Resolve GXS nickname
RsIdentityDetails details;
if (rsIdentity->getIdDetails(mGxsId, details)) {
name = QString::fromUtf8(details.mNickname.c_str());
} else {
name = tr("Distant Friend");
}
} else {
// Resolve Peer name
name = QString::fromStdString(rsPeers->getPeerName(RsPeerId(mPeerId)));
}

QString status_msg = name + tr(" has left");
m_ui->m_status_bar->setText(status_msg);
m_ui->m_status_bar->setVisible(true);
}

Expand Down
4 changes: 4 additions & 0 deletions gui/chess.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <QWidget>

#include "retroshare/rspeers.h"
#include "retroshare/rsidentity.h"

#include <QQueue>

Expand Down Expand Up @@ -55,9 +56,12 @@ class RetroChessWindow : public QWidget
public:
std::string mPeerId;
explicit RetroChessWindow(std::string peerid, int player = 0, QWidget *parent = 0);
explicit RetroChessWindow(const RsGxsId &gxsId, int player = 0, QWidget *parent = 0);
~RetroChessWindow();
int currentplayer;
int myid;
RsGxsId mGxsId; // Store GXS identity if using a tunnel
bool mIsGxs;

//from global

Expand Down
6 changes: 5 additions & 1 deletion gui/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ void Tile::mousePressEvent(QMouseEvent *event)
if((chess_window_p)->m_localplayer_turn == (chess_window_p)->turn)
{
validate( ++(chess_window_p)->count );
rsRetroChess->chess_click(peer_id, this->row,this->col,(chess_window_p)->count);
if ((chess_window_p)->mIsGxs) {
rsRetroChess->chess_click_gxs((chess_window_p)->mGxsId, this->row,this->col, (chess_window_p)->count);
} else {
rsRetroChess->chess_click((chess_window_p)->mPeerId, this->row,this->col, (chess_window_p)->count);
}
}
// not local player's turn
}
Expand Down
9 changes: 9 additions & 0 deletions interface/rsRetroChess.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ class RsRetroChess
virtual void acceptedInvite(RsPeerId peerID) = 0;
virtual void gotInvite(RsPeerId peerID) = 0;
virtual void sendInvite(RsPeerId peerID) = 0;

// New GXSID & Tunneling methods
virtual void chess_click_gxs(const RsGxsId &gxs_id, int col, int row, int count) = 0;
virtual void player_leave_gxs(const RsGxsId &gxs_id) = 0;
virtual void requestGxsTunnel(const RsGxsId &gxsId) = 0;
virtual void sendGxsInvite(const RsGxsId &gxsId) = 0;
virtual void addChessFriend(const RsGxsId &gxsId) = 0;
virtual void acceptedInviteGxs(const RsGxsId &gxsId) = 0;

};


Loading