S3RobotDlg.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:21k
源码类别:

模拟服务器

开发平台:

C/C++

  1. // S3RobotDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "S3Robot.h"
  5. #include "S3RobotDlg.h"
  6. #include "KEngine.h"
  7. #include "KIniFile.h"
  8. #include <process.h>    /* _beginthread, _endthread */
  9. #include "jxclient.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. #pragma comment(lib, "winmm.lib")
  16. const UINT g_unAppTimerEventID = 100;
  17. const UINT g_unGameDelay = 50;
  18. const char g_cszPlayerInfo[][MAX_PATH] = {
  19. "Player ID",
  20. "Current Position",
  21. "Current Mana",
  22. "Current Heath",
  23. "Server Info",
  24. "Ping Value",
  25. "Application Timer",
  26. "" // must insert this end of flag
  27. };
  28. enum enumPlayerInfo
  29. {
  30. enumPlayerID = 0,
  31. enumCurrentPosition,
  32. enumCurrentMana,
  33. enumCurrentHeath,
  34. enumServerAddress,
  35. enumPingValue,
  36. enumApplicationTimer
  37. };
  38. #define WM_CONNECT_CREATE WM_USER + 0x100
  39. #define WM_CONNECT_CLOSE WM_USER + 0x110
  40. void CALLBACK GameLoopFun(
  41. UINT uTimerID, 
  42. UINT uMsg, 
  43. DWORD_PTR dwUser, 
  44. DWORD_PTR dw1, 
  45. DWORD_PTR dw2 )
  46. {
  47. CS3RobotDlg *pDlg = reinterpret_cast< CS3RobotDlg * >( dwUser );
  48. if ( pDlg )
  49. {
  50. pDlg->PreProcess();
  51. pDlg->Process();
  52. }
  53. }
  54. void CALLBACK EventNotify( DWORD dwEventType )
  55. {
  56. HWND hWndMainDlg = AfxGetApp()->m_pMainWnd->GetSafeHwnd();
  57. if ( NULL == hWndMainDlg || FALSE == ::IsWindow( hWndMainDlg ) )
  58. {
  59. return;
  60. }
  61. switch ( dwEventType )
  62. {
  63. case SERVER_CONNECT_CREATE:
  64. PostMessage( hWndMainDlg, WM_CONNECT_CREATE, 0, 0 );
  65. break;
  66. case SERVER_CONNECT_CLOSE:
  67. PostMessage( hWndMainDlg, WM_CONNECT_CLOSE, 0, 0 );
  68. break;
  69. }
  70. }
  71. int g_nMsgProtocolSize[MAX_PROTOCOL_NUM] = 
  72. {
  73. -1, // s2c_login,
  74. -1, // s2c_logout,
  75. sizeof(BYTE), // s2c_syncend,
  76. sizeof(CURPLAYER_SYNC), // s2c_synccurplayer,
  77. -1, // s2c_synccurplayerskill
  78. sizeof(CURPLAYER_NORMAL_SYNC),// s2c_synccurplayernormal
  79. -1, // s2c_newplayer,
  80. -1, // s2c_removeplayer,
  81. sizeof(WORLD_SYNC), // s2c_syncworld,
  82. sizeof(PLAYER_SYNC), // s2c_syncplayer,
  83. sizeof(PLAYER_NORMAL_SYNC), // s2c_syncplayermin,
  84. sizeof(NPC_SYNC), // s2c_syncnpc,
  85. sizeof(NPC_NORMAL_SYNC), // s2c_syncnpcmin,
  86. sizeof(OBJ_SYNC_ADD), // s2c_objadd,
  87. sizeof(OBJ_SYNC_STATE), // s2c_syncobjstate,
  88. sizeof(OBJ_SYNC_DIR), // s2c_syncobjdir,
  89. sizeof(OBJ_SYNC_REMOVE), // s2c_objremove,
  90. sizeof(OBJ_SYNC_TRAP_ACT), // s2c_objTrapAct,
  91. sizeof(NPC_REMOVE_SYNC), // s2c_npcremove,
  92. sizeof(NPC_WALK_SYNC), // s2c_npcwalk,
  93. sizeof(NPC_RUN_SYNC), // s2c_npcrun,
  94. -1, // s2c_npcattack,
  95. -1, // s2c_npcmagic,
  96. -1, // s2c_npcjump,
  97. -1, // s2c_npctalk,
  98. sizeof(NPC_HURT_SYNC), // s2c_npchurt,
  99. sizeof(NPC_DEATH_SYNC), // s2c_npcdeath,
  100. sizeof(NPC_CHGCURCAMP_SYNC),// s2c_npcchgcurcamp,
  101. sizeof(NPC_CHGCAMP_SYNC), // s2c_npcchgcamp,
  102. sizeof(NPC_SKILL_SYNC), // s2c_skillcast,
  103. -1, // s2c_playertalk,
  104. sizeof(PLAYER_EXP_SYNC), // s2c_playerexp,
  105. sizeof(PLAYER_SEND_TEAM_INFO), // s2c_playersendteaminfo,
  106. sizeof(PLAYER_SEND_SELF_TEAM_INFO), // s2c_playersendselfteaminfo,
  107. sizeof(PLAYER_APPLY_TEAM_INFO_FALSE), // s2c_playerapplyteaminfofalse,
  108. sizeof(PLAYER_SEND_CREATE_TEAM_SUCCESS),// s2c_teamcreatesuccess,
  109. sizeof(PLAYER_SEND_CREATE_TEAM_FALSE), // s2c_teamcreatefalse,
  110. sizeof(PLAYER_TEAM_OPEN_CLOSE), // s2c_playersendteamopenclose,
  111. sizeof(PLAYER_APPLY_ADD_TEAM), // s2c_teamgetapply,
  112. sizeof(PLAYER_TEAM_ADD_MEMBER), // s2c_playersendteamaddmember,
  113. sizeof(PLAYER_LEAVE_TEAM), // s2c_playerleaveteam,
  114. sizeof(PLAYER_TEAM_CHANGE_CAPTAIN), // s2c_playerteamchangecaptain,
  115. sizeof(PLAYER_FACTION_DATA), // s2c_playerfactiondata,
  116. sizeof(PLAYER_LEAVE_FACTION), // s2c_playerleavefaction,
  117. sizeof(PLAYER_FACTION_SKILL_LEVEL), // s2c_playerfactionskilllevel,
  118. -1,//sizeof(PLAYER_SEND_CHAT_SYNC), // s2c_playersendchat,
  119. sizeof(PLAYER_LEAD_EXP_SYNC), // s2c_playersyncleadexp
  120. sizeof(PLAYER_LEVEL_UP_SYNC), // s2c_playerlevelup
  121. sizeof(PLAYER_TEAMMATE_LEVEL_SYNC), // s2c_playerteammatelevel
  122. sizeof(PLAYER_ATTRIBUTE_SYNC), // s2c_playersyncattribute
  123. sizeof(PLAYER_SKILL_LEVEL_SYNC), // s2c_playerskilllevel
  124. sizeof(ITEM_SYNC), // s2c_syncitem
  125. sizeof(ITEM_REMOVE_SYNC), // s2c_removeitem
  126. sizeof(PLAYER_MONEY_SYNC), // s2c_syncmoney
  127. sizeof(PLAYER_MOVE_ITEM_SYNC), // s2c_playermoveitem
  128. -1, // s2c_playershowui
  129. sizeof(CHAT_APPLY_ADD_FRIEND_SYNC), // s2c_chatapplyaddfriend
  130. sizeof(CHAT_ADD_FRIEND_SYNC), // s2c_chataddfriend
  131. sizeof(CHAT_REFUSE_FRIEND_SYNC), // s2c_chatrefusefriend
  132. sizeof(CHAT_ADD_FRIEND_FAIL_SYNC), // s2c_chataddfriendfail
  133. sizeof(CHAT_LOGIN_FRIEND_NONAME_SYNC), // s2c_chatloginfriendnoname
  134. sizeof(CHAT_LOGIN_FRIEND_NAME_SYNC), // s2c_chatloginfriendname
  135. sizeof(CHAT_ONE_FRIEND_DATA_SYNC), // s2c_chatonefrienddata
  136. sizeof(CHAT_FRIEND_ONLINE_SYNC), // s2c_chatfriendinline
  137. sizeof(CHAT_DELETE_FRIEND_SYNC), // s2c_chatdeletefriend
  138. sizeof(CHAT_FRIEND_OFFLINE_SYNC), // s2c_chatfriendoffline
  139. sizeof(ROLE_LIST_SYNC), // s2c_syncrolelist
  140. sizeof(TRADE_CHANGE_STATE_SYNC), // s2c_tradechangestate
  141. -1, // NPC_SET_MENU_STATE_SYNC s2c_npcsetmenustate
  142. sizeof(TRADE_MONEY_SYNC), // s2c_trademoneysync
  143. sizeof(TRADE_DECISION_SYNC), // s2c_tradedecision
  144. -1, // sizeof(CHAT_SCREENSINGLE_ERROR_SYNC) s2c_chatscreensingleerror
  145. sizeof(NPC_SYNC_STATEINFO), // s2c_syncnpcstate,
  146. -1, // sizeof(TEAM_INVITE_ADD_SYNC) s2c_teaminviteadd
  147. sizeof(TRADE_PRESS_OK_SYNC), // s2c_tradepressoksync
  148. sizeof(PING_COMMAND), // s2c_ping
  149. };
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CS3RobotDlg dialog
  152. CS3RobotDlg::CS3RobotDlg(CWnd* pParent /*=NULL*/)
  153. : CDialog(CS3RobotDlg::IDD, pParent)
  154. {
  155. //{{AFX_DATA_INIT(CS3RobotDlg)
  156. m_bCheckPostionRandom = FALSE;
  157. m_bCheckRepeatLastCmd = FALSE;
  158. m_csAccountName = _T("");
  159. m_csPassword = _T("");
  160. m_nPositionSkillID = 1;
  161. m_nPosition_x = 1;
  162. m_nPosition_y = 1;
  163. m_csSpeakMessage = _T("");
  164. m_nPlayerAction = 0;
  165. m_nPlayerLoginSelect = 0;
  166. //}}AFX_DATA_INIT
  167. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  168. m_pImgLst_InfoSmallIcon = NULL;
  169. m_pImgLst_InfoNormalIcon = NULL;
  170. m_bActiveLife = false;
  171. m_wGameTimerID = 0;
  172. InitFuntionEntry();
  173. }
  174. void CS3RobotDlg::DoDataExchange(CDataExchange* pDX)
  175. {
  176. CDialog::DoDataExchange(pDX);
  177. //{{AFX_DATA_MAP(CS3RobotDlg)
  178. DDX_Control(pDX, IDC_COPYRIGHT, m_ctrlCopyRight);
  179. DDX_Control(pDX, IDC_LIST_PLAYER_INFO, m_ctlPlayerInfoList);
  180. DDX_Control(pDX, IDC_LIST_CURRENT_MSG, m_ctlCurrentMsgList);
  181. DDX_Control(pDX, IDC_CTRL_LOGINSERVER, m_ctrlLoginServerComBox);
  182. DDX_Check(pDX, IDC_CHECK_POSITION_RANDOM, m_bCheckPostionRandom);
  183. DDX_Check(pDX, IDC_CHECK_REPEAT_LASTCOMMAND, m_bCheckRepeatLastCmd);
  184. DDX_Text(pDX, IDC_EDIT_ACCOUNTNAME, m_csAccountName);
  185. DDV_MaxChars(pDX, m_csAccountName, 32);
  186. DDX_Text(pDX, IDC_EDIT_PASSWORD, m_csPassword);
  187. DDV_MaxChars(pDX, m_csPassword, 32);
  188. DDX_Text(pDX, IDC_EDIT_POSITION_SKILLID, m_nPositionSkillID);
  189. DDV_MinMaxInt(pDX, m_nPositionSkillID, 1, 500);
  190. DDX_Text(pDX, IDC_EDIT_POSITION_X, m_nPosition_x);
  191. DDX_Text(pDX, IDC_EDIT_POSITION_Y, m_nPosition_y);
  192. DDX_Text(pDX, IDC_EDIT_SPEAK_MESSAGE, m_csSpeakMessage);
  193. DDV_MaxChars(pDX, m_csSpeakMessage, 128);
  194. DDX_Radio(pDX, IDC_RADIO_ACTION_MOVE, m_nPlayerAction);
  195. DDX_Radio(pDX, IDC_RADIO_PLAYER_FIRST, m_nPlayerLoginSelect);
  196. //}}AFX_DATA_MAP
  197. }
  198. BEGIN_MESSAGE_MAP(CS3RobotDlg, CDialog)
  199. //{{AFX_MSG_MAP(CS3RobotDlg)
  200. ON_WM_PAINT()
  201. ON_WM_QUERYDRAGICON()
  202. ON_BN_CLICKED(IDC_BTN_SEND_COMMAND, OnBtnSendCommand)
  203. ON_BN_CLICKED(IDC_BTN_USE_DEFAULT_SCTFILE, OnBtnUseDefaultSctfile)
  204. ON_BN_CLICKED(IDC_BTN_SCTIPTFILE_LOGIN, OnBtnSctiptfileLogin)
  205. ON_BN_CLICKED(IDC_RADIO_PLAYER_FIRST, OnRadioPlayerFirst)
  206. ON_BN_CLICKED(IDC_RADIO_PLAYER_SECOND, OnRadioPlayerSecond)
  207. ON_BN_CLICKED(IDC_RADIO_ACTION_MOVE, OnRadioActionMove)
  208. ON_BN_CLICKED(IDC_RADIO_ACTION_SKILL, OnRadioActionSkill)
  209. ON_BN_CLICKED(IDC_RADIO_ACTION_SPEAK, OnRadioActionSpeak)
  210. ON_BN_CLICKED(IDC_CHECK_POSITION_RANDOM, OnCheckPositionRandom)
  211. ON_BN_CLICKED(IDC_CHECK_REPEAT_LASTCOMMAND, OnCheckRepeatLastcommand)
  212. ON_WM_DESTROY()
  213. ON_WM_TIMER()
  214. ON_CBN_SELCHANGE(IDC_CTRL_LOGINSERVER, OnSelchangeCtrlLoginserver)
  215. //}}AFX_MSG_MAP
  216. ON_MESSAGE( WM_CONNECT_CREATE, OnConnectCreate )
  217. ON_MESSAGE( WM_CONNECT_CLOSE, OnConnectClose )
  218. END_MESSAGE_MAP()
  219. void CS3RobotDlg::PreProcess()
  220. {
  221. const char *pData = NULL;
  222. size_t size = 0;
  223. do
  224. {
  225. pData = GetFromServer( size );
  226. if ( !pData || 0 == size )
  227. {
  228. break;
  229. }
  230. const char *pMsg = pData;
  231. while ( pMsg < ( pData + size ) )
  232. {
  233. PROTOCOL_MSG_TYPE pmt = *( PROTOCOL_MSG_TYPE * )pMsg;
  234. ASSERT( pmt > s2c_begin && pmt < s2c_end );
  235. /*
  236.  * Process protocol
  237.  */
  238. if ( ProcessArray[pmt] )
  239. {
  240. (this->*ProcessArray[pmt])( pMsg );
  241. }
  242. /*
  243.  * Get next protocol
  244.  */
  245. int nProtocolSize = g_nMsgProtocolSize[ pmt - s2c_begin - 1 ];
  246. if ( nProtocolSize >= 0 )
  247. {
  248. pMsg += nProtocolSize;
  249. }
  250. else
  251. {
  252. unsigned short usMsgSize = *( unsigned short * )( pMsg + PROTOCOL_MSG_SIZE );
  253. pMsg += PROTOCOL_MSG_SIZE + usMsgSize;
  254. }
  255. }
  256. }while ( true );
  257. }
  258. void CS3RobotDlg::Process()
  259. {
  260. PING_COMMAND thePingCmd;
  261. thePingCmd.ProtocolType = c2s_ping;
  262. thePingCmd.m_dwTime = GetTickCount();
  263. SendToServer( reinterpret_cast< char * >( &thePingCmd ), sizeof( PING_COMMAND ) );
  264. }
  265. /////////////////////////////////////////////////////////////////////////////
  266. // CS3RobotDlg message handlers
  267. BOOL CS3RobotDlg::OnInitDialog()
  268. {
  269. CDialog::OnInitDialog();
  270. SetIcon(m_hIcon, TRUE); // Set big icon
  271. SetIcon(m_hIcon, FALSE); // Set small icon
  272. m_theLoginInfo.szAccountName[0] = 0;
  273. m_theLoginInfo.szPassword[0] = 0;
  274. m_theLoginInfo.nPlayerIndex = 0;
  275. m_ctrlCopyRight.SetURL( "mailto:liupeng@bj.kingsoft.net" );
  276. /*
  277.  * m_ctrlLoginServerComBox
  278.  */
  279. int nServerCount = 0;
  280. KIniFile iniFile;
  281. if ( iniFile.Load( "Settings\ServerList.ini" ) )
  282. {
  283. iniFile.GetInteger( "List", "Count", 0, &nServerCount );
  284. }
  285. CString csSection;
  286. char szTitle[MAX_PATH];
  287. char szAddress[MAX_PATH];
  288. int nAddressCount = 0;
  289. for ( int i=nServerCount-1; i>=0; i-- )
  290. {
  291. csSection.Format( "%d", i );
  292. szTitle[0] = 0;
  293. iniFile.GetString( csSection, "Title", NULL, szTitle, MAX_PATH );
  294. szAddress[0] = 0;
  295. iniFile.GetString( csSection, "Address", NULL, szAddress, MAX_PATH );
  296. if ( 0 != szTitle[0] )
  297. {
  298. int nPos = m_ctrlLoginServerComBox.InsertString( 0, szTitle );
  299. if ( LB_ERR != nPos && 0 != szAddress[0] )
  300. {
  301. m_ServerAddrMap.insert( SERVER_MAP::value_type( nAddressCount, szAddress ) );
  302. m_ctrlLoginServerComBox.SetItemData( nPos, nAddressCount );
  303. nAddressCount ++;
  304. }
  305. }
  306. }
  307. /*
  308.  * m_ctlPlayerInfoList
  309.  */
  310. m_ctlPlayerInfoList.SetExtendedStyle(
  311. m_ctlPlayerInfoList.GetExtendedStyle() | 
  312. LVS_EX_FULLROWSELECT | 
  313. LVS_EX_GRIDLINES );
  314. m_ctlPlayerInfoList.InsertColumn( 0, "Status", LVCFMT_LEFT, 100, 0 );
  315. m_ctlPlayerInfoList.InsertColumn( 1, "Value", LVCFMT_LEFT, 153, 1 );
  316. int nIndex = 0;
  317. while ( 0 != g_cszPlayerInfo[nIndex][0] )
  318. {
  319. m_ctlPlayerInfoList.InsertItem( nIndex, g_cszPlayerInfo[nIndex] );
  320. nIndex ++;
  321. }
  322. char szContent[MAX_PATH];
  323. if ( iniFile.Load( "RobotRecorder.ini" ) )
  324. {
  325. szContent[0] = 0;
  326. iniFile.GetString( "Logininfo", "AccountName", NULL, szContent, MAX_PATH );
  327. m_csAccountName = szContent;
  328. szContent[0] = 0;
  329. iniFile.GetString( "Logininfo", "Password", NULL, szContent, MAX_PATH );
  330. m_csPassword = szContent;
  331. }
  332. /*
  333.  * m_ctlCurrentMsgList
  334.  */
  335. m_ctlCurrentMsgList.SetExtendedStyle(
  336. m_ctlCurrentMsgList.GetExtendedStyle() | 
  337. LVS_EX_FULLROWSELECT );
  338. m_ctlCurrentMsgList.ModifyStyle( 0, LVS_NOCOLUMNHEADER, 0 );
  339. m_pImgLst_InfoSmallIcon = new CImageList();
  340. VERIFY( m_pImgLst_InfoSmallIcon->Create( 16, 16, TRUE, 0, 1 ) );
  341. m_pImgLst_InfoSmallIcon->Add( LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_INFO) ) );
  342. m_pImgLst_InfoSmallIcon->Add( LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_COR) ) );
  343. m_pImgLst_InfoSmallIcon->Add( LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_WARN) ) );
  344. m_pImgLst_InfoSmallIcon->Add( LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_WORLD) ) );
  345. m_pImgLst_InfoNormalIcon = new CImageList();
  346. VERIFY( m_pImgLst_InfoNormalIcon->Create( 32, 32, TRUE, 0, 1 ) );
  347. m_pImgLst_InfoNormalIcon->Add( LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_INFO) ) );
  348. m_pImgLst_InfoNormalIcon->Add( LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_COR) ) );
  349. m_pImgLst_InfoNormalIcon->Add( LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_WARN) ) );
  350. m_pImgLst_InfoNormalIcon->Add( LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_WORLD) ) );
  351. m_ctlCurrentMsgList.SetImageList( m_pImgLst_InfoSmallIcon, LVSIL_SMALL );
  352. m_ctlCurrentMsgList.SetImageList( m_pImgLst_InfoNormalIcon, LVSIL_NORMAL );
  353. CRect rect;
  354. m_ctlCurrentMsgList.GetWindowRect( &rect );
  355. m_ctlCurrentMsgList.InsertColumn (0, "CurrentMessage", LVCFMT_LEFT, rect.Width() - 4 );
  356. m_ctlCurrentMsgList.InsertItem( LVIF_TEXT | LVIF_IMAGE | LVIF_STATE, 0, "CurrentMessage", 0, LVIS_SELECTED, 0, 0 );
  357. m_ctlCurrentMsgList.SetItemText( 0, 0, "Welcome to sworldman world!" );
  358. /*
  359.  * Update some ctrl status
  360.  */
  361. m_ctrlLoginServerComBox.SetCurSel( 0 );
  362. ChangeServer( 0 );
  363. EnableInfoCtrl( FALSE );
  364. UpdateData( FALSE );
  365. /*
  366.  * Start up network engine
  367.  */
  368. ClientStartup();
  369. /*
  370.  * Prepare to show status
  371.  */
  372. m_unAppTimer = SetTimer( g_unAppTimerEventID, 1000, NULL );
  373. return TRUE;  // return TRUE  unless you set the focus to a control
  374. }
  375. // If you add a minimize button to your dialog, you will need the code below
  376. //  to draw the icon.  For MFC applications using the document/view model,
  377. //  this is automatically done for you by the framework.
  378. void CS3RobotDlg::OnPaint() 
  379. {
  380. if (IsIconic())
  381. {
  382. CPaintDC dc(this); // device context for painting
  383. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  384. // Center icon in client rectangle
  385. int cxIcon = GetSystemMetrics(SM_CXICON);
  386. int cyIcon = GetSystemMetrics(SM_CYICON);
  387. CRect rect;
  388. GetClientRect(&rect);
  389. int x = (rect.Width() - cxIcon + 1) / 2;
  390. int y = (rect.Height() - cyIcon + 1) / 2;
  391. // Draw the icon
  392. dc.DrawIcon(x, y, m_hIcon);
  393. }
  394. else
  395. {
  396. CDialog::OnPaint();
  397. }
  398. }
  399. HCURSOR CS3RobotDlg::OnQueryDragIcon()
  400. {
  401. return (HCURSOR) m_hIcon;
  402. }
  403. void CS3RobotDlg::OnSelchangeCtrlLoginserver() 
  404. {
  405. int nPos = m_ctrlLoginServerComBox.GetCurSel();
  406. ChangeServer( nPos );
  407. }
  408. void CS3RobotDlg::ChangeServer( int nPos )
  409. {
  410. if ( LB_ERR != nPos )
  411. {
  412. int nAddrIndex = m_ctrlLoginServerComBox.GetItemData( nPos );
  413. SERVER_MAP::iterator info = m_ServerAddrMap.find( nAddrIndex );
  414. if ( info != m_ServerAddrMap.end() )
  415. {
  416. const string &addr = (*info).second;
  417. CString csServerInfo;
  418. csServerInfo.Format( "@ %s , %d", addr.c_str(), 8888 );
  419. m_ctlPlayerInfoList.SetItemText( enumServerAddress, 1, csServerInfo );
  420. m_strServerAddr = addr;
  421. }
  422. }
  423. }
  424. void CS3RobotDlg::OnBtnSendCommand() 
  425. {
  426. }
  427. void CS3RobotDlg::OnBtnUseDefaultSctfile() 
  428. {
  429. }
  430. void CS3RobotDlg::OnOK() 
  431. {
  432. UpdateData( TRUE );
  433. if ( m_csAccountName.IsEmpty() )
  434. {
  435. AfxMessageBox( "Are you forget your name, aha?" );
  436. return;
  437. }
  438. EnableInfoCtrl( TRUE );
  439. strcpy( m_theLoginInfo.szAccountName, m_csAccountName );
  440. strcpy( m_theLoginInfo.szPassword, m_csPassword );
  441. m_theLoginInfo.nPlayerIndex = m_nPlayerLoginSelect;
  442. /*
  443.  * Connect to S3server
  444.  */
  445. InstallCallBack( EventNotify );
  446. ConnectTo( m_strServerAddr.c_str(), 8888 );
  447. /*
  448.  * Start game loop
  449.  */
  450. if ( m_wGameTimerID )
  451. {
  452. timeKillEvent( m_wGameTimerID );
  453. m_wGameTimerID = 0;
  454. }
  455. m_wGameTimerID = timeSetEvent( 
  456. g_unGameDelay, 
  457. 10,
  458. GameLoopFun, 
  459. reinterpret_cast< DWORD >( this ), 
  460. TIME_PERIODIC | TIME_CALLBACK_FUNCTION );
  461. /*
  462.  * Require to login
  463.  */
  464. BYTE szLoginInfo[33];
  465. szLoginInfo[0] = c2s_login;
  466. memcpy( &szLoginInfo[1], m_csAccountName, 31 );
  467. szLoginInfo[32] = 0;
  468. SendToServer( reinterpret_cast< char * >( szLoginInfo ), 33 );
  469. }
  470. void CS3RobotDlg::OnCancel() 
  471. {
  472. Shutdown();
  473. CDialog::OnCancel();
  474. }
  475. void CS3RobotDlg::OnBtnSctiptfileLogin() 
  476. {
  477. }
  478. void CS3RobotDlg::OnRadioPlayerFirst() 
  479. {
  480. }
  481. void CS3RobotDlg::OnRadioPlayerSecond() 
  482. {
  483. }
  484. void CS3RobotDlg::OnRadioActionMove() 
  485. {
  486. }
  487. void CS3RobotDlg::OnRadioActionSkill() 
  488. {
  489. }
  490. void CS3RobotDlg::OnRadioActionSpeak() 
  491. {
  492. }
  493. void CS3RobotDlg::OnCheckPositionRandom() 
  494. {
  495. }
  496. void CS3RobotDlg::OnCheckRepeatLastcommand() 
  497. {
  498. }
  499. void CS3RobotDlg::OnLogonSuccess()
  500. {
  501. }
  502. void CS3RobotDlg::OnWaitForLogon()
  503. {
  504. }
  505. void CS3RobotDlg::EnableInfoCtrl( BOOL bEnable /*TRUE*/ )
  506. {
  507. m_bActiveLife = (bEnable) ? true : false;
  508. /*
  509.  * when TRUE == bEnable
  510.  */
  511. m_ctlPlayerInfoList.EnableWindow( bEnable );
  512. m_ctlCurrentMsgList.EnableWindow( bEnable );
  513. EnableCtrl( IDC_RADIO_ACTION_MOVE, bEnable );
  514. EnableCtrl( IDC_RADIO_ACTION_SKILL, bEnable );
  515. EnableCtrl( IDC_RADIO_ACTION_SPEAK, bEnable );
  516. EnableCtrl( IDC_EDIT_POSITION_X, bEnable );
  517. EnableCtrl( IDC_EDIT_POSITION_Y, bEnable );
  518. EnableCtrl( IDC_SPIN1, bEnable );
  519. EnableCtrl( IDC_SPIN2, bEnable );
  520. EnableCtrl( IDC_SPIN3, bEnable );
  521. EnableCtrl( IDC_CHECK_POSITION_RANDOM, bEnable );
  522. EnableCtrl( IDC_EDIT_SPEAK_MESSAGE, bEnable );
  523. EnableCtrl( IDC_EDIT_POSITION_SKILLID, bEnable );
  524. EnableCtrl( IDC_BTN_SEND_COMMAND, bEnable );
  525. EnableCtrl( IDC_CHECK_REPEAT_LASTCOMMAND, bEnable );
  526. EnableCtrl( IDC_BTN_USE_DEFAULT_SCTFILE, bEnable );
  527. /*
  528.  * FALSE == bEnable
  529.  */
  530. BOOL bDisable = !bEnable;
  531. m_ctrlLoginServerComBox.EnableWindow( bDisable );
  532. EnableCtrl( IDC_EDIT_ACCOUNTNAME, bDisable );
  533. EnableCtrl( IDC_EDIT_PASSWORD, bDisable );
  534. EnableCtrl( IDC_RADIO_PLAYER_FIRST, bDisable );
  535. EnableCtrl( IDC_RADIO_PLAYER_SECOND, bDisable );
  536. EnableCtrl( IDC_BTN_SCTIPTFILE_LOGIN, bDisable );
  537. EnableCtrl( IDOK, bDisable );
  538. }
  539. void CS3RobotDlg::OnDestroy() 
  540. {
  541. CDialog::OnDestroy();
  542. if ( m_wGameTimerID )
  543. {
  544. timeKillEvent( m_wGameTimerID );
  545. m_wGameTimerID = 0;
  546. }
  547. KillTimer( g_unAppTimerEventID );
  548. ClientCleanup();
  549. if ( m_pImgLst_InfoSmallIcon )
  550. {
  551. delete m_pImgLst_InfoSmallIcon;
  552. m_pImgLst_InfoSmallIcon = NULL;
  553. }
  554. if ( m_pImgLst_InfoNormalIcon )
  555. {
  556. delete m_pImgLst_InfoNormalIcon;
  557. m_pImgLst_InfoNormalIcon = NULL;
  558. }
  559. UpdateData( TRUE );
  560. KIniFile iniFile;
  561. iniFile.WriteString( "Logininfo", "AccountName", m_csAccountName );
  562. iniFile.WriteString( "Logininfo", "Password", m_csPassword );
  563. iniFile.Save( "RobotRecorder.ini" );
  564. }
  565. void CS3RobotDlg::OnTimer(UINT nIDEvent) 
  566. {
  567. static TCHAR s_szBuffer[9];
  568. static unsigned long s_unTotalLifeTime = 1;
  569. static UINT unHour = 0;
  570. static UINT unMinute = 0;
  571. static UINT unSecond = 0;
  572. if ( m_bActiveLife && g_unAppTimerEventID == nIDEvent )
  573. {
  574. unHour = (UINT)( s_unTotalLifeTime / 3600 );
  575. unMinute = (UINT)( ( s_unTotalLifeTime % 3600 ) / 60 );
  576. unSecond = (UINT)( ( s_unTotalLifeTime % 3600 ) % 60 );
  577.    _stprintf( s_szBuffer, _T("%02d:%02d:%02d"),
  578.  unHour,
  579.  unMinute,
  580.  unSecond );
  581.    m_ctlPlayerInfoList.SetItemText( enumApplicationTimer, 1, s_szBuffer );
  582.    s_unTotalLifeTime ++;
  583. }
  584. CDialog::OnTimer(nIDEvent);
  585. }
  586. HRESULT CS3RobotDlg::OnConnectCreate( WPARAM wParam, LPARAM lParam )
  587. {
  588. m_ctlCurrentMsgList.InsertItem( LVIF_TEXT | LVIF_IMAGE | LVIF_STATE, 0, "CurrentMessage", 0, LVIS_SELECTED, 3, 0 );
  589. m_ctlCurrentMsgList.SetItemText( 0, 0, "Successful connect to server and wait for it confirm" );
  590. ::MessageBeep( -1 );
  591. return S_OK;
  592. }
  593. HRESULT CS3RobotDlg::OnConnectClose( WPARAM wParam, LPARAM lParam )
  594. {
  595. m_ctlCurrentMsgList.InsertItem( LVIF_TEXT | LVIF_IMAGE | LVIF_STATE, 0, "CurrentMessage", 0, LVIS_SELECTED, 2, 0 );
  596. m_ctlCurrentMsgList.SetItemText( 0, 0, "Connection was breaked" );
  597. ::MessageBeep( -1 );
  598. return S_OK;
  599. }
  600. bool CS3RobotDlg::ProcessPing( const char *pMsg )
  601. {
  602. return true;
  603. }
  604. bool CS3RobotDlg::Syncrolelist( const char *pMsg )
  605. {
  606. ROLE_LIST_SYNC *pRLS = (ROLE_LIST_SYNC *)pMsg;
  607. if ( pRLS )
  608. {
  609. for ( int i=0; i<2; i++ )
  610. {
  611. if ( 0 != pRLS->m_RoleList[i].szName[0] )
  612. {
  613. AfxMessageBox( pRLS->m_RoleList[i].szName );
  614. }
  615. else
  616. {
  617. AfxMessageBox( "not find!" );
  618. }
  619. }
  620. }
  621. return true;
  622. }
  623. void CS3RobotDlg::InitFuntionEntry()
  624. {
  625. ZeroMemory( ProcessArray, sizeof(ProcessArray) );
  626. ProcessArray[s2c_ping] = ProcessPing;
  627. ProcessArray[s2c_syncrolelist] = Syncrolelist;
  628. }