mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-24 10:23:02 -07:00
[Settings] Match a server on the exact host and port when adding it
This commit is contained in:
parent
501ec70512
commit
c0d3febf72
2 changed files with 54 additions and 17 deletions
|
|
@ -171,7 +171,12 @@ void ServersSettings::addNewServer(const QString &saveName,
|
||||||
bool savePassword,
|
bool savePassword,
|
||||||
const QString &site)
|
const QString &site)
|
||||||
{
|
{
|
||||||
if (updateExistingServer(saveName, serv, port, username, password, savePassword, site)) {
|
// Match the exact host-plus-port server the caller is adding, so a link or
|
||||||
|
// public-server list entry cannot clobber the port (and credentials) of an
|
||||||
|
// unrelated entry that happens to share the same hostname.
|
||||||
|
const int existingIndex = findServerIndex(serv, port);
|
||||||
|
if (existingIndex >= 0) {
|
||||||
|
updateServerFields(existingIndex, saveName, username, password, savePassword, site);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -271,22 +276,7 @@ bool ServersSettings::updateExistingServer(QString saveName,
|
||||||
for (int i = 0; i <= size; ++i) {
|
for (int i = 0; i <= size; ++i) {
|
||||||
if (serv == getValue(QString("server%1").arg(i), "server", "server_details").toString()) {
|
if (serv == getValue(QString("server%1").arg(i), "server", "server_details").toString()) {
|
||||||
setValue(port, QString("port%1").arg(i), "server", "server_details");
|
setValue(port, QString("port%1").arg(i), "server", "server_details");
|
||||||
if (!username.isEmpty()) {
|
updateServerFields(i, saveName, username, password, savePassword, site);
|
||||||
setValue(username, QString("username%1").arg(i), "server", "server_details");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (savePassword && !password.isEmpty()) {
|
|
||||||
setValue(password, QString("password%1").arg(i), "server", "server_details");
|
|
||||||
} else {
|
|
||||||
setValue(QString(), QString("password%1").arg(i), "server", "server_details");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!site.isEmpty()) {
|
|
||||||
setValue(site, QString("site%1").arg(i), "server", "server_details");
|
|
||||||
}
|
|
||||||
|
|
||||||
setValue(savePassword, QString("savePassword%1").arg(i), "server", "server_details");
|
|
||||||
setValue(saveName, QString("saveName%1").arg(i), "server", "server_details");
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -294,6 +284,31 @@ bool ServersSettings::updateExistingServer(QString saveName,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServersSettings::updateServerFields(int index,
|
||||||
|
const QString &saveName,
|
||||||
|
const QString &username,
|
||||||
|
const QString &password,
|
||||||
|
bool savePassword,
|
||||||
|
const QString &site)
|
||||||
|
{
|
||||||
|
if (!username.isEmpty()) {
|
||||||
|
setValue(username, QString("username%1").arg(index), "server", "server_details");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (savePassword && !password.isEmpty()) {
|
||||||
|
setValue(password, QString("password%1").arg(index), "server", "server_details");
|
||||||
|
} else {
|
||||||
|
setValue(QString(), QString("password%1").arg(index), "server", "server_details");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!site.isEmpty()) {
|
||||||
|
setValue(site, QString("site%1").arg(index), "server", "server_details");
|
||||||
|
}
|
||||||
|
|
||||||
|
setValue(savePassword, QString("savePassword%1").arg(index), "server", "server_details");
|
||||||
|
setValue(saveName, QString("saveName%1").arg(index), "server", "server_details");
|
||||||
|
}
|
||||||
|
|
||||||
int ServersSettings::findServerIndex(const QString &host, const QString &port) const
|
int ServersSettings::findServerIndex(const QString &host, const QString &port) const
|
||||||
{
|
{
|
||||||
int size = getValue("totalServers", "server", "server_details").toInt();
|
int size = getValue("totalServers", "server", "server_details").toInt();
|
||||||
|
|
@ -310,6 +325,21 @@ int ServersSettings::findServerIndex(const QString &host, const QString &port) c
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ServersSettings::findHostIndex(const QString &host) const
|
||||||
|
{
|
||||||
|
int size = getValue("totalServers", "server", "server_details").toInt();
|
||||||
|
|
||||||
|
for (int i = 0; i <= size; ++i) {
|
||||||
|
QString storedHost = getValue(QString("server%1").arg(i), "server", "server_details").toString();
|
||||||
|
|
||||||
|
if (storedHost.compare(host, Qt::CaseInsensitive) == 0) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
bool ServersSettings::hasUsername(const QString &host, const QString &port) const
|
bool ServersSettings::hasUsername(const QString &host, const QString &port) const
|
||||||
{
|
{
|
||||||
int index = findServerIndex(host, port);
|
int index = findServerIndex(host, port);
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,14 @@ public:
|
||||||
QString password,
|
QString password,
|
||||||
bool savePassword,
|
bool savePassword,
|
||||||
QString site = QString());
|
QString site = QString());
|
||||||
|
void updateServerFields(int index,
|
||||||
|
const QString &saveName,
|
||||||
|
const QString &username,
|
||||||
|
const QString &password,
|
||||||
|
bool savePassword,
|
||||||
|
const QString &site);
|
||||||
int findServerIndex(const QString &host, const QString &port) const;
|
int findServerIndex(const QString &host, const QString &port) const;
|
||||||
|
int findHostIndex(const QString &host) const;
|
||||||
bool hasUsername(const QString &host, const QString &port) const;
|
bool hasUsername(const QString &host, const QString &port) const;
|
||||||
bool hasCredentials(const QString &host, const QString &port) const;
|
bool hasCredentials(const QString &host, const QString &port) const;
|
||||||
bool hasLoginData(const QString &host, const QString &port) const;
|
bool hasLoginData(const QString &host, const QString &port) const;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue