📄 aujarddlg.cpp
字号:
// AujardDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Aujard.h"
#include "AujardDlg.h"
#include "ItemTableset.h"
#include <process.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define PROCESS_CHECK 100
#define CONCURRENT_CHECK 200
#define SERIAL_TIME 300
#define PACKET_CHECK 400
WORD g_increase_serial = 50001;
DWORD WINAPI ReadQueueThread(LPVOID lp);
CRITICAL_SECTION g_LogFileWrite;
DWORD WINAPI ReadQueueThread(LPVOID lp)
{
CAujardDlg* pMain = (CAujardDlg*)lp;
int recvlen = 0, index = 0;
BYTE command;
char recv_buff[1024];
memset( recv_buff, NULL, 1024 );
CString string;
//char logstr[256];
while(TRUE) {
if( pMain->m_LoggerRecvQueue.GetFrontMode() != R ) {
index = 0;
recvlen = pMain->m_LoggerRecvQueue.GetData( recv_buff );
if( recvlen > MAX_PKTSIZE ) {
Sleep(1);
continue;
}
command = GetByte( recv_buff, index );
switch( command ) {
case WIZ_LOGIN:
pMain->AccountLogIn( recv_buff+index );
break;
case WIZ_NEW_CHAR:
pMain->CreateNewChar( recv_buff+index );
break;
case WIZ_DEL_CHAR:
pMain->DeleteChar( recv_buff+index );
break;
case WIZ_SEL_CHAR:
pMain->SelectCharacter( recv_buff+index );
break;
case WIZ_SEL_NATION:
pMain->SelectNation( recv_buff+index );
break;
case WIZ_ALLCHAR_INFO_REQ:
pMain->AllCharInfoReq( recv_buff+index );
break;
case WIZ_LOGOUT:
pMain->UserLogOut( recv_buff+index );
break;
case WIZ_DATASAVE:
pMain->UserDataSave( recv_buff+index );
break;
case WIZ_KNIGHTS_PROCESS:
pMain->KnightsPacket( recv_buff+index );
break;
case WIZ_CLAN_PROCESS:
pMain->KnightsPacket( recv_buff+index );
break;
case WIZ_LOGIN_INFO:
pMain->SetLogInInfo( recv_buff+index );
break;
case WIZ_KICKOUT:
pMain->UserKickOut( recv_buff+index );
break;
case WIZ_BATTLE_EVENT:
pMain->BattleEventResult( recv_buff+index );
break;
case DB_COUPON_EVENT:
pMain->CouponEvent( recv_buff+index );
break;
}
recvlen = 0;
memset( recv_buff, NULL, 1024 );
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CAujardDlg dialog
CAujardDlg::CAujardDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAujardDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAujardDlg)
m_DBProcessNum = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
memset( m_strGameDSN, 0x00, 24 );
memset( m_strGameUID, 0x00, 24 );
memset( m_strGamePWD, 0x00, 24 );
memset( m_strAccountDSN, 0x00, 24 );
memset( m_strAccountUID, 0x00, 24 );
memset( m_strAccountPWD, 0x00, 24 );
memset( m_strLogDSN, 0x00, 24 );
memset( m_strLogUID, 0x00, 24 );
memset( m_strLogPWD, 0x00, 24 );
m_iSendPacketCount = 0;
m_iPacketCount = 0;
m_iRecvPacketCount = 0;
}
void CAujardDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAujardDlg)
DDX_Control(pDX, IDC_OUT_LIST, m_OutputList);
DDX_Text(pDX, IDC_DB_PROCESS, m_DBProcessNum);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAujardDlg, CDialog)
//{{AFX_MSG_MAP(CAujardDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAujardDlg message handlers
BOOL CAujardDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
//----------------------------------------------------------------------
// Logfile initialize
//----------------------------------------------------------------------
CTime time=CTime::GetCurrentTime();
char strLogFile[50]; memset(strLogFile, 0x00, 50);
wsprintf(strLogFile, "AujardLog-%d-%d-%d.txt", time.GetYear(), time.GetMonth(), time.GetDay());
m_LogFile.Open( strLogFile, CFile::modeWrite | CFile::modeCreate | CFile::modeNoTruncate | CFile::shareDenyNone );
m_LogFile.SeekToEnd();
m_iLogFileDay = time.GetDay();
InitializeCriticalSection( &g_LogFileWrite );
m_LoggerRecvQueue.InitailizeMMF( MAX_PKTSIZE, MAX_COUNT, SMQ_LOGGERSEND, FALSE ); // Dispatcher 狼 Send Queue
m_LoggerSendQueue.InitailizeMMF( MAX_PKTSIZE, MAX_COUNT, SMQ_LOGGERRECV, FALSE ); // Dispatcher 狼 Read Queue
if( !InitializeMMF() ) {
AfxMessageBox("Main Shared Memory Initialize Fail");
AfxPostQuitMessage(0);
return FALSE;
}
CString inipath;
inipath.Format( "%s\\Aujard.ini", GetProgPath() );
GetPrivateProfileString( "ODBC", "ACCOUNT_DSN", "", m_strAccountDSN, 24, inipath );
GetPrivateProfileString( "ODBC", "ACCOUNT_UID", "", m_strAccountUID, 24, inipath );
GetPrivateProfileString( "ODBC", "ACCOUNT_PWD", "", m_strAccountPWD, 24, inipath );
GetPrivateProfileString( "ODBC", "GAME_DSN", "", m_strGameDSN, 24, inipath );
GetPrivateProfileString( "ODBC", "GAME_UID", "", m_strGameUID, 24, inipath );
GetPrivateProfileString( "ODBC", "GAME_PWD", "", m_strGamePWD, 24, inipath );
GetPrivateProfileString( "ODBC", "LOG_DSN", "", m_strLogDSN, 24, inipath );
GetPrivateProfileString( "ODBC", "LOG_UID", "", m_strLogUID, 24, inipath );
GetPrivateProfileString( "ODBC", "LOG_PWD", "", m_strLogPWD, 24, inipath );
m_nServerNo = GetPrivateProfileInt("ZONE_INFO", "GROUP_INFO", 1, inipath);
m_nZoneNo = GetPrivateProfileInt("ZONE_INFO", "ZONE_INFO", 1, inipath);
if( !m_DBAgent.DatabaseInit() ) {
AfxPostQuitMessage(0);
return FALSE;
}
if( !LoadItemTable() ) {
AfxMessageBox("Load ItemTable Fail!!");
AfxPostQuitMessage(0);
return FALSE;
}
SetTimer( PROCESS_CHECK, 40000, NULL );
SetTimer( CONCURRENT_CHECK, 300000, NULL );
// SetTimer( SERIAL_TIME, 60000, NULL );
SetTimer( PACKET_CHECK, 120000, NULL);
DWORD id;
m_hReadQueueThread = ::CreateThread( NULL, 0, ReadQueueThread, (LPVOID)this, 0, &id);
CTime cur = CTime::GetCurrentTime();
CString starttime;
starttime.Format("Aujard Start : %d岿 %d老 %d矫 %d盒\r\n", cur.GetMonth(), cur.GetDay(), cur.GetHour(), cur.GetMinute());
m_LogFile.Write(starttime, starttime.GetLength());
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CAujardDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
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;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CAujardDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CAujardDlg::DestroyWindow()
{
KillTimer( PROCESS_CHECK );
KillTimer( CONCURRENT_CHECK );
// KillTimer( SERIAL_TIME );
KillTimer( PACKET_CHECK );
if( m_hReadQueueThread ) {
::TerminateThread( m_hReadQueueThread, 0 );
}
if( !m_ItemtableArray.IsEmpty() )
m_ItemtableArray.DeleteAllData();
if(m_LogFile.m_hFile != CFile::hFileNull) m_LogFile.Close();
DeleteCriticalSection( &g_LogFileWrite );
return CDialog::DestroyWindow();
}
BOOL CAujardDlg::InitializeMMF()
{
CString logstr;
DWORD filesize = MAX_USER * 4000; // 1疙寸 4000 bytes 捞郴 家夸
m_hMMFile = OpenFileMapping( FILE_MAP_ALL_ACCESS, TRUE, "KNIGHT_DB" );
if( m_hMMFile == NULL ) {
logstr = "Shared Memory Load Fail!!";
m_hMMFile = INVALID_HANDLE_VALUE;
return FALSE;
}
logstr = "Shared Memory Load Success!!";
m_OutputList.AddString( logstr );
m_lpMMFile = (char *)MapViewOfFile (m_hMMFile, FILE_MAP_WRITE, 0, 0, 0);
if( !m_lpMMFile )
return FALSE;
m_DBAgent.m_UserDataArray.reserve( MAX_USER );
_USER_DATA* pUser = NULL;
for(int i=0; i< MAX_USER; i++)
{
pUser = (_USER_DATA*)(m_lpMMFile + i*4000);
m_DBAgent.m_UserDataArray.push_back(pUser);
}
return TRUE;
}
BOOL CAujardDlg::LoadItemTable()
{
CItemTableSet ItemTableSet;
if( !ItemTableSet.Open() ) {
AfxMessageBox(_T("ItemTable Open Fail!"));
return FALSE;
}
if(ItemTableSet.IsBOF() || ItemTableSet.IsEOF()) {
AfxMessageBox(_T("ItemTable Empty!"));
return FALSE;
}
ItemTableSet.MoveFirst();
while( !ItemTableSet.IsEOF() )
{
_ITEM_TABLE* pTableItem = new _ITEM_TABLE;
pTableItem->m_iNum = ItemTableSet.m_Num;
strcpy(pTableItem->m_strName, ItemTableSet.m_strName);
pTableItem->m_bKind = ItemTableSet.m_Kind;
pTableItem->m_bSlot = ItemTableSet.m_Slot;
pTableItem->m_bRace = ItemTableSet.m_Race;
pTableItem->m_bClass = ItemTableSet.m_Class;
pTableItem->m_sDamage = ItemTableSet.m_Damage;
pTableItem->m_sDelay = ItemTableSet.m_Delay;
pTableItem->m_sRange = ItemTableSet.m_Range;
pTableItem->m_sWeight = ItemTableSet.m_Weight;
pTableItem->m_sDuration = ItemTableSet.m_Duration;
pTableItem->m_iBuyPrice = ItemTableSet.m_BuyPrice;
pTableItem->m_iSellPrice = ItemTableSet.m_SellPrice;
pTableItem->m_sAc = ItemTableSet.m_Ac;
pTableItem->m_bCountable = ItemTableSet.m_Countable;
pTableItem->m_iEffect1 = ItemTableSet.m_Effect1;
pTableItem->m_iEffect2 = ItemTableSet.m_Effect2;
pTableItem->m_bReqLevel = ItemTableSet.m_ReqLevel;
pTableItem->m_bReqRank = ItemTableSet.m_ReqRank;
pTableItem->m_bReqTitle = ItemTableSet.m_ReqTitle;
pTableItem->m_bReqStr = ItemTableSet.m_ReqStr;
pTableItem->m_bReqSta = ItemTableSet.m_ReqSta;
pTableItem->m_bReqDex = ItemTableSet.m_ReqDex;
pTableItem->m_bReqIntel = ItemTableSet.m_ReqIntel;
pTableItem->m_bReqCha = ItemTableSet.m_ReqCha;
pTableItem->m_bSellingGroup = ItemTableSet.m_SellingGroup;
pTableItem->m_ItemType = ItemTableSet.m_ItemType;
pTableItem->m_sHitrate = ItemTableSet.m_Hitrate;
pTableItem->m_sEvarate = ItemTableSet.m_Evasionrate;
pTableItem->m_sDaggerAc = ItemTableSet.m_DaggerAc;
pTableItem->m_sSwordAc = ItemTableSet.m_SwordAc;
pTableItem->m_sMaceAc = ItemTableSet.m_MaceAc;
pTableItem->m_sAxeAc = ItemTableSet.m_AxeAc;
pTableItem->m_sSpearAc = ItemTableSet.m_SpearAc;
pTableItem->m_sBowAc = ItemTableSet.m_BowAc;
pTableItem->m_bFireDamage = ItemTableSet.m_FireDamage;
pTableItem->m_bIceDamage = ItemTableSet.m_IceDamage;
pTableItem->m_bLightningDamage = ItemTableSet.m_LightningDamage;
pTableItem->m_bPoisonDamage = ItemTableSet.m_PoisonDamage;
pTableItem->m_bHPDrain = ItemTableSet.m_HPDrain;
pTableItem->m_bMPDamage = ItemTableSet.m_MPDamage;
pTableItem->m_bMPDrain = ItemTableSet.m_MPDrain;
pTableItem->m_bMirrorDamage = ItemTableSet.m_MirrorDamage;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -