Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use screen name instead of IP address to announce server through zeroconf #1286

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/newsfragments/zeroconf-announce-screen-name.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use screen name instead of IP address to announce server through zeroconf.
38 changes: 4 additions & 34 deletions src/gui/src/ZeroconfService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,6 @@ void ZeroconfService::errorHandle(DNSServiceErrorType errorCode)
tr("Error code: %1.").arg(errorCode));
}

QString ZeroconfService::getLocalIPAddresses()
{
QStringList addresses;
for (const QHostAddress& address : QNetworkInterface::allAddresses()) {
if (address.protocol() == QAbstractSocket::IPv4Protocol &&
address != QHostAddress(QHostAddress::LocalHost)) {
addresses.append(address.toString());
}
}

for (const QString& preferedIP : preferedIPAddress) {
for (const QString& address : addresses) {
if (address.startsWith(preferedIP)) {
return address;
}
}
}

return "";
}

bool ZeroconfService::registerService(bool server)
{
bool result = true;
Expand All @@ -159,19 +138,10 @@ bool ZeroconfService::registerService(bool server)
else {
m_pZeroconfRegister = new ZeroconfRegister(this);
if (server) {
QString localIP = getLocalIPAddresses();
if (localIP.isEmpty()) {
QMessageBox::warning(m_pMainWindow, tr("Barrier"),
tr("Failed to get local IP address. "
"Please manually type in server address "
"on your clients"));
}
else {
m_pZeroconfRegister->registerService(
ZeroconfRecord(tr("%1").arg(localIP),
QLatin1String(m_ServerServiceName), QString()),
m_zeroconfServer.serverPort());
}
m_pZeroconfRegister->registerService(
ZeroconfRecord(tr("%1").arg(m_pMainWindow->getScreenName()),
QLatin1String(m_ServerServiceName), QString()),
m_zeroconfServer.serverPort());
}
else {
m_pZeroconfRegister->registerService(
Expand Down
1 change: 0 additions & 1 deletion src/gui/src/ZeroconfService.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ private slots:
void errorHandle(DNSServiceErrorType errorCode);

private:
QString getLocalIPAddresses();
bool registerService(bool server);

private:
Expand Down