diff --git a/docs/apis/DataAPI/PermAPI.md b/docs/apis/DataAPI/PermAPI.md index 337de7c5..3d9d1b55 100644 --- a/docs/apis/DataAPI/PermAPI.md +++ b/docs/apis/DataAPI/PermAPI.md @@ -72,21 +72,21 @@ By static method: ### Properties - Name | Type | Description ------------------|-----------------|----------------------- -`name` | `String` | The role name -`displayName` | `String` | The role display name -`priority` | `Number` | The role priority -`permissions` | `Array` | The role permissions -`members` | `Array` | The role members(XUID) + | Name | Type | Description | + | ------------- | --------------- | ---------------------- | + | `name` | `String` | The role name | + | `displayName` | `String` | The role display name | + | `priority` | `Number` | The role priority | + | `permissions` | `Array` | The role permissions | + | `members` | `Array` | The role members(XUID) | The `permissions` property is an array of objects, each object contains the following properties: - Name | Type | Description ------------------|-----------------|----------------------- -`name` | `String` | The permission name -`enabled` | `Boolean` | Whether the permission is enabled -`extra` | `Object` | The extra data of the permission + | Name | Type | Description | + | --------- | --------- | --------------------------------- | + | `name` | `String` | The permission name | + | `enabled` | `Boolean` | Whether the permission is enabled | + | `extra` | `Object` | The extra data of the permission |
@@ -387,4 +387,4 @@ mc.listen("onJoin", function (pl, msg) { pl.kick("You are not allowed to join this server"); } }); -``` \ No newline at end of file +``` diff --git a/docs/apis/DataAPI/PermAPI.zh.md b/docs/apis/DataAPI/PermAPI.zh.md index 0c90b3fe..9bc9d8da 100644 --- a/docs/apis/DataAPI/PermAPI.zh.md +++ b/docs/apis/DataAPI/PermAPI.zh.md @@ -72,21 +72,21 @@ ### 属性 - 名称 | 类型 | 描述 ------------------|-----------------|----------------------- -`name` | `String` | 身份组名称 -`displayName` | `String` | 身份组显示名称 -`priority` | `Number` | 身份组优先级,越大越优先 -`permissions` | `Array` | 身份组拥有的权限 -`members` | `Array` | 身份组成员的XUID + | 名称 | 类型 | 描述 | + | ------------- | --------------- | ------------------------ | + | `name` | `String` | 身份组名称 | + | `displayName` | `String` | 身份组显示名称 | + | `priority` | `Number` | 身份组优先级,越大越优先 | + | `permissions` | `Array` | 身份组拥有的权限 | + | `members` | `Array` | 身份组成员的XUID | `permissions` 属性是一个对象的数组,每个对象都含有以下属性: - 名称 | 类型 | 描述 ------------------|-----------------|----------------------- -`name` | `String` | 权限名称 -`enabled` | `Boolean` | 权限是否开启 -`extra` | `Object` | 权限的额外数据 + | 名称 | 类型 | 描述 | + | --------- | --------- | -------------- | + | `name` | `String` | 权限名称 | + | `enabled` | `Boolean` | 权限是否开启 | + | `extra` | `Object` | 权限的额外数据 |
@@ -391,4 +391,4 @@ mc.listen("onJoin", function (pl, msg) { pl.kick("You are not allowed to join this server"); } }); -``` \ No newline at end of file +``` diff --git a/mkdocs.yml b/mkdocs.yml index 5492c878..e0036481 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -5,7 +5,7 @@ nav: - Home: index.md - Tutorials: - - tutorials/create_your_first_plugin.md + - tutorials/create_your_first_plugin.md - faq.md diff --git a/src/baselib/BaseLib.py b/src/baselib/BaseLib.py index a048a0c7..09a30fe0 100644 --- a/src/baselib/BaseLib.py +++ b/src/baselib/BaseLib.py @@ -10,7 +10,7 @@ def _llse_python_base_lib_command_handle(self, func=None): def wrapper(func): self.setCallback(func) return func - + if func: return wrapper(func) return wrapper diff --git a/src/legacy/api/BaseAPI.h b/src/legacy/api/BaseAPI.h index eae8634e..417355cb 100644 --- a/src/legacy/api/BaseAPI.h +++ b/src/legacy/api/BaseAPI.h @@ -52,7 +52,6 @@ class FloatPos : public FloatVec4, public ScriptClass { Local getDimId() { return Number::newNumber(dim); } Local toString(); - void setX(const Local& value) { x = value.asNumber().toInt64(); } void setY(const Local& value) { y = value.asNumber().toInt64(); } void setZ(const Local& value) { z = value.asNumber().toInt64(); } diff --git a/src/legacy/api/BlockEntityAPI.h b/src/legacy/api/BlockEntityAPI.h index cba8afde..116050db 100644 --- a/src/legacy/api/BlockEntityAPI.h +++ b/src/legacy/api/BlockEntityAPI.h @@ -27,4 +27,4 @@ class BlockEntityClass : public ScriptClass { Local setNbt(const Arguments& args); Local getBlock(const Arguments& args); }; -extern ClassDefine BlockEntityClassBuilder; \ No newline at end of file +extern ClassDefine BlockEntityClassBuilder; diff --git a/src/legacy/api/CommandCompatibleAPI.h b/src/legacy/api/CommandCompatibleAPI.h index 96d941b9..ec01602b 100644 --- a/src/legacy/api/CommandCompatibleAPI.h +++ b/src/legacy/api/CommandCompatibleAPI.h @@ -22,4 +22,4 @@ void ProcessRegCmdQueue(); // 玩家自定义命令注册回调 bool CallPlayerCmdCallback(Player* player, const std::string& cmdPrefix, const std::vector& paras); // 控制台自定义命令注册回调 -bool CallServerCmdCallback(const std::string& cmdPrefix, const std::vector& paras); \ No newline at end of file +bool CallServerCmdCallback(const std::string& cmdPrefix, const std::vector& paras); diff --git a/src/legacy/api/ContainerAPI.cpp b/src/legacy/api/ContainerAPI.cpp index e55baa2f..d71bfe47 100644 --- a/src/legacy/api/ContainerAPI.cpp +++ b/src/legacy/api/ContainerAPI.cpp @@ -196,4 +196,4 @@ Local ContainerClass::isEmpty(const Arguments& args) { return Boolean::newBoolean(container->isEmpty()); } CATCH("Fail in isEmpty!"); -} \ No newline at end of file +} diff --git a/src/legacy/api/ContainerAPI.h b/src/legacy/api/ContainerAPI.h index fa0e02f0..98e6c5ae 100644 --- a/src/legacy/api/ContainerAPI.h +++ b/src/legacy/api/ContainerAPI.h @@ -32,4 +32,4 @@ class ContainerClass : public ScriptClass { Local removeAllItems(const Arguments& args); Local isEmpty(const Arguments& args); }; -extern ClassDefine ContainerClassBuilder; \ No newline at end of file +extern ClassDefine ContainerClassBuilder; diff --git a/src/legacy/api/DataAPI.h b/src/legacy/api/DataAPI.h index b1cff33a..561a608f 100644 --- a/src/legacy/api/DataAPI.h +++ b/src/legacy/api/DataAPI.h @@ -31,7 +31,6 @@ extern ClassDefine DataClassBuilder; Local objectificationMoneyHistory(const string& res); - //////////////////// Money Static //////////////////// class MoneyClass { @@ -46,7 +45,6 @@ class MoneyClass { }; extern ClassDefine MoneyClassBuilder; - //////////////////// Classes //////////////////// class ConfBaseClass { @@ -66,7 +64,6 @@ class ConfBaseClass { virtual Local write(const Arguments& args) = 0; }; - class ConfJsonClass : public ScriptClass, public ConfBaseClass { private: ordered_json jsonConf; @@ -93,7 +90,6 @@ class ConfJsonClass : public ScriptClass, public ConfBaseClass { }; extern ClassDefine ConfJsonClassBuilder; - class ConfIniClass : public ScriptClass, public ConfBaseClass { private: SimpleIni* iniConf; diff --git a/src/legacy/api/DeviceAPI.h b/src/legacy/api/DeviceAPI.h index e5ec9892..0bac8ba6 100644 --- a/src/legacy/api/DeviceAPI.h +++ b/src/legacy/api/DeviceAPI.h @@ -28,4 +28,4 @@ class DeviceClass : public ScriptClass { Local getServerAddress(); Local getClientId(); }; -extern ClassDefine DeviceClassBuilder; \ No newline at end of file +extern ClassDefine DeviceClassBuilder; diff --git a/src/legacy/api/EntityAPI.h b/src/legacy/api/EntityAPI.h index 3bd030c2..925a3a8f 100644 --- a/src/legacy/api/EntityAPI.h +++ b/src/legacy/api/EntityAPI.h @@ -114,4 +114,4 @@ class EntityClass : public ScriptClass { Local removeEffect(const Arguments& args); }; extern ClassDefine EntityClassBuilder; -extern ClassDefine ActorDamageCauseBuilder; \ No newline at end of file +extern ClassDefine ActorDamageCauseBuilder; diff --git a/src/legacy/api/EventAPI.cpp b/src/legacy/api/EventAPI.cpp index 1fd9bced..d453f0cf 100644 --- a/src/legacy/api/EventAPI.cpp +++ b/src/legacy/api/EventAPI.cpp @@ -58,7 +58,6 @@ #include #include - //////////////////// Listeners //////////////////// // 监听器表 diff --git a/src/legacy/api/FileSystemAPI.h b/src/legacy/api/FileSystemAPI.h index 368c50a6..d1a8ea8d 100644 --- a/src/legacy/api/FileSystemAPI.h +++ b/src/legacy/api/FileSystemAPI.h @@ -23,7 +23,6 @@ Local CheckIsDir(const Arguments& args); Local GetFileSize(const Arguments& args); Local GetFilesList(const Arguments& args); - //////////////////// Classes //////////////////// class FileClass : public ScriptClass { private: @@ -79,4 +78,4 @@ class FileClass : public ScriptClass { static Local newFile(std::fstream&& f, const std::string& path, bool isBinary); static Local open(const Arguments& args) { return OpenFile(args); } }; -extern ClassDefine FileClassBuilder; \ No newline at end of file +extern ClassDefine FileClassBuilder; diff --git a/src/legacy/api/GameUtilsAPI.cpp b/src/legacy/api/GameUtilsAPI.cpp index 4b0e95fe..c92a6687 100644 --- a/src/legacy/api/GameUtilsAPI.cpp +++ b/src/legacy/api/GameUtilsAPI.cpp @@ -26,4 +26,4 @@ ClassDefine TextClassBuilder = defineClass("Format") .property("StrikeThrough", []() { return String::newString("§m"); }) .property("Random", []() { return String::newString("§k"); }) .property("Clear", []() { return String::newString("§r"); }) - .build(); \ No newline at end of file + .build(); diff --git a/src/legacy/api/GameUtilsAPI.h b/src/legacy/api/GameUtilsAPI.h index f02eda8f..ade11b0c 100644 --- a/src/legacy/api/GameUtilsAPI.h +++ b/src/legacy/api/GameUtilsAPI.h @@ -1,5 +1,4 @@ #pragma once #include "api/APIHelp.h" - -extern ClassDefine TextClassBuilder; \ No newline at end of file +extern ClassDefine TextClassBuilder; diff --git a/src/legacy/api/ItemAPI.h b/src/legacy/api/ItemAPI.h index 0c123bd6..2da948c0 100644 --- a/src/legacy/api/ItemAPI.h +++ b/src/legacy/api/ItemAPI.h @@ -72,4 +72,4 @@ class ItemClass : public ScriptClass { Local match(const Arguments& args); }; -extern ClassDefine ItemClassBuilder; \ No newline at end of file +extern ClassDefine ItemClassBuilder; diff --git a/src/legacy/api/LoggerAPI.h b/src/legacy/api/LoggerAPI.h index 5155a09c..d435c2f2 100644 --- a/src/legacy/api/LoggerAPI.h +++ b/src/legacy/api/LoggerAPI.h @@ -1,7 +1,6 @@ #pragma once #include "api/APIHelp.h" - //////////////////// Classes //////////////////// class LoggerClass { @@ -20,4 +19,4 @@ class LoggerClass { static Local setLogLevel(const Arguments& args); }; -extern ClassDefine LoggerClassBuilder; \ No newline at end of file +extern ClassDefine LoggerClassBuilder; diff --git a/src/legacy/api/McAPI.h b/src/legacy/api/McAPI.h index 2794b9ea..d43b314c 100644 --- a/src/legacy/api/McAPI.h +++ b/src/legacy/api/McAPI.h @@ -3,7 +3,6 @@ #include - class McClass { public: static Local getBDSVersion(const Arguments& args); @@ -72,4 +71,4 @@ class McClass { static Local getWeather(const Arguments& args); static Local setWeather(const Arguments& args); }; -extern ClassDefine McClassBuilder; \ No newline at end of file +extern ClassDefine McClassBuilder; diff --git a/src/legacy/api/MoreGlobal.h b/src/legacy/api/MoreGlobal.h index 2a3f643b..d6bb5008 100644 --- a/src/legacy/api/MoreGlobal.h +++ b/src/legacy/api/MoreGlobal.h @@ -7,4 +7,4 @@ class MoreGlobal { static void Init(); static DBStorage* getDBStorage() { return db; }; static void setDBStorage(DBStorage* dbs) { db = dbs; }; -}; \ No newline at end of file +}; diff --git a/src/legacy/api/NativeStdString.cpp b/src/legacy/api/NativeStdString.cpp index 8099a57b..13971d9e 100644 --- a/src/legacy/api/NativeStdString.cpp +++ b/src/legacy/api/NativeStdString.cpp @@ -321,4 +321,4 @@ Local NativeStdString::destroy() { return Local(); } CATCH("Fail in NativeStdString::destroy!"); -} \ No newline at end of file +} diff --git a/src/legacy/api/NativeStdString.h b/src/legacy/api/NativeStdString.h index a543f63a..652ba967 100644 --- a/src/legacy/api/NativeStdString.h +++ b/src/legacy/api/NativeStdString.h @@ -47,4 +47,4 @@ class NativeStdString : public ScriptClass { Local destroy(); }; -extern ClassDefine NativeStdStringBuilder; \ No newline at end of file +extern ClassDefine NativeStdStringBuilder; diff --git a/src/legacy/api/NetworkAPI.h b/src/legacy/api/NetworkAPI.h index 4a9b7b7d..9fb477ef 100644 --- a/src/legacy/api/NetworkAPI.h +++ b/src/legacy/api/NetworkAPI.h @@ -149,4 +149,4 @@ class HttpResponseClass : public ScriptClass { Local getReason(); Local getVersion(); }; -extern ClassDefine HttpResponseClassBuilder; \ No newline at end of file +extern ClassDefine HttpResponseClassBuilder; diff --git a/src/legacy/api/PlayerAPI.h b/src/legacy/api/PlayerAPI.h index e747a7f0..7d9da077 100644 --- a/src/legacy/api/PlayerAPI.h +++ b/src/legacy/api/PlayerAPI.h @@ -225,4 +225,4 @@ class PlayerClass : public ScriptClass { Local setAbility(const Arguments& args); }; -extern ClassDefine PlayerClassBuilder; \ No newline at end of file +extern ClassDefine PlayerClassBuilder; diff --git a/src/legacy/api/ScoreboardAPI.h b/src/legacy/api/ScoreboardAPI.h index e7d62841..338d273e 100644 --- a/src/legacy/api/ScoreboardAPI.h +++ b/src/legacy/api/ScoreboardAPI.h @@ -1,7 +1,6 @@ #pragma once #include "api/APIHelp.h" - //////////////////// Classes //////////////////// class Objective; class ObjectiveClass : public ScriptClass { @@ -23,4 +22,4 @@ class ObjectiveClass : public ScriptClass { Local deleteScore(const Arguments& args); Local getScore(const Arguments& args); }; -extern ClassDefine ObjectiveClassBuilder; \ No newline at end of file +extern ClassDefine ObjectiveClassBuilder; diff --git a/src/legacy/api/ScriptAPI.h b/src/legacy/api/ScriptAPI.h index f27ed14e..71ddde2f 100644 --- a/src/legacy/api/ScriptAPI.h +++ b/src/legacy/api/ScriptAPI.h @@ -1,7 +1,6 @@ #pragma once #include "api/APIHelp.h" - //////////////////// APIs //////////////////// Local Log(const Arguments& args); @@ -10,4 +9,4 @@ Local FastLog(const Arguments& args); Local SetTimeout(const Arguments& args); Local SetInterval(const Arguments& args); -Local ClearInterval(const Arguments& args); \ No newline at end of file +Local ClearInterval(const Arguments& args); diff --git a/src/legacy/api/StructureAPI.cpp b/src/legacy/api/StructureAPI.cpp index fee911d7..069db08e 100644 --- a/src/legacy/api/StructureAPI.cpp +++ b/src/legacy/api/StructureAPI.cpp @@ -95,4 +95,4 @@ Local McClass::setStructure(const Arguments& args) { return Boolean::newBoolean(true); } CATCH("Fail in setStructure!"); -} \ No newline at end of file +} diff --git a/src/legacy/api/SystemAPI.h b/src/legacy/api/SystemAPI.h index d368f147..e59c6bda 100644 --- a/src/legacy/api/SystemAPI.h +++ b/src/legacy/api/SystemAPI.h @@ -1,7 +1,6 @@ #pragma once #include "api/APIHelp.h" - //////////////////// System Static //////////////////// class SystemClass { @@ -13,4 +12,4 @@ class SystemClass { static Local cmd(const Arguments& args); static Local newProcess(const Arguments& args); }; -extern ClassDefine SystemClassBuilder; \ No newline at end of file +extern ClassDefine SystemClassBuilder; diff --git a/src/legacy/engine/LocalShareData.cpp b/src/legacy/engine/LocalShareData.cpp index 7662522f..14dc39a1 100644 --- a/src/legacy/engine/LocalShareData.cpp +++ b/src/legacy/engine/LocalShareData.cpp @@ -19,4 +19,4 @@ std::mutex messageLoopLock; void InitLocalShareData() { srand(clock()); localShareData = new LocalDataType; -} \ No newline at end of file +} diff --git a/src/legacy/engine/LocalShareData.h b/src/legacy/engine/LocalShareData.h index 058f185f..65812efd 100644 --- a/src/legacy/engine/LocalShareData.h +++ b/src/legacy/engine/LocalShareData.h @@ -6,7 +6,6 @@ #include #include - //////////////////// Structs //////////////////// // 命令回调信息结构体 @@ -61,4 +60,4 @@ extern std::mutex messageLoopLock; //////////////////// APIs //////////////////// -void InitLocalShareData(); \ No newline at end of file +void InitLocalShareData(); diff --git a/src/legacy/engine/OperationCount.h b/src/legacy/engine/OperationCount.h index 4d70384b..ab2374e2 100644 --- a/src/legacy/engine/OperationCount.h +++ b/src/legacy/engine/OperationCount.h @@ -20,4 +20,4 @@ class OperationCount { bool hasReachCount(int count); bool hasReachMaxEngineCount(); bool hasReachMaxBackendCount(); -}; \ No newline at end of file +}; diff --git a/src/legacy/legacyapi/Base64.h b/src/legacy/legacyapi/Base64.h index d372bdd4..47f5036c 100644 --- a/src/legacy/legacyapi/Base64.h +++ b/src/legacy/legacyapi/Base64.h @@ -105,4 +105,4 @@ inline std::string Decode(const std::string& base64_input) { return out; } -} // namespace Base64 \ No newline at end of file +} // namespace Base64 diff --git a/src/legacy/legacyapi/db/Any.cpp b/src/legacy/legacyapi/db/Any.cpp index 49712208..7cd5bf2b 100644 --- a/src/legacy/legacyapi/db/Any.cpp +++ b/src/legacy/legacyapi/db/Any.cpp @@ -199,4 +199,4 @@ Any Any::str2any(const std::string& str) { } else return Any(str); } -} // namespace DB \ No newline at end of file +} // namespace DB diff --git a/src/legacy/legacyapi/db/ConnParams.cpp b/src/legacy/legacyapi/db/ConnParams.cpp index 22b0b9a8..6c8fa7d9 100644 --- a/src/legacy/legacyapi/db/ConnParams.cpp +++ b/src/legacy/legacyapi/db/ConnParams.cpp @@ -179,4 +179,4 @@ std::string ConnParams::getPath() { return get({"path", "file", "fi std::string ConnParams::getRaw() { return raw; } -} // namespace DB \ No newline at end of file +} // namespace DB diff --git a/src/legacy/legacyapi/db/ConnParams.h b/src/legacy/legacyapi/db/ConnParams.h index fa6c3be5..10a10089 100644 --- a/src/legacy/legacyapi/db/ConnParams.h +++ b/src/legacy/legacyapi/db/ConnParams.h @@ -131,4 +131,4 @@ class ConnParams : public std::unordered_map { } }; -} // namespace DB \ No newline at end of file +} // namespace DB diff --git a/src/legacy/legacyapi/db/Pointer.h b/src/legacy/legacyapi/db/Pointer.h index b908be80..d6923fe1 100644 --- a/src/legacy/legacyapi/db/Pointer.h +++ b/src/legacy/legacyapi/db/Pointer.h @@ -47,4 +47,4 @@ class SharedPointer : public std::shared_ptr { } }; -} // namespace DB \ No newline at end of file +} // namespace DB diff --git a/src/legacy/legacyapi/db/Row.h b/src/legacy/legacyapi/db/Row.h index ab3a474a..fab77eb9 100644 --- a/src/legacy/legacyapi/db/Row.h +++ b/src/legacy/legacyapi/db/Row.h @@ -5,7 +5,6 @@ #include #include - namespace DB { class Row; @@ -259,4 +258,4 @@ inline T row_to(const DB::Row& row) { template <> inline DB::Row row_to(const DB::Row& row) { return row; -} \ No newline at end of file +} diff --git a/src/legacy/legacyapi/db/RowSet.cpp b/src/legacy/legacyapi/db/RowSet.cpp index 49c07683..46370d23 100644 --- a/src/legacy/legacyapi/db/RowSet.cpp +++ b/src/legacy/legacyapi/db/RowSet.cpp @@ -95,4 +95,4 @@ std::string RowSet::toTableString(const std::string& nullPattern) const { return result; } -} // namespace DB \ No newline at end of file +} // namespace DB diff --git a/src/legacy/legacyapi/db/RowSet.h b/src/legacy/legacyapi/db/RowSet.h index 088846a1..a080adbe 100644 --- a/src/legacy/legacyapi/db/RowSet.h +++ b/src/legacy/legacyapi/db/RowSet.h @@ -1,78 +1,78 @@ -#pragma once +c #pragma once #include "legacyapi/db/Row.h" #include #undef max -namespace DB { + namespace DB { -class RowSet : public std::vector { + class RowSet : public std::vector { - using Base = std::vector; + using Base = std::vector; -public: - std::shared_ptr header; //!< The header of the rows + public: + std::shared_ptr header; //!< The header of the rows - /** - * @brief Construct a new Row Set object - * - * @param header The header(column names) of rows(shared_ptr) - */ - RowSet(const std::shared_ptr& header = nullptr); - /** - * @brief Construct a new Row Set object - * - * @param header The header(column names) of rows - */ - RowSet(const RowHeader& header); - /// Move constructor - RowSet(RowSet&& set) noexcept; - /// Copy constructor - RowSet(const RowSet& set); - /// Move assignment operator - RowSet& operator=(RowSet&& set) noexcept; - /// Copy assignment operator - RowSet& operator=(const RowSet& set); + /** + * @brief Construct a new Row Set object + * + * @param header The header(column names) of rows(shared_ptr) + */ + RowSet(const std::shared_ptr& header = nullptr); + /** + * @brief Construct a new Row Set object + * + * @param header The header(column names) of rows + */ + RowSet(const RowHeader& header); + /// Move constructor + RowSet(RowSet&& set) noexcept; + /// Copy constructor + RowSet(const RowSet& set); + /// Move assignment operator + RowSet& operator=(RowSet&& set) noexcept; + /// Copy assignment operator + RowSet& operator=(const RowSet& set); - /** - * @brief Add a row to the set. - * - * @param row The row to add - */ - void add(const Row& row); - /** - * @brief Get if the set is valid - * - * @return bool True if valid - */ - bool valid(); - /** - * @brief Add a row to the set. - * - * @param row The row to add - * @see add(const Row&) - */ - void push_back(const Row& row); - /** - * @brief Convert to the table string. - * - * @param nullPattern When the value is null, what to replace with(default - * '\') - * @return std::string The result string - * @par sample - * @code - * | a | b | - * |=====|========| - * | awa | 114514 | - * | qwq | 233 | - * | ll | | - * |=====|========| - * @endcode - */ - std::string toTableString(const std::string& nullPattern = "") const; -}; + /** + * @brief Add a row to the set. + * + * @param row The row to add + */ + void add(const Row& row); + /** + * @brief Get if the set is valid + * + * @return bool True if valid + */ + bool valid(); + /** + * @brief Add a row to the set. + * + * @param row The row to add + * @see add(const Row&) + */ + void push_back(const Row& row); + /** + * @brief Convert to the table string. + * + * @param nullPattern When the value is null, what to replace with(default + * '\') + * @return std::string The result string + * @par sample + * @code + * | a | b | + * |=====|========| + * | awa | 114514 | + * | qwq | 233 | + * | ll | | + * |=====|========| + * @endcode + */ + std::string toTableString(const std::string& nullPattern = "") const; + }; -using ResultSet = RowSet; + using ResultSet = RowSet; -} // namespace DB \ No newline at end of file +} // namespace DB diff --git a/src/legacy/legacyapi/db/Session.cpp b/src/legacy/legacyapi/db/Session.cpp index 5b5148c5..72b4217c 100644 --- a/src/legacy/legacyapi/db/Session.cpp +++ b/src/legacy/legacyapi/db/Session.cpp @@ -1,123 +1,124 @@ -#include "legacyapi/db/Session.h" +l #include "legacyapi/db/Session.h" #include "legacyapi/db/impl/mysql/Session.h" + #include "legacyapi/db/impl/sqlite/Session.h" #include "ll/api/utils/StringUtils.h" -namespace DB { + namespace DB { -ll::Logger dbLogger("LLSEDB"); + ll::Logger dbLogger("LLSEDB"); -void Session::setDebugOutput(bool enable) { debugOutput = enable; } + void Session::setDebugOutput(bool enable) { debugOutput = enable; } -bool Session::relogin(const std::string& user, const std::string& password, const std::string& db) { - throw std::runtime_error("Session::relogin: Not implemented"); -} + bool Session::relogin(const std::string& user, const std::string& password, const std::string& db) { + throw std::runtime_error("Session::relogin: Not implemented"); + } -ResultSet Session::query(const std::string& query) { - bool headerSet = false; - ResultSet result; - this->query(query, [&](const Row& row) { - if (!headerSet) { - result.header = row.header; - headerSet = true; - } - result.push_back(row); - return true; - }); - IF_ENDBG { - if (result.valid()) { - dbLogger.debug("Session::query: Results >"); - for (auto& str : ll::string_utils::splitByPattern(result.toTableString(), "\n")) { - dbLogger.debug(str); + ResultSet Session::query(const std::string& query) { + bool headerSet = false; + ResultSet result; + this->query(query, [&](const Row& row) { + if (!headerSet) { + result.header = row.header; + headerSet = true; + } + result.push_back(row); + return true; + }); + IF_ENDBG { + if (result.valid()) { + dbLogger.debug("Session::query: Results >"); + for (auto& str : ll::string_utils::splitByPattern(result.toTableString(), "\n")) { + dbLogger.debug(str); + } + } else { + dbLogger.debug("Session::query: Query returned no result"); } - } else { - dbLogger.debug("Session::query: Query returned no result"); } + return result; } - return result; -} -std::string Session::getLastError() const { throw std::runtime_error("Session::getLastError: Not implemented"); } + std::string Session::getLastError() const { throw std::runtime_error("Session::getLastError: Not implemented"); } -std::weak_ptr Session::getOrSetSelf() { - if (self.expired()) { - IF_ENDBG dbLogger.debug("Session::getOrSetSelf: `self` expired, trying fetching"); - return self = getSession(this); + std::weak_ptr Session::getOrSetSelf() { + if (self.expired()) { + IF_ENDBG dbLogger.debug("Session::getOrSetSelf: `self` expired, trying fetching"); + return self = getSession(this); + } + return self; } - return self; -} -SharedPointer Session::operator<<(const std::string& query) { return prepare(query); } + SharedPointer Session::operator<<(const std::string& query) { return prepare(query); } -SharedPointer Session::create(DBType type) { return _Create(type); } -SharedPointer Session::create(const ConnParams& params) { - static std::unordered_map names{ - {"sqlite", DBType::SQLite}, - {"sqlite3", DBType::SQLite}, - {"file", DBType::SQLite}, - {"mysql", DBType::MySQL }, - {"mysqlc", DBType::MySQL } - }; - ConnParams copy = params; - auto scheme = copy.getScheme(); - std::transform(scheme.begin(), scheme.end(), scheme.begin(), ::tolower); - if (names.count(scheme)) { - return _Create(names[scheme], params); - } else { - throw std::runtime_error("Session::create: Unknown/Unsupported database type"); + SharedPointer Session::create(DBType type) { return _Create(type); } + SharedPointer Session::create(const ConnParams& params) { + static std::unordered_map names{ + {"sqlite", DBType::SQLite}, + {"sqlite3", DBType::SQLite}, + {"file", DBType::SQLite}, + {"mysql", DBType::MySQL }, + {"mysqlc", DBType::MySQL } + }; + ConnParams copy = params; + auto scheme = copy.getScheme(); + std::transform(scheme.begin(), scheme.end(), scheme.begin(), ::tolower); + if (names.count(scheme)) { + return _Create(names[scheme], params); + } else { + throw std::runtime_error("Session::create: Unknown/Unsupported database type"); + } } -} -SharedPointer Session::create(DBType type, const ConnParams& params) { return _Create(type, params); } -SharedPointer Session::create( - DBType type, - const std::string& host, - uint16_t port, - const std::string& user, - const std::string& password, - const std::string& database -) { - return _Create( - type, - { - {"host", host }, - {"port", port }, - {"user", user }, - {"password", password}, - {"database", database} + SharedPointer Session::create(DBType type, const ConnParams& params) { return _Create(type, params); } + SharedPointer Session::create( + DBType type, + const std::string& host, + uint16_t port, + const std::string& user, + const std::string& password, + const std::string& database + ) { + return _Create( + type, + { + {"host", host }, + {"port", port }, + {"user", user }, + {"password", password}, + {"database", database} + } + ); } - ); -} -SharedPointer Session::create(DBType type, const std::string& path) { - return _Create( - type, - { - {"path", path} + SharedPointer Session::create(DBType type, const std::string& path) { + return _Create( + type, + { + {"path", path} + } + ); } - ); -} -SharedPointer Session::_Create(DBType type, const ConnParams& params) { - Session* session = nullptr; - switch (type) { - case DBType::SQLite: - session = params.empty() ? new SQLiteSession() : new SQLiteSession(params); - break; - // case DBType::MySQL: - // session = params.empty() ? new MySQLSession() : new MySQLSession(params); - // break; - default: - throw std::runtime_error("Session::_Create: Unknown/Unsupported database type"); - } - if (session) { - auto result = SharedPointer(session); - result->self = result; - sessionPool.push_back(result); - return result; + SharedPointer Session::_Create(DBType type, const ConnParams& params) { + Session* session = nullptr; + switch (type) { + case DBType::SQLite: + session = params.empty() ? new SQLiteSession() : new SQLiteSession(params); + break; + // case DBType::MySQL: + // session = params.empty() ? new MySQLSession() : new MySQLSession(params); + // break; + default: + throw std::runtime_error("Session::_Create: Unknown/Unsupported database type"); + } + if (session) { + auto result = SharedPointer(session); + result->self = result; + sessionPool.push_back(result); + return result; + } + return SharedPointer(); } - return SharedPointer(); -} -std::vector> Session::sessionPool = std::vector>(); + std::vector> Session::sessionPool = std::vector>(); } // namespace DB diff --git a/src/legacy/legacyapi/db/Session.h b/src/legacy/legacyapi/db/Session.h index cf46efd8..9a207faf 100644 --- a/src/legacy/legacyapi/db/Session.h +++ b/src/legacy/legacyapi/db/Session.h @@ -226,4 +226,4 @@ class Session { } }; -} // namespace DB \ No newline at end of file +} // namespace DB diff --git a/src/legacy/legacyapi/db/Stmt.cpp b/src/legacy/legacyapi/db/Stmt.cpp index 77dfaf17..fa78518d 100644 --- a/src/legacy/legacyapi/db/Stmt.cpp +++ b/src/legacy/legacyapi/db/Stmt.cpp @@ -53,4 +53,4 @@ SharedPointer Stmt::operator,(const BindType& b) { return getSharedPointer(); } -} // namespace DB \ No newline at end of file +} // namespace DB diff --git a/src/legacy/legacyapi/db/Stmt.h b/src/legacy/legacyapi/db/Stmt.h index 5e10c0e9..c1f35122 100644 --- a/src/legacy/legacyapi/db/Stmt.h +++ b/src/legacy/legacyapi/db/Stmt.h @@ -590,4 +590,4 @@ inline IntoType into(T& out) { return IntoType{out}; } -} // namespace DB \ No newline at end of file +} // namespace DB diff --git a/src/legacy/legacyapi/db/Types.h b/src/legacy/legacyapi/db/Types.h index 83333e94..bea14550 100644 --- a/src/legacy/legacyapi/db/Types.h +++ b/src/legacy/legacyapi/db/Types.h @@ -35,4 +35,4 @@ struct Decimal { using ByteArray = std::vector; -} // namespace DB \ No newline at end of file +} // namespace DB diff --git a/src/legacy/legacyapi/db/impl/sqlite/Session.cpp b/src/legacy/legacyapi/db/impl/sqlite/Session.cpp index adffd15f..c0bed0c3 100644 --- a/src/legacy/legacyapi/db/impl/sqlite/Session.cpp +++ b/src/legacy/legacyapi/db/impl/sqlite/Session.cpp @@ -116,4 +116,4 @@ DBType SQLiteSession::getType() { return DBType::SQLite; } SharedPointer SQLiteSession::operator<<(const std::string& query) { return prepare(query, true); } -} // namespace DB \ No newline at end of file +} // namespace DB diff --git a/src/legacy/legacyapi/db/impl/sqlite/Session.h b/src/legacy/legacyapi/db/impl/sqlite/Session.h index dc5e9ed9..31578fe7 100644 --- a/src/legacy/legacyapi/db/impl/sqlite/Session.h +++ b/src/legacy/legacyapi/db/impl/sqlite/Session.h @@ -28,4 +28,4 @@ class SQLiteSession : public Session { friend class SQLiteStmt; }; -} // namespace DB \ No newline at end of file +} // namespace DB diff --git a/src/legacy/legacyapi/db/impl/sqlite/Stmt.h b/src/legacy/legacyapi/db/impl/sqlite/Stmt.h index 52da0bfe..962187b6 100644 --- a/src/legacy/legacyapi/db/impl/sqlite/Stmt.h +++ b/src/legacy/legacyapi/db/impl/sqlite/Stmt.h @@ -53,4 +53,4 @@ class SQLiteStmt : public Stmt { create(const std::weak_ptr& sess, const std::string& sql, bool autoExecute = false); }; -} // namespace DB \ No newline at end of file +} // namespace DB diff --git a/src/legacy/legacyapi/utils/FileHelper.h b/src/legacy/legacyapi/utils/FileHelper.h index dd134c6b..e54597e0 100644 --- a/src/legacy/legacyapi/utils/FileHelper.h +++ b/src/legacy/legacyapi/utils/FileHelper.h @@ -10,4 +10,4 @@ std::vector GetFileNameList(const std::string& dir); bool CreateDirs(const std::string path); std::optional ReadAllFile(const std::string& filePath, bool isBinary = false); bool WriteAllFile(const std::string& filePath, const std::string& content, bool isBinary = false); -std::pair UncompressFile(const std::string& filePath, const std::string& toDir, int processTimeout); \ No newline at end of file +std::pair UncompressFile(const std::string& filePath, const std::string& toDir, int processTimeout); diff --git a/src/legacy/legacyapi/utils/STLHelper.h b/src/legacy/legacyapi/utils/STLHelper.h index 7e70a860..41e00c10 100644 --- a/src/legacy/legacyapi/utils/STLHelper.h +++ b/src/legacy/legacyapi/utils/STLHelper.h @@ -11,4 +11,4 @@ void erase_if(ContainerT& items, const PredicateT& predicate) { ++it; } } -}; \ No newline at end of file +}; diff --git a/src/legacy/main/EconomicSystem.h b/src/legacy/main/EconomicSystem.h index 24625536..810645ab 100644 --- a/src/legacy/main/EconomicSystem.h +++ b/src/legacy/main/EconomicSystem.h @@ -19,4 +19,4 @@ class EconomySystem { static bool transMoney(xuid_t player1, xuid_t player2, money_t money, string const& notes); static std::string getMoneyHist(xuid_t player, int time); static void clearMoneyHist(int time); -}; \ No newline at end of file +}; diff --git a/src/legacy/main/SafeGuardRecord.h b/src/legacy/main/SafeGuardRecord.h index 783b9042..0e5c3ae4 100644 --- a/src/legacy/main/SafeGuardRecord.h +++ b/src/legacy/main/SafeGuardRecord.h @@ -2,4 +2,4 @@ #include void InitSafeGuardRecord(); -void RecordOperation(const std::string& pluginName, const std::string& operation, const std::string& content); \ No newline at end of file +void RecordOperation(const std::string& pluginName, const std::string& operation, const std::string& content); diff --git a/src/legacy/utils/IniHelper.h b/src/legacy/utils/IniHelper.h index cf01c44d..1b851d49 100644 --- a/src/legacy/utils/IniHelper.h +++ b/src/legacy/utils/IniHelper.h @@ -21,4 +21,4 @@ class SimpleIni : public CSimpleIniA { string getString(const string& sec, const string& key, const string& def); bool getBool(const string& sec, const string& key, bool def); bool deleteKey(const std::string& sec, const std::string& key); -}; \ No newline at end of file +}; diff --git a/src/lse/PluginMigration.cpp b/src/lse/PluginMigration.cpp index 25a3c848..ea425f5f 100644 --- a/src/lse/PluginMigration.cpp +++ b/src/lse/PluginMigration.cpp @@ -41,14 +41,18 @@ auto migratePlugin(const PluginManager& pluginManager, const std::filesystem::pa const auto& pluginDir = ll::plugin::getPluginsRoot() / pluginFileBaseName; if (std::filesystem::exists(pluginDir / pluginFileName)) { - throw std::runtime_error( - fmt::format("failed to migrate legacy plugin at {}: {} already exists", ll::string_utils::u8str2str(path.u8string()), ll::string_utils::u8str2str(pluginDir.u8string())) - ); + throw std::runtime_error(fmt::format( + "failed to migrate legacy plugin at {}: {} already exists", + ll::string_utils::u8str2str(path.u8string()), + ll::string_utils::u8str2str(pluginDir.u8string()) + )); } if (!std::filesystem::exists(pluginDir)) { if (!std::filesystem::create_directory(pluginDir)) { - throw std::runtime_error(fmt::format("failed to create directory {}", ll::string_utils::u8str2str(pluginDir.u8string()))); + throw std::runtime_error( + fmt::format("failed to create directory {}", ll::string_utils::u8str2str(pluginDir.u8string())) + ); } }