Skip to content

Commit

Permalink
fix: charset
Browse files Browse the repository at this point in the history
修复各处关联字符编码但未随之变动的代码
  • Loading branch information
mystringEmpty committed Sep 1, 2024
1 parent 3ace6d9 commit 3b8fb88
Show file tree
Hide file tree
Showing 13 changed files with 356 additions and 341 deletions.
20 changes: 9 additions & 11 deletions Dice/CharacterCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,9 @@ bool CharaCard::erase(string& key) {
return true;
}
void CharaCard::writeb(std::ofstream& fout) const {
fwrite(fout, string("Name"));
fwrite(fout, string("Tag"));
fwrite(fout, Name);
fwrite(fout, string("Attrs"));
fwrite(fout, string("Attr"));
AnysTable::writeb(fout);
if (!locks.empty()) {
fwrite(fout, string("Lock"));
Expand All @@ -433,22 +433,20 @@ void CharaCard::readb(std::ifstream& fin) {
string tag = fread<string>(fin);
while (tag != "END") {
switch (mCardTag[tag]) {
case 1:
case 4:
setName(fread<string>(fin));
break;
case 1:
setName(GBKtoUTF8(fread<string>(fin)));
break;
case 2:
dict["__Type"] = fread<string>(fin);
break;
case 3:
case 11:
AnysTable::readb(fin);
break;
case 11: {
std::unordered_map<string, short>TempAttr;
fread(fin, TempAttr);
for (auto& [key, val] : TempAttr) {
AnysTable::set(key, val);
}
}
case 3:
AnysTable::readgb(fin);
break;
case 21: {
std::unordered_map<string, string>TempExp;
Expand Down
7 changes: 4 additions & 3 deletions Dice/CharacterCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ class CardTemp;

enum class trigger_time { AfterUpdate };
inline unordered_map<string, short> mCardTag = {
{"Name", 1},
{"Name", 1}, //older
{"Tag", 4},
{"Type", 2},
{"Attrs", 3},
{"Attrs", 3}, //older
{"Lock", 103},
{"Attr", 11}, //older
{"Attr", 11},
{"DiceExp", 21},
{"Note", 101}, //older
{"Info", 102}, //older
Expand Down
23 changes: 16 additions & 7 deletions Dice/Dice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ void dataBackUp()
std::filesystem::create_directory(DiceDir / "audit", ec);
//备份列表
static auto pathUser{ dirUser / "UserConf.dat" };
fs::copy_file(pathUser, dirUser / "UserConf.dat.bak", fs::copy_options::update_existing);
if (fs::exists(pathUser))fs::copy_file(pathUser, dirUser / "UserConf.dat.bak", fs::copy_options::update_existing);
saveBFile(pathUser, UserList);
static auto pathPlayer{ dirUser / "PlayerCards.RDconf" };
fs::copy_file(pathPlayer, dirUser / "PlayerCards.RDconf.bak", fs::copy_options::update_existing);
if (fs::exists(pathPlayer))fs::copy_file(pathPlayer, dirUser / "PlayerCards.RDconf.bak", fs::copy_options::update_existing);
saveBFile(pathPlayer, PList);
static auto pathChat{ dirUser / "ChatConf.dat" };
fs::copy_file(pathChat, dirUser / "ChatConf.dat.bak", fs::copy_options::update_existing);
if (fs::exists(pathChat))fs::copy_file(pathChat, dirUser / "ChatConf.dat.bak", fs::copy_options::update_existing);
saveBFile(pathChat, ChatList);
}

Expand Down Expand Up @@ -404,22 +404,31 @@ R"( //私骰作成 即可成为我的主人~
if (HGLOBAL hGlobal = LoadResource(hDllModule, hRsrcInfo)) {
LPVOID pBuffer = LockResource(hGlobal); // 锁定资源
char* pByte = new char[dwSize + 1];
fs::create_directories(DiceDir / "webui");
ofstream fweb{ DiceDir / "webui" / "index.html" };
fweb.write((const char*)pBuffer, dwSize);
memcpy_s(pByte, dwSize, pBuffer, dwSize);
FreeResource(hGlobal);// 释放资源
fs::create_directories(DiceDir / "webui");
fstream fweb{ DiceDir / "webui" / "webui.html" };
std::stringstream buffer;
buffer << fweb.rdbuf();
string content = buffer.str();
if (content != pByte) {
fweb.write(pByte, dwSize);
}
delete[] pByte;
}
}
#else
if (string html; Network::GET("https://raw.sevencdn.com/Dice-Developer-Team/Dice/newdev/Dice/webui.html", html)) {
fs::create_directories(DiceDir / "webui");
ofstream fweb{ DiceDir / "webui" / "index.html" };
ofstream fweb{ DiceDir / "webui" / "webui.html" };
fweb.write(html.c_str(), html.length());
}
else if (!fs::exists(DiceDir / "webui" / "index.html")) {
console.log("获取webui页面失败!相关功能无法使用!", 0b10);
}
#endif
if (fs::exists(DiceDir / "webui" / "webui.html"))
fs::copy_file(DiceDir / "webui" / "webui.html", DiceDir / "webui" / "index.html", fs::copy_options::update_existing);
ManagerServer->addHandler("/api/basicinfo", h_basicinfoapi);
ManagerServer->addHandler("/api/custommsg", h_msgapi);
ManagerServer->addHandler("/api/adminconfig", h_config);
Expand Down
99 changes: 46 additions & 53 deletions Dice/DiceAttrVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "DiceAttrVar.h"
#include "StrExtern.hpp"
#include "DiceFile.hpp"
#include "DDAPI.h"

ByteS::ByteS(std::ifstream& fin) {
len = fread<size_t>(fin);
Expand Down Expand Up @@ -166,45 +167,45 @@ void AnysTable::writeb(std::ofstream& fout) const {
int idx{ 0 };
for (auto& val : *list) {
++idx;
if (val)vars[to_string(idx)] = AttrVar(val.to_json());
if (val)vars[to_string(idx)] = val;
}
}
fwrite(fout, vars);
}
void AnysTable::readb(std::ifstream& fs) {
short len = fread<short>(fs);
if (len < 0)return;
if (!fs.peek()) {
fs.ignore(2);
}
while (len--) {
dict[fread<string>(fs)].readb(fs);
}
if (string strI{ "0" }; dict.count(strI) || dict.count(strI = "1")) {
list = std::make_shared<VarArray>();
int idx{ strI == "0" ? 0 : 1 };
do {
list->push_back(dict.at(strI));
dict.erase(strI);
} while (dict.count(strI = to_string(++idx)));
if (short len = fread<short>(fs); len > 0) {
if (!fs.peek()) {
fs.ignore(2);
}
while (len--) {
dict[fread<string>(fs)].readb(fs);
}
if (string strI{ "0" }; dict.count(strI) || dict.count(strI = "1")) {
list = std::make_shared<VarArray>();
int idx{ strI == "0" ? 0 : 1 };
do {
list->push_back(dict.at(strI));
dict.erase(strI);
} while (dict.count(strI = to_string(++idx)));
}
}
}
void AnysTable::readgb(std::ifstream& fs) {
short len = fread<short>(fs);
if (len < 0)return;
if (!fs.peek()) {
fs.ignore(2);
}
while (len--) {
dict[GBKtoUTF8(fread<string>(fs))].readb(fs);
}
if (string strI{ "0" }; dict.count(strI) || dict.count(strI = "1")) {
list = std::make_shared<VarArray>();
int idx{ strI == "0" ? 0 : 1 };
do {
list->push_back(dict.at(strI));
dict.erase(strI);
} while (dict.count(strI = to_string(++idx)));
if (short len = fread<short>(fs); len > 0) {
if (!fs.peek()) {
fs.ignore(2);
}
while (len--) {
dict[GBKtoUTF8(fread<string>(fs))].readb(fs);
}
if (string strI{ "0" }; dict.count(strI) || dict.count(strI = "1")) {
list = std::make_shared<VarArray>();
int idx{ strI == "0" ? 0 : 1 };
do {
list->push_back(dict.at(strI));
dict.erase(strI);
} while (dict.count(strI = to_string(++idx)));
}
}
}
bool AnysTable::operator<(const AnysTable other)const { return dict < other.dict; }
Expand Down Expand Up @@ -1115,48 +1116,41 @@ void AttrVar::writeb(std::ofstream& fout) const {
}
void AttrVar::readb(std::ifstream& fin) {
des();
char tag{ fread<char>(fin) };
Type tag{ Type(fread<char>(fin)) };
type = tag;
switch (tag){
case 1:
type = Type::Boolean;
case Type::Boolean:
bit = fread<bool>(fin);
break;
case 2:
type = Type::Integer;
case Type::Integer:
attr = fread<int>(fin);
break;
case 3:
type = Type::Number;
case Type::Number:
number = fread<double>(fin);
break;
case 4:
case Type::GBString:
type = Type::U8String;
new(&text) string(GBKtoUTF8(fread<string>(fin)));
break;
case 12:
type = Type::U8String;
case Type::U8String:
new(&text) string(fread<string>(fin));
break;
case 5:
type = Type::Table;
case Type::Table:
new(&table) AttrObject(AnysTable());
table->readb(fin);
break;
case 21:
case Type::GBTable:
type = Type::Table;
new(&table) AttrObject(AnysTable());
table->readb(fin);
table->readgb(fin);
break;
case 6:
type = Type::Function;
case Type::Function:
new(&chunk) ByteS(fin);
break;
case 7:
type = Type::ID;
case Type::ID:
id = fread<long long>(fin);
break;
case 8:
type = Type::Set;
case Type::Set:
new(&flags) AttrSet(std::make_shared<fifo_set<AttrIndex>>());
if (size_t cnt = fread<size_t>(fin)) {
while (cnt--) {
Expand All @@ -1178,8 +1172,7 @@ void AttrVar::readb(std::ifstream& fin) {
}
}
break;
case 0:
default:
case Type::Nil:
break;
}
}
Expand Down
15 changes: 7 additions & 8 deletions Dice/DiceEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2978,12 +2978,12 @@ int DiceEvent::InnerOrder() {
string strMessage = strMsg.substr(intMsgCnt);
if (strMessage == "reset") {
fmt->msg_reset(strName);
note("已重置" + strName + "的自定义", 0b1);
note("已重置" + strName + "的自定义", 0b1);
}
else {
if (strMessage == "NULL")strMessage = "";
fmt->msg_edit(strName, strMessage);
note("已自定义" + strName + "的文本", 0b1);
note("已自定义" + strName + "的文本", 0b1);
}
return 1;
}
Expand Down Expand Up @@ -3611,12 +3611,12 @@ int DiceEvent::InnerOrder() {
}
if (attr.find("自动成功") == 0) {
strDifficulty = attr.substr(0, 8);
attr = attr.substr(8);
attr = attr.substr(12);
isAutomatic = true;
}
if (attr.find("困难") == 0 || attr.find("极难") == 0) {
strDifficulty += attr.substr(0, 4);
intDifficulty = (attr.substr(0, 4) == "困难") ? 2 : 5;
strDifficulty += attr.substr(0, 6);
intDifficulty = (attr.substr(0, 6) == "困难") ? 2 : 5;
attr = attr.substr(4);
}
if (pc) {
Expand Down Expand Up @@ -4767,8 +4767,7 @@ string DiceEvent::readAttrName()
{
if (!isspace(static_cast<unsigned char>(strMsg[intMsgCnt])) || (!isspace(
static_cast<unsigned char>(strMsg[intEnd]))))intEnd = intMsgCnt;
if (strMsg[intMsgCnt] < 0)intMsgCnt += 2;
else intMsgCnt++;
intMsgCnt++;
}
if (intMsgCnt == strLowerMessage.length() && strLowerMessage.find(' ', intBegin) != string::npos)
{
Expand Down Expand Up @@ -4825,7 +4824,7 @@ int DiceEvent::readClock(Clock& cc)
if (nHour > 23)return -2;
cc.first = nHour;
if (strMsg[intMsgCnt] == ':' || strMsg[intMsgCnt] == '.')intMsgCnt++;
if (strMsg.substr(intMsgCnt, 2) == "")intMsgCnt += 2;
if (strMsg.substr(intMsgCnt, 3) == "")intMsgCnt += 3;
readSkipSpace();
if (intMsgCnt >= strMsg.length() || !is_digit(strMsg[intMsgCnt]))
{
Expand Down
2 changes: 1 addition & 1 deletion Dice/DiceMsgReply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ void DiceMsgReply::readJson(const fifo_json& j) {
if (j.count("mode")) {
size_t mode{ sMode[j["mode"].get<string>()] };
string keyword{ j.count("keyword") ?
j["keyword"] : title
string(j["keyword"]) : title
};
keyMatch[mode] = std::make_unique<vector<string>>
(mode == 3 ? vector<string>{keyword} : getLines(keyword, '|'));
Expand Down
6 changes: 3 additions & 3 deletions Dice/DiceSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void DiceSession::log_on(DiceEvent* msg) {
msg->replyMsg("strLogOnAlready");
return;
}
(*msg)["log_name"] = logger.name;
msg->set("log_name", logger.name);
logger.isLogging = true;
msg->replyMsg("strLogOn");
for (const auto& ct : areas) {
Expand Down Expand Up @@ -255,8 +255,8 @@ void DiceSession::log_end(DiceEvent* msg) {
msg->replyMsg("strLogEndEmpty");
return;
}
(*msg)["log_file"] = logger.fileLog;
(*msg)["log_path"] = log_path().string();
msg->set("log_file", logger.fileLog);
msg->set("log_path", log_path().string());
msg->replyMsg("strLogEnd");
update();
msg->set("hook","LogEnd");
Expand Down
Loading

0 comments on commit 3b8fb88

Please sign in to comment.