Commit b5bae3aa authored by mercury233's avatar mercury233 Committed by DailyShana

update error logging (#1950)

parent a0ef133c
......@@ -1104,7 +1104,7 @@ void Game::AddChatMsg(wchar_t* msg, int player) {
chatMsg[0].append(L"[System]: ");
break;
case 9: //error message
chatMsg[0].append(L"[Script error:] ");
chatMsg[0].append(L"[Script Error]: ");
break;
default: //from watcher or unknown
if(player < 11 || player > 19)
......@@ -1112,6 +1112,25 @@ void Game::AddChatMsg(wchar_t* msg, int player) {
}
chatMsg[0].append(msg);
}
void Game::AddDebugMsg(char* msg)
{
if (enable_log & 0x1) {
wchar_t wbuf[1024];
BufferIO::DecodeUTF8(msg, wbuf);
mainGame->AddChatMsg(wbuf, 9);
}
if (enable_log & 0x2) {
FILE* fp = fopen("error.log", "at");
if (!fp)
return;
time_t nowtime = time(NULL);
struct tm *localedtime = localtime(&nowtime);
char timebuf[40];
strftime(timebuf, 40, "%Y-%m-%d %H:%M:%S", localedtime);
fprintf(fp, "[%s][Script Error]: %s\n", timebuf, msg);
fclose(fp);
}
}
void Game::ClearTextures() {
matManager.mCard.setTexture(0, 0);
mainGame->imgCard->setImage(0);
......
......@@ -104,6 +104,7 @@ public:
void SaveConfig();
void ShowCardInfo(int code);
void AddChatMsg(wchar_t* msg, int player);
void AddDebugMsg(char* msgbuf);
void ClearTextures();
void CloseDuelWindow();
......
......@@ -855,17 +855,7 @@ int ReplayMode::MessageHandler(long fduel, int type) {
return 0;
char msgbuf[1024];
get_log_message(fduel, (byte*)msgbuf);
if(enable_log == 1) {
wchar_t wbuf[1024];
BufferIO::DecodeUTF8(msgbuf, wbuf);
mainGame->AddChatMsg(wbuf, 9);
} else if(enable_log == 2) {
FILE* fp = fopen("error.log", "at");
if(!fp)
return 0;
fprintf(fp, "[Script error:] %s\n", msgbuf);
fclose(fp);
}
mainGame->AddDebugMsg(msgbuf);
return 0;
}
......
......@@ -1474,17 +1474,7 @@ int SingleDuel::MessageHandler(long fduel, int type) {
return 0;
char msgbuf[1024];
get_log_message(fduel, (byte*)msgbuf);
if(enable_log == 1) {
wchar_t wbuf[1024];
BufferIO::DecodeUTF8(msgbuf, wbuf);
mainGame->AddChatMsg(wbuf, 9);
} else if(enable_log == 2) {
FILE* fp = fopen("error.log", "at");
if(!fp)
return 0;
fprintf(fp, "[Script error:] %s\n", msgbuf);
fclose(fp);
}
mainGame->AddDebugMsg(msgbuf);
return 0;
}
void SingleDuel::SingleTimer(evutil_socket_t fd, short events, void* arg) {
......
......@@ -828,17 +828,7 @@ int SingleMode::MessageHandler(long fduel, int type) {
return 0;
char msgbuf[1024];
get_log_message(fduel, (byte*)msgbuf);
if(enable_log == 1) {
wchar_t wbuf[1024];
BufferIO::DecodeUTF8(msgbuf, wbuf);
mainGame->AddChatMsg(wbuf, 9);
} else if(enable_log == 2) {
FILE* fp = fopen("error.log", "at");
if(!fp)
return 0;
fprintf(fp, "[Script error:] %s\n", msgbuf);
fclose(fp);
}
mainGame->AddDebugMsg(msgbuf);
return 0;
}
......
......@@ -1581,17 +1581,7 @@ int TagDuel::MessageHandler(long fduel, int type) {
return 0;
char msgbuf[1024];
get_log_message(fduel, (byte*)msgbuf);
if(enable_log == 1) {
wchar_t wbuf[1024];
BufferIO::DecodeUTF8(msgbuf, wbuf);
mainGame->AddChatMsg(wbuf, 9);
} else if(enable_log == 2) {
FILE* fp = fopen("error.log", "at");
if(!fp)
return 0;
fprintf(fp, "[Script error:] %s\n", msgbuf);
fclose(fp);
}
mainGame->AddDebugMsg(msgbuf);
return 0;
}
void TagDuel::TagTimer(evutil_socket_t fd, short events, void* arg) {
......
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