Allow specify motd with .txt file
This commit is contained in:
19
src/main.cpp
19
src/main.cpp
@@ -598,7 +598,7 @@ void cmdLineHelp()
|
||||
" --disable-lan Disable LAN detection (connect using WAN).\n"
|
||||
" --auto-connect Automatically connect to fist server and start race\n"
|
||||
" --max-players=n Maximum number of clients (server only).\n"
|
||||
" --motd Message showing in all lobby of clients.\n"
|
||||
" --motd Message showing in all lobby of clients, can specify a .txt file.\n"
|
||||
" --no-validation Allow non validated and unencrypted connection in wan.\n"
|
||||
" --ranked Server will submit ranking to stk addons server.\n"
|
||||
" You require permission for that.\n"
|
||||
@@ -1065,7 +1065,22 @@ int handleCmdLine()
|
||||
|
||||
if (CommandLine::has("--motd", &s))
|
||||
{
|
||||
core::stringw motd = StringUtils::xmlDecode(s);
|
||||
core::stringw motd;
|
||||
if (s.find(".txt") != std::string::npos)
|
||||
{
|
||||
std::ifstream message(s);
|
||||
if (message.is_open())
|
||||
{
|
||||
for (std::string line; std::getline(message, line); )
|
||||
{
|
||||
motd += StringUtils::utf8ToWide(line).trim() + L"\n";
|
||||
}
|
||||
// Remove last newline
|
||||
motd.erase(motd.size() - 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
motd = StringUtils::xmlDecode(s);
|
||||
NetworkConfig::get()->setMOTD(motd);
|
||||
}
|
||||
if (CommandLine::has("--ranked"))
|
||||
|
||||
@@ -143,7 +143,7 @@ void GameSetup::addServerInfo(NetworkString* ns)
|
||||
ns->addFloat(0.0f).addFloat(0.0f);
|
||||
ns->addUInt8(NetworkConfig::get()->getMaxPlayers());
|
||||
|
||||
ns->encodeString(NetworkConfig::get()->getMOTD());
|
||||
ns->encodeString16(NetworkConfig::get()->getMOTD());
|
||||
} // addServerInfo
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -143,10 +143,10 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
BareNetworkString& encodeString16(const irr::core::stringw& value)
|
||||
{
|
||||
uint8_t str_len = (uint8_t)value.size();
|
||||
if (value.size() > 255)
|
||||
str_len = 255;
|
||||
addUInt8(str_len);
|
||||
uint16_t str_len = (uint16_t)value.size();
|
||||
if (value.size() > 65535)
|
||||
str_len = 65535;
|
||||
addUInt16(str_len);
|
||||
for (unsigned i = 0; i < str_len; i++)
|
||||
addUInt16((uint16_t)value[i]);
|
||||
return *this;
|
||||
@@ -154,13 +154,13 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
int decodeString16(irr::core::stringw* out) const
|
||||
{
|
||||
unsigned str_len = getUInt8();
|
||||
uint16_t str_len = getUInt16();
|
||||
for (unsigned i = 0; i < str_len; i++)
|
||||
{
|
||||
uint16_t c = getUInt16();
|
||||
out->append((wchar_t)c);
|
||||
}
|
||||
return str_len + 1;
|
||||
return str_len + 2;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
BareNetworkString& encodeString(const std::string &value);
|
||||
|
||||
@@ -531,9 +531,10 @@ void ClientLobby::handleServerInfo(Event* event)
|
||||
start_threshold, start_timeout, max_player);
|
||||
|
||||
// MOTD
|
||||
data.decodeStringW(&str);
|
||||
if (!str.empty())
|
||||
NetworkingLobby::getInstance()->addMoreServerInfo(str);
|
||||
core::stringw motd;
|
||||
data.decodeString16(&motd);
|
||||
if (!motd.empty())
|
||||
NetworkingLobby::getInstance()->addMoreServerInfo(motd);
|
||||
|
||||
} // handleServerInfo
|
||||
|
||||
|
||||
Reference in New Issue
Block a user