// GWLPConfig.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "GWLPConfig.h" #pragma comment(lib, "comctl32.lib") #include #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name // Forward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_GWLPCONFIG, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_GWLPCONFIG); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) msg.wParam; } // // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // // COMMENTS: // // This function and its usage are only necessary if you want this code // to be compatible with Win32 systems prior to the 'RegisterClassEx' // function that was added to Windows 95. It is important to call this function // so that the application will get 'well formed' small icons associated // with it. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_GWLPCONFIG); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCTSTR)IDC_GWLPCONFIG; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex); } // // FUNCTION: InitInstance(HANDLE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } //ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); InitCommonControls(); HWND maind=CreateDialog(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); ShowWindow(maind,nCmdShow); return TRUE; } // // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } #include // Message handler for about box. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: if(true) { //Load the proxy config file char ipstring[50]; memset(ipstring,0,50); short lsp=0; short gsp=0; int file_server=0; std::ifstream fin("GWLPBin/proxy.ini"); if(fin.fail()) { MessageBox(0,"Could not open Proxy config file. Please reinstall.","Fatal Error",MB_OK | MB_ICONSTOP | MB_APPLMODAL); ExitProcess(0); } fin >> ipstring; fin >> lsp; fin >> gsp; fin >> file_server; fin.close(); if(lsp==0 || gsp==0) { std::ifstream fin2("GWLPBin/play.ini"); if(fin2.fail()) { MessageBox(0,"Could not open Play config file. Please reinstall.","Fatal Error",MB_OK | MB_ICONSTOP | MB_APPLMODAL); ExitProcess(0); } fin2 >> ipstring; fin2.close(); if(strcmp(ipstring,"proxy")==0) { strcpy(ipstring,"127.0.0.1"); } } if(ipstring[0]==0) { strcpy(ipstring,"127.0.0.1"); } //Convert the IP string into IP address bytes unsigned char serverIP[4]; char temp[50]; strcpy(temp,ipstring); char *p=strtok(temp,"."); for(int i=0; i<4; i++) { serverIP[i]=(char)atoi(p); p=strtok(0,"."); } HWND sList=GetDlgItem(hDlg,IDC_IP); SendMessage(sList,IPM_SETADDRESS,0,MAKEIPADDRESS(serverIP[0],serverIP[1],serverIP[2],serverIP[3])); char ls[20]; char gs[20]; sprintf(ls,"%d",lsp); sprintf(gs,"%d",gsp); SetDlgItemText(hDlg,IDC_LSP,ls); SetDlgItemText(hDlg,IDC_GSP,gs); if (file_server) { CheckDlgButton(hDlg, IDC_CHECK1, BST_CHECKED); } } return TRUE; case WM_COMMAND: switch(LOWORD(wParam)) { case IDCANCEL: EndDialog(hDlg, LOWORD(wParam)); ExitProcess(0); break; case IDC_CLOSE: if(true) { //Check the IP address field HWND ipcon=GetDlgItem(hDlg,IDC_IP); DWORD addr; if(SendMessage(ipcon,IPM_GETADDRESS,0,(LPARAM)&addr)<4) { MessageBox(hDlg,"Please fill out the IP Address field fully.","Error",MB_OK | MB_APPLMODAL | MB_ICONSTOP); } else { char lsp[50]; char gsp[50]; int file_server=0; if (IsDlgButtonChecked(hDlg, IDC_CHECK1) == BST_CHECKED) { file_server=1; } //Check the ports GetDlgItemText(hDlg,IDC_LSP,lsp,50); GetDlgItemText(hDlg,IDC_GSP,gsp,50); if(lsp[0]==0 || gsp[0]==0) { MessageBox(hDlg,"Please fill out both port fields. If you are NOT using the proxy put zeroes in the LSP and GSP fields.","Error",MB_OK | MB_APPLMODAL | MB_ICONSTOP); } else { long ls=atoi(lsp); long gs=atoi(gsp); if(ls>0xFFFF || gs>0xFFFF) { MessageBox(hDlg,"Port value out of range. Ports must be 0-65535","Error",MB_OK | MB_APPLMODAL | MB_ICONSTOP); } else { //Convert the IP address unsigned char ip[4]; ip[0]=(unsigned char)FIRST_IPADDRESS(addr); ip[1]=(unsigned char)SECOND_IPADDRESS(addr); ip[2]=(unsigned char)THIRD_IPADDRESS(addr); ip[3]=(unsigned char)FOURTH_IPADDRESS(addr); char ips[50]; sprintf(ips,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]); //Output the proxy config file std::ofstream fout("GWLPBin/proxy.ini"); fout << ips << '\n'; fout << ls << '\n'; fout << gs << '\n'; fout << file_server << '\n'; fout.close(); bool proxyUsed=true; if(ls==0 || gs==0) { proxyUsed=false; } //Out the play config file std::ofstream fout2("GWLPBin/play.ini"); if(proxyUsed) { fout2 << "proxy"; } else { fout2 << ips; } fout2.close(); EndDialog(hDlg, LOWORD(wParam)); ExitProcess(0); return TRUE; } } } } } break; } return FALSE; }