Commit 1cda9341 authored by fallenstardust's avatar fallenstardust

为debugMessage添加卡名显示

对查找不到的卡名显示的卡隐藏添加的???
parent 6f00d739
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "netserver.h" #include "netserver.h"
#include "single_mode.h" #include "single_mode.h"
#include <thread> #include <thread>
#include <string>
#include <regex>
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
#include <android/CAndroidGUIEditBox.h> #include <android/CAndroidGUIEditBox.h>
#include <android/CAndroidGUIComboBox.h> #include <android/CAndroidGUIComboBox.h>
...@@ -2064,17 +2066,49 @@ void Game::ClearChatMsg() { ...@@ -2064,17 +2066,49 @@ void Game::ClearChatMsg() {
chatTiming[i] = 0; chatTiming[i] = 0;
} }
} }
std::string WCharToUTF8(const wchar_t* input) {
std::string output;
if(input == nullptr) return output;
char buffer[1024];
wcstombs(buffer, input, 1024);
output = buffer;
return output;
}
void Game::AddDebugMsg(const char* msg) { void Game::AddDebugMsg(const char* msg) {
if (enable_log & 0x1) { std::string message(msg);
wchar_t wbuf[1024]; unsigned int cardID = 0;
BufferIO::DecodeUTF8(msg, wbuf); std::regex cardIdPattern(R"((\d{8}))");
AddChatMsg(wbuf, 9); auto words_begin = std::sregex_iterator(message.begin(), message.end(), cardIdPattern);
} auto words_end = std::sregex_iterator();
if (enable_log & 0x2) { for (std::sregex_iterator i = words_begin; i != words_end; ++i) {
char msgbuf[1040]; std::smatch match = *i;
std::snprintf(msgbuf, sizeof msgbuf, "[Script Error]: %s", msg); cardID = std::stoul(match.str());
ErrorLog(msgbuf); break;
} }
std::string cardName = "Unknown";
if(cardID != 0) {
cardName = WCharToUTF8(dataManager.GetName(cardID));
}
std::string fullMsg;
if(cardID != 0 && cardName != "???") {
fullMsg += cardName;
fullMsg += ":";
} else {
fullMsg += "";
}
fullMsg += message;
if (enable_log & 0x1) {
wchar_t wbuf[1024];
BufferIO::DecodeUTF8(fullMsg.c_str(), wbuf);
AddChatMsg(wbuf, 9);
}
if (enable_log & 0x2) {
char msgbuf[1040];
std::snprintf(msgbuf, sizeof msgbuf, "[Script Error]: %s", fullMsg.c_str());
ErrorLog(msgbuf);
}
} }
void Game::ErrorLog(const char* msg) { void Game::ErrorLog(const char* msg) {
FILE* fp = std::fopen("error.log", "at"); FILE* fp = std::fopen("error.log", "at");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment