Files
Client/Server/ManageTool/ChatParser/ChatParserDlg.cpp
LGram16 dd97ddec92 Restructure repository to include all source folders
Move git root from Client/ to src/ to track all source code:
- Client: Game client source (moved to Client/Client/)
- Server: Game server source
- GameTools: Development tools
- CryptoSource: Encryption utilities
- database: Database scripts
- Script: Game scripts
- rylCoder_16.02.2008_src: Legacy coder tools
- GMFont, Game: Additional resources

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 20:17:20 +09:00

565 lines
13 KiB
C++

// ChatParserDlg.cpp : 구현 파일
//
#include "stdafx.h"
#include "ChatParser.h"
#include "ChatParserDlg.h"
#include "NFTokenizer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 응용 프로그램 정보에 사용되는 CAboutDlg 대화 상자입니다.
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// 대화 상자 데이터입니다.
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 지원입니다.
// 구현입니다.
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CChatParserDlg 대화 상자
CChatParserDlg::CChatParserDlg(CWnd* pParent /*=NULL*/)
: CDialog(CChatParserDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CChatParserDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_CHATLIST, m_ChatList);
DDX_Control(pDX, IDC_OLDVERSION, m_OldVersion);
DDX_Control(pDX, IDC_SERVERID, m_ServerGroup);
DDX_Control(pDX, IDC_ZONEID, m_ServerZone);
DDX_Control(pDX, IDC_CHATTYPE, m_ChatType);
DDX_Control(pDX, IDC_FINDNAMECHK, m_FindNameChk);
DDX_Control(pDX, IDC_FINDNAME, m_FindName);
}
BEGIN_MESSAGE_MAP(CChatParserDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_OPENFILE, &CChatParserDlg::OnBnClickedOpenfile)
ON_BN_CLICKED(IDC_FINDLIST, &CChatParserDlg::OnBnClickedFindlist)
ON_BN_CLICKED(IDC_FINDNAMECHK, &CChatParserDlg::OnBnClickedFindnamechk)
END_MESSAGE_MAP()
// CChatParserDlg 메시지 처리기
BOOL CChatParserDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 시스템 메뉴에 "정보..." 메뉴 항목을 추가합니다.
// IDM_ABOUTBOX는 시스템 명령 범위에 있어야 합니다.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 이 대화 상자의 아이콘을 설정합니다. 응용 프로그램의 주 창이 대화 상자가 아닐 경우에는
// 프레임워크가 이 작업을 자동으로 수행합니다.
SetIcon(m_hIcon, TRUE); // 큰 아이콘을 설정합니다.
SetIcon(m_hIcon, FALSE); // 작은 아이콘을 설정합니다.
// TODO: 여기에 추가 초기화 작업을 추가합니다.
SetDlgItemText(IDC_OPENFILE, GetMyINIString("LOCAL_STRING", "STRING_01"));
SetDlgItemText(IDC_OLDVERSION, GetMyINIString("LOCAL_STRING", "STRING_02"));
SetDlgItemText(IDC_FINDLIST, GetMyINIString("LOCAL_STRING", "STRING_04"));
SetDlgItemText(IDC_FINDNAMECHK, GetMyINIString("LOCAL_STRING", "STRING_05"));
m_FindName.EnableWindow(FALSE);
int iCount = atoi(GetMyINIString("SERVER_GROUP", "SERVER_GROUP_CNT"));
char strID[32];
char strName[32];
m_ServerGroup.AddString("All");
for(int i = 0; i < iCount; ++i)
{
wsprintf(strID, "SERVER_GROUP%d", i+1);
m_ServerGroup.AddString(GetMyINIString("SERVER_GROUP", strID));
}
m_ServerGroup.SetCurSel(0);
iCount = atoi(GetMyINIString("SERVER_ZONE", "SERVER_ZONE_CNT"));
m_ServerZone.AddString("All");
for(int i = 0; i < iCount; ++i)
{
wsprintf(strID, "SERVER_ZONE%d", i+1);
wsprintf(strName, "ZONE%s", GetMyINIString("SERVER_ZONE", strID));
m_ServerZone.AddString(strName);
}
m_ServerZone.SetCurSel(0);
iCount = atoi(GetMyINIString("CHAT_TYPE", "CHAT_TYPE_CNT"));
m_ChatType.AddString("All");
for(int i = 0; i < iCount; ++i)
{
wsprintf(strID, "CHAT_TYPE%d", i+1);
m_ChatType.AddString(GetMyINIString("CHAT_TYPE", strID));
}
m_ChatType.SetCurSel(0);
memset(&m_OpenFile, 0, sizeof(OPENFILENAME));
m_OpenFile.lStructSize = sizeof(OPENFILENAME);
m_OpenFile.hwndOwner = m_hWnd;
m_OpenFile.lpstrFilter = "Chat Log files\0*.log\0All files\0*.*";
m_OpenFile.nMaxFile = MAX_PATH * MAX_PATH;
m_OpenFile.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_EXPLORER;
m_OpenFile.lpstrFile = m_szFileName;
return TRUE; // 포커스를 컨트롤에 설정하지 않으면 TRUE를 반환합니다.
}
void CChatParserDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 대화 상자에 최소화 단추를 추가할 경우 아이콘을 그리려면
// 아래 코드가 필요합니다. 문서/뷰 모델을 사용하는 MFC 응용 프로그램의 경우에는
// 프레임워크에서 이 작업을 자동으로 수행합니다.
void CChatParserDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 그리기를 위한 디바이스 컨텍스트
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 클라이언트 사각형에서 아이콘을 가운데에 맞춥니다.
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 아이콘을 그립니다.
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// 사용자가 최소화된 창을 끄는 동안에 커서가 표시되도록 시스템에서
// 이 함수를 호출합니다.
HCURSOR CChatParserDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
// 추가
void CChatParserDlg::AddLineToChatList(unsigned char cChatType, char* szMsg)
{
CXListBox::Color cBackColor = CXListBox::BackColor;
CXListBox::Color cMessageColor = CXListBox::ChatNormal;
switch(cChatType)
{
case NORMAL:
cBackColor = CXListBox::BackColor; cMessageColor = CXListBox::ChatNormal;
break;
case PARTY:
cBackColor = CXListBox::BackColor; cMessageColor = CXListBox::ChatParty;
break;
case FRIEND:
cBackColor = CXListBox::BackColor; cMessageColor = CXListBox::ChatFriend;
break;
case GUILD:
cBackColor = CXListBox::BackColor; cMessageColor = CXListBox::ChatGuild;
break;
case CLIENT_LOG:
cBackColor = CXListBox::BackColor; cMessageColor = CXListBox::ChatNormal;
break;
case STALL:
cBackColor = CXListBox::BackColor; cMessageColor = CXListBox::ChatStall;
break;
case SHOUT:
cBackColor = CXListBox::BackColor; cMessageColor = CXListBox::ChatShout;
break;
case ADMIN_NORMAL_CHAT:
cBackColor = CXListBox::BackColor; cMessageColor = CXListBox::ChatAdminNormal;
break;
case ADMIN_SHOUT:
cBackColor = CXListBox::BackColor; cMessageColor = CXListBox::ChatAdminShout;
break;
case WHISPER:
cBackColor = CXListBox::BackColor; cMessageColor = CXListBox::ChatWhisper;
break;
case TRADE:
cBackColor = CXListBox::BackColor; cMessageColor = CXListBox::ChatTrade;
break;
case NOTICE:
cBackColor = CXListBox::BackColor; cMessageColor = CXListBox::ChatNotice;
break;
case DICE:
cBackColor = CXListBox::BackColor; cMessageColor = CXListBox::ChatAdminShout;
break;
case GMREPORT:
cBackColor = CXListBox::BackColor; cMessageColor = CXListBox::GMReport;
break;
}
m_ChatList.AddLine(cMessageColor, cBackColor, szMsg, FALSE);
}
void CChatParserDlg::Cleanup()
{
m_ChatList.ResetContent();
}
void CChatParserDlg::OnBnClickedOpenfile()
{
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
ZeroMemory(m_szFileName, MAX_PATH);
if(GetOpenFileName(&m_OpenFile))
{
// 파서하기
LoadFile();
SetDlgItemText(IDC_OPEN_FILENAME, m_szFileName);
}
}
void CChatParserDlg::LoadFile()
{
FILE* fp = fopen(m_szFileName, "rt");
if(fp == NULL)
return;
Cleanup();
m_ChatData.clear();
int iCount = 0;
BOOL bOldVersion = FALSE;
if(m_OldVersion.GetCheck())
bOldVersion = TRUE;
char strData[2048];
int Len = 0;
CHATLIST st;
while(!feof(fp))
{
fgets(strData, 2048, fp);
if(strncmp(strData, "[Ty-NOR]", 8) == 0)
break;
else
{
std::string str = strData;
std::string temp, temp2;
Nave::NFTokenizerA token(str, "[");
int iToken = token.CountTokens();
DWORD dwServerID = 0;
int Temp = 0;
for(int i = 0; i < iToken; ++i)
{
temp = token.NextToken();
if(i == 0) // 시간
{
sscanf(temp.c_str(), "%04d-%02d-%02d %02d:%02d:%02d",
&st.sysTime.wYear, &st.sysTime.wMonth, &st.sysTime.wDay,
&st.sysTime.wHour, &st.sysTime.wMinute, &st.sysTime.wSecond);
}
else if(i == 1)
{
sscanf(temp.c_str(), "ServerID:0x%08x", &dwServerID);
}
else if(i == 2)
{
temp2 = &temp[6];
temp2.erase(temp2.end()-1);
int n = temp2.find_first_of(" ");
strcpy(st.strServerName, temp2.c_str());
st.strServerName[n] = 0;
}
else if(i == 3)
{
sscanf(temp.c_str(), "Zone:%2d", &st.iZone);
}
else if(i == 4)
{
sscanf(temp.c_str(), "CH:%2d", &st.iChannel);
}
else if(i == 5)
{
sscanf(temp.c_str(), "X:%4d", &Temp);
}
else if(i == 6)
{
sscanf(temp.c_str(), "Z:%4d", &Temp);
}
else if(i == 7)
{
sscanf(temp.c_str(), "UID:%10d", &st.dwUID);
}
else if(i == 8)
{
sscanf(temp.c_str(), "CID:%10d", &st.dwCID);
}
else if(i == 9)
{
sscanf(temp.c_str(), "Type:%2d", &st.iChatType);
}
else if(i == 10)
{
temp2 = &temp[2];
temp2.erase(temp2.end()-1);
int n = temp2.find_last_not_of(" ");
strcpy(st.strSenderName, temp2.c_str());
st.strSenderName[n+1] = 0;
}
else if(i == 11)
{
temp2 = &temp[2];
temp2.erase(temp2.end()-1);
int n = temp2.find_last_not_of(" ");
strcpy(st.strTargetName, temp2.c_str());
st.strTargetName[n+1] = 0;
}
else if(i == 12)
{
strncpy(st.strMessage, temp.c_str(), temp.size()-2);
st.strMessage[temp.size()-2] = 0;
}
}
m_ChatData[iCount++] = st;
}
/*
if(strncmp(strData, "[Ty-NOR]", 8) == 0)
break;
else
{
// 시간 읽기
sscanf(strData, "[%04d-%02d-%02d %02d:%02d:%02d]",
&st.sysTime.wYear, &st.sysTime.wMonth, &st.sysTime.wDay,
&st.sysTime.wHour, &st.sysTime.wMinute, &st.sysTime.wSecond);
// 그룹
sscanf(&strData[21], "[Group:%s]", st.strServerName);
// 아이디들
sscanf(&strData[44], "[Zone:%2d][CH:%2d][UID:%10d][CID:%10d][Type:%2d]", &st.iZone, &st.iChannel, &st.dwUID, &st.dwCID, &st.iChatType);
if(strncmp(&strData[101], "[S:", 3) == 0)
{
// Sender
sscanf(&strData[101], "[S:%s]", st.strSenderName);
// Target
sscanfe(&strData[120], "[T:%s]", st.strTargetName);
if(st.strTargetName[0] == ']')
ZeroMemory(st.strTargetName, 32);
// Msg
strcpy(st.strMessage, &strData[140]);
Len = (int)strlen(st.strMessage);
if(st.strMessage[Len-2] == ']')
st.strMessage[Len-2] = 0;
else
st.strMessage[Len-1] = 0;
}
else
{
// Msg
strcpy(st.strMessage, &strData[102]);
Len = (int)strlen(st.strMessage);
if(st.strMessage[Len-2] == ']')
st.strMessage[Len-2] = 0;
else
st.strMessage[Len-1] = 0;
}
m_ChatData[iCount++] = st;
}
*/
}
m_ChatList.AddString(GetMyINIString("LOCAL_STRING", "STRING_03"));
fclose(fp);
}
void CChatParserDlg::OnBnClickedFindlist()
{
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
Cleanup();
char strData[2048];
int Len = 0;
char strTemp[32];
char strServerGroup[32];
int iGroupID = m_ServerGroup.GetCurSel();
if(iGroupID != 0)
{
m_ServerGroup.GetWindowText(strServerGroup, 32);
}
int iZoneID = m_ServerZone.GetCurSel();
if(iZoneID != 0)
{
iZoneID = 0;
m_ServerZone.GetWindowText(strTemp, 32);
sscanf(strTemp, "ZONE%d", &iZoneID);
}
int iChatType = m_ChatType.GetCurSel();
if(iChatType != 0)
{
m_ChatType.GetWindowText(strTemp, 32);
iChatType = GetChatType(strTemp);
}
char strName[64];
BOOL bFindName = FALSE;
if(m_FindNameChk.GetCheck())
{
bFindName = TRUE;
m_FindName.GetWindowText(strName, 64);
}
else
{
ZeroMemory(strName, 64);
}
// 출력
std::map<int, CHATLIST>::iterator obj = m_ChatData.begin();
std::map<int, CHATLIST>::iterator end = m_ChatData.end();
BOOL bAddItem;
while(obj != end)
{
CHATLIST& st = obj->second;
bAddItem = TRUE;
if(iGroupID != 0 && strcmp(strServerGroup, st.strServerName) != 0)
{
bAddItem = FALSE;
}
if(iZoneID != 0 && st.iZone != iZoneID)
{
bAddItem = FALSE;
}
if(iChatType != 0 && st.iChatType != iChatType)
{
bAddItem = FALSE;
}
if(bFindName)
{
if(strcmp(strName, st.strSenderName) != 0 && strcmp(strName, st.strTargetName) != 0)
bAddItem = FALSE;
}
if(bAddItem)
{
if(st.iChatType-1 == WHISPER)
{
if(strlen(st.strTargetName) == 0)
wsprintf(strData, "%-15s[Z:%02d/C:%d][%02d:%02d] %s", st.strServerName, st.iZone, st.iChannel, st.sysTime.wHour, st.sysTime.wMinute, st.strMessage);
else
wsprintf(strData, "%-15s[Z:%02d/C:%d][%02d:%02d] %s (To: %s)", st.strServerName, st.iZone, st.iChannel, st.sysTime.wHour, st.sysTime.wMinute, st.strMessage, st.strTargetName);
}
else
{
wsprintf(strData, "%-15s[Z:%02d/C:%d][%02d:%02d] %s", st.strServerName, st.iZone, st.iChannel, st.sysTime.wHour, st.sysTime.wMinute, st.strMessage);
}
if(iChatType == 0)
AddLineToChatList(st.iChatType-1, strData);
else
AddLineToChatList(iChatType-1, strData);
}
++obj;
}
UpdateData(false);
}
void CChatParserDlg::OnBnClickedFindnamechk()
{
m_FindName.EnableWindow(m_FindNameChk.GetCheck());
}