summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2018-03-08 01:35:19 +0300
committerAndrei Karas <akaras@inbox.ru>2018-03-08 01:35:19 +0300
commit676c5e978cbb312fbf4df8ec396c0f8b08944a96 (patch)
tree3336dda58d228fdada40453d80769e5186dab845 /src
parent0d9e625499c18a4eaf79d38dfb1ef6abf0c553bd (diff)
downloadplus-676c5e978cbb312fbf4df8ec396c0f8b08944a96.tar.gz
plus-676c5e978cbb312fbf4df8ec396c0f8b08944a96.tar.bz2
plus-676c5e978cbb312fbf4df8ec396c0f8b08944a96.tar.xz
plus-676c5e978cbb312fbf4df8ec396c0f8b08944a96.zip
Add support for enter auth pincode.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/windows/pincodedialog.cpp1
-rw-r--r--src/listeners/pincodelistener.cpp48
-rw-r--r--src/listeners/pincodelistener.h42
-rw-r--r--src/net/charserverhandler.h3
-rw-r--r--src/net/eathena/charserverhandler.cpp8
-rw-r--r--src/net/eathena/charserverhandler.h3
-rw-r--r--src/net/tmwa/charserverhandler.h5
-rw-r--r--src/pincodemanager.cpp40
-rw-r--r--src/pincodemanager.h4
-rw-r--r--src/progs/manaplus/client.cpp2
12 files changed, 155 insertions, 5 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e2b00849c..faa33db42 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1549,6 +1549,8 @@ SET(SRCS
listeners/newpincodelistener.h
listeners/newpincoderetrylistener.cpp
listeners/newpincoderetrylistener.h
+ listeners/pincodelistener.cpp
+ listeners/pincodelistener.h
listeners/shoprenamelistener.cpp
listeners/shoprenamelistener.h
listeners/skillwarplistener.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index e6dd49550..03402857b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1853,6 +1853,8 @@ SRC += gui/windows/bankwindow.cpp \
listeners/newpincodelistener.h \
listeners/newpincoderetrylistener.cpp \
listeners/newpincoderetrylistener.h \
+ listeners/pincodelistener.cpp \
+ listeners/pincodelistener.h \
listeners/requestadoptchildlistener.h \
listeners/shoprenamelistener.cpp \
listeners/shoprenamelistener.h \
diff --git a/src/gui/windows/pincodedialog.cpp b/src/gui/windows/pincodedialog.cpp
index b23ab17d1..257d5ae1c 100644
--- a/src/gui/windows/pincodedialog.cpp
+++ b/src/gui/windows/pincodedialog.cpp
@@ -119,6 +119,7 @@ const std::string &PincodeDialog::getMsg() const
void PincodeDialog::close()
{
keyboard.setEnabled(mEnabledKeyboard);
+ pincodeManager.clearDialog(this);
scheduleDelete();
}
diff --git a/src/listeners/pincodelistener.cpp b/src/listeners/pincodelistener.cpp
new file mode 100644
index 000000000..3179bbed6
--- /dev/null
+++ b/src/listeners/pincodelistener.cpp
@@ -0,0 +1,48 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2018 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "listeners/pincodelistener.h"
+
+#include "client.h"
+#include "pincodemanager.h"
+
+#include "gui/windows/pincodedialog.h"
+
+#include "debug.h"
+
+PincodeListener pincodeListener;
+
+void PincodeListener::action(const ActionEvent &event)
+{
+ if (event.getId() == "ok")
+ {
+ const PincodeDialog *const dialog = dynamic_cast<PincodeDialog*>(
+ event.getSource());
+ if (dialog != nullptr)
+ {
+ const std::string pincode = dialog->getMsg();
+ pincodeManager.sendPincode(pincode);
+ }
+ }
+ else
+ {
+ client->setState(State::SWITCH_LOGIN);
+ }
+}
diff --git a/src/listeners/pincodelistener.h b/src/listeners/pincodelistener.h
new file mode 100644
index 000000000..f32bf4ded
--- /dev/null
+++ b/src/listeners/pincodelistener.h
@@ -0,0 +1,42 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2018 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LISTENERS_PINCODELISTENER_H
+#define LISTENERS_PINCODELISTENER_H
+
+#include "listeners/actionlistener.h"
+
+#include "localconsts.h"
+
+class PincodeListener final : public ActionListener
+{
+ public:
+ PincodeListener() :
+ ActionListener()
+ { }
+
+ A_DELETE_COPY(PincodeListener)
+
+ void action(const ActionEvent &event) override final;
+};
+
+extern PincodeListener pincodeListener;
+
+#endif // LISTENERS_PINCODELISTENER_H
diff --git a/src/net/charserverhandler.h b/src/net/charserverhandler.h
index 56728a58f..fdf744cc4 100644
--- a/src/net/charserverhandler.h
+++ b/src/net/charserverhandler.h
@@ -90,6 +90,9 @@ class CharServerHandler notfinal
virtual void setNewPincode(const BeingId accountId,
const std::string &pin) const = 0;
+ virtual void sendCheckPincode(const BeingId accountId,
+ const std::string &pin) const = 0;
+
virtual void changeSlot(const int oldSlot,
const int newSlot) const = 0;
diff --git a/src/net/eathena/charserverhandler.cpp b/src/net/eathena/charserverhandler.cpp
index a62c79c3b..71bf6aeee 100644
--- a/src/net/eathena/charserverhandler.cpp
+++ b/src/net/eathena/charserverhandler.cpp
@@ -206,6 +206,14 @@ void CharServerHandler::setNewPincode(const BeingId accountId,
outMsg.writeString(pin, 4, "encrypted pin");
}
+void CharServerHandler::sendCheckPincode(const BeingId accountId,
+ const std::string &pin) const
+{
+ createOutPacket(CMSG_CHAR_PIN_CHECK);
+ outMsg.writeBeingId(accountId, "account id");
+ outMsg.writeString(pin, 4, "encrypted pin");
+}
+
void CharServerHandler::renameCharacter(const BeingId id,
const std::string &newName) const
{
diff --git a/src/net/eathena/charserverhandler.h b/src/net/eathena/charserverhandler.h
index 9e02dce1f..f41b14a79 100644
--- a/src/net/eathena/charserverhandler.h
+++ b/src/net/eathena/charserverhandler.h
@@ -65,6 +65,9 @@ class CharServerHandler final : public Ea::CharServerHandler
void setNewPincode(const BeingId accountId,
const std::string &pin) const override final;
+ void sendCheckPincode(const BeingId accountId,
+ const std::string &pin) const override final;
+
/**
* Sets the character create dialog. The handler will clean up this
* dialog when a new character is successfully created, and will unlock
diff --git a/src/net/tmwa/charserverhandler.h b/src/net/tmwa/charserverhandler.h
index 51bf08b84..37e71744e 100644
--- a/src/net/tmwa/charserverhandler.h
+++ b/src/net/tmwa/charserverhandler.h
@@ -67,6 +67,11 @@ class CharServerHandler final : public Ea::CharServerHandler
override final
{ }
+ void sendCheckPincode(const BeingId accountId A_UNUSED,
+ const std::string &pin A_UNUSED) const
+ override final
+ { }
+
/**
* Sets the character create dialog. The handler will clean up this
* dialog when a new character is successfully created, and will unlock
diff --git a/src/pincodemanager.cpp b/src/pincodemanager.cpp
index 4ee8abd3a..541726f9c 100644
--- a/src/pincodemanager.cpp
+++ b/src/pincodemanager.cpp
@@ -27,6 +27,7 @@
#include "listeners/newpincodelistener.h"
#include "listeners/newpincoderetrylistener.h"
+#include "listeners/pincodelistener.h"
#include "net/charserverhandler.h"
@@ -66,10 +67,17 @@ void PincodeManager::updateState()
{
switch (mState)
{
- case PincodeState::None:
case PincodeState::Ask:
- case PincodeState::Change:
- default:
+ CREATEWIDGETV(mDialog, PincodeDialog,
+ // TRANSLATORS: dialog caption
+ _("Pincode"),
+ // TRANSLATORS: dialog label
+ _("Enter pincode"),
+ mSeed,
+ nullptr);
+ mDialog->requestFocus();
+ mDialog->setActionEventId("ok");
+ mDialog->addActionListener(&pincodeListener);
break;
case PincodeState::Create:
CREATEWIDGETV(mDialog, PincodeDialog,
@@ -83,6 +91,10 @@ void PincodeManager::updateState()
mDialog->setActionEventId("ok");
mDialog->addActionListener(&newPincodeListener);
break;
+ case PincodeState::Change:
+ case PincodeState::None:
+ default:
+ break;
}
}
@@ -107,7 +119,7 @@ void PincodeManager::setNewPincode(const std::string &pincode)
if (mNewPincode != pincode)
{
mNewPincode.clear();
- OkDialog *const dialog = CREATEWIDGETR(OkDialog,
+ CREATEWIDGETV(mDialog, OkDialog,
// TRANSLATORS: error header
_("Pincode"),
// TRANSLATORS: error message
@@ -119,7 +131,7 @@ void PincodeManager::setNewPincode(const std::string &pincode)
ShowCenter_true,
nullptr,
260);
- dialog->addActionListener(&newPincodeRetryListener);
+ mDialog->addActionListener(&newPincodeRetryListener);
}
else
{
@@ -130,10 +142,28 @@ void PincodeManager::setNewPincode(const std::string &pincode)
}
}
+void PincodeManager::sendPincode(const std::string &pincode)
+{
+ charServerHandler->sendCheckPincode(mAccountId,
+ pincode);
+}
+
void PincodeManager::pinOk()
{
+ mState = PincodeState::None;
}
void PincodeManager::wrongPin()
{
+ mState = PincodeState::Ask;
+ updateState();
+}
+
+void PincodeManager::closeDialogs()
+{
+ if (mDialog)
+ {
+ mDialog->scheduleDelete();
+ mDialog = nullptr;
+ }
}
diff --git a/src/pincodemanager.h b/src/pincodemanager.h
index bf3d2e8fc..b05e09af8 100644
--- a/src/pincodemanager.h
+++ b/src/pincodemanager.h
@@ -62,6 +62,10 @@ class PincodeManager final
void setNewPincode(const std::string &pincode);
+ void sendPincode(const std::string &pincode);
+
+ void closeDialogs();
+
protected:
std::string mNewPincode;
uint32_t mSeed;
diff --git a/src/progs/manaplus/client.cpp b/src/progs/manaplus/client.cpp
index 84f6cdcce..bc5007884 100644
--- a/src/progs/manaplus/client.cpp
+++ b/src/progs/manaplus/client.cpp
@@ -1080,6 +1080,7 @@ int Client::gameExec()
BLOCK_START("Client::gameExec STATE_CHOOSE_SERVER")
logger->log1("State: CHOOSE SERVER");
unloadData();
+ pincodeManager.closeDialogs();
// Allow changing this using a server choice dialog
// We show the dialog box only if the command-line
@@ -1620,6 +1621,7 @@ int Client::gameExec()
serverConfig.write();
logger->log1("State: ERROR");
logger->log("Error: %s\n", errorMessage.c_str());
+ pincodeManager.closeDialogs();
mCurrentDialog = DialogsManager::openErrorDialog(
// TRANSLATORS: error message header
_("Error"),