From 3be4300f12d4e936a1beea0021b14cf6313ee3b9 Mon Sep 17 00:00:00 2001 From: David Athay Date: Tue, 8 Jul 2008 15:16:22 +0000 Subject: #359 patch by Scraggy --- src/gui/chat.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++----- src/gui/chat.h | 9 ++++++ 2 files changed, 92 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 5e3aaf60..2894bb70 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -275,13 +275,25 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) } else if (msg.substr(0, IS_HELP_LENGTH) == IS_HELP) { - chatLog("-- Help --", BY_SERVER); - chatLog("/help: Display this help.", BY_SERVER); - chatLog("/announce: Global announcement (GM only)", BY_SERVER); - chatLog("/where: Display map name", BY_SERVER); - chatLog("/who: Display number of online users", BY_SERVER); - chatLog("/clear: Clears this window", BY_SERVER); - chatLog("/whisper : Sends a private to ", BY_SERVER); + msg.erase(0, IS_HELP_LENGTH + 1); + trim(msg); + std::size_t space = msg.find(" "); + std::string msg1; + if (space == std::string::npos) + { + msg1 = ""; + } + else + { + msg1 = msg.substr(space + 1, msg.length()); + msg = msg.substr(0, space); + } + if (msg != "" && msg.at(0) == '/') + { + msg.erase(0, 1); + } + trim(msg1); + help(msg, msg1); } else if (msg.substr(0, IS_WHERE_LENGTH) == IS_WHERE) { @@ -469,3 +481,67 @@ ChatWindow::setVisible(bool isVisible) mTmpVisible = false; } +void ChatWindow::help(const std::string &msg1, const std::string &msg2) +{ + chatLog("-- Help --", BY_SERVER); + if (msg1 == "") + { + chatLog("/announce: Global announcement (GM only)", BY_SERVER); + chatLog("/clear: Clears this window", BY_SERVER); + chatLog("/help: Display this help.", BY_SERVER); + chatLog("/where: Display map name", BY_SERVER); + chatLog("/whisper : Sends a private " + " to ", BY_SERVER); + chatLog("/who: Display number of online users", BY_SERVER); + chatLog("For more information, type /help ", BY_SERVER); + return; + } + if (msg1 == "announce") + { + chatLog("Command: /announce ", BY_SERVER); + chatLog("*** only available to a GM ***", BY_SERVER); + chatLog("This command sends the message to " + "all players currently online.", BY_SERVER); + return; + } + if (msg1 == "clear") + { + chatLog("Command: /clear", BY_SERVER); + chatLog("This command clears the chat log of previous chat.", + BY_SERVER); + return; + } + if (msg1 == "help") + { + chatLog("Command: /help", BY_SERVER); + chatLog("This command displays a list of all commands available.", + BY_SERVER); + chatLog("Command: /help ", BY_SERVER); + chatLog("This command displays help on .", BY_SERVER); + return; + } + if (msg1 == "where") + { + chatLog("Command: /where", BY_SERVER); + chatLog("This command displays the name of the current map.", + BY_SERVER); + return; + } + if (msg1 == "whisper") + { + chatLog("Command: /whisper ", BY_SERVER); + chatLog("This command sends the message to has spaces in it, enclose it in " + "double quotes (\").", BY_SERVER); + return; + } + if (msg1 == "who") + { + chatLog("Command: /who", BY_SERVER); + chatLog("This command displays the number of players currently " + "online.", BY_SERVER); + return; + } + chatLog("Unknown command.", BY_SERVER); + chatLog("Type /help for a list of commands.", BY_SERVER); +} diff --git a/src/gui/chat.h b/src/gui/chat.h index 0bdc76f1..a1d659a0 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -208,6 +208,15 @@ class ChatWindow : public Window, public gcn::ActionListener, void scroll(int amount); + /** + * help implements the /help command + * + * @param msg1 is the command that the player needs help on + * @param msg2 is the sub-command relating to the command + */ + void + help(const std::string &msg1, const std::string &msg2); + private: Network *mNetwork; bool mTmpVisible; -- cgit v1.2.3-60-g2f50