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>
This commit is contained in:
295
Server/Billing/GetHanBillingLogData/GetHanBillingLogData.cpp
Normal file
295
Server/Billing/GetHanBillingLogData/GetHanBillingLogData.cpp
Normal file
@@ -0,0 +1,295 @@
|
||||
// GetHanBillingLogData.cpp : <20><><EFBFBD><EFBFBD> <20><><EFBFBD>α<CEB1><D7B7><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <myOLEDB.h>
|
||||
#include <Config.h>
|
||||
#include <Log.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <ctime>
|
||||
#include <list>
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
struct BillingLogData
|
||||
{
|
||||
char strClientID[20];
|
||||
int UID;
|
||||
int intCRMIndex;
|
||||
char strIP[15];
|
||||
char strBillingType[2];
|
||||
int tinyServerID;
|
||||
char firstLoginTime[20];
|
||||
char loginTime[20];
|
||||
char logoutTime[20];
|
||||
int intPlayTime;
|
||||
|
||||
};
|
||||
|
||||
#pragma pack()
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
bool LoadLastProcessedTime(const char* szFileName, __time64_t* lpLastProcessedTime)
|
||||
{
|
||||
FILE* file = fopen(szFileName, "rb");
|
||||
if(0 != file)
|
||||
{
|
||||
if(0 != lpLastProcessedTime)
|
||||
{
|
||||
tm tmLastProcessedTime;
|
||||
memset(&tmLastProcessedTime, 0, sizeof(tm));
|
||||
|
||||
fscanf(file, "%04d-%02d-%02d %02d:%02d:%02d",
|
||||
&tmLastProcessedTime.tm_year, &tmLastProcessedTime.tm_mon, &tmLastProcessedTime.tm_mday,
|
||||
&tmLastProcessedTime.tm_hour, &tmLastProcessedTime.tm_min, &tmLastProcessedTime.tm_sec);
|
||||
|
||||
tmLastProcessedTime.tm_year -= 1900;
|
||||
tmLastProcessedTime.tm_mon -= 1;
|
||||
|
||||
*lpLastProcessedTime = _mktime64(&tmLastProcessedTime);
|
||||
fclose(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SaveLastProcessedTime(const char* szFileName, __time64_t LastProcessedTime)
|
||||
{
|
||||
FILE* file = fopen(szFileName, "wt");
|
||||
if(0 != file)
|
||||
{
|
||||
tm tmLastProcessedTime = *_localtime64(&LastProcessedTime);
|
||||
|
||||
fprintf(file, "%04d-%02d-%02d %02d:%02d:%02d",
|
||||
tmLastProcessedTime.tm_year + 1900, tmLastProcessedTime.tm_mon + 1, tmLastProcessedTime.tm_mday,
|
||||
tmLastProcessedTime.tm_hour, tmLastProcessedTime.tm_min, tmLastProcessedTime.tm_sec);
|
||||
|
||||
fclose(file);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int APIENTRY _tWinMain(HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPTSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
CLog log;
|
||||
CConfigurator config;
|
||||
|
||||
OleDB hanDB;
|
||||
OleDB gamaDB;
|
||||
|
||||
char szQuery[OleDB::MaxQueryTextLen];
|
||||
int nQueryLen = 0;
|
||||
|
||||
if(!log.RedirectStdOut("GetHanBillingLogData_Log"))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
cout << endl << writetime << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>մϴ<D5B4>." << endl;
|
||||
|
||||
TCHAR* tszConfigFileName = TEXT("BillingLogData.cfg");
|
||||
|
||||
if(!config.Load(tszConfigFileName))
|
||||
{
|
||||
cout << writetime << tszConfigFileName << "DB<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char* szTimeFileName = "GetHanBillingLogDataTime.txt";
|
||||
|
||||
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_MSSQL))
|
||||
{
|
||||
cout << writetime << "<EFBFBD>Ѱ<EFBFBD><EFBFBD><EFBFBD>DB : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. : " << hanDB.GetErrorString()
|
||||
<< " ServerName : " << szHanServerName
|
||||
<< " DBName : " << szHanDBName
|
||||
<< " UserName : " << szHanUserName
|
||||
<< " Password : " << szHanPassword
|
||||
<< endl;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char* szGamaServerName = config.Get("GamaServerName");
|
||||
const char* szGamaDBName = config.Get("GamaDBName");
|
||||
const char* szGamaUserName = config.Get("GamaUserName");
|
||||
const char* szGamaPassword = config.Get("GamaPassword");
|
||||
|
||||
if(!gamaDB.ConnectSQLServer(szGamaServerName, szGamaDBName,
|
||||
szGamaUserName, szGamaPassword, OleDB::ConnType_MSSQL))
|
||||
{
|
||||
cout << writetime << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>DB : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. : " << gamaDB.GetErrorString()
|
||||
<< " ServerName : " << szGamaServerName
|
||||
<< " DBName : " << szGamaDBName
|
||||
<< " UserName : " << szGamaUserName
|
||||
<< " Password : " << szGamaPassword
|
||||
<< endl;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
__time64_t lastTime = 0;
|
||||
if(!LoadLastProcessedTime(szTimeFileName, &lastTime))
|
||||
{
|
||||
cout << writetime << szTimeFileName << "<EFBFBD>ð<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
__time64_t currentTime = _time64(0);
|
||||
|
||||
tm tmLastTime = *_localtime64(&lastTime);
|
||||
tm tmCurrentTime = *_localtime64(¤tTime);
|
||||
|
||||
_snprintf(szQuery, OleDB::MaxQueryTextLen - 1, "select "
|
||||
"strClientID, "
|
||||
"UID, "
|
||||
"intCRMIndex, "
|
||||
"strIp, "
|
||||
"CAST(strBillingType AS VARCHAR(2)), "
|
||||
"CAST(tinyServerID AS INT), "
|
||||
"CONVERT(varchar(20), FirstLoginTime, 20), "
|
||||
"CONVERT(varchar(20), LoginTime, 20), "
|
||||
"CONVERT(varchar(20), LogoutTime, 20), "
|
||||
"intPlayTime "
|
||||
"from tblcurrentuser_log where firstlogintime >='%04d-%02d-%02d %02d:%02d:%02d' "
|
||||
"and firstlogintime < '%04d-%02d-%02d %02d:%02d:%02d'",
|
||||
|
||||
tmLastTime.tm_year + 1900, tmLastTime.tm_mon + 1, tmLastTime.tm_mday,
|
||||
tmLastTime.tm_hour, tmLastTime.tm_min, tmLastTime.tm_sec,
|
||||
|
||||
tmCurrentTime.tm_year + 1900, tmCurrentTime.tm_mon + 1, tmCurrentTime.tm_mday,
|
||||
tmCurrentTime.tm_hour, tmCurrentTime.tm_min, tmCurrentTime.tm_sec);
|
||||
|
||||
szQuery[OleDB::MaxQueryTextLen - 1] = 0;
|
||||
|
||||
if(!hanDB.ExcuteQuery(szQuery))
|
||||
{
|
||||
cout << writetime << "<EFBFBD>Ѱ<EFBFBD><EFBFBD><EFBFBD>DB : <20><><EFBFBD><EFBFBD> <20>α<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>"
|
||||
<< hanDB.GetErrorString() << endl;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef std::list<std::pair<int, BillingLogData*> > InsertList;
|
||||
|
||||
InsertList insertList;
|
||||
|
||||
const int MAX_DATA = OleDB::MaxRowNum;
|
||||
BillingLogData* lpBillingLogData = new BillingLogData[MAX_DATA];
|
||||
|
||||
int nReturnRow = 0;
|
||||
int nTotalRow = 0;
|
||||
while(hanDB.GetData((void**)lpBillingLogData,
|
||||
sizeof(BillingLogData), MAX_DATA, &nReturnRow))
|
||||
{
|
||||
if(0 == nReturnRow)
|
||||
{
|
||||
if(0 != lpBillingLogData)
|
||||
{
|
||||
delete [] lpBillingLogData;
|
||||
lpBillingLogData = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
nTotalRow += nReturnRow;
|
||||
insertList.push_back(std::make_pair(nReturnRow, lpBillingLogData));
|
||||
lpBillingLogData = new BillingLogData[MAX_DATA];
|
||||
}
|
||||
|
||||
InsertList::iterator pos = insertList.begin();
|
||||
InsertList::iterator end = insertList.end();
|
||||
|
||||
int nInsertRow = 0;
|
||||
|
||||
for(;pos != end; ++pos)
|
||||
{
|
||||
BillingLogData* lpBillingLogData = pos->second;
|
||||
BillingLogData* lpBillingLogDataEnd = lpBillingLogData + pos->first;
|
||||
|
||||
for(; lpBillingLogData != lpBillingLogDataEnd; ++lpBillingLogData)
|
||||
{
|
||||
_snprintf(szQuery, OleDB::MaxQueryTextLen - 1,
|
||||
"INSERT INTO Tblcurrentuser_log values ('%s', %d, %d, '%s', '%c', %d, '%s', '%s', '%s', %d)",
|
||||
lpBillingLogData->strClientID,
|
||||
lpBillingLogData->UID,
|
||||
lpBillingLogData->intCRMIndex,
|
||||
lpBillingLogData->strIP,
|
||||
lpBillingLogData->strBillingType[0],
|
||||
lpBillingLogData->tinyServerID,
|
||||
lpBillingLogData->firstLoginTime,
|
||||
lpBillingLogData->loginTime,
|
||||
lpBillingLogData->logoutTime,
|
||||
lpBillingLogData->intPlayTime);
|
||||
|
||||
szQuery[OleDB::MaxQueryTextLen - 1] = 0;
|
||||
|
||||
if(!gamaDB.ExcuteQuery(szQuery, OleDB::Rowset_Update))
|
||||
{
|
||||
cout << writetime << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>DB : <20>Ѱ<EFBFBD><D1B0>ӿ<EFBFBD><D3BF><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>. : "
|
||||
<< gamaDB.GetErrorString() << " " << szQuery;
|
||||
}
|
||||
else
|
||||
{
|
||||
++nInsertRow;
|
||||
}
|
||||
}
|
||||
|
||||
delete [] pos->second;
|
||||
}
|
||||
|
||||
if(!SaveLastProcessedTime(szTimeFileName, currentTime))
|
||||
{
|
||||
cout << writetime << szTimeFileName << "<EFBFBD>ð<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>Ͽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>." << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(nInsertRow != nTotalRow)
|
||||
{
|
||||
cout << writetime << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ǽ<EFBFBD> : " << nInsertRow << " <20>о<EFBFBD><D0BE><EFBFBD> <20>Ǽ<EFBFBD> : " << nTotalRow << endl;
|
||||
}
|
||||
|
||||
cout << writetime << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>߽<EFBFBD><DFBD>ϴ<EFBFBD>. : ó<><C3B3> <20>Ǽ<EFBFBD> : " << nTotalRow << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user