4919 lines
130 KiB
C++
4919 lines
130 KiB
C++
//---------------------------------------------------------------------------
|
||
|
||
#include <vcl.h>
|
||
#include <mmsystem.h>
|
||
#include <Tlhelp32.h>
|
||
#pragma hdrstop
|
||
|
||
#include "RBmasterMain.h"
|
||
#include "CommonV8Handler.h"
|
||
#include "HttpThread.h"
|
||
#include "GlobalUnit.h"
|
||
#include "BacABThread.h"
|
||
#include "BacDPThread.h"
|
||
#include "BacJSThread.h"
|
||
#include "GameUnit.h"
|
||
#include "UtilityUnit.h"
|
||
#include "HookJS.h"
|
||
#include "LoginUnit.h"
|
||
#include "PolicyEditFormUnit.h"
|
||
#include "TableSet.h"
|
||
#include "BetLogFormUnit.h"
|
||
#include "ChartFormUnit.h"
|
||
#include "SettingFormUnit.h"
|
||
#include "ResetFormUnit.h"
|
||
#include "ChipsFormUnit.h"
|
||
#include "ActCodeFormUnit.h"
|
||
#include "AIFormUnit.h"
|
||
|
||
#define USER_VAR_FILE "rbmvrf"
|
||
#define USER_VAR_VERSION 0x02
|
||
#define USER_WEB_FILE "rbmwbf"
|
||
#define USER_WEB_VERSION 0x01
|
||
|
||
#define USER_GAME_FILE "rbmgmf"
|
||
#define USER_GAME_VERSION 0x0F
|
||
//0x0C 增加清空台桌下注记录/开局X手后... v3.2.0
|
||
//0x0D 调整游台换台策略 v3.2.1
|
||
//0x0E 增加连续下注忽略和 v3.8.2
|
||
|
||
#define UR_LOGIN 0x10
|
||
#define UR_REPORT 0x100
|
||
#define UR_LOGOUT 0x101
|
||
|
||
//---------------------------------------------------------------------------
|
||
#pragma package(smart_init)
|
||
#pragma comment(lib, "winmm")
|
||
#pragma link "TableUnit"
|
||
#pragma link "InfoFrameUnit"
|
||
#pragma resource "*.dfm"
|
||
TMainForm *MainForm;
|
||
|
||
typedef struct tUVFHeader{
|
||
char head[4];
|
||
|
||
tUVFHeader(){
|
||
head[0] = 'U';
|
||
head[1] = 'V';
|
||
head[2] = 'F';
|
||
head[3] = USER_VAR_VERSION;
|
||
}
|
||
} TUVFHEADER;
|
||
|
||
typedef struct tUGFHeader{
|
||
char head[4];
|
||
|
||
tUGFHeader(){
|
||
head[0] = 'U';
|
||
head[1] = 'G';
|
||
head[2] = 'F';
|
||
head[3] = USER_GAME_VERSION;
|
||
}
|
||
} TUGFHEADER;
|
||
|
||
typedef struct tUWFHeader{
|
||
char head[4];
|
||
|
||
tUWFHeader(){
|
||
head[0] = 'U';
|
||
head[1] = 'W';
|
||
head[2] = 'F';
|
||
head[3] = USER_WEB_VERSION;
|
||
}
|
||
} TUWFHEADER;
|
||
|
||
typedef struct tUWFData{
|
||
char id[32];
|
||
char li[16];
|
||
char gt[16];
|
||
char un[32];
|
||
char dm[64];
|
||
char fw[512];
|
||
char url[2048];
|
||
|
||
tUWFData(){memset(this, 0, sizeof(this));};
|
||
} TUWFDATA;
|
||
|
||
#define MAX_STR_LEN 256
|
||
#define WSNUM 9
|
||
char* websites[WSNUM] = { "gci.dsn20102022.co",
|
||
"gci.jnhui0032.com",
|
||
"gci.bnm8585.com",
|
||
"gci.bcasiaintegration.com",
|
||
"gci.gnroi.club",
|
||
"gci.wy168y.com",
|
||
"gci.71xfky6dmujm0i5.com",
|
||
"gci.4kh1mb8gkpb5.com",
|
||
"gci.myf7f3bx.com"
|
||
};
|
||
char urServer[32] = {0};
|
||
|
||
////////////////////////////////////////////////////////////////////////////////
|
||
|
||
__fastcall TMainForm::TMainForm(TComponent* Owner)
|
||
: TForm(Owner)
|
||
{
|
||
m_vlThread = m_jsThread = m_dpThread = m_urThread = NULL;
|
||
m_bClosing = false;
|
||
m_bWebLogon = m_bManual = false;
|
||
m_bmTBPBackTile = m_bmTBPPile = m_bmCapOver = NULL;
|
||
m_pDPTimer = m_pUtilTimer = m_pRunTimer = NULL;
|
||
m_nTabCols = m_nTabGap = 0;
|
||
m_nTabShow = 15;
|
||
m_nTabRun = 0;
|
||
m_tmBetPause = m_tmDeadPause = m_tmWebFocus = m_tmChart = m_tmCount = m_tmLogon = m_tmRunTime = 0;
|
||
m_btnAI = NULL;
|
||
|
||
//游戏平台浏览器
|
||
m_chrm = NULL;
|
||
m_hV8Sema = CreateSemaphore( NULL, 1, 1, NULL );
|
||
m_hV8ValueSema = CreateSemaphore( NULL, 0, 1, NULL );
|
||
m_v8Values = new TStringList;
|
||
m_bChrmClosed = false;
|
||
|
||
//代码策略浏览器
|
||
m_chrmCode = NULL;
|
||
m_v8CodeValues = new TStringList;
|
||
m_hV8CodeSema = CreateSemaphore( NULL, 1, 1, NULL );
|
||
m_hV8CodeValueSema = CreateSemaphore( NULL, 0, 1, NULL );
|
||
m_bChrmCodeClosed = false;
|
||
|
||
m_iWindowState = wsNormal;
|
||
|
||
m_iWSVelo = m_iWS = -1;
|
||
m_idDevice = m_tExpire = 0;
|
||
|
||
m_bDragReady = m_bDraging = false;
|
||
m_pDragTimer = NULL;
|
||
m_iLastSel = -1;
|
||
|
||
sprintf(urServer, "%s:98", g_apiServer);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::FormCreate(TObject *Sender)
|
||
{
|
||
m_hPMDll = LoadLibrary(L"Paramencode.dll");
|
||
if( !m_hPMDll || !(PM_ParamEncode=(PM_PARAMENCODE)GetProcAddress(m_hPMDll, "ParamEncode")) ){
|
||
Tag = -1;
|
||
return;
|
||
}
|
||
|
||
// 执行文件版本信息
|
||
DWORD dwHandle;
|
||
DWORD dwVerLen = GetFileVersionInfoSize(Application->ExeName.c_str(), &dwHandle);
|
||
if (dwVerLen) {
|
||
TCHAR *lpData = new TCHAR[dwVerLen];
|
||
if (GetFileVersionInfo(Application->ExeName.c_str(), 0, dwVerLen, lpData)) {
|
||
PVSFixedFileInfo lpffi;
|
||
UINT uLen;
|
||
if (VerQueryValue(lpData, TEXT("\\"), (void **)&lpffi, &uLen)) {
|
||
m_version[0] = HIWORD(lpffi->dwFileVersionMS);
|
||
m_version[1] = LOWORD(lpffi->dwFileVersionMS);
|
||
m_version[2] = HIWORD(lpffi->dwFileVersionLS);
|
||
m_version[3] = LOWORD(lpffi->dwFileVersionLS);
|
||
}
|
||
}
|
||
delete[]lpData;
|
||
}
|
||
|
||
Caption = APPNAME;
|
||
// Caption = Caption + " " + IntToStr(m_version[0]) + "." + IntToStr(m_version[1]);
|
||
m_lblVersion->Caption = "v " + IntToStr(m_version[0]) + "." + IntToStr(m_version[1]);
|
||
|
||
if( g_bTesting )
|
||
m_lblVersion->Caption = m_lblVersion->Caption + " -D";
|
||
|
||
Tag = InitGlobalVars();
|
||
if( Tag<0 || Tag==2 )
|
||
return;
|
||
|
||
// 获取DPI
|
||
HDC hdc = GetDC(NULL);
|
||
if (hdc != NULL) {
|
||
g_xDpi = GetDeviceCaps(hdc, LOGPIXELSX);
|
||
g_yDpi = GetDeviceCaps(hdc, LOGPIXELSY);
|
||
ReleaseDC(NULL, hdc);
|
||
}
|
||
|
||
// 标题栏
|
||
m_bmTBPBackTile = new TBitmap();
|
||
m_bmTBPBackTile->LoadFromResourceName(int(HInstance), L"TB_TILE");
|
||
|
||
m_bmTBPPile = new TBitmap();
|
||
TPngImage *png = new TPngImage();
|
||
TResourceStream * pStream = new TResourceStream(int(HInstance), L"TB_PILE", RT_RCDATA);
|
||
png->LoadFromStream(pStream);
|
||
delete pStream;
|
||
m_bmTBPPile->Assign(png);
|
||
delete png;
|
||
|
||
// 1x1 白色遮罩(预乘 alpha,像素值在 FillCapOver 里按需改)
|
||
m_bmCapOver = new TBitmap();
|
||
m_bmCapOver->SetSize(1, 1);
|
||
m_bmCapOver->PixelFormat = pf32bit;
|
||
m_bmCapOver->AlphaFormat = afPremultiplied;
|
||
|
||
// 系统按钮:改为视觉透明 —— 覆盖 VCL 画的不透明底色
|
||
m_oldTbWndProc = m_tbp->WindowProc;
|
||
m_tbp->WindowProc = TBWndProc;
|
||
|
||
m_tbp->TitleButtonMin->OnPaint = OnCapPaint;
|
||
m_tbp->TitleButtonRestore->OnPaint = OnCapPaint;
|
||
m_tbp->TitleButtonClose->OnPaint = OnCapPaint;
|
||
|
||
m_tbp->TitleButtonMin->OnMouseDown = OnCapMouseDown;
|
||
m_tbp->TitleButtonMin->OnMouseUp = OnCapMouseUp;
|
||
m_tbp->TitleButtonClose->OnMouseDown = OnCapMouseDown;
|
||
m_tbp->TitleButtonClose->OnMouseUp = OnCapMouseUp;
|
||
|
||
TCaptionButtonItem *ai = static_cast<TCaptionButtonItem*>( m_tbp->CustomButtons->Add() );
|
||
ai->OnPaint = OnAIBtnPaint;
|
||
ai->OnClick = OnAIBtnClick;
|
||
ai->Hint = L"AI助手";
|
||
ai->ShowHint = true;
|
||
ai->ButtonType = sbCustom;
|
||
ai->Width = DPIX(45);
|
||
|
||
m_pDPTimer = new TTimer(NULL);
|
||
m_pDPTimer->OnTimer = DPTimerProc;
|
||
m_pDPTimer->Interval = 1000;
|
||
m_pDPTimer->Enabled = false;
|
||
|
||
m_pRunTimer = new TTimer(NULL);
|
||
m_pRunTimer->OnTimer = RunTimerProc;
|
||
m_pRunTimer->Interval = 60000;
|
||
m_pRunTimer->Enabled = true;
|
||
|
||
Randomize();
|
||
GetDeviceId();
|
||
|
||
int tmRand = Random(30); //10-30秒随机间隔避免并发请求
|
||
m_tmDailyLogin = 300 + tmRand; //00:05:00 - 00:05:30 请求用户信息
|
||
m_tmDailyReport = 86400 - tmRand - 15; //23:59:15 - 23:59:45 上报实打流水
|
||
|
||
LoadPolicies();
|
||
FileUserVars();
|
||
FileGame();
|
||
|
||
for(int i=0; i<g_aBetPolicies.size(); i++){
|
||
TBasePolicy* pPolicy = g_aBetPolicies[i];
|
||
m_cbBetWays->AddItem(pPolicy->name,NULL);
|
||
}
|
||
if(g_iBetPolicy<g_aBetPolicies.size())
|
||
m_cbBetWays->ItemIndex = g_iBetPolicy;
|
||
else
|
||
g_iBetPolicy = -1;
|
||
|
||
for(int i=0; i<g_aChipPolicies.size(); i++){
|
||
TBasePolicy* pPolicy = g_aChipPolicies[i];
|
||
m_cbBetChips->AddItem(pPolicy->name,NULL);
|
||
}
|
||
if(g_iChipPolicy>=0 && g_iChipPolicy<g_aChipPolicies.size())
|
||
m_cbBetChips->ItemIndex = g_iChipPolicy;
|
||
else{
|
||
g_iChipPolicy = -1;
|
||
g_nChipMul = 0;
|
||
}
|
||
if(g_nChipMul>0){
|
||
m_leChipMul->Text = g_nChipMul;
|
||
m_leChipMul->Enabled = true;
|
||
}
|
||
|
||
if(g_iPlatform > m_pmLogin->Items->Count)
|
||
g_iPlatform = 0;
|
||
else if(g_iPlatform>0)
|
||
m_pmLogin->Items->Items[g_iPlatform-1]->Checked = true;
|
||
|
||
AppendMenu(GetSystemMenu(Handle,false),MF_SEPARATOR,0,L"");
|
||
AppendMenu(GetSystemMenu(Handle,false),MF_STRING,200,L"软件操作说明(&D)");
|
||
AppendMenu(GetSystemMenu(Handle,false),MF_STRING,201,L"授权验证(&A)...");
|
||
|
||
if(g_iPlatform==PF_PA && m_iWS<0)
|
||
WebsiteVelocity();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::CreateParams(TCreateParams &Params)
|
||
{
|
||
TForm::CreateParams(Params);
|
||
|
||
String strFullName = TPath::GetFullPath(Application->ExeName);
|
||
wcscpy(Params.WinClassName, (LPCTSTR)strFullName.c_str());
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::FormShow(TObject *Sender)
|
||
{
|
||
CustomTitleBar->Enabled = false;
|
||
CustomTitleBar->Enabled = true;
|
||
|
||
if(!m_dpThread){
|
||
m_dpThread = new TDataParseThread();
|
||
m_dpThread->Start();
|
||
}
|
||
|
||
m_pUtilTimer = new TTimer(NULL);
|
||
m_pUtilTimer->Tag = -1;
|
||
m_pUtilTimer->OnTimer = UtilTimerProc;
|
||
m_pUtilTimer->Interval = 500;
|
||
m_pUtilTimer->Enabled = true; //false; //
|
||
|
||
if(!m_pUtilTimer->Enabled && m_sActCode.Length())
|
||
PostMessage(Handle, UM_USERCONFIRM, UR_LOGIN, 0 );
|
||
|
||
m_cbBetWays->SelLength = 0;
|
||
m_cbBetChips->SelLength = 0;
|
||
|
||
m_tsMode->State = g_bSimulate ? tssOff : tssOn;
|
||
|
||
///////////////////////////////////////////
|
||
//test
|
||
// for(int i=0; i<75; i++){
|
||
// TGame* pG = new TGame(100+i);
|
||
// pG->vid = pG->iGame;
|
||
// pG->iState = ST_BETTING;
|
||
// g_aGames.push_back(pG);
|
||
//
|
||
// TTableFrame* pT = new TTableFrame(NULL);
|
||
// pT->Parent = m_panWeb;
|
||
// pT->SetGame(pG);
|
||
//
|
||
// m_aTables.push_back(pT);
|
||
// }
|
||
// ResetTableGrid();
|
||
// int ts = DateTimeToUnix(Now(), false);
|
||
// for(int i=0; i<100; i++){
|
||
// PostMessage(m_aTables[0]->Handle, UM_LOG_UPDATE, ST_ROUND, 0);
|
||
// TBetLog* pLog = new TBetLog;
|
||
// pLog->ts = ts++;
|
||
// pLog->ev = LOGEVT_START;
|
||
// SendMessage(Handle, UM_LOG_UPDATE, 0, (long)pLog);
|
||
// }
|
||
// PostMessage(m_aTables[0]->Handle, UM_LOG_UPDATE, ST_FAILED, 25);
|
||
|
||
|
||
///////////////////////////////////////////
|
||
}
|
||
//--------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::FormCloseQuery(TObject *Sender, bool &CanClose)
|
||
{
|
||
if( !m_bClosing ){
|
||
if(g_bGameOn){
|
||
int mrRet = MessageBox(Handle, L"正在挂机中,是否确定退出程序?", L"退出",
|
||
MB_ICONQUESTION | MB_OKCANCEL);
|
||
|
||
if( mrRet==mrCancel ){
|
||
CanClose = false;
|
||
return;
|
||
}
|
||
else{
|
||
GameOff();
|
||
}
|
||
}
|
||
else{
|
||
RBReport();
|
||
}
|
||
|
||
if(g_aGames.nBetted[0] || g_aGames.nBetted[1]){
|
||
int mrRet = MessageBox(Handle, L"尚有结算未完成,是否确定退出程序?", L"退出",
|
||
MB_ICONQUESTION | MB_OKCANCEL);
|
||
|
||
if( mrRet==mrCancel ){
|
||
CanClose = false;
|
||
return;
|
||
}
|
||
}
|
||
|
||
if(AIForm){
|
||
int mrRet = MessageBox(Handle, L"AI 助手尚未关闭,是否确定退出程序?", L"退出",
|
||
MB_ICONQUESTION | MB_OKCANCEL);
|
||
|
||
if( mrRet==mrCancel ){
|
||
CanClose = false;
|
||
return;
|
||
}
|
||
|
||
AIForm->Perform( WM_CLOSE, 0, 0 );
|
||
|
||
Sleep(300);
|
||
}
|
||
|
||
Logout();
|
||
}
|
||
|
||
ClearVLThread();
|
||
ClearJSThread();
|
||
ClearABThread();
|
||
ClearDPThread();
|
||
|
||
if( m_pDPTimer ){
|
||
delete m_pDPTimer;
|
||
m_pDPTimer = NULL;
|
||
}
|
||
|
||
if( m_pRunTimer ){
|
||
delete m_pRunTimer;
|
||
m_pRunTimer = NULL;
|
||
}
|
||
|
||
ClearUtilTimer();
|
||
|
||
if( m_hV8Sema ){
|
||
CloseHandle( m_hV8Sema );
|
||
m_hV8Sema = NULL;
|
||
}
|
||
|
||
if( m_hV8ValueSema ){
|
||
CloseHandle( m_hV8ValueSema );
|
||
m_hV8ValueSema = NULL;
|
||
}
|
||
|
||
if( m_v8Values ){
|
||
delete m_v8Values;
|
||
m_v8Values = NULL;
|
||
}
|
||
|
||
if( m_hV8CodeSema ){
|
||
CloseHandle( m_hV8CodeSema );
|
||
m_hV8CodeSema = NULL;
|
||
}
|
||
|
||
if( m_hV8CodeValueSema ){
|
||
CloseHandle( m_hV8CodeValueSema );
|
||
m_hV8CodeValueSema = NULL;
|
||
}
|
||
|
||
if( m_v8CodeValues ){
|
||
delete m_v8CodeValues;
|
||
m_v8CodeValues = NULL;
|
||
}
|
||
|
||
if(m_chrm || m_chrmCode ){
|
||
if( !m_bClosing ){
|
||
m_bClosing = true;
|
||
if( m_chrm ) m_chrm->CloseBrowser(true);
|
||
if( m_chrmCode ) m_chrmCode->CloseBrowser(true);
|
||
CanClose = false;
|
||
}
|
||
else if(m_chrm && !m_bChrmClosed || m_chrmCode && !m_bChrmCodeClosed){
|
||
CanClose = false;
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
|
||
{
|
||
if(m_urThread){
|
||
Sleep(500);
|
||
ClearURThread();
|
||
}
|
||
|
||
if( m_hPMDll )
|
||
FreeLibrary( m_hPMDll );
|
||
|
||
if( m_chrm ){
|
||
delete m_chrm;
|
||
m_chrm = NULL;
|
||
}
|
||
|
||
if( m_chrmCode ){
|
||
delete m_chrmCode;
|
||
m_chrmCode = NULL;
|
||
}
|
||
|
||
if( m_bmTBPBackTile ){
|
||
delete m_bmTBPBackTile;
|
||
m_bmTBPBackTile = NULL;
|
||
}
|
||
|
||
if( m_bmTBPPile ){
|
||
delete m_bmTBPPile;
|
||
m_bmTBPPile = NULL;
|
||
}
|
||
|
||
if( m_bmCapOver ){
|
||
delete m_bmCapOver;
|
||
m_bmCapOver = NULL;
|
||
}
|
||
|
||
ClearGames();
|
||
|
||
FileGame( true );
|
||
FileUserVars( true );
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::FormActivate(TObject *Sender)
|
||
{
|
||
if(ChartForm && ChartForm->WindowState==wsMaximized){
|
||
FormStyle = fsStayOnTop;
|
||
Application->BringToFront();
|
||
FormStyle = fsNormal;
|
||
}
|
||
|
||
SetTableFocus();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::FormResize(TObject *Sender)
|
||
{
|
||
ResetIdle();
|
||
|
||
if(m_iWindowState==wsMaximized && WindowState==wsNormal){ //恢复
|
||
SetBounds(m_nLeft, m_nTop, m_nWidth, m_nHeight);
|
||
}
|
||
|
||
if(m_iWindowState!=wsMinimized && WindowState!=wsMinimized){
|
||
//是否自动调整高度
|
||
int hPan = ClientHeight - m_panTopBar->Top - m_panTopBar->Height - 2,
|
||
nRem = hPan % TFHEIGHT;
|
||
if(nRem < DPIY(12))
|
||
ClientHeight -= nRem;
|
||
else if(TFHEIGHT-nRem < DPIY(12))
|
||
ClientHeight += TFHEIGHT-nRem;
|
||
|
||
m_panWeb->Height = ClientHeight - m_panTopBar->Top - m_panTopBar->Height;
|
||
|
||
//tbp处理
|
||
m_tbp->Width = ClientWidth;
|
||
m_lblBigProfit->Left = (m_tbp->Width - m_lblBigProfit->Width)/ 2;
|
||
m_lblRunTime->Left = m_tbp->Width - m_lblRunTime->Width - DPIX(14);
|
||
|
||
if(WindowState==wsMaximized){
|
||
m_imgLogo->Top = DPIY(6);
|
||
m_lblBigProfit->Top = DPIY(16);
|
||
m_lblPlatform->Top = m_imgLogo->Top + DPIY(3);
|
||
m_lblVersion->Top = m_imgLogo->Top + m_imgLogo->Height - DPIY(20);
|
||
}
|
||
else if(m_iWindowState!=wsNormal){
|
||
m_imgLogo->Top = DPIY(10);
|
||
m_lblBigProfit->Top = DPIY(20);
|
||
m_lblPlatform->Top = m_imgLogo->Top + DPIY(3);
|
||
m_lblVersion->Top = m_imgLogo->Top + m_imgLogo->Height - DPIY(20);
|
||
}
|
||
|
||
if( m_tbp->TitleButtonRestore ) m_tbp->TitleButtonRestore->Invalidate();
|
||
|
||
if(m_frmInfo->Width < ClientWidth)
|
||
m_frmInfo->Left = (ClientWidth - m_frmInfo->Width) / 2;
|
||
else
|
||
m_frmInfo->Left = 0;
|
||
|
||
m_panTopBar->Left = (ClientWidth - m_panTopBar->Width) / 2;
|
||
|
||
m_lblTips->Left = (m_panWeb->Width - m_lblTips->Width) / 2;
|
||
m_lblAnnonce->Top = m_panWeb->Height - DPIY(50);
|
||
|
||
bool bResetGrid = false;
|
||
int nWidth = m_panWeb->Width-DPIX(20);//留出滚动条位置
|
||
int nTabCols = nWidth / TFWIDTH;
|
||
int nTabGap = (nWidth % TFWIDTH) / (nTabCols-1);
|
||
if(m_nTabCols!=nTabCols){ //列数改变
|
||
m_nTabCols = nTabCols;
|
||
m_panWeb->VertScrollBar->Position = 0; //滚动条复位
|
||
bResetGrid = true;
|
||
}
|
||
if(m_nTabGap != nTabGap){
|
||
m_nTabGap = nTabGap;
|
||
bResetGrid = true;
|
||
}
|
||
if(bResetGrid)
|
||
ResetTableGrid();
|
||
|
||
int dpi5 = DPIX(5), dpi60 = DPIX(60);
|
||
if(ChipsForm && ChipsForm->Width < dpi60){
|
||
int x = Left > dpi60 ? ChipsForm->Width - dpi5 : -dpi5; //放置到窗口内外
|
||
TPoint pt = TPoint(x, m_panWeb->Top);
|
||
pt = ClientToScreen(pt);
|
||
ChipsForm->Left = pt.x;
|
||
ChipsForm->Top = pt.y;
|
||
ChipsForm->BringToFront();
|
||
}
|
||
}
|
||
|
||
if(m_iWindowState==wsNormal && WindowState==wsNormal){
|
||
m_nWidth = Width, m_nHeight = Height;
|
||
}
|
||
|
||
m_iWindowState = WindowState;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::FormMove(TWMMove &msg)
|
||
{
|
||
if(Visible && WindowState!=wsMaximized)
|
||
m_nLeft = Left, m_nTop = Top;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
|
||
{
|
||
ResetIdle();
|
||
|
||
if(ActiveControl && (ActiveControl->ClassNameIs(TComboBox::ClassName())
|
||
|| ActiveControl->ClassNameIs(TLabeledEdit::ClassName())))
|
||
return;
|
||
|
||
if(!m_aTables.empty()){
|
||
if(Key==VK_UP){
|
||
m_panWeb->Perform(WM_VSCROLL,SB_LINEUP,0);
|
||
}
|
||
else if(Key==VK_DOWN){
|
||
m_panWeb->Perform(WM_VSCROLL,SB_LINEDOWN,0);
|
||
}
|
||
else if(Key==VK_PRIOR){ //pageup
|
||
m_panWeb->Perform(WM_VSCROLL,SB_PAGEUP,0);
|
||
}
|
||
else if(Key==VK_NEXT){ //pagedown
|
||
m_panWeb->Perform(WM_VSCROLL,SB_PAGEDOWN,0);
|
||
}
|
||
else if(Key==VK_HOME){
|
||
m_panWeb->Perform(WM_VSCROLL,SB_TOP,0);
|
||
}
|
||
else if(Key==VK_END){
|
||
m_panWeb->Perform(WM_VSCROLL,SB_BOTTOM,0);
|
||
}
|
||
else if(Key=='A' && Shift.Contains( ssCtrl )){
|
||
if(!m_bManual){
|
||
LockWindowUpdate( m_panWeb->Handle );
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
m_aTables[i]->SetSel(true);
|
||
m_aSelTabs.insert(i);
|
||
}
|
||
LockWindowUpdate(0);
|
||
}
|
||
}
|
||
else if(Key==VK_ESCAPE){
|
||
ClearSelect();
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::FormMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
|
||
{
|
||
ResetIdle();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::SystemMenuCommand(TWMMenuSelect &Msg)
|
||
{
|
||
TForm::Dispatch(&Msg);
|
||
if(Msg.IDItem==200){
|
||
PostMessage(Handle, UM_OPENMAUAL, 0, 0);
|
||
}
|
||
else if(Msg.IDItem==201){
|
||
PostMessage(Handle, UM_SUBFORMSHOWN, 0, 0);
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ClearUtilTimer()
|
||
{
|
||
if(m_pUtilTimer){
|
||
delete m_pUtilTimer;
|
||
m_pUtilTimer = NULL;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ClearVLThread()
|
||
{
|
||
if( m_vlThread ){
|
||
((TVeloThread*)m_vlThread)->Cancel();
|
||
m_vlThread->WaitFor();
|
||
|
||
delete m_vlThread;
|
||
m_vlThread = NULL;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ClearJSThread()
|
||
{
|
||
if( m_jsThread ){
|
||
((TJSHandleThread*)m_jsThread)->Cancel();
|
||
m_jsThread->WaitFor();
|
||
|
||
delete m_jsThread;
|
||
m_jsThread = NULL;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ClearURThread()
|
||
{
|
||
if( m_urThread ){
|
||
((TAsynHttpThread*)m_urThread)->Cancel();
|
||
m_urThread->WaitFor();
|
||
|
||
delete m_urThread;
|
||
m_urThread = NULL;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ClearDPThread()
|
||
{
|
||
if( m_dpThread ){
|
||
((TDataParseThread*)m_dpThread)->Cancel();
|
||
m_dpThread->WaitFor();
|
||
|
||
delete m_dpThread;
|
||
m_dpThread = NULL;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ClearABThread(int hThread)
|
||
{
|
||
vector<TThread*>::iterator itTh = m_aABThreads.begin();
|
||
|
||
while( itTh!=m_aABThreads.end() ){
|
||
if( hThread==0 || (*itTh)->Handle==hThread ){
|
||
((TBaseThread*)(*itTh))->Cancel();
|
||
(*itTh)->WaitFor();
|
||
delete (*itTh);
|
||
|
||
itTh = m_aABThreads.erase(itTh);
|
||
|
||
if( hThread!=0 )
|
||
break;
|
||
}
|
||
else
|
||
itTh++;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
int __fastcall TMainForm::InitGlobalVars()
|
||
{
|
||
char szBuffer[2048] = "",
|
||
szFile[256];
|
||
bool bSave = false;
|
||
int iUpdate = 0;
|
||
FILE* fp = NULL;
|
||
|
||
//读取文件配置
|
||
sprintf( szFile, "%s\\%s", g_AppPath, GLOBAL_VAR_FILE );
|
||
fp = fopen( szFile, "rb" );
|
||
if( fp ){
|
||
TGVFHEADER header;
|
||
int ret = fread( (void*)szBuffer, 1, sizeof(header), fp );
|
||
|
||
if( ret==sizeof(header) && !memcmp(szBuffer, header.head, sizeof(header.head)) ){
|
||
if( ((TGVFHEADER*)szBuffer)->iUpdate > 0 ){ //需要完成更新
|
||
ret = TryUpdate(); //尝试更新
|
||
if( ret==0 )
|
||
bSave = true; //需更改标志
|
||
else if( ret==1 )
|
||
iUpdate = 1;
|
||
else if( ret==3 ){
|
||
fclose( fp );
|
||
|
||
return ret;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
bSave = true;
|
||
|
||
fclose( fp );
|
||
}
|
||
else
|
||
bSave = true;
|
||
|
||
DebugPrint( "server: %s", urServer );
|
||
|
||
//获取版本信息
|
||
int num = 3, str_len;
|
||
char arrMap[3][2][MAX_STR_LEN] = { {"op", "getInfo"},
|
||
{"sid", ""},
|
||
{"ver", ""}};
|
||
|
||
sprintf( arrMap[1][1], "%d", SOFTWARE_ID );
|
||
sprintf( arrMap[2][1], "%d", m_version[0]*10000 + m_version[1]*100 + m_version[2] );
|
||
|
||
char strEncode[256];
|
||
int enc = PM_ParamEncode( strEncode, &str_len, arrMap, num );
|
||
|
||
DebugPrint( "ret=%d, str=%s", enc, strEncode );
|
||
|
||
char szReturn[2048];
|
||
int len = 2048;
|
||
int ret = 0;
|
||
|
||
THttpParam param;
|
||
strcpy( param.server, urServer );
|
||
param.sizeIn = str_len;
|
||
param.dataIn = strEncode;
|
||
param.sizeOut = len;
|
||
param.dataOut = szReturn;
|
||
strcpy( param.api, "Api" );
|
||
|
||
DWORD id;
|
||
HANDLE hThread = CreateThread( NULL, 0, HttpProc, ¶m, 0, &id );
|
||
if( hThread ){
|
||
DWORD dwRet = WaitForSingleObject( hThread, 10000 );
|
||
if( param.hRequest )
|
||
InternetCloseHandle( param.hRequest );
|
||
if( param.hConnect )
|
||
InternetCloseHandle( param.hConnect );
|
||
if( param.hSession )
|
||
InternetCloseHandle( param.hSession );
|
||
|
||
param.hSession = param.hConnect = param.hRequest = NULL;
|
||
|
||
WaitForSingleObject( hThread, 200 );
|
||
CloseHandle( hThread );
|
||
|
||
if( dwRet==WAIT_OBJECT_0 && param.errCode==0 ){ //线程正常退出
|
||
DebugPrint( "infoReturn %s", szReturn );
|
||
if(szReturn[0]=='\"' && szReturn[param.sizeOut-1]=='\"')
|
||
szReturn[param.sizeOut-1] = 0;
|
||
|
||
char* pos;
|
||
if( pos = strstr( szReturn, "err:" ) ){
|
||
int err;
|
||
sscanf( pos+4, "%d", &err );
|
||
ret = -4;
|
||
}
|
||
else if(strstr( szReturn, "flg" )){
|
||
char *tokenPtr=strtok(szReturn,"|");
|
||
while( tokenPtr ){
|
||
if( pos = strstr(tokenPtr, "flg") ){
|
||
int flg;
|
||
sscanf( pos+4, "%d", &flg );
|
||
|
||
if(flg==0)
|
||
return 2;
|
||
}
|
||
else if( pos = strstr(tokenPtr, "ver") ){
|
||
int ver;
|
||
sscanf( pos+4, "%d", &ver );
|
||
|
||
WORD major = ver / 10000,
|
||
minor = (ver % 10000) / 100,
|
||
release = ver % 100;
|
||
|
||
if(major>m_version[0] || major==m_version[0] && minor>m_version[1])
|
||
ret = 4;
|
||
else if(major==m_version[0] && minor==m_version[1] && release>m_version[2])
|
||
ret = 1;
|
||
}
|
||
tokenPtr=strtok(NULL,"|");
|
||
}
|
||
}
|
||
}
|
||
else
|
||
ret = -3;
|
||
}
|
||
else
|
||
ret = -3;
|
||
|
||
//写入配置文件
|
||
if( bSave ){
|
||
fp = fopen( szFile, "wb" );
|
||
if( fp ){
|
||
szBuffer[0] = 0;
|
||
|
||
TGVFHEADER header;
|
||
header.iUpdate = iUpdate;
|
||
fwrite( (void*)&header, sizeof(header), 1, fp );
|
||
|
||
sprintf(szBuffer, "srv=%s", urServer);
|
||
fwrite( szBuffer, 1, strlen(szBuffer)+1, fp );
|
||
fclose( fp );
|
||
}
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
int __fastcall TMainForm::TryUpdate()
|
||
{
|
||
//处理只更新Upgrade.exe的情况
|
||
TSearchRec sr;
|
||
int iAttr = 0;
|
||
|
||
int ret = 0;
|
||
String strPath = g_AppPath;
|
||
strPath += L"upgrade\\";
|
||
|
||
if( FindFirst(strPath + L"*.*", iAttr, sr)==0 ){
|
||
do{
|
||
if( !(iAttr & faDirectory) && sr.Name.CompareIC(UPDATE_APP_NAME)
|
||
&& sr.Name.CompareIC(MD5_FILE_NAME) ){
|
||
ret = 3;
|
||
break;
|
||
}
|
||
}
|
||
while( FindNext(sr)==0 );
|
||
|
||
FindClose(sr);
|
||
}
|
||
|
||
String fOld = strPath + UPDATE_APP_NAME;
|
||
if( FileExists( fOld, false ) ){
|
||
//等待进程关闭
|
||
HANDLE hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS,0 ); //获取进程快照
|
||
if( hSnapshot ){
|
||
DWORD idProcess = 0;
|
||
PROCESSENTRY32 pe32;
|
||
Process32First( hSnapshot, &pe32 ); //指向第一个进程
|
||
do{
|
||
if( lstrcmpi( pe32.szExeFile, _TEXT(UPDATE_APP_NAME) )==0 ){ //查找进程
|
||
idProcess = pe32.th32ProcessID;
|
||
break;
|
||
}
|
||
}
|
||
while( Process32Next(hSnapshot, &pe32) ); // 循环直到取不到进程
|
||
|
||
if( idProcess ){
|
||
HANDLE hApp= OpenProcess( PROCESS_ALL_ACCESS, FALSE, idProcess ); //根据进程ID获取程序的句柄
|
||
if( hApp ){
|
||
if( WaitForSingleObject( hApp, 2000 )==WAIT_TIMEOUT )// 等待程序关闭2秒
|
||
TerminateProcess( hApp, 0 );
|
||
|
||
CloseHandle( hApp );
|
||
}
|
||
}
|
||
|
||
CloseHandle( hSnapshot );
|
||
}
|
||
|
||
String fNew = (String)g_AppPath + UPDATE_APP_NAME;
|
||
if( !MoveFileEx( fOld.c_str(), fNew.c_str(), MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH ) )
|
||
ret = 1;
|
||
}
|
||
|
||
fOld = strPath + MD5_FILE_NAME;
|
||
if( FileExists( fOld, false ) ){
|
||
String fNew = (String)g_AppPath + MD5_FILE_NAME;
|
||
if( !MoveFileEx( fOld.c_str(), fNew.c_str(), MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH ) )
|
||
ret = 1;
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::DPTimerProc(TObject* Sender)
|
||
{
|
||
if(!m_bWebLogon || !m_dpThread)
|
||
return;
|
||
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TGame* pG = m_aTables[i]->m_pGame;
|
||
if(pG->gmstatus==1 && pG->timeout>0){
|
||
pG->timeout--;
|
||
if(pG->hTable) PostMessage(pG->hTable, UM_TAB_UPDATE, UPDATE_TIME, 0);
|
||
}
|
||
else if(pG->gmstatus==2 && pG->timeout<0){ //已下注开牌中
|
||
if(--pG->timeout<-60){ //开牌结算超时60s
|
||
DebugPrint("%s 超时", ((AnsiString)pG->vid).c_str());
|
||
pG->HandleResult( 2 );
|
||
}
|
||
}
|
||
}
|
||
|
||
if(g_bGameOn){
|
||
g_aGames.runTime++;
|
||
|
||
if(ChartForm)
|
||
PostMessage(ChartForm->Handle, UM_RUN_TIME, 0, 0);
|
||
}
|
||
|
||
bool bCheckDead = false;
|
||
if(m_tmDeadPause>0){
|
||
m_tmDeadPause--;
|
||
|
||
if(!m_tmDeadPause){
|
||
if(g_aGames.nBetted[2]>0){ //强制超时
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TGame* pG = m_aTables[i]->m_pGame;
|
||
if(pG->iState==ST_BETTED && !pG->bIndPolicy)
|
||
pG->HandleResult( 2 );
|
||
}
|
||
}
|
||
|
||
if(g_aGames.pRankChip && !g_aGames.bFloat) //全局计算注码爆缆重启
|
||
g_aGames.ResetRankChip();
|
||
|
||
g_bDeadPause = false;
|
||
bCheckDead = true;
|
||
}
|
||
}
|
||
|
||
bool bCheckBet = false;
|
||
if(m_tmBetPause>0){
|
||
m_tmBetPause--;
|
||
|
||
bool bBetted = g_aGames.nBetted[0]>0 || g_aGames.nBetted[1]>0;
|
||
if(!m_tmBetPause && bBetted){ //强制超时
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TGame* pG = m_aTables[i]->m_pGame;
|
||
if(pG->iState==ST_BETTED)
|
||
pG->HandleResult( 2 );
|
||
}
|
||
|
||
bBetted = false;
|
||
}
|
||
|
||
if(!bBetted && (g_aGames.betData.profits[3]!=0 //结算完成,重置当期赢利
|
||
|| g_aGames.fCurrProfitPeak!=0)){ //双重判定,避免当期赢利恰好为0的情况
|
||
g_aGames.betData.profits[3] = g_aGames.fCurrProfitPeak = 0;
|
||
m_frmInfo->m_lblCurProfit->Caption = "0";
|
||
m_frmInfo->m_lblCurProfit->Font->Color = clLime;
|
||
|
||
TBetLog* pLog = new TBetLog;
|
||
pLog->ts = DateTimeToUnix(Now(), false);
|
||
pLog->ev = LOGEVT_RESET;
|
||
pLog->op = 0;
|
||
SendMessage(Handle, UM_LOG_UPDATE, 0, (long)pLog);
|
||
|
||
if(g_aGames.pRankChip && !g_aGames.bFloat) //全局计算注码止停重启
|
||
g_aGames.ResetRankChip();
|
||
}
|
||
|
||
if(!m_tmBetPause){
|
||
g_bBetPause = false;
|
||
bCheckBet = true;
|
||
}
|
||
}
|
||
|
||
if(bCheckDead && g_bGameOn && !m_tmBetPause){
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
TGame* pG = pT->m_pGame;
|
||
|
||
if(pG->bRun && !pG->bIndPolicy)
|
||
pG->AutoBetOn(true);
|
||
}
|
||
}
|
||
|
||
if(bCheckBet && g_bGameOn){
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
TGame* pG = pT->m_pGame;
|
||
|
||
if(!m_tmDeadPause && !bCheckDead || pG->bIndPolicy)
|
||
pG->AutoBetOn(true);
|
||
}
|
||
}
|
||
|
||
m_tmWebFocus++;
|
||
if(m_tmWebFocus==590){ //9分50秒设为前台10秒,保活
|
||
m_chrm->WasHidden(false);
|
||
m_chrm->SetFocus(true);
|
||
}
|
||
else if(m_tmWebFocus==600){
|
||
m_tmWebFocus = 0;
|
||
m_chrm->SetFocus(false);
|
||
m_chrm->WasHidden(true);
|
||
}
|
||
|
||
if(g_iPlatform!=PF_AB){
|
||
if(g_tmIdle<600){ //软件10分钟无操作,以此判断是否待机状态
|
||
g_tmIdle++;
|
||
|
||
if(g_tmIdle==600)
|
||
m_chrm->ExecuteJavaScript("tmRetry=300;console.log('tmRetry:',tmRetry);", "", 0);
|
||
}
|
||
|
||
m_chrm->ExecuteJavaScript("chkSockets();", "", 0); //检查网络状态
|
||
}
|
||
|
||
if(m_tmCount>0){
|
||
m_tmCount++;
|
||
if((m_tmCount % 3600)==0){ //每小时修正计时
|
||
m_tmCount = GetTimeCount();
|
||
}
|
||
else if(m_tmCount==m_tmDailyReport){ //每日结算上报
|
||
RBReport();
|
||
}
|
||
else if(m_tmCount==m_tmDailyLogin){ //每日登录获取授权信息
|
||
PostMessage(Handle, UM_USERCONFIRM, UR_LOGIN, 0 );
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UtilTimerProc(TObject* Sender)
|
||
{
|
||
TTimer* pT = m_pUtilTimer;
|
||
pT->Enabled = false;
|
||
|
||
if(pT->Tag==-1){
|
||
ClearUtilTimer();
|
||
PostMessage( Handle, UM_CHECKCEF, 0, 0 );
|
||
}
|
||
else if(pT->Tag==0){
|
||
m_tmWebFocus = 0;
|
||
m_chrm->ExecuteJavaScript(goLinkJS_PA, "", 0);//尝试进多台
|
||
pT->Enabled = true;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::RunTimerProc(TObject* Sender)
|
||
{
|
||
m_tmRunTime += 60;
|
||
|
||
int d = m_tmRunTime / 86400,
|
||
r = m_tmRunTime - d * 86400,
|
||
h, m;
|
||
h = r / 3600, r -= h * 3600;
|
||
m = r / 60, r -= m * 60;
|
||
|
||
m_lblRunTime->Caption = Format(String("运行时间 %d 天 %d 时 %d 分"), ARRAYOFCONST((d, h, m)));
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnWSConnectError()
|
||
{
|
||
GameOff();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::GameOn()
|
||
{
|
||
if(!g_bGameOn){
|
||
m_btnStart->Enabled = false;
|
||
m_btnStart->Caption = "停止挂机";
|
||
|
||
TBetLog* pLog = new TBetLog;
|
||
pLog->ts = DateTimeToUnix(Now(), false);
|
||
pLog->ev = LOGEVT_START;
|
||
SendMessage(Handle, UM_LOG_UPDATE, 0, (long)pLog);
|
||
|
||
g_bGameOn = true;
|
||
g_bBetPause = false;
|
||
g_bDeadPause = false;
|
||
m_tmBetPause = 0;
|
||
m_tmDeadPause = 0;
|
||
|
||
//初始化图表数据
|
||
TDot dot;
|
||
if(g_aDots[0].empty()){
|
||
double pro = g_aGames.betData.profits[0];
|
||
dot.val = pro<0 ? pro - 0.5 : pro + 0.5;
|
||
g_aDots[0].push_back(dot);
|
||
}
|
||
if(g_aDots[1].empty()){
|
||
dot.val = g_settings.fSimAcc + 0.5;
|
||
g_aDots[1].push_back(dot);
|
||
}
|
||
if(g_aDots[2].empty()){
|
||
dot.val = g_fBalance + 0.5;
|
||
g_aDots[2].push_back(dot);
|
||
}
|
||
if(g_aDots[3].empty()){
|
||
dot.val = g_aGames.betData.counts[0] - g_aGames.betData.counts[1];
|
||
g_aDots[3].push_back(dot);
|
||
}
|
||
|
||
if(g_settings.bInitCurProfitByStart){//重置当期赢利
|
||
m_frmInfo->m_lblCurProfit->Caption = "0";
|
||
m_frmInfo->m_lblCurProfit->Font->Color = clLime;
|
||
m_frmInfo->m_lblSRProfit->Caption = "0";
|
||
m_frmInfo->m_lblSRProfit->Font->Color = clYellow;
|
||
}
|
||
|
||
g_aGames.GameOn();
|
||
|
||
StartJSThread( JS_OP_GAMEON );
|
||
|
||
m_btnStart->Enabled = true;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::GameOff(int iReason)
|
||
{
|
||
if( g_bGameOn ){
|
||
m_btnStart->Enabled = false;
|
||
|
||
g_bGameOn = false;
|
||
|
||
ClearJSThread();
|
||
ClearABThread();
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
pT->m_pGame->GameOff();
|
||
}
|
||
|
||
g_aGames.GameOff();
|
||
|
||
TBetLog* pLog = new TBetLog;
|
||
pLog->ts = DateTimeToUnix(Now(), false);
|
||
pLog->ev = LOGEVT_END;
|
||
pLog->op = iReason;
|
||
SendMessage(Handle, UM_LOG_UPDATE, 0, (long)pLog);
|
||
|
||
m_btnStart->Caption = "开始挂机";
|
||
m_btnStart->Enabled = true;
|
||
|
||
if(iReason>0){
|
||
String msg;
|
||
if(iReason==1)
|
||
msg = "总体止赢";
|
||
else if(iReason==2)
|
||
msg = "总体止损";
|
||
else if(iReason==3)
|
||
msg = "模拟本金低于限红";
|
||
else if(iReason==4)
|
||
msg = "游台爆缆";
|
||
else if(iReason==5)
|
||
msg = "账户止赢";
|
||
else if(iReason==6)
|
||
msg = "账户止损";
|
||
else if(iReason==7)
|
||
msg = "动态止损";
|
||
else if(iReason==8)
|
||
msg = "总体阶梯爆缆";
|
||
|
||
msg += ",停止挂机!";
|
||
ShowMessage(msg);
|
||
}
|
||
|
||
RBReport();
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::FileUserWeb( bool bSave )
|
||
{
|
||
char szFile[256];
|
||
sprintf( szFile, "%suser\\%s", g_AppPath, USER_WEB_FILE );
|
||
FILE* fp = bSave ? fopen( szFile, "wb" ) : fopen( szFile, "rb" );
|
||
|
||
if( fp ){
|
||
TUWFHEADER header, rHeader;
|
||
TUWFDATA data;
|
||
int len;
|
||
|
||
if( bSave ){
|
||
fwrite( &header, sizeof(header), 1, fp );
|
||
|
||
if(g_iPlatform==PF_PA || g_iPlatform==PF_DB)
|
||
sprintf(data.id, ((AnsiString)m_loginValues[0]).c_str() );
|
||
|
||
if(g_iPlatform==PF_PA){
|
||
sprintf(data.li, ((AnsiString)m_loginValues[1]).c_str() );
|
||
sprintf(data.gt, ((AnsiString)m_loginValues[2]).c_str() );
|
||
sprintf(data.un, ((AnsiString)m_loginValues[3]).c_str() );
|
||
sprintf(data.dm, ((AnsiString)m_loginValues[4]).c_str() );
|
||
sprintf(data.fw, ((AnsiString)m_loginValues[5]).c_str() );
|
||
}
|
||
|
||
sprintf(data.url, ((AnsiString)m_url).c_str() );
|
||
|
||
fwrite( &data, sizeof(data), 1, fp );
|
||
}
|
||
else{
|
||
int ret = fread( (void*)&rHeader, 1, sizeof(header), fp );
|
||
if( ret==sizeof(header) && !memcmp(&rHeader, header.head, sizeof(header.head)) ){
|
||
fread( &data, sizeof(TUWFDATA), 1, fp );
|
||
|
||
m_loginValues[0] = data.id;
|
||
m_loginValues[1] = data.li;
|
||
m_loginValues[2] = data.gt;
|
||
m_loginValues[3] = data.un;
|
||
m_loginValues[4] = data.dm;
|
||
m_loginValues[5] = data.fw;
|
||
m_url = data.url;
|
||
}
|
||
}
|
||
|
||
fclose( fp );
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::FileUserVars( bool bSave )
|
||
{
|
||
char szBuffer[2048] = "",
|
||
szFile[256];
|
||
|
||
sprintf( szFile, "%suser\\%s", g_AppPath, USER_VAR_FILE );
|
||
FILE* fp;
|
||
|
||
if( bSave )
|
||
fp = fopen( szFile, "wb" );
|
||
else
|
||
fp = fopen( szFile, "rb" );
|
||
|
||
if( fp ){
|
||
TUVFHEADER header;
|
||
int val;
|
||
|
||
if( bSave ){
|
||
fwrite( (void*)&header, sizeof(header), 1, fp );
|
||
|
||
szBuffer[0] = 0;
|
||
|
||
char temp[64];
|
||
|
||
sprintf( temp, "%d", g_bAutoLogin );
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d", g_iRoad );
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d", g_iBetPolicy );
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d", g_iChipPolicy );
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d", g_nChipMul );
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d", m_nTabShow );
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d", m_nTabRun );
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d", g_bSimulate );
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d", g_bShowSetting );
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d-%d", g_RandomChip.minChip, g_RandomChip.maxChip);
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d", g_BPAskBet.bet[0] | (g_BPAskBet.bet[1]<<8));
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d %s %s", g_BPDiffBet.diff[0] | (g_BPDiffBet.diff[1]<<8),
|
||
g_BPDiffBet.bets[0], g_BPDiffBet.bets[1]);
|
||
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d", m_iWSVelo );
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d", g_iPlatform );
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d", WindowState==wsMinimized ? wsNormal : WindowState );
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%d %d %d %d", m_nLeft, m_nTop, m_nWidth, m_nHeight);
|
||
strcat( szBuffer, temp );
|
||
|
||
sprintf( temp, "\n%s", ((AnsiString)m_sActCode).c_str());
|
||
strcat( szBuffer, temp);
|
||
|
||
fwrite( szBuffer, 1, strlen(szBuffer), fp );
|
||
}
|
||
else{
|
||
char buf[16];
|
||
int ret = fread( (void*)buf, 1, sizeof(header), fp );
|
||
|
||
if( ret==sizeof(header) && !memcmp(buf, &header, 3) ){
|
||
fseek( fp, 0, SEEK_END );
|
||
int size = ftell( fp ) - sizeof(header);
|
||
if( size>2048 )
|
||
size = 2048;
|
||
|
||
fseek( fp, sizeof(header), SEEK_SET );
|
||
fread( szBuffer, 1, size, fp );
|
||
|
||
int nVal = 0;
|
||
char *token=strtok(szBuffer,"\n");
|
||
if( token ){
|
||
sscanf( token, "%d", &val );
|
||
g_bAutoLogin = val;
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
sscanf( token, "%d", &val );
|
||
m_cbRoad->ItemIndex = g_iRoad = val;
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
sscanf( token, "%d", &val );
|
||
g_iBetPolicy = val;
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
sscanf( token, "%d", &val );
|
||
g_iChipPolicy = val;
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
sscanf( token, "%d", &val );
|
||
g_nChipMul = val;
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
sscanf( token, "%d", &val );
|
||
m_nTabShow = val;
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
sscanf( token, "%d", &val );
|
||
m_nTabRun = val;
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
sscanf( token, "%d", &val );
|
||
g_bSimulate = val;
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
sscanf( token, "%d", &val );
|
||
g_bShowSetting = val;
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
int mi, ma;
|
||
sscanf( token, "%d-%d", &mi, &ma );
|
||
g_RandomChip.minChip = mi;
|
||
g_RandomChip.maxChip = ma;
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
int bets;
|
||
sscanf( token, "%d", &bets );
|
||
g_BPAskBet.bet[0] = bets & 0xFF;
|
||
g_BPAskBet.bet[1] = (bets & 0xFF00) >> 8;
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
if(buf[3]<2){
|
||
int data;
|
||
sscanf( token, "%d", &data );
|
||
g_BPDiffBet.diff[0] = data & 0xFF;
|
||
g_BPDiffBet.diff[1] = (data & 0xFF00) >> 8;
|
||
|
||
int bet[2] = { (data & 0xFF0000) >> 16, (data & 0xFF000000) >> 24};
|
||
for(int i=0; i<2; i++)
|
||
strcpy(g_BPDiffBet.bets[i], bet[i]==1 ? "a" : "s");
|
||
}
|
||
else{
|
||
int cond;
|
||
sscanf( token, "%d %s %s", &cond, g_BPDiffBet.bets[0], g_BPDiffBet.bets[1] );
|
||
g_BPDiffBet.diff[0] = cond & 0xFF;
|
||
g_BPDiffBet.diff[1] = (cond & 0xFF00) >> 8;
|
||
}
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
sscanf( token, "%d", &val );
|
||
m_iWS = m_iWSVelo = val;
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
sscanf( token, "%d", &val );
|
||
g_iPlatform = val;
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
sscanf( token, "%d", &val );
|
||
WindowState = val;
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
sscanf( token, "%d %d %d %d", &m_nLeft, &m_nTop, &m_nWidth, &m_nHeight );
|
||
Position = poDesigned;
|
||
SetBounds(m_nLeft, m_nTop, m_nWidth, m_nHeight);
|
||
}
|
||
|
||
token=strtok(NULL,"\n");
|
||
if( token ){
|
||
char temp[64];
|
||
sscanf( token, "%s", temp );
|
||
m_sActCode = temp;
|
||
}
|
||
}
|
||
}
|
||
|
||
fclose( fp );
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::FileGame( bool bSave )
|
||
{
|
||
char szFile[256];
|
||
sprintf( szFile, "%suser\\%s", g_AppPath, USER_GAME_FILE );
|
||
FILE* fp = NULL;
|
||
|
||
if( bSave )
|
||
fp = fopen( szFile, "wb" );
|
||
else
|
||
fp = fopen( szFile, "rb" );
|
||
|
||
if( fp ){
|
||
TUGFHEADER header;
|
||
|
||
if( bSave ){
|
||
fseek( fp, 0, SEEK_SET );
|
||
fwrite( (void*)&header, sizeof(header), 1, fp );
|
||
|
||
fwrite( &g_settings, sizeof(TSettings), 1, fp );
|
||
fwrite( &g_aGames.betData, sizeof(TBetData), 1, fp);
|
||
int sz = g_aIPGames.size();
|
||
fwrite( &sz, sizeof(int), 1, fp);
|
||
if(sz>0){
|
||
char vid[8];
|
||
for(int i=0; i<sz; i++){
|
||
TIPGame* pIG = g_aIPGames[i];
|
||
strcpy(vid, ((AnsiString)pIG->vid).c_str());
|
||
fwrite(vid, sizeof(vid), 1, fp);
|
||
fwrite(&pIG->iBetPolicy, sizeof(int), 1, fp);
|
||
fwrite(&pIG->iChipPolicy, sizeof(int), 1, fp);
|
||
fwrite(&pIG->nChipMul, sizeof(int), 1, fp);
|
||
}
|
||
}
|
||
}
|
||
else{
|
||
char buf[16];
|
||
int ret = fread( (void*)buf, 1, sizeof(header), fp );
|
||
|
||
if( ret==sizeof(header) && !memcmp(buf, &header, 3)){
|
||
TUGFHEADER* fHeader = (TUGFHEADER*)buf;
|
||
|
||
if(fHeader->head[3]>=0x0E){
|
||
fread( &g_settings, sizeof(TSettings), 1, fp );
|
||
}
|
||
else if(fHeader->head[3]>=0x0C){ //最低支持ver0C
|
||
TSettingsD d;
|
||
fread( &d, sizeof(TSettingsD), 1, fp );
|
||
|
||
if(fHeader->head[3]==0x0C){
|
||
if(d.iFloatMode==3)
|
||
d.iFloatMode = 4;
|
||
}
|
||
|
||
if(d.bFloat){
|
||
if(d.iFloatMode)
|
||
d.iFloatMode <<= 1;
|
||
else
|
||
d.iFloatMode = 1;
|
||
}
|
||
|
||
g_settings.FromVersionD(d);
|
||
}
|
||
else
|
||
goto FILEGAME_EXIT_LINE;
|
||
|
||
fread( &g_aGames.betData, sizeof(TBetData), 1, fp);
|
||
|
||
if(fHeader->head[3]>=0x0F){
|
||
int sz;
|
||
fread(&sz, sizeof(int), 1, fp);
|
||
if(sz>0){
|
||
char vid[8];
|
||
for(int i=0; i<sz; i++){
|
||
int iB, iC, nM;
|
||
fread(vid, sizeof(vid), 1, fp);
|
||
fread(&iB, sizeof(int), 1, fp);
|
||
fread(&iC, sizeof(int), 1, fp);
|
||
fread(&nM, sizeof(int), 1, fp);
|
||
|
||
if(iB<g_aBetPolicies.size() && iC<g_aChipPolicies.size())
|
||
g_aIPGames.AddIPGame(vid, iB, iC, nM);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
FILEGAME_EXIT_LINE:
|
||
fclose( fp );
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ChangeWebsite()
|
||
{
|
||
m_chrm->StopLoad();
|
||
m_chrm->LoadURL("about:blank");
|
||
|
||
m_iWS = (m_iWS+1) % WSNUM;
|
||
if(m_iWS==m_iWSVelo){
|
||
PostMessage( Handle, UM_WEBDEAD, -3, 0 );
|
||
}
|
||
else{
|
||
DebugPrint( "Change website: %s", websites[m_iWS] );
|
||
m_chrm->LoadURL(websites[m_iWS]);
|
||
}
|
||
}
|
||
|
||
/////////////////////////////////////////////////////////////////////////////
|
||
// DCEF3
|
||
void __fastcall TMainForm::WebAfterCreated(TObject *Sender, const _di_ICefBrowser browser)
|
||
{
|
||
if( m_bClosing )
|
||
return;
|
||
|
||
// if(Sender==m_chrmCode){
|
||
// m_chrmCode->LoadURL("about:blank");
|
||
// }
|
||
// else
|
||
if(g_bAutoLogin && (g_iPlatform==PF_AB && !m_url.IsEmpty()
|
||
|| g_iPlatform==PF_DB && !m_url.IsEmpty() && !m_loginValues[0].IsEmpty()
|
||
|| g_iPlatform==PF_PA && m_iWS>=0 && !m_loginValues[1].IsEmpty())){
|
||
LoadUrl();
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WebBeforeClose(TObject* Sender, const _di_ICefBrowser browser)
|
||
{
|
||
if( m_bClosing ){
|
||
if(Sender==m_chrm)
|
||
m_bChrmClosed = true;
|
||
else if(Sender==m_chrmCode)
|
||
m_bChrmCodeClosed = true;
|
||
|
||
PostMessage( Handle, WM_CLOSE, 0, 0 );
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WebBeforeContextMenu(TObject* Sender, const _di_ICefBrowser browser,
|
||
const _di_ICefFrame frame, const _di_ICefContextMenuParams params,
|
||
const _di_ICefMenuModel model)
|
||
{
|
||
model->Clear();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WebBeforePopup(TObject* Sender, const _di_ICefBrowser browser, const _di_ICefFrame frame,
|
||
int popup_id, const ustring targetUrl, const ustring targetFrameName,
|
||
TCefWindowOpenDisposition targetDisposition, bool userGesture, const TCefPopupFeatures &popupFeatures,
|
||
TCefWindowInfo &windowInfo, _di_ICefClient &client, TCefBrowserSettings &settings,
|
||
_di_ICefDictionaryValue &extra_info, bool &noJavascriptAccess, bool &Result)
|
||
{
|
||
Result = true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WebJsdialog(TObject* Sender, const _di_ICefBrowser browser, const ustring originUrl,
|
||
TCefJsDialogType dialogType, const ustring messageText, const ustring defaultPromptText,
|
||
_di_ICefJsDialogCallback callback, bool &suppressMessage, bool &Result)
|
||
{
|
||
if(Sender==m_chrm && g_iPlatform==PF_AB && dialogType==JSDIALOGTYPE_ALERT){
|
||
DebugPrint("Alert %s - %s", ((AnsiString)messageText).c_str(), ((AnsiString)originUrl).c_str());
|
||
PostMessage( Handle, UM_WEBDEAD, 3, 0 );
|
||
m_lblTips->Visible = false;
|
||
}
|
||
|
||
suppressMessage = true;
|
||
Result = false;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WebLoadError(TObject* Sender, const _di_ICefBrowser browser, const _di_ICefFrame frame,
|
||
TCefErrorCode errorCode, const ustring errorText, const ustring failedUrl)
|
||
{
|
||
if( m_bClosing )
|
||
return;
|
||
|
||
if( !m_bWebLogon ){
|
||
if(g_iPlatform==PF_PA && failedUrl.Pos(websites[m_iWS])>0 && failedUrl.Length()-strlen(websites[m_iWS]) <= 9){
|
||
ChangeWebsite();
|
||
}
|
||
else if(g_iPlatform==PF_AB){
|
||
DebugPrint("load error %s (%s[%d])", ((AnsiString)failedUrl).c_str(), ((AnsiString)errorText).c_str(), errorCode);
|
||
if(failedUrl.Pos(m_url)>0){
|
||
PostMessage( Handle, UM_WEBDEAD, 3, 0 );
|
||
m_lblTips->Visible = false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WebLoadEnd(TObject* Sender, const _di_ICefBrowser browser,
|
||
const _di_ICefFrame frame, int httpStatusCode)
|
||
{
|
||
if( m_bClosing )
|
||
return;
|
||
|
||
if( httpStatusCode==200 ){
|
||
String url = frame->GetUrl();
|
||
if(g_iPlatform==PF_PA && m_iWS>=0 && url.Pos(websites[m_iWS]) && url.Length()-strlen(websites[m_iWS]) <= 9 ){
|
||
if(m_loginValues[0].Length()>0){
|
||
m_lblTips->Caption = "正在登录网站...";
|
||
m_lblTips->Visible = true;
|
||
|
||
String strJS = Format(loginJS_PA, ARRAYOFCONST((m_loginValues[0],m_loginValues[1],m_loginValues[2],
|
||
m_loginValues[3],m_loginValues[4],m_loginValues[5])));
|
||
m_chrm->ExecuteJavaScript(strJS, "", 0);
|
||
}
|
||
}
|
||
else if(url.Pos(m_url)){
|
||
m_lblTips->Caption = "正在连接网站...";
|
||
m_lblTips->Visible = true;
|
||
|
||
if(g_iPlatform==PF_DB){
|
||
StartJSThread( JS_OP_WSHANDLE0 );
|
||
|
||
if(m_loginValues[0].Length()>0){
|
||
String strJS = Format(loginJS_DB, ARRAYOFCONST((m_loginValues[0])));
|
||
m_chrm->ExecuteJavaScript(strJS, "", 0);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WebResourceLoadComplete(TObject* Sender, const _di_ICefBrowser browser,
|
||
const _di_ICefFrame frame, const _di_ICefRequest request, const _di_ICefResponse response,
|
||
TCefUrlRequestStatus status, __int64 receivedContentLength)
|
||
{
|
||
if( m_bClosing )
|
||
return;
|
||
|
||
String url = request->GetUrl();
|
||
TCefResourceType type = request->GetResourceType();
|
||
DebugPrint("load %s", ((AnsiString)url).c_str());
|
||
if( type==RT_XHR && status==UR_SUCCESS ){
|
||
// DebugPrint("load %s", ((AnsiString)url).c_str());
|
||
if( g_iPlatform==PF_PA ){
|
||
if( url.Pos("module.config") ){
|
||
m_lblTips->Caption = "加载网站资源...";
|
||
}
|
||
else if(url.Pos("main_") && url.Pos(".min.js")){
|
||
m_lblTips->Caption = "加载主程序...";
|
||
StartJSThread( JS_OP_WSHANDLE0 );
|
||
}
|
||
else if( url.Pos("GameCommon_v") || url.Pos("PCPlaza_v") ){
|
||
m_lblTips->Caption = "加载游戏资源...";
|
||
StartJSThread( JS_OP_WSHANDLE1 );
|
||
}
|
||
else if( url.Pos("PCPlaza_hans") || url.Pos("PCEvent_hans") ){
|
||
m_lblTips->Caption = "加载基础数据...";
|
||
StartJSThread( JS_OP_WSHANDLE2 );
|
||
}
|
||
}
|
||
else if( g_iPlatform==PF_AB ){
|
||
if( url.Pos("loadConfig.json") ){
|
||
StartJSThread( JS_OP_WSHANDLE0 );
|
||
}
|
||
else if(url.Pos("netGame.ab") || url.Pos("system-a") && url.Pos("-v9.json")){
|
||
m_lblTips->Caption = "加载网站资源...";
|
||
if(!m_bWebLogon)
|
||
StartJSThread( JS_OP_WSHANDLE1 );
|
||
|
||
m_chrm->ExecuteJavaScript(msgJS_AB, "", 0 );
|
||
}
|
||
else if( url.Pos("lang.json") || url.Pos("sideHall.atlas") ){
|
||
m_lblTips->Caption = "正在登录游戏...";
|
||
if(!m_bWebLogon)
|
||
StartJSThread( JS_OP_WSHANDLE2 );
|
||
}
|
||
}
|
||
else if( g_iPlatform==PF_DB ){
|
||
if( url.Pos("loadConfig/list?") ){
|
||
m_lblTips->Caption = "加载网站资源...";
|
||
// StartJSThread( JS_OP_WSHANDLE1 );
|
||
}
|
||
else if( url.Pos("player/getPlayerInitConfig") ){
|
||
m_lblTips->Caption = "正在登录游戏...";
|
||
StartJSThread( JS_OP_WSHANDLE2 );
|
||
|
||
m_chrm->ExecuteJavaScript( userJS_DB, "", 0 );
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WebBeforeResourceLoad(TObject* Sender, const _di_ICefBrowser browser, const _di_ICefFrame frame,
|
||
const _di_ICefRequest request, const _di_ICefCallback callback, /* out */ TCefReturnValue &Result)
|
||
{
|
||
if( m_bClosing )
|
||
return;
|
||
|
||
if( g_iPlatform==PF_PA ){
|
||
String url = request->GetUrl();
|
||
if((url.Pos("region.html") || url.Pos("ipwho.is")) && url.Pos(websites[m_iWS])){
|
||
ChangeWebsite();
|
||
Result = RV_CANCEL;
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WebProcessMessageReceived(TObject* Sender, const _di_ICefBrowser browser,
|
||
const _di_ICefFrame frame, TCefProcessId sourceProcess, const _di_ICefProcessMessage message,
|
||
/* out */ bool &Result)
|
||
{
|
||
if( m_bClosing )
|
||
return;
|
||
|
||
if( message->Name=="ReturnJQValue" ){
|
||
_di_ICefListValue argList = message->GetArgumentList();
|
||
TStringList* values = Sender==m_chrmCode ? m_v8CodeValues : m_v8Values;
|
||
|
||
for( int i=0; i<argList->GetSize(); i++ ){
|
||
values->Append( argList->GetString(i) );
|
||
}
|
||
|
||
ReleaseV8ValueSema(Sender==m_chrmCode);
|
||
Result = true;
|
||
}
|
||
else if( message->Name=="GetUserInfo" ){
|
||
_di_ICefListValue argList = message->GetArgumentList();
|
||
|
||
if( argList->GetSize()==5 ){
|
||
String un = argList->GetString(0).Trim();
|
||
String balance = argList->GetString(1).Trim();
|
||
String currency = argList->GetString(2).Trim();
|
||
String betMin = argList->GetString(3).Trim();
|
||
String betMax = argList->GetString(4).Trim();
|
||
|
||
m_frmInfo->m_lblAccName->Caption = un;
|
||
|
||
m_tmCount = GetTimeCount();
|
||
|
||
if( g_iPlatform==PF_AB || g_iPlatform==PF_DB ){
|
||
ClearJSThread();
|
||
m_bWebLogon = true;
|
||
m_tmLogon = 0;
|
||
m_lblTips->Caption = "加载台桌数据...";
|
||
|
||
FileUserWeb( true );
|
||
|
||
if(g_iPlatform==PF_DB){
|
||
m_chrm->ExecuteJavaScript( msgJS_DB, "", 0 );
|
||
}
|
||
}
|
||
|
||
if(!g_uid){
|
||
PostMessage(Handle, UM_USERCONFIRM, UR_LOGIN, 0 );
|
||
}
|
||
else{
|
||
SetExpireJS();
|
||
}
|
||
|
||
double fBalance = balance.ToDouble();
|
||
if(!(g_bTesting && g_settings.bSimAccOn) && fBalance!=g_fBalance){
|
||
g_fBalance = fBalance;
|
||
|
||
PostMessage(Handle, UM_STATE_UPDATE, STATE_BALANCE, 0);
|
||
PostMessage(Application->MainFormHandle, UM_CHART_UPDATE, 2, 1); //重置余额图表
|
||
}
|
||
|
||
int minBet, maxBet;
|
||
if(TryStrToInt(betMin, minBet) && TryStrToInt(betMax, maxBet)){
|
||
if(minBet!=g_MinOnBet || maxBet!=g_MaxOnBet){
|
||
g_MinOnBet = minBet;
|
||
g_MaxOnBet = maxBet;
|
||
}
|
||
}
|
||
PostMessage(Handle, UM_STATE_UPDATE, STATE_LIMIT, 0);
|
||
}
|
||
Result = true;
|
||
}
|
||
else if( message->Name=="OnJSMessage" ){
|
||
_di_ICefListValue argList = message->GetArgumentList();
|
||
if( argList->GetSize()==1 ){
|
||
String sData = argList->GetString(0);
|
||
|
||
if(sData=="0"){
|
||
PostMessage( Handle, UM_WEBDEAD, -3, 0 );
|
||
m_lblTips->Visible = false;
|
||
}
|
||
else if( m_bWebLogon && m_dpThread ){
|
||
((TDataParseThread*)m_dpThread)->ParseData(sData);
|
||
}
|
||
}
|
||
|
||
Result = true;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ReleaseV8ValueSema(bool bCode)
|
||
{
|
||
HANDLE& hSema = bCode ? m_hV8CodeValueSema : m_hV8ValueSema;
|
||
|
||
if(!ReleaseSemaphore( hSema, 1, NULL)){
|
||
DebugPrint("V8ValueSema error: %d", GetLastError());
|
||
CloseHandle( hSema );
|
||
hSema = CreateSemaphore( NULL, 0, 1, NULL );
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
//bCode=false:游戏平台浏览器,JS分支必须返回ReturnJQValue且延迟不大于2秒
|
||
//bCode=true:代码策略执行通道,统一等待500ms(JS时限≤100ms);超时视为失败
|
||
TStringList* __fastcall TMainForm::GetJQValue( String& str, _di_ICefFrame frame, bool bCode )
|
||
{
|
||
HANDLE& hV8Sema = bCode ? m_hV8CodeSema : m_hV8Sema;
|
||
HANDLE& hV8ValueSema = bCode ? m_hV8CodeValueSema : m_hV8ValueSema;
|
||
TStringList* v8Values = bCode ? m_v8CodeValues : m_v8Values;
|
||
|
||
WaitForSingleObject( hV8Sema, INFINITE );//60000 );
|
||
|
||
v8Values->Clear();
|
||
frame->ExecuteJavaScript( str, "", 0 );
|
||
DWORD dwRet = WaitForSingleObject( hV8ValueSema, bCode ? 500 : 2000 );
|
||
|
||
TStringList* values = NULL;
|
||
if( dwRet==WAIT_OBJECT_0 ){
|
||
values = new TStringList;
|
||
for( int i=0; i<v8Values->Count; i++ ){
|
||
values->Append( v8Values->Strings[i] );
|
||
}
|
||
v8Values->Clear();
|
||
}
|
||
else if(dwRet==WAIT_TIMEOUT){
|
||
ReleaseV8ValueSema(bCode);
|
||
}
|
||
|
||
ReleaseSemaphore( hV8Sema, 1, NULL );
|
||
|
||
return values;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
//执行代码策略:拼装 prelude 与 context 后同步求值 code(bCode通道)
|
||
// kind SPE=calcBet(road,context) WCH=calcBetWithChip(road,chipMult,context)
|
||
// CSP=calcChip(result,chipMult,context)
|
||
// code 策略JS源码(TBasePolicy::code)
|
||
// prelude 声明当手输入变量的JS片段(如 "var road=[1,2,3]; var chipMult=10;")
|
||
// ctx 上一轮返回的context对象串(首次/中间状态失效为"{}"),原样透传
|
||
// ret 成功时填充:bet/chip/context 必须完整合法,blast 可选(缺失或写错=iBlast=0,不算失败)
|
||
//校验通过返回 true 并填充 ret;失败返回 false(执行失败=该台停止下注,不得降级)
|
||
bool __fastcall TMainForm::EvalJSCode(int kind, const String& sCode,
|
||
const String& sPrelude, const String& sCtx, TJSCodeRet& ret)
|
||
{
|
||
if( !m_chrmCode || !m_chrmCode->Browser || sCode.IsEmpty() || sPrelude.IsEmpty() ){
|
||
return false;
|
||
}
|
||
|
||
//默认值:未输出的可选字段保持 -1/0/空串(返回false时调用方忽略ret)
|
||
ret.iBet = -1;
|
||
ret.iChip = -1;
|
||
ret.iBlast = 0;
|
||
ret.iBlastMinutes = 0;
|
||
ret.sCtx = "";
|
||
|
||
TStringList* values = NULL;
|
||
TJSONValue* pRoot = NULL;
|
||
|
||
try{
|
||
String strJS = sPrelude + L" var context=" + (sCtx.Length() ? sCtx : String("{}") ) + L";" + sCode;
|
||
|
||
values = GetJQValue( strJS, m_chrmCode->Browser->MainFrame, true );
|
||
if( values && values->Count>0 && values->Strings[0].Length() ){
|
||
pRoot = TJSONObject::ParseJSONValue( values->Strings[0] );
|
||
}
|
||
}
|
||
catch(Exception &exception){
|
||
Application->ShowException(&exception);
|
||
}
|
||
|
||
if(values)
|
||
delete values;
|
||
|
||
if( !pRoot || !pRoot->InheritsFrom(__classid(TJSONObject)) ){ //必须为JSON对象
|
||
delete pRoot;
|
||
return false;
|
||
}
|
||
|
||
TJSONObject* pObj = (TJSONObject*)pRoot;
|
||
TJSONValue* v;
|
||
TJSONObject* ctx;
|
||
|
||
//必需key:类型、范围校验(原独立校验逻辑并入)
|
||
switch(kind){
|
||
case KIND_BET_SPE: //bet∈[0,4]:0=不打 1=庄 2=闲 3=和 4=局停
|
||
v = pObj->GetValue("bet");
|
||
if( !v || !v->InheritsFrom(__classid(TJSONNumber))
|
||
|| (int)((TJSONNumber*)v)->AsInt<0 || (int)((TJSONNumber*)v)->AsInt>4 )
|
||
goto FAIL;
|
||
ret.iBet = (int)((TJSONNumber*)v)->AsInt;
|
||
break;
|
||
|
||
case KIND_BET_WCH: //bet∈[0,4],chip≥0(基码个数)
|
||
v = pObj->GetValue("bet");
|
||
if( !v || !v->InheritsFrom(__classid(TJSONNumber))
|
||
|| (int)((TJSONNumber*)v)->AsInt<0 || (int)((TJSONNumber*)v)->AsInt>4 )
|
||
goto FAIL;
|
||
ret.iBet = (int)((TJSONNumber*)v)->AsInt;
|
||
|
||
v = pObj->GetValue("chip");
|
||
if( !v || !v->InheritsFrom(__classid(TJSONNumber))
|
||
|| (int)((TJSONNumber*)v)->AsInt<0 )
|
||
goto FAIL;
|
||
ret.iChip = (int)((TJSONNumber*)v)->AsInt;
|
||
break;
|
||
|
||
case KIND_CHIP_SPE: //chip≥0(基码个数)
|
||
v = pObj->GetValue("chip");
|
||
if( !v || !v->InheritsFrom(__classid(TJSONNumber))
|
||
|| (int)((TJSONNumber*)v)->AsInt<0 )
|
||
goto FAIL;
|
||
ret.iChip = (int)((TJSONNumber*)v)->AsInt;
|
||
break;
|
||
|
||
default: //未知策略类型
|
||
goto FAIL;
|
||
}
|
||
|
||
//context必须为对象,成功时原样序列化透传下一轮
|
||
ctx = (TJSONObject*)pObj->GetValue("context");
|
||
if( !ctx || !ctx->InheritsFrom(__classid(TJSONObject)) )
|
||
goto FAIL;
|
||
ret.sCtx = ctx->ToString();
|
||
|
||
//可选key:blast(爆缆动作),缺失或写错=0(爆缆不生效,不算失败)
|
||
v = pObj->GetValue("blast");
|
||
if( v && v->InheritsFrom(__classid(TJSONString)) ){
|
||
String s = ((TJSONString*)v)->Value();
|
||
if( s=="stop" )
|
||
ret.iBlast = 1;
|
||
else if( s=="shuffle" )
|
||
ret.iBlast = 2;
|
||
else if( s=="pause" ){ //仅pause读blastMinutes:0-15的数字,写错或缺失即整条爆缆不生效
|
||
TJSONValue* vm = pObj->GetValue("blastMinutes");
|
||
if( vm && vm->InheritsFrom(__classid(TJSONNumber)) ){
|
||
int m = (int)((TJSONNumber*)vm)->AsInt;
|
||
if( m>=0 && m<=15 ){
|
||
ret.iBlast = 3;
|
||
ret.iBlastMinutes = m;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
delete pRoot;
|
||
return true;
|
||
|
||
FAIL:
|
||
delete pRoot;
|
||
return false;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ResetTableGrid()
|
||
{
|
||
LockWindowUpdate( m_panWeb->Handle );
|
||
|
||
int oldPos = m_panWeb->VertScrollBar->Position;
|
||
|
||
//对齐台桌顶部
|
||
if(oldPos>0){
|
||
int nRem = oldPos % TFHEIGHT;
|
||
if(nRem>0){
|
||
if(nRem < DPIY(12))
|
||
oldPos -= nRem;
|
||
else if(TFHEIGHT-nRem < DPIY(12))
|
||
oldPos += TFHEIGHT-nRem;
|
||
}
|
||
}
|
||
|
||
m_panWeb->VertScrollBar->Position = 0; //Position复位,才从顶部开始显示
|
||
int row = 0, col = 0;
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
pT->Left = col * (TFWIDTH + m_nTabGap);
|
||
pT->Top = row * TFHEIGHT;
|
||
pT->Visible = true;
|
||
|
||
if(++col==m_nTabCols && i<m_aTables.size()-1){
|
||
col = 0;
|
||
row++;
|
||
}
|
||
}
|
||
|
||
if(m_aTables.empty()){
|
||
m_panWeb->VertScrollBar->Range = 0;
|
||
}
|
||
else{
|
||
int minRange = m_panWeb->Height-3;
|
||
int range = TFHEIGHT * (row+1);
|
||
int maxPos = range - minRange;
|
||
m_panWeb->VertScrollBar->Range = max(range, minRange);
|
||
|
||
if(oldPos>0){
|
||
m_panWeb->VertScrollBar->Position = oldPos<=maxPos ? oldPos //原始位置
|
||
: range - m_panWeb->Height + m_panWeb->Height % TFHEIGHT; //底部位置
|
||
}
|
||
}
|
||
|
||
LockWindowUpdate( 0 );
|
||
|
||
if(BetLogForm)
|
||
BetLogForm->BringToFront();
|
||
|
||
m_iLastSel = -1;
|
||
SetTableFocus();
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
bool __fastcall TMainForm::StopWebLoad()
|
||
{
|
||
if( g_iPlatform==PF_AB && m_url.IsEmpty()
|
||
|| g_iPlatform==PF_DB && m_url.IsEmpty() && m_loginValues[0].IsEmpty()
|
||
|| g_iPlatform==PF_PA && m_loginValues[1].IsEmpty())
|
||
return false;
|
||
|
||
m_pDPTimer->Enabled = false;
|
||
m_tsMode->Enabled = false;
|
||
m_btnStart->Enabled = false;
|
||
m_btnTables->Enabled = false;
|
||
m_btnManual->Enabled = false;
|
||
|
||
ClearJSThread();
|
||
ManualOff();
|
||
GameOff();
|
||
ClearGames();
|
||
|
||
m_chrm->StopLoad();
|
||
m_chrm->LoadURL("about:blank");
|
||
|
||
m_bWebLogon = false;
|
||
m_tmCount = 0;
|
||
|
||
g_uid = 0;
|
||
|
||
m_key = "";
|
||
if(AIForm)
|
||
AIForm->OnLogout();
|
||
|
||
if( g_iPlatform==PF_PA ){
|
||
m_loginValues[0] = m_loginValues[1] = m_loginValues[2]
|
||
= m_loginValues[3] = m_loginValues[4] = m_loginValues[5] = "";
|
||
}
|
||
else{
|
||
m_url = "";
|
||
|
||
if(g_iPlatform==PF_DB)
|
||
m_loginValues[0] = "";
|
||
}
|
||
|
||
m_lblTips->Caption = "请登录游戏";
|
||
m_lblTips->Show();
|
||
m_lblPlatform->Caption = "未登录";
|
||
|
||
return true;
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMRestoreWindow(TMessage &msg)
|
||
{
|
||
if (WindowState == wsMinimized) {
|
||
WindowState = wsNormal;
|
||
}
|
||
|
||
FormStyle = fsStayOnTop;
|
||
Application->BringToFront();
|
||
FormStyle = fsNormal;
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMWebDead(TMessage &msg)
|
||
{
|
||
if(!StopWebLoad())
|
||
return;
|
||
|
||
bool bActCode = false;
|
||
|
||
int reason = msg.WParam;
|
||
if(reason==0){
|
||
MessageBox(Handle, L"账号被重复登入,请重新登录", L"登录", MB_ICONERROR | MB_OK);
|
||
}
|
||
// else if(reason==2){
|
||
// MessageBox(Handle, L"网站资源加载失败,请重新登录", L"登录", MB_ICONERROR | MB_OK);
|
||
// }
|
||
else if(reason==3){
|
||
MessageBox(Handle, L"网站连接异常,请重新登录", L"登录", MB_ICONERROR | MB_OK);
|
||
}
|
||
else if(reason==-2){ //-2=授权验证已过期
|
||
if(m_sActCode.Length()){
|
||
MessageBox(Handle, L"授权码已过期,请延期或更换", L"授权", MB_ICONERROR | MB_OK);
|
||
bActCode = true;
|
||
}
|
||
else{
|
||
MessageBox(Handle, L"未授权账号或授权已过期,请重新登录", L"登录", MB_ICONERROR | MB_OK);
|
||
g_bAutoLogin = false;
|
||
}
|
||
}
|
||
else if(reason==-3){ //网络异常中断 -1=登录失败 3=连接关闭 4=连接失效
|
||
MessageBox(Handle, L"登录失败,请重新登录", L"登录", MB_ICONERROR | MB_OK);
|
||
}
|
||
else if(reason==-4){
|
||
if(m_sActCode.Length()){
|
||
MessageBox(Handle, L"授权码验证异常,请稍后重试", L"授权", MB_ICONERROR | MB_OK);
|
||
bActCode = true;
|
||
}
|
||
else
|
||
MessageBox(Handle, L"账号授权验证异常,请稍后重新登录", L"登录", MB_ICONERROR | MB_OK);
|
||
}
|
||
else{
|
||
MessageBox(Handle, L"网站登录超时,请重新登录", L"登录", MB_ICONERROR | MB_OK);
|
||
}
|
||
|
||
if(bActCode)
|
||
PostMessage( Handle, UM_SUBFORMSHOWN, 0, 0 );
|
||
else
|
||
PostMessage( Handle, UM_WEBLOGIN, g_iPlatform, 0 );
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMVelocity(TMessage &msg)
|
||
{
|
||
Screen->Cursor = crDefault;
|
||
|
||
ClearVLThread();
|
||
|
||
m_lblTips->Visible = false;
|
||
|
||
if((int)msg.WParam<0){
|
||
// m_iWSVelo = m_iWS = -1;
|
||
|
||
ShowMessage("网站无法连接,请检查网络状态");
|
||
return;
|
||
}
|
||
|
||
if(m_iWSVelo>=0)
|
||
m_iWS = m_iWSVelo;
|
||
else
|
||
m_iWS = m_iWSVelo = msg.WParam;
|
||
|
||
DebugPrint( "Current website: %s", websites[m_iWS] );
|
||
|
||
if(g_iPlatform==PF_PA && g_bAutoLogin && !m_loginValues[1].IsEmpty()
|
||
&& m_chrm && m_chrm->Initialized ){
|
||
LoadUrl();
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMCheckCEF(TMessage &msg)
|
||
{
|
||
StartJSThread( JS_OP_CHECKCEF );
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMStatus(TMessage &msg)
|
||
{
|
||
// m_sbar->SimpleText = m_strStatus;
|
||
// m_strStatus = "";
|
||
//
|
||
// if( msg.WParam >= 1 && msg.WParam <= 6 ){
|
||
// //保存当前下注及注码状态
|
||
// if( msg.WParam==1 || msg.WParam>=5 ){
|
||
// FileGame( true );
|
||
// }
|
||
//
|
||
// if( m_btnSound->Tag==0 || msg.WParam==4 ){ //播放提示音
|
||
// TCHAR snd[256];
|
||
// wsprintf( snd, L"%ssnd%d", ((String)g_AppPath).c_str(), msg.WParam );
|
||
//
|
||
// PlaySound( NULL, NULL, SND_NODEFAULT );
|
||
// PlaySound( snd, NULL, SND_ASYNC|SND_FILENAME|SND_NODEFAULT );
|
||
// }
|
||
// }
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMAutoBetEnd(TMessage &msg)
|
||
{
|
||
int hThread = msg.LParam;
|
||
ClearABThread(hThread);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMJsHandled(TMessage &msg)
|
||
{
|
||
if( !m_jsThread )
|
||
return;
|
||
|
||
int iOp = msg.WParam,
|
||
ret = msg.LParam;
|
||
String sRet = ((TJSHandleThread*)m_jsThread)->m_sRet;
|
||
|
||
ClearJSThread();
|
||
|
||
if( iOp==JS_OP_CHECKCEF ){
|
||
if( ret>=0 ){
|
||
InitBrowser(true); //初始化代码执行浏览器
|
||
|
||
FileUserWeb();
|
||
// InitBrowser(); //初始化游戏平台浏览器
|
||
m_lblTips->Caption = "请登录游戏";
|
||
|
||
if(m_sActCode.Length())
|
||
PostMessage(Handle, UM_USERCONFIRM, UR_LOGIN, 0 );
|
||
}
|
||
}
|
||
else if( iOp>=JS_OP_WSHANDLE0 && iOp<=JS_OP_WSHANDLE3 ){
|
||
if( ret==1 ){
|
||
DebugPrint( "Got ws update data" );
|
||
|
||
if( g_iPlatform==PF_PA ){
|
||
m_bWebLogon = true;
|
||
m_iWSVelo = m_iWS;
|
||
|
||
m_lblTips->Caption = "加载台桌数据...";
|
||
m_lblTips->Visible = true;
|
||
|
||
m_chrm->ExecuteJavaScript( baseJS_PA, "", 0 );
|
||
m_chrm->ExecuteJavaScript( enterJS_PA, "", 0 );
|
||
m_chrm->ExecuteJavaScript( linkJS_PA, "", 0 );
|
||
|
||
FileUserWeb( true );
|
||
}
|
||
}
|
||
else{
|
||
PostMessage( Handle, UM_WEBDEAD, ret, 0 );
|
||
m_lblTips->Visible = false;
|
||
}
|
||
}
|
||
else if( iOp==JS_OP_GAMEON ){
|
||
// m_btnStart->Enabled = true;
|
||
DebugPrint("Game complete on");
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMSetBet(TMessage &msg)
|
||
{
|
||
if( g_bGameOn || m_bManual){
|
||
int iGame = msg.WParam;
|
||
TAutoBetThread* pThread = new TAutoBetThread(iGame);
|
||
m_aABThreads.push_back(pThread);
|
||
pThread->Start();
|
||
}
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMAddTable(TMessage &msg)
|
||
{
|
||
if(m_bClosing)
|
||
return;
|
||
|
||
int ind = msg.WParam;
|
||
TGame* pG = (TGame*)msg.LParam;
|
||
if(pG){//单个台桌
|
||
int nTab = m_aTables.size();
|
||
if(m_nTabShow<0 || nTab < m_nTabShow){
|
||
TTableFrame* pT = new TTableFrame(NULL);
|
||
pT->Parent = m_panWeb;
|
||
pT->SetGame(pG);
|
||
m_aTables.insert( m_aTables.begin()+ind, pT );
|
||
|
||
if(m_nTabRun<0 || nTab<m_nTabRun)
|
||
pT->SetRun(true);
|
||
|
||
DebugPrint("AddTable %s", ((AnsiString)pG->vid).c_str());
|
||
}
|
||
}
|
||
else{//全部台桌
|
||
//先清空台桌
|
||
m_aSelTabs.clear();
|
||
for(int i=0; i<m_aTables.size(); i++)
|
||
delete m_aTables[i];
|
||
m_aTables.clear();
|
||
|
||
int nGame = g_aGames.size();
|
||
int nShow = (m_nTabShow<0 || m_nTabShow>nGame) ? nGame : m_nTabShow;
|
||
|
||
for(int i=0; i<nShow; i++){
|
||
TGame* pG = g_aGames[i];
|
||
TTableFrame* pT = new TTableFrame(NULL);
|
||
pT->Parent = m_panWeb;
|
||
pT->SetGame(pG);
|
||
m_aTables.push_back(pT);
|
||
|
||
if(m_nTabRun<0 || i<m_nTabRun)
|
||
pT->SetRun(true);
|
||
}
|
||
|
||
// m_imgBack->Visible = false;
|
||
m_lblAnnonce->Visible = false;
|
||
m_lblTips->Visible = false;
|
||
|
||
m_btnLogin->Caption = "重新登录";
|
||
m_btnStart->Enabled = true;
|
||
m_btnTables->Enabled = true;
|
||
m_btnManual->Enabled = true;
|
||
m_tsMode->Enabled = true;
|
||
m_pDPTimer->Enabled = true;
|
||
|
||
PostMessage(Handle, UM_STATE_UPDATE, STATE_ALL, 0);
|
||
|
||
if( g_iPlatform==PF_PA ){
|
||
//获取用户信息
|
||
m_chrm->ExecuteJavaScript( userJS_PA, "", 0 );
|
||
|
||
ClearUtilTimer();
|
||
|
||
m_pUtilTimer = new TTimer(NULL);
|
||
m_pUtilTimer->Tag = 0;
|
||
m_pUtilTimer->OnTimer = UtilTimerProc;
|
||
m_pUtilTimer->Interval = 1000;
|
||
m_pUtilTimer->Enabled = true;
|
||
}
|
||
}
|
||
|
||
ResetTableGrid();
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMPolicyChanged(TMessage &msg)
|
||
{
|
||
int op = msg.WParam>>16, //操作类型 0=修改 1=添加 2=删除
|
||
iType = msg.WParam & 0xFFFF, //策略类型
|
||
iPolicy = msg.LParam; //策略序号
|
||
TComboBox* pCB = iType==TYPE_P_BET ? m_cbBetWays : m_cbBetChips;
|
||
|
||
if(op==0){ //选择
|
||
pCB->ItemIndex = iPolicy;
|
||
OnPolicyChange(pCB);
|
||
}
|
||
else if(op==1){ //添加
|
||
vector<TBasePolicy*>& aPolicies = iType==TYPE_P_BET ? g_aBetPolicies : g_aChipPolicies;
|
||
TBasePolicy* pPolicy = aPolicies.back();
|
||
pCB->AddItem(pPolicy->name, NULL);
|
||
}
|
||
else if(op==2){ //删除
|
||
pCB->Items->Delete(iPolicy);
|
||
|
||
if(pCB->ItemIndex<0)
|
||
pCB->Text = pCB->Hint;
|
||
|
||
int& gPolicy = iType==TYPE_P_BET ? g_iBetPolicy : g_iChipPolicy;
|
||
gPolicy = pCB->ItemIndex;
|
||
|
||
//独立策略修改
|
||
for(int i=g_aIPGames.size()-1; i>=0; i--){
|
||
TIPGame* pIG = g_aIPGames[i];
|
||
int& rIGP = iType==TYPE_P_BET ? pIG->iBetPolicy : pIG->iChipPolicy;
|
||
if(rIGP>iPolicy){
|
||
rIGP--;
|
||
|
||
if(pIG->pGame){
|
||
int& rGP = iType==TYPE_P_BET ? pIG->pGame->iBetPolicy : pIG->pGame->iChipPolicy;
|
||
rGP = rIGP;
|
||
}
|
||
}
|
||
else if(rIGP==iPolicy){ //删除独立策略
|
||
if(pIG->pGame){
|
||
pIG->pGame->ResetIP();
|
||
}
|
||
|
||
g_aIPGames.erase(g_aIPGames.begin()+i);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMLogUpdate(TMessage &msg)
|
||
{
|
||
TBetLog* pLog = (TBetLog*)msg.LParam;
|
||
if(pLog){ //添加
|
||
g_aBetLogs.push_back(pLog);
|
||
}
|
||
else{ //清空
|
||
for(int i=0; i<g_aBetLogs.size(); i++)
|
||
delete g_aBetLogs[i];
|
||
g_aBetLogs.clear();
|
||
}
|
||
|
||
if(BetLogForm)
|
||
PostMessage(BetLogForm->Handle, UM_LOG_UPDATE, 0, 0);
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMShowActCode(TMessage &msg)
|
||
{
|
||
if(ActCodeForm)
|
||
return;
|
||
|
||
ActCodeForm = new TActCodeForm(this, m_sActCode, m_tExpire);
|
||
ActCodeForm->ShowModal();
|
||
delete ActCodeForm;
|
||
ActCodeForm = NULL;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMOpenManual(TMessage &msg)
|
||
{
|
||
int op = msg.WParam;
|
||
|
||
String fn = String(g_AppPath) + "软件操作说明.doc";
|
||
if((DWORD)ShellExecute(Handle, L"Open", fn.c_str(), NULL, NULL, SW_SHOWNORMAL)<=32){
|
||
fn = String(g_AppPath);
|
||
if(op==1)
|
||
fn += "打法注码编辑说明.txt";
|
||
else
|
||
fn += "软件操作说明.txt";
|
||
ShellExecute(Handle, L"Open", fn.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMUserConfirm(TMessage &msg)
|
||
{
|
||
ClearURThread();
|
||
|
||
int op = msg.WParam;
|
||
if(op==UR_RESET){
|
||
m_sActCode = "";
|
||
return;
|
||
}
|
||
|
||
bool bVerify = op<UR_LOGIN;
|
||
if(bVerify && !ActCodeForm)
|
||
return;
|
||
|
||
char arrMap[6][2][MAX_STR_LEN] = {
|
||
{"op", "userLogin"},
|
||
{"un", ""},
|
||
{"web", ""},
|
||
{"sid", ""},
|
||
{"ver", ""},
|
||
{"did", ""}
|
||
};
|
||
int num = 6, str_len;
|
||
if(bVerify || m_sActCode.Length()){
|
||
String sCode = bVerify ? ActCodeForm->m_sCode : m_sActCode;
|
||
|
||
strcpy( arrMap[1][1], ((AnsiString)sCode).c_str() );
|
||
strcpy( arrMap[2][1], "FS");
|
||
}
|
||
else{
|
||
strcpy( arrMap[1][1], ((AnsiString)m_frmInfo->m_lblAccName->Caption).c_str() );
|
||
strcpy( arrMap[2][1], g_iPlatform==PF_AB ? "ABG" : g_iPlatform==PF_DB ? "DB" : "AG");
|
||
}
|
||
sprintf( arrMap[3][1], "%d", SOFTWARE_ID );
|
||
sprintf( arrMap[4][1], "%d", m_version[0]*10000 + m_version[1]*100 + m_version[2] );
|
||
sprintf( arrMap[5][1], "%u", m_idDevice );
|
||
|
||
char strEncode[256];
|
||
int ret = PM_ParamEncode( strEncode, &str_len, arrMap, num );
|
||
|
||
DebugPrint( "ret=%d, str=%s", ret, strEncode );
|
||
|
||
m_urThread = new TAsynHttpThread( Handle, urServer, "Api", strEncode, str_len, op );
|
||
m_urThread->Start();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMHttpReturn(TMessage &msg)
|
||
{
|
||
if( !m_urThread )
|
||
return;
|
||
|
||
int errCode = msg.WParam;
|
||
int op = msg.LParam;
|
||
TAsynHttpThread* urThread = (TAsynHttpThread*)m_urThread;
|
||
|
||
String mbText, mbTitle;
|
||
int mbFlag = 0;
|
||
|
||
if( op==UR_REPORT ){
|
||
if( errCode==0 ){
|
||
g_nRBReport = 0;
|
||
|
||
char *szReturn = urThread->m_dataOut;
|
||
DebugPrint( "rbReportResult %s", szReturn );
|
||
}
|
||
}
|
||
else if( op==UR_LOGOUT ){
|
||
if( errCode==0 ){
|
||
char *szReturn = urThread->m_dataOut;
|
||
DebugPrint( "rbLogoutResult %s", szReturn );
|
||
}
|
||
}
|
||
else{
|
||
bool bVerify = op<UR_LOGIN;
|
||
int uid = 0,
|
||
extm = 0,
|
||
repeat = bVerify ? op : (op - UR_LOGIN),
|
||
errRes = 0;
|
||
String apiKey;
|
||
|
||
if( errCode==0 ){
|
||
int len = urThread->m_sizeOut;
|
||
char *szReturn = urThread->m_dataOut;
|
||
if(szReturn[0]=='\"' && szReturn[len-1]=='\"')
|
||
szReturn[len-1] = 0;
|
||
|
||
DebugPrint( "userLoginResult %s", szReturn );
|
||
|
||
char* pos;
|
||
if( pos = strstr( szReturn, "err:" ) ){
|
||
sscanf( pos+4, "%d", &errRes );
|
||
}
|
||
else if(strstr( szReturn, "uid:" )){
|
||
char *tokenPtr=strtok(szReturn,"|");
|
||
while( tokenPtr ){
|
||
if( pos = strstr(tokenPtr, "uid:") ){
|
||
sscanf( pos+4, "%d", &uid );
|
||
}
|
||
else if( pos = strstr(tokenPtr, "exp:") ){
|
||
sscanf( pos+4, "%d", &extm );
|
||
}
|
||
else if( pos = strstr(tokenPtr, "key:") ){
|
||
apiKey = pos + 4;
|
||
}
|
||
tokenPtr=strtok(NULL,"|");
|
||
}
|
||
}
|
||
}
|
||
|
||
if(errRes){
|
||
m_tExpire = 0;
|
||
|
||
if(bVerify){
|
||
if(ActCodeForm)
|
||
PostMessage(ActCodeForm->Handle, UM_USERCONFIRM, errRes, 0);
|
||
}
|
||
else if(m_sActCode.Length()){
|
||
StopWebLoad();
|
||
|
||
if(errRes==102)
|
||
m_sActCode = "";
|
||
|
||
mbText = errRes==102 ? "无效的授权码"
|
||
: errRes==106 ? "该授权码正在其它设备上使用"
|
||
: "授权验证异常";
|
||
mbTitle = "授权";
|
||
mbFlag = MB_ICONERROR;
|
||
}
|
||
}
|
||
else if(errCode && !uid){
|
||
if(repeat<2){ //重试2次
|
||
PostMessage(Handle, UM_USERCONFIRM, op+1, 0 );
|
||
}
|
||
else if(bVerify){
|
||
if(ActCodeForm)
|
||
PostMessage(ActCodeForm->Handle, UM_USERCONFIRM, 100, 0);
|
||
}
|
||
else{
|
||
PostMessage(Handle, UM_WEBDEAD, -4, 0 );
|
||
}
|
||
}
|
||
else if(g_uid==0 && uid>0){
|
||
g_uid = uid;
|
||
m_tExpire = extm;
|
||
|
||
extm = m_tExpire - time(NULL);
|
||
|
||
bool bExpired = extm <= 0;
|
||
|
||
if(bExpired){
|
||
if(bVerify)
|
||
StopWebLoad();
|
||
else
|
||
PostMessage(Handle, UM_WEBDEAD, -2, 0 );
|
||
}
|
||
else{
|
||
SetExpireJS();
|
||
|
||
m_key = apiKey;
|
||
if(AIForm)
|
||
AIForm->OnLogin(apiKey);
|
||
}
|
||
|
||
if(bVerify){
|
||
if(ActCodeForm){
|
||
m_sActCode = ActCodeForm->m_sCode;
|
||
PostMessage(ActCodeForm->Handle, UM_USERCONFIRM, 0, m_tExpire);
|
||
}
|
||
}
|
||
else if(!bExpired && !g_bGameOn && g_tmIdle<600){ //非无人值守挂机状态
|
||
for(int i=1; i<=7; i++){
|
||
if(extm < i * 86400){
|
||
mbText = "您的";
|
||
mbText += m_sActCode.Length() ? "授权码" : "账号授权";
|
||
mbText += "将在 " + IntToStr(i) + " 天内到期";
|
||
mbTitle = "注意";
|
||
mbFlag = MB_ICONWARNING;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
delete m_urThread;
|
||
m_urThread = NULL;
|
||
|
||
if(mbFlag){
|
||
MessageBox(Handle, (wchar_t*)mbText.c_str(), (wchar_t*)mbTitle.c_str(), MB_OK | mbFlag);
|
||
if(mbFlag==MB_ICONERROR)
|
||
PostMessage(Handle, UM_SUBFORMSHOWN, 0, 0 );
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMWebLogin(TMessage &msg)
|
||
{
|
||
if(ActCodeForm)
|
||
return;
|
||
|
||
ClearJSThread();
|
||
|
||
if(!m_bWebLogon && m_chrm && m_chrm->Initialized){
|
||
m_chrm->StopLoad();
|
||
m_chrm->LoadURL("about:blank");
|
||
}
|
||
|
||
int iPF = msg.WParam;
|
||
|
||
if(iPF==PF_PA && m_iWS<0 && !m_vlThread)
|
||
WebsiteVelocity();
|
||
|
||
TLoginForm * pForm = new TLoginForm(this, iPF);
|
||
if (pForm->ShowModal() == mrOk) {
|
||
m_pDPTimer->Enabled = false;
|
||
m_tsMode->Enabled = false;
|
||
m_btnStart->Enabled = false;
|
||
m_btnTables->Enabled = false;
|
||
m_btnManual->Enabled = false;
|
||
|
||
if(m_chrm && m_chrm->Initialized){
|
||
m_chrm->StopLoad();
|
||
m_chrm->LoadURL("about:blank");
|
||
}
|
||
|
||
ManualOff();
|
||
g_bGameOn ? GameOff() : RBReport();
|
||
ClearGames();
|
||
|
||
|
||
m_bWebLogon = false;
|
||
// if(!m_sActCode.Length())
|
||
g_uid = 0;
|
||
|
||
m_key = "";
|
||
if(AIForm)
|
||
AIForm->OnLogout();
|
||
|
||
g_MinOnBet = 20; //缺省限红
|
||
g_MaxOnBet = 50000;
|
||
|
||
g_iPlatform = iPF;//pForm->m_iPlatform;
|
||
m_pmLogin->Items->Items[g_iPlatform-1]->Checked = true;
|
||
|
||
m_tmWebFocus = 0;
|
||
m_chrm->WasHidden(false);
|
||
m_chrm->SetFocus(true); //设为前台运行,否则无法加载
|
||
|
||
if( g_iPlatform==PF_PA ){
|
||
for(int i=0; i<6; i++ )
|
||
m_loginValues[i] = pForm->m_values[i];
|
||
|
||
if(m_chrm && m_chrm->Initialized && m_iWS>=0){
|
||
LoadUrl();
|
||
}
|
||
}
|
||
else{
|
||
m_url = pForm->m_url;
|
||
|
||
if(g_iPlatform==PF_DB)
|
||
m_loginValues[0] = pForm->m_values[0];
|
||
|
||
if(m_chrm && m_chrm->Initialized){
|
||
LoadUrl();
|
||
}
|
||
}
|
||
|
||
m_frmInfo->m_lblAccName->Caption = "";
|
||
m_frmInfo->m_lblLimits->Caption = "";
|
||
|
||
if(!g_settings.bSimAccOn || !g_bSimulate)
|
||
m_frmInfo->m_lblAccount->Caption = "";
|
||
|
||
m_lblTips->Caption = "正在连接网站...";
|
||
m_lblAnnonce->Visible = true;
|
||
m_lblTips->Visible = true;
|
||
}
|
||
// else{
|
||
// m_lblTips->Caption = "请登录游戏";
|
||
// }
|
||
|
||
delete pForm;
|
||
|
||
SetTableFocus();
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMStateUpdate(TMessage &msg)
|
||
{
|
||
int type = msg.WParam;
|
||
|
||
if(type==STATE_ALL){
|
||
if(g_aGames.betData.amounts[0]>0){
|
||
m_frmInfo->m_lblAmount->Caption = g_aGames.betData.amounts[0];
|
||
m_frmInfo->m_lblTotProfit->Caption = FormatFloat("0.##",g_aGames.betData.profits[0]);
|
||
m_frmInfo->m_lblTotProfit->Font->Color = g_aGames.betData.profits[0]<0 ? clFuchsia : clYellow;
|
||
m_lblBigProfit->Caption = "总赢利:" + m_frmInfo->m_lblTotProfit->Caption;
|
||
}
|
||
else{
|
||
m_frmInfo->m_lblAmount->Caption = "";
|
||
m_frmInfo->m_lblTotProfit->Caption = "";
|
||
m_lblBigProfit->Caption = "总赢利:-";
|
||
}
|
||
|
||
if(g_aGames.betData.amounts[1]>0){
|
||
m_frmInfo->m_lblRealAmount->Caption = g_aGames.betData.amounts[1];
|
||
m_frmInfo->m_lblRealProfit->Caption = FormatFloat("0.##",g_aGames.betData.profits[4]);
|
||
m_frmInfo->m_lblRealProfit->Font->Color = g_aGames.betData.profits[4]<0 ? clFuchsia : clYellow;
|
||
}
|
||
else{
|
||
m_frmInfo->m_lblRealAmount->Caption = "";
|
||
m_frmInfo->m_lblRealProfit->Caption = "";
|
||
}
|
||
|
||
if(g_aGames.betData.amounts[2]>0){
|
||
m_frmInfo->m_lblManAmount->Caption = g_aGames.betData.amounts[2];
|
||
m_frmInfo->m_lblManProfit->Caption = FormatFloat("0.##",g_aGames.betData.profits[5]);
|
||
m_frmInfo->m_lblManProfit->Font->Color = g_aGames.betData.profits[5]<0 ? clFuchsia : clYellow;
|
||
}
|
||
else{
|
||
m_frmInfo->m_lblManAmount->Caption = "";
|
||
m_frmInfo->m_lblManProfit->Caption = "";
|
||
}
|
||
|
||
if(g_aGames.betData.profits[1]>0 || g_aGames.betData.profits[2]<0){
|
||
m_frmInfo->m_lblPeakU->Caption = FormatFloat("0.##",g_aGames.betData.profits[1]);
|
||
m_frmInfo->m_lblPeakL->Caption = FormatFloat("0.##",g_aGames.betData.profits[2]);
|
||
}
|
||
else{
|
||
m_frmInfo->m_lblPeakU->Caption = "";
|
||
m_frmInfo->m_lblPeakL->Caption = "";
|
||
}
|
||
|
||
m_frmInfo->m_lblCurProfit->Caption = FormatFloat("0.##",g_aGames.betData.profits[3]);
|
||
m_frmInfo->m_lblCurProfit->Font->Color = g_aGames.betData.profits[3]<0 ? clFuchsia : clLime;
|
||
|
||
m_frmInfo->m_lblSRTitle->Caption = g_bSimulate ? "当前模拟:" : "当前实打:";
|
||
double srProf = g_bSimulate ? g_aGames.betData.profits[6] : g_aGames.betData.profits[7];
|
||
m_frmInfo->m_lblSRProfit->Caption = FormatFloat("0.##", srProf);
|
||
m_frmInfo->m_lblSRProfit->Font->Color = srProf<0 ? clFuchsia : clYellow;
|
||
|
||
if(g_aGames.betData.counts[0]>0)
|
||
m_frmInfo->m_lblWinCount->Caption = g_aGames.betData.counts[0];
|
||
else
|
||
m_frmInfo->m_lblWinCount->Caption = "";
|
||
|
||
if(g_aGames.betData.counts[1]>0)
|
||
m_frmInfo->m_lblLosCount->Caption = g_aGames.betData.counts[1];
|
||
else
|
||
m_frmInfo->m_lblLosCount->Caption = "";
|
||
|
||
if(g_aGames.betData.counts[2]>0)
|
||
m_frmInfo->m_lblSWin->Caption = g_aGames.betData.counts[2];
|
||
else
|
||
m_frmInfo->m_lblSWin->Caption = "";
|
||
|
||
if(g_aGames.betData.counts[3]>0)
|
||
m_frmInfo->m_lblSLos->Caption = g_aGames.betData.counts[3];
|
||
else
|
||
m_frmInfo->m_lblSLos->Caption = "";
|
||
|
||
if(g_aGames.betData.dead>0)
|
||
m_frmInfo->m_lblDead->Caption = g_aGames.betData.dead;
|
||
else
|
||
m_frmInfo->m_lblDead->Caption = "";
|
||
|
||
if(g_aGames.betData.maxChip>0)
|
||
m_frmInfo->m_lblMaxChip->Caption = g_aGames.betData.maxChip;
|
||
else
|
||
m_frmInfo->m_lblMaxChip->Caption = "";
|
||
|
||
if(g_settings.bSimAccOn && g_bSimulate){
|
||
m_frmInfo->m_lblAccountTitle->Caption = "本金:";
|
||
m_frmInfo->m_lblAccount->Caption = FormatFloat("0.##",g_settings.fSimAcc);
|
||
}
|
||
else{
|
||
m_frmInfo->m_lblAccountTitle->Caption = "余额:";
|
||
m_frmInfo->m_lblAccount->Caption = FormatFloat("0.##",g_fBalance);
|
||
}
|
||
}
|
||
else if(type==STATE_BALANCE){
|
||
double fBalance;
|
||
if(g_settings.bSimAccOn && g_bSimulate){
|
||
if(msg.LParam)
|
||
m_frmInfo->m_lblAccountTitle->Caption = "本金:";
|
||
m_frmInfo->m_lblAccount->Caption = FormatFloat("0.##",g_settings.fSimAcc);
|
||
fBalance = g_settings.fSimAcc;
|
||
}
|
||
else{
|
||
if(msg.LParam)
|
||
m_frmInfo->m_lblAccountTitle->Caption = "余额:";
|
||
m_frmInfo->m_lblAccount->Caption = FormatFloat("0.##",g_fBalance);
|
||
fBalance = g_fBalance;
|
||
}
|
||
|
||
if(!g_aDots[1].empty()){
|
||
int nSim = g_settings.fSimAcc + 0.5;
|
||
if(nSim != g_aDots[1].back().val){
|
||
g_aDots[1].push_back(TDot(nSim, time(NULL)));
|
||
if(ChartForm)
|
||
PostMessage(ChartForm->Handle, UM_CHART_UPDATE, 1, 0);
|
||
}
|
||
}
|
||
if(!g_aDots[2].empty()){
|
||
int nBalance = g_fBalance + 0.5;
|
||
if(nBalance != g_aDots[2].back().val){
|
||
g_aDots[2].push_back(TDot(nBalance, time(NULL)));
|
||
if(ChartForm)
|
||
PostMessage(ChartForm->Handle, UM_CHART_UPDATE, 2, 0);
|
||
}
|
||
}
|
||
|
||
int stopAcc = 0;
|
||
if(g_settings.bAccStopWin && fBalance>=g_settings.nAccStopWin)
|
||
stopAcc = 5;
|
||
else if(g_settings.bAccStopLos && fBalance<=g_settings.nAccStopLos)
|
||
stopAcc = 6;
|
||
|
||
if(stopAcc)
|
||
GameOff(stopAcc);
|
||
}
|
||
else if(type==STATE_AMOUNT){
|
||
if(g_aGames.betData.amounts[0]>0){
|
||
m_frmInfo->m_lblAmount->Caption = g_aGames.betData.amounts[0];
|
||
m_frmInfo->m_lblTotProfit->Caption = FormatFloat("0.##",g_aGames.betData.profits[0]);
|
||
m_frmInfo->m_lblTotProfit->Font->Color = g_aGames.betData.profits[0]<0 ? clFuchsia : clYellow;
|
||
m_lblBigProfit->Caption = "总赢利:" + m_frmInfo->m_lblTotProfit->Caption;
|
||
}
|
||
else{
|
||
m_frmInfo->m_lblAmount->Caption = "";
|
||
m_frmInfo->m_lblTotProfit->Caption = "";
|
||
m_lblBigProfit->Caption = "总赢利:0";
|
||
}
|
||
|
||
if(g_aGames.betData.amounts[1]>0){
|
||
m_frmInfo->m_lblRealAmount->Caption = g_aGames.betData.amounts[1];
|
||
m_frmInfo->m_lblRealProfit->Caption = FormatFloat("0.##",g_aGames.betData.profits[4]);
|
||
m_frmInfo->m_lblRealProfit->Font->Color = g_aGames.betData.profits[4]<0 ? clFuchsia : clYellow;
|
||
}
|
||
else{
|
||
m_frmInfo->m_lblRealAmount->Caption = "";
|
||
m_frmInfo->m_lblRealProfit->Caption = "";
|
||
}
|
||
}
|
||
else if(type==STATE_LIMIT){
|
||
m_frmInfo->m_lblLimits->Caption = IntToStr(g_MinOnBet) + " - " + IntToStr(g_MaxOnBet);
|
||
|
||
if(g_iChipPolicy>=0 && g_aChipPolicies[g_iChipPolicy]->kind!=KIND_CHIP_COM)
|
||
RecalcMultiRate();
|
||
}
|
||
else if(type==STATE_BET_R){
|
||
int wl = msg.LParam;
|
||
if(g_aGames.betData.amounts[0]>0){
|
||
m_frmInfo->m_lblTotProfit->Caption = FormatFloat("0.##",g_aGames.betData.profits[0]);
|
||
m_frmInfo->m_lblTotProfit->Font->Color = g_aGames.betData.profits[0]<0 ? clFuchsia : clYellow;
|
||
m_lblBigProfit->Caption = "总赢利:" + m_frmInfo->m_lblTotProfit->Caption;
|
||
|
||
if(!g_aDots[0].empty()){
|
||
double pro = g_aGames.betData.profits[0];
|
||
int nProfit = pro<0 ? pro - 0.5 : pro + 0.5;
|
||
if(nProfit != g_aDots[0].back().val){
|
||
g_aDots[0].push_back(TDot(nProfit, time(NULL)));
|
||
if(ChartForm)
|
||
PostMessage(ChartForm->Handle, UM_CHART_UPDATE, 0, 0);
|
||
}
|
||
}
|
||
}
|
||
|
||
if(g_aGames.betData.amounts[1]>0){
|
||
m_frmInfo->m_lblRealProfit->Caption = FormatFloat("0.##",g_aGames.betData.profits[4]);
|
||
m_frmInfo->m_lblRealProfit->Font->Color = g_aGames.betData.profits[4]<0 ? clFuchsia : clYellow;
|
||
}
|
||
|
||
m_frmInfo->m_lblCurProfit->Caption = FormatFloat("0.##",g_aGames.betData.profits[3]);
|
||
m_frmInfo->m_lblCurProfit->Font->Color = g_aGames.betData.profits[3]<0 ? clFuchsia : clLime;
|
||
m_frmInfo->m_lblSRTitle->Caption = g_bSimulate ? "当前模拟:" : "当前实打:";
|
||
double srProf = g_bSimulate ? g_aGames.betData.profits[6] : g_aGames.betData.profits[7];
|
||
m_frmInfo->m_lblSRProfit->Caption = FormatFloat("0.##", srProf);
|
||
m_frmInfo->m_lblSRProfit->Font->Color = srProf<0 ? clFuchsia : clYellow;
|
||
|
||
int iStop = 0;
|
||
bool bSwitch = false;
|
||
if(wl==0){
|
||
TBetLog* pLog = new TBetLog;
|
||
pLog->ts = DateTimeToUnix(Now(), false);
|
||
pLog->ev = LOGEVT_RESET;
|
||
pLog->op = 0;
|
||
SendMessage(Handle, UM_LOG_UPDATE, 0, (long)pLog);
|
||
}
|
||
else if(wl==1){
|
||
// m_frmInfo->m_lblWinCount->Caption = g_aGames.betData.counts[0];
|
||
|
||
if(g_bGameOn){
|
||
if(g_settings.bTotalStopWin && g_aGames.betData.profits[3]>=g_settings.nTotalStopWin) //总体止赢
|
||
iStop = 1;
|
||
|
||
if(g_bSimulate && g_settings.bS2RWin && g_settings.nS2RWin<=g_aGames.betData.profits[6]
|
||
|| !g_bSimulate && g_settings.bR2SWin && g_settings.nR2SWin<=g_aGames.betData.profits[7]) //模实切换
|
||
bSwitch = true;
|
||
}
|
||
}
|
||
else if(wl==2){
|
||
// m_frmInfo->m_lblLosCount->Caption = g_aGames.betData.counts[1];
|
||
|
||
if(g_bGameOn){
|
||
if(g_settings.bTotalStopLos && g_aGames.betData.profits[3]<=-g_settings.nTotalStopLos)//总体止损
|
||
iStop = 2;
|
||
|
||
if(g_settings.bU2DStop && (!g_settings.bU2DMinPeak || g_aGames.fCurrProfitPeak >= g_settings.nU2DMinPeak)
|
||
&& g_aGames.betData.profits[3] <= g_aGames.fCurrProfitPeak - g_settings.nU2DStop ){
|
||
if(!iStop || !g_settings.bU2DPause || g_settings.iTotalLosOp==2
|
||
&& g_settings.nTotalLosPause < g_settings.nU2DPause )
|
||
iStop = 7;
|
||
}
|
||
|
||
if(g_bSimulate && g_settings.bS2RLos && -g_settings.nS2RLos>=g_aGames.betData.profits[6]
|
||
|| !g_bSimulate && g_settings.bR2SLos && -g_settings.nR2SLos>=g_aGames.betData.profits[7]) //模实切换
|
||
bSwitch = true;
|
||
|
||
if(g_settings.bSimAccOn && g_settings.bStopLow && g_settings.fSimAcc<g_MinOnBet){
|
||
//检查是否还有待结算
|
||
bool bBetted = g_aGames.nBetted[0] || g_settings.bSyncReal && g_aGames.nBetted[1];
|
||
if(!bBetted){
|
||
GameOff(3);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if(g_bGameOn && iStop){
|
||
if(iStop==1 && g_settings.iTotalWinOp==0 || iStop==2 && g_settings.iTotalLosOp==0
|
||
|| iStop==7 && !g_settings.bU2DPause ){ //停止挂机
|
||
GameOff(iStop);
|
||
}
|
||
else if(!g_bBetPause){ //下局重置/暂停重置
|
||
ClearABThread();
|
||
bool bBreak = iStop==1 && g_settings.iTotalWinOp==1
|
||
|| iStop==2 && g_settings.iTotalLosOp==1; //下局重置
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
if(pT->m_pGame->bRun)
|
||
pT->m_pGame->AutoBetOff(bBreak);
|
||
}
|
||
|
||
if(g_aGames.bFloat) //游台无须等待结算
|
||
g_aGames.ResetFloat();
|
||
|
||
TBetLog* pLog = new TBetLog;
|
||
pLog->ts = DateTimeToUnix(Now(), false);
|
||
pLog->ev = LOGEVT_RESET;
|
||
pLog->op = iStop;
|
||
pLog->num = bBreak;
|
||
SendMessage(Handle, UM_LOG_UPDATE, 0, (long)pLog);
|
||
|
||
int sec = (iStop==7 && g_settings.bU2DPause ? g_settings.nU2DPause
|
||
: iStop==1 && g_settings.iTotalWinOp==2 ? g_settings.nTotalWinPause
|
||
: iStop==2 && g_settings.iTotalLosOp==2 ? g_settings.nTotalLosPause
|
||
: 0 ) * 60;
|
||
|
||
if(sec==0 && g_aGames.pRankChip){ //立即重置
|
||
g_aGames.ResetRankChip();
|
||
}
|
||
else if(m_tmBetPause<sec){ //暂停重启
|
||
m_tmBetPause = sec;
|
||
g_bBetPause = true; //暂停下注
|
||
}
|
||
}
|
||
}
|
||
|
||
if(bSwitch && g_bGameOn){
|
||
m_tsMode->State = !m_tsMode->State;
|
||
}
|
||
}
|
||
else if(type==STATE_PEAK){
|
||
int ul = msg.LParam;
|
||
if(ul==1){
|
||
m_frmInfo->m_lblPeakU->Caption = FormatFloat("0.##",g_aGames.betData.profits[1]);
|
||
}
|
||
else if(ul==2){
|
||
m_frmInfo->m_lblPeakL->Caption = FormatFloat("0.##",g_aGames.betData.profits[2]);
|
||
}
|
||
else if(g_aGames.betData.profits[1]>0 || g_aGames.betData.profits[2]<0){
|
||
m_frmInfo->m_lblPeakU->Caption = FormatFloat("0.##",g_aGames.betData.profits[1]);
|
||
m_frmInfo->m_lblPeakL->Caption = FormatFloat("0.##",g_aGames.betData.profits[2]);
|
||
}
|
||
else{
|
||
m_frmInfo->m_lblPeakU->Caption = "";
|
||
m_frmInfo->m_lblPeakL->Caption = "";
|
||
}
|
||
}
|
||
else if(type==STATE_COUNT){
|
||
int ind = msg.LParam;
|
||
bool bUpdChart = false;
|
||
if(ind==0){
|
||
if(g_aGames.betData.counts[0]>0){
|
||
m_frmInfo->m_lblWinCount->Caption = g_aGames.betData.counts[0];
|
||
bUpdChart = true;
|
||
}
|
||
else
|
||
m_frmInfo->m_lblWinCount->Caption = "";
|
||
}
|
||
else if(ind==1){
|
||
if(g_aGames.betData.counts[1]>0){
|
||
m_frmInfo->m_lblLosCount->Caption = g_aGames.betData.counts[1];
|
||
bUpdChart = true;
|
||
}
|
||
else
|
||
m_frmInfo->m_lblLosCount->Caption = "";
|
||
}
|
||
else if(ind==2){
|
||
if(g_aGames.betData.counts[2]>0)
|
||
m_frmInfo->m_lblSWin->Caption = g_aGames.betData.counts[2];
|
||
else
|
||
m_frmInfo->m_lblSWin->Caption = "";
|
||
}
|
||
else{
|
||
if(g_aGames.betData.counts[3]>0)
|
||
m_frmInfo->m_lblSLos->Caption = g_aGames.betData.counts[3];
|
||
else
|
||
m_frmInfo->m_lblSLos->Caption = "";
|
||
}
|
||
|
||
if(bUpdChart && !g_aDots[3].empty()){
|
||
int nWL = g_aGames.betData.counts[0] - g_aGames.betData.counts[1];
|
||
if(nWL != g_aDots[3].back().val){
|
||
g_aDots[3].push_back(TDot(nWL, time(NULL)));
|
||
if(ChartForm)
|
||
PostMessage(ChartForm->Handle, UM_CHART_UPDATE, 3, 0);
|
||
}
|
||
}
|
||
}
|
||
else if(type==STATE_MISC){
|
||
if(g_aGames.betData.maxChip>0)
|
||
m_frmInfo->m_lblMaxChip->Caption = g_aGames.betData.maxChip;
|
||
else
|
||
m_frmInfo->m_lblMaxChip->Caption = "";
|
||
|
||
if(g_aGames.betData.dead>0)
|
||
m_frmInfo->m_lblDead->Caption = g_aGames.betData.dead;
|
||
else
|
||
m_frmInfo->m_lblDead->Caption = "";
|
||
}
|
||
else if(type==STATE_REAL){
|
||
if(msg.LParam){
|
||
if(g_aGames.betData.amounts[1]>0){
|
||
m_frmInfo->m_lblRealAmount->Caption = g_aGames.betData.amounts[1];
|
||
m_frmInfo->m_lblRealProfit->Caption = FormatFloat("0.##",g_aGames.betData.profits[4]);
|
||
m_frmInfo->m_lblRealProfit->Font->Color = g_aGames.betData.profits[4]<0 ? clFuchsia : clYellow;
|
||
}
|
||
else{
|
||
m_frmInfo->m_lblRealAmount->Caption = "";
|
||
m_frmInfo->m_lblRealProfit->Caption = "";
|
||
}
|
||
}
|
||
else{
|
||
m_frmInfo->m_lblRealProfit->Caption = FormatFloat("0.##",g_aGames.betData.profits[4]);
|
||
m_frmInfo->m_lblRealProfit->Font->Color = g_aGames.betData.profits[4]<0 ? clFuchsia : clYellow;
|
||
}
|
||
}
|
||
else if(type==STATE_MAN){
|
||
if(msg.LParam){
|
||
if(g_aGames.betData.amounts[2]>0){
|
||
m_frmInfo->m_lblManAmount->Caption = g_aGames.betData.amounts[2];
|
||
m_frmInfo->m_lblManProfit->Caption = FormatFloat("0.##",g_aGames.betData.profits[5]);
|
||
m_frmInfo->m_lblManProfit->Font->Color = g_aGames.betData.profits[5]<0 ? clFuchsia : clYellow;
|
||
}
|
||
else{
|
||
m_frmInfo->m_lblManAmount->Caption = "";
|
||
m_frmInfo->m_lblManProfit->Caption = "";
|
||
}
|
||
}
|
||
else{
|
||
m_frmInfo->m_lblManProfit->Caption = FormatFloat("0.##",g_aGames.betData.profits[5]);
|
||
m_frmInfo->m_lblManProfit->Font->Color = g_aGames.betData.profits[5]<0 ? clFuchsia : clYellow;
|
||
}
|
||
}
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMEnterTable(TMessage &msg)
|
||
{
|
||
if(m_pUtilTimer && m_pUtilTimer->Tag==0)
|
||
ClearUtilTimer();
|
||
|
||
int tab = msg.WParam;
|
||
|
||
m_chrm->WasHidden(false);
|
||
m_chrm->SetFocus(true); //设为前台,否则无法加载
|
||
|
||
if(tab==1){ //进入多台
|
||
m_tmWebFocus = 590; //保活10秒,以加载完成
|
||
}
|
||
else{
|
||
if( g_iPlatform==PF_PA ){
|
||
if(tab==0)
|
||
m_chrm->ExecuteJavaScript(goLinkJS_PA, "", 0); //进入多台
|
||
else
|
||
m_chrm->ExecuteJavaScript(goLobbyJS_PA, "", 0); //先回大厅
|
||
}
|
||
else if( g_iPlatform==PF_AB ){
|
||
m_chrm->ExecuteJavaScript(goLinkJS_AB, "", 0); //进入多台
|
||
}
|
||
|
||
m_tmWebFocus = 0;
|
||
}
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMChartUpdate(TMessage &msg)
|
||
{
|
||
int mod = msg.WParam,
|
||
op = msg.LParam;
|
||
if( op ){ //清除图表数据
|
||
g_aDots[mod].clear();
|
||
|
||
bool bAllClear = true;
|
||
for(int i=0; i<4; i++){
|
||
if(g_aDots[i].size()>1){
|
||
bAllClear = false;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if(bAllClear)
|
||
g_aGames.runTime = 0; //重置挂机时间
|
||
|
||
if(g_bGameOn){
|
||
TDot dot;
|
||
if(mod==0){
|
||
double pro = g_aGames.betData.profits[0];
|
||
dot.val = pro<0 ? pro - 0.5 : pro + 0.5;
|
||
g_aDots[0].push_back(dot);
|
||
}
|
||
else if(mod==1){
|
||
dot.val = g_settings.fSimAcc + 0.5;
|
||
g_aDots[1].push_back(dot);
|
||
}
|
||
else if(mod==2){
|
||
dot.val = g_fBalance + 0.5;
|
||
g_aDots[2].push_back(dot);
|
||
}
|
||
else if(mod==3){
|
||
dot.val = g_aGames.betData.counts[0] - g_aGames.betData.counts[1];
|
||
g_aDots[3].push_back(dot);
|
||
}
|
||
}
|
||
}
|
||
|
||
if(ChartForm)
|
||
PostMessage(ChartForm->Handle, UM_CHART_UPDATE, mod, op);
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMFloatBet(TMessage &msg)
|
||
{
|
||
// TGame* pGLast = g_aGames.GetGame(g_aGames.iFloatGame);
|
||
vector<TGame*> games;
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
TGame* pG = pT->m_pGame;
|
||
|
||
if(pG->bRun && !pG->bIndPolicy && pG->timeout>3
|
||
&& pG->iGame!=g_aGames.iFloatGame)
|
||
games.push_back(pG);
|
||
}
|
||
|
||
int iStart = Random(games.size());
|
||
for(int i=iStart; i<games.size(); i++)
|
||
games[i]->AutoBetOn();
|
||
for(int i=iStart-1; i>=0; i--)
|
||
games[i]->AutoBetOn();
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMFloatDead(TMessage &msg)
|
||
{
|
||
int dead = msg.WParam;
|
||
int pause = msg.LParam;
|
||
|
||
g_aGames.ResetFloat();
|
||
|
||
if(dead==0){ //立即停止
|
||
TBetLog* pLog = new TBetLog;
|
||
pLog->ts = DateTimeToUnix(Now(), false);
|
||
pLog->ev = LOGEVT_END;
|
||
pLog->op = 4;
|
||
SendMessage(Handle, UM_LOG_UPDATE, 0, (long)pLog);
|
||
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
TGame* pG = pT->m_pGame;
|
||
if(pG->bRun && !pG->bIndPolicy)
|
||
pT->SetRun(false);
|
||
}
|
||
|
||
// GameOff(4);
|
||
}
|
||
else{
|
||
TBetLog* pLog = new TBetLog;
|
||
strcpy(pLog->tno, "游台");
|
||
pLog->ts = DateTimeToUnix(Now(), false);
|
||
pLog->ev = LOGEVT_DEAD;
|
||
pLog->op = dead;
|
||
pLog->num = pause;
|
||
SendMessage(Handle, UM_LOG_UPDATE, 0, (long)pLog);
|
||
|
||
if(g_bGameOn){
|
||
if(dead==1){ //新局重启
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
TGame* pG = pT->m_pGame;
|
||
if(pG->bRun && !pG->bIndPolicy)
|
||
pG->AutoBetOff(true);
|
||
}
|
||
}
|
||
else{ //暂停重启
|
||
if(pause==0){ //立即重启
|
||
if(!g_bBetPause) //当前没有暂停
|
||
PostMessage(Handle, UM_FLOAT_BET, 0, 0);
|
||
}
|
||
else{
|
||
int sec = pause * 60;
|
||
if(m_tmDeadPause < sec){ //可能止赢止损暂停中
|
||
m_tmDeadPause = sec;
|
||
g_bDeadPause = true; //爆缆暂停
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMGlobalBet(TMessage &msg)
|
||
{
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
TGame* pG = pT->m_pGame;
|
||
|
||
if(pG->bRun && !pG->bIndPolicy && pG->timeout>3)
|
||
pG->AutoBetOn();
|
||
}
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::UMGlobalDead(TMessage &msg)
|
||
{
|
||
int dead = msg.WParam;
|
||
int pause = msg.LParam;
|
||
|
||
g_aGames.ResetRankChip();
|
||
|
||
if(dead==0){ //立即停止
|
||
TBetLog* pLog = new TBetLog;
|
||
pLog->ts = DateTimeToUnix(Now(), false);
|
||
pLog->ev = LOGEVT_END;
|
||
pLog->op = 8;
|
||
SendMessage(Handle, UM_LOG_UPDATE, 0, (long)pLog);
|
||
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
TGame* pG = pT->m_pGame;
|
||
if(pG->bRun && !pG->bIndPolicy)
|
||
pT->SetRun(false);
|
||
}
|
||
// GameOff(8);
|
||
}
|
||
else{
|
||
TBetLog* pLog = new TBetLog;
|
||
strcpy(pLog->tno, "总体");
|
||
pLog->ts = DateTimeToUnix(Now(), false);
|
||
pLog->ev = LOGEVT_DEAD;
|
||
pLog->op = dead;
|
||
pLog->num = pause;
|
||
SendMessage(Handle, UM_LOG_UPDATE, 0, (long)pLog);
|
||
|
||
if(g_bGameOn && (dead==1 || dead==2 && pause!=0)){ //dead==1新局重启
|
||
if(dead==2){
|
||
int sec = pause * 60;
|
||
if(m_tmDeadPause < sec){ //可能止赢止损暂停中
|
||
m_tmDeadPause = sec;
|
||
g_bDeadPause = true; //爆缆暂停
|
||
}
|
||
}
|
||
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
TGame* pG = pT->m_pGame;
|
||
if(pG->bRun && !pG->bIndPolicy)
|
||
pG->AutoBetOff(dead==1);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::StartJSThread(int iOp)
|
||
{
|
||
if( m_jsThread ){
|
||
if(((TJSHandleThread*)m_jsThread)->m_op >= iOp)
|
||
return;
|
||
|
||
ClearJSThread();
|
||
}
|
||
|
||
m_jsThread = new TJSHandleThread( iOp );
|
||
m_jsThread->Start();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::GetDeviceId()
|
||
{
|
||
HKEY hKey;
|
||
DWORD dwDisposition;
|
||
long lResult;
|
||
lResult = RegCreateKeyEx(HKEY_CURRENT_USER, L"SOFTWARE\\RnB\\RBmaster", 0,
|
||
NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,
|
||
&dwDisposition);
|
||
|
||
if (lResult == ERROR_SUCCESS) {
|
||
if (dwDisposition == REG_OPENED_EXISTING_KEY) {
|
||
UINT nValue;
|
||
DWORD dwSize = sizeof(int), dwType;
|
||
|
||
long lRes = RegQueryValueEx(hKey, L"deviceId", NULL, &dwType,
|
||
(LPBYTE) & nValue, &dwSize);
|
||
if (lRes == ERROR_SUCCESS && dwSize > 0) {
|
||
m_idDevice = nValue;
|
||
}
|
||
}
|
||
}
|
||
|
||
if(!m_idDevice){
|
||
m_idDevice = time(NULL) % (int)1e9 + Random(4) * (int)1e9;
|
||
|
||
if(lResult == ERROR_SUCCESS) {
|
||
RegSetValueEx(hKey, L"deviceId", 0, REG_DWORD,
|
||
(LPBYTE) &m_idDevice, sizeof(DWORD));
|
||
}
|
||
}
|
||
|
||
if(lResult == ERROR_SUCCESS) {
|
||
RegCloseKey(hKey);
|
||
}
|
||
|
||
DebugPrint("idDevice: %u", m_idDevice);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ResetGame()
|
||
{
|
||
// g_betSet.nBaseChip = m_leChip->Text.ToInt();
|
||
// g_betSet.fSum = 0;
|
||
// g_betSet.nWinCounts = g_betSet.nLosCounts = 0;
|
||
// g_betSet.fWinSum = g_betSet.fLosSum = 0;
|
||
UpdateStatistics();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ClearGames()
|
||
{
|
||
m_aSelTabs.clear();
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
delete m_aTables[i];
|
||
}
|
||
m_aTables.clear();
|
||
|
||
g_aGames.ClearAllGames();
|
||
|
||
ResetTableGrid();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ManualOn()
|
||
{
|
||
if(!m_bManual){
|
||
m_bManual = true;
|
||
m_btnManual->Caption = "关闭手工";
|
||
|
||
LockWindowUpdate( m_panWeb->Handle );
|
||
//清除台桌选择
|
||
ClearSelect();
|
||
|
||
//显示筹码
|
||
ChipsForm = new TChipsForm(this);
|
||
int x = Left>DPIX(60) ? - DPIX(50) : -DPIX(5); //放置到窗口外
|
||
TPoint pt = TPoint(x, m_panWeb->Top);
|
||
pt = ClientToScreen(pt);
|
||
ChipsForm->Left = pt.x;
|
||
ChipsForm->Top = pt.y;
|
||
ChipsForm->Show();
|
||
|
||
//开启手工
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
PostMessage(m_aTables[i]->Handle, UM_MANUAL_SET, true, 0);
|
||
}
|
||
LockWindowUpdate( 0 );
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ManualOff()
|
||
{
|
||
if(m_bManual){
|
||
m_bManual = false;
|
||
m_btnManual->Caption = "开启手工";
|
||
|
||
ChipsForm->Hide();
|
||
delete ChipsForm;
|
||
ChipsForm = NULL;
|
||
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
PostMessage(m_aTables[i]->Handle, UM_MANUAL_SET, false, 0);
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::InitBrowser(bool bCode)
|
||
{
|
||
TChromium* chrm = new TChromium(NULL);
|
||
|
||
chrm->OnBeforeClose = WebBeforeClose;
|
||
chrm->OnBeforeContextMenu = WebBeforeContextMenu;
|
||
chrm->OnBeforePopup = WebBeforePopup;
|
||
chrm->OnJsdialog = WebJsdialog;
|
||
|
||
if(bCode){
|
||
chrm->DefaultUrl = "about:blank";
|
||
|
||
m_chrmCode = chrm;
|
||
}
|
||
else{
|
||
chrm->OnAfterCreated = WebAfterCreated;
|
||
chrm->OnProcessMessageReceived = WebProcessMessageReceived;
|
||
chrm->OnLoadEnd = WebLoadEnd;
|
||
chrm->OnResourceLoadComplete = WebResourceLoadComplete;
|
||
chrm->OnLoadError = WebLoadError;
|
||
chrm->OnBeforeResourceLoad = WebBeforeResourceLoad;
|
||
|
||
m_chrm = chrm;
|
||
}
|
||
|
||
chrm->CreateBrowser();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
_di_ICefFrame __fastcall TMainForm::GetCefFrame( int type )
|
||
{
|
||
if( m_chrm ){
|
||
if( type==MAIN_FRAME )
|
||
return m_chrm->Browser->MainFrame;// >GetFrameByident( m_idMainFrm );
|
||
}
|
||
|
||
return NULL;
|
||
}
|
||
|
||
//---------------------------------------------------------------------------
|
||
|
||
bool __fastcall TMainForm::WebsiteVelocity()
|
||
{
|
||
Screen->Cursor = crHourGlass;
|
||
m_vlThread = new TVeloThread( Handle, WSNUM, websites );
|
||
// ((TVeloThread*)m_vlThread)->m_sWebsite = m_sWebsite;
|
||
m_vlThread->Start();
|
||
|
||
return true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnStartClick(TObject *Sender)
|
||
{
|
||
if( !g_bGameOn ){
|
||
if(g_iBetPolicy<0){
|
||
ShowMessage( "请先选择打法" );
|
||
goto Start_Click_Exit;
|
||
}
|
||
|
||
if(g_iChipPolicy<0){
|
||
ShowMessage( "请先选择注码" );
|
||
goto Start_Click_Exit;
|
||
}
|
||
|
||
if(g_aGames.nBetted[0] || g_aGames.nBetted[1]){
|
||
int mrRet = MessageBox(Handle, L"上次结算尚未完成,是否开始挂机?", L"挂机",
|
||
MB_ICONQUESTION | MB_OKCANCEL);
|
||
|
||
if( mrRet==mrCancel )
|
||
goto Start_Click_Exit;
|
||
}
|
||
|
||
if(g_bShowSetting && ShowSettingForm()==mrCancel)
|
||
goto Start_Click_Exit;
|
||
|
||
GameOn();
|
||
}
|
||
else{
|
||
GameOff();
|
||
}
|
||
|
||
Start_Click_Exit:
|
||
SetTableFocus();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WebMouseWheelDown(TObject *Sender, TShiftState Shift, TPoint &MousePos, bool &Handled)
|
||
{
|
||
m_panWeb->Perform(WM_VSCROLL,SB_LINEDOWN,0);
|
||
Handled = true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WebMouseWheelUp(TObject *Sender, TShiftState Shift, TPoint &MousePos, bool &Handled)
|
||
{
|
||
m_panWeb->Perform(WM_VSCROLL,SB_LINEUP,0);
|
||
Handled = true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnRoadChange(TObject *Sender)
|
||
{
|
||
TComboBox* combo = (TComboBox*)Sender;
|
||
|
||
int iRoad = combo->ItemIndex;
|
||
if( iRoad!=g_iRoad ){
|
||
g_iRoad = iRoad;
|
||
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
TGame* pG = pT->m_pGame;
|
||
if(pG && pG->iRoad<0)
|
||
PostMessage(pT->Handle, UM_CHANGE_ROAD, 0, 0);
|
||
}
|
||
}
|
||
|
||
SetTableFocus();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnTablesClick(TObject *Sender)
|
||
{
|
||
TButton* pB = (TButton*)Sender;
|
||
|
||
TTabSetForm* pForm = new TTabSetForm(this, g_aGames.size(), m_nTabShow, m_nTabRun);
|
||
|
||
TPoint pt = TPoint(m_panTopBar->Left + pB->Left, m_panTopBar->Top + pB->Top);
|
||
pt = ClientToScreen(pt);
|
||
pForm->Top = pt.y + pB->Height + 2;
|
||
pForm->Left = pt.x - (pForm->Width - pB->Width)/2;
|
||
|
||
if(mrOk == pForm->ShowModal()){
|
||
ClearSelect();
|
||
|
||
m_nTabShow = pForm->m_nShow;
|
||
m_nTabRun = pForm->m_nRun;
|
||
|
||
int nTab = m_aTables.size();
|
||
if(m_nTabShow<0 || nTab<m_nTabShow){ //显示台桌增加
|
||
int nGame = g_aGames.size();
|
||
int nShow = (m_nTabShow<0 || m_nTabShow>nGame) ? nGame : m_nTabShow;
|
||
for(int i=nTab; i<nShow; i++){
|
||
TGame* pG = g_aGames[i];
|
||
TTableFrame* pT = new TTableFrame(NULL);
|
||
pT->Parent = m_panWeb;
|
||
pT->SetGame(pG);
|
||
m_aTables.push_back(pT);
|
||
|
||
if(m_bManual)
|
||
PostMessage(pT->Handle, UM_MANUAL_SET, true, 0);
|
||
}
|
||
|
||
ResetTableGrid();
|
||
}
|
||
else if(nTab > m_nTabShow){ //显示台桌减少
|
||
for(int i=nTab-1; i>=m_nTabShow; i--){
|
||
TTableFrame* pT = m_aTables[i];
|
||
pT->SetRun(false);
|
||
pT->SetGame(NULL);
|
||
delete pT;
|
||
m_aTables.pop_back();
|
||
}
|
||
ResetTableGrid();
|
||
}
|
||
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
pT->SetRun(m_nTabRun<0 || i<m_nTabRun);
|
||
}
|
||
}
|
||
|
||
delete pForm;
|
||
|
||
SetTableFocus();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnPolicyEditClick(TObject *Sender)
|
||
{
|
||
int iType = Sender==m_lblBetChipEdit;
|
||
TComboBox* pCB = iType ? m_cbBetChips : m_cbBetWays;
|
||
|
||
TPolicyEditForm* pForm = new TPolicyEditForm(this, iType);
|
||
|
||
if(pForm->ShowModal()==mrOk){
|
||
}
|
||
|
||
delete pForm;
|
||
|
||
SetTableFocus();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnPolicyChange(TObject *Sender)
|
||
{
|
||
TComboBox* combo = (TComboBox*)Sender;
|
||
int& iPolicy = Sender==m_cbBetWays ? g_iBetPolicy : g_iChipPolicy;
|
||
|
||
int ind = combo->ItemIndex;
|
||
if( ind!=iPolicy ){
|
||
iPolicy = ind;
|
||
|
||
if(ind<0){
|
||
combo->Text = combo->Hint;
|
||
|
||
if(combo==m_cbBetChips){
|
||
g_nChipMul = 0;
|
||
m_leChipMul->Text = "";
|
||
m_leChipMul->Enabled = false;
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
if(combo==m_cbBetChips){ //根据最小注码调整倍数
|
||
if(g_aChipPolicies[ind]->kind==KIND_CHIP_COM){
|
||
g_nChipMul = 0;
|
||
m_leChipMul->Text = "";
|
||
m_leChipMul->Enabled = false;
|
||
}
|
||
else{
|
||
RecalcMultiRate();
|
||
}
|
||
}
|
||
else{ //根据打法改变路珠显示
|
||
m_cbRoad->ItemIndex = ((TBetPolicy*)g_aBetPolicies[ind])->road;
|
||
OnRoadChange(m_cbRoad);
|
||
}
|
||
|
||
if(g_bGameOn){
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
TGame* pG = pT->m_pGame;
|
||
if(pG && pG->bRun && !pG->bIndPolicy){
|
||
pG->AutoBetOff();
|
||
pG->AutoBetOn();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
SetTableFocus();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::RecalcMultiRate()
|
||
{
|
||
int minChip = ((TChipPolicy*)g_aChipPolicies[g_iChipPolicy])->miniChip;
|
||
if(minChip>0){
|
||
int multi = g_MinOnBet / minChip;
|
||
if(g_MinOnBet % minChip) multi++;
|
||
|
||
if(g_nChipMul<multi){
|
||
g_nChipMul = multi;
|
||
m_leChipMul->Text = IntToStr(multi);
|
||
m_leChipMul->Enabled = true;
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
int __fastcall TMainForm::IsPolicyInUse(int type, int iPolicy)
|
||
{
|
||
int& rgP = type==TYPE_P_BET ? g_iBetPolicy : g_iChipPolicy;
|
||
if(g_bGameOn && rgP==iPolicy)
|
||
return 1;
|
||
|
||
for(int i=0; i<m_aTables.size(); i++){
|
||
TTableFrame* pT = m_aTables[i];
|
||
int& rP = type==TYPE_P_BET ? pT->m_pGame->iBetPolicy
|
||
: pT->m_pGame->iChipPolicy;
|
||
if(rP==iPolicy)
|
||
return 2;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
Int8 __fastcall TMainForm::ShowSettingForm()
|
||
{
|
||
SettingForm = new TSettingForm(NULL);
|
||
TPoint pt = TPoint(m_panTopBar->Left + m_btnSetting->Left
|
||
+ m_btnSetting->Width - SettingForm->Width, m_panWeb->Top);
|
||
pt = ClientToScreen(pt);
|
||
SettingForm->Top = pt.y;
|
||
SettingForm->Left = pt.x;
|
||
|
||
Int8 ret = SettingForm->ShowModal();
|
||
|
||
delete SettingForm;
|
||
SettingForm = NULL;
|
||
|
||
SetTableFocus();
|
||
|
||
return ret;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnLoginClick(TObject *Sender)
|
||
{
|
||
if(g_bGameOn){
|
||
int mrRet = MessageBox(Handle, L"正在挂机中,是否确定重新登录?", L"登录",
|
||
MB_ICONQUESTION | MB_OKCANCEL);
|
||
|
||
if( mrRet==mrCancel ){
|
||
goto LoginExit;
|
||
}
|
||
else{
|
||
GameOff();
|
||
}
|
||
}
|
||
|
||
if(g_aGames.nBetted[0] || g_aGames.nBetted[1]){
|
||
int mrRet = MessageBox(Handle, L"尚有结算未完成,是否确定重新登录?", L"登录",
|
||
MB_ICONQUESTION | MB_OKCANCEL);
|
||
|
||
if( mrRet==mrCancel ){
|
||
goto LoginExit;
|
||
}
|
||
}
|
||
|
||
TPoint pt = TPoint(m_panTopBar->Left + m_btnLogin->Left,
|
||
m_panTopBar->Top + m_btnLogin->Top + m_btnLogin->Height);
|
||
pt = ClientToScreen(pt);
|
||
m_pmLogin->Popup( pt.x, pt.y );
|
||
|
||
LoginExit:
|
||
SetTableFocus();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnLoginMenuClick(TObject *Sender)
|
||
{
|
||
TMenuItem* pMI = (TMenuItem*)Sender;
|
||
// SetTableFocus();
|
||
PostMessage( Handle, UM_WEBLOGIN, pMI->Tag, 0 );
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnAccountClick(TObject *Sender)
|
||
{
|
||
if(!m_frmInfo->m_lblAccName->Caption.IsEmpty()){
|
||
Clipboard()->AsText = m_frmInfo->m_lblAccName->Caption;
|
||
ShowMessage("账号已复制到剪切板");
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnChipMulExit(TObject *Sender)
|
||
{
|
||
int minChip = ((TChipPolicy*)g_aChipPolicies[g_iChipPolicy])->miniChip;
|
||
int mul = m_leChipMul->Text.ToInt();
|
||
if(minChip * mul < g_MinOnBet){
|
||
int multi = g_MinOnBet / minChip;
|
||
if(g_MinOnBet % minChip) multi++;
|
||
|
||
m_leChipMul->Text = IntToStr(multi);
|
||
|
||
ShowMessage("请输入适当的投注倍数\n(最小值:" + IntToStr(multi) + ")");
|
||
|
||
m_leChipMul->SetFocus();
|
||
}
|
||
else
|
||
g_nChipMul = mul;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnLogsClick(TObject *Sender)
|
||
{
|
||
if(!BetLogForm){
|
||
BetLogForm = new TBetLogForm(this);
|
||
|
||
TPoint pt = TPoint(ClientWidth - BetLogForm->Width, m_panWeb->Top);
|
||
pt = ClientToScreen(pt);
|
||
BetLogForm->Left = pt.x;
|
||
BetLogForm->Top = pt.y;
|
||
|
||
BetLogForm->Show();
|
||
}
|
||
else{
|
||
BetLogForm->BringToFront();
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnChartClick(TObject *Sender)
|
||
{
|
||
if(!ChartForm){
|
||
//初始化图表数据
|
||
TDot dot;
|
||
if(g_aDots[0].empty()){
|
||
double pro = g_aGames.betData.profits[0];
|
||
dot.val = pro<0 ? pro - 0.5 : pro + 0.5;
|
||
g_aDots[0].push_back(dot);
|
||
}
|
||
if(g_aDots[1].empty()){
|
||
dot.val = g_settings.fSimAcc + 0.5;
|
||
g_aDots[1].push_back(dot);
|
||
}
|
||
if(g_aDots[2].empty()){
|
||
dot.val = g_fBalance + 0.5;
|
||
g_aDots[2].push_back(dot);
|
||
}
|
||
if(g_aDots[3].empty()){
|
||
dot.val = g_aGames.betData.counts[0] - g_aGames.betData.counts[1];
|
||
g_aDots[3].push_back(dot);
|
||
}
|
||
|
||
ChartForm = new TChartForm(this);
|
||
|
||
TPoint pt = TPoint(0, ClientHeight - ChartForm->Height - DPIY(4));
|
||
pt = ClientToScreen(pt);
|
||
ChartForm->Left = pt.x;
|
||
ChartForm->Top = pt.y;
|
||
ChartForm->Show();
|
||
}
|
||
else{
|
||
if(ChartForm->WindowState==wsMinimized)
|
||
ChartForm->WindowState = wsNormal;
|
||
|
||
ChartForm->BringToFront();
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnSettingClick(TObject *Sender)
|
||
{
|
||
ShowSettingForm();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnResetClick(TObject *Sender)
|
||
{
|
||
ResetForm = new TResetForm(NULL);
|
||
TPoint pt = TPoint( m_panTopBar->Left + m_btnReset->Left
|
||
+ (m_btnReset->Width - ResetForm->Width)/ 2
|
||
, m_panWeb->Top);
|
||
pt = ClientToScreen(pt);
|
||
ResetForm->Left = pt.x;
|
||
ResetForm->Top = pt.y;
|
||
|
||
ResetForm->ShowModal();
|
||
|
||
delete ResetForm;
|
||
ResetForm = NULL;
|
||
|
||
SetTableFocus();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnModeClick(TObject *Sender)
|
||
{
|
||
g_bSimulate = m_tsMode->State==tssOff;
|
||
if(g_bSimulate){
|
||
if(g_bGameOn)
|
||
g_aGames.betData.profits[6] = 0;
|
||
|
||
if(g_settings.bSimAccOn){
|
||
m_frmInfo->m_lblAccountTitle->Caption = "本金";
|
||
m_frmInfo->m_lblAccount->Caption = FormatFloat("0.##",g_settings.fSimAcc);
|
||
}
|
||
}
|
||
else{
|
||
if(g_bGameOn)
|
||
g_aGames.betData.profits[7] = 0;
|
||
|
||
if(g_settings.bSimAccOn){
|
||
m_frmInfo->m_lblAccountTitle->Caption = "余额";
|
||
m_frmInfo->m_lblAccount->Caption = FormatFloat("0.##",g_fBalance);
|
||
}
|
||
}
|
||
m_frmInfo->m_lblSRTitle->Caption = g_bSimulate ? "当前模拟:" : "当前实打:";
|
||
m_frmInfo->m_lblSRProfit->Caption = "";
|
||
|
||
if(g_bGameOn){
|
||
TBetLog* pLog = new TBetLog;
|
||
pLog->ts = DateTimeToUnix(Now(), false);
|
||
pLog->ev = LOGEVT_SWITCH;
|
||
pLog->op = g_bSimulate;
|
||
SendMessage(Handle, UM_LOG_UPDATE, 0, (long)pLog);
|
||
}
|
||
|
||
SetTableFocus();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnManualClick(TObject *Sender)
|
||
{
|
||
if(!m_bManual){
|
||
ManualOn();
|
||
}
|
||
else{
|
||
ManualOff();
|
||
}
|
||
|
||
SetTableFocus();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnChipMulKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
|
||
{
|
||
if( Key==13 )
|
||
SetTableFocus();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::RBReport()
|
||
{
|
||
if(!g_uid || !g_nRBReport || m_sActCode.Length() || g_bTesting)
|
||
return;
|
||
|
||
ClearURThread();
|
||
|
||
char arrMap[3][2][MAX_STR_LEN] = {
|
||
{"op", "rbReport"},
|
||
{"uid", ""},
|
||
{"amo", ""}
|
||
};
|
||
sprintf( arrMap[1][1], "%d", g_uid );
|
||
sprintf( arrMap[2][1], "%d", g_nRBReport );
|
||
|
||
int num = 3, str_len;
|
||
char strEncode[256];
|
||
int ret = PM_ParamEncode( strEncode, &str_len, arrMap, num );
|
||
|
||
m_urThread = new TAsynHttpThread( Handle, urServer, "Api", strEncode, str_len, UR_REPORT );
|
||
m_urThread->Start();
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::Logout()
|
||
{
|
||
if(!g_uid || !m_idDevice || !m_sActCode.Length())
|
||
return;
|
||
|
||
ClearURThread();
|
||
|
||
char arrMap[3][2][MAX_STR_LEN] = {
|
||
{"op", "rbLogout"},
|
||
{"uid", ""},
|
||
{"did", ""}
|
||
};
|
||
sprintf( arrMap[1][1], "%u", g_uid );
|
||
sprintf( arrMap[2][1], "%u", m_idDevice );
|
||
|
||
int num = 3, str_len;
|
||
char strEncode[256];
|
||
int ret = PM_ParamEncode( strEncode, &str_len, arrMap, num );
|
||
|
||
m_urThread = new TAsynHttpThread( Handle, urServer, "Api", strEncode, str_len, UR_LOGOUT );
|
||
m_urThread->Start();
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::SetExpireJS()
|
||
{
|
||
if(m_bWebLogon){
|
||
String strJS = Format(g_iPlatform==PF_PA ? expireJS_PA
|
||
: g_iPlatform==PF_AB ? expireJS_AB
|
||
: expireJS_DB,
|
||
ARRAYOFCONST((g_uid, m_tExpire)));
|
||
m_chrm->ExecuteJavaScript( strJS, "", 0 );
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
int __fastcall TMainForm::GetTimeCount()
|
||
{
|
||
time_t t;
|
||
struct tm *tm;
|
||
time(&t);
|
||
tm = localtime(&t);
|
||
|
||
return tm->tm_hour * 60 * 60 + tm->tm_min * 60 + tm->tm_sec;
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
void __fastcall TMainForm::LoadUrl()
|
||
{
|
||
m_chrm->LoadURL(g_iPlatform==PF_PA ? (String)websites[m_iWS] : m_url);
|
||
m_lblTips->Caption = "正在连接网站...";
|
||
|
||
//修改title
|
||
String platform = g_iPlatform==PF_DB ? "多宝(DB)"
|
||
: g_iPlatform==PF_AB ? "欧博(ABG)"
|
||
: "PA视讯(AG)";
|
||
// String title = Caption;
|
||
// int pos = title.Pos("当前游戏:");
|
||
// if(pos>0){
|
||
// title = title.SubString(1, pos+4);
|
||
// title += platform;
|
||
// }
|
||
// else{
|
||
// title += " 当前游戏:" + platform;
|
||
// }
|
||
//
|
||
// Caption = title;
|
||
m_lblPlatform->Caption = platform;
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::SetTableFocus()
|
||
{
|
||
if(!m_aTables.empty()){
|
||
TWinControl* pCtrl = ActiveControl;
|
||
if(!pCtrl || !pCtrl->ClassNameIs(TDrawGrid::ClassName())
|
||
&& !pCtrl->ClassNameIs(TStringGrid::ClassName())){
|
||
int sp = m_panWeb->VertScrollBar->Position,
|
||
r = sp / TFHEIGHT;
|
||
if(sp % TFHEIGHT > DPIY(20)) r++;
|
||
|
||
m_aTables[r * m_nTabCols]->m_dgRoad->SetFocus();
|
||
DebugPrint("Set focus on table row: %d", r);
|
||
}
|
||
}
|
||
else if(m_panWeb->Showing){
|
||
m_panWeb->SetFocus();
|
||
}
|
||
}
|
||
// ---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnComboCloseUp(TObject *Sender)
|
||
{
|
||
SetTableFocus();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
int __fastcall TMainForm::GetTableByPos(int x, int y)
|
||
{
|
||
int row = (m_panWeb->VertScrollBar->Position + y) / TFHEIGHT,
|
||
col = x / (TFWIDTH + m_nTabGap);
|
||
|
||
if( x % (TFWIDTH + m_nTabGap) > TFWIDTH)
|
||
return -1;
|
||
|
||
int n = row * m_nTabCols + col;
|
||
if(n < m_aTables.size())
|
||
return n;
|
||
|
||
return -1;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
TForm *fmMask = NULL;
|
||
int xDown, yDown, xMove, yMove;
|
||
int spDown, spMove; //滚动条位置(起始/上次)
|
||
int mode; //集合运算 0=none单集(b) 1=shift并集(a+b) 2=ctrl对称差集(a+b-a^b)
|
||
set<int> setSel, setUns;
|
||
|
||
void __fastcall TMainForm::WebMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
|
||
{
|
||
if(m_aTables.empty() || m_bManual) //开启手工不进行台桌选择
|
||
return;
|
||
|
||
setSel.clear();
|
||
setUns.clear();
|
||
|
||
if( Button==mbRight ){
|
||
if(Sender!=m_panWeb){
|
||
TPoint pt = ((TControl*)Sender)->ClientToParent(TPoint(X,Y), m_panWeb);
|
||
X = pt.x;
|
||
Y = pt.y;
|
||
}
|
||
|
||
int iSel = GetTableByPos(X, Y);
|
||
set<int>::iterator it = m_aSelTabs.find(iSel);
|
||
if(it==m_aSelTabs.end()){ //未点击选中项
|
||
for(it=m_aSelTabs.begin(); it!=m_aSelTabs.end(); it++){
|
||
m_aTables[*it]->SetSel(false);
|
||
}
|
||
m_aSelTabs.clear();
|
||
m_iLastSel = -1;
|
||
}
|
||
}
|
||
else if( Button==mbLeft ){
|
||
if(Sender!=m_panWeb){
|
||
TPoint pt = ((TControl*)Sender)->ClientToParent(TPoint(X,Y), m_panWeb);
|
||
X = pt.x;
|
||
Y = pt.y;
|
||
}
|
||
|
||
int iSel = GetTableByPos(X, Y);
|
||
|
||
if(Shift.Contains(ssShift)){
|
||
if(iSel>=0){
|
||
if(m_iLastSel<0){
|
||
m_aTables[iSel]->SetSel(true);
|
||
m_aSelTabs.insert(iSel);
|
||
m_iLastSel = iSel;
|
||
}
|
||
else{
|
||
int iF = iSel < m_iLastSel ? iSel : m_iLastSel,
|
||
iL = iF==iSel ? m_iLastSel : iSel;
|
||
|
||
set<int>::iterator it = m_aSelTabs.begin();
|
||
while(it!=m_aSelTabs.end()){ //先删
|
||
if(*it < iF || *it > iL){
|
||
m_aTables[*it]->SetSel(false);
|
||
it = m_aSelTabs.erase(it);
|
||
}
|
||
else
|
||
it++;
|
||
}
|
||
|
||
LockWindowUpdate( m_panWeb->Handle );
|
||
for(int i=iF; i<=iL; i++){ //后加
|
||
it = m_aSelTabs.find(i);
|
||
if(it==m_aSelTabs.end()){
|
||
m_aTables[i]->SetSel(true);
|
||
m_aSelTabs.insert(i);
|
||
}
|
||
}
|
||
LockWindowUpdate( 0 );
|
||
}
|
||
}
|
||
|
||
mode = 1;
|
||
}
|
||
else if(Shift.Contains(ssCtrl)){
|
||
if(iSel>=0){
|
||
set<int>::iterator it = m_aSelTabs.find(iSel);
|
||
if(it==m_aSelTabs.end()){
|
||
LockWindowUpdate( m_panWeb->Handle );
|
||
m_aTables[iSel]->SetSel(true);
|
||
setSel.insert(iSel);
|
||
LockWindowUpdate( 0 );
|
||
}
|
||
else{
|
||
m_aTables[iSel]->SetSel(false);
|
||
setUns.insert(iSel);
|
||
}
|
||
|
||
m_iLastSel = iSel;
|
||
}
|
||
|
||
mode = 2;
|
||
}
|
||
else{
|
||
set<int>::iterator it = m_aSelTabs.begin();
|
||
while(it!=m_aSelTabs.end()){
|
||
if(*it!=iSel){
|
||
m_aTables[*it]->SetSel(false);
|
||
it = m_aSelTabs.erase(it);
|
||
}
|
||
else
|
||
it++;
|
||
}
|
||
|
||
if(iSel>=0){
|
||
if(m_aSelTabs.empty()){
|
||
LockWindowUpdate( m_panWeb->Handle );
|
||
m_aTables[iSel]->SetSel(true);
|
||
m_aSelTabs.insert(iSel);
|
||
LockWindowUpdate( 0 );
|
||
}
|
||
}
|
||
|
||
m_iLastSel = iSel;
|
||
mode = 0;
|
||
}
|
||
|
||
spDown = m_panWeb->VertScrollBar->Position;
|
||
xDown = X, yDown = Y;
|
||
m_bDragReady = true;
|
||
SetCapture( m_panWeb->Handle );
|
||
// DebugPrint("Captured");
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WebMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
|
||
{
|
||
if(m_bDragReady){
|
||
if( abs(X-xDown)>=5
|
||
|| abs(Y-yDown)>=5 ){ //开始拖动
|
||
m_bDragReady = false;
|
||
m_bDraging = true;
|
||
// DebugPrint("beging draging");
|
||
|
||
int l = xDown<X ? xDown : X,
|
||
t = yDown<Y ? yDown : Y,
|
||
w = abs(X - xDown),
|
||
h = abs(Y - yDown);
|
||
xMove = X, yMove = Y;
|
||
spMove = m_panWeb->VertScrollBar->Position;
|
||
|
||
LockWindowUpdate( m_panWeb->Handle );
|
||
if(!fmMask){
|
||
fmMask = new TForm((HWND)NULL);
|
||
fmMask->Visible = false;
|
||
fmMask->Parent = m_panWeb;
|
||
fmMask->Position = poDesigned;
|
||
// fmMask->FormStyle = fsStayOnTop;
|
||
fmMask->BorderStyle = bsNone;
|
||
fmMask->AlphaBlend = true;
|
||
fmMask->AlphaBlendValue = 60;
|
||
fmMask->Color = clBlack;
|
||
fmMask->DoubleBuffered = true;
|
||
fmMask->ParentDoubleBuffered = false;
|
||
}
|
||
|
||
fmMask->SetBounds(l, t, w, h);
|
||
fmMask->Show();
|
||
LockWindowUpdate( 0 );
|
||
}
|
||
}
|
||
else if(m_bDraging){
|
||
if(spMove==m_panWeb->VertScrollBar->Position && xMove==X && yMove==Y) //位置未改变
|
||
return;
|
||
|
||
if(fmMask){
|
||
xMove = X, yMove = Y;
|
||
spMove = m_panWeb->VertScrollBar->Position;
|
||
|
||
int dY = spMove - spDown;
|
||
int x0 = xDown,
|
||
y0 = dY ? Min(Max(yDown - dY, 2), m_panWeb->Height - 4 ) : yDown,
|
||
x1 = Min( Max(X, 2), m_panWeb->Width - DPIX(22) ),
|
||
y1 = Min( Max(Y, 2), m_panWeb->Height - 4 );
|
||
int l = x0<x1 ? x0 : x1,
|
||
t = y0<y1 ? y0 : y1,
|
||
w = abs(x1 - x0),
|
||
h = abs(y1 - y0);
|
||
|
||
LockWindowUpdate( m_panWeb->Handle );
|
||
fmMask->SetBounds(l, t, w, h);
|
||
SelectTables(xDown, yDown + spDown, x1, y1 + spMove);
|
||
LockWindowUpdate(0);
|
||
}
|
||
|
||
SetScrollTimer(Y);
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WebMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
|
||
{
|
||
if(m_aTables.empty())
|
||
return;
|
||
|
||
if( Button==mbRight && Shift.Empty() ){
|
||
if(!m_aSelTabs.empty()){
|
||
TPoint pt = ((TControl*)Sender)->ClientToScreen(TPoint(X,Y));
|
||
m_pmRight->Popup( pt.x, pt.y );
|
||
}
|
||
}
|
||
else if( Button==mbLeft ){
|
||
if(m_bDragReady || m_bDraging){
|
||
if(!setSel.empty()){
|
||
m_aSelTabs.insert(setSel.begin(), setSel.end());
|
||
setSel.clear();
|
||
}
|
||
if(!setUns.empty()){
|
||
for(set<int>::iterator it=setUns.begin(); it!=setUns.end(); it++)
|
||
m_aSelTabs.erase(*it);
|
||
setUns.clear();
|
||
}
|
||
|
||
if(fmMask){
|
||
LockWindowUpdate( m_panWeb->Handle );
|
||
delete fmMask;
|
||
fmMask = NULL;
|
||
LockWindowUpdate(0);
|
||
}
|
||
|
||
m_bDragReady = m_bDraging = false;
|
||
ReleaseCapture();
|
||
// DebugPrint("Release capture");
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::SetScrollTimer(int y)
|
||
{
|
||
int maxY = m_panWeb->VertScrollBar->Range - m_panWeb->Height;
|
||
if( maxY > 0 ){
|
||
short iDirect = 0;
|
||
if( y > m_panWeb->Height && m_panWeb->VertScrollBar->Position < maxY )
|
||
iDirect = 1;
|
||
else if( y < 0 && m_panWeb->VertScrollBar->Position > 0 )
|
||
iDirect = -1;
|
||
|
||
if( iDirect!=0 ){
|
||
if( !m_pDragTimer ){
|
||
m_pDragTimer = new TTimer(this);
|
||
m_pDragTimer->OnTimer = ScrollTimerProc;
|
||
m_pDragTimer->Tag = iDirect;
|
||
m_pDragTimer->Interval = 500;
|
||
m_pDragTimer->Enabled = true;
|
||
}
|
||
}
|
||
else if( m_pDragTimer ){
|
||
delete m_pDragTimer;
|
||
m_pDragTimer = NULL;
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ScrollTimerProc(TObject* Sender)
|
||
{
|
||
if( m_bDraging ){
|
||
// DebugPrint( "On timer." );
|
||
|
||
if( m_pDragTimer->Tag!=0 ){
|
||
int iDirect = m_pDragTimer->Tag;
|
||
|
||
LockWindowUpdate( m_panWeb->Handle );
|
||
m_panWeb->Perform(WM_VSCROLL, iDirect>0 ? SB_LINEDOWN : SB_LINEUP, 0);
|
||
|
||
spMove = m_panWeb->VertScrollBar->Position;
|
||
int dY = spMove - spDown;
|
||
int x0 = xDown,
|
||
y0 = Min(Max(yDown - dY, 2), m_panWeb->Height - 4 ),
|
||
x1 = Min( Max(xMove, 2), m_panWeb->Width - DPIX(22) ),
|
||
y1 = Min( Max(yMove, 2), m_panWeb->Height - 4 );
|
||
int l = x0<x1 ? x0 : x1,
|
||
t = y0<y1 ? y0 : y1,
|
||
w = abs(x1 - x0),
|
||
h = abs(y1 - y0);
|
||
|
||
fmMask->SetBounds(l, t, w, h);
|
||
SelectTables(xDown, yDown + spDown, x1, y1 + spMove);
|
||
LockWindowUpdate(0);
|
||
|
||
int maxY = m_panWeb->VertScrollBar->Range - m_panWeb->Height;
|
||
if( spMove<=0 || spMove>=maxY ){
|
||
delete m_pDragTimer;
|
||
m_pDragTimer = NULL;
|
||
}
|
||
else if( m_pDragTimer->Interval>200 ){
|
||
m_pDragTimer->Interval = 200;
|
||
}
|
||
}
|
||
}
|
||
else if( m_pDragTimer ){
|
||
delete m_pDragTimer;
|
||
m_pDragTimer = NULL;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
set<int> aLastSel;
|
||
void __fastcall TMainForm::SelectTables(int x1, int y1, int x2, int y2)
|
||
{
|
||
set<int> aSel;
|
||
|
||
int r1 = (y1) / TFHEIGHT,
|
||
c1 = x1 / (TFWIDTH + m_nTabGap),
|
||
r2 = (y2) / TFHEIGHT,
|
||
c2 = x2 / (TFWIDTH + m_nTabGap);
|
||
bool g1 = x1 % (TFWIDTH + m_nTabGap) > TFWIDTH,
|
||
g2 = x2 % (TFWIDTH + m_nTabGap) > TFWIDTH;
|
||
|
||
if( c1<c2 && g1)
|
||
c1++;
|
||
else if(c1>c2 && g2)
|
||
c2++;
|
||
else if(c1==c2 && g1 && g2)
|
||
c1 = c2 = -1;
|
||
|
||
if(c1>=0){
|
||
int sr = r1<r2 ? r1 : r2,
|
||
er = sr==r1 ? r2 : r1,
|
||
sc = c1<c2 ? c1 : c2,
|
||
ec = sc==c1 ? c2 : c1;
|
||
|
||
for(int r=sr; r<=er; r++){
|
||
for(int c=sc; c<=ec; c++){
|
||
int n = r * m_nTabCols + c;
|
||
if(n < m_aTables.size())
|
||
aSel.insert(n);
|
||
else
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if(aSel==aLastSel)
|
||
return;
|
||
|
||
aLastSel = aSel;
|
||
|
||
set<int> sel, uns;
|
||
if(mode==0){
|
||
set_difference(m_aSelTabs.begin(), m_aSelTabs.end(), aSel.begin(), aSel.end(), inserter(uns, uns.begin()));
|
||
set_difference(aSel.begin(), aSel.end(), m_aSelTabs.begin(), m_aSelTabs.end(), inserter(sel, sel.begin()));
|
||
|
||
set<int> tmpSel, tmpUns;
|
||
set_difference(setUns.begin(), setUns.end(), uns.begin(), uns.end(), inserter(tmpSel, tmpSel.begin()));
|
||
set_difference(setSel.begin(), setSel.end(), sel.begin(), sel.end(), inserter(tmpUns, tmpUns.begin()));
|
||
setSel = sel;
|
||
setUns = uns;
|
||
|
||
sel.insert(tmpSel.begin(), tmpSel.end());
|
||
uns.insert(tmpUns.begin(), tmpUns.end());
|
||
|
||
set<int>::iterator it = uns.begin();
|
||
while(it!=uns.end()){
|
||
m_aTables[*it]->SetSel(false);
|
||
it++;
|
||
}
|
||
|
||
it = sel.begin();
|
||
while(it!=sel.end()){
|
||
m_aTables[*it]->SetSel(true);
|
||
it++;
|
||
}
|
||
}
|
||
else if(mode==1){
|
||
set_difference(setSel.begin(), setSel.end(), aSel.begin(), aSel.end(), inserter(uns, uns.begin()));
|
||
set_difference(aSel.begin(), aSel.end(), m_aSelTabs.begin(), m_aSelTabs.end(), inserter(sel, sel.begin()));
|
||
|
||
set<int>::iterator it = uns.begin();
|
||
while(it!=uns.end()){
|
||
m_aTables[*it]->SetSel(false);
|
||
it++;
|
||
}
|
||
|
||
it = sel.begin();
|
||
while(it!=sel.end()){
|
||
m_aTables[*it]->SetSel(true);
|
||
it++;
|
||
}
|
||
|
||
setSel = sel;
|
||
}
|
||
else if(mode==2){
|
||
set_intersection(m_aSelTabs.begin(), m_aSelTabs.end(), aSel.begin(), aSel.end(), inserter(uns, uns.begin()));
|
||
set_difference(aSel.begin(), aSel.end(), uns.begin(), uns.end(), inserter(sel, sel.begin()));
|
||
|
||
set<int> tmpSel, tmpUns;
|
||
set_difference(setUns.begin(), setUns.end(), uns.begin(), uns.end(), inserter(tmpSel, tmpSel.begin()));
|
||
set_difference(setSel.begin(), setSel.end(), sel.begin(), sel.end(), inserter(tmpUns, tmpUns.begin()));
|
||
setSel = sel;
|
||
setUns = uns;
|
||
|
||
sel.insert(tmpSel.begin(), tmpSel.end());
|
||
uns.insert(tmpUns.begin(), tmpUns.end());
|
||
|
||
set<int>::iterator it = uns.begin();
|
||
while(it!=uns.end()){
|
||
m_aTables[*it]->SetSel(false);
|
||
it++;
|
||
}
|
||
|
||
it = sel.begin();
|
||
while(it!=sel.end()){
|
||
m_aTables[*it]->SetSel(true);
|
||
it++;
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::ClearSelect()
|
||
{
|
||
if(m_aSelTabs.empty())
|
||
return;
|
||
|
||
for(set<int>::iterator it = m_aSelTabs.begin(); it!=m_aSelTabs.end(); it++)
|
||
m_aTables[*it]->SetSel(false);
|
||
|
||
m_aSelTabs.clear();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnPMRightClick(TObject *Sender)
|
||
{
|
||
if(Sender==m_miUnselect){
|
||
ClearSelect();
|
||
}
|
||
else if(Sender==m_miSpec){
|
||
PostMessage(Handle, UM_OPENMAUAL, 0, 0);
|
||
}
|
||
else{
|
||
if(Sender==m_miRunOnly || Sender==m_miStopOthers){
|
||
set<int> all, uns;
|
||
for(int i=0; i<m_aTables.size(); i++)
|
||
all.insert(i);
|
||
|
||
set_difference(all.begin(), all.end(), m_aSelTabs.begin(), m_aSelTabs.end(), inserter(uns, uns.begin()));
|
||
|
||
for(set<int>::iterator it = uns.begin(); it!=uns.end(); it++)
|
||
m_aTables[*it]->SetRun(false);
|
||
}
|
||
|
||
if(Sender!=m_miStopOthers){
|
||
LockWindowUpdate( m_panWeb->Handle );
|
||
bool bR = Sender==m_miRun || Sender==m_miRunOnly;
|
||
for(set<int>::iterator it = m_aSelTabs.begin(); it!=m_aSelTabs.end(); it++)
|
||
m_aTables[*it]->SetRun( bR );
|
||
LockWindowUpdate( 0 );
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::TitleBarPaint(TObject *Sender, TCanvas *Canvas, TRect &ARect)
|
||
{
|
||
DrawTBBg(Canvas, ARect, ARect.Left, ARect.Top);
|
||
|
||
// 背景:200x79 贴块横向平铺
|
||
if( m_bmTBPBackTile && !m_bmTBPBackTile->Empty ){
|
||
int tw = m_bmTBPBackTile->Width;
|
||
for( int x = ARect.Left; x < ARect.Right; x += tw ){
|
||
if( m_bmTBPBackTile->Height == ARect.Height() )
|
||
Canvas->Draw(x, ARect.Top, m_bmTBPBackTile);
|
||
else
|
||
Canvas->StretchDraw(TRect(x, ARect.Top, x + tw, ARect.Bottom), m_bmTBPBackTile);
|
||
}
|
||
}
|
||
else{
|
||
Canvas->Brush->Color = 0x00303030;
|
||
Canvas->FillRect(ARect);
|
||
}
|
||
|
||
// 胶囊:居中,按原尺寸不拉伸
|
||
if( m_bmTBPPile && !m_bmTBPPile->Empty ){
|
||
int px = ARect.Left + (ARect.Width() - m_bmTBPPile->Width ) / 2;
|
||
int py = ARect.Top + (ARect.Height() - m_bmTBPPile->Height) / 2;
|
||
Canvas->Draw(px, py, m_bmTBPPile);
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnAIBtnClick(TObject *Sender)
|
||
{
|
||
if(AIForm){
|
||
AIForm->BringToFront();
|
||
}
|
||
else{
|
||
AIForm = new TAIForm(NULL, m_key);
|
||
AIForm->Show();
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnAIBtnPaint(TObject *Sender)
|
||
{
|
||
TSystemTitlebarButton *btn = static_cast<TSystemTitlebarButton*>(Sender);
|
||
m_btnAI = btn; // 回填指针,SyncCapHover 要用
|
||
|
||
TCanvas *c = btn->Canvas;
|
||
const int w = btn->Width, h = btn->Height;
|
||
|
||
// 1) 用面板贴图盖掉 VCL 先画的主题底色 → 视觉透明
|
||
DrawTBBg(c, TRect(0, 0, w, h), btn->Left, btn->Top);
|
||
|
||
// 2) hover / pressed
|
||
const bool hot = (btn->Tag & 1) != 0,
|
||
down = (btn->Tag & 2) != 0;
|
||
if( down ) FillCapOver(c, TRect(0,0,w,h), 0x40);
|
||
else if( hot ) FillCapOver(c, TRect(0,0,w,h), 0x30);
|
||
|
||
// 3) 外框:和最小化/关闭同色(激活白、非激活灰)
|
||
c->Brush->Style = bsClear; // 不填充,别盖掉 hover 叠加
|
||
c->Pen->Color = Active ? clWhite : TColor(0x00999999);
|
||
c->Pen->Width = 1;
|
||
c->Rectangle( TRect(DPIX(6), DPIX(5), w - DPIX(5), h - DPIX(5)) );
|
||
|
||
// 4) 文字:黄色(非激活窗用暗黄)
|
||
c->Font->Color = Active ? clYellow : TColor(0x00008080);
|
||
c->Font->Size = 10;
|
||
|
||
const String s = L"AI";
|
||
c->TextOut( (w - c->TextWidth(s)) / 2, (h - c->TextHeight(s)) / 2, s );
|
||
c->Brush->Style = bsSolid;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::DrawTBBg(TCanvas *c, const TRect &dst, int panelX, int panelY)
|
||
{
|
||
// 把标题栏贴块画进 c 的 dst 矩形;dst 左上角对应面板坐标 (panelX, panelY)
|
||
if( !m_bmTBPBackTile || m_bmTBPBackTile->Empty ){
|
||
c->Brush->Color = 0x00303030;
|
||
c->FillRect(dst);
|
||
return;
|
||
}
|
||
const int tw = m_bmTBPBackTile->Width,
|
||
th = m_bmTBPBackTile->Height;
|
||
for( int y = 0; y < dst.Height(); ){
|
||
const int sy = (panelY + y) % th;
|
||
int hh = th - sy;
|
||
if( hh > dst.Height() - y ) hh = dst.Height() - y;
|
||
for( int x = 0; x < dst.Width(); ){
|
||
const int sx = (panelX + x) % tw;
|
||
int ww = tw - sx;
|
||
if( ww > dst.Width() - x ) ww = dst.Width() - x;
|
||
c->CopyRect( TRect(dst.Left + x, dst.Top + y, dst.Left + x + ww, dst.Top + y + hh),
|
||
m_bmTBPBackTile->Canvas,
|
||
TRect(sx, sy, sx + ww, sy + hh) );
|
||
x += ww;
|
||
}
|
||
y += hh;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
static __fastcall bool PtInCapBtn(TSystemTitlebarButton *b, int x, int y)
|
||
{
|
||
return b && b->Visible &&
|
||
x >= b->Left && x < b->Left + b->Width &&
|
||
y >= b->Top && y < b->Top + b->Height;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::SetCapHover(TSystemTitlebarButton *btn, bool hot)
|
||
{
|
||
if( !btn ) return;
|
||
NativeInt t = btn->Tag & ~1;
|
||
if( hot ) t |= 1;
|
||
if( t != btn->Tag ){
|
||
btn->Tag = t;
|
||
btn->Invalidate();
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::SyncCapHover(const TPoint &pt)
|
||
{
|
||
// 纯几何判断,幂等:任意触发点都可以反复调
|
||
if( !m_tbp ) return;
|
||
SetCapHover(m_tbp->TitleButtonMin, PtInCapBtn(m_tbp->TitleButtonMin, pt.x, pt.y));
|
||
SetCapHover(m_tbp->TitleButtonRestore, PtInCapBtn(m_tbp->TitleButtonRestore, pt.x, pt.y));
|
||
SetCapHover(m_tbp->TitleButtonClose, PtInCapBtn(m_tbp->TitleButtonClose, pt.x, pt.y));
|
||
if( m_btnAI ) SetCapHover(m_btnAI, PtInCapBtn(m_btnAI, pt.x, pt.y));
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnCapPaint(TObject *Sender)
|
||
{
|
||
//按钮自绘
|
||
|
||
TSystemTitlebarButton *btn = static_cast<TSystemTitlebarButton*>(Sender);
|
||
TCanvas *c = btn->Canvas;
|
||
const int w = btn->Width, h = btn->Height;
|
||
|
||
// 1) 回填面板背景 —— 这一步才实现“透明”
|
||
DrawTBBg(c, TRect(0, 0, w, h), btn->Left, btn->Top);
|
||
|
||
// 2) hover / pressed(按 Tag 位标记,见 OnCapMouse*)
|
||
const bool hot = (btn->Tag & 1) != 0,
|
||
down = (btn->Tag & 2) != 0;
|
||
// if( btn->ButtonType == sbClose ){
|
||
if( down ) FillCapOver(c, TRect(0,0,w,h), 0x40); // 关闭键按下:偏红,见说明
|
||
else if( hot ) FillCapOver(c, TRect(0,0,w,h), 0x30);
|
||
// }
|
||
// else if( down ) FillCapOver(c, TRect(0,0,w,h), 0x40);
|
||
// else if( hot ) FillCapOver(c, TRect(0,0,w,h), 0x30);
|
||
|
||
// 3) 字形(尺寸对齐 VCL:GetSymbolSize = ScaleValue(9),符号区右下各减 1)
|
||
const int S = DPIX(9);
|
||
const int l = (w - 1 - S) / 2,
|
||
t = (h - 1 - S) / 2;
|
||
c->Pen->Color = Active ? clWhite : TColor(0x00999999); // 非激活窗是灰字
|
||
c->Pen->Width = 1;
|
||
c->Brush->Style = bsClear;
|
||
switch( btn->ButtonType ){
|
||
case sbMinimize:
|
||
c->MoveTo(l, t + S/2);
|
||
c->LineTo(l + S, t + S/2);
|
||
break;
|
||
case sbRestore:
|
||
if( WindowState == wsMaximized ){ // 最大化时画“还原”双框
|
||
c->Rectangle(l + 2, t, l + S, t + S - 2);
|
||
c->Rectangle(l, t + 2, l + S - 2, t + S);
|
||
}
|
||
else
|
||
c->Rectangle(l, t, l + S, t + S);
|
||
break;
|
||
default: // sbClose
|
||
c->MoveTo(l, t); c->LineTo(l + S, t + S);
|
||
c->MoveTo(l, t + S); c->LineTo(l + S, t);
|
||
break;
|
||
}
|
||
c->Brush->Style = bsSolid;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::FillCapOver(TCanvas *c, const TRect &r, BYTE alpha)
|
||
{
|
||
// hover 遮罩
|
||
// 预乘白色:RGB 与 alpha 同值,GDI AlphaBlend 才是“叠一层 10%~20% 白”
|
||
TRGBQuad *q = reinterpret_cast<TRGBQuad*>( m_bmCapOver->ScanLine[0] );
|
||
q->rgbBlue = q->rgbGreen = q->rgbRed = q->rgbReserved = alpha;
|
||
c->StretchDraw(r, m_bmCapOver); // TBitmap 32bpp + afPremultiplied → 走 AlphaBlend 分支
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnCapMouseDown(TObject *Sender, TMouseButton, TShiftState, int, int)
|
||
{
|
||
TControl *b=static_cast<TControl*>(Sender);
|
||
b->Tag |= 2;
|
||
b->Invalidate();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnCapMouseUp(TObject *Sender, TMouseButton, TShiftState, int, int)
|
||
{
|
||
TControl *b=static_cast<TControl*>(Sender);
|
||
b->Tag &= ~2;
|
||
b->Invalidate();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WMNCMouseMove(TWMMouse &Msg)
|
||
{
|
||
// 恢复/最大化按钮那片是窗体的 NC 区,只会来这条消息
|
||
if( m_tbp ){
|
||
SyncCapHover( m_tbp->ScreenToClient(Mouse->CursorPos) );
|
||
|
||
// 注册"离开非客户区"通知,否则移出窗口后没有收尾消息
|
||
TRACKMOUSEEVENT tme;
|
||
tme.cbSize = sizeof(tme);
|
||
tme.dwFlags = TME_LEAVE | TME_NONCLIENT;
|
||
tme.hwndTrack = Handle;
|
||
tme.dwHoverTime = HOVER_DEFAULT;
|
||
TrackMouseEvent(&tme);
|
||
}
|
||
// Result 不动,不用 Dispatch(TCustomForm 没有 WM_NCMOUSEMOVE 的处理器)
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::WMNCLeave(TMessage &Msg)
|
||
{
|
||
if( m_tbp ) SyncCapHover( TPoint(-1, -1) );
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::TBWndProc(TMessage &Message)
|
||
{
|
||
if( m_tbp ){
|
||
switch( Message.Msg ){
|
||
case WM_NCHITTEST:
|
||
{
|
||
TWMNCHitTest *ht = reinterpret_cast<TWMNCHitTest*>(&Message);
|
||
SyncCapHover( m_tbp->ScreenToClient(TPoint(ht->XPos, ht->YPos)) );
|
||
break;
|
||
}
|
||
case WM_MOUSELEAVE:
|
||
SyncCapHover( TPoint(-1, -1) );
|
||
break;
|
||
}
|
||
}
|
||
if( m_oldTbWndProc ) m_oldTbWndProc(Message); // 必须转发
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|
||
void __fastcall TMainForm::OnLogoClick(TObject *Sender)
|
||
{
|
||
// 菜单左上角贴 Logo 左下角(屏幕坐标)
|
||
TPoint p = m_imgLogo->ClientToScreen( TPoint(0, m_imgLogo->Height) );
|
||
SendMessage(Handle, WM_POPUPSYSTEMMENU, 0, LPARAM(MAKELONG(p.x, p.y)));
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|