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>
374 lines
12 KiB
C++
374 lines
12 KiB
C++
// GetHanBilling.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include <myOLEDB.h>
|
|
#include <Config.h>
|
|
#include <Log.h>
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include <ctime>
|
|
#include <vector>
|
|
#include <oledb.h>
|
|
#include <srv.h>
|
|
|
|
using namespace std;
|
|
|
|
#pragma pack(1)
|
|
|
|
//##### KTE - EDIT 20041207 #####
|
|
struct HanBillingData
|
|
{
|
|
//DBCHAR m_EndDate[20];
|
|
//DBCHAR m_MemberID[20];
|
|
//DBCHAR m_BillNum[11];
|
|
//DBCHAR m_RylUID[11];
|
|
//DBCHAR m_GameMin[11];
|
|
//DBCHAR m_BillingType[2];
|
|
|
|
DBCHAR m_MemberID[20];
|
|
DBCHAR m_RegDate[20];
|
|
DBCHAR m_BillEndDate[20];
|
|
DBCHAR m_KeeperSeq[11];
|
|
DBCHAR m_RylUID[11];
|
|
DBCHAR m_AddedDay[11];
|
|
DBCHAR m_AddedTime[11];
|
|
DBCHAR m_AddedMonth[11];
|
|
DBCHAR m_AutoBill[2];
|
|
};
|
|
|
|
#pragma pack()
|
|
|
|
template<class _Elem, class _Traits>
|
|
inline basic_ostream<_Elem, _Traits>& __cdecl writetime(basic_ostream<_Elem, _Traits>& _Ostr)
|
|
{
|
|
SYSTEMTIME systime;
|
|
GetLocalTime(&systime);
|
|
|
|
_Elem fill = _Ostr.fill();
|
|
|
|
_Ostr << setfill('0')
|
|
<< "["
|
|
<< setw(4) << systime.wYear << "-"
|
|
<< setw(2) << systime.wMonth << "-"
|
|
<< setw(2) << systime.wDay << " "
|
|
<< setw(2) << systime.wHour << ":"
|
|
<< setw(2) << systime.wMinute << ":"
|
|
<< setw(2) << systime.wSecond << "] " << setfill(fill);
|
|
|
|
return (_Ostr);
|
|
}
|
|
|
|
int APIENTRY _tWinMain(HINSTANCE hInstance,
|
|
HINSTANCE hPrevInstance,
|
|
LPTSTR lpCmdLine,
|
|
int nCmdShow)
|
|
{
|
|
CLog log;
|
|
CConfigurator config;
|
|
|
|
OleDB hanDB;
|
|
OleDB billingDB;
|
|
|
|
char szQuery[OleDB::MaxQueryTextLen];
|
|
int nQueryLen = 0;
|
|
|
|
if(!log.RedirectStdOut("GetHanBillingLog"))
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
cout << endl << writetime << "쿼리를 실행합니다." << endl;
|
|
|
|
TCHAR* tszConfigFileName = TEXT("BillingInfo.cfg");
|
|
|
|
if(!config.Load(tszConfigFileName))
|
|
{
|
|
cout << writetime << tszConfigFileName << "DB설정 파일을 읽을 수 없습니다." << endl;
|
|
return -1;
|
|
}
|
|
|
|
const char* szHanServerName = config.Get("HanServerName");
|
|
const char* szHanDBName = config.Get("HanDBName");
|
|
const char* szHanUserName = config.Get("HanUserName");
|
|
const char* szHanPassword = config.Get("HanPassword");
|
|
|
|
if(!hanDB.ConnectSQLServer(szHanServerName, szHanDBName,
|
|
szHanUserName, szHanPassword, OleDB::ConnType_ORACLE))
|
|
{
|
|
cout << writetime << "한게임DB : 접속할 수 없습니다. : " << hanDB.GetErrorString()
|
|
<< " ServerName : " << szHanServerName
|
|
<< " DBName : " << szHanDBName
|
|
<< " UserName : " << szHanUserName
|
|
<< " Password : " << szHanPassword
|
|
<< endl;
|
|
|
|
return -1;
|
|
}
|
|
|
|
const char* szBillingServerName = config.Get("BillingServerName");
|
|
const char* szBillingDBName = config.Get("BillingDBName");
|
|
const char* szBillingUserName = config.Get("BillingUserName");
|
|
const char* szBillingPassword = config.Get("BillingPassword");
|
|
|
|
if(!billingDB.ConnectSQLServer(szBillingServerName, szBillingDBName,
|
|
szBillingUserName, szBillingPassword, OleDB::ConnType_MSSQL))
|
|
{
|
|
cout << writetime << "빌링DB : 접속할 수 없습니다. : " << billingDB.GetErrorString()
|
|
<< " ServerName : " << szBillingServerName
|
|
<< " DBName : " << szBillingDBName
|
|
<< " UserName : " << szBillingUserName
|
|
<< " Password : " << szBillingPassword
|
|
<< endl;
|
|
|
|
return -1;
|
|
}
|
|
|
|
// 테이블 클리어
|
|
if(!billingDB.ExcuteQuery("EXEC agt_PersonBilling_Delete"))
|
|
{
|
|
cout << writetime << "빌링DB : 임시 테이블 삭제에 실패했습니다 : "
|
|
<< billingDB.GetErrorString() << endl;
|
|
|
|
return -1;
|
|
}
|
|
|
|
// 데이터 가져오기
|
|
|
|
int nMinNum = 0;
|
|
|
|
if(!billingDB.ExcuteQueryGetData(
|
|
"SELECT intCount FROM TblImportedNum WHERE strCompType = 'H'", &nMinNum))
|
|
{
|
|
cout << writetime << "빌링DB : 마지막으로 처리된 데이터 건수 번호를 얻어올 수 없습니다 : "
|
|
<< billingDB.GetErrorString() << endl;
|
|
|
|
return -1;
|
|
}
|
|
|
|
//##### KTE - EDIT 20041207 #####
|
|
//nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen,
|
|
// "SELECT TO_CHAR(ENDDATE, 'YYYY-MM-DD HH24:MI:SS '), "
|
|
// "MEMBERID, "
|
|
// "CAST(BILLNUM AS VARCHAR(11)),"
|
|
// "CAST(RYLUID AS VARCHAR(11)),"
|
|
// "CAST(GAMEMIN AS VARCHAR(11)),"
|
|
// "CAST(BILLTYPE AS VARCHAR(2)) "
|
|
// " FROM RYLBILLINGT WHERE BILLNUM > ? AND HanCHK = 'N' ORDER BY BILLNUM ASC");
|
|
|
|
nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen,
|
|
"SELECT MEMBERID,"
|
|
"TO_CHAR(REGDATE, 'YYYY-MM-DD HH24:MI:SS '),"
|
|
"TO_CHAR(BILLENDDATE,'YYYY-MM-DD HH24:MI:SS '),"
|
|
"CAST(KEEPERSEQ AS VARCHAR(11)),"
|
|
"CAST(RYLUID AS VARCHAR(11)),"
|
|
"CAST(ADDEDDAY AS VARCHAR(11)),"
|
|
"CAST(ADDEDTIME AS VARCHAR(11)),"
|
|
"CAST(ADDEDMONTH AS VARCHAR(11)),"
|
|
"CAST(AUTOBILL AS VARCHAR(2)) "
|
|
"FROM RYLCHECKT WHERE KEEPERSEQ > ? AND CHECKFLAG = 'N' ORDER BY KEEPERSEQ ASC");
|
|
|
|
if(nQueryLen < 0)
|
|
{
|
|
cout << writetime << "한게임DB : 빌링 데이터를 얻어오는 쿼리를 만들 수 없습니다." << endl;
|
|
return -1;
|
|
}
|
|
|
|
OleDB::PARAM_INFO BillingInfoParam;
|
|
memset(&BillingInfoParam, 0, sizeof(OleDB::PARAM_INFO));
|
|
|
|
BillingInfoParam.ColNum = 1;
|
|
|
|
BillingInfoParam.ColSize[0] = sizeof(int);
|
|
BillingInfoParam.ColType[0] = DBTYPE_I4;
|
|
|
|
if(!hanDB.ExcuteQueryWithParams(szQuery,
|
|
reinterpret_cast<char*>(&nMinNum), BillingInfoParam, OleDB::Rowset_Get))
|
|
{
|
|
cout << writetime << "한게임DB : 빌링 정보를 얻어올 수 없습니다 : "
|
|
<< hanDB.GetErrorString() << endl;
|
|
|
|
return -1;
|
|
}
|
|
|
|
typedef std::vector<HanBillingData> BillingDataArray;
|
|
|
|
BillingDataArray hanBillingArray;
|
|
hanBillingArray.reserve(5000);
|
|
|
|
const int MAX_DATA = 1000;
|
|
HanBillingData hanBillingData[MAX_DATA];
|
|
memset(hanBillingData, 0, sizeof(HanBillingData) * MAX_DATA);
|
|
|
|
int nReturnRow = 0;
|
|
while(hanDB.GetData((void**)&hanBillingData,
|
|
sizeof(HanBillingData), MAX_DATA, &nReturnRow))
|
|
{
|
|
if(0 == nReturnRow)
|
|
{
|
|
break;
|
|
}
|
|
|
|
hanBillingArray.insert(hanBillingArray.end(),
|
|
hanBillingData, hanBillingData + nReturnRow);
|
|
|
|
memset(hanBillingData, 0, sizeof(HanBillingData) * MAX_DATA);
|
|
}
|
|
|
|
|
|
//##### KTE - EDIT 20041207 #####
|
|
// BillNum, MemberID, RylUID, BillingType, EndTime, GameMin
|
|
//const char* szInsertQuery = "INSERT INTO TblPersonBilling_log "
|
|
// "(intIndex, strClientID, UID, strBillingType, dateEndTime, intServiceTime, strConvertChk, dateInsertTime) "
|
|
// "values (%s, '%s', %s, '%s', '%s', %s, 'N', GetDate())";
|
|
|
|
//const char* szNullEndInsertQuery = "INSERT INTO TblPersonBilling_log "
|
|
// "(intIndex, strClientID, UID, strBillingType, dateEndTime, intServiceTime, strConvertChk, dateInsertTime) "
|
|
// "values (%s, '%s', %s, '%s', NULL, %s, 'N', GetDate())";
|
|
|
|
// BillNum , ClientID , UID , RegDate , AddedDay , AddedTime , AddedMonth , BillEndDate , AutoBill ,CheckFlag,InsertTime
|
|
const char* szInsertQuery = "INSERT INTO dbo.TblRYLCheckT "
|
|
"(BillNum , ClientID , UID , RegDate , AddedDay , AddedTime , AddedMonth , BillEndDate , AutoBill,CheckFlag ,InsertTime) "
|
|
"VALUES (%s, '%s' , %s , '%s' , %s , %s , %s , '%s' , '%s' , 'N' , GETDATE() )" ;
|
|
|
|
const char* szNullEndInsertQuery = "INSERT INTO dbo.TblRYLCheckT "
|
|
"(BillNum , ClientID , UID , RegDate , AddedDay , AddedTime , AddedMonth , AutoBill,CheckFlag ,InsertTime) "
|
|
"VALUES (%s, '%s' , %s , '%s' , %s , %s , %s , '%s' , 'N' , GETDATE() )" ;
|
|
|
|
BillingDataArray::iterator pos = hanBillingArray.begin();
|
|
BillingDataArray::iterator end = hanBillingArray.end();
|
|
|
|
for(; pos != end; ++pos)
|
|
{
|
|
HanBillingData& data = *pos;
|
|
|
|
//if(0 == strlen(data.m_EndDate))
|
|
//{
|
|
// nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen, szNullEndInsertQuery,
|
|
// data.m_BillNum, data.m_MemberID, data.m_RylUID, data.m_BillingType, data.m_GameMin);
|
|
//}
|
|
//else
|
|
//{
|
|
// nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen, szInsertQuery,
|
|
// data.m_BillNum, data.m_MemberID, data.m_RylUID, data.m_BillingType,
|
|
// data.m_EndDate, data.m_GameMin);
|
|
//}
|
|
if( 0 == strlen(data.m_BillEndDate))
|
|
{
|
|
nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen,szNullEndInsertQuery,
|
|
data.m_KeeperSeq, data.m_MemberID, data.m_RylUID, data.m_RegDate,
|
|
data.m_AddedDay, data.m_AddedTime, data.m_AddedMonth, data.m_AutoBill);
|
|
|
|
}
|
|
else
|
|
{
|
|
nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen,szInsertQuery,
|
|
data.m_KeeperSeq, data.m_MemberID, data.m_RylUID, data.m_RegDate,
|
|
data.m_AddedDay, data.m_AddedTime, data.m_AddedMonth, data.m_BillEndDate, data.m_AutoBill);
|
|
}
|
|
|
|
if(nQueryLen < 0)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
if(!billingDB.ExcuteQuery(szQuery))
|
|
{
|
|
cout << writetime << "빌링DB : 한게임에서 가져온 데이터를 기록할 수 없습니다. : " << billingDB.GetErrorString()
|
|
<< " 현재 BillNum : " << data.m_KeeperSeq << endl;
|
|
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
int nMaxNum = 0;
|
|
|
|
//##### KTE - EDIT 20041207 #####
|
|
//if(!billingDB.ExcuteQueryGetData(
|
|
// "SELECT MAX(intIndex) FROM TblPersonBilling_log WHERE strConvertCHK ='N'", &nMaxNum))
|
|
|
|
if(!billingDB.ExcuteQueryGetData(
|
|
"SELECT MAX(BillNum) FROM dbo.TblRYLCheckT WHERE CheckFlag = 'N'", &nMaxNum))
|
|
{
|
|
cout << writetime << "빌링DB : 한게임에서 가져온 데이터 건수 최대 번호를 얻어올 수 없습니다 : "
|
|
<< billingDB.GetErrorString() << endl;
|
|
|
|
return -1;
|
|
}
|
|
|
|
if(0 < nMaxNum)
|
|
{
|
|
//##### KTE - EDIT 20041207 #####
|
|
//nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen,
|
|
// "UPDATE RYLBILLINGT SET HANCHK = 'Y' "
|
|
// "WHERE BILLNUM > ? AND BILLNUM <= ? AND HANCHK = 'N'");
|
|
nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen,
|
|
"UPDATE RYLCHECKT SET CHECKFLAG = 'Y' "
|
|
"WHERE KEEPERSEQ > ? AND KEEPERSEQ <= ? AND CHECKFLAG = 'N'");
|
|
|
|
if(nQueryLen < 0)
|
|
{
|
|
cout << writetime << "한게임DB : 과금 처리 업데이트 실패 - 쿼리 생성 실패" << endl;
|
|
return -1;
|
|
}
|
|
|
|
OleDB::PARAM_INFO BillingUpdateParam;
|
|
memset(&BillingUpdateParam, 0, sizeof(OleDB::PARAM_INFO));
|
|
|
|
BillingUpdateParam.ColNum = 2;
|
|
|
|
BillingUpdateParam.ColSize[0] = sizeof(int);
|
|
BillingUpdateParam.ColType[0] = DBTYPE_I4;
|
|
|
|
BillingUpdateParam.ColSize[1] = sizeof(int);
|
|
BillingUpdateParam.ColType[1] = DBTYPE_I4;
|
|
|
|
char szData[sizeof(int) * 2];
|
|
memcpy(szData, &nMinNum, sizeof(int));
|
|
memcpy(szData + sizeof(int), &nMaxNum, sizeof(int));
|
|
|
|
if(!hanDB.ExcuteQueryWithParams(szQuery, szData, BillingUpdateParam, OleDB::Rowset_Update))
|
|
{
|
|
cout << writetime << "한게임DB : 과금 처리 업데이트 실패 - 쿼리 실패 : "
|
|
<< hanDB.GetErrorString() << endl;
|
|
return -1;
|
|
}
|
|
|
|
nQueryLen = _snprintf(szQuery, OleDB::MaxQueryTextLen,
|
|
"UPDATE TblImportedNum SET intCount = %d WHERE strCompType = 'H'", nMaxNum);
|
|
|
|
if(nQueryLen < 0)
|
|
{
|
|
cout << writetime << "빌링DB : 과금 처리 업데이트 실패 - 쿼리 생성 실패 "
|
|
<< " MinBillingNum : " << nMinNum
|
|
<< " MaxBillingNum : " << nMaxNum << endl;
|
|
return -1;
|
|
}
|
|
|
|
if(!billingDB.ExcuteQuery(szQuery, OleDB::Rowset_Update))
|
|
{
|
|
cout << writetime << "빌링DB : 과금 처리 업데이트 실패 - 쿼리 실패 : "
|
|
<< billingDB.GetErrorString()
|
|
<< " MinBillingNum : " << nMinNum
|
|
<< " MaxBillingNum : " << nMaxNum << endl;
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
// 데이터 처리
|
|
if(!billingDB.ExcuteQuery("EXEC agt_PersonBilling_CHK"))
|
|
{
|
|
cout << writetime << "빌링DB : 가져온 데이터를 처리하는 데 실패했습니다. : "
|
|
<< billingDB.GetErrorString()
|
|
<< " MinBillingNum : " << nMinNum
|
|
<< " MaxBillingNum : " << nMaxNum << endl;
|
|
|
|
return -1;
|
|
}
|
|
|
|
cout << writetime << "쿼리 실행 완료." << endl;
|
|
return 0;
|
|
}
|
|
|
|
|