room stuff and minor fixes
This commit is contained in:
parent
80277ff573
commit
78d81ae65a
19 changed files with 159 additions and 99 deletions
|
@ -5,7 +5,7 @@ INCLUDEPATH += . src ../common
|
|||
MOC_DIR = build
|
||||
OBJECTS_DIR = build
|
||||
RESOURCES = cockatrice.qrc
|
||||
QT += network svg
|
||||
QT += network svg webkit
|
||||
|
||||
HEADERS += src/counter.h \
|
||||
src/dlg_creategame.h \
|
||||
|
|
|
@ -46,6 +46,7 @@ signals:
|
|||
void listRoomsEventReceived(Event_ListRooms *event);
|
||||
void gameJoinedEventReceived(Event_GameJoined *event);
|
||||
void messageEventReceived(Event_Message *event);
|
||||
void userInfoChanged(ServerInfo_User *userInfo);
|
||||
protected slots:
|
||||
void processProtocolItem(ProtocolItem *item);
|
||||
protected:
|
||||
|
|
|
@ -42,12 +42,17 @@ void RemoteClient::slotConnected()
|
|||
setStatus(StatusAwaitingWelcome);
|
||||
}
|
||||
|
||||
void RemoteClient::loginResponse(ResponseCode response)
|
||||
void RemoteClient::loginResponse(ProtocolResponse *response)
|
||||
{
|
||||
if (response == RespOk)
|
||||
Response_Login *resp = qobject_cast<Response_Login *>(response);
|
||||
if (!resp)
|
||||
disconnectFromServer();
|
||||
|
||||
if (resp->getResponseCode() == RespOk) {
|
||||
setStatus(StatusLoggedIn);
|
||||
else {
|
||||
emit serverError(response);
|
||||
emit userInfoChanged(resp->getUserInfo());
|
||||
} else {
|
||||
emit serverError(resp->getResponseCode());
|
||||
setStatus(StatusDisconnecting);
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +83,7 @@ void RemoteClient::readData()
|
|||
|
||||
setStatus(StatusLoggingIn);
|
||||
Command_Login *cmdLogin = new Command_Login(userName, password);
|
||||
connect(cmdLogin, SIGNAL(finished(ResponseCode)), this, SLOT(loginResponse(ResponseCode)));
|
||||
connect(cmdLogin, SIGNAL(finished(ProtocolResponse *)), this, SLOT(loginResponse(ProtocolResponse *)));
|
||||
sendCommand(cmdLogin);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define REMOTECLIENT_H
|
||||
|
||||
#include <QTcpSocket>
|
||||
#include "protocol_datastructures.h"
|
||||
#include "abstractclient.h"
|
||||
|
||||
class QTimer;
|
||||
|
@ -22,7 +21,7 @@ private slots:
|
|||
void readData();
|
||||
void slotSocketError(QAbstractSocket::SocketError error);
|
||||
void ping();
|
||||
void loginResponse(ResponseCode response);
|
||||
void loginResponse(ProtocolResponse *response);
|
||||
private:
|
||||
static const int maxTimeout = 10;
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <QCheckBox>
|
||||
#include <QInputDialog>
|
||||
#include <QLabel>
|
||||
#include <QScrollBar>
|
||||
#include "dlg_creategame.h"
|
||||
#include "tab_room.h"
|
||||
#include "userlist.h"
|
||||
|
@ -17,6 +18,8 @@
|
|||
#include "protocol_items.h"
|
||||
#include "gamesmodel.h"
|
||||
|
||||
#include <QTextTable>
|
||||
|
||||
GameSelector::GameSelector(AbstractClient *_client, int _roomId, QWidget *parent)
|
||||
: QGroupBox(parent), client(_client), roomId(_roomId)
|
||||
{
|
||||
|
@ -119,14 +122,50 @@ void GameSelector::processGameInfo(ServerInfo_Game *info)
|
|||
gameListModel->updateGameList(info);
|
||||
}
|
||||
|
||||
TabRoom::TabRoom(AbstractClient *_client, ServerInfo_Room *info)
|
||||
: Tab(), client(_client), roomId(info->getRoomId()), roomName(info->getName())
|
||||
ChatView::ChatView(const QString &_ownName, QWidget *parent)
|
||||
: QTextEdit(parent), ownName(_ownName)
|
||||
{
|
||||
setTextInteractionFlags(Qt::TextSelectableByMouse);
|
||||
|
||||
QTextTableFormat format;
|
||||
format.setBorderStyle(QTextFrameFormat::BorderStyle_None);
|
||||
table = textCursor().insertTable(1, 3, format);
|
||||
}
|
||||
|
||||
void ChatView::appendMessage(const QString &sender, const QString &message)
|
||||
{
|
||||
QTextCursor cellCursor = table->cellAt(table->rows() - 1, 0).lastCursorPosition();
|
||||
cellCursor.insertText(QDateTime::currentDateTime().toString("[hh:mm]"));
|
||||
QTextTableCell senderCell = table->cellAt(table->rows() - 1, 1);
|
||||
QTextCharFormat senderFormat;
|
||||
if (sender == ownName) {
|
||||
senderFormat.setFontWeight(QFont::Bold);
|
||||
senderFormat.setForeground(Qt::red);
|
||||
} else
|
||||
senderFormat.setForeground(Qt::blue);
|
||||
senderCell.setFormat(senderFormat);
|
||||
cellCursor = senderCell.lastCursorPosition();
|
||||
cellCursor.insertText(sender);
|
||||
QTextTableCell messageCell = table->cellAt(table->rows() - 1, 2);
|
||||
QTextCharFormat messageFormat;
|
||||
if (sender.isEmpty())
|
||||
messageFormat.setForeground(Qt::darkGreen);
|
||||
messageCell.setFormat(messageFormat);
|
||||
cellCursor = messageCell.lastCursorPosition();
|
||||
cellCursor.insertText(message);
|
||||
|
||||
table->appendRows(1);
|
||||
|
||||
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
|
||||
}
|
||||
|
||||
TabRoom::TabRoom(AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info)
|
||||
: Tab(), client(_client), roomId(info->getRoomId()), roomName(info->getName()), ownName(_ownName)
|
||||
{
|
||||
gameSelector = new GameSelector(client, roomId);
|
||||
userList = new UserList(false);
|
||||
|
||||
textEdit = new QTextEdit;
|
||||
textEdit->setReadOnly(true);
|
||||
chatView = new ChatView(ownName);
|
||||
sayLabel = new QLabel;
|
||||
sayEdit = new QLineEdit;
|
||||
sayLabel->setBuddy(sayEdit);
|
||||
|
@ -137,7 +176,7 @@ TabRoom::TabRoom(AbstractClient *_client, ServerInfo_Room *info)
|
|||
sayHbox->addWidget(sayEdit);
|
||||
|
||||
QVBoxLayout *chatVbox = new QVBoxLayout;
|
||||
chatVbox->addWidget(textEdit);
|
||||
chatVbox->addWidget(chatView);
|
||||
chatVbox->addLayout(sayHbox);
|
||||
|
||||
chatGroupBox = new QGroupBox;
|
||||
|
@ -221,23 +260,18 @@ void TabRoom::processListGamesEvent(Event_ListGames *event)
|
|||
|
||||
void TabRoom::processJoinRoomEvent(Event_JoinRoom *event)
|
||||
{
|
||||
textEdit->append(tr("%1 has joined the room.").arg(sanitizeHtml(event->getUserInfo()->getName())));
|
||||
chatView->appendMessage(QString(), tr("%1 has joined the room.").arg(event->getUserInfo()->getName()));
|
||||
userList->processUserInfo(event->getUserInfo());
|
||||
emit userEvent();
|
||||
}
|
||||
|
||||
void TabRoom::processLeaveRoomEvent(Event_LeaveRoom *event)
|
||||
{
|
||||
textEdit->append(tr("%1 has left the room.").arg(sanitizeHtml(event->getPlayerName())));
|
||||
chatView->appendMessage(QString(), tr("%1 has left the room.").arg(event->getPlayerName()));
|
||||
userList->deleteUser(event->getPlayerName());
|
||||
emit userEvent();
|
||||
}
|
||||
|
||||
void TabRoom::processSayEvent(Event_RoomSay *event)
|
||||
{
|
||||
if (event->getPlayerName().isEmpty())
|
||||
textEdit->append(QString("<font color=\"blue\">%1</font").arg(sanitizeHtml(event->getMessage())));
|
||||
else
|
||||
textEdit->append(QString("<font color=\"red\">%1:</font> %2").arg(sanitizeHtml(event->getPlayerName())).arg(sanitizeHtml(event->getMessage())));
|
||||
chatView->appendMessage(event->getPlayerName(), event->getMessage());
|
||||
emit userEvent();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "tab.h"
|
||||
#include "protocol_datastructures.h"
|
||||
#include <QGroupBox>
|
||||
#include <QTextEdit>
|
||||
|
||||
class AbstractClient;
|
||||
class UserList;
|
||||
|
@ -12,6 +13,7 @@ class QTextEdit;
|
|||
class QLineEdit;
|
||||
class QTreeView;
|
||||
class QPushButton;
|
||||
class QTextTable;
|
||||
class QCheckBox;
|
||||
class GamesModel;
|
||||
class GamesProxyModel;
|
||||
|
@ -47,16 +49,27 @@ public:
|
|||
void processGameInfo(ServerInfo_Game *info);
|
||||
};
|
||||
|
||||
class ChatView : public QTextEdit {
|
||||
Q_OBJECT;
|
||||
private:
|
||||
QTextTable *table;
|
||||
QString ownName;
|
||||
public:
|
||||
ChatView(const QString &_ownName, QWidget *parent = 0);
|
||||
void appendMessage(const QString &sender, const QString &message);
|
||||
};
|
||||
|
||||
class TabRoom : public Tab {
|
||||
Q_OBJECT
|
||||
private:
|
||||
AbstractClient *client;
|
||||
int roomId;
|
||||
QString roomName;
|
||||
QString ownName;
|
||||
|
||||
GameSelector *gameSelector;
|
||||
UserList *userList;
|
||||
QTextEdit *textEdit;
|
||||
ChatView *chatView;
|
||||
QLabel *sayLabel;
|
||||
QLineEdit *sayEdit;
|
||||
QGroupBox *chatGroupBox;
|
||||
|
@ -74,7 +87,7 @@ private slots:
|
|||
void processLeaveRoomEvent(Event_LeaveRoom *event);
|
||||
void processSayEvent(Event_RoomSay *event);
|
||||
public:
|
||||
TabRoom(AbstractClient *_client, ServerInfo_Room *info);
|
||||
TabRoom(AbstractClient *_client, const QString &_ownName, ServerInfo_Room *info);
|
||||
~TabRoom();
|
||||
void retranslateUi();
|
||||
void processRoomEvent(RoomEvent *event);
|
||||
|
|
|
@ -116,32 +116,7 @@ void RoomSelector::joinFinished(ProtocolResponse *r)
|
|||
emit roomJoined(resp->getRoomInfo());
|
||||
}
|
||||
|
||||
ServerMessageLog::ServerMessageLog(AbstractClient *_client, QWidget *parent)
|
||||
: QGroupBox(parent)
|
||||
{
|
||||
textEdit = new QTextEdit;
|
||||
textEdit->setReadOnly(true);
|
||||
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(textEdit);
|
||||
|
||||
setLayout(vbox);
|
||||
retranslateUi();
|
||||
|
||||
connect(_client, SIGNAL(serverMessageEventReceived(Event_ServerMessage *)), this, SLOT(processServerMessageEvent(Event_ServerMessage *)));
|
||||
}
|
||||
|
||||
void ServerMessageLog::retranslateUi()
|
||||
{
|
||||
setTitle(tr("Server messages"));
|
||||
}
|
||||
|
||||
void ServerMessageLog::processServerMessageEvent(Event_ServerMessage *event)
|
||||
{
|
||||
textEdit->append(event->getMessage());
|
||||
}
|
||||
|
||||
UserInfoBox::UserInfoBox(AbstractClient *_client, QWidget *parent)
|
||||
UserInfoBox::UserInfoBox(ServerInfo_User *userInfo, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
avatarLabel = new QLabel;
|
||||
|
@ -169,9 +144,7 @@ UserInfoBox::UserInfoBox(AbstractClient *_client, QWidget *parent)
|
|||
|
||||
setLayout(mainLayout);
|
||||
|
||||
Command_GetUserInfo *cmd = new Command_GetUserInfo;
|
||||
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(processResponse(ProtocolResponse *)));
|
||||
_client->sendCommand(cmd);
|
||||
updateInfo(userInfo);
|
||||
}
|
||||
|
||||
void UserInfoBox::retranslateUi()
|
||||
|
@ -180,12 +153,8 @@ void UserInfoBox::retranslateUi()
|
|||
userLevelLabel1->setText(tr("User level:"));
|
||||
}
|
||||
|
||||
void UserInfoBox::processResponse(ProtocolResponse *response)
|
||||
void UserInfoBox::updateInfo(ServerInfo_User *user)
|
||||
{
|
||||
Response_GetUserInfo *resp = qobject_cast<Response_GetUserInfo *>(response);
|
||||
if (!resp)
|
||||
return;
|
||||
ServerInfo_User *user = resp->getUserInfo();
|
||||
int userLevel = user->getUserLevel();
|
||||
|
||||
QPixmap avatarPixmap;
|
||||
|
@ -208,21 +177,20 @@ void UserInfoBox::processResponse(ProtocolResponse *response)
|
|||
userLevelLabel3->setText(userLevelText);
|
||||
}
|
||||
|
||||
TabServer::TabServer(AbstractClient *_client, QWidget *parent)
|
||||
TabServer::TabServer(AbstractClient *_client, ServerInfo_User *userInfo, QWidget *parent)
|
||||
: Tab(parent), client(_client)
|
||||
{
|
||||
roomSelector = new RoomSelector(client);
|
||||
serverMessageLog = new ServerMessageLog(client);
|
||||
userInfoBox = new UserInfoBox(client);
|
||||
serverInfoBox = new QTextBrowser;
|
||||
userInfoBox = new UserInfoBox(userInfo);
|
||||
userList = new UserList(true);
|
||||
|
||||
// connect(gameSelector, SIGNAL(gameJoined(int)), this, SIGNAL(gameJoined(int)));
|
||||
connect(roomSelector, SIGNAL(roomJoined(ServerInfo_Room *)), this, SIGNAL(roomJoined(ServerInfo_Room *)));
|
||||
connect(userList, SIGNAL(openMessageDialog(const QString &, bool)), this, SIGNAL(openMessageDialog(const QString &, bool)));
|
||||
connect(userList, SIGNAL(userLeft(const QString &)), this, SIGNAL(userLeft(const QString &)));
|
||||
|
||||
connect(client, SIGNAL(userJoinedEventReceived(Event_UserJoined *)), this, SLOT(processUserJoinedEvent(Event_UserJoined *)));
|
||||
connect(client, SIGNAL(userLeftEventReceived(Event_UserLeft *)), this, SLOT(processUserLeftEvent(Event_UserLeft *)));
|
||||
connect(client, SIGNAL(serverMessageEventReceived(Event_ServerMessage *)), this, SLOT(processServerMessageEvent(Event_ServerMessage *)));
|
||||
|
||||
Command_ListUsers *cmd = new Command_ListUsers;
|
||||
connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(processListUsersResponse(ProtocolResponse *)));
|
||||
|
@ -230,7 +198,7 @@ TabServer::TabServer(AbstractClient *_client, QWidget *parent)
|
|||
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(roomSelector);
|
||||
vbox->addWidget(serverMessageLog);
|
||||
vbox->addWidget(serverInfoBox);
|
||||
|
||||
QVBoxLayout *vbox2 = new QVBoxLayout;
|
||||
vbox2->addWidget(userInfoBox);
|
||||
|
@ -246,11 +214,15 @@ TabServer::TabServer(AbstractClient *_client, QWidget *parent)
|
|||
void TabServer::retranslateUi()
|
||||
{
|
||||
roomSelector->retranslateUi();
|
||||
serverMessageLog->retranslateUi();
|
||||
userInfoBox->retranslateUi();
|
||||
userList->retranslateUi();
|
||||
}
|
||||
|
||||
void TabServer::processServerMessageEvent(Event_ServerMessage *event)
|
||||
{
|
||||
serverInfoBox->setHtml(event->getMessage());
|
||||
}
|
||||
|
||||
void TabServer::processListUsersResponse(ProtocolResponse *response)
|
||||
{
|
||||
Response_ListUsers *resp = qobject_cast<Response_ListUsers *>(response);
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
|
||||
#include <QGroupBox>
|
||||
#include <QTreeWidget>
|
||||
#include <QTextBrowser>
|
||||
#include "tab.h"
|
||||
#include "protocol_datastructures.h"
|
||||
//#include "protocol_datastructures.h"
|
||||
|
||||
class AbstractClient;
|
||||
class QTextEdit;
|
||||
|
@ -17,6 +18,8 @@ class Event_ServerMessage;
|
|||
class Event_UserJoined;
|
||||
class Event_UserLeft;
|
||||
class ProtocolResponse;
|
||||
class ServerInfo_User;
|
||||
class ServerInfo_Room;
|
||||
|
||||
class RoomSelector : public QGroupBox {
|
||||
Q_OBJECT
|
||||
|
@ -37,25 +40,13 @@ public:
|
|||
void retranslateUi();
|
||||
};
|
||||
|
||||
class ServerMessageLog : public QGroupBox {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QTextEdit *textEdit;
|
||||
private slots:
|
||||
void processServerMessageEvent(Event_ServerMessage *event);
|
||||
public:
|
||||
ServerMessageLog(AbstractClient *_client, QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
};
|
||||
|
||||
class UserInfoBox : public QWidget {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QLabel *avatarLabel, *nameLabel, *countryLabel1, *countryLabel2, *userLevelLabel1, *userLevelLabel2, *userLevelLabel3;
|
||||
private slots:
|
||||
void processResponse(ProtocolResponse *response);
|
||||
void updateInfo(ServerInfo_User *user);
|
||||
public:
|
||||
UserInfoBox(AbstractClient *_client, QWidget *parent = 0);
|
||||
UserInfoBox(ServerInfo_User *userInfo, QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
};
|
||||
|
||||
|
@ -63,21 +54,21 @@ class TabServer : public Tab {
|
|||
Q_OBJECT
|
||||
signals:
|
||||
void roomJoined(ServerInfo_Room *info);
|
||||
// void gameJoined(int gameId);
|
||||
void openMessageDialog(const QString &userName, bool focus);
|
||||
void userLeft(const QString &userName);
|
||||
private slots:
|
||||
void processListUsersResponse(ProtocolResponse *response);
|
||||
void processUserJoinedEvent(Event_UserJoined *event);
|
||||
void processUserLeftEvent(Event_UserLeft *event);
|
||||
void processServerMessageEvent(Event_ServerMessage *event);
|
||||
private:
|
||||
AbstractClient *client;
|
||||
RoomSelector *roomSelector;
|
||||
ServerMessageLog *serverMessageLog;
|
||||
QTextBrowser *serverInfoBox;
|
||||
UserList *userList;
|
||||
UserInfoBox *userInfoBox;
|
||||
public:
|
||||
TabServer(AbstractClient *_client, QWidget *parent = 0);
|
||||
TabServer(AbstractClient *_client, ServerInfo_User *userInfo, QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
QString getTabText() const { return tr("Server"); }
|
||||
};
|
||||
|
|
|
@ -51,16 +51,18 @@ void TabSupervisor::myAddTab(Tab *tab)
|
|||
addTab(tab, tab->getTabText());
|
||||
}
|
||||
|
||||
void TabSupervisor::start(AbstractClient *_client)
|
||||
void TabSupervisor::start(AbstractClient *_client, ServerInfo_User *userInfo)
|
||||
{
|
||||
client = _client;
|
||||
userName = userInfo->getName();
|
||||
|
||||
connect(client, SIGNAL(roomEventReceived(RoomEvent *)), this, SLOT(processRoomEvent(RoomEvent *)));
|
||||
connect(client, SIGNAL(gameEventContainerReceived(GameEventContainer *)), this, SLOT(processGameEventContainer(GameEventContainer *)));
|
||||
connect(client, SIGNAL(gameJoinedEventReceived(Event_GameJoined *)), this, SLOT(gameJoined(Event_GameJoined *)));
|
||||
connect(client, SIGNAL(messageEventReceived(Event_Message *)), this, SLOT(processMessageEvent(Event_Message *)));
|
||||
connect(client, SIGNAL(maxPingTime(int, int)), this, SLOT(updatePingTime(int, int)));
|
||||
|
||||
tabServer = new TabServer(client);
|
||||
tabServer = new TabServer(client, userInfo);
|
||||
connect(tabServer, SIGNAL(roomJoined(ServerInfo_Room *)), this, SLOT(addRoomTab(ServerInfo_Room *)));
|
||||
connect(tabServer, SIGNAL(openMessageDialog(const QString &, bool)), this, SLOT(addMessageTab(const QString &, bool)));
|
||||
connect(tabServer, SIGNAL(userLeft(const QString &)), this, SLOT(processUserLeft(const QString &)));
|
||||
|
@ -162,7 +164,7 @@ void TabSupervisor::gameLeft(TabGame *tab)
|
|||
|
||||
void TabSupervisor::addRoomTab(ServerInfo_Room *info)
|
||||
{
|
||||
TabRoom *tab = new TabRoom(client, info);
|
||||
TabRoom *tab = new TabRoom(client, userName, info);
|
||||
connect(tab, SIGNAL(roomClosing(TabRoom *)), this, SLOT(roomLeft(TabRoom *)));
|
||||
myAddTab(tab);
|
||||
roomTabs.insert(info->getRoomId(), tab);
|
||||
|
@ -177,12 +179,15 @@ void TabSupervisor::roomLeft(TabRoom *tab)
|
|||
removeTab(indexOf(tab));
|
||||
}
|
||||
|
||||
TabMessage *TabSupervisor::addMessageTab(const QString &userName, bool focus)
|
||||
TabMessage *TabSupervisor::addMessageTab(const QString &receiverName, bool focus)
|
||||
{
|
||||
TabMessage *tab = new TabMessage(client, userName);
|
||||
if (receiverName == userName)
|
||||
return 0;
|
||||
|
||||
TabMessage *tab = new TabMessage(client, receiverName);
|
||||
connect(tab, SIGNAL(talkClosing(TabMessage *)), this, SLOT(talkLeft(TabMessage *)));
|
||||
myAddTab(tab);
|
||||
messageTabs.insert(userName, tab);
|
||||
messageTabs.insert(receiverName, tab);
|
||||
if (focus)
|
||||
setCurrentWidget(tab);
|
||||
return tab;
|
||||
|
@ -230,6 +235,8 @@ void TabSupervisor::processMessageEvent(Event_Message *event)
|
|||
tab = messageTabs.value(event->getReceiverName());
|
||||
if (!tab)
|
||||
tab = addMessageTab(event->getSenderName(), false);
|
||||
if (!tab)
|
||||
return;
|
||||
tab->processMessageEvent(event);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,10 +17,12 @@ class GameEventContainer;
|
|||
class Event_GameJoined;
|
||||
class Event_Message;
|
||||
class ServerInfo_Room;
|
||||
class ServerInfo_User;
|
||||
|
||||
class TabSupervisor : public QTabWidget {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QString userName;
|
||||
QIcon *tabChangedIcon;
|
||||
AbstractClient *client;
|
||||
QList<AbstractClient *> localClients;
|
||||
|
@ -34,7 +36,7 @@ public:
|
|||
TabSupervisor(QWidget *parent = 0);
|
||||
~TabSupervisor();
|
||||
void retranslateUi();
|
||||
void start(AbstractClient *_client);
|
||||
void start(AbstractClient *_client, ServerInfo_User *userInfo);
|
||||
void startLocal(const QList<AbstractClient *> &_clients);
|
||||
void stop();
|
||||
int getGameCount() const { return gameTabs.size(); }
|
||||
|
|
|
@ -64,15 +64,18 @@ void MainWindow::statusChanged(ClientStatus _status)
|
|||
aConnect->setEnabled(false);
|
||||
aDisconnect->setEnabled(true);
|
||||
break;
|
||||
case StatusLoggedIn: {
|
||||
tabSupervisor->start(client);
|
||||
case StatusLoggedIn:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::userInfoReceived(ServerInfo_User *info)
|
||||
{
|
||||
tabSupervisor->start(client, info);
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
void MainWindow::actConnect()
|
||||
|
@ -260,6 +263,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout()));
|
||||
connect(client, SIGNAL(statusChanged(ClientStatus)), this, SLOT(statusChanged(ClientStatus)));
|
||||
connect(client, SIGNAL(protocolVersionMismatch(int, int)), this, SLOT(protocolVersionMismatch(int, int)));
|
||||
connect(client, SIGNAL(userInfoChanged(ServerInfo_User *)), this, SLOT(userInfoReceived(ServerInfo_User *)));
|
||||
|
||||
tabSupervisor = new TabSupervisor;
|
||||
connect(tabSupervisor, SIGNAL(setMenu(QMenu *)), this, SLOT(updateTabMenu(QMenu *)));
|
||||
|
|
|
@ -28,6 +28,7 @@ class TabSupervisor;
|
|||
class RemoteClient;
|
||||
class LocalClient;
|
||||
class LocalServer;
|
||||
class ServerInfo_User;
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
@ -38,6 +39,7 @@ private slots:
|
|||
void serverError(ResponseCode r);
|
||||
void socketError(const QString &errorStr);
|
||||
void protocolVersionMismatch(int localVersion, int remoteVersion);
|
||||
void userInfoReceived(ServerInfo_User *userInfo);
|
||||
void localGameEnded();
|
||||
|
||||
void actConnect();
|
||||
|
|
|
@ -44,6 +44,7 @@ void ProtocolItem::initializeHash()
|
|||
registerSerializableItem("respdeck_download", Response_DeckDownload::newItem);
|
||||
registerSerializableItem("respdeck_upload", Response_DeckUpload::newItem);
|
||||
registerSerializableItem("respdump_zone", Response_DumpZone::newItem);
|
||||
registerSerializableItem("resplogin", Response_Login::newItem);
|
||||
|
||||
registerSerializableItem("room_eventlist_games", Event_ListGames::newItem);
|
||||
registerSerializableItem("room_eventjoin_room", Event_JoinRoom::newItem);
|
||||
|
@ -281,6 +282,14 @@ Response_DumpZone::Response_DumpZone(int _cmdId, ResponseCode _responseCode, Ser
|
|||
insertItem(_zone);
|
||||
}
|
||||
|
||||
Response_Login::Response_Login(int _cmdId, ResponseCode _responseCode, ServerInfo_User *_userInfo)
|
||||
: ProtocolResponse(_cmdId, _responseCode, "login")
|
||||
{
|
||||
if (!_userInfo)
|
||||
_userInfo = new ServerInfo_User;
|
||||
insertItem(_userInfo);
|
||||
}
|
||||
|
||||
GameEvent::GameEvent(const QString &_eventName, int _playerId)
|
||||
: ProtocolItem("game_event", _eventName)
|
||||
{
|
||||
|
|
|
@ -44,6 +44,7 @@ enum ItemId {
|
|||
ItemId_Response_DeckUpload = ItemId_Other + 304,
|
||||
ItemId_Response_DumpZone = ItemId_Other + 305,
|
||||
ItemId_Response_JoinRoom = ItemId_Other + 306,
|
||||
ItemId_Response_Login = ItemId_Other + 307,
|
||||
ItemId_Invalid = ItemId_Other + 1000
|
||||
};
|
||||
|
||||
|
@ -268,6 +269,15 @@ public:
|
|||
ServerInfo_Zone *getZone() const { return static_cast<ServerInfo_Zone *>(itemMap.value("zone")); }
|
||||
};
|
||||
|
||||
class Response_Login : public ProtocolResponse {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Response_Login(int _cmdId = -1, ResponseCode _responseCode = RespOk, ServerInfo_User *_userInfo = 0);
|
||||
int getItemId() const { return ItemId_Response_Login; }
|
||||
static SerializableItem *newItem() { return new Response_Login; }
|
||||
ServerInfo_User *getUserInfo() const { return static_cast<ServerInfo_User *>(itemMap.value("user")); }
|
||||
};
|
||||
|
||||
// --------------
|
||||
// --- EVENTS ---
|
||||
// --------------
|
||||
|
|
|
@ -108,6 +108,11 @@ void Server::broadcastRoomUpdate()
|
|||
delete event;
|
||||
}
|
||||
|
||||
void Server::gameCreated(Server_Game *game)
|
||||
{
|
||||
games.insert(game->getGameId(), game);
|
||||
}
|
||||
|
||||
void Server::gameClosing(int gameId)
|
||||
{
|
||||
qDebug("Server::gameClosing");
|
||||
|
|
|
@ -18,6 +18,7 @@ class Server : public QObject
|
|||
signals:
|
||||
void pingClockTimeout();
|
||||
private slots:
|
||||
void gameCreated(Server_Game *game);
|
||||
void gameClosing(int gameId);
|
||||
void broadcastRoomUpdate();
|
||||
public:
|
||||
|
|
|
@ -25,6 +25,10 @@ Server_ProtocolHandler::~Server_ProtocolHandler()
|
|||
// so it will not receive the game update event.
|
||||
server->removeClient(this);
|
||||
|
||||
QMapIterator<int, Server_Room *> roomIterator(rooms);
|
||||
while (roomIterator.hasNext())
|
||||
roomIterator.next().value()->removeClient(this);
|
||||
|
||||
QMapIterator<int, QPair<Server_Game *, Server_Player *> > gameIterator(games);
|
||||
while (gameIterator.hasNext()) {
|
||||
gameIterator.next();
|
||||
|
@ -37,10 +41,6 @@ Server_ProtocolHandler::~Server_ProtocolHandler()
|
|||
p->setProtocolHandler(0);
|
||||
}
|
||||
|
||||
QMapIterator<int, Server_Room *> roomIterator(rooms);
|
||||
while (roomIterator.hasNext())
|
||||
roomIterator.next().value()->removeClient(this);
|
||||
|
||||
delete userInfo;
|
||||
}
|
||||
|
||||
|
@ -235,7 +235,8 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd, CommandContain
|
|||
}
|
||||
}
|
||||
|
||||
return RespOk;
|
||||
cont->setResponse(new Response_Login(cont->getCmdId(), RespOk, new ServerInfo_User(userInfo, true)));
|
||||
return RespNothing;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdMessage(Command_Message *cmd, CommandContainer *cont)
|
||||
|
@ -302,6 +303,8 @@ ResponseCode Server_ProtocolHandler::cmdJoinRoom(Command_JoinRoom *cmd, CommandC
|
|||
r->addClient(this);
|
||||
rooms.insert(r->getId(), r);
|
||||
|
||||
enqueueProtocolItem(new Event_RoomSay(r->getId(), QString(), r->getJoinMessage()));
|
||||
|
||||
cont->setResponse(new Response_JoinRoom(cont->getCmdId(), RespOk, r->getInfo(true)));
|
||||
return RespNothing;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ ServerInfo_Room *Server_Room::getInfo(bool complete) const
|
|||
{
|
||||
QList<ServerInfo_Game *> gameList;
|
||||
QList<ServerInfo_User *> userList;
|
||||
qDebug() << "getInfo: complete=" << complete;
|
||||
if (complete) {
|
||||
QMapIterator<int, Server_Game *> gameIterator(games);
|
||||
while (gameIterator.hasNext())
|
||||
|
@ -79,6 +78,7 @@ Server_Game *Server_Room::createGame(const QString &description, const QString &
|
|||
broadcastGameListUpdate(newGame);
|
||||
|
||||
emit gameCreated(newGame);
|
||||
emit roomInfoChanged();
|
||||
|
||||
return newGame;
|
||||
}
|
||||
|
@ -90,4 +90,5 @@ void Server_Room::removeGame()
|
|||
games.remove(game->getGameId());
|
||||
|
||||
emit gameClosing(game->getGameId());
|
||||
emit roomInfoChanged();
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
QString getName() const { return name; }
|
||||
QString getDescription() const { return description; }
|
||||
bool getAutoJoin() const { return autoJoin; }
|
||||
QString getJoinMessage() const { return joinMessage; }
|
||||
const QMap<int, Server_Game *> &getGames() const { return games; }
|
||||
Server *getServer() const;
|
||||
ServerInfo_Room *getInfo(bool complete) const;
|
||||
|
|
Loading…
Reference in a new issue