Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.16.201' into 1.16.201
Browse files Browse the repository at this point in the history
# Conflicts:
#	.idea/workspace.xml
  • Loading branch information
hhhxiao committed Feb 20, 2021
2 parents 6987ce0 + 89398f2 commit ba30001
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 147 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/cmake-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CMake
on:
push:
branches:
- 1.16.4-main
- 1.16.201

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand Down Expand Up @@ -62,9 +62,9 @@ jobs:
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# upload_url: https://github.com/quizhizhe/TrapDoor/releases/tag/1.16.4
# asset_path: ${{github.workspace}}/build/Release/trapdoor-mod.dll
# asset_name: trapdoor-mod.dll
# asset_name: trapdoor-v0.9.20-1.16.201.dll
# asset_content_type: application/dll
#
## - name: Test
Expand Down
8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ target_include_directories(${MOD_API_NAME}
)

target_link_libraries(${MOD_API_NAME} ${PROJECT_SOURCE_DIR}/api/lib/detours.lib)
target_link_libraries(${MOD_API_NAME} ${PROJECT_SOURCE_DIR}/api/lib/sqlite3.lib)



Expand Down
9 changes: 6 additions & 3 deletions mod/TrapdoorMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace mod {
void TrapdoorMod::initialize() {
BDSMod::initialize();
this->commandManager.setCommandConfig(this->configManager.getCommandsConfig());
this->playerStatisticManager.init("trapdoor.db");
// this->playerStatisticManager.init("trapdoor.db");
mod::initBackup();
this->initFunctionEnable();
this->villageHelper.setConfig(this->configManager.getVillageConfig());
Expand Down Expand Up @@ -74,7 +74,9 @@ namespace mod {
->then(ARG("draw", "开启/关闭区块draw命令", BOOL, {
this->simpleBuilder.setAble(holder->getBool());
info(player, "设置简单建造为 %d", holder->getBool());
}))
}));
/*
//commented out fully player statistics manager
->then(ARG("stat", "开启/关闭玩家行为统计", BOOL, {
if (!configManager.getFunctionConfig().playerStat) {
error(player, "该功能已被关闭,请联系服主");
Expand All @@ -83,6 +85,7 @@ namespace mod {
this->playerStatisticManager.setAble(holder->getBool());
info(player, "设置玩家行为统计为 %d", holder->getBool());
}));
*/

//史莱姆显示
commandManager.registerCmd("slime", "史莱姆区块相关")
Expand Down Expand Up @@ -386,7 +389,7 @@ namespace mod {
auto functionCfg = this->configManager.getFunctionConfig();
this->spawnHelper.setAble(functionCfg.spawnHelper);
this->rotationHelper.setAble(functionCfg.cactusRotation);
this->playerStatisticManager.setAble(functionCfg.playerStat);
// this->playerStatisticManager.setAble(functionCfg.playerStat);
this->simpleBuilder.setAble(functionCfg.simpleDraw);
this->hopperChannelManager.setAble(functionCfg.hopperCounter);
}
Expand Down
12 changes: 6 additions & 6 deletions mod/TrapdoorMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
#include "player/PlayerFunction.h"
#include "player/SimpleBuilder.h"
#include "SlimeChunkHelper.h"
#include "player/PlayerStatisticManager.h"
//#include "player/PlayerStatisticManager.h"

namespace mod {

struct ModInfo {
const std::string minecraftVersion = "1.16.4.02";
const std::string modVersion = "trapdoor-0.9.20";
const std::string minecraftVersion = "1.16.201";
const std::string modVersion = "trapdoor-0.9.21";
};

class TrapdoorMod : public trapdoor::BDSMod {
Expand All @@ -37,7 +37,7 @@ namespace mod {
PlayerFunction playerFunctions;
SimpleBuilder simpleBuilder;
SlimeChunkHelper slimeChunkHelper;
PlayerStatisticManager playerStatisticManager;
// PlayerStatisticManager playerStatisticManager;

void registerTickCommand();

Expand Down Expand Up @@ -81,12 +81,12 @@ namespace mod {

inline SpawnAnalyzer &getSpawnAnalyzer() { return this->spawnAnalyzer; }

inline PlayerStatisticManager &getPlayerStatisticManager() { return this->playerStatisticManager; }
// inline PlayerStatisticManager &getPlayerStatisticManager() { return this->playerStatisticManager; }

inline std::string getLevelName() { return this->configManager.getServerConfig().levelName; }


};
}

#endif //MOD_TRAPDOORMOD_H
#endif //MOD_TRAPDOORMOD_H
74 changes: 37 additions & 37 deletions mod/player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,43 @@

//player place block
using namespace SymHook;

THook(
int64_t,
MSSYM_B1QE21onBlockPlacedByPlayerB1AE34VanillaServerGameplayEventListenerB2AAA4UEAAB1QE14AW4EventResultB2AAE10AEAVPlayerB2AAA9AEBVBlockB2AAE12AEBVBlockPosB3AAUA1NB1AA1Z,
void *self,
trapdoor::Actor *player,
trapdoor::Block &block,
const trapdoor::BlockPos &pos,
bool flag
) {
auto modInstance = trapdoor::bdsMod->asInstance<mod::TrapdoorMod>();
modInstance->getPlayerStatisticManager().insetPlayerAction(player->getNameTag(), pos,
mod::PlayerStatisticManager::PLACE_BLOCK,
player->getDimensionID(),
block.getName());

return original(self, player, block, pos, flag);
}
//
//THook(
// int64_t,
// MSSYM_B1QE21onBlockPlacedByPlayerB1AE34VanillaServerGameplayEventListenerB2AAA4UEAAB1QE14AW4EventResultB2AAE10AEAVPlayerB2AAA9AEBVBlockB2AAE12AEBVBlockPosB3AAUA1NB1AA1Z,
// void *self,
// trapdoor::Actor *player,
// trapdoor::Block &block,
// const trapdoor::BlockPos &pos,
// bool flag
//) {
// auto modInstance = trapdoor::bdsMod->asInstance<mod::TrapdoorMod>();
// modInstance->getPlayerStatisticManager().insetPlayerAction(player->getNameTag(), pos,
// mod::PlayerStatisticManager::PLACE_BLOCK,
// player->getDimensionID(),
// block.getName());
//
// return original(self, player, block, pos, flag);
//}
//player destroy block

THook(
void,
MSSYM_B2QUE20destroyBlockInternalB1AA8GameModeB2AAA4AEAAB1UE13NAEBVBlockPosB2AAA1EB1AA1Z,
uint64_t *self,
const trapdoor::BlockPos *pos,
int64_t a3,
int a4
) {
uint64_t *ptr = self + 1;
auto player = reinterpret_cast<trapdoor::Actor *>(*ptr);
auto modInstance = trapdoor::bdsMod->asInstance<mod::TrapdoorMod>();
auto block = player->getBlockSource()->getBlock(pos->x, pos->y, pos->z);
modInstance->getPlayerStatisticManager().insetPlayerAction(player->getNameTag(), *pos,
mod::PlayerStatisticManager::DESTROY_BLOCK,
player->getDimensionID(),
block->getName());
original(self, pos, a3, a4);
}
//
//THook(
// void,
// MSSYM_B2QUE20destroyBlockInternalB1AA8GameModeB2AAA4AEAAB1UE13NAEBVBlockPosB2AAA1EB1AA1Z,
// uint64_t *self,
// const trapdoor::BlockPos *pos,
// int64_t a3,
// int a4
//) {
// uint64_t *ptr = self + 1;
// auto player = reinterpret_cast<trapdoor::Actor *>(*ptr);
// auto modInstance = trapdoor::bdsMod->asInstance<mod::TrapdoorMod>();
// auto block = player->getBlockSource()->getBlock(pos->x, pos->y, pos->z);
// modInstance->getPlayerStatisticManager().insetPlayerAction(player->getNameTag(), *pos,
// mod::PlayerStatisticManager::DESTROY_BLOCK,
// player->getDimensionID(),
// block->getName());
// original(self, pos, a3, a4);
//}


98 changes: 49 additions & 49 deletions mod/player/PlayerStatisticManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,53 @@
#include "tools/MsgBuilder.h"

namespace mod {
int mod::PlayerStatisticManager::createPlayerActionTable() {
const std::string playerActionTableSQL =
R"(
create table if not exists player_acton(
action_id integer primary key autoincrement,
player_id VARCHAR(128) not null,
action_time timestamp not null default (datetime('now','localtime')),
action_type int,
action_dim int,
action_p_x int,
action_p_y int,
action_p_z int,
action_string VARCHAR(512)
)
)";
return this->executeSQL(playerActionTableSQL);
}

int PlayerStatisticManager::executeSQL(const std::string &sql) {
char *errorMsg;
auto rc = sqlite3_exec(db, sql.c_str(), nullptr, nullptr, &errorMsg);
if (rc != SQLITE_OK) {
L_DEBUG("SQL error: %s\n", errorMsg);
sqlite3_free(errorMsg);
}
return rc;
}

void PlayerStatisticManager::insetPlayerAction(const std::string &playerName, const trapdoor::BlockPos &pos,
PlayerStatisticManager::PLAYER_ACTION playerAction, int dim,
const std::string &msg) {

auto sql = trapdoor::format(
"insert into player_acton(player_id,action_type,action_dim,action_p_x,action_p_y,action_p_z,action_string)\n"
" VALUES ('%s', %d,%d,%d,%d,%d, '%s')",
playerName.c_str(), playerAction, dim, pos.x, pos.y, pos.z, msg.c_str()
);
this->executeSQL(sql);
}

void PlayerStatisticManager::init(const std::string &dbName) {
L_INFO("begin init player statistic database");
sqlite3_open(dbName.c_str(), &this->db);
if (this->createPlayerActionTable() != 0) {
L_ERROR("create table failure");
} else {
L_INFO("success create table");
}
}
// int mod::PlayerStatisticManager::createPlayerActionTable() {
// const std::string playerActionTableSQL =
// R"(
// create table if not exists player_acton(
// action_id integer primary key autoincrement,
// player_id VARCHAR(128) not null,
// action_time timestamp not null default (datetime('now','localtime')),
// action_type int,
// action_dim int,
// action_p_x int,
// action_p_y int,
// action_p_z int,
// action_string VARCHAR(512)
// )
// )";
// return this->executeSQL(playerActionTableSQL);
// }
//
// int PlayerStatisticManager::executeSQL(const std::string &sql) {
// char *errorMsg;
// auto rc = sqlite3_exec(db, sql.c_str(), nullptr, nullptr, &errorMsg);
// if (rc != SQLITE_OK) {
// L_DEBUG("SQL error: %s\n", errorMsg);
// sqlite3_free(errorMsg);
// }
// return rc;
// }
//
// void PlayerStatisticManager::insetPlayerAction(const std::string &playerName, const trapdoor::BlockPos &pos,
// PlayerStatisticManager::PLAYER_ACTION playerAction, int dim,
// const std::string &msg) {
//
// auto sql = trapdoor::format(
// "insert into player_acton(player_id,action_type,action_dim,action_p_x,action_p_y,action_p_z,action_string)\n"
// " VALUES ('%s', %d,%d,%d,%d,%d, '%s')",
// playerName.c_str(), playerAction, dim, pos.x, pos.y, pos.z, msg.c_str()
// );
// this->executeSQL(sql);
// }
//
// void PlayerStatisticManager::init(const std::string &dbName) {
// L_INFO("begin init player statistic database");
// sqlite3_open(dbName.c_str(), &this->db);
// if (this->createPlayerActionTable() != 0) {
// L_ERROR("create table failure");
// } else {
// L_INFO("success create table");
// }
// }
}
50 changes: 25 additions & 25 deletions mod/player/PlayerStatisticManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@
#include "tools/noncopyable .h"

namespace mod {

class PlayerStatisticManager : noncopyable {
sqlite3 *db = nullptr;
bool enable = false;

int executeSQL(const std::string &sql);

int createPlayerActionTable();

public:
enum PLAYER_ACTION {
DESTROY_BLOCK,
PLACE_BLOCK
};

inline void setAble(bool able) { this->enable = able; }

inline bool isEnable() const { return this->enable; }

void init(const std::string &dbName);

void insetPlayerAction(const std::string &playerName, const trapdoor::BlockPos &pos,
PLAYER_ACTION playerAction, int dim, const std::string &msg
);
};
//
// class PlayerStatisticManager : noncopyable {
// sqlite3 *db = nullptr;
// bool enable = false;
//
// int executeSQL(const std::string &sql);
//
// int createPlayerActionTable();
//
// public:
// enum PLAYER_ACTION {
// DESTROY_BLOCK,
// PLACE_BLOCK
// };
//
// inline void setAble(bool able) { this->enable = able; }
//
// inline bool isEnable() const { return this->enable; }
//
// void init(const std::string &dbName);
//
// void insetPlayerAction(const std::string &playerName, const trapdoor::BlockPos &pos,
// PLAYER_ACTION playerAction, int dim, const std::string &msg
// );
// };
}


Expand Down
Loading

0 comments on commit ba30001

Please sign in to comment.