Skip to content

Commit

Permalink
Merge pull request #13 from jprzimba/player-statements
Browse files Browse the repository at this point in the history
[FATURE] Log Players Statements
  • Loading branch information
jprzimba authored Jan 1, 2025
2 parents 4ac54a4 + b6a10e4 commit 4f5699f
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 22 deletions.
2 changes: 2 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ resetSessionsOnStartup = false
-- Misc.
-- NOTE: experienceDisplayRates: set to false to ignore exp rate or true to include exp rate
-- NOTE: disableLegacyRaids: set to true to disable legacy XML raids
-- NOTE: logPlayersStatements will log all player statements.
allowChangeOutfit = true
freePremium = false
kickIdlePlayerAfterMinutes = 15
Expand All @@ -448,6 +449,7 @@ disableMonsterArmor = false
minElementalResistance = -200
maxElementalResistance = 200
maxDamageReflection = 200
logPlayersStatements = false

-- Chain system
-- NOTE: combatChainDelay: set to minimum 50 miliseconds
Expand Down
30 changes: 11 additions & 19 deletions data/migrations/47.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
function onUpdateDatabase()
logger.info("Updating database to version 47 (hireling)")
logger.info("Updating database to version 47 (player statements)")

db.query([[
CREATE TABLE IF NOT EXISTS `player_hirelings` (
`id` INT NOT NULL PRIMARY KEY auto_increment,
`player_id` INT NOT NULL,
`name` varchar(255),
`active` tinyint unsigned NOT NULL DEFAULT '0',
`sex` tinyint unsigned NOT NULL DEFAULT '0',
`posx` int(11) NOT NULL DEFAULT '0',
`posy` int(11) NOT NULL DEFAULT '0',
`posz` int(11) NOT NULL DEFAULT '0',
`lookbody` int(11) NOT NULL DEFAULT '0',
`lookfeet` int(11) NOT NULL DEFAULT '0',
`lookhead` int(11) NOT NULL DEFAULT '0',
`looklegs` int(11) NOT NULL DEFAULT '0',
`looktype` int(11) NOT NULL DEFAULT '136',
FOREIGN KEY(`player_id`) REFERENCES `players`(`id`)
ON DELETE CASCADE
)
CREATE TABLE IF NOT EXISTS `player_statements`(
`id` INT NOT NULL AUTO_INCREMENT,
`player_id` INT NOT NULL,
`receiver` TEXT NOT NULL,
`channel_id` INT NOT NULL DEFAULT 0,
`text` VARCHAR (255) NOT NULL,
`date` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), KEY (`player_id`), KEY (`channel_id`),
FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
]])
end
2 changes: 1 addition & 1 deletion markdowns/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- Protocol 14.05 support. ([Tryller](https://github.com/jprzimba))
- New protocol 14.05 assets. ([Tryller](https://github.com/jprzimba))
- Optimized the `onPlayerSellAllLoot` code to prevent prolonged freezes. ([Tryller](https://github.com/jprzimba))
- Add new configurable featurees in `config.lua`: `chainSystemVipOnly`, `fieldOwnershipDuration`, `bedsOnlyPremium`, `loginProtectionPeriod`, `chainSystemModifyMagic`. ([Tryller](https://github.com/jprzimba))
- 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))

Expand Down
14 changes: 13 additions & 1 deletion schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS `server_config` (
CONSTRAINT `server_config_pk` PRIMARY KEY (`config`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

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

-- Table structure `accounts`
CREATE TABLE IF NOT EXISTS `accounts` (
Expand Down Expand Up @@ -572,6 +572,18 @@ CREATE TABLE IF NOT EXISTS `player_charms` (
`tracker list` BLOB NULL
) ENGINE = InnoDB DEFAULT CHARSET=utf8;

-- Table structure `player_statements`
CREATE TABLE IF NOT EXISTS `player_statements` (
`id` INT NOT NULL AUTO_INCREMENT,
`player_id` INT NOT NULL,
`receiver` TEXT NOT NULL,
`channel_id` INT NOT NULL DEFAULT 0,
`text` VARCHAR (255) NOT NULL,
`date` BIGINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), KEY (`player_id`), KEY (`channel_id`),
FOREIGN KEY (`player_id`) REFERENCES `players`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Table structure `player_deaths`
CREATE TABLE IF NOT EXISTS `player_deaths` (
`player_id` int(11) NOT NULL,
Expand Down
1 change: 1 addition & 0 deletions src/config/config_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,5 @@ enum ConfigKey_t : uint16_t {
BEDS_ONLY_PREMIUM,
LOGIN_PROTECTION,
SPELL_NAME_INSTEAD_WORDS,
LOG_PLAYERS_STATEMENTS,
};
1 change: 1 addition & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ bool ConfigManager::load() {
loadBoolConfig(L, CHAIN_SYSTEM_VIP_ONLY, "chainSystemVipOnly", false);
loadBoolConfig(L, BEDS_ONLY_PREMIUM, "bedsOnlyPremium", true);
loadBoolConfig(L, SPELL_NAME_INSTEAD_WORDS, "spellNameInsteadOfWords", false);
loadBoolConfig(L, LOG_PLAYERS_STATEMENTS, "logPlayersStatements", false);

loadFloatConfig(L, BESTIARY_RATE_CHARM_SHOP_PRICE, "bestiaryRateCharmShopPrice", 1.0);
loadFloatConfig(L, COMBAT_CHAIN_SKILL_FORMULA_AXE, "combatChainSkillFormulaAxe", 0.9);
Expand Down
1 change: 0 additions & 1 deletion src/database/databasemanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ class DatabaseManager {
static bool getDatabaseConfig(const std::string &config, int32_t &value);
static void registerDatabaseConfig(const std::string &config, int32_t value);
};

6 changes: 6 additions & 0 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "io/iobestiary.hpp"
#include "io/ioguild.hpp"
#include "io/iologindata.hpp"
#include "io/functions/iologindata_save_player.hpp"
#include "io/iomarket.hpp"
#include "io/ioprey.hpp"
#include "items/bed.hpp"
Expand Down Expand Up @@ -6232,6 +6233,11 @@ void Game::playerSay(uint32_t playerId, uint16_t channelId, SpeakClasses type, c
player->removeMessageBuffer();
}

uint32_t statementId = 0;
if (g_configManager().getBoolean(LOG_PLAYERS_STATEMENTS)) {
IOLoginDataSave::savePlayerStatement(player, receiver, channelId, text, statementId);
}

switch (type) {
case TALKTYPE_SAY:
internalCreatureSay(player, TALKTYPE_SAY, text, false);
Expand Down
21 changes: 21 additions & 0 deletions src/io/functions/iologindata_save_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,3 +808,24 @@ bool IOLoginDataSave::savePlayerStorage(const std::shared_ptr<Player> &player) {
}
return true;
}

bool IOLoginDataSave::savePlayerStatement(const std::shared_ptr<Player> &player, const std::string &receiver, uint16_t channelId, const std::string &text, uint32_t &statementId) {
if (!player) {
g_logger().warn("[IOLoginData::savePlayerStatement] - Player nullptr: {}", __FUNCTION__);
return false;
}

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

query << "INSERT INTO `player_statements` (`player_id`, `receiver`, `channel_id`, `text`, `date`) VALUES ("
<< player->getGUID() << ", " << db.escapeString(receiver) << ", " << channelId << ", "
<< db.escapeString(text) << ", " << time(nullptr) << ")";

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

statementId = db.getLastInsertId();
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 @@ -38,6 +38,7 @@ class IOLoginDataSave : public IOLoginData {
static bool savePlayerForgeHistory(const std::shared_ptr<Player> &player);
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);

protected:
using ItemBlockList = std::list<std::pair<int32_t, std::shared_ptr<Item>>>;
Expand Down

0 comments on commit 4f5699f

Please sign in to comment.