Added callback to display player names of connected players.
This commit is contained in:
@@ -99,4 +99,5 @@ void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myW->SignalN
|
|||||||
|
|
||||||
void GuiWrapper::SignalNetServerSuccess(int actionID) { }
|
void GuiWrapper::SignalNetServerSuccess(int actionID) { }
|
||||||
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { }
|
void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { }
|
||||||
|
void GuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { myW->SignalNetServerPlayerJoined(QString::fromUtf8(playerName.c_str())); }
|
||||||
|
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ public:
|
|||||||
|
|
||||||
void SignalNetServerSuccess(int actionID);
|
void SignalNetServerSuccess(int actionID);
|
||||||
void SignalNetServerError(int errorID, int osErrorID);
|
void SignalNetServerError(int errorID, int osErrorID);
|
||||||
|
void SignalNetServerPlayerJoined(const std::string &playerName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -544,6 +544,9 @@ mainWindowImpl::mainWindowImpl(QMainWindow *parent)
|
|||||||
// Errors are handled globally, not within one dialog.
|
// Errors are handled globally, not within one dialog.
|
||||||
connect(this, SIGNAL(SignalNetClientError(int, int)), this, SLOT(networkError(int, int)));
|
connect(this, SIGNAL(SignalNetClientError(int, int)), this, SLOT(networkError(int, int)));
|
||||||
|
|
||||||
|
connect(this, SIGNAL(SignalNetServerPlayerJoined(QString)), myStartNetworkGameDialog, SLOT(addConnectedPlayer(QString)));
|
||||||
|
|
||||||
|
|
||||||
// textBrowser_Log->append(QString::number(this->pos().x(),10)+" "+QString::number(this->pos().y(),10));
|
// textBrowser_Log->append(QString::number(this->pos().x(),10)+" "+QString::number(this->pos().y(),10));
|
||||||
// textBrowser_Log->append(QString::number(this->x(),10)+" "+QString::number(this->y(),10));
|
// textBrowser_Log->append(QString::number(this->x(),10)+" "+QString::number(this->y(),10));
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ signals:
|
|||||||
void SignalNetClientConnect(int actionID);
|
void SignalNetClientConnect(int actionID);
|
||||||
void SignalNetClientGameInfo(int actionID);
|
void SignalNetClientGameInfo(int actionID);
|
||||||
void SignalNetClientError(int errorID, int osErrorID);
|
void SignalNetClientError(int errorID, int osErrorID);
|
||||||
|
void SignalNetServerPlayerJoined(QString playerName);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
|||||||
@@ -41,10 +41,10 @@ void startNetworkGameDialogImpl::cancel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void startNetworkGameDialogImpl::addConnectedPlayer(std::string playerName) {
|
void startNetworkGameDialogImpl::addConnectedPlayer(QString playerName) {
|
||||||
|
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget,0);
|
QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget,0);
|
||||||
item->setData(0, 0, QString::fromUtf8(playerName.c_str()));
|
item->setData(0, 0, playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startNetworkGameDialogImpl::keyPressEvent ( QKeyEvent * event ) {
|
void startNetworkGameDialogImpl::keyPressEvent ( QKeyEvent * event ) {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public slots:
|
|||||||
|
|
||||||
void startGame();
|
void startGame();
|
||||||
void cancel();
|
void cancel();
|
||||||
void addConnectedPlayer(std::string);
|
void addConnectedPlayer(QString playerName);
|
||||||
|
|
||||||
void keyPressEvent ( QKeyEvent*);
|
void keyPressEvent ( QKeyEvent*);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define ADD_PADDING(x) ((((x) + 3) >> 2) << 2)
|
#define ADD_PADDING(x) ((((x) + 3) >> 2) << 2)
|
||||||
|
|
||||||
#define NET_TYPE_JOIN_GAME 1
|
#define NET_TYPE_JOIN_GAME 1
|
||||||
#define NET_TYPE_JOIN_GAME_ACK 2
|
#define NET_TYPE_JOIN_GAME_ACK 2
|
||||||
|
|||||||
@@ -77,7 +77,9 @@ ServerRecvStateInit::Process(ServerRecvThread &server)
|
|||||||
if (tmpPacket)
|
if (tmpPacket)
|
||||||
{
|
{
|
||||||
// TODO: check password
|
// TODO: check password
|
||||||
// TODO: display name
|
NetPacketJoinGame::Data playerData;
|
||||||
|
tmpPacket->GetData(playerData);
|
||||||
|
server.GetCallback().SignalNetServerPlayerJoined(playerData.playerName);
|
||||||
boost::shared_ptr<NetPacket> answer(new NetPacketJoinGameAck);
|
boost::shared_ptr<NetPacket> answer(new NetPacketJoinGameAck);
|
||||||
server.GetSender().Send(answer, recvSock);
|
server.GetSender().Send(answer, recvSock);
|
||||||
session->SetState(SessionData::Established);
|
session->SetState(SessionData::Established);
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
ServerRecvThread::ServerRecvThread()
|
ServerRecvThread::ServerRecvThread(ServerCallback &cb)
|
||||||
|
: m_callback(cb)
|
||||||
{
|
{
|
||||||
m_senderCallback.reset(new ServerSenderCallback(*this));
|
m_senderCallback.reset(new ServerSenderCallback(*this));
|
||||||
m_sender.reset(new SenderThread(GetSenderCallback()));
|
m_sender.reset(new SenderThread(GetSenderCallback()));
|
||||||
@@ -85,6 +86,12 @@ ServerRecvThread::AddNotification(unsigned notification)
|
|||||||
m_notificationQueue.push_back(notification);
|
m_notificationQueue.push_back(notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServerCallback &
|
||||||
|
ServerRecvThread::GetCallback()
|
||||||
|
{
|
||||||
|
return m_callback;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerRecvThread::Main()
|
ServerRecvThread::Main()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ ServerThread::ServerThread(ServerCallback &cb)
|
|||||||
: m_callback(cb)
|
: m_callback(cb)
|
||||||
{
|
{
|
||||||
m_context.reset(new ServerContext);
|
m_context.reset(new ServerContext);
|
||||||
m_recvThread.reset(new ServerRecvThread);
|
m_recvThread.reset(new ServerRecvThread(cb));
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerThread::~ServerThread()
|
ServerThread::~ServerThread()
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
#ifndef _SERVERCALLBACK_H_
|
#ifndef _SERVERCALLBACK_H_
|
||||||
#define _SERVERCALLBACK_H_
|
#define _SERVERCALLBACK_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class ServerCallback
|
class ServerCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -28,6 +30,8 @@ public:
|
|||||||
|
|
||||||
virtual void SignalNetServerSuccess(int actionID) = 0;
|
virtual void SignalNetServerSuccess(int actionID) = 0;
|
||||||
virtual void SignalNetServerError(int errorID, int osErrorID) = 0;
|
virtual void SignalNetServerError(int errorID, int osErrorID) = 0;
|
||||||
|
|
||||||
|
virtual void SignalNetServerPlayerJoined(const std::string &playerName) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include <net/connectdata.h>
|
#include <net/connectdata.h>
|
||||||
#include <net/sessiondata.h>
|
#include <net/sessiondata.h>
|
||||||
|
#include <net/servercallback.h>
|
||||||
|
|
||||||
#define RECEIVER_THREAD_TERMINATE_TIMEOUT 200
|
#define RECEIVER_THREAD_TERMINATE_TIMEOUT 200
|
||||||
|
|
||||||
@@ -43,13 +44,15 @@ class NetPacket;
|
|||||||
class ServerRecvThread : public Thread
|
class ServerRecvThread : public Thread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ServerRecvThread();
|
ServerRecvThread(ServerCallback &gui);
|
||||||
virtual ~ServerRecvThread();
|
virtual ~ServerRecvThread();
|
||||||
|
|
||||||
void SendToAllPlayers(boost::shared_ptr<NetPacket> packet);
|
void SendToAllPlayers(boost::shared_ptr<NetPacket> packet);
|
||||||
void AddConnection(boost::shared_ptr<ConnectData> data);
|
void AddConnection(boost::shared_ptr<ConnectData> data);
|
||||||
void AddNotification(unsigned notification);
|
void AddNotification(unsigned notification);
|
||||||
|
|
||||||
|
ServerCallback &GetCallback();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
typedef std::deque<boost::shared_ptr<ConnectData> > ConnectQueue;
|
typedef std::deque<boost::shared_ptr<ConnectData> > ConnectQueue;
|
||||||
@@ -94,6 +97,8 @@ private:
|
|||||||
|
|
||||||
std::auto_ptr<ServerSenderCallback> m_senderCallback;
|
std::auto_ptr<ServerSenderCallback> m_senderCallback;
|
||||||
|
|
||||||
|
ServerCallback &m_callback;
|
||||||
|
|
||||||
friend class ServerRecvStateInit;
|
friend class ServerRecvStateInit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user