Skip to content
Permalink
Browse files

Merge PR #2144: Ban logging verbosity

  • Loading branch information...
mkrautz committed May 18, 2016
2 parents ec87aa6 + 5d1a56e commit c522cff0dcd079e7171cedb94b0e6d2534d0dd1f
Showing with 33 additions and 1 deletion.
  1. +17 −0 src/Net.cpp
  2. +3 −0 src/Net.h
  3. +13 −1 src/murmur/Messages.cpp
@@ -162,3 +162,20 @@ bool Ban::operator ==(const Ban &other) const {
bool Ban::isValid() const {
return haAddress.isValid() && (iMask >= 8) && (iMask <= 128);
}

QString Ban::toString() const {
return QString(QLatin1String("Hash: \"%1\", Host: \"%2\", Mask: \"%3\", Username: \"%4\", Reason: \"%5\", BanStart: \"%6\", BanEnd: \"%7\" %8")).arg(
qsHash,
haAddress.toString(),
haAddress.isV6() ? QString::number(iMask) : QString::number(iMask-96),
qsUsername,
qsReason,
qdtStart.toLocalTime().toString("yyyy-MM-dd hh:mm:ss"),
qdtStart.toLocalTime().addSecs(iDuration).toString("yyyy-MM-dd hh:mm:ss"),
iDuration == 0 ? "(permanent)" : "(temporary)"
);
}

quint32 qHash(const Ban &b) {
return qHash(b.qsHash) ^ qHash(b.haAddress) ^ qHash(b.qsUsername) ^ qHash(b.iMask);
}
@@ -61,8 +61,11 @@ struct Ban {
bool isValid() const;
bool operator < (const Ban &) const;
bool operator == (const Ban &) const;
QString toString() const;
};

quint32 qHash(const Ban &);

#if Q_BYTE_ORDER == Q_BIG_ENDIAN
#define SWAP64(x) (x)
#else
@@ -400,6 +400,7 @@ void Server::msgAuthenticate(ServerUser *uSource, MumbleProto::Authenticate &msg
void Server::msgBanList(ServerUser *uSource, MumbleProto::BanList &msg) {
MSG_SETUP(ServerUser::Authenticated);

QSet<Ban> previousBans, newBans;
if (! hasPermission(uSource, qhChannels.value(0), ChanACL::Ban)) {
PERM_DENIED(uSource, qhChannels.value(0), ChanACL::Ban);
return;
@@ -419,6 +420,7 @@ void Server::msgBanList(ServerUser *uSource, MumbleProto::BanList &msg) {
}
sendMessage(uSource, msg);
} else {
previousBans = qlBans.toSet();
qlBans.clear();
for (int i=0;i < msg.bans_size(); ++i) {
const MumbleProto::BanList_BanEntry &be = msg.bans(i);
@@ -436,8 +438,18 @@ void Server::msgBanList(ServerUser *uSource, MumbleProto::BanList &msg) {
b.qdtStart = QDateTime::currentDateTime().toUTC();
}
b.iDuration = be.duration();
if (b.isValid())
if (b.isValid()) {
qlBans << b;
}
}
newBans = qlBans.toSet();
QSet<Ban> removed = previousBans - newBans;
QSet<Ban> added = newBans - previousBans;
foreach(const Ban &b, removed) {
log(uSource, QString("Removed ban: %1").arg(b.toString()));
}
foreach(const Ban &b, added) {
log(uSource, QString("New ban: %1").arg(b.toString()));
}
saveBans();
log(uSource, "Updated banlist");

0 comments on commit c522cff

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