Skip to content

Commit

Permalink
修复一个token的bug,尝试使用新的语言函数
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohengying committed Jul 19, 2021
1 parent 6d3e2f6 commit 86c1871
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 212 deletions.
2 changes: 1 addition & 1 deletion api/Offset.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ constexpr uint64_t BLOCK_GET_LEGACY = 0x10;
// todo:BlockLegacy::getBlockItemId(BlockLegacy *this)
constexpr uint64_t BLOCKLEGACY_GET_BLOCK_ID = 0x14C;

//
//
constexpr uint64_t BASECIRCUITCOMPONENT_GET_STRENGTH = 0x34;

// todo
Expand Down
1 change: 0 additions & 1 deletion api/commands/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ THook(
//找到发送命令的玩家

trapdoor::Actor *source = nullptr;
L_DEBUG("receive command");
trapdoor::bdsMod->getLevel()->forEachPlayer(
[&id, &source](trapdoor::Actor *player) {
if (player->getClientID()->getHash() == id->getHash()) {
Expand Down
11 changes: 5 additions & 6 deletions api/commands/CommandManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
namespace trapdoor {
namespace {
//字符串转为tokens列表
std::vector<std::string> tokenize(std::string &commandString) {
std::vector<std::string> tokenize(const std::string &commandString) {
std::vector<std::string> tokens;
std::stringstream str(commandString);
std::string command;
while (str >> commandString)
tokens.push_back(commandString);
while (str >> command)
tokens.push_back(command);
return tokens;
}

VA cmdQueue = 0;
} // namespace

//解析玩家命令字符串
int CommandManager::parse(Actor *player, std::string cmd) {
int CommandManager::parse(Actor *player, const std::string &cmd) {
auto tokens = tokenize(cmd);
if (tokens.empty())
return -1;
Expand Down Expand Up @@ -65,8 +65,7 @@ CommandNode *CommandManager::registerCmd(const std::string &cmd,
}

bool CommandManager::findCommand(const std::string &cmd) {
std::string buff(cmd);
auto tokens = tokenize(buff);
auto tokens = tokenize(cmd);
if (tokens.empty())
return false;
return this->commandList.find(tokens[0]) != this->commandList.end();
Expand Down
86 changes: 43 additions & 43 deletions api/commands/CommandManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,66 @@
#ifndef COMMANDMANAGER_COMMANDMANAGER_H
#define COMMANDMANAGER_COMMANDMANAGER_H

#define EXE(S) execute([&](ArgHolder *holder, Actor *player) { S })
#define ARG(arg, desc, type, work) Arg(arg, desc, ArgType::type)->EXE(work)

#define EXE(S) execute([&](ArgHolder *holder,Actor *player){S})
#define ARG(arg, desc, type, work) Arg(arg,desc,ArgType::type)->EXE(work)

#include <map>
#include <vector>
#include <sstream>
#include "CommandNode.h"
#include "entity/Actor.h"
#include "tools/noncopyable .h"

#include <map>
#include <sstream>
#include <vector>

namespace trapdoor {

struct CommandConfig {
bool enable = true; //是否启用
CommandPermissionLevel permissionLevel = Admin; //权限等级
//下面两个还没启用,主要是还没获取游戏模式的接口(设置游戏模式的都有了)
bool needCheat = false;
bool survival = false; //生存中是否可用
};
struct CommandConfig {
bool enable = true; //是否启用
CommandPermissionLevel permissionLevel = Admin; //权限等级
//下面两个还没启用,主要是还没获取游戏模式的接口(设置游戏模式的都有了)
bool needCheat = false;
bool survival = false; //生存中是否可用
};

class CommandManager : public trapdoor::noncopyable {
//命令列表
std::map<std::string, CommandNode *> commandList;
//命令配置文件列表
std::map<std::string, CommandConfig> commandConfigList;

class CommandManager : public trapdoor::noncopyable {
//命令列表
std::map<std::string, CommandNode *> commandList;
//命令配置文件列表
std::map<std::string, CommandConfig> commandConfigList;
public:
CommandNode *registerCmd(const std::string &cmd,
const std::string &description = "no description",
CommandPermissionLevel level = Any,
ArgType type = ArgType::NONE);
public:
CommandNode *registerCmd(const std::string &cmd,
const std::string &description = "no description",
CommandPermissionLevel level = Any,
ArgType type = ArgType::NONE);

bool enablePermissionCheck = true;
bool enablePermissionCheck = true;

//解析命令
int parse(Actor *player, std::string cmd);
//解析命令
int parse(Actor *player, const std::string &cmd);

inline void setEnablePermissionCheck(bool able) {
this->enablePermissionCheck = able;
}
inline void setEnablePermissionCheck(bool able) {
this->enablePermissionCheck = able;
}

//设置命令配置
void setCommandConfig(std::map<std::string, CommandConfig> &cmdConfigList);
//设置命令配置
void setCommandConfig(std::map<std::string, CommandConfig> &cmdConfigList);

//打印帮助信息
void printfHelpInfo(Actor *player);
//打印帮助信息
void printfHelpInfo(Actor *player);

//在当前命令列表里面查找命令
bool findCommand(const std::string &cmd);
//在当前命令列表里面查找命令
bool findCommand(const std::string &cmd);

//检查权限等级
bool checkCommandPermission(const std::string &command, Actor *player, bool showInfo = true);
//检查权限等级
bool checkCommandPermission(const std::string &command, Actor *player,
bool showInfo = true);

//执行原版命令
static bool runVanillaCommand(const std::string &command);
};
//执行原版命令
static bool runVanillaCommand(const std::string &command);
};

}
} // namespace trapdoor

typedef trapdoor::CommandManager CommandManager;

#endif //COMMANDMANAGER_COMMANDMANAGER_H
#endif // COMMANDMANAGER_COMMANDMANAGER_H
5 changes: 5 additions & 0 deletions api/language/I18nManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@ void I18nManager::getSystemLangAndSet() {
std::string LANG(const std::string &l) {
return trapdoor::bdsMod->getI18NManager().get(l);
}

} // namespace trapdoor

std::string operator""_i18(const char *key, unsigned long long) {
return trapdoor::LANG(key);
}
55 changes: 29 additions & 26 deletions api/language/I18nManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,47 @@
#ifndef MOD_I18NMANAGER_H
#define MOD_I18NMANAGER_H

#include "tools/json.hpp"
#include <set>
#include <unordered_map>
#include "tools/json.hpp"

namespace trapdoor {
using json = nlohmann::json;
using json = nlohmann::json;

class I18nManager {
std::string current_lang = "zh_cn";
std::set<std::string> languages;
std::unordered_map<std::string, std::unordered_map<std::string, std::string>> strings;
class I18nManager {
std::string current_lang = "zh_cn";
std::set<std::string> languages;
std::unordered_map<std::string,
std::unordered_map<std::string, std::string>>
strings;

void findLanguageFile();
void findLanguageFile();

void readLanguageFile(const std::string &langName);
void readLanguageFile(const std::string &langName);

void getSystemLangAndSet();
void getSystemLangAndSet();

public:
std::string get(const std::string &id);
public:
std::string get(const std::string &id);

bool tryChangeLanguage(const std::string &language);
bool tryChangeLanguage(const std::string &language);

std::string getAllLanguages() {
std::string s;
for (const auto &lang:this->languages)
s += lang + "\n";
return s;
}
std::string getAllLanguages() {
std::string s;
for (const auto &lang : this->languages)
s += lang + "\n";
return s;
}

inline void initialize() {
this->getSystemLangAndSet();
this->findLanguageFile();
}
};
inline void initialize() {
this->getSystemLangAndSet();
this->findLanguageFile();
}
};

std::string LANG(const std::string &l);
}
std::string LANG(const std::string &l);
} // namespace trapdoor

std::string operator""_i18(const char *key, unsigned long long);

#endif //MOD_I18NMANAGER_H
#endif // MOD_I18NMANAGER_H
Loading

0 comments on commit 86c1871

Please sign in to comment.