mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Clang-format (#3028)
* 1/3 Add .clang-format file and travis compilation check * 2/3 Run clang-format * 3/3 Fix compilation problems due to include reordering * 3bis/3 AfterControlStatement: false
This commit is contained in:
parent
8dbdd24c8e
commit
b29bd9e070
272 changed files with 13378 additions and 9535 deletions
|
|
@ -1,42 +1,54 @@
|
|||
#include "server_room.h"
|
||||
#include "server_protocolhandler.h"
|
||||
#include "server_game.h"
|
||||
#include <QDebug>
|
||||
#include "server_protocolhandler.h"
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
|
||||
#include "pb/commands.pb.h"
|
||||
#include "pb/room_commands.pb.h"
|
||||
#include "pb/event_join_room.pb.h"
|
||||
#include "pb/event_leave_room.pb.h"
|
||||
#include "pb/event_list_games.pb.h"
|
||||
#include "pb/event_room_say.pb.h"
|
||||
#include "pb/serverinfo_room.pb.h"
|
||||
#include "pb/room_commands.pb.h"
|
||||
#include "pb/serverinfo_chat_message.pb.h"
|
||||
#include "pb/serverinfo_room.pb.h"
|
||||
#include <google/protobuf/descriptor.h>
|
||||
|
||||
Server_Room::Server_Room(int _id, int _chatHistorySize, const QString &_name, const QString &_description, const QString &_permissionLevel, const QString &_privilegeLevel, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent)
|
||||
: QObject(parent), id(_id), chatHistorySize(_chatHistorySize), name(_name), description(_description), permissionLevel(_permissionLevel), privilegeLevel(_privilegeLevel), autoJoin(_autoJoin), joinMessage(_joinMessage), gameTypes(_gameTypes), gamesLock(QReadWriteLock::Recursive)
|
||||
Server_Room::Server_Room(int _id,
|
||||
int _chatHistorySize,
|
||||
const QString &_name,
|
||||
const QString &_description,
|
||||
const QString &_permissionLevel,
|
||||
const QString &_privilegeLevel,
|
||||
bool _autoJoin,
|
||||
const QString &_joinMessage,
|
||||
const QStringList &_gameTypes,
|
||||
Server *parent)
|
||||
: QObject(parent), id(_id), chatHistorySize(_chatHistorySize), name(_name), description(_description),
|
||||
permissionLevel(_permissionLevel), privilegeLevel(_privilegeLevel), autoJoin(_autoJoin),
|
||||
joinMessage(_joinMessage), gameTypes(_gameTypes), gamesLock(QReadWriteLock::Recursive)
|
||||
{
|
||||
connect(this, SIGNAL(gameListChanged(ServerInfo_Game)), this, SLOT(broadcastGameListUpdate(ServerInfo_Game)), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(gameListChanged(ServerInfo_Game)), this, SLOT(broadcastGameListUpdate(ServerInfo_Game)),
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
Server_Room::~Server_Room()
|
||||
{
|
||||
qDebug("Server_Room destructor");
|
||||
|
||||
|
||||
gamesLock.lockForWrite();
|
||||
const QList<Server_Game *> gameList = games.values();
|
||||
for (int i = 0; i < gameList.size(); ++i)
|
||||
delete gameList[i];
|
||||
games.clear();
|
||||
gamesLock.unlock();
|
||||
|
||||
|
||||
usersLock.lockForWrite();
|
||||
users.clear();
|
||||
usersLock.unlock();
|
||||
}
|
||||
|
||||
bool Server_Room::userMayJoin(const ServerInfo_User & userInfo)
|
||||
bool Server_Room::userMayJoin(const ServerInfo_User &userInfo)
|
||||
{
|
||||
|
||||
if (permissionLevel.toLower() == "administrator" || permissionLevel.toLower() == "moderator")
|
||||
|
|
@ -45,15 +57,11 @@ bool Server_Room::userMayJoin(const ServerInfo_User & userInfo)
|
|||
if (permissionLevel.toLower() == "registered" && !(userInfo.user_level() & ServerInfo_User::IsRegistered))
|
||||
return false;
|
||||
|
||||
if (privilegeLevel.toLower() != "none")
|
||||
{
|
||||
if (privilegeLevel.toLower() == "privileged")
|
||||
{
|
||||
if (privilegeLevel.toLower() != "none") {
|
||||
if (privilegeLevel.toLower() == "privileged") {
|
||||
if (privilegeLevel.toLower() == "none")
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (privilegeLevel.toLower() != QString::fromStdString(userInfo.privlevel()).toLower())
|
||||
return false;
|
||||
}
|
||||
|
|
@ -66,7 +74,8 @@ Server *Server_Room::getServer() const
|
|||
return static_cast<Server *>(parent());
|
||||
}
|
||||
|
||||
const ServerInfo_Room &Server_Room::getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes, bool includeExternalData) const
|
||||
const ServerInfo_Room &
|
||||
Server_Room::getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes, bool includeExternalData) const
|
||||
{
|
||||
result.set_room_id(id);
|
||||
result.set_name(name.toStdString());
|
||||
|
|
@ -74,7 +83,7 @@ const ServerInfo_Room &Server_Room::getInfo(ServerInfo_Room &result, bool comple
|
|||
result.set_auto_join(autoJoin);
|
||||
result.set_permissionlevel(permissionLevel.toStdString());
|
||||
result.set_privilegelevel(privilegeLevel.toStdString());
|
||||
|
||||
|
||||
gamesLock.lockForRead();
|
||||
result.set_game_count(games.size() + externalGames.size());
|
||||
if (complete) {
|
||||
|
|
@ -88,7 +97,7 @@ const ServerInfo_Room &Server_Room::getInfo(ServerInfo_Room &result, bool comple
|
|||
}
|
||||
}
|
||||
gamesLock.unlock();
|
||||
|
||||
|
||||
usersLock.lockForRead();
|
||||
result.set_player_count(users.size() + externalUsers.size());
|
||||
if (complete) {
|
||||
|
|
@ -102,14 +111,14 @@ const ServerInfo_Room &Server_Room::getInfo(ServerInfo_Room &result, bool comple
|
|||
}
|
||||
}
|
||||
usersLock.unlock();
|
||||
|
||||
|
||||
if (complete || showGameTypes)
|
||||
for (int i = 0; i < gameTypes.size(); ++i) {
|
||||
ServerInfo_GameType *gameTypeInfo = result.add_gametype_list();
|
||||
gameTypeInfo->set_game_type_id(i);
|
||||
gameTypeInfo->set_description(gameTypes[i].toStdString());
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +126,9 @@ RoomEvent *Server_Room::prepareRoomEvent(const ::google::protobuf::Message &room
|
|||
{
|
||||
RoomEvent *event = new RoomEvent;
|
||||
event->set_room_id(id);
|
||||
event->GetReflection()->MutableMessage(event, roomEvent.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(roomEvent);
|
||||
event->GetReflection()
|
||||
->MutableMessage(event, roomEvent.GetDescriptor()->FindExtensionByName("ext"))
|
||||
->CopyFrom(roomEvent);
|
||||
return event;
|
||||
}
|
||||
|
||||
|
|
@ -126,21 +137,21 @@ void Server_Room::addClient(Server_ProtocolHandler *client)
|
|||
Event_JoinRoom event;
|
||||
event.mutable_user_info()->CopyFrom(client->copyUserInfo(false));
|
||||
sendRoomEvent(prepareRoomEvent(event));
|
||||
|
||||
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
|
||||
|
||||
usersLock.lockForWrite();
|
||||
users.insert(QString::fromStdString(client->getUserInfo()->name()), client);
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
|
||||
|
||||
// XXX This can be removed during the next client update.
|
||||
gamesLock.lockForRead();
|
||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
gamesLock.unlock();
|
||||
// -----------
|
||||
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
}
|
||||
|
||||
|
|
@ -148,22 +159,22 @@ void Server_Room::removeClient(Server_ProtocolHandler *client)
|
|||
{
|
||||
usersLock.lockForWrite();
|
||||
users.remove(QString::fromStdString(client->getUserInfo()->name()));
|
||||
|
||||
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
|
||||
|
||||
Event_LeaveRoom event;
|
||||
event.set_name(client->getUserInfo()->name());
|
||||
sendRoomEvent(prepareRoomEvent(event));
|
||||
|
||||
|
||||
// XXX This can be removed during the next client update.
|
||||
gamesLock.lockForRead();
|
||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
gamesLock.unlock();
|
||||
// -----------
|
||||
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
}
|
||||
|
||||
|
|
@ -174,7 +185,7 @@ void Server_Room::addExternalUser(const ServerInfo_User &userInfo)
|
|||
Event_JoinRoom event;
|
||||
event.mutable_user_info()->CopyFrom(userInfoContainer.copyUserInfo(false));
|
||||
sendRoomEvent(prepareRoomEvent(event), false);
|
||||
|
||||
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
|
||||
|
|
@ -182,7 +193,7 @@ void Server_Room::addExternalUser(const ServerInfo_User &userInfo)
|
|||
externalUsers.insert(QString::fromStdString(userInfo.name()), userInfoContainer);
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
}
|
||||
|
||||
|
|
@ -191,17 +202,17 @@ void Server_Room::removeExternalUser(const QString &name)
|
|||
// This function is always called from the Server thread with server->roomsMutex locked.
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
|
||||
|
||||
usersLock.lockForWrite();
|
||||
if (externalUsers.contains(name))
|
||||
externalUsers.remove(name);
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
|
||||
|
||||
Event_LeaveRoom event;
|
||||
event.set_name(name.toStdString());
|
||||
sendRoomEvent(prepareRoomEvent(event), false);
|
||||
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
}
|
||||
|
||||
|
|
@ -210,7 +221,7 @@ void Server_Room::updateExternalGameList(const ServerInfo_Game &gameInfo)
|
|||
// This function is always called from the Server thread with server->roomsMutex locked.
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
|
||||
|
||||
gamesLock.lockForWrite();
|
||||
if (!gameInfo.has_player_count() && externalGames.contains(gameInfo.game_id()))
|
||||
externalGames.remove(gameInfo.game_id());
|
||||
|
|
@ -218,16 +229,18 @@ void Server_Room::updateExternalGameList(const ServerInfo_Game &gameInfo)
|
|||
externalGames.insert(gameInfo.game_id(), gameInfo);
|
||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
gamesLock.unlock();
|
||||
|
||||
|
||||
broadcastGameListUpdate(gameInfo, false);
|
||||
emit roomInfoChanged(roomInfo);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// This function is called from the Server thread and from the S_PH thread.
|
||||
// server->roomsMutex is always locked.
|
||||
|
||||
|
||||
QReadLocker roomGamesLocker(&gamesLock);
|
||||
Server_Game *g = games.value(cmd.game_id());
|
||||
if (!g) {
|
||||
|
|
@ -235,31 +248,34 @@ Response::ResponseCode Server_Room::processJoinGameCommand(const Command_JoinGam
|
|||
CommandContainer cont;
|
||||
cont.set_cmd_id(rc.getCmdId());
|
||||
RoomCommand *roomCommand = cont.add_room_command();
|
||||
roomCommand->GetReflection()->MutableMessage(roomCommand, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
|
||||
getServer()->sendIsl_RoomCommand(cont, externalGames.value(cmd.game_id()).server_id(), userInterface->getUserInfo()->session_id(), id);
|
||||
|
||||
roomCommand->GetReflection()
|
||||
->MutableMessage(roomCommand, cmd.GetDescriptor()->FindExtensionByName("ext"))
|
||||
->CopyFrom(cmd);
|
||||
getServer()->sendIsl_RoomCommand(cont, externalGames.value(cmd.game_id()).server_id(),
|
||||
userInterface->getUserInfo()->session_id(), id);
|
||||
|
||||
return Response::RespNothing;
|
||||
} else
|
||||
return Response::RespNameNotFound;
|
||||
}
|
||||
|
||||
|
||||
QMutexLocker gameLocker(&g->gameMutex);
|
||||
|
||||
Response::ResponseCode result = g->checkJoin(userInterface->getUserInfo(), QString::fromStdString(cmd.password()), cmd.spectator(), cmd.override_restrictions());
|
||||
|
||||
Response::ResponseCode result = g->checkJoin(userInterface->getUserInfo(), QString::fromStdString(cmd.password()),
|
||||
cmd.spectator(), cmd.override_restrictions());
|
||||
if (result == Response::RespOk)
|
||||
g->addPlayer(userInterface, rc, cmd.spectator());
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Server_Room::say(const QString &userName, const QString &s, bool sendToIsl)
|
||||
{
|
||||
Event_RoomSay event;
|
||||
event.set_name(userName.toStdString());
|
||||
event.set_message(s.toStdString());
|
||||
sendRoomEvent(prepareRoomEvent(event), sendToIsl);
|
||||
|
||||
|
||||
if (chatHistorySize != 0) {
|
||||
ServerInfo_ChatMessage chatMessage;
|
||||
QDateTime dateTime = dateTime.currentDateTimeUtc();
|
||||
|
|
@ -275,7 +291,6 @@ void Server_Room::say(const QString &userName, const QString &s, bool sendToIsl)
|
|||
chatHistory << chatMessage;
|
||||
historyLock.unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Server_Room::sendRoomEvent(RoomEvent *event, bool sendToIsl)
|
||||
|
|
@ -287,10 +302,10 @@ void Server_Room::sendRoomEvent(RoomEvent *event, bool sendToIsl)
|
|||
userIterator.next().value()->sendProtocolItem(*event);
|
||||
}
|
||||
usersLock.unlock();
|
||||
|
||||
|
||||
if (sendToIsl)
|
||||
static_cast<Server *>(parent())->sendIsl_RoomEvent(*event);
|
||||
|
||||
|
||||
delete event;
|
||||
}
|
||||
|
||||
|
|
@ -305,10 +320,10 @@ void Server_Room::addGame(Server_Game *game)
|
|||
{
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
|
||||
|
||||
gamesLock.lockForWrite();
|
||||
connect(game, SIGNAL(gameInfoChanged(ServerInfo_Game)), this, SLOT(broadcastGameListUpdate(ServerInfo_Game)));
|
||||
|
||||
|
||||
game->gameMutex.lock();
|
||||
games.insert(game->getGameId(), game);
|
||||
ServerInfo_Game gameInfo;
|
||||
|
|
@ -316,7 +331,7 @@ void Server_Room::addGame(Server_Game *game)
|
|||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
game->gameMutex.unlock();
|
||||
gamesLock.unlock();
|
||||
|
||||
|
||||
// XXX This can be removed during the next client update.
|
||||
usersLock.lockForRead();
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
|
|
@ -331,32 +346,32 @@ void Server_Room::removeGame(Server_Game *game)
|
|||
{
|
||||
// No need to lock gamesLock or gameMutex. This method is only
|
||||
// called from ~Server_Game, which locks both mutexes anyway beforehand.
|
||||
|
||||
|
||||
disconnect(game, 0, this, 0);
|
||||
|
||||
|
||||
ServerInfo_Game gameInfo;
|
||||
game->getInfo(gameInfo);
|
||||
emit gameListChanged(gameInfo);
|
||||
|
||||
|
||||
games.remove(game->getGameId());
|
||||
|
||||
|
||||
ServerInfo_Room roomInfo;
|
||||
roomInfo.set_room_id(id);
|
||||
roomInfo.set_game_count(games.size() + externalGames.size());
|
||||
|
||||
|
||||
// XXX This can be removed during the next client update.
|
||||
usersLock.lockForRead();
|
||||
roomInfo.set_player_count(users.size() + externalUsers.size());
|
||||
usersLock.unlock();
|
||||
// -----------
|
||||
|
||||
|
||||
emit roomInfoChanged(roomInfo);
|
||||
}
|
||||
|
||||
int Server_Room::getGamesCreatedByUser(const QString &userName) const
|
||||
{
|
||||
QReadLocker locker(&gamesLock);
|
||||
|
||||
|
||||
QMapIterator<int, Server_Game *> gamesIterator(games);
|
||||
int result = 0;
|
||||
while (gamesIterator.hasNext())
|
||||
|
|
@ -368,7 +383,7 @@ int Server_Room::getGamesCreatedByUser(const QString &userName) const
|
|||
QList<ServerInfo_Game> Server_Room::getGamesOfUser(const QString &userName) const
|
||||
{
|
||||
QReadLocker locker(&gamesLock);
|
||||
|
||||
|
||||
QList<ServerInfo_Game> result;
|
||||
QMapIterator<int, Server_Game *> gamesIterator(games);
|
||||
while (gamesIterator.hasNext()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue