Rev 158 | Rev 161 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 158 | Rev 160 | ||
---|---|---|---|
Line 803... | Line 803... | ||
803 | 803 | ||
804 | return; // finished |
804 | return; // finished |
805 | } |
805 | } |
806 | 806 | ||
807 | 807 | ||
808 | bool Debug_SendLogToAuthor ( |
808 | bool Debug_SendLogToAuthor (bool should_include_description) |
809 | { |
809 | { |
810 | // this function upload the engine history to the remote server for debug purposes. |
810 | // this function upload the engine history to the remote server for debug purposes. |
811 | 811 | ||
- | 812 | static wchar_t descriptionfile_pathname[MAX_PATH]; |
|
812 | static char log_buffer[512 * 1024]; |
813 | static char log_buffer[512 * 1024]; |
813 | static char log_base64buffer[512 * 1024 * 4 / 3]; |
814 | static char log_base64buffer[512 * 1024 * 4 / 3]; |
- | 815 | static char description_buffer[512 * 1024]; |
|
- | 816 | static char description_base64buffer[512 * 1024 * 4 / 3]; |
|
814 | static char board_buffer[8 * 5 * 8 * 3]; |
817 | static char board_buffer[8 * 5 * 8 * 3]; |
815 | static char board_base64buffer[8 * 5 * 8 * 3 * 4 / 3]; |
818 | static char board_base64buffer[8 * 5 * 8 * 3 * 4 / 3]; |
816 | static char http_buffer[1024 * 1024]; // used both for request and reply |
819 | static char http_buffer[1024 * 1024]; // used both for request and reply |
817 | static char user_email[64]; |
820 | static char user_email[64]; |
818 | static char program_version[10]; |
821 | static char program_version[10]; |
819 | 822 | ||
820 | struct sockaddr_in service; |
823 | struct sockaddr_in service; |
821 | struct hostent *hostinfo; |
824 | struct hostent *hostinfo; |
- | 825 | SHELLEXECUTEINFO bugreport_shinfo; |
|
- | 826 | buffer_t bugreport_buffer; |
|
822 | unsigned char part; |
827 | unsigned char part; |
823 | char *write_ptr; |
828 | char *write_ptr; |
824 | int write_index; |
829 | int write_index; |
825 | int read_index; |
830 | int read_index; |
826 | int length; |
831 | int length; |
Line 829... | Line 834... | ||
829 | int i; |
834 | int i; |
830 | int j; |
835 | int j; |
831 | 836 | ||
832 | // get a hand on the log file and read its contents |
837 | // get a hand on the log file and read its contents |
833 | _wfopen_s (&fp, logfile_pathname, L"rb"); |
838 | _wfopen_s (&fp, logfile_pathname, L"rb"); |
834 | if (fp |
839 | if (fp != NULL) |
835 | return (false); // couldn't open game history log file, return an error condition |
- | |
- | 840 | { |
|
836 | fseek (fp, 0, SEEK_END); |
841 | fseek (fp, 0, SEEK_END); |
837 | length = ftell (fp); // get file size |
842 | length = ftell (fp); // get file size |
838 | fseek (fp, 0, SEEK_SET); |
843 | fseek (fp, 0, SEEK_SET); |
839 | if (length > sizeof (log_base64buffer) - 1) |
844 | if (length > sizeof (log_base64buffer) - 1) |
840 | return (false); // history file too big, return an error condition |
845 | return (false); // history file too big, return an error condition |
841 | fread (log_base64buffer, 1, length, fp); |
846 | fread (log_base64buffer, 1, length, fp); |
842 | log_base64buffer[length] = 0; // terminate buffer ourselves |
847 | log_base64buffer[length] = 0; // terminate buffer ourselves |
843 | fclose (fp); |
848 | fclose (fp); |
844 | ConvertTo7BitASCII (log_buffer, sizeof (log_buffer), (wchar_t *) log_base64buffer); |
849 | ConvertTo7BitASCII (log_buffer, sizeof (log_buffer), (wchar_t *) log_base64buffer); |
- | 850 | } |
|
- | 851 | else |
|
- | 852 | log_buffer[0] = 0; // couldn't open game history log file |
|
- | 853 | ||
- | 854 | // should the user include a problem report ? |
|
- | 855 | if (should_include_description) |
|
- | 856 | { |
|
- | 857 | // have the user describe his problem with Notepad |
|
- | 858 | swprintf_s (descriptionfile_pathname, WCHAR_SIZEOF (descriptionfile_pathname), L"%s\\Chess Giants bug report.txt", app_path); |
|
- | 859 | Buffer_Initialize (&bugreport_buffer); |
|
- | 860 | length = wcslen (LOCALIZE (L"PleaseDescribeTheProblem")); |
|
- | 861 | Buffer_Append (&bugreport_buffer, (char *) LOCALIZE (L"PleaseDescribeTheProblem"), length * sizeof (wchar_t)); |
|
- | 862 | Buffer_Append (&bugreport_buffer, (char *) L"\r\n", 2 * sizeof (wchar_t)); |
|
- | 863 | for (write_index = 0; write_index < length; write_index++) |
|
- | 864 | Buffer_Append (&bugreport_buffer, (char *) L"-", sizeof (wchar_t)); |
|
- | 865 | Buffer_Append (&bugreport_buffer, (char *) L"\r\n", 2 * sizeof (wchar_t)); |
|
- | 866 | Buffer_Append (&bugreport_buffer, (char *) L"\r\n=> ", 5 * sizeof (wchar_t)); |
|
- | 867 | Buffer_WriteToFileW (&bugreport_buffer, descriptionfile_pathname); |
|
- | 868 | memset (&bugreport_shinfo, 0, sizeof (bugreport_shinfo)); |
|
- | 869 | bugreport_shinfo.cbSize = sizeof (SHELLEXECUTEINFO); |
|
- | 870 | bugreport_shinfo.fMask = SEE_MASK_NOCLOSEPROCESS; |
|
- | 871 | bugreport_shinfo.lpFile = L"notepad.exe"; |
|
- | 872 | bugreport_shinfo.lpParameters = descriptionfile_pathname; |
|
- | 873 | bugreport_shinfo.nShow = SW_SHOW; |
|
- | 874 | ShellExecuteEx (&bugreport_shinfo); |
|
- | 875 | WaitForSingleObject (bugreport_shinfo.hProcess, INFINITE); |
|
- | 876 | CloseHandle (bugreport_shinfo.hProcess); |
|
- | 877 | ||
- | 878 | // get a hand on the error description file and read its contents |
|
- | 879 | _wfopen_s (&fp, descriptionfile_pathname, L"rb"); |
|
- | 880 | if (fp != NULL) |
|
- | 881 | { |
|
- | 882 | fseek (fp, 0, SEEK_END); |
|
- | 883 | length = ftell (fp); // get file size |
|
- | 884 | fseek (fp, 0, SEEK_SET); |
|
- | 885 | if (length > sizeof (description_base64buffer) - 1) |
|
- | 886 | return (false); // history file too big, return an error condition |
|
- | 887 | fread (description_base64buffer, 1, length, fp); |
|
- | 888 | description_base64buffer[length] = 0; // terminate buffer ourselves |
|
- | 889 | fclose (fp); |
|
- | 890 | _wunlink (descriptionfile_pathname); // as soon as it's read, DELETE the error description file |
|
- | 891 | ConvertTo7BitASCII (description_buffer, sizeof (description_buffer), (wchar_t *) description_base64buffer); |
|
- | 892 | } |
|
- | 893 | else |
|
- | 894 | description_buffer[0] = 0; // couldn't open error description file |
|
- | 895 | } |
|
- | 896 | else |
|
- | 897 | description_buffer[0] = 0; // no description |
|
845 | 898 | ||
846 | // capture and encode the board |
899 | // capture and encode the board |
847 | strcpy_s (board_buffer, sizeof (board_buffer), "+---+---+---+---+---+---+---+---+\n"); |
900 | strcpy_s (board_buffer, sizeof (board_buffer), "+---+---+---+---+---+---+---+---+\n"); |
848 | for (i = 7; i >= 0; i--) // lines are in reverse order in this stupid program of mine >.< |
901 | for (i = 7; i >= 0; i--) // lines are in reverse order in this stupid program of mine >.< |
849 | { |
902 | { |
Line 919... | Line 972... | ||
919 | else |
972 | else |
920 | strcpy_s (user_email, sizeof (user_email), "an+unregistered+user"); |
973 | strcpy_s (user_email, sizeof (user_email), "an+unregistered+user"); |
921 | length = strlen ("registrant=") + strlen (user_email) |
974 | length = strlen ("registrant=") + strlen (user_email) |
922 | + strlen ("&version=") + strlen (program_version) |
975 | + strlen ("&version=") + strlen (program_version) |
923 | + strlen ("&board=") + base64_encode (board_base64buffer, board_buffer, strlen (board_buffer)) |
976 | + strlen ("&board=") + base64_encode (board_base64buffer, board_buffer, strlen (board_buffer)) |
924 | + strlen ("&log=") + base64_encode (log_base64buffer, log_buffer, strlen (log_buffer)) |
977 | + strlen ("&log=") + base64_encode (log_base64buffer, log_buffer, strlen (log_buffer)) |
- | 978 | + strlen ("&description=") + base64_encode (description_base64buffer, description_buffer, strlen (description_buffer)); |
|
925 | sprintf_s (http_buffer, sizeof (http_buffer), |
979 | sprintf_s (http_buffer, sizeof (http_buffer), |
926 | "POST /chess/sendcrash.php HTTP/1.1\r\n" |
980 | "POST /chess/sendcrash.php HTTP/1.1\r\n" |
927 | "Host: pmbaty.com\r\n" |
981 | "Host: pmbaty.com\r\n" |
928 | "Content-Type: application/x-www-form-urlencoded\r\n" |
982 | "Content-Type: application/x-www-form-urlencoded\r\n" |
929 | "Content-Length: %d\r\n" |
983 | "Content-Length: %d\r\n" |
930 | "Connection: close\r\n" |
984 | "Connection: close\r\n" |
931 | "\r\n" |
985 | "\r\n" |
932 | "registrant=%s&version=%s&board=%s&log=%s", length, user_email, program_version, board_base64buffer, |
986 | "registrant=%s&version=%s&board=%s&log=%s&description=%s", length, user_email, program_version, board_base64buffer, log_base64buffer, description_base64buffer); |
933 | length = strlen (http_buffer); |
987 | length = strlen (http_buffer); |
934 | write_index = send (s, http_buffer, length, 0); // send the HTTP query |
988 | write_index = send (s, http_buffer, length, 0); // send the HTTP query |
935 | if (write_index != length) |
989 | if (write_index != length) |
936 | { |
990 | { |
937 | closesocket (s); // finished communicating, close TCP socket |
991 | closesocket (s); // finished communicating, close TCP socket |