summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2018-05-20 06:11:17 +0300
committerAndrei Karas <akaras@inbox.ru>2018-05-20 06:11:17 +0300
commit3363acba6f1e8e51937ae2e354a8086c5c56b8cd (patch)
treecc2429241a3e7cba7a90ba1ae1b76e0abf8e5345
parent1f5ca54b8f60e112c2043160700055290c8ce912 (diff)
downloadmv-3363acba6f1e8e51937ae2e354a8086c5c56b8cd.tar.gz
mv-3363acba6f1e8e51937ae2e354a8086c5c56b8cd.tar.bz2
mv-3363acba6f1e8e51937ae2e354a8086c5c56b8cd.tar.xz
mv-3363acba6f1e8e51937ae2e354a8086c5c56b8cd.zip
Show gm revive button in death dialog if player have rights for @alive command.
-rw-r--r--src/gui/dialogsmanager.cpp43
-rw-r--r--src/gui/windows/confirmdialog.cpp31
-rw-r--r--src/gui/windows/confirmdialog.h16
-rw-r--r--src/listeners/playerpostdeathlistener.h31
-rw-r--r--src/net/eathena/beingrecv.cpp2
-rw-r--r--src/net/tmwa/beingrecv.cpp2
-rw-r--r--src/resources/db/groupdb.cpp30
-rw-r--r--src/resources/db/groupdb.h3
8 files changed, 131 insertions, 27 deletions
diff --git a/src/gui/dialogsmanager.cpp b/src/gui/dialogsmanager.cpp
index 2a4f407ee..288fadc94 100644
--- a/src/gui/dialogsmanager.cpp
+++ b/src/gui/dialogsmanager.cpp
@@ -48,6 +48,7 @@
#include "net/inventoryhandler.h"
#include "resources/db/deaddb.h"
+#include "resources/db/groupdb.h"
#include "utils/gettext.h"
@@ -57,7 +58,7 @@
#undef ERROR
#endif // WIN32
-OkDialog *deathNotice = nullptr;
+Window *deathNotice = nullptr;
DialogsManager *dialogsManager = nullptr;
OkDialog *weightNotice = nullptr;
time_t weightNoticeTime = 0;
@@ -141,17 +142,35 @@ void DialogsManager::playerDeath()
#ifndef DYECMD
if (deathNotice == nullptr)
{
- CREATEWIDGETV(deathNotice, OkDialog,
- // TRANSLATORS: message header
- _("Message"),
- DeadDB::getRandomString(),
- // TRANSLATORS: ok dialog button
- _("Revive"),
- DialogType::OK,
- Modal_false,
- ShowCenter_true,
- nullptr,
- 260);
+ if (GroupDb::isAllowCommand(ServerCommandType::alive))
+ {
+ CREATEWIDGETV(deathNotice, ConfirmDialog,
+ // TRANSLATORS: message header
+ _("Message"),
+ DeadDB::getRandomString(),
+ // TRANSLATORS: ok dialog button
+ _("Revive"),
+ // TRANSLATORS: ok dialog button
+ _("GM revive"),
+ SOUND_REQUEST,
+ false,
+ Modal_false,
+ nullptr);
+ }
+ else
+ {
+ CREATEWIDGETV(deathNotice, OkDialog,
+ // TRANSLATORS: message header
+ _("Message"),
+ DeadDB::getRandomString(),
+ // TRANSLATORS: ok dialog button
+ _("Revive"),
+ DialogType::OK,
+ Modal_false,
+ ShowCenter_true,
+ nullptr,
+ 260);
+ }
deathNotice->addActionListener(&postDeathListener);
}
#endif // DYECMD
diff --git a/src/gui/windows/confirmdialog.cpp b/src/gui/windows/confirmdialog.cpp
index a77d3bece..73f23e172 100644
--- a/src/gui/windows/confirmdialog.cpp
+++ b/src/gui/windows/confirmdialog.cpp
@@ -41,6 +41,31 @@ ConfirmDialog::ConfirmDialog(const std::string &restrict title,
Window *const parent) :
Window(title, modal, parent, "confirm.xml"),
ActionListener(),
+ // TRANSLATORS: confirm dialog button
+ mYesMsg(_("Yes")),
+ // TRANSLATORS: confirm dialog button
+ mNoMsg(_("No")),
+ mTextBox(new TextBox(this)),
+ mIgnore(ignore)
+{
+ mTextBox->setEditable(false);
+ mTextBox->setOpaque(Opaque_false);
+ mTextBox->setTextWrapped(msg, 260);
+ soundManager.playGuiSound(soundEvent);
+}
+
+ConfirmDialog::ConfirmDialog(const std::string &restrict title,
+ const std::string &restrict msg,
+ const std::string &restrict yesMsg,
+ const std::string &restrict noMsg,
+ const std::string &restrict soundEvent,
+ const bool ignore,
+ const Modal modal,
+ Window *const parent) :
+ Window(title, modal, parent, "confirm.xml"),
+ ActionListener(),
+ mYesMsg(yesMsg),
+ mNoMsg(noMsg),
mTextBox(new TextBox(this)),
mIgnore(ignore)
{
@@ -54,14 +79,12 @@ void ConfirmDialog::postInit()
{
Window::postInit();
Button *const yesButton = new Button(this,
- // TRANSLATORS: confirm dialog button
- _("Yes"),
+ mYesMsg,
"yes",
BUTTON_SKIN,
this);
Button *const noButton = new Button(this,
- // TRANSLATORS: confirm dialog button
- _("No"),
+ mNoMsg,
"no",
BUTTON_SKIN,
this);
diff --git a/src/gui/windows/confirmdialog.h b/src/gui/windows/confirmdialog.h
index f2a7f9094..58522c2e2 100644
--- a/src/gui/windows/confirmdialog.h
+++ b/src/gui/windows/confirmdialog.h
@@ -52,6 +52,20 @@ class ConfirmDialog notfinal : public Window,
const Modal modal,
Window *const parent);
+ /**
+ * Constructor.
+ *
+ * @see Window::Window
+ */
+ ConfirmDialog(const std::string &restrict title,
+ const std::string &restrict msg,
+ const std::string &restrict yesMsg,
+ const std::string &restrict noMsg,
+ const std::string &restrict soundEvent,
+ const bool ignore,
+ const Modal modal,
+ Window *const parent);
+
A_DELETE_COPY(ConfirmDialog)
/**
@@ -62,6 +76,8 @@ class ConfirmDialog notfinal : public Window,
void postInit() override final;
private:
+ std::string mYesMsg;
+ std::string mNoMsg;
TextBox *mTextBox A_NONNULLPOINTER;
bool mIgnore;
};
diff --git a/src/listeners/playerpostdeathlistener.h b/src/listeners/playerpostdeathlistener.h
index c5c6c47fb..58ceee324 100644
--- a/src/listeners/playerpostdeathlistener.h
+++ b/src/listeners/playerpostdeathlistener.h
@@ -30,11 +30,12 @@
#include "gui/windows/npcdialog.h"
+#include "net/adminhandler.h"
#include "net/playerhandler.h"
#include "localconsts.h"
-extern OkDialog *deathNotice;
+extern Window *deathNotice;
/**
* Listener used for handling death message.
@@ -47,18 +48,30 @@ struct PlayerPostDeathListener final : public ActionListener
A_DELETE_COPY(PlayerPostDeathListener)
- void action(const ActionEvent &event A_UNUSED) override final
+ void action(const ActionEvent &event) override final
{
- if (playerHandler != nullptr)
- playerHandler->respawn();
+ const bool respawn = !(event.getId() == "no");
deathNotice = nullptr;
+ if (respawn)
+ {
+ if (playerHandler != nullptr)
+ playerHandler->respawn();
- DialogsManager::closeDialogs();
- PopupManager::closePopupMenu();
+ DialogsManager::closeDialogs();
+ PopupManager::closePopupMenu();
+ NpcDialog::clearDialogs();
- NpcDialog::clearDialogs();
- if (localPlayer != nullptr)
- localPlayer->respawn();
+ if (localPlayer != nullptr)
+ localPlayer->respawn();
+ }
+ else
+ {
+ DialogsManager::closeDialogs();
+ PopupManager::closePopupMenu();
+ NpcDialog::clearDialogs();
+ if (localPlayer != nullptr)
+ adminHandler->alive(localPlayer->getName());
+ }
}
};
diff --git a/src/net/eathena/beingrecv.cpp b/src/net/eathena/beingrecv.cpp
index 1d098e9bc..5ec7cae15 100644
--- a/src/net/eathena/beingrecv.cpp
+++ b/src/net/eathena/beingrecv.cpp
@@ -71,7 +71,7 @@
#include "debug.h"
extern int serverVersion;
-extern OkDialog *deathNotice;
+extern Window *deathNotice;
extern bool packets_re;
extern bool packets_main;
extern bool packets_zero;
diff --git a/src/net/tmwa/beingrecv.cpp b/src/net/tmwa/beingrecv.cpp
index a40bcd1aa..3a6e19076 100644
--- a/src/net/tmwa/beingrecv.cpp
+++ b/src/net/tmwa/beingrecv.cpp
@@ -56,7 +56,7 @@
#include "debug.h"
-extern OkDialog *deathNotice;
+extern Window *deathNotice;
namespace TmwAthena
{
diff --git a/src/resources/db/groupdb.cpp b/src/resources/db/groupdb.cpp
index 1d1d1bffa..d8dc1117f 100644
--- a/src/resources/db/groupdb.cpp
+++ b/src/resources/db/groupdb.cpp
@@ -22,6 +22,10 @@
#include "configuration.h"
+#include "being/localplayer.h"
+
+#include "net/net.h"
+
#include "utils/checkutils.h"
#include "resources/beingcommon.h"
@@ -400,6 +404,32 @@ const GroupInfo *GroupDb::getGroup(const int id)
return (*it).second;
}
+bool GroupDb::isAllowCommand(const ServerCommandTypeT command)
+{
+ const int groupId = localPlayer->getGroupId();
+ const GroupInfo *const group = GroupDb::getGroup(groupId);
+ if (group == nullptr)
+ return false;
+
+#ifdef TMWA_SUPPORT
+ // allow any commands for legacy if group > 0
+ if (Net::getNetworkType() == ServerType::TMWATHENA &&
+ localPlayer != nullptr &&
+ localPlayer->isGM())
+ {
+ return true;
+ }
+#endif
+ if (group->mPermissions[CAST_SIZE(ServerPermissionType::all_commands)] ==
+ Enable_true)
+ {
+ return true;
+ }
+ const ServerCommandEnable::Type enabled =
+ group->mCommands[CAST_SIZE(command)];
+ return (enabled & ServerCommandEnable::Self) != 0;
+}
+
#ifdef UNITTESTS
GroupDb::GroupInfos &GroupDb::getGroups()
{
diff --git a/src/resources/db/groupdb.h b/src/resources/db/groupdb.h
index f447baa96..19a186911 100644
--- a/src/resources/db/groupdb.h
+++ b/src/resources/db/groupdb.h
@@ -21,6 +21,8 @@
#ifndef RESOURCES_DB_GROUPDB_H
#define RESOURCES_DB_GROUPDB_H
+#include "enums/resources/servercommandtype.h"
+
#include "enums/simpletypes/skiperror.h"
#include <map>
@@ -44,6 +46,7 @@ namespace GroupDb
bool getHighlightName(const int id) A_WARN_UNUSED;
const std::string &getBadge(const int id) A_WARN_UNUSED;
const GroupInfo *getGroup(const int id) A_WARN_UNUSED RETURNS_NONNULL;
+ bool isAllowCommand(const ServerCommandTypeT command);
typedef std::map<int, GroupInfo*> GroupInfos;
typedef GroupInfos::iterator GroupInfosIter;