Clone of Akilla's acserver @ https://github.com/deregtd/ACServer

maindlg.h 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. // maindlg.h : interface of the CMainDlg class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_MAINDLG_H__4B488390_CE2F_4798_8415_47500D263534__INCLUDED_)
  5. #define AFX_MAINDLG_H__4B488390_CE2F_4798_8415_47500D263534__INCLUDED_
  6. #if _MSC_VER >= 1000
  7. #pragma once
  8. #endif // _MSC_VER >= 1000
  9. #include "..\ClientInject\ClientInject.h"
  10. #include <stdio.h>
  11. #include <io.h>
  12. #include <fcntl.h>
  13. #include <commdlg.h>
  14. HINSTANCE g_hInst;
  15. class CMainDlg : public CDialogImpl<CMainDlg>,
  16. public CMessageFilter
  17. {
  18. public:
  19. enum { IDD = IDD_MAINDLG };
  20. virtual BOOL PreTranslateMessage(MSG* pMsg)
  21. {
  22. return IsDialogMessage(pMsg);
  23. }
  24. BEGIN_MSG_MAP(CMainDlg)
  25. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  26. COMMAND_ID_HANDLER(IDOK, OnOK)
  27. COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
  28. COMMAND_HANDLER(IDC_BROWSE_CLIENT, BN_CLICKED, OnClickedBrowse_client)
  29. END_MSG_MAP()
  30. LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  31. {
  32. // center the dialog on the screen
  33. CenterWindow();
  34. // set icons
  35. HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
  36. IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
  37. SetIcon(hIcon, TRUE);
  38. HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
  39. IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
  40. SetIcon(hIconSmall, FALSE);
  41. // register object for message filtering and idle updates
  42. CMessageLoop* pLoop = _Module.GetMessageLoop();
  43. ATLASSERT(pLoop != NULL);
  44. pLoop->AddMessageFilter(this);
  45. // Lookup saved values in the registry
  46. CRegKey rk;
  47. if ( rk.Create ( HKEY_CURRENT_USER, _T( "Software\\AcEmu\\Client" ) ) != ERROR_SUCCESS )
  48. {
  49. CloseDialog ( IDCANCEL );
  50. return FALSE;
  51. }
  52. TCHAR szServer[ 255 ];
  53. DWORD dwSize = 255;
  54. enum eFirstFocus { eNone, eServer, eLogin, ePassword, eClientPath };
  55. eFirstFocus ff = eNone;
  56. if ( rk.QueryValue ( szServer, _T( "Server" ), &dwSize ) == ERROR_SUCCESS )
  57. SetDlgItemText ( IDC_SERVER, szServer );
  58. else
  59. {
  60. SetDlgItemText ( IDC_SERVER, "Server:IP" );
  61. ff = eServer;
  62. }
  63. TCHAR szUserName[ 255 ];
  64. DWORD dwUNSize = 255;
  65. if ( rk.QueryValue ( szUserName, _T( "Account" ), &dwUNSize ) == ERROR_SUCCESS )
  66. SetDlgItemText ( IDC_ACCOUNT, szUserName );
  67. else if ( ff == eNone )
  68. ff = eLogin;
  69. TCHAR szPassword[ 255 ];
  70. DWORD dwPWDSize = 255;
  71. if ( rk.QueryValue ( szPassword, _T( "Password" ), &dwPWDSize ) == ERROR_SUCCESS )
  72. {
  73. SetDlgItemText ( IDC_PASSWORD, szPassword );
  74. CheckDlgButton ( IDC_SAVEPASSWORD, BST_CHECKED );
  75. }
  76. else if ( ff == eNone )
  77. ff = ePassword;
  78. TCHAR szClientPath[ 255 ];
  79. DWORD dwCPSize = 255;
  80. if ( rk.QueryValue ( szClientPath, _T( "ClientPath" ), &dwCPSize ) == ERROR_SUCCESS )
  81. SetDlgItemText ( IDC_CLIENT_PATH, szClientPath );
  82. else if ( ff == eNone )
  83. ff = eClientPath;
  84. switch ( ff )
  85. {
  86. case eNone:
  87. case eServer:
  88. ::SetFocus ( GetDlgItem ( IDC_SERVER ) );
  89. break;
  90. case eLogin:
  91. ::SetFocus ( GetDlgItem ( IDC_ACCOUNT ) );
  92. break;
  93. case ePassword:
  94. ::SetFocus ( GetDlgItem ( IDC_PASSWORD ) );
  95. break;
  96. case eClientPath:
  97. ::SetFocus ( GetDlgItem ( IDC_CLIENT_PATH ) );
  98. break;
  99. }
  100. return FALSE;
  101. }
  102. in_addr m_addr;
  103. bool verifyHostName ( LPCTSTR szHostName )
  104. {
  105. WSADATA wd;
  106. WSAStartup ( MAKEWORD(2, 0), &wd );
  107. DWORD dwAddr = inet_addr ( szHostName );
  108. if ( dwAddr != INADDR_NONE )
  109. {
  110. m_addr.S_un.S_addr = dwAddr;
  111. WSACleanup ();
  112. return true;
  113. }
  114. // Do a DNS Lookup
  115. hostent *host_lookup = gethostbyname ( szHostName );
  116. bool bRet = ( host_lookup != NULL );
  117. if ( bRet )
  118. m_addr.S_un.S_addr = *reinterpret_cast< DWORD * > ( host_lookup->h_addr_list[ 0 ] );
  119. else
  120. MessageBox ( _T( "Host not found." ), _T( "Login Client" ), MB_ICONERROR );
  121. WSACleanup ();
  122. return bRet;
  123. }
  124. LRESULT OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  125. {
  126. TCHAR szComputerName[ 255 ];
  127. GetDlgItemText ( IDC_SERVER, szComputerName, 255 );
  128. if ( szComputerName[ 0 ] == _T( '\0' ) )
  129. {
  130. MessageBox ( _T( "Server Name is required." ), _T( "Login Client" ), MB_ICONERROR );
  131. ::SetFocus ( GetDlgItem ( IDC_SERVER ) );
  132. return 0;
  133. }
  134. TCHAR szUserName[ 255 ];
  135. GetDlgItemText ( IDC_ACCOUNT, szUserName, 255 );
  136. if ( szUserName[ 0 ] == _T( '\0' ) )
  137. {
  138. MessageBox ( _T( "Account Name is required." ), _T( "Login Client" ), MB_ICONERROR );
  139. ::SetFocus ( GetDlgItem ( IDC_ACCOUNT ) );
  140. return 0;
  141. }
  142. TCHAR szPassword[ 255 ];
  143. GetDlgItemText ( IDC_PASSWORD, szPassword, 255 );
  144. if ( szPassword[ 0 ] == _T( '\0' ) )
  145. {
  146. MessageBox ( _T( "Password is required." ), _T( "Login Client" ), MB_ICONERROR );
  147. ::SetFocus ( GetDlgItem ( IDC_PASSWORD ) );
  148. return 0;
  149. }
  150. TCHAR szClientPath[ 255 ];
  151. GetDlgItemText ( IDC_CLIENT_PATH, szClientPath, 255 );
  152. if ( szPassword[ 0 ] == _T( '\0' ) )
  153. {
  154. MessageBox ( _T( "Client Path is required." ), _T( "Login Client" ), MB_ICONERROR );
  155. ::SetFocus ( GetDlgItem ( IDC_CLIENT_PATH ) );
  156. return 0;
  157. }
  158. DWORD sPort = 0;
  159. char *szPortArea = strchr(szComputerName,':');
  160. if (!szPortArea)
  161. {
  162. MessageBox ( _T( "Address format is Address:Port." ), _T( "Login Client" ), MB_ICONERROR );
  163. ::SetFocus ( GetDlgItem ( IDC_PASSWORD ) );
  164. return 0;
  165. }
  166. sscanf(szPortArea+1,"%i",&sPort);
  167. if ((!sPort) || (sPort > 32767))
  168. {
  169. MessageBox ( _T( "Invalid Port." ), _T( "Login Client" ), MB_ICONERROR );
  170. ::SetFocus ( GetDlgItem ( IDC_PASSWORD ) );
  171. return 0;
  172. }
  173. /* char tpcheckad[255]; sprintf(tpcheckad, "%s", szClientPath);
  174. int tpcheck = _open(tpcheckad, _O_RDONLY);
  175. if (tpcheck == -1)
  176. {
  177. //File doesn't exist or other error
  178. char invpath[255]; sprintf(invpath, "Invalid Client Path: %s", szClientPath);
  179. MessageBox ( _T( invpath ), _T( "Login Client" ), MB_ICONERROR );
  180. ::SetFocus ( GetDlgItem ( IDC_CLIENT_PATH ) );
  181. return 0;
  182. }
  183. _close(tpcheck);
  184. */
  185. *szPortArea = 0;
  186. // Verify the computer name and convert to IP as neccessary
  187. {
  188. // CWaitCursor wc;
  189. if ( !verifyHostName ( szComputerName ) )
  190. {
  191. ::SetFocus ( GetDlgItem ( IDC_SERVER ) );
  192. return 0;
  193. }
  194. }
  195. *szPortArea = ':';
  196. // Save Settings
  197. CRegKey rk;
  198. if ( rk.Create ( HKEY_CURRENT_USER, _T( "Software\\ACEmu\\Client" ) ) == ERROR_SUCCESS )
  199. {
  200. rk.SetValue ( szComputerName, _T( "Server" ) );
  201. rk.SetValue ( szUserName, _T( "Account" ) );
  202. if ( IsDlgButtonChecked ( IDC_SAVEPASSWORD ) == BST_CHECKED )
  203. rk.SetValue ( szPassword, _T( "Password" ) );
  204. else
  205. rk.DeleteValue ( _T( "Password" ) );
  206. rk.SetValue (szClientPath, _T( "ClientPath" ) );
  207. }
  208. else
  209. MessageBox ( _T( "Could not save settings in registry" ), _T( "Login Client" ), MB_ICONWARNING );
  210. executeClient ( m_addr.S_un.S_addr, szUserName, szPassword, (short) sPort, szClientPath );
  211. // SetActiveWindow();
  212. CloseDialog(wID);
  213. return 0;
  214. }
  215. LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  216. {
  217. CloseDialog(wID);
  218. return 0;
  219. }
  220. void CloseDialog(int nVal)
  221. {
  222. DestroyWindow();
  223. ::PostQuitMessage(nVal);
  224. }
  225. LRESULT OnClickedBrowse_client(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  226. {
  227. //Add browse client shit...
  228. OPENFILENAME ofn;
  229. ZeroMemory(&ofn,sizeof(ofn));
  230. ofn.lStructSize = sizeof(ofn);
  231. ofn.hwndOwner = GetActiveWindow();
  232. ofn.hInstance = g_hInst;
  233. char Filters[] = "Asheron's Call Client Executables\0*.exe\0\0";
  234. ofn.lpstrFilter = (char *) &Filters[0];
  235. ofn.lpstrCustomFilter = NULL;
  236. //Add default Filename Here!
  237. ofn.nFilterIndex = 1;
  238. char FileName[255];
  239. sprintf(FileName,"c:\\program files\\microsoft games\\asheron's call\\*.exe");
  240. ofn.lpstrFile = FileName;
  241. ofn.nMaxFile = 100;
  242. ofn.lpstrFileTitle = NULL;
  243. ofn.nMaxFileTitle = NULL;
  244. // ofn.lpstrInitialDir = ROMDir;
  245. ofn.lpstrTitle = "Find Client Executable";
  246. ofn.Flags = OFN_FILEMUSTEXIST;
  247. ofn.lpstrDefExt = NULL;
  248. ofn.lCustData = NULL;
  249. ofn.lpfnHook = NULL;
  250. ofn.lpTemplateName = NULL;
  251. int tpb = GetOpenFileName(&ofn);
  252. SetDlgItemText ( IDC_CLIENT_PATH, ofn.lpstrFile );
  253. // MessageBox("Not Implemented Yet", "Login Client", MB_OK);
  254. return 0;
  255. }
  256. };
  257. /////////////////////////////////////////////////////////////////////////////
  258. //{{AFX_INSERT_LOCATION}}
  259. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  260. #endif // !defined(AFX_MAINDLG_H__4B488390_CE2F_4798_8415_47500D263534__INCLUDED_)