From 5e507c9829942c434a6f1ae7a4f3a488c7e50bef Mon Sep 17 00:00:00 2001 From: est31 Date: Sat, 25 Jul 2015 07:43:32 +0200 Subject: Add server side ncurses terminal This adds a chat console the server owner can use for administration or to talk with players. It runs in its own thread, which makes the user interface immune to the server's lag, behaving just like a client, except timeout. As it uses the same console code as the f10 console, things like nick completion or a scroll buffer basically come for free. The terminal itself is written in a general way so that adding a client version later on is just about implementing an interface. Fatal errors are printed after the console exists and the ncurses terminal buffer gets cleaned up with endwin(), so that the error still remains visible. The server owner can chose their username their entered text will have in chat and where players can send PMs to. Once the username is secured with a password to prevent anybody to take over the server, the owner can execute admin tasks over the console. This change includes a contribution by @kahrl who has improved ncurses library detection. --- src/network/serverpackethandler.cpp | 67 ++++--------------------------------- 1 file changed, 6 insertions(+), 61 deletions(-) (limited to 'src/network') diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index d9ff564da..3c446e31d 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -1059,69 +1059,14 @@ void Server::handleCommand_ChatMessage(NetworkPacket* pkt) return; } - // If something goes wrong, this player is to blame - RollbackScopeActor rollback_scope(m_rollback, - std::string("player:")+player->getName()); - // Get player name of this client - std::wstring name = narrow_to_wide(player->getName()); - - // Run script hook - bool ate = m_script->on_chat_message(player->getName(), - wide_to_narrow(message)); - // If script ate the message, don't proceed - if (ate) - return; - - // Line to send to players - std::wstring line; - // Whether to send to the player that sent the line - bool send_to_sender_only = false; - - // Commands are implemented in Lua, so only catch invalid - // commands that were not "eaten" and send an error back - if (message[0] == L'/') { - message = message.substr(1); - send_to_sender_only = true; - if (message.length() == 0) - line += L"-!- Empty command"; - else - line += L"-!- Invalid command: " + str_split(message, L' ')[0]; - } - else { - if (checkPriv(player->getName(), "shout")) { - line += L"<"; - line += name; - line += L"> "; - line += message; - } else { - line += L"-!- You don't have permission to shout."; - send_to_sender_only = true; - } - } + std::string name = player->getName(); + std::wstring wname = narrow_to_wide(name); - if (line != L"") - { - /* - Send the message to sender - */ - if (send_to_sender_only) { - SendChatMessage(pkt->getPeerId(), line); - } - /* - Send the message to others - */ - else { - actionstream << "CHAT: " << wide_to_narrow(line)< clients = m_clients.getClientIDs(); - - for (std::vector::iterator i = clients.begin(); - i != clients.end(); ++i) { - if (*i != pkt->getPeerId()) - SendChatMessage(*i, line); - } - } + std::wstring answer_to_sender = handleChat(name, wname, message, pkt->getPeerId()); + if (!answer_to_sender.empty()) { + // Send the answer to sender + SendChatMessage(pkt->getPeerId(), answer_to_sender); } } -- cgit v1.2.3