summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client.cpp1
-rw-r--r--src/client.h1
-rw-r--r--src/commandhandler.cpp9
-rw-r--r--src/commandhandler.h5
-rw-r--r--src/game.cpp2
-rw-r--r--src/gui/chat.cpp5
-rw-r--r--src/localplayer.cpp69
-rw-r--r--src/localplayer.h24
8 files changed, 115 insertions, 1 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 8debb559..44df362e 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -125,6 +125,7 @@ void ErrorListener::action(const gcn::ActionEvent &)
volatile int tick_time; /**< Tick counter */
volatile int fps = 0; /**< Frames counted in the last second */
volatile int frame_count = 0; /**< Counts the frames during one second */
+volatile int cur_time;
/**
* Advances game logic counter.
diff --git a/src/client.h b/src/client.h
index 233ee646..c120b248 100644
--- a/src/client.h
+++ b/src/client.h
@@ -50,6 +50,7 @@ static const short DEFAULT_PORT = 6901;
extern volatile int fps;
extern volatile int tick_time;
+extern volatile int cur_time;
class ErrorListener : public gcn::ActionListener
{
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index 8d70b717..80a3b99f 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -122,6 +122,10 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab)
{
handlePresent(args, tab);
}
+ else if (type == "away")
+ {
+ handleAway(args, tab);
+ }
else
{
tab->chatLog(_("Unknown command."));
@@ -507,3 +511,8 @@ void CommandHandler::handleUnignore(const std::string &args, ChatTab *tab)
else
tab->chatLog(_("Player could not be unignored!"), BY_SERVER);
}
+
+void CommandHandler::handleAway(const std::string &args, ChatTab *tab)
+{
+ player_node->setAway(args);
+}
diff --git a/src/commandhandler.h b/src/commandhandler.h
index dec554bb..c65c3670 100644
--- a/src/commandhandler.h
+++ b/src/commandhandler.h
@@ -142,6 +142,11 @@ class CommandHandler
* Handle an unignore command.
*/
void handleUnignore(const std::string &args, ChatTab *tab);
+
+ /**
+ * Handle away command.
+ */
+ void handleAway(const std::string &args, ChatTab *tab);
};
extern CommandHandler *commandHandler;
diff --git a/src/game.cpp b/src/game.cpp
index 88c74de6..79f21863 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -339,6 +339,8 @@ void Game::logic()
if (mCurrentMap)
mCurrentMap->update();
+ cur_time = time(NULL);
+
// Handle network stuff
if (!Net::getGameHandler()->isConnected())
{
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 8965ec70..d53bcf0a 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -456,9 +456,14 @@ void ChatWindow::whisper(const std::string &nick,
if (tab)
{
if (own)
+ {
tab->chatInput(mes);
+ }
else
+ {
tab->chatLog(nick, mes);
+ player_node->afkRespond(tab, nick);
+ }
}
else
{
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index ff7961b9..9729f55d 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -42,6 +42,7 @@
#include "gui/gui.h"
#include "gui/inventorywindow.h"
#include "gui/ministatus.h"
+#include "gui/okdialog.h"
#include "gui/skilldialog.h"
#include "gui/statuswindow.h"
#include "gui/theme.h"
@@ -49,6 +50,7 @@
#include "gui/widgets/chattab.h"
+#include "net/chathandler.h"
#include "net/guildhandler.h"
#include "net/inventoryhandler.h"
#include "net/net.h"
@@ -73,6 +75,8 @@
// TODO: This can fine tuned later on when running is added...
const short walkingKeyboardDelay = 1000;
+#define AWAY_LIMIT_TIMER 60
+
LocalPlayer *player_node = NULL;
LocalPlayer::LocalPlayer(int id, int subtype):
@@ -100,8 +104,13 @@ LocalPlayer::LocalPlayer(int id, int subtype):
mPathSetByMouse(false),
mInventory(new Inventory(Inventory::INVENTORY)),
mLocalWalkTime(-1),
- mMessageTime(0)
+ mMessageTime(0),
+ mAwayDialog(0),
+ mAfkTime(0),
+ mAwayMode(false)
{
+ mAwayListener = new AwayListener();
+
mUpdateName = true;
mTextColor = &Theme::getThemeColor(Theme::PLAYER);
@@ -1414,3 +1423,61 @@ void LocalPlayer::optionChanged(const std::string &value)
setShowName(config.getValue("showownname", 1));
}
}
+
+void LocalPlayer::changeAwayMode()
+{
+ mAwayMode = !mAwayMode;
+ mAfkTime = 0;
+ if (mAwayMode)
+ {
+ cancelFollow();
+ mAwayDialog = new OkDialog(_("Away"),
+ config.getValue("afkMessage", "I am away from keyboard"));
+ mAwayDialog->addActionListener(mAwayListener);
+ }
+ else
+ {
+ 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();
+ }
+} \ No newline at end of file
diff --git a/src/localplayer.h b/src/localplayer.h
index dd7b94d4..2c06dfb5 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -26,15 +26,19 @@
#include "gui/userpalette.h"
+#include <guichan/actionlistener.hpp>
+
#include <memory>
#include <vector>
+class ChatTab;
class Equipment;
class FloorItem;
class ImageSet;
class Inventory;
class Item;
class Map;
+class OkDialog;
struct Special
@@ -44,6 +48,12 @@ struct Special
int recharge;
};
+class AwayListener : public gcn::ActionListener
+{
+ public:
+ void action(const gcn::ActionEvent &event);
+};
+
/**
* Attributes used during combat. Available to all the beings.
@@ -352,6 +362,15 @@ class LocalPlayer : public Player
bool isPathSetByMouse() const
{ return mPathSetByMouse; }
+ void changeAwayMode();
+
+ bool getAwayMode()
+ { return mAwayMode; }
+
+ void setAway(const std::string &message);
+
+ void afkRespond(ChatTab *tab, const std::string &nick);
+
void addMessageToQueue(const std::string &message,
int color = UserPalette::EXP_INFO);
@@ -480,6 +499,11 @@ class LocalPlayer : public Player
/** Queued exp messages*/
std::list<MessagePair> mMessages;
int mMessageTime;
+ AwayListener *mAwayListener;
+ OkDialog *mAwayDialog;
+
+ int mAfkTime;
+ bool mAwayMode;
};
extern LocalPlayer *player_node;