From 153f07fdfb60ddfeeb3bdb59e5f061e870334d3a Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 13 Aug 2011 17:09:23 +0200 Subject: [PATCH 1/7] Remove distinction between /# and / commands No need to make the server command syntax more complicated than necessary. If the need ever arise, we'll find some other way to distinguish the client commands. Also, the /# syntax is deprecated and will be made obsolete in time. --- src/game.cpp | 12 ------------ src/server.cpp | 8 +++++--- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index ab385213..22fab706 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -114,18 +114,6 @@ struct TextDestChat : public TextDest // Discard empty line if(text == L"") return; - - // Parse command (server command starts with "/#") - if(text[0] == L'/' && text[1] != L'#') - { - std::wstring reply = L"Local: "; - - reply += L"Local commands not yet supported. " - L"Server prefix is \"/#\"."; - - m_client->addChatMessage(reply); - return; - } // Send to others m_client->sendChatMessage(text); diff --git a/src/server.cpp b/src/server.cpp index 5b657bc2..1f33a66f 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3245,12 +3245,14 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) u64 privs = getPlayerPrivs(player); // Parse commands - std::wstring commandprefix = L"/#"; - if(message.substr(0, commandprefix.size()) == commandprefix) + if(message[0] == L'/') { line += L"Server: "; - message = message.substr(commandprefix.size()); + size_t strip_size = 1; + if (message[1] == L'#') // support old-style commans + ++strip_size; + message = message.substr(strip_size); WStrfnd f1(message); f1.next(L" "); // Skip over /#whatever From d2c0b4905abd895b87d5ed9b8769b1a60d692970 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 13 Aug 2011 17:35:10 +0200 Subject: [PATCH 2/7] Defines for server command context flags --- src/server.cpp | 4 ++-- src/servercommand.cpp | 4 ++-- src/servercommand.h | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 1f33a66f..fabfbc84 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3267,8 +3267,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) privs); line += processServerCommand(ctx); - send_to_sender = ctx->flags & 1; - send_to_others = ctx->flags & 2; + send_to_sender = ctx->flags & SEND_TO_SENDER; + send_to_others = ctx->flags & SEND_TO_OTHERS; delete ctx; } diff --git a/src/servercommand.cpp b/src/servercommand.cpp index 663693b9..31f18c53 100644 --- a/src/servercommand.cpp +++ b/src/servercommand.cpp @@ -130,7 +130,7 @@ void cmd_shutdown(std::wostringstream &os, ctx->server->requestShutdown(); os<flags |= 2; + ctx->flags |= SEND_TO_OTHERS; } void cmd_setting(std::wostringstream &os, @@ -232,7 +232,7 @@ std::wstring processServerCommand(ServerCommandContext *ctx) { std::wostringstream os(std::ios_base::binary); - ctx->flags = 1; // Default, unless we change it. + ctx->flags = SEND_TO_SENDER; // Default, unless we change it. u64 privs = ctx->privs; diff --git a/src/servercommand.h b/src/servercommand.h index cee4976b..15679f33 100644 --- a/src/servercommand.h +++ b/src/servercommand.h @@ -25,9 +25,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "player.h" #include "server.h" +#define SEND_TO_SENDER (1<<0) +#define SEND_TO_OTHERS (1<<1) + struct ServerCommandContext { - std::vector parms; std::wstring paramstring; Server* server; From da19aee307221dd2e6bdd00393124587654d0206 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 13 Aug 2011 17:37:31 +0200 Subject: [PATCH 3/7] Server now supports replies without prefix --- src/server.cpp | 12 ++++++++---- src/servercommand.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index fabfbc84..f6659204 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3247,13 +3247,11 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) // Parse commands if(message[0] == L'/') { - line += L"Server: "; - size_t strip_size = 1; if (message[1] == L'#') // support old-style commans ++strip_size; message = message.substr(strip_size); - + WStrfnd f1(message); f1.next(L" "); // Skip over /#whatever std::wstring paramstring = f1.next(L""); @@ -3266,9 +3264,15 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) player, privs); - line += processServerCommand(ctx); + std::wstring reply(processServerCommand(ctx)); send_to_sender = ctx->flags & SEND_TO_SENDER; send_to_others = ctx->flags & SEND_TO_OTHERS; + + if (ctx->flags & SEND_NO_PREFIX) + line += reply; + else + line += L"Server: " + reply; + delete ctx; } diff --git a/src/servercommand.h b/src/servercommand.h index 15679f33..648a5733 100644 --- a/src/servercommand.h +++ b/src/servercommand.h @@ -27,6 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define SEND_TO_SENDER (1<<0) #define SEND_TO_OTHERS (1<<1) +#define SEND_NO_PREFIX (1<<2) struct ServerCommandContext { From 0488bf54d3f0b767eb53a026b4b52de86cfbd4ab Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 13 Aug 2011 17:41:18 +0200 Subject: [PATCH 4/7] /me command --- src/servercommand.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/servercommand.cpp b/src/servercommand.cpp index 31f18c53..89ba0771 100644 --- a/src/servercommand.cpp +++ b/src/servercommand.cpp @@ -25,6 +25,14 @@ void cmd_status(std::wostringstream &os, os<server->getStatusString(); } +void cmd_me(std::wostringstream &os, + ServerCommandContext *ctx) +{ + std::wstring name = narrow_to_wide(ctx->player->getName()); + os << L"* " << name << L" " << ctx->paramstring; + ctx->flags |= SEND_TO_OTHERS | SEND_NO_PREFIX; +} + void cmd_privs(std::wostringstream &os, ServerCommandContext *ctx) { @@ -283,6 +291,10 @@ std::wstring processServerCommand(ServerCommandContext *ctx) { cmd_banunban(os, ctx); } + else if(ctx->parms[0] == L"me") + { + cmd_me(os, ctx); + } else { os<parms[0]; From 42134bb49eaa5116838a2c188c432c8b9420dff8 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 13 Aug 2011 18:56:15 +0200 Subject: [PATCH 5/7] Send KEY_END when (re)creating a text input This ensures that on creation and when resizing the cursor is at the end of the text rather than at the beginnig. --- src/guiTextInputMenu.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/guiTextInputMenu.cpp b/src/guiTextInputMenu.cpp index bfe0ea5d..208ced80 100644 --- a/src/guiTextInputMenu.cpp +++ b/src/guiTextInputMenu.cpp @@ -103,6 +103,12 @@ void GUITextInputMenu::regenerateGui(v2u32 screensize) gui::IGUIElement *e = Environment->addEditBox(text.c_str(), rect, true, this, 256); Environment->setFocus(e); + + irr::SEvent evt; + evt.EventType = EET_KEY_INPUT_EVENT; + evt.KeyInput.Key = KEY_END; + evt.KeyInput.PressedDown = true; + e->OnEvent(evt); } changeCtype(""); { From 53eedd3ba4029d7f4154477c3492748bb4f6e4e5 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 13 Aug 2011 18:16:49 +0200 Subject: [PATCH 6/7] Introduce hotkey for calling up a command window This is just a chat window with the / text pre-loaded. --- src/defaultsettings.cpp | 1 + src/game.cpp | 8 ++++++++ src/guiKeyChangeMenu.cpp | 30 ++++++++++++++++++++++++++++++ src/guiKeyChangeMenu.h | 3 +++ 4 files changed, 42 insertions(+) diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 26599785..8438bf4f 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -39,6 +39,7 @@ void set_default_settings() g_settings.setDefault("keymap_sneak", "KEY_LSHIFT"); g_settings.setDefault("keymap_inventory", "KEY_KEY_I"); g_settings.setDefault("keymap_chat", "KEY_KEY_T"); + g_settings.setDefault("keymap_cmd", "/"); g_settings.setDefault("keymap_rangeselect", "KEY_KEY_R"); g_settings.setDefault("keymap_freemove", "KEY_KEY_K"); g_settings.setDefault("keymap_fastmove", "KEY_KEY_J"); diff --git a/src/game.cpp b/src/game.cpp index 22fab706..dd1e58b4 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1320,6 +1320,14 @@ void the_game( &g_menumgr, dest, L""))->drop(); } + else if(input->wasKeyDown(getKeySetting("keymap_cmd"))) + { + TextDest *dest = new TextDestChat(&client); + + (new GUITextInputMenu(guienv, guiroot, -1, + &g_menumgr, dest, + L"/"))->drop(); + } else if(input->wasKeyDown(getKeySetting("keymap_freemove"))) { if(g_settings.getBool("free_move")) diff --git a/src/guiKeyChangeMenu.cpp b/src/guiKeyChangeMenu.cpp index 5968d5c1..d6de1149 100644 --- a/src/guiKeyChangeMenu.cpp +++ b/src/guiKeyChangeMenu.cpp @@ -226,6 +226,21 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize) this->chat = Environment->addButton(rect, this, GUI_ID_KEY_CHAT_BUTTON, wgettext(key_chat.name())); } + offset += v2s32(0, 25); + { + core::rect < s32 > rect(0, 0, 100, 20); + rect += topleft + v2s32(offset.X, offset.Y); + Environment->addStaticText(wgettext("Command"), rect, false, true, this, -1); + //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT); + } + + { + core::rect < s32 > rect(0, 0, 100, 30); + rect += topleft + v2s32(offset.X + 105, offset.Y - 5); + this->cmd = Environment->addButton(rect, this, GUI_ID_KEY_CMD_BUTTON, + wgettext(key_cmd.name())); + } + //next col offset = v2s32(250, 40); @@ -333,6 +348,7 @@ bool GUIKeyChangeMenu::acceptInput() g_settings.set("keymap_sneak", key_sneak.sym()); g_settings.set("keymap_inventory", key_inventory.sym()); g_settings.set("keymap_chat", key_chat.sym()); + g_settings.set("keymap_cmd", key_cmd.sym()); g_settings.set("keymap_rangeselect", key_range.sym()); g_settings.set("keymap_freemove", key_fly.sym()); g_settings.set("keymap_fastmove", key_fast.sym()); @@ -351,6 +367,7 @@ void GUIKeyChangeMenu::init_keys() key_sneak = getKeySetting("keymap_sneak"); key_inventory = getKeySetting("keymap_inventory"); key_chat = getKeySetting("keymap_chat"); + key_cmd = getKeySetting("keymap_cmd"); key_range = getKeySetting("keymap_rangeselect"); key_fly = getKeySetting("keymap_freemove"); key_fast = getKeySetting("keymap_fastmove"); @@ -391,6 +408,9 @@ bool GUIKeyChangeMenu::resetMenu() case GUI_ID_KEY_CHAT_BUTTON: this->chat->setText(wgettext(key_chat.name())); break; + case GUI_ID_KEY_CMD_BUTTON: + this->cmd->setText(wgettext(key_cmd.name())); + break; case GUI_ID_KEY_RANGE_BUTTON: this->range->setText(wgettext(key_range.name())); break; @@ -460,6 +480,11 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event) this->chat->setText(wgettext(kp.name())); this->key_chat = kp; } + else if (activeKey == GUI_ID_KEY_CMD_BUTTON) + { + this->cmd->setText(wgettext(kp.name())); + this->key_cmd = kp; + } else if (activeKey == GUI_ID_KEY_RANGE_BUTTON) { this->range->setText(wgettext(kp.name())); @@ -564,6 +589,11 @@ bool GUIKeyChangeMenu::OnEvent(const SEvent& event) activeKey = event.GUIEvent.Caller->getID(); this->chat->setText(wgettext("press Key")); break; + case GUI_ID_KEY_CMD_BUTTON: + resetMenu(); + activeKey = event.GUIEvent.Caller->getID(); + this->cmd->setText(wgettext("press Key")); + break; case GUI_ID_KEY_SNEAK_BUTTON: resetMenu(); activeKey = event.GUIEvent.Caller->getID(); diff --git a/src/guiKeyChangeMenu.h b/src/guiKeyChangeMenu.h index a1dfa17c..2e8773a7 100644 --- a/src/guiKeyChangeMenu.h +++ b/src/guiKeyChangeMenu.h @@ -43,6 +43,7 @@ enum GUI_ID_KEY_FAST_BUTTON, GUI_ID_KEY_JUMP_BUTTON, GUI_ID_KEY_CHAT_BUTTON, + GUI_ID_KEY_CMD_BUTTON, GUI_ID_KEY_SNEAK_BUTTON, GUI_ID_KEY_INVENTORY_BUTTON, GUI_ID_KEY_DUMP_BUTTON, @@ -87,6 +88,7 @@ private: gui::IGUIButton *range; gui::IGUIButton *dump; gui::IGUIButton *chat; + gui::IGUIButton *cmd; s32 activeKey; KeyPress key_forward; @@ -101,6 +103,7 @@ private: KeyPress key_fast; KeyPress key_range; KeyPress key_chat; + KeyPress key_cmd; KeyPress key_dump; }; From 9c94538fb7a7d7712d8da21d16790359a853f575 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Mon, 22 Aug 2011 13:43:53 +0200 Subject: [PATCH 7/7] Change way commands are displayed in chat window --- src/client.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/client.h b/src/client.h index 963eb670..1a7ef924 100644 --- a/src/client.h +++ b/src/client.h @@ -270,6 +270,12 @@ public: void addChatMessage(const std::wstring &message) { + if (message[0] == L'/') { + m_chat_queue.push_back( + (std::wstring)L"issued command: "+message); + return; + } + //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL);