- dstream<<"CHAT: "<<wide_to_narrow(line)<<std::endl;
-
- /*
- Send the message to all other clients
- */
- for(core::map<u16, RemoteClient*>::Iterator
- i = m_clients.getIterator();
- i.atEnd() == false; i++)
+ // Line to send to players
+ std::wstring line;
+ // Whether to send to the player that sent the line
+ bool send_to_sender = false;
+ // Whether to send to other players
+ bool send_to_others = false;
+
+ // Parse commands
+ std::wstring commandprefix = L"/#";
+ if(message.substr(0, commandprefix.size()) == commandprefix)
+ {
+ line += L"Server: ";
+
+ message = message.substr(commandprefix.size());
+ // Get player name as narrow string
+ std::string name_s = player->getName();
+ // Convert message to narrow string
+ std::string message_s = wide_to_narrow(message);
+ // Operator is the single name defined in config.
+ std::string operator_name = g_settings.get("name");
+ bool is_operator = (operator_name != "" &&
+ wide_to_narrow(name) == operator_name);
+ bool valid_command = false;
+ if(message_s == "help")
+ {
+ line += L"-!- Available commands: ";
+ line += L"status ";
+ if(is_operator)
+ {
+ line += L"shutdown setting ";
+ }
+ else
+ {
+ }
+ send_to_sender = true;
+ valid_command = true;
+ }
+ else if(message_s == "status")
+ {
+ line = getStatusString();
+ send_to_sender = true;
+ valid_command = true;
+ }
+ else if(is_operator)
+ {
+ if(message_s == "shutdown")
+ {
+ dstream<<DTIME<<" Server: Operator requested shutdown."
+ <<std::endl;
+ m_shutdown_requested.set(true);
+
+ line += L"*** Server shutting down (operator request)";
+ send_to_sender = true;
+ valid_command = true;
+ }
+ else if(message_s.substr(0,8) == "setting ")
+ {
+ std::string confline = message_s.substr(8);
+ g_settings.parseConfigLine(confline);
+ line += L"-!- Setting changed.";
+ send_to_sender = true;
+ valid_command = true;
+ }
+ }
+
+ if(valid_command == false)
+ {
+ line += L"-!- Invalid command: " + message;
+ send_to_sender = true;
+ }
+ }
+ else