163 lines
4.1 KiB
C++
163 lines
4.1 KiB
C++
//---------------------------------------------------------------------------
|
|
#include <vcl.h>
|
|
#pragma hdrstop
|
|
|
|
#include "BacJSThread.h"
|
|
#include "UtilityUnit.h"
|
|
#include "GlobalUnit.h"
|
|
#include "GameUnit.h"
|
|
//---------------------------------------------------------------------------
|
|
#pragma package(smart_init)
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// TAutoBetThread
|
|
|
|
__fastcall TJSHandleThread::TJSHandleThread(int iOp)
|
|
{
|
|
m_op = iOp;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TJSHandleThread::Execute()
|
|
{
|
|
int ret = 0;
|
|
|
|
if( m_op==JS_OP_CHECKCEF )
|
|
ret = CheckCEF();
|
|
// else if( m_op==JS_OP_GETIPADDR )
|
|
// ret = GetIPAddr();
|
|
else if( m_op>=JS_OP_WSHANDLE0 && m_op<=JS_OP_WSHANDLE3 )
|
|
ret = GetWSHandle();
|
|
else if( m_op==JS_OP_GAMEON )
|
|
ret = GameOn();
|
|
|
|
if( !Terminated )
|
|
PostMessage( Application->MainFormHandle, UM_JSHANDLED, m_op, ret );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
int __fastcall TJSHandleThread::CheckCEF()
|
|
{
|
|
int iRet = -1;
|
|
|
|
for( int i=0; i<10; i++ ){
|
|
if( GlobalCEFApp && GlobalCEFApp->GlobalContextInitialized ){
|
|
iRet = 1;
|
|
break;
|
|
}
|
|
|
|
if( !Halt(500) )
|
|
break;
|
|
}
|
|
|
|
return iRet;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
int __fastcall TJSHandleThread::GetWSHandle()
|
|
{
|
|
int iRet = -1;
|
|
|
|
_di_ICefFrame frame = GetCefFrame(MAIN_FRAME);
|
|
if( frame ){
|
|
String sQuery;
|
|
if( g_iPlatform==PF_PA ){
|
|
sQuery = "{"
|
|
"let iRet = -1;"
|
|
"if(Core.LoginStore.instance && VideoGameCore.PlazaSocket.instance){"
|
|
"if(Core.LoginStore.instance.loginDone)"
|
|
"iRet = VideoGameCore.PlazaSocket.instance.readyState;"
|
|
"else "
|
|
"iRet = -3;"
|
|
"}"
|
|
"if(!iRet) iRet = -1;"
|
|
"cefApp.ReturnJQValue(iRet);"
|
|
"}";
|
|
}
|
|
else if( g_iPlatform==PF_AB ){
|
|
sQuery = "{"
|
|
"let iRet = -1;"
|
|
"if(Netbet && Netbet.component && Netbet.component.entity"
|
|
"&& Netbet.component.entity.manager && Netbet.component.entity.manager.ServiceManager){"
|
|
"const instSM = Netbet.component.entity.manager.ServiceManager.getInstance();"
|
|
"if(instSM && instSM.isConnected()){"
|
|
"const instUD = Netbet.component.entity.UserDO.getInstance();"
|
|
"if(instUD && instUD.getLoginSuccessTime()) iRet = 1;"
|
|
"else console.log('not login');"
|
|
"}"
|
|
"else console.log('not connect to Server');"
|
|
"}"
|
|
"else console.log(!Netbet ? 'no Netbet' : !Netbet.component ? 'no component'"
|
|
": !Netbet.component.entity ? 'no entity'"
|
|
": !Netbet.component.entity.manager ? 'no manager' : 'no service');"
|
|
|
|
"cefApp.ReturnJQValue(iRet);"
|
|
"}";
|
|
}
|
|
else if( g_iPlatform==PF_DB ){
|
|
sQuery = "{"
|
|
"let iRet = -1;"
|
|
"if(typeof App!='undefined' && App.Socket){"
|
|
"const status = App.Socket.status;"
|
|
"console.log('App.Socket.status=', status);"
|
|
|
|
"if(status==2 && App.user && App.gameManager && App.setting) "
|
|
"iRet = 1;"
|
|
"else if(status==3){"
|
|
"const reason = App.Socket._reConnectReason;"
|
|
"console.log('App.Socket._reConnectReason=', reason);"
|
|
|
|
"iRet = 3;"
|
|
|
|
"}"
|
|
"};"
|
|
"cefApp.ReturnJQValue(iRet);"
|
|
"}";
|
|
}
|
|
|
|
for( int i=0; i<60 && !Terminated; i++ ){
|
|
DebugPrint( "Try to steal websocket data step %d", m_op );
|
|
String sRet;
|
|
|
|
TStringList* strlst = GetJQValue( sQuery, frame );
|
|
if( strlst ){
|
|
if(strlst->Count==1)
|
|
sRet = (*strlst)[0];
|
|
delete strlst;
|
|
}
|
|
|
|
DebugPrint("GetJQValue return: %s", strlst ? "sRet" : "null");
|
|
if(!sRet.IsEmpty() )
|
|
TryStrToInt(sRet, iRet);
|
|
|
|
if( iRet>0 || !Halt(g_iPlatform==PF_AB ? 800 : 500) )
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(iRet==3) iRet = -3;
|
|
|
|
return iRet;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
int __fastcall TJSHandleThread::GameOn()
|
|
{
|
|
if( !Halt(100) )
|
|
return 0;
|
|
|
|
for( int i=0; i<g_aGames.size() && !Terminated && g_bGameOn; i++ ){
|
|
TGame* pG = g_aGames[i];
|
|
if(pG->bRun){
|
|
pG->GameOn();
|
|
|
|
if( !Halt(10) )
|
|
break;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|