//--------------------------------------------------------------------------- #include #include #include #include #include #pragma hdrstop #include "BacABThread.h" #include "TableUnit.h" #include "GlobalUnit.h" #include "UtilityUnit.h" #include "HookJS.h" //--------------------------------------------------------------------------- #pragma package(smart_init) ///////////////////////////////////////////////////////////////////////////// // TAutoBetThread __fastcall TAutoBetThread::TAutoBetThread(int iG) { m_iGame = iG; } //--------------------------------------------------------------------------- void __fastcall TAutoBetThread::Execute() { TGame *pGame = g_aGames.GetGame(m_iGame); if(pGame){ for(int i=0; iaManBets.size(); i++){ //优先处理手工下注 TManBet& rMB = pGame->aManBets[i]; if(rMB.state==ST_INIT){ rMB.state = ST_BETTING; int ret = RealBet(pGame, rMB.chips); if(!Terminated && ret!=0) pGame->BetResp(ret, rMB.chips); goto EXIT; //一个线程只处理一个下注 } } if(pGame->iState==ST_BETSET){ pGame->iState = ST_BETTING; if(pGame->nChip>0 && pGame->nChipBetResp(10, NULL); goto EXIT; } else if(pGame->nChip>g_MaxOnBet){ pGame->BetResp(11, NULL); goto EXIT; } int tmMinDelay = pGame->timeout - (pGame->timeout>15 ? 12 : 9); if( tmMinDelay>=0 ){ int tmMin = tmMinDelay >= 2 ? 2000 : tmMinDelay * 1000, tmMax = (pGame->timeout - (pGame->timeout>15 ? 10 : 7))*1000, tmHalt = tmMin + Random(tmMax - tmMin); if( tmHalt>0 && !Halt(tmHalt) ) goto EXIT; } if( pGame->nChip>=0 && pGame->iState==ST_BETTING && pGame->CanBet() ){//再次确认下注状态 if(g_bSimulate){ pGame->bReal = false; if(g_settings.bSimAccOn && g_settings.bNoBetLow && g_settings.fSimAcc < pGame->nChip) pGame->BetResp(26, NULL); else pGame->BetResp(0, NULL); } else if(!g_bTesting && g_fBalance < pGame->nChip){ pGame->BetResp(26, NULL); } else{ pGame->bReal = true; if(pGame->nChip==0){ pGame->BetResp(0, NULL); } else{ int ret= RealBet(pGame, NULL); if(!Terminated && ret!=0) pGame->BetResp(ret, NULL); } } } } } EXIT: if( !Terminated ) PostMessage( Application->MainFormHandle, UM_AUTOBETEND, 0, Handle ); } //--------------------------------------------------------------------------- int __fastcall TAutoBetThread::RealBet(TGame* pG, int chips[]) { _di_ICefFrame frame = GetCefFrame(MAIN_FRAME); if( !frame ) return -1; String strJS; if( g_iPlatform==PF_PA ){ strJS = "{" "if(VideoGameCore.LinkStoreFactory.instance){" "const tab=VideoGameCore.LinkStoreFactory.instance.getBetTableStore('" + pG->vid + "');" "if(tab && tab.betEnabled){"; // "console.log('======"+pG->vid+" is betEnable');"; if(chips){ for(int i=0; i<3; i++){ if(chips[i]>0){ strJS += "tab.addChipByPlayType(" + IntToStr(i+1) + "," + IntToStr(chips[i]) + ");"; } } } else{ strJS += "tab.addChipByPlayType(" + IntToStr(pG->iBet) + "," + IntToStr(pG->nChip) + ");"; } if(g_bTesting){ //测试时模拟下注反馈 int chip[3] = {0}; if(chips) memcpy(chip, chips, sizeof(chip)); else chip[pG->iBet-1] = pG->nChip; strJS += "tab.cancelBet();" "setTimeout(function(){" "const msg = '6|"+pG->vid+"|0|"+pG->gmcode; for(int i=0; i<3; i++) strJS += "|" + IntToStr(chip[i]); strJS += "';" "cefApp.OnJSMessage(msg);" "},1000);"; } else{ strJS += "tab.confirmBet();"; } strJS += "cefApp.ReturnJQValue('0');" "}else if(!tab || tab.isGameMaintaining){"// VideoGameCore.isGameMaintain('"+pG->vid+"')){" "cefApp.ReturnJQValue('2');"; if(g_bTesting) strJS += "console.log('======"+pG->vid+" is maintaining');"; strJS += "}else{" "const gms = tab.gameSnapshot ? tab.gameSnapshot.gmstatus : -1;" "const sSkt = VideoGameCore.singleSocket;" "const pSkt = VideoGameCore.PlazaSocket.instance;" "cefApp.ReturnJQValue(gms>=2 && sSkt.connected ? '3' : '');"; if(g_bTesting) strJS += "console.log('======"+pG->vid+" is not betEnable'," "'gmstatus:', gms," "'sSkt:', sSkt.connected, sSkt.readyState," "'pSkt:', pSkt.connected, pSkt.readyState);"; strJS += "if(!sSkt.connected && sSkt.readyState>1){"; if(g_bTesting) strJS += "console.log('singleSocket connect: ', sSkt.connected, sSkt.readyState);"; strJS += "sSkt.connect();" "}" "if(pSkt && !pSkt.connected && pSkt.readyState>1){"; if(g_bTesting) strJS += "console.log('PlazaSocket connect: ', pSkt.connected, pSkt.readyState);"; strJS += "pSkt.connect();" "}" "}" "}else{" "cefApp.ReturnJQValue('');"; if(g_bTesting) strJS += "console.log('======myGameLink closed');"; strJS += "}" "}"; } else if( g_iPlatform==PF_AB ){ strJS = "{" "const tid = " + IntToStr(pG->iGame) + ";" "const bts = ["; if(chips){ for(int i=0; i<3; i++){ if(chips[i]>0){ strJS += IntToStr(i+1001) + ",";// [1001|1002|1003]; } } } else{ strJS += IntToStr(pG->iBet+1000); //[1001|1002|1003]; } strJS += "];" "const bas = ["; if(chips){ for(int i=0; i<3; i++){ if(chips[i]>0){ strJS += IntToStr(chips[i] * 100) + ","; } } } else{ strJS += IntToStr(pG->nChip * 100); } strJS += "];"; strJS += "const gh = Netbet.component.entity.gameHallDO.getInstance();" "const td = gh ? gh.getTableDO(tid) : null;" "const gst = td ? td.getCurGameStatusText(td.getGameRoundId()) : 'INVALID';" "if(gst=='BETTING'){"; if(g_bTesting){ //测试时模拟下注反馈 int chip[3] = {0}; if(chips) memcpy(chip, chips, sizeof(chip)); else chip[pG->iBet-1] = pG->nChip; strJS += "setTimeout(function(){" "const msg = '6|" + IntToStr(pG->iGame) + "|0|" + pG->gmcode; for(int i=0; i<3; i++) strJS += "|" + IntToStr(chip[i]); strJS += "';" // "console.log(msg);" "cefApp.OnJSMessage(msg);" "},1000);"; } else{ strJS += "multiTableBet(tid, bts, bas);"; } strJS += "cefApp.ReturnJQValue('0');" "}else{"; if(g_bTesting) strJS += "console.log('==="+IntToStr(pG->iGame)+"==="+pG->vid+" status is '+gst);"; strJS += "cefApp.ReturnJQValue(gst=='NO_USE_STATUS'? '2' : '');" "};" "}"; } else if( g_iPlatform==PF_DB ){ strJS = "(async function(){" "const multi = App.PresenterManager.presenterDic.dict.MultiplayPresenter;" "if(multi && multi.model){" "const g = multi.model.getGameTalbeInfo("+ IntToStr(pG->iGame) + ");" "if(g){" "if(g.gameStatus!=2){" "cefApp.ReturnJQValue(3);" "return;" "}" "let res = 0;"; if(!g_bTesting){// || g_fBalance>0){ //单独测试pushChip if(chips){ for(int i=0; i<3; i++){ if(chips[i]>0){ strJS += "if(!res){" "res = await pushChip(" + IntToStr(pG->iGame) + "," + IntToStr(i+1) + "," + IntToStr(chips[i]) + ");" // "console.log('pushChip result:', res);" "if(res){" "cancelBet(" + IntToStr(pG->iGame) + ");" "cefApp.ReturnJQValue(res);" "return;" "}" "}"; } } } else{ strJS += "res = await pushChip(" + IntToStr(pG->iGame) + "," + IntToStr(pG->iBet) + "," + IntToStr(pG->nChip) + ");" // "console.log('pushChip:', res);" "if(res){" "cefApp.ReturnJQValue(res);" "return;" "}"; } } if(g_bTesting){ //测试时模拟下注反馈 int chip[3] = {0}; if(chips) memcpy(chip, chips, sizeof(chip)); else chip[pG->iBet-1] = pG->nChip; strJS +=//"cancelBet(" + IntToStr(pG->iGame) + ");" "setTimeout(function(){" "const msg = '6|" + IntToStr(pG->iGame) + "|0|" + pG->gmcode; for(int i=0; i<3; i++) strJS += "|" + IntToStr(chip[i]); strJS += "';" "cefApp.OnJSMessage(msg);" "},1000);"; } else{ strJS +="sureBet(" + IntToStr(pG->iGame) + ");"; } strJS += "cefApp.ReturnJQValue('0');" "return;" "}" "}" "cefApp.ReturnJQValue('');" //非正常状态返回 "})()"; } // DebugPrint(((AnsiString)strJS).c_str()); int ret = -1; while( !Terminated && pG->timeout>1 ){ String sMsg; TStringList* strlst = GetJQValue( strJS, frame ); if( strlst ){ if(strlst->Count==1) sMsg = (*strlst)[0]; delete strlst; } if(sMsg.Length()>0) TryStrToInt(sMsg, ret); else DebugPrint("GetJQValue return: %s", strlst ? "''" : "null"); if( ret>=0 || !Halt(1000) ) //得到结果 或 用户cancel中途退出 break; if(chips==NULL && g_bSimulate){ //改变了模式 if(g_settings.bSimAccOn && g_settings.bNoBetLow && g_settings.fSimAcc < pG->nChip){ pG->BetResp(26, NULL); } else{ pG->bReal = false; pG->BetResp(0, NULL); } ret = 0; break; } } #ifdef _DEBUG if( !Terminated && ret<0 ) DebugPrint("%s 下注超时", ((AnsiString)pG->vid).c_str()); #endif return ret<0 ? 25 : ret; } /////////////////////////////////////////////////////////////////////////////