Skip to content

Commit

Permalink
Merge PR #5948: FEAT(server): FEAT(server): Flag bot connections
Browse files Browse the repository at this point in the history
FEAT(server): Flag bot connections

This commit introduces a new flag that connecting clients can use to
tell the server they are connecting to that they consider themselves bot
clients. This information can then be used (as is the case for the
official server implementation) to e.g. correct the reported user count
on the server to only include "real" clients - aka: no bots.

Fixes #5461
  • Loading branch information
Krzmbrzl authored Nov 27, 2022
2 parents 9c33451 + 68c31e5 commit fc4db91
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Mumble.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ message Authenticate {
// A list of CELT bitstream version constants supported by the client.
repeated int32 celt_versions = 4;
optional bool opus = 5 [default = false];
// 0 = REGULAR, 1 = BOT
optional int32 client_type = 6 [default = 0];
}

// Sent by the client to notify the server that the client is still alive.
Expand Down
9 changes: 9 additions & 0 deletions src/murmur/ClientType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef MUMBLE_MURMUR_CLIENT_TYPE_H_
#define MUMBLE_MURMUR_CLIENT_TYPE_H_

enum class ClientType {
REGULAR,
BOT,
};

#endif
12 changes: 12 additions & 0 deletions src/murmur/Messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ACL.h"
#include "Channel.h"
#include "ChannelListenerManager.h"
#include "ClientType.h"
#include "Connection.h"
#include "Group.h"
#include "Meta.h"
Expand Down Expand Up @@ -601,6 +602,17 @@ void Server::msgAuthenticate(ServerUser *uSource, MumbleProto::Authenticate &msg
sendMessage(uSource, mptm);
}

switch (msg.client_type()) {
case static_cast< int >(ClientType::BOT):
uSource->m_clientType = ClientType::BOT;
m_botCount++;
break;
case static_cast< int >(ClientType::REGULAR):
// No-op (also applies to unknown values of msg.client_type())
// (The default client type is regular anyway, so we don't need to change anything here)
break;
}

log(uSource, "Authenticated");

emit userConnected(uSource);
Expand Down
7 changes: 6 additions & 1 deletion src/murmur/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "ACL.h"
#include "Channel.h"
#include "ClientType.h"
#include "Connection.h"
#include "EnvUtils.h"
#include "Group.h"
Expand Down Expand Up @@ -641,7 +642,7 @@ gsl::span< const Mumble::Protocol::byte >
pingData.requestAdditionalInformation = false;

pingData.serverVersion = Version::get();
pingData.userCount = qhUsers.size();
pingData.userCount = qhUsers.size() - m_botCount;
pingData.maxUserCount = iMaxUsers;
pingData.maxBandwidthPerUser = iMaxBandwidth;
pingData.containsAdditionalInformation = true;
Expand Down Expand Up @@ -1662,6 +1663,10 @@ void Server::connectionClosed(QAbstractSocket::SocketError err, const QString &r
mpur.set_session(u->uiSession);
sendExcept(u, mpur);

if (u->m_clientType == ClientType::BOT) {
m_botCount--;
}

emit userDisconnected(u);
}

Expand Down
1 change: 1 addition & 0 deletions src/murmur/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class Server : public QThread {
QString qsWelcomeTextFile;
bool bCertRequired;
bool bForceExternalAuth;
unsigned int m_botCount = 0;

QString qsRegName;
QString qsRegPassword;
Expand Down
6 changes: 4 additions & 2 deletions src/murmur/ServerUser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "ServerUser.h"

#include "ClientType.h"
#include "Meta.h"
#include "Server.h"

Expand All @@ -15,8 +16,9 @@
ServerUser::ServerUser(Server *p, QSslSocket *socket)
: Connection(p, socket), User(), s(nullptr), leakyBucket(p->iMessageLimit, p->iMessageBurst),
m_pluginMessageBucket(5, 20) {
sState = ServerUser::Connected;
sUdpSocket = INVALID_SOCKET;
sState = ServerUser::Connected;
m_clientType = ClientType::REGULAR;
sUdpSocket = INVALID_SOCKET;

memset(&saiUdpAddress, 0, sizeof(saiUdpAddress));
memset(&saiTcpLocalAddress, 0, sizeof(saiTcpLocalAddress));
Expand Down
2 changes: 2 additions & 0 deletions src/murmur/ServerUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# include "win.h"
#endif

#include "ClientType.h"
#include "Connection.h"
#include "HostAddress.h"
#include "Timer.h"
Expand Down Expand Up @@ -108,6 +109,7 @@ class ServerUser : public Connection, public User {
public:
enum State { Connected, Authenticated };
State sState;
ClientType m_clientType;
operator QString() const;

float dUDPPingAvg, dUDPPingVar;
Expand Down

0 comments on commit fc4db91

Please sign in to comment.