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 all commits
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
10 changes: 0 additions & 10 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 @@ -292,15 +291,6 @@ bool ConfigManager::load()
return true;
}

bool ConfigManager::reload()
{
bool result = load();
if (transformToSHA1(getString(ConfigManager::MOTD)) != g_game.getMotdHash()) {
g_game.incrementMotdNum();
}
return result;
}

static std::string dummyStr;

const std::string& ConfigManager::getString(string_config_t what) const
Expand Down
2 changes: 0 additions & 2 deletions 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 Expand Up @@ -124,7 +123,6 @@ class ConfigManager
};

bool load();
bool reload();

const std::string& getString(string_config_t what) const;
int32_t getNumber(integer_config_t what) const;
Expand Down
35 changes: 2 additions & 33 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 Expand Up @@ -5743,7 +5712,7 @@ bool Game::reload(ReloadTypes_t reloadType)
switch (reloadType) {
case RELOAD_TYPE_ACTIONS: return g_actions->reload();
case RELOAD_TYPE_CHAT: return g_chat->load();
case RELOAD_TYPE_CONFIG: return g_config.reload();
case RELOAD_TYPE_CONFIG: return g_config.load();
case RELOAD_TYPE_CREATURESCRIPTS: {
g_creatureEvents->reload();
g_creatureEvents->removeInvalidEvents();
Expand Down Expand Up @@ -5817,7 +5786,7 @@ bool Game::reload(ReloadTypes_t reloadType)
}

g_actions->reload();
g_config.reload();
g_config.load();
g_creatureEvents->reload();
g_monsters.reload();
g_moveEvents->reload();
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: 2 additions & 2 deletions src/protocolstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void ProtocolStatus::sendStatusString()
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();
motd.text() = "N/A";

std::ostringstream ss;
doc.save(ss, "", pugi::format_raw);
Expand Down Expand Up @@ -160,7 +160,7 @@ 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("N/A"); //MOTD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// MOTD

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't worry, @ranisalt clang will fix that in the future I hope

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
2 changes: 1 addition & 1 deletion src/signals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void sighupHandler()
g_actions->reload();
std::cout << "Reloaded actions." << std::endl;

g_config.reload();
g_config.load();
std::cout << "Reloaded config." << std::endl;

g_creatureEvents->reload();
Expand Down