Skip to content

Commit 9ca2736

Browse files
committed
feat: webui
1 parent 7a79bba commit 9ca2736

File tree

12 files changed

+44
-1436
lines changed

12 files changed

+44
-1436
lines changed

Dice/CharacterCard.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,14 @@ void Player::readb(std::ifstream& fin)
724724
NameList[name] = card;
725725
}
726726
}
727-
if (short len = fread<short>(fin); len > 0){
727+
if (short len = fread<short>(fin); len > 0) {
728728
while (len--) {
729729
unsigned long long gid = fread<unsigned long long>(fin);
730730
unsigned short pcid = fread<unsigned short>(fin);
731-
if(mCardList.count(pcid))mGroupCard[gid] = mCardList[pcid];
731+
if (mCardList.count(pcid))mGroupCard[gid] = mCardList[pcid];
732732
}
733733
}
734+
else if (!mCardList.empty())mGroupCard[0] = mCardList[0];
734735
}
735736

736737
AttrVar idx_pc(const AttrObject& eve){

Dice/CharacterCard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class CharaCard: public AnysTable
189189
void setType(const string&);
190190
void update();
191191
CharaCard(size_t i) :id(i) {
192-
dict["__Name"] = to_string(id);
192+
dict["__Name"] = Name = to_string(id);
193193
setType("COC7");
194194
dict["__Update"] = (long long)time(nullptr);
195195
}

Dice/Dice.cpp

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -392,43 +392,36 @@ R"( //私骰作成 即可成为我的主人~
392392
llStartTime = time(nullptr);
393393
DD::debugLog("Dice.WebInit");
394394
if (console["EnableWebUI"]) {
395+
fs::path dirWebUI{ DiceDir / "webui" };
395396
try {
396397
const std::string port_option = std::string(AllowInternetAccess ? "0.0.0.0" : "127.0.0.1") + ":" + std::to_string(Port);
397398

398-
std::vector<std::string> mg_options = { "document_root", (DiceDir / "webui").u8string(), "listening_ports", port_option.c_str() };
399+
std::vector<std::string> mg_options = { "document_root", dirWebUI.u8string(), "listening_ports", port_option.c_str() };
399400

400401
ManagerServer = std::make_unique<CivetServer>(mg_options);
401-
#ifdef _WIN32
402-
if (HRSRC hRsrcInfo = FindResource(hDllModule, MAKEINTRESOURCE(ID_ADMIN_HTML), TEXT("FILE"))) {
403-
DWORD dwSize = SizeofResource(hDllModule, hRsrcInfo);
404-
if (HGLOBAL hGlobal = LoadResource(hDllModule, hRsrcInfo)) {
405-
LPVOID pBuffer = LockResource(hGlobal); // 锁定资源
406-
char* pByte = new char[dwSize + 1];
407-
memcpy_s(pByte, dwSize, pBuffer, dwSize);
408-
FreeResource(hGlobal);// 释放资源
409-
fs::create_directories(DiceDir / "webui");
410-
fstream fweb{ DiceDir / "webui" / "webui.html" };
411-
std::stringstream buffer;
412-
buffer << fweb.rdbuf();
413-
string content = buffer.str();
414-
if (content != pByte) {
415-
fweb.write(pByte, dwSize);
416-
}
417-
delete[] pByte;
418-
}
402+
#ifndef __ANDROID__
403+
if (!fs::exists(dirWebUI / ".git") && fs::exists(dirWebUI)) {
404+
console.log("删除旧index.html");
405+
fs::remove_all(dirWebUI);
406+
}
407+
if (!fs::exists(dirWebUI)) {
408+
DiceRepo repo{ dirWebUI, "https://gitee.com/diceki/DiceWebUI.git" };
409+
}
410+
else {
411+
DiceRepo repo{ dirWebUI };
412+
string errinfo;
413+
repo.update(errinfo);
419414
}
420415
#else
421416
if (string html; Network::GET("https://raw.sevencdn.com/Dice-Developer-Team/Dice/newdev/Dice/webui.html", html)) {
422-
fs::create_directories(DiceDir / "webui");
423-
ofstream fweb{ DiceDir / "webui" / "webui.html" };
417+
fs::create_directories(dirWebUI);
418+
ofstream fweb{ DiceDir / "webui" / "index.html" };
424419
fweb.write(html.c_str(), html.length());
425420
}
426-
else if (!fs::exists(DiceDir / "webui" / "index.html")) {
421+
#endif
422+
if (!fs::exists(DiceDir / "webui" / "index.html")) {
427423
console.log("获取webui页面失败!相关功能无法使用!", 0b10);
428424
}
429-
#endif
430-
if (fs::exists(DiceDir / "webui" / "webui.html"))
431-
fs::copy_file(DiceDir / "webui" / "webui.html", DiceDir / "webui" / "index.html", fs::copy_options::update_existing);
432425
ManagerServer->addHandler("/api/basicinfo", h_basicinfoapi);
433426
ManagerServer->addHandler("/api/custommsg", h_msgapi);
434427
ManagerServer->addHandler("/api/adminconfig", h_config);

Dice/DiceEvent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3623,7 +3623,7 @@ int DiceEvent::InnerOrder() {
36233623
attr = attr.substr(12);
36243624
isAutomatic = true;
36253625
}
3626-
if (attr.find("困难") == 0 || attr.find("极难") == 0) {
3626+
if (attr.find("困难") == 0 || attr.find("极难") == 0 || attr.find("极限") == 0) {
36273627
strDifficulty += attr.substr(0, 6);
36283628
intDifficulty = (attr.substr(0, 6) == "困难") ? 2 : 5;
36293629
attr = attr.substr(6);

Dice/DiceJS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ int js_dice_Set_get_own(JSContext* ctx, JSPropertyDescriptor* desc, JSValueConst
414414
}
415415
int js_dice_Set_delete(JSContext* ctx, JSValue obj, JSAtom atom) {
416416
JS2SET(obj);
417-
return set->erase(js_AtomToIndex(ctx, atom)) != set->end() ? JS_TRUE : JS_FALSE;
417+
return set->erase(js_AtomToIndex(ctx, atom)) != set->end() ? TRUE : FALSE;
418418
}
419419

420420
QJSDEF(log) {

Dice/GlobalVar.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ const dict_ci<string> PlainMsg
442442
{"strSelfName", "" },
443443
{"strSelfNick", "&strSelfName" },
444444
{"self", "&strSelfCall"},
445-
{"strBotHeader", "试验型 " },
445+
{"strBotHeader", "标准型 " },
446446
{"strBotMsg", "\n使用.help 查看{self}帮助文档"},
447447
{"strHlpMsg", R"(请使用.dismiss ID(或后四位) 使{self}退群退讨论组
448448
.bot on/off ID(或at或后四位) //开启或关闭指令
@@ -721,8 +721,8 @@ Type=[回复性质](Reply/Order)
721721
)" },
722722
{"回复列表","{strSelfName}的回复触发词列表:{list_reply_deck}"},
723723
{"game",R"(游戏模式:
724-
`.game new 桌名` 创建游戏(桌名可省略,前缀以`规则:`可以指定应用规则)
725-
例: `.game new DND:`
724+
`.game new 桌名` 创建游戏(桌名可省略,前缀以`规则-`可以指定应用规则)
725+
例: `.game new DND-`
726726
创建者自动视为GM
727727
`.game over` 销毁本桌游戏
728728
`.game state` 查看本桌状态

Dice/GlobalVar.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
* Please Do not modify Dice_Build, Dice_Ver_Without_Build, DiceRequestHeader or Dice_Ver
3838
* To costum version info, please modify const Dice_Short_Ver or Dice_Full_Ver
3939
*/
40-
constexpr unsigned short Dice_Build = 665u;
41-
inline const std::string Dice_Ver_Without_Build = "2.7.0beta10";
40+
constexpr unsigned short Dice_Build = 666u;
41+
inline const std::string Dice_Ver_Without_Build = "2.7.0release";
4242
constexpr auto DiceRequestHeader = "Dice/2.7.0";
4343
inline const std::string Dice_Ver = Dice_Ver_Without_Build + "(" + std::to_string(Dice_Build) + ")";
4444
extern std::string Dice_Short_Ver;

Dice/ManagerSystem.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ AttrVar getContextItem(const AttrObject& context, string item, bool isTrust) {
222222
}
223223

224224
[[nodiscard]] bool User::empty() const {
225-
return (!nTrust) && (!updated()) && dict.empty() && strNick.empty();
225+
return (!nTrust) && (!updated()) && dict.size() <= 1 && strNick.empty();
226+
}
227+
[[nodiscard]] bool Chat::empty() const {
228+
return !updated() && dict.size() <= 1;
226229
}
227230
void User::setConf(const string& key, const AttrVar& val)
228231
{

Dice/ManagerSystem.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ class User :public AnysTable
6464
const long long ID = 0;
6565
//1-私用信任,2-拉黑豁免,3-加黑退群,4-后台管理,5-Master
6666
int nTrust = 0;
67-
time_t tCreated = time(nullptr);
67+
time_t tCreated = 0;
6868

69-
explicit User(long long id): ID(id){}
69+
explicit User(long long id): ID(id){
70+
dict["tCreated"] = tCreated = time(nullptr);
71+
}
7072
unordered_map<long long, string> strNick{};
7173
mutable std::mutex ex_user;
7274
bool has(const string& key)const override;
@@ -153,9 +155,11 @@ class Chat :public AnysTable {
153155
MetaType getType()const override { return MetaType::Context; }
154156
const long long ID = 0;
155157
long long inviter = 0;
156-
time_t tCreated = time(nullptr);
158+
time_t tCreated = 0;
157159

158-
explicit Chat(long long id):ID(id) {}
160+
explicit Chat(long long id):ID(id) {
161+
dict["tCreated"] = tCreated = time(nullptr);
162+
}
159163

160164
unordered_map<long long, AnysTable>ChConf;
161165

@@ -194,6 +198,7 @@ class Chat :public AnysTable {
194198
return *this;
195199
}
196200
void invited(long long id);
201+
[[nodiscard]] bool empty() const override;
197202
int getConf(const string& key, int def = 0) {
198203
if (has(key))return get_int(key);
199204
return def;

Dice/Resource.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ END
4444

4545
#endif // APSTUDIO_INVOKED
4646

47-
ID_ADMIN_HTML FILE "webui.html"
47+
// ID_ADMIN_HTML FILE "webui.html"
4848

4949
/////////////////////////////////////////////////////////////////////////////
5050
//

0 commit comments

Comments
 (0)