Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed MOTD #4057

Merged
merged 3 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ loginProtocolPort = 7171
gameProtocolPort = 7172
statusProtocolPort = 7171
maxPlayers = 0
motd = "Welcome to The Forgotten Server!"
onePlayerOnlinePerAccount = true
allowClones = false
allowWalkthrough = true
Expand Down
5 changes: 4 additions & 1 deletion data/migrations/32.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
function onUpdateDatabase()
return false
print("> Updating database to version 32 (removed MOTD)")
db.query("DELETE FROM `server_config` WHERE `config` = 'motd_num'")
db.query("DELETE FROM `server_config` WHERE `config` = 'motd_hash'")
return true
end
3 changes: 3 additions & 0 deletions data/migrations/33.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function onUpdateDatabase()
return false
end
2 changes: 1 addition & 1 deletion schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ CREATE TABLE IF NOT EXISTS `towns` (
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;

INSERT INTO `server_config` (`config`, `value`) VALUES ('db_version', '31'), ('motd_hash', ''), ('motd_num', '0'), ('players_record', '0');
INSERT INTO `server_config` (`config`, `value`) VALUES ('db_version', '32'), ('players_record', '0');

DROP TRIGGER IF EXISTS `ondelete_players`;
DROP TRIGGER IF EXISTS `oncreate_guilds`;
Expand Down
4 changes: 0 additions & 4 deletions src/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ bool ConfigManager::load()
string[OWNER_EMAIL] = getGlobalString(L, "ownerEmail", "");
string[URL] = getGlobalString(L, "url", "");
string[LOCATION] = getGlobalString(L, "location", "");
string[MOTD] = getGlobalString(L, "motd", "");
string[WORLD_TYPE] = getGlobalString(L, "worldType", "pvp");

integer[MAX_PLAYERS] = getGlobalNumber(L, "maxPlayers");
Expand Down Expand Up @@ -295,9 +294,6 @@ bool ConfigManager::load()
bool ConfigManager::reload()
{
bool result = load();
if (transformToSHA1(getString(ConfigManager::MOTD)) != g_game.getMotdHash()) {
g_game.incrementMotdNum();
}
return result;
EPuncker marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
1 change: 0 additions & 1 deletion src/configmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class ConfigManager
URL,
LOCATION,
IP,
MOTD,
WORLD_TYPE,
MYSQL_HOST,
MYSQL_USER,
Expand Down
31 changes: 0 additions & 31 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ void Game::setGameState(GameState_t newState)
quests.loadFromXml();
mounts.loadFromXml();

loadMotdNum();
loadPlayersRecord();
loadAccountStorageValues();

Expand All @@ -133,7 +132,6 @@ void Game::setGameState(GameState_t newState)
it = players.begin();
}

saveMotdNum();
saveGameState();

g_dispatcher.addTask(
Expand Down Expand Up @@ -4796,35 +4794,6 @@ void Game::updatePlayerShield(Player* player)
}
}

void Game::loadMotdNum()
{
Database& db = Database::getInstance();

DBResult_ptr result = db.storeQuery("SELECT `value` FROM `server_config` WHERE `config` = 'motd_num'");
if (result) {
motdNum = result->getNumber<uint32_t>("value");
} else {
db.executeQuery("INSERT INTO `server_config` (`config`, `value`) VALUES ('motd_num', '0')");
}

result = db.storeQuery("SELECT `value` FROM `server_config` WHERE `config` = 'motd_hash'");
if (result) {
motdHash = result->getString("value");
if (motdHash != transformToSHA1(g_config.getString(ConfigManager::MOTD))) {
++motdNum;
}
} else {
db.executeQuery("INSERT INTO `server_config` (`config`, `value`) VALUES ('motd_hash', '')");
}
}

void Game::saveMotdNum() const
{
Database& db = Database::getInstance();
db.executeQuery(fmt::format("UPDATE `server_config` SET `value` = '{:d}' WHERE `config` = 'motd_num'", motdNum));
db.executeQuery(fmt::format("UPDATE `server_config` SET `value` = '{:s}' WHERE `config` = 'motd_hash'", transformToSHA1(g_config.getString(ConfigManager::MOTD))));
}

void Game::checkPlayersRecord()
{
const size_t playersOnline = getPlayersOnline();
Expand Down
9 changes: 0 additions & 9 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,6 @@ class Game
int16_t getWorldTime() { return worldTime; }
void updateWorldTime();

void loadMotdNum();
void saveMotdNum() const;
const std::string& getMotdHash() const { return motdHash; }
uint32_t getMotdNum() const { return motdNum; }
void incrementMotdNum() { motdNum++; }

void sendOfflineTrainingDialog(Player* player);

const std::unordered_map<uint32_t, Player*>& getPlayers() const { return players; }
Expand Down Expand Up @@ -584,9 +578,6 @@ class Game
void updatePlayersRecord() const;
uint32_t playersRecord = 0;

std::string motdHash;
uint32_t motdNum = 0;

uint32_t lastStageLevel = 0;
bool stagesEnabled = false;
bool useLastStageLevel = false;
Expand Down
3 changes: 1 addition & 2 deletions src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2111,7 +2111,6 @@ void LuaScriptInterface::registerFunctions()
registerEnumIn("configKeys", ConfigManager::URL)
registerEnumIn("configKeys", ConfigManager::LOCATION)
registerEnumIn("configKeys", ConfigManager::IP)
registerEnumIn("configKeys", ConfigManager::MOTD)
registerEnumIn("configKeys", ConfigManager::WORLD_TYPE)
registerEnumIn("configKeys", ConfigManager::MYSQL_HOST)
registerEnumIn("configKeys", ConfigManager::MYSQL_USER)
Expand Down Expand Up @@ -12858,7 +12857,7 @@ int LuaScriptInterface::luaItemTypeGetAbilities(lua_State* L)
lua_rawseti(L, -2, i + 1);
}
lua_setfield(L, -2, "specialMagicLevel");

// Damage boost percent
lua_createtable(L, 0, COMBAT_COUNT);
for (int32_t i = 0; i < COMBAT_COUNT; i++) {
Expand Down
7 changes: 0 additions & 7 deletions src/protocollogin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ void ProtocolLogin::getCharacterList(const std::string& accountName, const std::
output->addByte(0);
}

const std::string& motd = g_config.getString(ConfigManager::MOTD);
if (!motd.empty()) {
//Add MOTD
output->addByte(0x14);
output->addString(fmt::format("{:d}\n{:s}", g_game.getMotdNum(), motd));
}

//Add session key
output->addByte(0x28);
output->addString(accountName + "\n" + password + "\n" + token + "\n" + std::to_string(ticks));
Expand Down
4 changes: 0 additions & 4 deletions src/protocolstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ void ProtocolStatus::sendStatusString()
map.append_attribute("width") = std::to_string(mapWidth).c_str();
map.append_attribute("height") = std::to_string(mapHeight).c_str();

pugi::xml_node motd = tsqp.append_child("motd");
motd.text() = g_config.getString(ConfigManager::MOTD).c_str();

EPuncker marked this conversation as resolved.
Show resolved Hide resolved
std::ostringstream ss;
doc.save(ss, "", pugi::format_raw);

Expand Down Expand Up @@ -160,7 +157,6 @@ void ProtocolStatus::sendInfo(uint16_t requestedInfo, const std::string& charact

if (requestedInfo & REQUEST_MISC_SERVER_INFO) {
output->addByte(0x12);
output->addString(g_config.getString(ConfigManager::MOTD));
EPuncker marked this conversation as resolved.
Show resolved Hide resolved
output->addString(g_config.getString(ConfigManager::LOCATION));
output->addString(g_config.getString(ConfigManager::URL));
output->add<uint64_t>((OTSYS_TIME() - ProtocolStatus::start) / 1000);
Expand Down