QTfrontend/gameuiconfig.cpp
changeset 14745 7b2bd37d7503
parent 14682 93429d8f6b3f
child 14966 575dbd7b5f43
--- a/QTfrontend/gameuiconfig.cpp	Tue Apr 02 00:13:25 2019 +0200
+++ b/QTfrontend/gameuiconfig.cpp	Tue Apr 02 01:03:39 2019 +0200
@@ -115,7 +115,7 @@
     Form->ui.pageOptions->CBDampenAudio->setChecked(value("audio/dampen", true).toBool());
     Form->ui.pageOptions->SLVolume->setValue(value("audio/volume", 100).toUInt());
 
-    QString netNick = value("net/nick", tr("Guest")+QString("%1").arg(rand())).toString();
+    QString netNick = value("net/nick", getRandomNick()).toString();
     Form->ui.pageOptions->editNetNick->setText(netNick);
     bool savePwd = value("net/savepassword",true).toBool();
     Form->ui.pageOptions->CBSavePassword->setChecked(savePwd);
@@ -517,6 +517,16 @@
     Form->ui.pageOptions->editNetNick->setText(value("net/nick", "").toString());
 }
 
+QString GameUIConfig::getRandomNick()
+{
+    // Generate random nick name or pick old one if one was already generated.
+    QString nick;
+    if (cachedRandomNick.isNull())
+        // "Guest" + number between 1 and 99999
+        cachedRandomNick = tr("Guest") + QString("%1").arg(rand() % 99999 + 1);
+    return cachedRandomNick;
+}
+
 QByteArray GameUIConfig::netPasswordHash()
 {
     return QCryptographicHash::hash(Form->ui.pageOptions->editNetPassword->text().toUtf8(), QCryptographicHash::Md5).toHex();