From 65ef705d73144167aa6e3eeef87fd55a691fc9e0 Mon Sep 17 00:00:00 2001 From: Eugenio Favalli Date: Tue, 3 Jan 2006 17:54:26 +0000 Subject: Enabled some /commands. --- src/game.cpp | 11 ++++++++++- src/gui/chat.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++------------ src/gui/chat.h | 8 ++++++-- src/net/protocol.h | 1 + 4 files changed, 59 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 37b2e995..7f873aef 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -196,7 +196,7 @@ void createGuiWindows() { // Create dialogs chatWindow = new ChatWindow( - config.getValue("homeDir", "") + std::string("/chatlog.txt")); + config.getValue("homeDir", "") + std::string("/chatlog.txt")); menuWindow = new MenuWindow(); statusWindow = new StatusWindow(); miniStatusWindow = new MiniStatusWindow(); @@ -1913,6 +1913,15 @@ void do_parse() being->setName(msg.readString(24)); } break; + + case SMSG_WHO_ANSWER: + { + std::stringstream userMsg; + userMsg << "Online users: "; + userMsg << msg.readInt32(); + chatWindow->chatLog(userMsg.str(), BY_SERVER); + } + break; case 0x0119: // Change in players look diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 91b6be91..748f4848 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -32,15 +32,16 @@ #include "chatinput.h" #include "scrollarea.h" -#include "../playerinfo.h" -#include "../log.h" - +#include "../game.h" #include "../graphics.h" -extern Graphics *graphics; +#include "../log.h" +#include "../playerinfo.h" #include "../net/messageout.h" #include "../net/protocol.h" +extern Graphics *graphics; + ChatWindow::ChatWindow(const std::string &logfile): Window(""), mTmpVisible(false) @@ -194,7 +195,6 @@ ChatWindow::action(const std::string& eventId) if (eventId == "chatinput") { std::string message = chatInput->getText(); - printf("Message: %s\n", message.c_str()); if (message.length() > 0) { // If message different from previous, put it in the history @@ -253,20 +253,50 @@ ChatWindow::isFocused() void ChatWindow::chatSend(std::string nick, std::string msg) { - short packetId = CMSG_CHAT_MESSAGE; - - // prepare command - if (msg.substr(0, 1) == "/") { - // prepare ordinary message - chatLog("Sorry but /commands are not available yet", BY_SERVER); + // Prepare command + if (msg.substr(0, 1) == "/") + { + /* Some messages are managed client side, while others + * require server handling by proper packet. Probably + * those if elses should be replaced by protocol calls */ + if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) + { + msg.erase(0, IS_ANNOUNCE_LENGTH); + MessageOut outMsg; + outMsg.writeInt16(0x0099); + outMsg.writeInt16(msg.length() + 4); + outMsg.writeString(msg, msg.length()); + } + 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); + } + else if (msg.substr(0, IS_WHERE_LENGTH) == IS_WHERE) + { + chatLog(map_path, BY_SERVER); + } + else if (msg.substr(0, IS_WHO_LENGTH) == IS_WHO) + { + MessageOut outMsg; + outMsg.writeInt16(0x00c1); + } + else + { + chatLog("Unknown command", BY_SERVER); + } } + // Prepare ordinary message else { nick += " : "; nick += msg; msg = nick; MessageOut outMsg; - outMsg.writeInt16(packetId); + outMsg.writeInt16(CMSG_CHAT_MESSAGE); outMsg.writeInt16(msg.length() + 4); outMsg.writeString(msg, msg.length()); } diff --git a/src/gui/chat.h b/src/gui/chat.h index 80189665..5b470e27 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -48,8 +48,12 @@ class ScrollArea; #define IS_ANNOUNCE "/announce " #define IS_ANNOUNCE_LENGTH 10 -#define IS_WHERE "/where " -#define IS_WHERE_LENGTH 7 +#define IS_HELP "/help" +#define IS_HELP_LENGTH 5 +#define IS_WHERE "/where" +#define IS_WHERE_LENGTH 6 +#define IS_WHO "/who" +#define IS_WHO_LENGTH 4 /** * gets in between usernick and message text depending on diff --git a/src/net/protocol.h b/src/net/protocol.h index 8ac0f16d..e7d6f286 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -39,6 +39,7 @@ class Being; #define SMSG_PLAYER_STAT_UPDATE_4 0x00bc #define SMSG_PLAYER_STAT_UPDATE_5 0x00bd #define SMSG_PLAYER_STAT_UPDATE_6 0x00be +#define SMSG_WHO_ANSWER 0x00c2 #define SMSG_PLAYER_WARP 0x0091 /**< Warp player to map/location */ #define SMSG_PLAYER_INVENTORY 0x01ee #define SMSG_PLAYER_INVENTORY_ADD 0x00a0 -- cgit v1.2.3-70-g09d2