Skip to content

Commit

Permalink
* update
Browse files Browse the repository at this point in the history
  • Loading branch information
jprzimba committed Jan 30, 2025
2 parents b453256 + 7c4017a commit fed60a5
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
16 changes: 16 additions & 0 deletions data/migrations/51.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function onUpdateDatabase()
logger.info("Updating database to version 51 (Player Old Names)")

db.query([[
CREATE TABLE `player_oldnames` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`player_id` int(11) NOT NULL,
`former_name` varchar(255) NOT NULL DEFAULT '',
`name` varchar(255) NOT NULL,
`old_name` varchar(255) NOT NULL,
`date` int(11) NOT NULL,
PRIMARY KEY (`id`),
INDEX `player_id_index` (`player_id`)
)
]])
end
5 changes: 4 additions & 1 deletion markdowns/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
- Added Vibrancy imbuement. ([pennaor](https://github.com/pennaor))
- Added Soul Pit arena/animus mastery/soul core. ([FelipePaluco](https://github.com/FelipePaluco))
- Added a new command `/mute`, which will mute a player until unmuted by `/unmute`. ([Tryller](https://github.com/jprzimba))
- Cyclopedia House Auction system. ([murilo09](https://github.com/murilo09))
- Updated name change functionality to save old player names in a database table called `player_oldnames`. ([Tryller](https://github.com/jprzimba))

## Added files

- data/migrations/49.lua
- data/migrations/50.lua
- data/migrations/51.lua
- data-global/lib/others/soulpit.lua
- data-global/startup/tables/tile.lua
- data-global/npc/myzzi.lua
Expand Down Expand Up @@ -73,7 +77,6 @@
- Add new configurable featurees in `config.lua`: `chainSystemVipOnly`, `fieldOwnershipDuration`, `bedsOnlyPremium`, `loginProtectionPeriod`, `chainSystemModifyMagic`, `logPlayersStatements`. ([Tryller](https://github.com/jprzimba))
- Added a new commands for players: `!randomoutfit`, `!spellwords`. ([Tryller](https://github.com/jprzimba))
- Moved emote spells to `kv` instead of `storage`. ([Tryller](https://github.com/jprzimba))
- Cyclopedia House Auction system. ([murilo09](https://github.com/murilo09))
- Updated npcs and spells from 13.40 updates. ([murilo09](https://github.com/murilo09))
- Added a Rook system with configurations in `config.lua`. ([Tryller](https://github.com/jprzimba))
- Added a new group `game tester` with flag `isgametester` in `groups.xml` and a new player flag `PlayerFlag_IsGameTester`. ([Tryller](https://github.com/jprzimba))
Expand Down
35 changes: 35 additions & 0 deletions src/io/functions/iologindata_save_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "creatures/monsters/monsters.hpp"
#include "creatures/players/animus_mastery/animus_mastery.hpp"
#include "game/game.hpp"
#include "game/scheduling/save_manager.hpp"
#include "io/ioprey.hpp"
#include "items/containers/depot/depotchest.hpp"
#include "items/containers/inbox/inbox.hpp"
Expand Down Expand Up @@ -838,3 +839,37 @@ bool IOLoginDataSave::savePlayerStatement(const std::shared_ptr<Player> &player,
statementId = db.getLastInsertId();
return true;
}

bool IOLoginDataSave::savePlayerNamesAndChangeName(const std::shared_ptr<Player> &player, const std::string &newName, const std::string &oldName) {
if (!player) {
g_logger().warn("[IOLoginData::savePlayerStatement] - Player nullptr: {}", __FUNCTION__);
return false;
}

Database &db = Database::getInstance();
std::ostringstream query;

const time_t now = time(nullptr);

// find former name
std::string formerName = oldName;
auto result = db.storeQuery(fmt::format("SELECT `former_name` FROM `player_oldnames` WHERE `player_id` = {} LIMIT 1", player->getGUID()));
if (result) {
formerName = result->getString("former_name");
}

query << "INSERT INTO `player_oldnames` (`player_id`, `former_name`, `name`, `old_name`, `date`) VALUES ("
<< player->getGUID() << ", " << db.escapeString(formerName) << ", " << db.escapeString(newName) << ", " << db.escapeString(oldName) << ", " << now << ")";

if (!db.executeQuery(query.str())) {
return false;
}

if (player->isOnline()) {
player->removePlayer(true, true);
}

player->setName(newName);
g_saveManager().savePlayer(player);
return true;
}
1 change: 1 addition & 0 deletions src/io/functions/iologindata_save_player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class IOLoginDataSave : public IOLoginData {
static bool savePlayerBosstiary(const std::shared_ptr<Player> &player);
static bool savePlayerStorage(const std::shared_ptr<Player> &player);
static bool savePlayerStatement(const std::shared_ptr<Player> &player, const std::string &receiver, uint16_t channelId, const std::string &text, uint32_t &statementId);
static bool savePlayerNamesAndChangeName(const std::shared_ptr<Player> &player, const std::string &newName, const std::string &oldName);

protected:
using ItemBlockList = std::list<std::pair<int32_t, std::shared_ptr<Item>>>;
Expand Down
9 changes: 4 additions & 5 deletions src/lua/functions/creatures/player/player_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "game/scheduling/save_manager.hpp"
#include "io/iobestiary.hpp"
#include "io/iologindata.hpp"
#include "io/functions/iologindata_save_player.hpp"
#include "io/ioprey.hpp"
#include "items/containers/depot/depotchest.hpp"
#include "items/containers/depot/depotlocker.hpp"
Expand Down Expand Up @@ -4212,13 +4213,11 @@ int PlayerFunctions::luaPlayerChangeName(lua_State* L) {
Lua::pushBoolean(L, false);
return 0;
}
if (player->isOnline()) {
player->removePlayer(true, true);
}

player->kv()->remove("namelock");
const auto newName = Lua::getString(L, 2);
player->setName(newName);
g_saveManager().savePlayer(player);
const auto oldName = player->getName();
IOLoginDataSave::savePlayerNamesAndChangeName(player, newName, oldName);
return 1;
}

Expand Down

0 comments on commit fed60a5

Please sign in to comment.