diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/listeners/changepincodelistener.cpp | 48 | ||||
-rw-r--r-- | src/listeners/changepincodelistener.h | 42 | ||||
-rw-r--r-- | src/net/charserverhandler.h | 4 | ||||
-rw-r--r-- | src/net/eathena/charserverhandler.cpp | 10 | ||||
-rw-r--r-- | src/net/eathena/charserverhandler.h | 4 | ||||
-rw-r--r-- | src/net/eathena/charserverrecv.cpp | 4 | ||||
-rw-r--r-- | src/net/tmwa/charserverhandler.h | 6 | ||||
-rw-r--r-- | src/pincodemanager.cpp | 80 | ||||
-rw-r--r-- | src/pincodemanager.h | 3 | ||||
-rw-r--r-- | src/progs/dyecmd/client.cpp | 4 | ||||
-rw-r--r-- | src/progs/dyecmd/client.h | 2 | ||||
-rw-r--r-- | src/progs/manaplus/client.cpp | 13 | ||||
-rw-r--r-- | src/progs/manaplus/client.h | 2 |
15 files changed, 224 insertions, 2 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index faa33db42..f055faa2a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1545,6 +1545,8 @@ SET(SRCS listeners/buyingstoremodelistener.h listeners/buyingstoreslotslistener.cpp listeners/buyingstoreslotslistener.h + listeners/changepincodelistener.cpp + listeners/changepincodelistener.h listeners/newpincodelistener.cpp listeners/newpincodelistener.h listeners/newpincoderetrylistener.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 03402857b..99018a570 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1849,6 +1849,8 @@ SRC += gui/windows/bankwindow.cpp \ listeners/buyingstoremodelistener.h \ listeners/buyingstoreslotslistener.cpp \ listeners/buyingstoreslotslistener.h \ + listeners/changepincodelistener.cpp \ + listeners/changepincodelistener.h \ listeners/newpincodelistener.cpp \ listeners/newpincodelistener.h \ listeners/newpincoderetrylistener.cpp \ diff --git a/src/listeners/changepincodelistener.cpp b/src/listeners/changepincodelistener.cpp new file mode 100644 index 000000000..3f5d98aa0 --- /dev/null +++ b/src/listeners/changepincodelistener.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/changepincodelistener.h" + +#include "client.h" +#include "pincodemanager.h" + +#include "gui/windows/pincodedialog.h" + +#include "debug.h" + +ChangePincodeListener changePincodeListener; + +void ChangePincodeListener::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.changePincode(pincode); + } + } + else + { + client->setState(State::SWITCH_LOGIN); + } +} diff --git a/src/listeners/changepincodelistener.h b/src/listeners/changepincodelistener.h new file mode 100644 index 000000000..34ecd3cf9 --- /dev/null +++ b/src/listeners/changepincodelistener.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_CHANGEPINCODELISTENER_H +#define LISTENERS_CHANGEPINCODELISTENER_H + +#include "listeners/actionlistener.h" + +#include "localconsts.h" + +class ChangePincodeListener final : public ActionListener +{ + public: + ChangePincodeListener() : + ActionListener() + { } + + A_DELETE_COPY(ChangePincodeListener) + + void action(const ActionEvent &event) override final; +}; + +extern ChangePincodeListener changePincodeListener; + +#endif // LISTENERS_CHANGEPINCODELISTENER_H diff --git a/src/net/charserverhandler.h b/src/net/charserverhandler.h index fdf744cc4..9bc3aa86a 100644 --- a/src/net/charserverhandler.h +++ b/src/net/charserverhandler.h @@ -93,6 +93,10 @@ class CharServerHandler notfinal virtual void sendCheckPincode(const BeingId accountId, const std::string &pin) const = 0; + virtual void changePincode(const BeingId accountId, + const std::string &oldPin, + const std::string &newPin) 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 71bf6aeee..630dca675 100644 --- a/src/net/eathena/charserverhandler.cpp +++ b/src/net/eathena/charserverhandler.cpp @@ -214,6 +214,16 @@ void CharServerHandler::sendCheckPincode(const BeingId accountId, outMsg.writeString(pin, 4, "encrypted pin"); } +void CharServerHandler::changePincode(const BeingId accountId, + const std::string &oldPin, + const std::string &newPin) const +{ + createOutPacket(CMSG_CHAR_PIN_CHANGE); + outMsg.writeBeingId(accountId, "account id"); + outMsg.writeString(oldPin, 4, "old encrypted pin"); + outMsg.writeString(newPin, 4, "new 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 f41b14a79..a712c5a56 100644 --- a/src/net/eathena/charserverhandler.h +++ b/src/net/eathena/charserverhandler.h @@ -68,6 +68,10 @@ class CharServerHandler final : public Ea::CharServerHandler void sendCheckPincode(const BeingId accountId, const std::string &pin) const override final; + void changePincode(const BeingId accountId, + const std::string &oldPin, + const std::string &newPin) 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/eathena/charserverrecv.cpp b/src/net/eathena/charserverrecv.cpp index 6d5fd63ca..ece603ac2 100644 --- a/src/net/eathena/charserverrecv.cpp +++ b/src/net/eathena/charserverrecv.cpp @@ -370,7 +370,7 @@ void CharServerRecv::processPincodeStatus(Net::MessageIn &msg) case 8: // pincode was incorrect case 5: // client show error? pincodeManager.wrongPin(); - break; + return; case 6: // Unable to use your KSSN number break; case 7: // char select window shows a button @@ -379,6 +379,8 @@ void CharServerRecv::processPincodeStatus(Net::MessageIn &msg) UNIMPLEMENTEDPACKET; break; } + if (client) + client->updatePinState(); } void CharServerRecv::processCharCreate(Net::MessageIn &msg) diff --git a/src/net/tmwa/charserverhandler.h b/src/net/tmwa/charserverhandler.h index 37e71744e..8e2b25767 100644 --- a/src/net/tmwa/charserverhandler.h +++ b/src/net/tmwa/charserverhandler.h @@ -72,6 +72,12 @@ class CharServerHandler final : public Ea::CharServerHandler override final { } + void changePincode(const BeingId accountId A_UNUSED, + const std::string &oldPin A_UNUSED, + const std::string &newPin 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 d8f2cea5a..67b14f2bf 100644 --- a/src/pincodemanager.cpp +++ b/src/pincodemanager.cpp @@ -27,6 +27,7 @@ #include "gui/widgets/createwidget.h" +#include "listeners/changepincodelistener.h" #include "listeners/newpincodelistener.h" #include "listeners/newpincoderetrylistener.h" #include "listeners/pincodelistener.h" @@ -40,6 +41,7 @@ PincodeManager pincodeManager; PincodeManager::PincodeManager() : + mOldPincode(), mNewPincode(), mSeed(0U), mAccountId(BeingId_zero), @@ -57,6 +59,7 @@ void PincodeManager::init() mSeed = 0; mAccountId = BeingId_zero; mState = PincodeState::None; + mNewPincode.clear(); } void PincodeManager::clearDialog(const PincodeDialog *const PincodeDialog) @@ -82,11 +85,12 @@ void PincodeManager::updateState() mDialog->addActionListener(&pincodeListener); break; case PincodeState::Create: + mNewPincode.clear(); CREATEWIDGETV(mDialog, PincodeDialog, // TRANSLATORS: dialog caption _("New pincode"), // TRANSLATORS: dialog label - _("Set new pincode"), + _("Enter new pincode"), mSeed, nullptr); mDialog->requestFocus(); @@ -94,6 +98,19 @@ void PincodeManager::updateState() mDialog->addActionListener(&newPincodeListener); break; case PincodeState::Change: + mOldPincode.clear(); + mNewPincode.clear(); + CREATEWIDGETV(mDialog, PincodeDialog, + // TRANSLATORS: dialog caption + _("Change pincode"), + // TRANSLATORS: dialog label + _("Enter old pincode"), + mSeed, + nullptr); + mDialog->requestFocus(); + mDialog->setActionEventId("ok"); + mDialog->addActionListener(&changePincodeListener); + break; case PincodeState::None: default: break; @@ -144,6 +161,67 @@ void PincodeManager::setNewPincode(const std::string &pincode) } } +void PincodeManager::changePincode(const std::string &pincode) +{ + if (mOldPincode.empty()) + { // set old pincode + mOldPincode = pincode; + CREATEWIDGETV(mDialog, PincodeDialog, + // TRANSLATORS: dialog caption + _("Change pincode"), + // TRANSLATORS: dialog label + _("Enter new pincode"), + mSeed, + nullptr); + mDialog->requestFocus(); + mDialog->setActionEventId("ok"); + mDialog->addActionListener(&changePincodeListener); + } + else if (mNewPincode.empty()) + { // set first new pincode + mNewPincode = pincode; + CREATEWIDGETV(mDialog, PincodeDialog, + // TRANSLATORS: dialog caption + _("Change pincode"), + // TRANSLATORS: dialog label + _("Confirm new pincode"), + mSeed, + nullptr); + mDialog->requestFocus(); + mDialog->setActionEventId("ok"); + mDialog->addActionListener(&changePincodeListener); + } + else + { // new pincode confirmation + if (mNewPincode != pincode) + { + mOldPincode.clear(); + mNewPincode.clear(); + CREATEWIDGETV(mDialog, OkDialog, + // TRANSLATORS: error header + _("Pincode"), + // TRANSLATORS: error message + _("Wrong pincode confirmation!"), + // TRANSLATORS: ok dialog button + _("OK"), + DialogType::ERROR, + Modal_true, + ShowCenter_true, + nullptr, + 260); + mDialog->addActionListener(&newPincodeRetryListener); + } + else + { + charServerHandler->changePincode(mAccountId, + mOldPincode, + mNewPincode); + mOldPincode.clear(); + mNewPincode.clear(); + } + } +} + void PincodeManager::sendPincode(const std::string &pincode) { charServerHandler->sendCheckPincode(mAccountId, diff --git a/src/pincodemanager.h b/src/pincodemanager.h index 671333e59..37b7e6921 100644 --- a/src/pincodemanager.h +++ b/src/pincodemanager.h @@ -58,6 +58,8 @@ class PincodeManager final void setState(const PincodeState state) { mState = state; } + void changePincode(const std::string &pincode); + void clearDialog(const PincodeDialog *const PincodeDialog); void setNewPincode(const std::string &pincode); @@ -69,6 +71,7 @@ class PincodeManager final bool isBlocked(); protected: + std::string mOldPincode; std::string mNewPincode; uint32_t mSeed; BeingId mAccountId; diff --git a/src/progs/dyecmd/client.cpp b/src/progs/dyecmd/client.cpp index 40b2ad48f..353d4718f 100644 --- a/src/progs/dyecmd/client.cpp +++ b/src/progs/dyecmd/client.cpp @@ -809,6 +809,10 @@ void Client::focusWindow() } } +void Client::updatePinState() +{ +} + void Client::logVars() { #ifdef ANDROID diff --git a/src/progs/dyecmd/client.h b/src/progs/dyecmd/client.h index 89dd82e11..6b110ccbd 100644 --- a/src/progs/dyecmd/client.h +++ b/src/progs/dyecmd/client.h @@ -74,6 +74,8 @@ class Client final : public ActionListener void windowRemoved(const Window *const window); + void updatePinState(); + void focusWindow(); void slowLogic(); diff --git a/src/progs/manaplus/client.cpp b/src/progs/manaplus/client.cpp index 504916ea7..4b9132b53 100644 --- a/src/progs/manaplus/client.cpp +++ b/src/progs/manaplus/client.cpp @@ -1861,6 +1861,19 @@ void Client::focusWindow() } } +void Client::updatePinState() +{ + if (mCurrentDialog == nullptr || + mState != State::CHAR_SELECT) + { + return; + } + CharSelectDialog *const dialog = + dynamic_cast<CharSelectDialog*>(mCurrentDialog); + if (dialog != nullptr) + pincodeManager.updateState(); +} + void Client::logVars() { #ifdef ANDROID diff --git a/src/progs/manaplus/client.h b/src/progs/manaplus/client.h index 28ab7323e..0cd26f454 100644 --- a/src/progs/manaplus/client.h +++ b/src/progs/manaplus/client.h @@ -90,6 +90,8 @@ class Client final : public ConfigListener, void focusWindow(); + void updatePinState(); + void slowLogic(); ServerInfo &getCurrentServer() |