Skip to content

Commit fed60a5

Browse files
committed
* update
2 parents b453256 + 7c4017a commit fed60a5

File tree

5 files changed

+60
-6
lines changed

5 files changed

+60
-6
lines changed

data/migrations/51.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function onUpdateDatabase()
2+
logger.info("Updating database to version 51 (Player Old Names)")
3+
4+
db.query([[
5+
CREATE TABLE `player_oldnames` (
6+
`id` int(11) NOT NULL AUTO_INCREMENT,
7+
`player_id` int(11) NOT NULL,
8+
`former_name` varchar(255) NOT NULL DEFAULT '',
9+
`name` varchar(255) NOT NULL,
10+
`old_name` varchar(255) NOT NULL,
11+
`date` int(11) NOT NULL,
12+
PRIMARY KEY (`id`),
13+
INDEX `player_id_index` (`player_id`)
14+
)
15+
]])
16+
end

markdowns/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
- Added Vibrancy imbuement. ([pennaor](https://github.com/pennaor))
1212
- Added Soul Pit arena/animus mastery/soul core. ([FelipePaluco](https://github.com/FelipePaluco))
1313
- Added a new command `/mute`, which will mute a player until unmuted by `/unmute`. ([Tryller](https://github.com/jprzimba))
14+
- Cyclopedia House Auction system. ([murilo09](https://github.com/murilo09))
15+
- Updated name change functionality to save old player names in a database table called `player_oldnames`. ([Tryller](https://github.com/jprzimba))
1416

1517
## Added files
1618

1719
- data/migrations/49.lua
20+
- data/migrations/50.lua
21+
- data/migrations/51.lua
1822
- data-global/lib/others/soulpit.lua
1923
- data-global/startup/tables/tile.lua
2024
- data-global/npc/myzzi.lua
@@ -73,7 +77,6 @@
7377
- Add new configurable featurees in `config.lua`: `chainSystemVipOnly`, `fieldOwnershipDuration`, `bedsOnlyPremium`, `loginProtectionPeriod`, `chainSystemModifyMagic`, `logPlayersStatements`. ([Tryller](https://github.com/jprzimba))
7478
- Added a new commands for players: `!randomoutfit`, `!spellwords`. ([Tryller](https://github.com/jprzimba))
7579
- Moved emote spells to `kv` instead of `storage`. ([Tryller](https://github.com/jprzimba))
76-
- Cyclopedia House Auction system. ([murilo09](https://github.com/murilo09))
7780
- Updated npcs and spells from 13.40 updates. ([murilo09](https://github.com/murilo09))
7881
- Added a Rook system with configurations in `config.lua`. ([Tryller](https://github.com/jprzimba))
7982
- Added a new group `game tester` with flag `isgametester` in `groups.xml` and a new player flag `PlayerFlag_IsGameTester`. ([Tryller](https://github.com/jprzimba))

src/io/functions/iologindata_save_player.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "creatures/monsters/monsters.hpp"
2323
#include "creatures/players/animus_mastery/animus_mastery.hpp"
2424
#include "game/game.hpp"
25+
#include "game/scheduling/save_manager.hpp"
2526
#include "io/ioprey.hpp"
2627
#include "items/containers/depot/depotchest.hpp"
2728
#include "items/containers/inbox/inbox.hpp"
@@ -838,3 +839,37 @@ bool IOLoginDataSave::savePlayerStatement(const std::shared_ptr<Player> &player,
838839
statementId = db.getLastInsertId();
839840
return true;
840841
}
842+
843+
bool IOLoginDataSave::savePlayerNamesAndChangeName(const std::shared_ptr<Player> &player, const std::string &newName, const std::string &oldName) {
844+
if (!player) {
845+
g_logger().warn("[IOLoginData::savePlayerStatement] - Player nullptr: {}", __FUNCTION__);
846+
return false;
847+
}
848+
849+
Database &db = Database::getInstance();
850+
std::ostringstream query;
851+
852+
const time_t now = time(nullptr);
853+
854+
// find former name
855+
std::string formerName = oldName;
856+
auto result = db.storeQuery(fmt::format("SELECT `former_name` FROM `player_oldnames` WHERE `player_id` = {} LIMIT 1", player->getGUID()));
857+
if (result) {
858+
formerName = result->getString("former_name");
859+
}
860+
861+
query << "INSERT INTO `player_oldnames` (`player_id`, `former_name`, `name`, `old_name`, `date`) VALUES ("
862+
<< player->getGUID() << ", " << db.escapeString(formerName) << ", " << db.escapeString(newName) << ", " << db.escapeString(oldName) << ", " << now << ")";
863+
864+
if (!db.executeQuery(query.str())) {
865+
return false;
866+
}
867+
868+
if (player->isOnline()) {
869+
player->removePlayer(true, true);
870+
}
871+
872+
player->setName(newName);
873+
g_saveManager().savePlayer(player);
874+
return true;
875+
}

src/io/functions/iologindata_save_player.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class IOLoginDataSave : public IOLoginData {
3939
static bool savePlayerBosstiary(const std::shared_ptr<Player> &player);
4040
static bool savePlayerStorage(const std::shared_ptr<Player> &player);
4141
static bool savePlayerStatement(const std::shared_ptr<Player> &player, const std::string &receiver, uint16_t channelId, const std::string &text, uint32_t &statementId);
42+
static bool savePlayerNamesAndChangeName(const std::shared_ptr<Player> &player, const std::string &newName, const std::string &oldName);
4243

4344
protected:
4445
using ItemBlockList = std::list<std::pair<int32_t, std::shared_ptr<Item>>>;

src/lua/functions/creatures/player/player_functions.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "game/scheduling/save_manager.hpp"
3737
#include "io/iobestiary.hpp"
3838
#include "io/iologindata.hpp"
39+
#include "io/functions/iologindata_save_player.hpp"
3940
#include "io/ioprey.hpp"
4041
#include "items/containers/depot/depotchest.hpp"
4142
#include "items/containers/depot/depotlocker.hpp"
@@ -4212,13 +4213,11 @@ int PlayerFunctions::luaPlayerChangeName(lua_State* L) {
42124213
Lua::pushBoolean(L, false);
42134214
return 0;
42144215
}
4215-
if (player->isOnline()) {
4216-
player->removePlayer(true, true);
4217-
}
4216+
42184217
player->kv()->remove("namelock");
42194218
const auto newName = Lua::getString(L, 2);
4220-
player->setName(newName);
4221-
g_saveManager().savePlayer(player);
4219+
const auto oldName = player->getName();
4220+
IOLoginDataSave::savePlayerNamesAndChangeName(player, newName, oldName);
42224221
return 1;
42234222
}
42244223

0 commit comments

Comments
 (0)