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>
803 lines
23 KiB
C++
803 lines
23 KiB
C++
// BillingTestModuleDlg.cpp : 구현 파일
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "BillingTestModule.h"
|
|
#include "BillingTestModuleDlg.h"
|
|
#include ".\billingtestmoduledlg.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
#include <vector>
|
|
#include <algorithm>
|
|
|
|
// 응용 프로그램 정보에 사용되는 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()
|
|
|
|
|
|
// CBillingTestModuleDlg 대화 상자
|
|
const int ID_PROCESS_PACKET_TIMER = 1000;
|
|
|
|
|
|
CBillingTestModuleDlg::CBillingTestModuleDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CBillingTestModuleDlg::IDD, pParent)
|
|
, m_LoginAckDelay(0)
|
|
, m_BillAuthAckDelay(0)
|
|
, m_nSocketNum(0)
|
|
{
|
|
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
|
}
|
|
|
|
void CBillingTestModuleDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_CURRENT_USER_LIST, m_ctrlCurrentUserList);
|
|
DDX_Control(pDX, IDC_LOGIN_IP_LIST, m_ctrlLoginIPList);
|
|
DDX_Control(pDX, IDC_IP_START, m_StartIP);
|
|
DDX_Control(pDX, IDC_IP_END, m_EndIP);
|
|
|
|
DDX_Control(pDX, IDC_LOGIN_ACK_TYPE, m_LoginAckType);
|
|
DDX_Control(pDX, IDC_BILL_AUTH_ACK_TYPE, m_BillAuthAckType);
|
|
|
|
DDX_Text(pDX, IDC_LOGIN_ACK_DELAY, m_LoginAckDelay);
|
|
DDX_Text(pDX, IDC_BILL_AUTH_ACK_DELAY, m_BillAuthAckDelay);
|
|
DDX_Control(pDX, IDC_LOG_LIST, m_BillingLog);
|
|
DDX_Control(pDX, IDC_LOGIN_ACK_DELAY, m_LoginAckDelayDlg);
|
|
DDX_Control(pDX, IDC_BILL_AUTH_ACK_DELAY, m_BillAuthAckDelayDlg);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CBillingTestModuleDlg, CDialog)
|
|
ON_WM_SYSCOMMAND()
|
|
ON_WM_PAINT()
|
|
ON_WM_QUERYDRAGICON()
|
|
//}}AFX_MSG_MAP
|
|
ON_WM_CONTEXTMENU()
|
|
ON_COMMAND(ID_DISCONNECT_USER, OnDisconnectUser)
|
|
ON_COMMAND(ID_SEND_MSG_USER, OnSendMsgUser)
|
|
ON_COMMAND(ID_IP_DELETE, OnIpDelete)
|
|
ON_BN_CLICKED(IDC_IP_ADD, OnBnClickedIPAdd)
|
|
ON_BN_CLICKED(IDC_SAVELOG, OnBnClickedSaveLog)
|
|
ON_BN_CLICKED(IDC_CLEARLOG, OnBnClickedClearLog)
|
|
ON_WM_TIMER()
|
|
ON_WM_DESTROY()
|
|
ON_CBN_SELCHANGE(IDC_LOGIN_ACK_TYPE, OnCbnSelchangeLoginAckType)
|
|
ON_CBN_SELCHANGE(IDC_BILL_AUTH_ACK_TYPE, OnCbnSelchangeBillAuthAckType)
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
// CBillingTestModuleDlg 메시지 처리기
|
|
|
|
BOOL CBillingTestModuleDlg::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: 여기에 추가 초기화 작업을 추가합니다.
|
|
|
|
m_ctrlCurrentUserList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_FLATSB);
|
|
m_ctrlCurrentUserList.InsertColumn( 0, "ID", LVCFMT_LEFT, 200);
|
|
m_ctrlCurrentUserList.InsertColumn( 1, "접속중인 IP", LVCFMT_LEFT, 200);
|
|
|
|
m_ctrlLoginIPList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_FLATSB);
|
|
m_ctrlLoginIPList.InsertColumn( 0, "IP 대역 시작", LVCFMT_LEFT, 200);
|
|
m_ctrlLoginIPList.InsertColumn( 1, "IP 대역 끝", LVCFMT_LEFT, 200);
|
|
|
|
m_BillingLog.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_FLATSB);
|
|
m_BillingLog.InsertColumn(0, "로그", LVCFMT_LEFT, 500);
|
|
|
|
LoadAddress();
|
|
|
|
m_LoginAckType.InsertString(NORMAL_PROCESS, "기본 처리");
|
|
m_LoginAckType.InsertString(SUCCESS_ALL_PROCESS, "모두 성공");
|
|
m_LoginAckType.InsertString(FAIL_ALL_PROCESS, "모두 실패");
|
|
m_LoginAckType.InsertString(DELAY_ALL_PROCESS, "지연 처리");
|
|
m_LoginAckType.InsertString(DROP_ALL_PROCESS, "요청 버림");
|
|
|
|
m_LoginAckType.SetCurSel(NORMAL_PROCESS);
|
|
m_LoginAckDelayDlg.SetReadOnly();
|
|
|
|
m_BillAuthAckType.InsertString(NORMAL_PROCESS, "기본 처리");
|
|
m_BillAuthAckType.InsertString(SUCCESS_ALL_PROCESS, "모두 성공");
|
|
m_BillAuthAckType.InsertString(FAIL_ALL_PROCESS, "모두 실패");
|
|
m_BillAuthAckType.InsertString(DELAY_ALL_PROCESS, "지연 처리");
|
|
m_BillAuthAckType.InsertString(DROP_ALL_PROCESS, "요청 버림");
|
|
|
|
m_BillAuthAckType.SetCurSel(NORMAL_PROCESS);
|
|
m_BillAuthAckDelayDlg.SetReadOnly();
|
|
|
|
m_LoginAckDelay = 0;
|
|
m_BillAuthAckDelay = 0;
|
|
|
|
CString windowName;
|
|
windowName.Format("BillingTestModule : Port(%u)", CBillingTestModuleApp::LISTEN_PORT);
|
|
SetWindowText(windowName);
|
|
|
|
UpdateData(false);
|
|
|
|
theApp.SetMainDlg(*this);
|
|
|
|
SetTimer(ID_PROCESS_PACKET_TIMER, 200, 0);
|
|
return TRUE; // 컨트롤에 대한 포커스를 설정하지 않을 경우 TRUE를 반환합니다.
|
|
}
|
|
|
|
void CBillingTestModuleDlg::OnSysCommand(UINT nID, LPARAM lParam)
|
|
{
|
|
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
|
|
{
|
|
CAboutDlg dlgAbout;
|
|
dlgAbout.DoModal();
|
|
}
|
|
else
|
|
{
|
|
CDialog::OnSysCommand(nID, lParam);
|
|
}
|
|
}
|
|
|
|
// 대화 상자에 최소화 단추를 추가할 경우 아이콘을 그리려면
|
|
// 아래 코드가 필요합니다. 문서/뷰 모델을 사용하는 MFC 응용 프로그램의 경우에는
|
|
// 프레임워크에서 이 작업을 자동으로 수행합니다.
|
|
|
|
void CBillingTestModuleDlg::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 CBillingTestModuleDlg::OnQueryDragIcon()
|
|
{
|
|
return static_cast<HCURSOR>(m_hIcon);
|
|
}
|
|
|
|
void CBillingTestModuleDlg::OnContextMenu(CWnd* pWnd, CPoint point)
|
|
{
|
|
if( (pWnd->GetSafeHwnd() == m_ctrlCurrentUserList.GetSafeHwnd())
|
|
&& (0 < m_ctrlCurrentUserList.GetSelectedCount()) )
|
|
{
|
|
CMenu muTemp, *pContextMenu;
|
|
muTemp.LoadMenu(IDR_CONTEXT_MENU);
|
|
pContextMenu = muTemp.GetSubMenu(0);
|
|
pContextMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);
|
|
}
|
|
else if( (pWnd->GetSafeHwnd() == m_ctrlLoginIPList.GetSafeHwnd())
|
|
&& (0 < m_ctrlLoginIPList.GetSelectedCount()) )
|
|
{
|
|
CMenu muTemp, *pContextMenu;
|
|
muTemp.LoadMenu(IDR_CONTEXT_MENU);
|
|
pContextMenu = muTemp.GetSubMenu(1);
|
|
pContextMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);
|
|
}
|
|
}
|
|
|
|
void CBillingTestModuleDlg::OnOK()
|
|
{
|
|
//CDialog::OnOK();
|
|
}
|
|
|
|
BOOL CBillingTestModuleDlg::PreTranslateMessage(MSG* pMsg)
|
|
{
|
|
if( ( WM_KEYDOWN == pMsg->message ) && ( VK_RETURN == pMsg->wParam ) )
|
|
{
|
|
if( (GetFocus() == GetDlgItem(IDC_IP_END)->GetFocus()) )
|
|
{
|
|
// 여기서 IP 추가
|
|
}
|
|
}
|
|
|
|
return CDialog::PreTranslateMessage(pMsg);
|
|
}
|
|
|
|
void CBillingTestModuleDlg::OnDisconnectUser()
|
|
{
|
|
// 강제로 접속끊기
|
|
POSITION pos = m_ctrlCurrentUserList.GetFirstSelectedItemPosition();
|
|
|
|
int nPos = m_ctrlCurrentUserList.GetNextSelectedItem(pos);
|
|
|
|
int nLength = 0;
|
|
|
|
while(-1 != nPos)
|
|
{
|
|
HanUnitedBilling::GLTransStruct glTransStruct;
|
|
memset(&glTransStruct, 0, sizeof(HanUnitedBilling::GLTransStruct));
|
|
|
|
nLength = m_ctrlCurrentUserList.GetItemText(nPos, 1, glTransStruct.Data, HanUnitedBilling::MAX_IP_LEN);
|
|
glTransStruct.Data[nLength] = 0;
|
|
|
|
nLength = m_ctrlCurrentUserList.GetItemText(nPos, 0,
|
|
glTransStruct.Data + HanUnitedBilling::MAX_IP_LEN, HanUnitedBilling::MAX_ID_LEN);
|
|
|
|
glTransStruct.Data[nLength + HanUnitedBilling::MAX_IP_LEN] = 0;
|
|
|
|
glTransStruct.HeaderMsg = htons(HanUnitedBilling::CUT_IP);
|
|
|
|
glTransStruct.DataSize = htons(
|
|
HanUnitedBilling::MAX_ID_LEN +
|
|
HanUnitedBilling::MAX_IP_LEN);
|
|
|
|
glTransStruct.SeqID = 0;
|
|
|
|
theApp.SendPendingAll(glTransStruct);
|
|
|
|
nPos = m_ctrlLoginIPList.GetNextSelectedItem(pos);
|
|
}
|
|
}
|
|
|
|
void CBillingTestModuleDlg::OnSendMsgUser()
|
|
{
|
|
// 유저에게 메세지 보내기
|
|
// 강제로 접속끊기
|
|
POSITION pos = m_ctrlCurrentUserList.GetFirstSelectedItemPosition();
|
|
|
|
int nPos = m_ctrlCurrentUserList.GetNextSelectedItem(pos);
|
|
|
|
int nLength = 0;
|
|
|
|
while(-1 != nPos)
|
|
{
|
|
HanUnitedBilling::GLTransStruct glTransStruct;
|
|
memset(&glTransStruct, 0, sizeof(HanUnitedBilling::GLTransStruct));
|
|
|
|
nLength = m_ctrlCurrentUserList.GetItemText(nPos, 1, glTransStruct.Data, HanUnitedBilling::MAX_IP_LEN);
|
|
glTransStruct.Data[nLength] = 0;
|
|
|
|
nLength = m_ctrlCurrentUserList.GetItemText(nPos, 0,
|
|
glTransStruct.Data + HanUnitedBilling::MAX_IP_LEN, HanUnitedBilling::MAX_ID_LEN);
|
|
glTransStruct.Data[nLength + HanUnitedBilling::MAX_IP_LEN] = 0;
|
|
|
|
nLength = _sntprintf(glTransStruct.Data + HanUnitedBilling::MAX_IP_LEN + HanUnitedBilling::MAX_ID_LEN,
|
|
HanUnitedBilling::MAX_MSG_LEN - 1, "이 가난뱅이 녀석, 돈을 제때 넣으란 말이다. 우하하하");
|
|
glTransStruct.Data[nLength + HanUnitedBilling::MAX_IP_LEN + HanUnitedBilling::MAX_ID_LEN] = 0;
|
|
|
|
glTransStruct.HeaderMsg = htons(HanUnitedBilling::WARNNOTICE);
|
|
|
|
glTransStruct.DataSize = htons(
|
|
HanUnitedBilling::MAX_ID_LEN +
|
|
HanUnitedBilling::MAX_IP_LEN +
|
|
HanUnitedBilling::MAX_MSG_LEN);
|
|
|
|
glTransStruct.SeqID = 0;
|
|
|
|
theApp.SendPendingAll(glTransStruct);
|
|
|
|
nPos = m_ctrlLoginIPList.GetNextSelectedItem(pos);
|
|
}
|
|
}
|
|
|
|
void CBillingTestModuleDlg::OnIpDelete()
|
|
{
|
|
// IP 대역 삭제
|
|
|
|
POSITION pos = m_ctrlLoginIPList.GetFirstSelectedItemPosition();
|
|
|
|
std::vector<int> deletePos;
|
|
|
|
int nPos = m_ctrlLoginIPList.GetNextSelectedItem(pos);
|
|
while(-1 != nPos)
|
|
{
|
|
deletePos.push_back(nPos);
|
|
nPos = m_ctrlLoginIPList.GetNextSelectedItem(pos);
|
|
}
|
|
|
|
std::sort(deletePos.begin(), deletePos.end(), std::greater<int>());
|
|
|
|
std::vector<int>::iterator pos_delete = deletePos.begin();
|
|
std::vector<int>::iterator end_delete = deletePos.end();
|
|
|
|
for(; pos_delete != end_delete; ++pos_delete)
|
|
{
|
|
m_ctrlLoginIPList.DeleteItem(*pos_delete);
|
|
}
|
|
|
|
SaveAddress();
|
|
}
|
|
|
|
|
|
void CBillingTestModuleDlg::OnBnClickedIPAdd()
|
|
{
|
|
// IP 대역 추가
|
|
if(!m_StartIP.IsBlank() && !m_EndIP.IsBlank())
|
|
{
|
|
DWORD dwStartAddress = 0;
|
|
DWORD dwEndAddress = 0;
|
|
|
|
m_StartIP.GetAddress(dwStartAddress);
|
|
m_EndIP.GetAddress(dwEndAddress);
|
|
|
|
std::pair<in_addr, in_addr> addressPair;
|
|
|
|
addressPair.first.S_un.S_addr = htonl(dwStartAddress);
|
|
addressPair.second.S_un.S_addr = htonl(dwEndAddress);
|
|
|
|
AddAddress(addressPair.first, addressPair.second);
|
|
SaveAddress();
|
|
}
|
|
}
|
|
|
|
void CBillingTestModuleDlg::AddAddress(in_addr addressStart, in_addr addressEnd)
|
|
{
|
|
int nMaxCount = m_ctrlLoginIPList.GetItemCount();
|
|
m_ctrlLoginIPList.InsertItem(nMaxCount, 0);
|
|
|
|
m_ctrlLoginIPList.SetItemText(nMaxCount, 0, inet_ntoa(addressStart));
|
|
m_ctrlLoginIPList.SetItemText(nMaxCount, 1, inet_ntoa(addressEnd));
|
|
}
|
|
|
|
|
|
const TCHAR* g_szBillingAddress = "BillingAddress.txt";
|
|
|
|
void CBillingTestModuleDlg::SaveAddress()
|
|
{
|
|
FILE* file = fopen(g_szBillingAddress, "wt");
|
|
|
|
if(0 != file)
|
|
{
|
|
int nMaxCount = m_ctrlLoginIPList.GetItemCount();
|
|
for(int nCount = 0; nCount < nMaxCount; ++nCount)
|
|
{
|
|
fprintf(file, "%s\t%s\n",
|
|
m_ctrlLoginIPList.GetItemText(nCount, 0),
|
|
m_ctrlLoginIPList.GetItemText(nCount, 1));
|
|
}
|
|
|
|
fclose(file);
|
|
}
|
|
}
|
|
|
|
void CBillingTestModuleDlg::LoadAddress()
|
|
{
|
|
FILE* file = fopen(g_szBillingAddress, "rt");
|
|
|
|
if(0 != file)
|
|
{
|
|
const int MAX_BUFFER = 4096;
|
|
char szBuffer[MAX_BUFFER];
|
|
|
|
char szIPStart[MAX_BUFFER];
|
|
char szIPEnd[MAX_BUFFER];
|
|
|
|
in_addr addrStart;
|
|
in_addr addrEnd;
|
|
|
|
while(fgets(szBuffer, MAX_BUFFER - 1, file))
|
|
{
|
|
szBuffer[MAX_BUFFER - 1] = 0;
|
|
|
|
if(EOF != sscanf(szBuffer, "%s\t%s\n", szIPStart, szIPEnd))
|
|
{
|
|
addrStart.S_un.S_addr = inet_addr(szIPStart);
|
|
addrEnd.S_un.S_addr = inet_addr(szIPEnd);
|
|
|
|
AddAddress(addrStart, addrEnd);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void CBillingTestModuleDlg::OnBnClickedSaveLog()
|
|
{
|
|
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
|
|
|
|
const int MAX_LOG_LINE = 4096;
|
|
TCHAR szLogText[MAX_LOG_LINE];
|
|
|
|
const char* szLogFileName = "HanUnitedBillingLog.log";
|
|
|
|
FILE* file = fopen(szLogFileName, "at");
|
|
if(0 != file)
|
|
{
|
|
int nMAXCount = m_BillingLog.GetItemCount();
|
|
for(int nCount = 0; nCount < nMAXCount; ++nCount)
|
|
{
|
|
int nLength = m_BillingLog.GetItemText(nCount, 0, szLogText, MAX_LOG_LINE - 1);
|
|
|
|
if(0 < nLength && nLength < MAX_LOG_LINE)
|
|
{
|
|
szLogText[nLength] = 0;
|
|
fprintf(file, "%s\n", szLogText);
|
|
}
|
|
}
|
|
|
|
fclose(file);
|
|
}
|
|
|
|
m_BillingLog.DeleteAllItems();
|
|
AfxMessageBox("로그를 저장하는 데 성공했습니다.");
|
|
}
|
|
|
|
void CBillingTestModuleDlg::OnBnClickedClearLog()
|
|
{
|
|
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
|
|
m_BillingLog.DeleteAllItems();
|
|
}
|
|
|
|
void CBillingTestModuleDlg::AddLog(DlgLogType eDlgLogType, const TCHAR* szFormat, ...)
|
|
{
|
|
const int MAX_LOG_LINE = 4096;
|
|
TCHAR szLogText[MAX_LOG_LINE];
|
|
|
|
SYSTEMTIME sysTime;
|
|
GetLocalTime(&sysTime);
|
|
|
|
const TCHAR* szLogType = _T("UNK");
|
|
|
|
switch(eDlgLogType)
|
|
{
|
|
case NORMAL_LOG: szLogType = _T("NOR"); break;
|
|
case ERROR_LOG: szLogType = _T("ERR"); break;
|
|
}
|
|
|
|
int nTotalLength = _sntprintf(szLogText, MAX_LOG_LINE - 1, _T("[%s][%04d-%02d-%02d %02d:%02d:%02d] "),
|
|
szLogType, sysTime.wYear, sysTime.wMonth, sysTime.wDay, sysTime.wHour, sysTime.wMinute, sysTime.wSecond);
|
|
|
|
va_list arglist;
|
|
va_start(arglist, szFormat);
|
|
|
|
int nLength = _vsntprintf(szLogText + nTotalLength,
|
|
MAX_LOG_LINE - nTotalLength - 1, szFormat, arglist);
|
|
|
|
va_end(arglist);
|
|
|
|
if(0 < nLength && nTotalLength + nLength < MAX_LOG_LINE)
|
|
{
|
|
nTotalLength += nLength;
|
|
szLogText[nTotalLength] = 0;
|
|
|
|
m_BillingLog.InsertItem(m_BillingLog.GetItemCount(), szLogText);
|
|
}
|
|
}
|
|
|
|
|
|
bool CBillingTestModuleDlg::Login(CBillingAsyncSocket& billingAsyncSocket,
|
|
unsigned long dwSeqID, const char* szID, const char* szIP)
|
|
{
|
|
HanUnitedBilling::GLTransStruct glTransStruct;
|
|
memset(&glTransStruct, 0, sizeof(HanUnitedBilling::GLTransStruct));
|
|
|
|
unsigned short usSuccess = 0;
|
|
|
|
switch(GetLoginAckType())
|
|
{
|
|
case SUCCESS_ALL_PROCESS:
|
|
usSuccess = 1;
|
|
AddLog(NORMAL_LOG, "ID:%s/IP:%s/SeqID:%u/유저 로그인 처리 무조건 성공", szID, szIP, dwSeqID);
|
|
break;
|
|
|
|
case FAIL_ALL_PROCESS:
|
|
usSuccess = 0;
|
|
AddLog(NORMAL_LOG, "ID:%s/IP:%s/SeqID:%u/유저 로그인 처리 무조건 실패", szID, szIP, dwSeqID);
|
|
break;
|
|
|
|
default:
|
|
|
|
if(-1 != FindCurrentUserPos(szID, szIP))
|
|
{
|
|
usSuccess = 0;
|
|
AddLog(ERROR_LOG, "ID:%s/IP:%s/SeqID:%u/유저 로그인 처리 실패(중복 로그인)", szID, szIP, dwSeqID);
|
|
}
|
|
else if(!CheckIPList(szIP))
|
|
{
|
|
usSuccess = 0;
|
|
AddLog(ERROR_LOG, "ID:%s/IP:%s/SeqID:%u/유저 로그인 처리 실패(IP리스트에 없음)", szID, szIP, dwSeqID);
|
|
}
|
|
else
|
|
{
|
|
usSuccess = 1;
|
|
AddLog(NORMAL_LOG, "ID:%s/IP:%s/SeqID:%u/유저 로그인 처리 성공", szID, szIP, dwSeqID);
|
|
|
|
int nCount = m_ctrlCurrentUserList.GetItemCount();
|
|
|
|
m_ctrlCurrentUserList.InsertItem(nCount, "");
|
|
m_ctrlCurrentUserList.SetItemText(nCount, 0, szID);
|
|
m_ctrlCurrentUserList.SetItemText(nCount, 1, szIP);
|
|
}
|
|
break;
|
|
}
|
|
|
|
glTransStruct.HeaderMsg = htons(HanUnitedBilling::AUTH_RESULT);
|
|
|
|
glTransStruct.DataSize = htons(
|
|
HanUnitedBilling::MAX_ID_LEN +
|
|
HanUnitedBilling::MAX_IP_LEN +
|
|
sizeof(unsigned short));
|
|
|
|
glTransStruct.SeqID = htonl(dwSeqID);
|
|
|
|
_snprintf(glTransStruct.Data, HanUnitedBilling::MAX_IP_LEN, "%s", szIP);
|
|
_snprintf(glTransStruct.Data + HanUnitedBilling::MAX_IP_LEN, HanUnitedBilling::MAX_ID_LEN, "%s", szID);
|
|
|
|
usSuccess = htons(usSuccess);
|
|
memcpy(glTransStruct.Data + HanUnitedBilling::MAX_IP_LEN + HanUnitedBilling::MAX_ID_LEN,
|
|
&usSuccess, sizeof(unsigned short));
|
|
|
|
billingAsyncSocket.SendPending(glTransStruct);
|
|
return true;
|
|
}
|
|
|
|
|
|
bool CBillingTestModuleDlg::Logout(CBillingAsyncSocket& billingAsyncSocket,
|
|
unsigned long dwSeqID, const char* szID, const char* szIP)
|
|
{
|
|
int nPos = FindCurrentUserPos(szID, szIP);
|
|
if(-1 != nPos)
|
|
{
|
|
m_ctrlCurrentUserList.DeleteItem(nPos);
|
|
|
|
AddLog(NORMAL_LOG, "ID:%s/IP:%s/유저 로그아웃 처리 성공", szID, szIP);
|
|
return true;
|
|
}
|
|
|
|
AddLog(ERROR_LOG, "ID:%s/IP:%s/유저 로그아웃 처리 실패. 유저가 없습니다.", szID, szIP);
|
|
return false;
|
|
}
|
|
|
|
|
|
bool CBillingTestModuleDlg::BillAuth(CBillingAsyncSocket& billingAsyncSocket,
|
|
unsigned long dwSeqID, const char* szID, const char* szIP)
|
|
{
|
|
HanUnitedBilling::GLTransStruct glTransStruct;
|
|
memset(&glTransStruct, 0, sizeof(HanUnitedBilling::GLTransStruct));
|
|
|
|
unsigned short usSuccess = 0;
|
|
|
|
switch(GetLoginAckType())
|
|
{
|
|
case SUCCESS_ALL_PROCESS:
|
|
usSuccess = 1;
|
|
AddLog(NORMAL_LOG, "ID:%s/IP:%s/SeqID:%u/유저 과금 가능 여부 무조건 성공", szID, szIP, dwSeqID);
|
|
break;
|
|
|
|
case FAIL_ALL_PROCESS:
|
|
usSuccess = 0;
|
|
AddLog(NORMAL_LOG, "ID:%s/IP:%s/SeqID:%u/유저 과금 가능 여부 무조건 실패", szID, szIP, dwSeqID);
|
|
break;
|
|
|
|
default:
|
|
|
|
if(-1 != FindCurrentUserPos(szID, szIP))
|
|
{
|
|
usSuccess = 0;
|
|
AddLog(ERROR_LOG, "ID:%s/IP:%s/SeqID:%u/유저 과금 불가능 (중복 로그인)", szID, szIP, dwSeqID);
|
|
}
|
|
else if(!CheckIPList(szIP))
|
|
{
|
|
usSuccess = 0;
|
|
AddLog(ERROR_LOG, "ID:%s/IP:%s/SeqID:%u/유저 과금 불가능 (과금 내역 없음)", szID, szIP, dwSeqID);
|
|
}
|
|
else
|
|
{
|
|
usSuccess = 1;
|
|
AddLog(NORMAL_LOG, "ID:%s/IP:%s/SeqID:%u/유저 과금 가능", szID, szIP, dwSeqID);
|
|
}
|
|
break;
|
|
}
|
|
|
|
glTransStruct.HeaderMsg = htons(HanUnitedBilling::BILL_AUTH_RESULT);
|
|
|
|
glTransStruct.DataSize = htons(
|
|
HanUnitedBilling::MAX_ID_LEN +
|
|
HanUnitedBilling::MAX_IP_LEN +
|
|
sizeof(unsigned short));
|
|
|
|
glTransStruct.SeqID = htonl(dwSeqID);
|
|
|
|
_snprintf(glTransStruct.Data, HanUnitedBilling::MAX_IP_LEN, "%s", szIP);
|
|
_snprintf(glTransStruct.Data + HanUnitedBilling::MAX_IP_LEN, HanUnitedBilling::MAX_ID_LEN, "%s", szID);
|
|
|
|
usSuccess = htons(usSuccess);
|
|
memcpy(glTransStruct.Data + HanUnitedBilling::MAX_IP_LEN + HanUnitedBilling::MAX_ID_LEN,
|
|
&usSuccess, sizeof(unsigned short));
|
|
|
|
billingAsyncSocket.SendPending(glTransStruct);
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
int CBillingTestModuleDlg::FindCurrentUserPos(const char* szID, const char* szIP)
|
|
{
|
|
int nMaxCount = m_ctrlCurrentUserList.GetItemCount();
|
|
|
|
TCHAR szUserID[HanUnitedBilling::MAX_ID_LEN + 1];
|
|
TCHAR szUserIP[HanUnitedBilling::MAX_IP_LEN + 1];
|
|
|
|
int nLength = 0;
|
|
|
|
for(int nCount = 0; nCount < nMaxCount; ++nCount)
|
|
{
|
|
nLength = m_ctrlCurrentUserList.GetItemText(nCount, 0,
|
|
szUserID, HanUnitedBilling::MAX_ID_LEN);
|
|
|
|
szUserID[nLength] = 0;
|
|
|
|
nLength = m_ctrlCurrentUserList.GetItemText(nCount, 1,
|
|
szUserIP, HanUnitedBilling::MAX_IP_LEN);
|
|
|
|
szUserIP[nLength] = 0;
|
|
|
|
if(0 == _tcsncmp(szID, szUserID, HanUnitedBilling::MAX_ID_LEN)
|
|
&& 0 == _tcsncmp(szIP, szUserIP, HanUnitedBilling::MAX_IP_LEN))
|
|
{
|
|
return nCount;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
bool CBillingTestModuleDlg::CheckIPList(const char* szIP)
|
|
{
|
|
in_addr address;
|
|
address.S_un.S_addr = inet_addr(szIP);
|
|
|
|
char szIPStart[HanUnitedBilling::MAX_IP_LEN + 1];
|
|
char szIPEnd[HanUnitedBilling::MAX_IP_LEN + 1];
|
|
|
|
in_addr addr_start;
|
|
in_addr addr_end;
|
|
|
|
int nLength = 0;
|
|
|
|
int nMaxCount = m_ctrlLoginIPList.GetItemCount();
|
|
for(int nCount = 0; nCount < nMaxCount; ++nCount)
|
|
{
|
|
nLength = m_ctrlLoginIPList.GetItemText(nCount, 0, szIPStart, HanUnitedBilling::MAX_IP_LEN);
|
|
szIPStart[nLength] = 0;
|
|
|
|
nLength = m_ctrlLoginIPList.GetItemText(nCount, 1, szIPEnd, HanUnitedBilling::MAX_IP_LEN);
|
|
szIPEnd[nLength] = 0;
|
|
|
|
addr_start.S_un.S_addr = inet_addr(szIPStart);
|
|
addr_end.S_un.S_addr = inet_addr(szIPEnd);
|
|
|
|
if(addr_start.S_un.S_un_b.s_b1 <= address.S_un.S_un_b.s_b1 &&
|
|
address.S_un.S_un_b.s_b1 <= addr_end.S_un.S_un_b.s_b1 &&
|
|
|
|
addr_start.S_un.S_un_b.s_b2 <= address.S_un.S_un_b.s_b2 &&
|
|
address.S_un.S_un_b.s_b2 <= addr_end.S_un.S_un_b.s_b2 &&
|
|
|
|
addr_start.S_un.S_un_b.s_b3 <= address.S_un.S_un_b.s_b3 &&
|
|
address.S_un.S_un_b.s_b3 <= addr_end.S_un.S_un_b.s_b3 &&
|
|
|
|
addr_start.S_un.S_un_b.s_b3 <= address.S_un.S_un_b.s_b3 &&
|
|
address.S_un.S_un_b.s_b3 <= addr_end.S_un.S_un_b.s_b3)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
void CBillingTestModuleDlg::OnTimer(UINT nIDEvent)
|
|
{
|
|
// TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다.
|
|
|
|
if(nIDEvent == ID_PROCESS_PACKET_TIMER)
|
|
{
|
|
theApp.ProcessPacket();
|
|
|
|
size_t nSocketNum = theApp.GetConnectedSocketNum();
|
|
|
|
if(m_nSocketNum != nSocketNum)
|
|
{
|
|
CString windowName;
|
|
windowName.Format("BillingTestModule : Port(%u) - %d Connection now.",
|
|
CBillingTestModuleApp::LISTEN_PORT, nSocketNum);
|
|
SetWindowText(windowName);
|
|
|
|
m_nSocketNum = nSocketNum;
|
|
}
|
|
}
|
|
|
|
CDialog::OnTimer(nIDEvent);
|
|
}
|
|
|
|
void CBillingTestModuleDlg::OnDestroy()
|
|
{
|
|
CDialog::OnDestroy();
|
|
|
|
// TODO: 여기에 메시지 처리기 코드를 추가합니다.
|
|
KillTimer(ID_PROCESS_PACKET_TIMER);
|
|
theApp.ResetMainDlg(*this);
|
|
}
|
|
|
|
void CBillingTestModuleDlg::OnCbnSelchangeLoginAckType()
|
|
{
|
|
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
|
|
|
|
if(DELAY_ALL_PROCESS != GetLoginAckType())
|
|
{
|
|
m_LoginAckDelayDlg.SetReadOnly();
|
|
}
|
|
else
|
|
{
|
|
m_LoginAckDelayDlg.SetReadOnly(false);
|
|
}
|
|
}
|
|
|
|
void CBillingTestModuleDlg::OnCbnSelchangeBillAuthAckType()
|
|
{
|
|
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
|
|
|
|
if(DELAY_ALL_PROCESS != GetBillAuthAckType())
|
|
{
|
|
m_BillAuthAckDelayDlg.SetReadOnly();
|
|
}
|
|
else
|
|
{
|
|
m_BillAuthAckDelayDlg.SetReadOnly(false);
|
|
}
|
|
}
|