From 780bcbc2ea75603f2eef7369a6f7b5ddfc5888b5 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Tue, 28 Dec 2010 22:04:41 +0100 Subject: Revert "Remove the AFK response system" This reverts commit 3d6a2d9c80a969c3613f567dd7029e75ef59b5cb. I've by that readded the AFK system on master. Please, remove it when we've got a proper replacement. --- src/localplayer.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) (limited to 'src/localplayer.cpp') diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 17641ed4..a4560030 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -80,10 +80,15 @@ LocalPlayer::LocalPlayer(int id, int subtype): mPathSetByMouse(false), mLocalWalkTime(-1), mMessageTime(0), - mShowIp(false) + mShowIp(false), + mAwayDialog(0), + mAfkTime(0), + mAwayMode(false) { listen(CHANNEL_ATTRIBUTES); + mAwayListener = new AwayListener(); + mUpdateName = true; setShowName(config.getValue("showownname", 1)); @@ -94,6 +99,8 @@ LocalPlayer::LocalPlayer(int id, int subtype): LocalPlayer::~LocalPlayer() { + delete mAwayDialog; + delete mAwayListener; } void LocalPlayer::logic() @@ -1110,3 +1117,58 @@ void LocalPlayer::event(Channels channel, const Mana::Event &event) Being::event(channel, event); } + +void LocalPlayer::changeAwayMode() +{ + mAwayMode = !mAwayMode; + mAfkTime = 0; + if (mAwayMode) + { + mAwayDialog = new OkDialog(_("Away"), + config.getValue("afkMessage", "I am away from keyboard")); + mAwayDialog->addActionListener(mAwayListener); + } + + mAwayDialog = 0; +} + +void LocalPlayer::setAway(const std::string &message) +{ + if (!message.empty()) + config.setValue("afkMessage", message); + changeAwayMode(); +} + +void LocalPlayer::afkRespond(ChatTab *tab, const std::string &nick) +{ + if (mAwayMode) + { + if (mAfkTime == 0 + || cur_time < mAfkTime + || cur_time - mAfkTime > AWAY_LIMIT_TIMER) + { + std::string msg = "*AFK*: " + + config.getValue("afkMessage", "I am away from keyboard"); + + Net::getChatHandler()->privateMessage(nick, msg); + if (!tab) + { + localChatTab->chatLog(getName() + " : " + msg, + ACT_WHISPER, false); + } + else + { + tab->chatLog(getName(), msg); + } + mAfkTime = cur_time; + } + } +} + +void AwayListener::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "ok" && player_node->getAwayMode()) + { + player_node->changeAwayMode(); + } +} -- cgit v1.2.3-70-g09d2