fixed game list update bug, minor optimizations, restrict client protocol output to QT_DEBUG mode
This commit is contained in:
parent
118b575e58
commit
ae19d3dc4b
13 changed files with 75 additions and 50 deletions
|
@ -25,7 +25,6 @@ AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, int _id
|
||||||
|
|
||||||
AbstractCardItem::~AbstractCardItem()
|
AbstractCardItem::~AbstractCardItem()
|
||||||
{
|
{
|
||||||
qDebug() << "AbstractCardItem destructor:" << name;
|
|
||||||
emit deleteCardInfoPopup(name);
|
emit deleteCardInfoPopup(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,8 @@ void DlgCreateGame::sharedCtor()
|
||||||
|
|
||||||
onlyBuddiesCheckBox = new QCheckBox(tr("Only &buddies can join"));
|
onlyBuddiesCheckBox = new QCheckBox(tr("Only &buddies can join"));
|
||||||
onlyRegisteredCheckBox = new QCheckBox(tr("Only ®istered users can join"));
|
onlyRegisteredCheckBox = new QCheckBox(tr("Only ®istered users can join"));
|
||||||
onlyRegisteredCheckBox->setChecked(true);
|
if (room && room->getUserInfo()->user_level() & ServerInfo_User::IsRegistered)
|
||||||
|
onlyRegisteredCheckBox->setChecked(true);
|
||||||
|
|
||||||
QGridLayout *joinRestrictionsLayout = new QGridLayout;
|
QGridLayout *joinRestrictionsLayout = new QGridLayout;
|
||||||
joinRestrictionsLayout->addWidget(passwordLabel, 0, 0);
|
joinRestrictionsLayout->addWidget(passwordLabel, 0, 0);
|
||||||
|
|
|
@ -61,12 +61,17 @@ DlgFilterGames::DlgFilterGames(const QMap<int, QString> &allGameTypes, QWidget *
|
||||||
QGroupBox *maxPlayersGroupBox = new QGroupBox(tr("Maximum player count"));
|
QGroupBox *maxPlayersGroupBox = new QGroupBox(tr("Maximum player count"));
|
||||||
maxPlayersGroupBox->setLayout(maxPlayersFilterLayout);
|
maxPlayersGroupBox->setLayout(maxPlayersFilterLayout);
|
||||||
|
|
||||||
QGridLayout *leftColumn = new QGridLayout;
|
QGridLayout *leftGrid = new QGridLayout;
|
||||||
leftColumn->addWidget(gameNameFilterLabel, 0, 0);
|
leftGrid->addWidget(gameNameFilterLabel, 0, 0);
|
||||||
leftColumn->addWidget(gameNameFilterEdit, 0, 1);
|
leftGrid->addWidget(gameNameFilterEdit, 0, 1);
|
||||||
leftColumn->addWidget(creatorNameFilterLabel, 1, 0);
|
leftGrid->addWidget(creatorNameFilterLabel, 1, 0);
|
||||||
leftColumn->addWidget(creatorNameFilterEdit, 1, 1);
|
leftGrid->addWidget(creatorNameFilterEdit, 1, 1);
|
||||||
leftColumn->addWidget(maxPlayersGroupBox, 2, 0, 1, 2);
|
leftGrid->addWidget(maxPlayersGroupBox, 2, 0, 1, 2);
|
||||||
|
leftGrid->addWidget(unavailableGamesVisibleCheckBox, 3, 0, 1, 2);
|
||||||
|
|
||||||
|
QVBoxLayout *leftColumn = new QVBoxLayout;
|
||||||
|
leftColumn->addLayout(leftGrid);
|
||||||
|
leftColumn->addStretch();
|
||||||
|
|
||||||
QVBoxLayout *rightColumn = new QVBoxLayout;
|
QVBoxLayout *rightColumn = new QVBoxLayout;
|
||||||
rightColumn->addWidget(gameTypeFilterGroupBox);
|
rightColumn->addWidget(gameTypeFilterGroupBox);
|
||||||
|
|
|
@ -7,15 +7,6 @@ GamesModel::GamesModel(const QMap<int, QString> &_rooms, const QMap<int, GameTyp
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GamesModel::~GamesModel()
|
|
||||||
{
|
|
||||||
if (!gameList.isEmpty()) {
|
|
||||||
beginRemoveRows(QModelIndex(), 0, gameList.size() - 1);
|
|
||||||
gameList.clear();
|
|
||||||
endRemoveRows();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant GamesModel::data(const QModelIndex &index, int role) const
|
QVariant GamesModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
|
@ -81,12 +72,12 @@ void GamesModel::updateGameList(const ServerInfo_Game &game)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < gameList.size(); i++)
|
for (int i = 0; i < gameList.size(); i++)
|
||||||
if (gameList[i].game_id() == game.game_id()) {
|
if (gameList[i].game_id() == game.game_id()) {
|
||||||
if (!game.has_player_count()) {
|
if (game.closed()) {
|
||||||
beginRemoveRows(QModelIndex(), i, i);
|
beginRemoveRows(QModelIndex(), i, i);
|
||||||
gameList.removeAt(i);
|
gameList.removeAt(i);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
} else {
|
} else {
|
||||||
gameList[i] = game;
|
gameList[i].MergeFrom(game);
|
||||||
emit dataChanged(index(i, 0), index(i, 7));
|
emit dataChanged(index(i, 0), index(i, 7));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -107,9 +98,10 @@ GamesProxyModel::GamesProxyModel(QObject *parent, ServerInfo_User *_ownUser)
|
||||||
{
|
{
|
||||||
setDynamicSortFilter(true);
|
setDynamicSortFilter(true);
|
||||||
}
|
}
|
||||||
|
#include <QDebug>
|
||||||
void GamesProxyModel::setUnavailableGamesVisible(bool _unavailableGamesVisible)
|
void GamesProxyModel::setUnavailableGamesVisible(bool _unavailableGamesVisible)
|
||||||
{
|
{
|
||||||
|
qDebug() << "setting to" << _unavailableGamesVisible;
|
||||||
unavailableGamesVisible = _unavailableGamesVisible;
|
unavailableGamesVisible = _unavailableGamesVisible;
|
||||||
invalidateFilter();
|
invalidateFilter();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include "gametypemap.h"
|
#include "gametypemap.h"
|
||||||
|
#include "pb/serverinfo_game.pb.h"
|
||||||
|
|
||||||
class ServerInfo_Game;
|
|
||||||
class ServerInfo_User;
|
class ServerInfo_User;
|
||||||
|
|
||||||
class GamesModel : public QAbstractTableModel {
|
class GamesModel : public QAbstractTableModel {
|
||||||
|
@ -18,7 +18,6 @@ private:
|
||||||
QMap<int, GameTypeMap> gameTypes;
|
QMap<int, GameTypeMap> gameTypes;
|
||||||
public:
|
public:
|
||||||
GamesModel(const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QObject *parent = 0);
|
GamesModel(const QMap<int, QString> &_rooms, const QMap<int, GameTypeMap> &_gameTypes, QObject *parent = 0);
|
||||||
~GamesModel();
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const { return parent.isValid() ? 0 : gameList.size(); }
|
int rowCount(const QModelIndex &parent = QModelIndex()) const { return parent.isValid() ? 0 : gameList.size(); }
|
||||||
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 8; }
|
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 8; }
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
|
|
|
@ -118,7 +118,9 @@ void RemoteClient::readData()
|
||||||
|
|
||||||
ServerMessage newServerMessage;
|
ServerMessage newServerMessage;
|
||||||
newServerMessage.ParseFromArray(inputBuffer.data(), messageLength);
|
newServerMessage.ParseFromArray(inputBuffer.data(), messageLength);
|
||||||
qDebug(("IN " + QString::number(messageLength) + ": " + QString::fromStdString(newServerMessage.DebugString())).toUtf8());
|
#ifdef QT_DEBUG
|
||||||
|
qDebug(("IN " + QString::number(messageLength) + ": " + QString::fromStdString(newServerMessage.ShortDebugString())).toUtf8());
|
||||||
|
#endif
|
||||||
inputBuffer.remove(0, messageLength);
|
inputBuffer.remove(0, messageLength);
|
||||||
messageInProgress = false;
|
messageInProgress = false;
|
||||||
|
|
||||||
|
@ -133,7 +135,9 @@ void RemoteClient::sendCommandContainer(const CommandContainer &cont)
|
||||||
{
|
{
|
||||||
QByteArray buf;
|
QByteArray buf;
|
||||||
unsigned int size = cont.ByteSize();
|
unsigned int size = cont.ByteSize();
|
||||||
qDebug(("OUT " + QString::number(size) + ": " + QString::fromStdString(cont.DebugString())).toUtf8());
|
#ifdef QT_DEBUG
|
||||||
|
qDebug(("OUT " + QString::number(size) + ": " + QString::fromStdString(cont.ShortDebugString())).toUtf8());
|
||||||
|
#endif
|
||||||
buf.resize(size + 4);
|
buf.resize(size + 4);
|
||||||
cont.SerializeToArray(buf.data() + 4, size);
|
cont.SerializeToArray(buf.data() + 4, size);
|
||||||
buf.data()[3] = (unsigned char) size;
|
buf.data()[3] = (unsigned char) size;
|
||||||
|
|
|
@ -68,6 +68,7 @@ public:
|
||||||
const QMap<int, QString> &getGameTypes() const { return gameTypes; }
|
const QMap<int, QString> &getGameTypes() const { return gameTypes; }
|
||||||
QString getChannelName() const { return roomName; }
|
QString getChannelName() const { return roomName; }
|
||||||
QString getTabText() const { return roomName; }
|
QString getTabText() const { return roomName; }
|
||||||
|
const ServerInfo_User *getUserInfo() const { return ownUser; }
|
||||||
|
|
||||||
PendingCommand *prepareRoomCommand(const ::google::protobuf::Message &cmd);
|
PendingCommand *prepareRoomCommand(const ::google::protobuf::Message &cmd);
|
||||||
void sendRoomCommand(PendingCommand *pend);
|
void sendRoomCommand(PendingCommand *pend);
|
||||||
|
|
|
@ -19,4 +19,5 @@ message ServerInfo_Game {
|
||||||
optional uint32 spectators_count = 31;
|
optional uint32 spectators_count = 31;
|
||||||
optional bool started = 50;
|
optional bool started = 50;
|
||||||
optional uint32 start_time = 51;
|
optional uint32 start_time = 51;
|
||||||
|
optional bool closed = 52;
|
||||||
}
|
}
|
||||||
|
|
|
@ -294,7 +294,9 @@ void Server_Game::doStartGameIfReady()
|
||||||
locker.unlock();
|
locker.unlock();
|
||||||
|
|
||||||
ServerInfo_Game gameInfo;
|
ServerInfo_Game gameInfo;
|
||||||
getInfo(gameInfo);
|
gameInfo.set_room_id(room->getId());
|
||||||
|
gameInfo.set_game_id(gameId);
|
||||||
|
gameInfo.set_started(true);
|
||||||
emit gameInfoChanged(gameInfo);
|
emit gameInfoChanged(gameInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,6 +329,14 @@ void Server_Game::stopGameIfFinished()
|
||||||
}
|
}
|
||||||
|
|
||||||
sendGameStateToPlayers();
|
sendGameStateToPlayers();
|
||||||
|
|
||||||
|
locker.unlock();
|
||||||
|
|
||||||
|
ServerInfo_Game gameInfo;
|
||||||
|
gameInfo.set_room_id(room->getId());
|
||||||
|
gameInfo.set_game_id(gameId);
|
||||||
|
gameInfo.set_started(false);
|
||||||
|
emit gameInfoChanged(gameInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
Response::ResponseCode Server_Game::checkJoin(ServerInfo_User *user, const QString &_password, bool spectator, bool overrideRestrictions)
|
Response::ResponseCode Server_Game::checkJoin(ServerInfo_User *user, const QString &_password, bool spectator, bool overrideRestrictions)
|
||||||
|
@ -393,7 +403,9 @@ void Server_Game::addPlayer(Server_AbstractUserInterface *userInterface, Respons
|
||||||
|
|
||||||
if (broadcastUpdate) {
|
if (broadcastUpdate) {
|
||||||
ServerInfo_Game gameInfo;
|
ServerInfo_Game gameInfo;
|
||||||
getInfo(gameInfo);
|
gameInfo.set_room_id(room->getId());
|
||||||
|
gameInfo.set_game_id(gameId);
|
||||||
|
gameInfo.set_player_count(getPlayerCount());
|
||||||
emit gameInfoChanged(gameInfo);
|
emit gameInfoChanged(gameInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,9 +433,10 @@ void Server_Game::removePlayer(Server_Player *player)
|
||||||
bool spectator = player->getSpectator();
|
bool spectator = player->getSpectator();
|
||||||
player->prepareDestroy();
|
player->prepareDestroy();
|
||||||
|
|
||||||
if (!getPlayerCount())
|
if (!getPlayerCount()) {
|
||||||
deleteLater();
|
deleteLater();
|
||||||
else if (!spectator) {
|
return;
|
||||||
|
} else if (!spectator) {
|
||||||
if (playerHost) {
|
if (playerHost) {
|
||||||
int newHostId = -1;
|
int newHostId = -1;
|
||||||
QMapIterator<int, Server_Player *> playerIterator(players);
|
QMapIterator<int, Server_Player *> playerIterator(players);
|
||||||
|
@ -445,7 +458,9 @@ void Server_Game::removePlayer(Server_Player *player)
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo_Game gameInfo;
|
ServerInfo_Game gameInfo;
|
||||||
getInfo(gameInfo);
|
gameInfo.set_room_id(room->getId());
|
||||||
|
gameInfo.set_game_id(gameId);
|
||||||
|
gameInfo.set_player_count(getPlayerCount());
|
||||||
emit gameInfoChanged(gameInfo);
|
emit gameInfoChanged(gameInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -645,8 +660,10 @@ void Server_Game::getInfo(ServerInfo_Game &result) const
|
||||||
QMutexLocker locker(&gameMutex);
|
QMutexLocker locker(&gameMutex);
|
||||||
|
|
||||||
result.set_room_id(room->getId());
|
result.set_room_id(room->getId());
|
||||||
result.set_game_id(getGameId());
|
result.set_game_id(gameId);
|
||||||
if (!players.isEmpty()) {
|
if (players.isEmpty())
|
||||||
|
result.set_closed(true);
|
||||||
|
else {
|
||||||
for (int i = 0; i < gameTypes.size(); ++i)
|
for (int i = 0; i < gameTypes.size(); ++i)
|
||||||
result.add_game_types(gameTypes[i]);
|
result.add_game_types(gameTypes[i]);
|
||||||
|
|
||||||
|
|
|
@ -422,7 +422,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdGetGamesOfUser(const Command_G
|
||||||
while (roomIterator.hasNext()) {
|
while (roomIterator.hasNext()) {
|
||||||
Server_Room *room = roomIterator.next().value();
|
Server_Room *room = roomIterator.next().value();
|
||||||
room->gamesMutex.lock();
|
room->gamesMutex.lock();
|
||||||
re->add_room_list()->CopyFrom(room->getInfo(false, true));
|
room->getInfo(*re->add_room_list(), false, true);
|
||||||
QListIterator<ServerInfo_Game> gameIterator(room->getGamesOfUser(QString::fromStdString(cmd.user_name())));
|
QListIterator<ServerInfo_Game> gameIterator(room->getGamesOfUser(QString::fromStdString(cmd.user_name())));
|
||||||
while (gameIterator.hasNext())
|
while (gameIterator.hasNext())
|
||||||
re->add_game_list()->CopyFrom(gameIterator.next());
|
re->add_game_list()->CopyFrom(gameIterator.next());
|
||||||
|
@ -470,7 +470,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdListRooms(const Command_ListRo
|
||||||
Event_ListRooms event;
|
Event_ListRooms event;
|
||||||
QMapIterator<int, Server_Room *> roomIterator(server->getRooms());
|
QMapIterator<int, Server_Room *> roomIterator(server->getRooms());
|
||||||
while (roomIterator.hasNext())
|
while (roomIterator.hasNext())
|
||||||
event.add_room_list()->CopyFrom(roomIterator.next().value()->getInfo(false));
|
roomIterator.next().value()->getInfo(*event.add_room_list(), false);
|
||||||
rc.enqueuePreResponseItem(ServerMessage::SESSION_EVENT, prepareSessionEvent(event));
|
rc.enqueuePreResponseItem(ServerMessage::SESSION_EVENT, prepareSessionEvent(event));
|
||||||
|
|
||||||
acceptsRoomListChanges = true;
|
acceptsRoomListChanges = true;
|
||||||
|
@ -498,7 +498,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdJoinRoom(const Command_JoinRoo
|
||||||
rc.enqueuePostResponseItem(ServerMessage::ROOM_EVENT, r->prepareRoomEvent(joinMessageEvent));
|
rc.enqueuePostResponseItem(ServerMessage::ROOM_EVENT, r->prepareRoomEvent(joinMessageEvent));
|
||||||
|
|
||||||
Response_JoinRoom *re = new Response_JoinRoom;
|
Response_JoinRoom *re = new Response_JoinRoom;
|
||||||
re->mutable_room_info()->CopyFrom(r->getInfo(true));
|
r->getInfo(*re->mutable_room_info(), true);
|
||||||
|
|
||||||
rc.setResponseExtension(re);
|
rc.setResponseExtension(re);
|
||||||
return Response::RespOk;
|
return Response::RespOk;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "pb/event_leave_room.pb.h"
|
#include "pb/event_leave_room.pb.h"
|
||||||
#include "pb/event_list_games.pb.h"
|
#include "pb/event_list_games.pb.h"
|
||||||
#include "pb/event_room_say.pb.h"
|
#include "pb/event_room_say.pb.h"
|
||||||
|
#include "pb/serverinfo_room.pb.h"
|
||||||
#include <google/protobuf/descriptor.h>
|
#include <google/protobuf/descriptor.h>
|
||||||
|
|
||||||
Server_Room::Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent)
|
Server_Room::Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent)
|
||||||
|
@ -38,9 +39,8 @@ Server *Server_Room::getServer() const
|
||||||
return static_cast<Server *>(parent());
|
return static_cast<Server *>(parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfo_Room Server_Room::getInfo(bool complete, bool showGameTypes, bool updating, bool includeExternalData) const
|
const ServerInfo_Room &Server_Room::getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes, bool updating, bool includeExternalData) const
|
||||||
{
|
{
|
||||||
ServerInfo_Room result;
|
|
||||||
result.set_room_id(id);
|
result.set_room_id(id);
|
||||||
|
|
||||||
if (!updating) {
|
if (!updating) {
|
||||||
|
@ -104,7 +104,8 @@ void Server_Room::addClient(Server_ProtocolHandler *client)
|
||||||
userList.append(client);
|
userList.append(client);
|
||||||
usersLock.unlock();
|
usersLock.unlock();
|
||||||
|
|
||||||
emit roomInfoChanged(getInfo(false, false, true));
|
ServerInfo_Room roomInfo;
|
||||||
|
emit roomInfoChanged(getInfo(roomInfo, false, false, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::removeClient(Server_ProtocolHandler *client)
|
void Server_Room::removeClient(Server_ProtocolHandler *client)
|
||||||
|
@ -117,7 +118,8 @@ void Server_Room::removeClient(Server_ProtocolHandler *client)
|
||||||
event.set_name(client->getUserInfo()->name());
|
event.set_name(client->getUserInfo()->name());
|
||||||
sendRoomEvent(prepareRoomEvent(event));
|
sendRoomEvent(prepareRoomEvent(event));
|
||||||
|
|
||||||
emit roomInfoChanged(getInfo(false, false, true));
|
ServerInfo_Room roomInfo;
|
||||||
|
emit roomInfoChanged(getInfo(roomInfo, false, false, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::addExternalUser(const ServerInfo_User &userInfo)
|
void Server_Room::addExternalUser(const ServerInfo_User &userInfo)
|
||||||
|
@ -132,7 +134,8 @@ void Server_Room::addExternalUser(const ServerInfo_User &userInfo)
|
||||||
externalUsers.insert(QString::fromStdString(userInfo.name()), userInfoContainer);
|
externalUsers.insert(QString::fromStdString(userInfo.name()), userInfoContainer);
|
||||||
usersLock.unlock();
|
usersLock.unlock();
|
||||||
|
|
||||||
emit roomInfoChanged(getInfo(false, false, true));
|
ServerInfo_Room roomInfo;
|
||||||
|
emit roomInfoChanged(getInfo(roomInfo, false, false, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::removeExternalUser(const QString &name)
|
void Server_Room::removeExternalUser(const QString &name)
|
||||||
|
@ -147,7 +150,8 @@ void Server_Room::removeExternalUser(const QString &name)
|
||||||
event.set_name(name.toStdString());
|
event.set_name(name.toStdString());
|
||||||
sendRoomEvent(prepareRoomEvent(event), false);
|
sendRoomEvent(prepareRoomEvent(event), false);
|
||||||
|
|
||||||
emit roomInfoChanged(getInfo(false, false, true));
|
ServerInfo_Room roomInfo;
|
||||||
|
emit roomInfoChanged(getInfo(roomInfo, false, false, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::updateExternalGameList(const ServerInfo_Game &gameInfo)
|
void Server_Room::updateExternalGameList(const ServerInfo_Game &gameInfo)
|
||||||
|
@ -161,7 +165,8 @@ void Server_Room::updateExternalGameList(const ServerInfo_Game &gameInfo)
|
||||||
gamesMutex.unlock();
|
gamesMutex.unlock();
|
||||||
|
|
||||||
broadcastGameListUpdate(gameInfo, false);
|
broadcastGameListUpdate(gameInfo, false);
|
||||||
emit roomInfoChanged(getInfo(false, false, true));
|
ServerInfo_Room roomInfo;
|
||||||
|
emit roomInfoChanged(getInfo(roomInfo, false, false, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
Response::ResponseCode Server_Room::processJoinGameCommand(const Command_JoinGame &cmd, ResponseContainer &rc, Server_AbstractUserInterface *userInterface)
|
Response::ResponseCode Server_Room::processJoinGameCommand(const Command_JoinGame &cmd, ResponseContainer &rc, Server_AbstractUserInterface *userInterface)
|
||||||
|
@ -215,7 +220,7 @@ void Server_Room::sendRoomEvent(RoomEvent *event, bool sendToIsl)
|
||||||
delete event;
|
delete event;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::broadcastGameListUpdate(ServerInfo_Game gameInfo, bool sendToIsl)
|
void Server_Room::broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool sendToIsl)
|
||||||
{
|
{
|
||||||
Event_ListGames event;
|
Event_ListGames event;
|
||||||
event.add_game_list()->CopyFrom(gameInfo);
|
event.add_game_list()->CopyFrom(gameInfo);
|
||||||
|
@ -236,7 +241,8 @@ void Server_Room::addGame(Server_Game *game)
|
||||||
game->gameMutex.unlock();
|
game->gameMutex.unlock();
|
||||||
|
|
||||||
emit gameListChanged(gameInfo);
|
emit gameListChanged(gameInfo);
|
||||||
emit roomInfoChanged(getInfo(false, false, true));
|
ServerInfo_Room roomInfo;
|
||||||
|
emit roomInfoChanged(getInfo(roomInfo, false, false, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Room::removeGame(Server_Game *game)
|
void Server_Room::removeGame(Server_Game *game)
|
||||||
|
@ -252,7 +258,8 @@ void Server_Room::removeGame(Server_Game *game)
|
||||||
|
|
||||||
games.remove(game->getGameId());
|
games.remove(game->getGameId());
|
||||||
|
|
||||||
emit roomInfoChanged(getInfo(false, false, true));
|
ServerInfo_Room roomInfo;
|
||||||
|
emit roomInfoChanged(getInfo(roomInfo, false, false, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
int Server_Room::getGamesCreatedByUser(const QString &userName) const
|
int Server_Room::getGamesCreatedByUser(const QString &userName) const
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QReadWriteLock>
|
#include <QReadWriteLock>
|
||||||
#include "serverinfo_user_container.h"
|
#include "serverinfo_user_container.h"
|
||||||
#include "pb/serverinfo_room.pb.h"
|
|
||||||
#include "pb/response.pb.h"
|
#include "pb/response.pb.h"
|
||||||
|
|
||||||
class Server_ProtocolHandler;
|
class Server_ProtocolHandler;
|
||||||
|
@ -26,8 +25,8 @@ class Server_AbstractUserInterface;
|
||||||
class Server_Room : public QObject {
|
class Server_Room : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void roomInfoChanged(ServerInfo_Room roomInfo);
|
void roomInfoChanged(const ServerInfo_Room &roomInfo);
|
||||||
void gameListChanged(ServerInfo_Game gameInfo);
|
void gameListChanged(const ServerInfo_Game &gameInfo);
|
||||||
private:
|
private:
|
||||||
int id;
|
int id;
|
||||||
QString name;
|
QString name;
|
||||||
|
@ -40,7 +39,7 @@ private:
|
||||||
QList<Server_ProtocolHandler *> userList;
|
QList<Server_ProtocolHandler *> userList;
|
||||||
QMap<QString, ServerInfo_User_Container> externalUsers;
|
QMap<QString, ServerInfo_User_Container> externalUsers;
|
||||||
private slots:
|
private slots:
|
||||||
void broadcastGameListUpdate(ServerInfo_Game gameInfo, bool sendToIsl = true);
|
void broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool sendToIsl = true);
|
||||||
public:
|
public:
|
||||||
mutable QReadWriteLock usersLock;
|
mutable QReadWriteLock usersLock;
|
||||||
mutable QMutex gamesMutex;
|
mutable QMutex gamesMutex;
|
||||||
|
@ -55,7 +54,7 @@ public:
|
||||||
const QMap<int, Server_Game *> &getGames() const { return games; }
|
const QMap<int, Server_Game *> &getGames() const { return games; }
|
||||||
const QMap<int, ServerInfo_Game> &getExternalGames() const { return externalGames; }
|
const QMap<int, ServerInfo_Game> &getExternalGames() const { return externalGames; }
|
||||||
Server *getServer() const;
|
Server *getServer() const;
|
||||||
ServerInfo_Room getInfo(bool complete, bool showGameTypes = false, bool updating = false, bool includeExternalData = true) const;
|
const ServerInfo_Room &getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes = false, bool updating = false, bool includeExternalData = true) const;
|
||||||
int getGamesCreatedByUser(const QString &name) const;
|
int getGamesCreatedByUser(const QString &name) const;
|
||||||
QList<ServerInfo_Game> getGamesOfUser(const QString &name) const;
|
QList<ServerInfo_Game> getGamesOfUser(const QString &name) const;
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ void IslInterface::initServer()
|
||||||
Server_Room *room = roomIterator.next().value();
|
Server_Room *room = roomIterator.next().value();
|
||||||
room->usersLock.lockForRead();
|
room->usersLock.lockForRead();
|
||||||
room->gamesMutex.lock();
|
room->gamesMutex.lock();
|
||||||
event.add_room_list()->CopyFrom(room->getInfo(true, true, false, false));
|
room->getInfo(*event.add_room_list(), true, true, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
IslMessage message;
|
IslMessage message;
|
||||||
|
|
Loading…
Reference in a new issue