Skip to content
Permalink
Browse files

Allow admins to clear user avatars/textures.

  • Loading branch information...
bontibon authored and mkrautz committed Apr 12, 2014
1 parent 02ddd91 commit 52d19ac3aeb49513b592b3c5b409db0d2592d8f5
@@ -1131,11 +1131,11 @@ void MainWindow::on_qaServerTexture_triggered() {
const QImage &img = choice.second;

if ((img.height() <= 1024) && (img.width() <= 1024))
g.sh->setTexture(choice.first);
g.sh->setUserTexture(g.uiSession, choice.first);
}

void MainWindow::on_qaServerTextureRemove_triggered() {
g.sh->setTexture(QByteArray());
g.sh->setUserTexture(g.uiSession, QByteArray());
}

void MainWindow::on_qaServerTokens_triggered() {
@@ -1193,6 +1193,7 @@ void MainWindow::qmUser_aboutToShow() {
else {
qmUser->addAction(qaUserCommentView);
qmUser->addAction(qaUserCommentReset);
qmUser->addAction(qaUserTextureReset);
}

qmUser->addAction(qaUserTextMessage);
@@ -1244,6 +1245,7 @@ void MainWindow::qmUser_aboutToShow() {
qaUserLocalMute->setEnabled(false);
qaUserLocalIgnore->setEnabled(false);
qaUserCommentReset->setEnabled(false);
qaUserTextureReset->setEnabled(false);
qaUserCommentView->setEnabled(false);
} else {
qaUserKick->setEnabled(! self);
@@ -1252,6 +1254,7 @@ void MainWindow::qmUser_aboutToShow() {
qaUserLocalMute->setEnabled(! self);
qaUserLocalIgnore->setEnabled(! self);
qaUserCommentReset->setEnabled(! p->qbaCommentHash.isEmpty() && (g.pPermissions & (ChanACL::Move | ChanACL::Write)));
qaUserTextureReset->setEnabled(! p->qbaTextureHash.isEmpty() && (g.pPermissions & (ChanACL::Move | ChanACL::Write)));
qaUserCommentView->setEnabled(! p->qbaCommentHash.isEmpty());

qaUserMute->setChecked(p->bMute || p->bSuppress);
@@ -1493,6 +1496,22 @@ void MainWindow::on_qaUserCommentReset_triggered() {
}
}

void MainWindow::on_qaUserTextureReset_triggered() {
ClientUser *p = getContextMenuUser();

if (!p)
return;

unsigned int session = p->uiSession;

int ret = QMessageBox::question(this, QLatin1String("Mumble"),
tr("Are you sure you want to reset the avatar of user %1?").arg(Qt::escape(p->qsName)),
QMessageBox::Yes, QMessageBox::No);
if (ret == QMessageBox::Yes) {
g.sh->setUserTexture(session, QByteArray());
}
}

void MainWindow::on_qaUserInformation_triggered() {
ClientUser *p = getContextMenuUser();

@@ -187,6 +187,7 @@ class MainWindow : public QMainWindow, public MessageHandler, public Ui::MainWin
void on_qaSelfRegister_triggered();
void qmUser_aboutToShow();
void on_qaUserCommentReset_triggered();
void on_qaUserTextureReset_triggered();
void on_qaUserCommentView_triggered();
void on_qaUserKick_triggered();
void on_qaUserBan_triggered();
@@ -788,6 +788,14 @@ the channel's context menu.</string>
<string>Reset the comment of the selected user.</string>
</property>
</action>
<action name="qaUserTextureReset">
<property name="text">
<string>Reset &amp;Avatar</string>
</property>
<property name="toolTip">
<string>Reset the avatar of the selected user.</string>
</property>
</action>
<action name="qaChannelJoin">
<property name="text">
<string>&amp;Join Channel</string>
@@ -680,49 +680,6 @@ void ServerHandler::createChannel(unsigned int parent_, const QString &name, con
sendMessage(mpcs);
}

void ServerHandler::setTexture(const QByteArray &qba) {
QByteArray texture;
if ((uiVersion >= 0x010202) || qba.isEmpty()) {
texture = qba;
} else {
QByteArray raw = qba;
QBuffer qb(& raw);
qb.open(QIODevice::ReadOnly);
QImageReader qir;
if (qba.startsWith("<?xml"))
qir.setFormat("svg");
qir.setDevice(&qb);

QSize sz = qir.size();
sz.scale(600, 60, Qt::KeepAspectRatio);
qir.setScaledSize(sz);

QImage tex = qir.read();

if (tex.isNull())
return;

qWarning() << tex.width() << tex.height();

raw = QByteArray(600*60*4, 0);
QImage img(reinterpret_cast<unsigned char *>(raw.data()), 600, 60, QImage::Format_ARGB32);

QPainter imgp(&img);
imgp.setRenderHint(QPainter::Antialiasing);
imgp.setRenderHint(QPainter::TextAntialiasing);
imgp.setCompositionMode(QPainter::CompositionMode_SourceOver);
imgp.drawImage(0, 0, tex);

texture = qCompress(QByteArray(reinterpret_cast<const char *>(img.bits()), 600*60*4));
}
MumbleProto::UserState mpus;
mpus.set_texture(blob(texture));
sendMessage(mpus);

if (! texture.isEmpty())
Database::setBlob(sha1(texture), texture);
}

void ServerHandler::requestBanList() {
MumbleProto::BanList mpbl;
mpbl.set_query(true);
@@ -783,6 +740,52 @@ void ServerHandler::setUserComment(unsigned int uiSession, const QString &commen
sendMessage(mpus);
}

void ServerHandler::setUserTexture(unsigned int uiSession, const QByteArray &qba) {
QByteArray texture;

if ((uiVersion >= 0x010202) || qba.isEmpty()) {
texture = qba;
} else {
QByteArray raw = qba;
QBuffer qb(& raw);
qb.open(QIODevice::ReadOnly);
QImageReader qir;
if (qba.startsWith("<?xml")) {
qir.setFormat("svg");
}
qir.setDevice(&qb);

QSize sz = qir.size();
sz.scale(600, 60, Qt::KeepAspectRatio);
qir.setScaledSize(sz);

QImage tex = qir.read();
if (tex.isNull()) {
return;
}

raw = QByteArray(600*60*4, 0);
QImage img(reinterpret_cast<unsigned char *>(raw.data()), 600, 60, QImage::Format_ARGB32);

QPainter imgp(&img);
imgp.setRenderHint(QPainter::Antialiasing);
imgp.setRenderHint(QPainter::TextAntialiasing);
imgp.setCompositionMode(QPainter::CompositionMode_SourceOver);
imgp.drawImage(0, 0, tex);

texture = qCompress(QByteArray(reinterpret_cast<const char *>(img.bits()), 600*60*4));
}

MumbleProto::UserState mpus;
mpus.set_session(uiSession);
mpus.set_texture(blob(texture));
sendMessage(mpus);

if (! texture.isEmpty()) {
Database::setBlob(sha1(texture), texture);
}
}

void ServerHandler::removeChannel(unsigned int channel) {
MumbleProto::ChannelRemove mpcr;
mpcr.set_channel_id(channel);
@@ -130,7 +130,6 @@ class ServerHandler : public QThread {
void requestUserStats(unsigned int uiSession, bool statsOnly);
void joinChannel(unsigned int channel);
void createChannel(unsigned int parent_, const QString &name, const QString &description, unsigned int position, bool temporary);
void setTexture(const QByteArray &qba);
void requestBanList();
void requestUserList();
void requestACL(unsigned int channel);
@@ -139,6 +138,7 @@ class ServerHandler : public QThread {
void sendUserTextMessage(unsigned int uiSession, const QString &message_);
void sendChannelTextMessage(unsigned int channel, const QString &message_, bool tree);
void setUserComment(unsigned int uiSession, const QString &comment);
void setUserTexture(unsigned int uiSession, const QByteArray &qba);
void removeChannel(unsigned int channel);
void addChannelLink(unsigned int channel, unsigned int link);
void removeChannelLink(unsigned int channel, unsigned int link);
@@ -562,6 +562,16 @@ void Server::msgUserState(ServerUser *uSource, MumbleProto::UserState &msg) {
PERM_DENIED_TYPE(TextTooLong);
return;
}
if (uSource != pDstServerUser) {
if (! hasPermission(uSource, root, ChanACL::Move)) {
PERM_DENIED(uSource, root, ChanACL::Move);
return;
}
if (msg.texture().length() > 0) {
PERM_DENIED_TYPE(TextTooLong);
return;
}
}
}


@@ -578,8 +588,9 @@ void Server::msgUserState(ServerUser *uSource, MumbleProto::UserState &msg) {
}

// Prevent self-targeting state changes from being applied to others
if ((pDstServerUser != uSource) && (msg.has_self_deaf() || msg.has_self_mute() || msg.has_texture() || msg.has_plugin_context() || msg.has_plugin_identity() || msg.has_recording()))
if ((pDstServerUser != uSource) && (msg.has_self_deaf() || msg.has_self_mute() || msg.has_plugin_context() || msg.has_plugin_identity() || msg.has_recording())) {
return;
}

/*
-------------------- Permission checks done. Now act --------------------
@@ -588,13 +599,14 @@ void Server::msgUserState(ServerUser *uSource, MumbleProto::UserState &msg) {

if (msg.has_texture()) {
QByteArray qba = blob(msg.texture());
if (uSource->iId > 0) {
if (pDstServerUser->iId > 0) {
// For registered users store the texture we just received in the database
if (! setTexture(uSource->iId, qba))
if (! setTexture(pDstServerUser->iId, qba)) {
return;
}
} else {
// For unregistered users or SuperUser only get the hash
hashAssign(uSource->qbaTexture, uSource->qbaTextureHash, qba);
hashAssign(pDstServerUser->qbaTexture, pDstServerUser->qbaTextureHash, qba);
}

// The texture will be sent out later in this function

0 comments on commit 52d19ac

Please sign in to comment.
You can’t perform that action at this time.