📄 autoplayconfiger.cpp
字号:
// AutoplayConfiger.cpp : implementation file
//
#include "stdafx.h"
#include "SoccerDoctor.h"
#include "AutoplayConfiger.h"
#include "param.h"
// CAutoplayConfiger dialog
IMPLEMENT_DYNAMIC(CAutoplayConfiger, CDialog)
CAutoplayConfiger::CAutoplayConfiger(CWnd* pParent /*=NULL*/)
: CDialog(CAutoplayConfiger::IDD, pParent),_ApThread(NULL)
{
}
CAutoplayConfiger::~CAutoplayConfiger()
{
theApp.WriteProfileString("USTCWrightEagle","SoccerDoctorServerHost",_ServerAddr);
theApp.WriteProfileInt("USTCWrightEagle","SoccerDoctorServerPort",_ServerPort);
theApp.WriteProfileString("USTCWrightEagle","SoccerDoctorClientParam",_ClientParam);
theApp.WriteProfileString("USTCWrightEagle","SoccerDoctorClientPath",_ClientPath);
theApp.WriteProfileString("USTCWrightEagle","SoccerDoctorGoalieParam",_GoalieParam);
theApp.WriteProfileInt("USTCWrightEagle","SoccerDoctorGoalieNum",_GoalieNum);
if( _ApThread ){
delete _ApThread;
}
}
void CAutoplayConfiger::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_SERVPORT, _ServerPort);
DDX_Text(pDX, IDC_SERVADDR, _ServerAddr);
DDX_Text(pDX, IDC_CLIENTPATH, _ClientPath);
DDX_Text(pDX, IDC_CLIENTPARAM, _ClientParam);
DDX_Text(pDX, IDC_GOALIEPARAM, _GoalieParam);
DDX_Text(pDX, IDC_GOALIENUM, _GoalieNum);
}
BEGIN_MESSAGE_MAP(CAutoplayConfiger, CDialog)
ON_BN_CLICKED(IDC_BROWSE_CLIENT,OnBrowseClient)
ON_BN_CLICKED(IDC_AUTOPLAY,OnRunAutoplay)
END_MESSAGE_MAP()
// CAutoplayConfiger message handlers
void CAutoplayConfiger::OnBrowseClient()
{
CFileDialog openDlg(TRUE,NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, NULL, NULL,0);
if(openDlg.DoModal() == IDOK){
_ClientPath = openDlg.GetPathName();
UpdateData(FALSE);
}
}
BOOL CAutoplayConfiger::OnInitDialog()
{
CDialog::OnInitDialog();
_ServerAddr = theApp.GetProfileString("USTCWrightEagle","SoccerDoctorServerHost","localhost") ;
_ServerPort = theApp.GetProfileInt("USTCWrightEagle","SoccerDoctorServerPort",6000) ;
_ClientPath = theApp.GetProfileString("USTCWrightEagle","SoccerDoctorClientPath","Client.exe") ;
_ClientParam = theApp.GetProfileString("USTCWrightEagle","SoccerDoctorClientParam","") ;
_GoalieParam = theApp.GetProfileString("USTCWrightEagle","SoccerDoctorGoalieParam","") ;
_GoalieNum = theApp.GetProfileInt("USTCWrightEagle","SoccerDoctorGoalieNum",1) ;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAutoplayConfiger::OnRunAutoplay()
{
if( _ApThread ){
delete _ApThread;
}
_ApThread = new CAutoplayThread(_ServerAddr,
_ServerPort,_ClientPath,_ClientParam,_GoalieParam,_GoalieNum);
_ApThread->CreateThread();
}
/************************************************************************/
/* CAutoplayThread Class */
/************************************************************************/
int CAutoplayThread::Run()
{
char param[100];
CString client_dir = _ClientPath.Left(_ClientPath.ReverseFind('\\'));
HANDLE handle[MAX_PLAYER]; // 存放进程的句柄
STARTUPINFO si;
PROCESS_INFORMATION pi;
while( true ){
for( UINT i=1; i<=MAX_PLAYER; i++){
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if( i == _GoalieNum ){
sprintf(param,"%s -host %s -port %d -UNum %d %s",_ClientParam,_ServerAddr,_ServerPort,i,_GoalieParam);
}else{
sprintf(param,"%s -host %s -port %d -UNum %d ",_ClientParam,_ServerAddr,_ServerPort,i);
}
CreateProcess( _ClientPath,param,NULL,NULL,FALSE,0,NULL,client_dir,&si,&pi );
handle[i-1] = pi.hProcess;
}
WaitForMultipleObjects(MAX_PLAYER,handle,TRUE,INFINITE);
Sleep(1000*30); // 1 half minute
}
return 0;
}
BOOL CAutoplayThread::InitInstance()
{
// do nothing
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -