mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
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.
This commit is contained in:
parent
1384108f8c
commit
5e507c9829
22 changed files with 1213 additions and 90 deletions
|
@ -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());
|
||||
std::string name = player->getName();
|
||||
std::wstring wname = narrow_to_wide(name);
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
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)<<std::endl;
|
||||
|
||||
std::vector<u16> clients = m_clients.getClientIDs();
|
||||
|
||||
for (std::vector<u16>::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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue