Rev 185 | Rev 187 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 185 | Rev 186 | ||
|---|---|---|---|
| Line 520... | Line 520... | ||
| 520 | 520 | ||
| 521 | return; // finished, string is now single-line |
521 | return; // finished, string is now single-line |
| 522 | } |
522 | } |
| 523 | 523 | ||
| 524 | 524 | ||
| 525 |
|
525 | size_t ConvertTo7BitASCII (char *dest, size_t dest_size_in_bytes, wchar_t *source) |
| 526 | { |
526 | { |
| 527 | // helper function to quickly convert a wide char string to 7-bit ASCII |
527 | // helper function to quickly convert a wide char string to 7-bit ASCII |
| 528 | 528 | ||
| 529 | // do the conversion. Use WideCharToMultiByte() preferentially because wcstombs() |
529 | // do the conversion. Use WideCharToMultiByte() preferentially because wcstombs() |
| 530 | // stops at the first non-convertible character, whereas the former doesn't. |
530 | // stops at the first non-convertible character, whereas the former doesn't. |
| 531 | WideCharToMultiByte (20127, 0, source, -1, dest, dest_size_in_bytes, NULL, NULL); // 20127 is 7-bit US-ASCII code |
531 | return (WideCharToMultiByte (20127, 0, source, -1, dest, dest_size_in_bytes, NULL, NULL) - 1); // 20127 is 7-bit US-ASCII code page, -1 to null-terminate output string |
| 532 | return; |
- | |
| 533 | } |
532 | } |
| 534 | 533 | ||
| 535 | 534 | ||
| 536 |
|
535 | size_t ConvertToWideChar (wchar_t *dest, size_t dest_size_in_wchars, char *source) |
| 537 | { |
536 | { |
| 538 | // helper function to quickly convert an ASCII string to wide char |
537 | // helper function to quickly convert an ASCII string to wide char |
| 539 | 538 | ||
| 540 | size_t converted_count; |
539 | size_t converted_count; |
| 541 | 540 | ||
| 542 | // do the conversion (WARNING: EXTREMELY COSTY FUNCTION!) |
541 | // do the conversion (WARNING: EXTREMELY COSTY FUNCTION!) |
| 543 | mbstowcs_s (&converted_count, dest, dest_size_in_wchars, source, _TRUNCATE); |
542 | mbstowcs_s (&converted_count, dest, dest_size_in_wchars, source, _TRUNCATE); |
| 544 | return; |
543 | return (converted_count); |
| 545 | } |
544 | } |
| 546 | 545 | ||
| 547 | 546 | ||
| 548 | void MinutesToWideCharString (wchar_t *dest, size_t dest_size_in_wchars, int minutes) |
547 | void MinutesToWideCharString (wchar_t *dest, size_t dest_size_in_wchars, int minutes) |
| 549 | { |
548 | { |
| Line 758... | Line 757... | ||
| 758 | return (true); // copy out the width and height and return TRUE |
757 | return (true); // copy out the width and height and return TRUE |
| 759 | } |
758 | } |
| 760 | 759 | ||
| 761 | fclose (fp); // close file now |
760 | fclose (fp); // close file now |
| 762 | return (false); // file is probably not a DDS, BMP, PNG, TGA or JPEG image |
761 | return (false); // file is probably not a DDS, BMP, PNG, TGA or JPEG image |
| - | 762 | } |
|
| - | 763 | ||
| - | 764 | ||
| - | 765 | void GenerateVersionNumber (char *out_string, size_t outstring_maxsize) |
|
| - | 766 | { |
|
| - | 767 | // handy helper to generate a version number in the form YYYYMMDD |
|
| - | 768 | ||
| - | 769 | sprintf_s (out_string, outstring_maxsize, "%c%c%c%c%s%c%c", |
|
| - | 770 | __DATE__[7], __DATE__[8], __DATE__[9], __DATE__[10], // year |
|
| - | 771 | (strncmp (__DATE__, "Jan", 3) == 0 ? "01" : |
|
| - | 772 | (strncmp (__DATE__, "Feb", 3) == 0 ? "02" : |
|
| - | 773 | (strncmp (__DATE__, "Mar", 3) == 0 ? "03" : |
|
| - | 774 | (strncmp (__DATE__, "Apr", 3) == 0 ? "04" : |
|
| - | 775 | (strncmp (__DATE__, "May", 3) == 0 ? "05" : |
|
| - | 776 | (strncmp (__DATE__, "Jun", 3) == 0 ? "06" : |
|
| - | 777 | (strncmp (__DATE__, "Jul", 3) == 0 ? "07" : |
|
| - | 778 | (strncmp (__DATE__, "Aug", 3) == 0 ? "08" : |
|
| - | 779 | (strncmp (__DATE__, "Sep", 3) == 0 ? "09" : |
|
| - | 780 | (strncmp (__DATE__, "Oct", 3) == 0 ? "10" : |
|
| - | 781 | (strncmp (__DATE__, "Nov", 3) == 0 ? "11" : |
|
| - | 782 | (strncmp (__DATE__, "Dec", 3) == 0 ? "12" : "??")))))))))))), |
|
| - | 783 | (__DATE__[4] == ' ' ? '0' : __DATE__[4]), __DATE__[5]); |
|
| - | 784 | ||
| - | 785 | return; // finished |
|
| 763 | } |
786 | } |
| 764 | 787 | ||
| 765 | 788 | ||
| 766 | void Debug_Init (const wchar_t *logfile_name) |
789 | void Debug_Init (const wchar_t *logfile_name) |
| 767 | { |
790 | { |
| Line 850... | Line 873... | ||
| 850 | 873 | ||
| 851 | bool Debug_SendLogToAuthor (char *reason, bool should_include_description) |
874 | bool Debug_SendLogToAuthor (char *reason, bool should_include_description) |
| 852 | { |
875 | { |
| 853 | // this function upload the engine history to the remote server for debug purposes. |
876 | // this function upload the engine history to the remote server for debug purposes. |
| 854 | 877 | ||
| 855 |
|
878 | wchar_t descriptionfile_pathname[MAX_PATH]; |
| 856 | static char log_buffer[512 * 1024]; |
- | |
| 857 | static char log_base64buffer[512 * 1024 * 4 / 3]; |
- | |
| 858 | static char description_buffer[512 * 1024]; |
- | |
| 859 | static char description_base64buffer[512 * 1024 * 4 / 3]; |
- | |
| 860 | static char board_buffer[8 * 5 * 8 * 3]; |
- | |
| 861 | static char board_base64buffer[8 * 5 * 8 * 3 * 4 / 3]; |
- | |
| 862 | static char http_buffer[1024 * 1024]; // used both for request and reply |
- | |
| 863 |
|
879 | char temp_string[1024]; |
| 864 | static char program_version[10]; |
- | |
| 865 | - | ||
| 866 | struct sockaddr_in service; |
880 | struct sockaddr_in service; |
| 867 | struct hostent *hostinfo; |
881 | struct hostent *hostinfo; |
| 868 | SHELLEXECUTEINFO bugreport_shinfo; |
882 | SHELLEXECUTEINFO bugreport_shinfo; |
| - | 883 | buffer_t temp_buffer; |
|
| - | 884 | buffer_t description_buffer; |
|
| - | 885 | buffer_t logfile_buffer; |
|
| 869 | buffer_t |
886 | buffer_t board_buffer; |
| - | 887 | buffer_t http_buffer; // used for both request and reply |
|
| - | 888 | bool was_successful; |
|
| - | 889 | unsigned char color; |
|
| 870 | unsigned char part; |
890 | unsigned char part; |
| 871 | char * |
891 | char *base64buffer; // mallocated |
| 872 | int write_index; |
892 | int write_index; |
| 873 | int read_index; |
893 | int read_index; |
| 874 | int length; |
894 | int length; |
| 875 | SOCKET s; |
895 | SOCKET s; |
| 876 | FILE *fp; |
- | |
| 877 | int i; |
896 | int i; |
| 878 | int j; |
897 | int j; |
| 879 | 898 | ||
| 880 | // get a hand on the log file and read its contents |
899 | // get a hand on the log file and read its contents |
| 881 |
|
900 | Buffer_Initialize (&logfile_buffer); |
| 882 | if ( |
901 | if (Buffer_ReadFromFileW (&temp_buffer, logfile_pathname)) |
| 883 | { |
902 | { |
| 884 | fseek (fp, 0, SEEK_END); |
- | |
| 885 |
|
903 | logfile_buffer.data = (char *) malloc (temp_buffer.size); // necessarily less |
| 886 | if (length > sizeof (log_base64buffer) - 1) |
- | |
| 887 | swprintf_s ((wchar_t *) log_base64buffer, WCHAR_SIZEOF (log_base64buffer), L"Log file at \"%s\" too big (> %d bytes).", logfile_pathname, sizeof (log_base64buffer) - 1); // history file too big |
- | |
| 888 | else |
- | |
| 889 | { |
- | |
| 890 | fseek (fp, 0, SEEK_SET); |
- | |
| 891 | fread (log_base64buffer, 1, length, fp); |
- | |
| 892 |
|
904 | logfile_buffer.size = ConvertTo7BitASCII (logfile_buffer.data, temp_buffer.size, (wchar_t *) temp_buffer.data); |
| 893 | } |
- | |
| 894 | fclose (fp); |
- | |
| 895 | } |
905 | } |
| 896 | else |
906 | else |
| - | 907 | { |
|
| 897 |
|
908 | Buffer_AppendCString (&logfile_buffer, "Couldn't open log file at \""); |
| 898 | ConvertTo7BitASCII ( |
909 | ConvertTo7BitASCII (temp_string, sizeof (temp_string), logfile_pathname); Buffer_AppendCString (&logfile_buffer, temp_string); |
| - | 910 | Buffer_AppendCString (&logfile_buffer, "\".\n"); |
|
| - | 911 | } |
|
| 899 | 912 | ||
| 900 | // should the user include a problem report ? |
913 | // should the user include a problem report ? |
| - | 914 | Buffer_Initialize (&description_buffer); |
|
| 901 | if (should_include_description) |
915 | if (should_include_description) |
| 902 | { |
916 | { |
| 903 | // have the user describe his problem with Notepad |
917 | // have the user describe his problem with Notepad |
| 904 | swprintf_s (descriptionfile_pathname, WCHAR_SIZEOF (descriptionfile_pathname), L"%s\\Chess Giants bug report.txt", app_path); |
918 | swprintf_s (descriptionfile_pathname, WCHAR_SIZEOF (descriptionfile_pathname), L"%s\\Chess Giants bug report.txt", app_path); |
| 905 | Buffer_Initialize (& |
919 | Buffer_Initialize (&description_buffer); |
| 906 | length = wcslen (LOCALIZE (L"PleaseDescribeTheProblem")); |
920 | length = wcslen (LOCALIZE (L"PleaseDescribeTheProblem")); |
| 907 | Buffer_Append (& |
921 | Buffer_Append (&description_buffer, (char *) LOCALIZE (L"PleaseDescribeTheProblem"), length * sizeof (wchar_t)); |
| 908 | Buffer_Append (& |
922 | Buffer_Append (&description_buffer, (char *) L"\r\n", 2 * sizeof (wchar_t)); |
| 909 | for (write_index = 0; write_index < length; write_index++) |
923 | for (write_index = 0; write_index < length; write_index++) |
| 910 | Buffer_Append (& |
924 | Buffer_Append (&description_buffer, (char *) L"-", sizeof (wchar_t)); |
| 911 | Buffer_Append (& |
925 | Buffer_Append (&description_buffer, (char *) L"\r\n", 2 * sizeof (wchar_t)); |
| 912 | Buffer_Append (& |
926 | Buffer_Append (&description_buffer, (char *) L"\r\n=> ", 5 * sizeof (wchar_t)); |
| 913 | Buffer_WriteToFileW (& |
927 | Buffer_WriteToFileW (&description_buffer, descriptionfile_pathname); |
| 914 | memset (&bugreport_shinfo, 0, sizeof (bugreport_shinfo)); |
928 | memset (&bugreport_shinfo, 0, sizeof (bugreport_shinfo)); |
| 915 | bugreport_shinfo.cbSize = sizeof (SHELLEXECUTEINFO); |
929 | bugreport_shinfo.cbSize = sizeof (SHELLEXECUTEINFO); |
| 916 | bugreport_shinfo.fMask = SEE_MASK_NOCLOSEPROCESS; |
930 | bugreport_shinfo.fMask = SEE_MASK_NOCLOSEPROCESS; |
| 917 | bugreport_shinfo.lpFile = L"notepad.exe"; |
931 | bugreport_shinfo.lpFile = L"notepad.exe"; |
| 918 | bugreport_shinfo.lpParameters = descriptionfile_pathname; |
932 | bugreport_shinfo.lpParameters = descriptionfile_pathname; |
| Line 920... | Line 934... | ||
| 920 | ShellExecuteEx (&bugreport_shinfo); |
934 | ShellExecuteEx (&bugreport_shinfo); |
| 921 | WaitForSingleObject (bugreport_shinfo.hProcess, INFINITE); |
935 | WaitForSingleObject (bugreport_shinfo.hProcess, INFINITE); |
| 922 | CloseHandle (bugreport_shinfo.hProcess); |
936 | CloseHandle (bugreport_shinfo.hProcess); |
| 923 | 937 | ||
| 924 | // get a hand on the error description file and read its contents |
938 | // get a hand on the error description file and read its contents |
| 925 |
|
939 | Buffer_Initialize (&description_buffer); |
| 926 | if ( |
940 | if (Buffer_ReadFromFileW (&temp_buffer, descriptionfile_pathname)) |
| 927 | { |
941 | { |
| 928 | fseek (fp, 0, SEEK_END); |
- | |
| 929 | length = ftell (fp); // get file size |
- | |
| 930 | fseek (fp, 0, SEEK_SET); |
- | |
| 931 | if (length > sizeof (description_base64buffer) - 1) |
- | |
| 932 | return (false); // history file too big, return an error condition |
- | |
| 933 | fread (description_base64buffer, 1, length, fp); |
- | |
| 934 |
|
942 | description_buffer.data = (char *) malloc (temp_buffer.size); // necessarily less |
| 935 | fclose (fp); |
- | |
| 936 |
|
943 | description_buffer.size = ConvertTo7BitASCII (description_buffer.data, temp_buffer.size, (wchar_t *) temp_buffer.data); |
| 937 | } |
944 | } |
| 938 | else |
945 | else |
| - | 946 | { |
|
| 939 |
|
947 | Buffer_AppendCString (&description_buffer, "Couldn't open error description file at \""); |
| 940 | ConvertTo7BitASCII ( |
948 | ConvertTo7BitASCII (temp_string, sizeof (temp_string), descriptionfile_pathname); Buffer_AppendCString (&description_buffer, temp_string); |
| - | 949 | Buffer_AppendCString (&description_buffer, "\".\n"); |
|
| - | 950 | } |
|
| 941 | } |
951 | } |
| 942 | else |
- | |
| 943 | description_buffer[0] = 0; // no description |
- | |
| 944 | 952 | ||
| 945 | // append the program-given reason to the description buffer |
953 | // append the program-given reason to the description buffer |
| 946 |
|
954 | Buffer_AppendCharArray (&description_buffer, "\n\nChess Giants reason: "); |
| 947 |
|
955 | Buffer_AppendCString (&description_buffer, reason); |
| 948 | 956 | ||
| 949 | // capture and encode the board |
957 | // capture and encode the board |
| - | 958 | Buffer_Initialize (&board_buffer); |
|
| 950 |
|
959 | Buffer_AppendCharArray (&board_buffer, "+---+---+---+---+---+---+---+---+\n"); |
| 951 | for (i = 7; i >= 0; i--) // lines are in reverse order in this stupid program of mine >.< |
960 | for (i = 7; i >= 0; i--) // lines are in reverse order in this stupid program of mine >.< |
| 952 | { |
961 | { |
| 953 |
|
962 | Buffer_AppendCString (&board_buffer, "|"); |
| 954 | *write_ptr = '|'; write_ptr++; |
- | |
| 955 | for (j = 0; j < 8; j++) |
963 | for (j = 0; j < 8; j++) |
| 956 | { |
964 | { |
| 957 | part = the_board.moves[the_board.move_count - 1].slots[i][j].part; |
965 | part = the_board.moves[the_board.move_count - 1].slots[i][j].part; |
| 958 |
|
966 | color = the_board.moves[the_board.move_count - 1].slots[i][j].color; |
| 959 | if (part == PART_ROOK) |
967 | if (part == PART_ROOK) Buffer_AppendCString (&board_buffer, (color == COLOR_WHITE ? " R |" : " r |")); |
| 960 | else if (part == PART_KNIGHT) |
968 | else if (part == PART_KNIGHT) Buffer_AppendCString (&board_buffer, (color == COLOR_WHITE ? " N |" : " n |")); |
| 961 | else if (part == PART_BISHOP) |
969 | else if (part == PART_BISHOP) Buffer_AppendCString (&board_buffer, (color == COLOR_WHITE ? " B |" : " b |")); |
| 962 | else if (part == PART_QUEEN) |
970 | else if (part == PART_QUEEN) Buffer_AppendCString (&board_buffer, (color == COLOR_WHITE ? " Q |" : " q |")); |
| 963 | else if (part == PART_KING) |
971 | else if (part == PART_KING) Buffer_AppendCString (&board_buffer, (color == COLOR_WHITE ? " K |" : " k |")); |
| 964 | else if (part == PART_PAWN) |
972 | else if (part == PART_PAWN) Buffer_AppendCString (&board_buffer, (color == COLOR_WHITE ? " P |" : " p |")); |
| 965 | else |
973 | else Buffer_AppendCString (&board_buffer, " |"); |
| 966 | if (the_board.moves[the_board.move_count - 1].slots[i][j].color == COLOR_WHITE) *write_ptr = toupper (*write_ptr); |
- | |
| 967 | *write_ptr++; |
- | |
| 968 | *write_ptr = ' '; write_ptr++; |
- | |
| 969 | *write_ptr = '|'; write_ptr++; |
- | |
| 970 | } |
974 | } |
| 971 | *write_ptr = '\n'; write_ptr++; |
- | |
| 972 | *write_ptr = 0; |
- | |
| 973 |
|
975 | Buffer_AppendCharArray (&board_buffer, "\n" "+---+---+---+---+---+---+---+---+\n"); |
| 974 | } |
976 | } |
| 975 | - | ||
| 976 | // build the program version |
- | |
| 977 | sprintf_s (program_version, sizeof (program_version), "%04d%02d%02d", |
- | |
| 978 | atoi (strrchr (__DATE__, ' ') + 1), |
- | |
| 979 | (__DATE__[0] == 'F' ? 2 : // February |
- | |
| 980 | (__DATE__[0] == 'S' ? 9 : // September |
- | |
| 981 | (__DATE__[0] == 'O' ? 10 : // October |
- | |
| 982 | (__DATE__[0] == 'N' ? 11 : // November |
- | |
| 983 | (__DATE__[0] == 'D' ? 12 : // December |
- | |
| 984 | (__DATE__[1] == 'p' ? 4 : // April |
- | |
| 985 | (__DATE__[0] == 'A' ? 8 : // August |
- | |
| 986 | (__DATE__[2] == 'r' ? 3 : // March |
- | |
| 987 | (__DATE__[0] == 'M' ? 5 : // May |
- | |
| 988 | (__DATE__[1] == 'a' ? 1 : // January |
- | |
| 989 | (__DATE__[2] == 'n' ? 6 : // June |
- | |
| 990 | (__DATE__[0] == 'J' ? 7 : // July |
- | |
| 991 | 0)))))))))))), |
- | |
| 992 | atoi (strchr (__DATE__, ' ') + 1)); |
- | |
| 993 | 977 | ||
| 994 | // get our distribution server's IP address from the host name |
978 | // get our distribution server's IP address from the host name |
| 995 | hostinfo = gethostbyname ("pmbaty.com"); |
979 | hostinfo = gethostbyname ("pmbaty.com"); |
| 996 | if (hostinfo == NULL) |
980 | if (hostinfo == NULL) |
| 997 | return (false); // couldn't resolve hostname, return an error condition |
981 | return (false); // couldn't resolve hostname, return an error condition |
| Line 1011... | Line 995... | ||
| 1011 | closesocket (s); // finished communicating, close TCP socket |
995 | closesocket (s); // finished communicating, close TCP socket |
| 1012 | return (false); // couldn't resolve hostname, return an error condition |
996 | return (false); // couldn't resolve hostname, return an error condition |
| 1013 | } |
997 | } |
| 1014 | 998 | ||
| 1015 | // build the HTTP POST query and send it |
999 | // build the HTTP POST query and send it |
| 1016 | if (options.registration.user_email[0] != 0) |
- | |
| 1017 |
|
1000 | base64buffer = (char *) malloc ((max (board_buffer.size, max (logfile_buffer.size, description_buffer.size)) * 4 / 3 + 4) * sizeof (char)); |
| 1018 | else |
- | |
| 1019 |
|
1001 | Buffer_Initialize (&http_buffer); |
| 1020 |
|
1002 | Buffer_AppendCharArray (&http_buffer, "registrant="); ConvertTo7BitASCII (temp_string, sizeof (temp_string), (options.registration.user_email[0] != 0 ? options.registration.user_email : L"an+unregistered+user")); Buffer_AppendCString (&http_buffer, temp_string); |
| 1021 |
|
1003 | Buffer_AppendCharArray (&http_buffer, "&version="); GenerateVersionNumber (temp_string, sizeof (temp_string)); Buffer_AppendCString (&http_buffer, temp_string); |
| 1022 |
|
1004 | Buffer_AppendCharArray (&http_buffer, "&player1="); Buffer_Append (&http_buffer, (the_board.players[COLOR_WHITE].type == PLAYER_INTERNET ? "I" : (the_board.players[COLOR_WHITE].type == PLAYER_COMPUTER ? "C" : "H")), 1); |
| 1023 |
|
1005 | Buffer_AppendCharArray (&http_buffer, "&player2="); Buffer_Append (&http_buffer, (the_board.players[COLOR_BLACK].type == PLAYER_INTERNET ? "I" : (the_board.players[COLOR_BLACK].type == PLAYER_COMPUTER ? "C" : "H")), 1); |
| 1024 |
|
1006 | Buffer_AppendCharArray (&http_buffer, "&board="); base64_encode (base64buffer, board_buffer.data, board_buffer.size); Buffer_AppendCString (&http_buffer, base64buffer); |
| 1025 |
|
1007 | Buffer_AppendCharArray (&http_buffer, "&log="); base64_encode (base64buffer, logfile_buffer.data, logfile_buffer.size); Buffer_AppendCString (&http_buffer, base64buffer); |
| 1026 |
|
1008 | Buffer_AppendCharArray (&http_buffer, "&description="); base64_encode (base64buffer, description_buffer.data, description_buffer.size); Buffer_AppendCString (&http_buffer, base64buffer); |
| 1027 |
|
1009 | Buffer_Forget (&description_buffer); |
| 1028 |
|
1010 | Buffer_Forget (&logfile_buffer); |
| 1029 |
|
1011 | Buffer_Forget (&board_buffer); |
| 1030 |
|
1012 | free (base64buffer); |
| 1031 |
|
1013 | length = http_buffer.size; |
| 1032 |
|
1014 | Buffer_Initialize (&temp_buffer); |
| 1033 |
|
1015 | Buffer_WriteAt (&temp_buffer, 256, "", 1); // make sure buffer is big enough |
| 1034 |
|
1016 | temp_buffer.size = sprintf_s (temp_buffer.data, temp_buffer.size, |
| 1035 |
|
1017 | "POST /chess/sendcrash.php HTTP/1.1" "\r\n" |
| 1036 |
|
1018 | "Host: " "pmbaty.com" "\r\n" |
| 1037 |
|
1019 | "Content-Type: " "application/x-www-form-urlencoded" "\r\n" |
| 1038 |
|
1020 | "Content-Length: %d" "\r\n" |
| 1039 |
|
1021 | "Connection: " "close" "\r\n" |
| 1040 |
|
1022 | "\r\n", length); |
| 1041 |
|
1023 | Buffer_PrependBuffer (&http_buffer, &temp_buffer); |
| 1042 |
|
1024 | Buffer_Forget (&temp_buffer); |
| 1043 | write_index = send (s, |
1025 | write_index = send (s, http_buffer.data, http_buffer.size, 0); // send the HTTP query |
| 1044 | if (write_index != |
1026 | if (write_index != http_buffer.size) |
| 1045 | { |
1027 | { |
| 1046 | closesocket (s); // finished communicating, close TCP socket |
1028 | closesocket (s); // finished communicating, close TCP socket |
| 1047 | return (false); // couldn't resolve hostname, return an error condition |
1029 | return (false); // couldn't resolve hostname, return an error condition |
| 1048 | } |
1030 | } |
| 1049 | 1031 | ||
| 1050 | // read the reply (10 seconds timeout) |
1032 | // read the reply (10 seconds timeout) |
| 1051 | http_buffer[0] = 0; |
1033 | http_buffer.data[0] = 0; |
| 1052 | read_index = RecvWithTimeout (s, 10.0f, |
1034 | read_index = RecvWithTimeout (s, 10.0f, http_buffer.data, http_buffer.size, 0); |
| 1053 | if (read_index < 1) |
1035 | if (read_index < 1) |
| 1054 | { |
1036 | { |
| 1055 | closesocket (s); // finished communicating, close TCP socket |
1037 | closesocket (s); // finished communicating, close TCP socket |
| 1056 | return (false); // couldn't resolve hostname, return an error condition |
1038 | return (false); // couldn't resolve hostname, return an error condition |
| 1057 | } |
1039 | } |
| 1058 | 1040 | ||
| 1059 | closesocket (s); // finished communicating, close TCP socket |
1041 | closesocket (s); // finished communicating, close TCP socket |
| 1060 | 1042 | ||
| 1061 | // terminate recv buffer ourselves |
1043 | // terminate recv buffer ourselves and see if the server accepted our post |
| 1062 | http_buffer[read_index] = 0; |
1044 | http_buffer.data[read_index] = 0; |
| 1063 | - | ||
| 1064 | //MessageBoxA (NULL, http_buffer, "HTTP response", MB_OK); |
1045 | //MessageBoxA (NULL, http_buffer, "HTTP response", MB_OK); |
| - | 1046 | was_successful = (strstr (http_buffer.data, "Success") != NULL); |
|
| - | 1047 | Buffer_Forget (&http_buffer); |
|
| - | 1048 | ||
| 1065 | return ( |
1049 | return (was_successful); // and return whether the server accepted our post |
| 1066 | } |
1050 | } |
| 1067 | 1051 | ||
| 1068 | 1052 | ||
| 1069 | int RecvWithTimeout (int socket_id, float timeout_in_seconds, char *outbuf, size_t outbuf_size, int flags) |
1053 | int RecvWithTimeout (int socket_id, float timeout_in_seconds, char *outbuf, size_t outbuf_size, int flags) |
| 1070 | { |
1054 | { |