Rev 153 | Rev 158 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 153 | Rev 154 | ||
---|---|---|---|
Line 144... | Line 144... | ||
144 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_GETCHESSGAMES, LOCALIZE (L"Menu_HelpGetChessGames")); |
144 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_GETCHESSGAMES, LOCALIZE (L"Menu_HelpGetChessGames")); |
145 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
145 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
146 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ADDMODIFYVISUALTHEMES, LOCALIZE (L"Menu_HelpAddModifyThemes")); |
146 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ADDMODIFYVISUALTHEMES, LOCALIZE (L"Menu_HelpAddModifyThemes")); |
147 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ADDMODIFYENGINES, LOCALIZE (L"Menu_HelpAddModifyEngines")); |
147 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ADDMODIFYENGINES, LOCALIZE (L"Menu_HelpAddModifyEngines")); |
148 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ADDMODIFYTRANSLATIONS, LOCALIZE (L"Menu_HelpAddModifyTranslations")); |
148 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ADDMODIFYTRANSLATIONS, LOCALIZE (L"Menu_HelpAddModifyTranslations")); |
- | 149 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
|
- | 150 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_REPORTAPROBLEM, LOCALIZE (L"Menu_HelpReportAProblem")); |
|
149 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
151 | AppendMenu (hDropDownMenu, MF_SEPARATOR, 0, NULL); |
150 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ABOUT, LOCALIZE (L"Menu_HelpAbout")); |
152 | AppendMenu (hDropDownMenu, MF_STRING, MENUID_HELP_ABOUT, LOCALIZE (L"Menu_HelpAbout")); |
151 | AppendMenu (hMainMenu, MF_POPUP, (UINT) hDropDownMenu, LOCALIZE (L"Menu_Help")); |
153 | AppendMenu (hMainMenu, MF_POPUP, (UINT) hDropDownMenu, LOCALIZE (L"Menu_Help")); |
152 | DestroyMenu (hDropDownMenu); |
154 | DestroyMenu (hDropDownMenu); |
153 | 155 | ||
Line 798... | Line 800... | ||
798 | va_end (argptr); |
800 | va_end (argptr); |
799 | fclose (fp); // flush buffers and close it |
801 | fclose (fp); // flush buffers and close it |
800 | } |
802 | } |
801 | 803 | ||
802 | return; // finished |
804 | return; // finished |
- | 805 | } |
|
- | 806 | ||
- | 807 | ||
- | 808 | bool Debug_SendLogToAuthor (void) |
|
- | 809 | { |
|
- | 810 | // this function upload the engine history to the remote server for debug purposes. |
|
- | 811 | ||
- | 812 | static char log_buffer[512 * 1024]; |
|
- | 813 | static char log_base64buffer[512 * 1024 * 4 / 3]; |
|
- | 814 | static char board_buffer[8 * 5 * 8 * 3]; |
|
- | 815 | static char board_base64buffer[8 * 5 * 8 * 3 * 4 / 3]; |
|
- | 816 | static char http_buffer[1024 * 1024]; // used both for request and reply |
|
- | 817 | static char user_email[64]; |
|
- | 818 | static char program_version[10]; |
|
- | 819 | ||
- | 820 | struct sockaddr_in service; |
|
- | 821 | struct hostent *hostinfo; |
|
- | 822 | unsigned char part; |
|
- | 823 | char *write_ptr; |
|
- | 824 | int write_index; |
|
- | 825 | int read_index; |
|
- | 826 | int length; |
|
- | 827 | SOCKET s; |
|
- | 828 | FILE *fp; |
|
- | 829 | int i; |
|
- | 830 | int j; |
|
- | 831 | ||
- | 832 | // get a hand on the log file and read its contents |
|
- | 833 | _wfopen_s (&fp, logfile_pathname, L"rb"); |
|
- | 834 | if (fp == NULL) |
|
- | 835 | return (false); // couldn't open game history log file, return an error condition |
|
- | 836 | fseek (fp, 0, SEEK_END); |
|
- | 837 | length = ftell (fp); // get file size |
|
- | 838 | fseek (fp, 0, SEEK_SET); |
|
- | 839 | if (length > sizeof (log_base64buffer) - 1) |
|
- | 840 | return (false); // history file too big, return an error condition |
|
- | 841 | fread (log_base64buffer, 1, length, fp); |
|
- | 842 | log_base64buffer[length] = 0; // terminate buffer ourselves |
|
- | 843 | fclose (fp); |
|
- | 844 | ConvertTo7BitASCII (log_buffer, sizeof (log_buffer), (wchar_t *) log_base64buffer); |
|
- | 845 | ||
- | 846 | // capture and encode the board |
|
- | 847 | 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 >.< |
|
- | 849 | { |
|
- | 850 | write_ptr = &board_buffer[strlen (board_buffer)]; |
|
- | 851 | *write_ptr = '|'; write_ptr++; |
|
- | 852 | for (j = 0; j < 8; j++) |
|
- | 853 | { |
|
- | 854 | part = the_board.moves[the_board.move_count - 1].slots[i][j].part; |
|
- | 855 | *write_ptr = ' '; write_ptr++; |
|
- | 856 | if (part == PART_ROOK) *write_ptr = 'r'; |
|
- | 857 | else if (part == PART_KNIGHT) *write_ptr = 'k'; |
|
- | 858 | else if (part == PART_BISHOP) *write_ptr = 'b'; |
|
- | 859 | else if (part == PART_QUEEN) *write_ptr = 'q'; |
|
- | 860 | else if (part == PART_KING) *write_ptr = 'k'; |
|
- | 861 | else if (part == PART_PAWN) *write_ptr = 'p'; |
|
- | 862 | else *write_ptr = ' '; |
|
- | 863 | if (the_board.moves[the_board.move_count - 1].slots[i][j].color == COLOR_WHITE) *write_ptr = toupper (*write_ptr); |
|
- | 864 | *write_ptr++; |
|
- | 865 | *write_ptr = ' '; write_ptr++; |
|
- | 866 | *write_ptr = '|'; write_ptr++; |
|
- | 867 | } |
|
- | 868 | *write_ptr = '\n'; write_ptr++; |
|
- | 869 | *write_ptr = 0; |
|
- | 870 | strcat_s (board_buffer, sizeof (board_buffer), "+---+---+---+---+---+---+---+---+\n"); |
|
- | 871 | } |
|
- | 872 | ||
- | 873 | // build the program version |
|
- | 874 | memcpy (&program_version[0], &(__DATE__)[7], 4); |
|
- | 875 | memcpy (&program_version[4], (strncmp (__DATE__, "Jan", 3) == 0 ? "01" : |
|
- | 876 | (strncmp (__DATE__, "Feb", 3) == 0 ? "02" : |
|
- | 877 | (strncmp (__DATE__, "Mar", 3) == 0 ? "03" : |
|
- | 878 | (strncmp (__DATE__, "Apr", 3) == 0 ? "04" : |
|
- | 879 | (strncmp (__DATE__, "May", 3) == 0 ? "05" : |
|
- | 880 | (strncmp (__DATE__, "Jun", 3) == 0 ? "06" : |
|
- | 881 | (strncmp (__DATE__, "Jul", 3) == 0 ? "07" : |
|
- | 882 | (strncmp (__DATE__, "Aug", 3) == 0 ? "08" : |
|
- | 883 | (strncmp (__DATE__, "Sep", 3) == 0 ? "09" : |
|
- | 884 | (strncmp (__DATE__, "Oct", 3) == 0 ? "10" : |
|
- | 885 | (strncmp (__DATE__, "Nov", 3) == 0 ? "11" : |
|
- | 886 | (strncmp (__DATE__, "Dec", 3) == 0 ? "12" : "??")))))))))))), 2); |
|
- | 887 | memcpy (&program_version[6], &(__DATE__)[4], 2); |
|
- | 888 | program_version[8] = 0; |
|
- | 889 | ||
- | 890 | // initialize the network subsystem if required |
|
- | 891 | if (!Network_Init ()) |
|
- | 892 | return (false); // couldn't initialize WinSock, return an error condition |
|
- | 893 | ||
- | 894 | // get our distribution server's IP address from the host name |
|
- | 895 | hostinfo = gethostbyname ("pmbaty.com"); |
|
- | 896 | if (hostinfo == NULL) |
|
- | 897 | return (false); // couldn't resolve hostname, return an error condition |
|
- | 898 | ||
- | 899 | // fill in the sockaddr server structure with the server hostinfo data |
|
- | 900 | service.sin_family = AF_INET; |
|
- | 901 | service.sin_addr.s_addr = inet_addr (inet_ntoa (*(struct in_addr *) hostinfo->h_addr_list[0])); |
|
- | 902 | service.sin_port = htons (80); // connect to webserver there (port 80) |
|
- | 903 | ||
- | 904 | // create our socket |
|
- | 905 | if ((s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) |
|
- | 906 | return (false); // couldn't resolve hostname, return an error condition |
|
- | 907 | ||
- | 908 | // connect to the distributor's webserver using that socket |
|
- | 909 | if (connect (s, (struct sockaddr *) &service, sizeof (service)) == -1) |
|
- | 910 | { |
|
- | 911 | closesocket (s); // finished communicating, close TCP socket |
|
- | 912 | return (false); // couldn't resolve hostname, return an error condition |
|
- | 913 | } |
|
- | 914 | ||
- | 915 | // build the HTTP POST query and send it |
|
- | 916 | if (options.registration.user_email[0] != 0) |
|
- | 917 | ConvertTo7BitASCII (user_email, sizeof (user_email), options.registration.user_email); |
|
- | 918 | else |
|
- | 919 | strcpy_s (user_email, sizeof (user_email), "an+unregistered+user"); |
|
- | 920 | length = strlen ("registrant=") + strlen (user_email) |
|
- | 921 | + strlen ("&version=") + strlen (program_version) |
|
- | 922 | + strlen ("&board=") + base64_encode (board_base64buffer, board_buffer, strlen (board_buffer)) |
|
- | 923 | + strlen ("&log=") + base64_encode (log_base64buffer, log_buffer, strlen (log_buffer)); |
|
- | 924 | sprintf_s (http_buffer, sizeof (http_buffer), |
|
- | 925 | "POST /chess/sendcrash.php HTTP/1.1\r\n" |
|
- | 926 | "Host: pmbaty.com\r\n" |
|
- | 927 | "Content-Type: application/x-www-form-urlencoded\r\n" |
|
- | 928 | "Content-Length: %d\r\n" |
|
- | 929 | "Connection: close\r\n" |
|
- | 930 | "\r\n" |
|
- | 931 | "registrant=%s&version=%s&board=%s&log=%s", length, user_email, program_version, board_base64buffer, log_base64buffer); |
|
- | 932 | length = strlen (http_buffer); |
|
- | 933 | write_index = send (s, http_buffer, length, 0); // send the HTTP query |
|
- | 934 | if (write_index != length) |
|
- | 935 | { |
|
- | 936 | closesocket (s); // finished communicating, close TCP socket |
|
- | 937 | return (false); // couldn't resolve hostname, return an error condition |
|
- | 938 | } |
|
- | 939 | ||
- | 940 | // read the reply (10 seconds timeout) |
|
- | 941 | http_buffer[0] = 0; |
|
- | 942 | read_index = RecvWithTimeout (s, 10.0f, http_buffer, sizeof (http_buffer), 0); |
|
- | 943 | if (read_index < 1) |
|
- | 944 | { |
|
- | 945 | closesocket (s); // finished communicating, close TCP socket |
|
- | 946 | return (false); // couldn't resolve hostname, return an error condition |
|
- | 947 | } |
|
- | 948 | ||
- | 949 | closesocket (s); // finished communicating, close TCP socket |
|
- | 950 | ||
- | 951 | // terminate recv buffer ourselves |
|
- | 952 | http_buffer[read_index] = 0; |
|
- | 953 | ||
- | 954 | //MessageBoxA (NULL, http_buffer, "HTTP response", MB_OK); |
|
- | 955 | return (strstr (http_buffer, "Success") != NULL); // and return whether the server accepted our post |
|
803 | } |
956 | } |
804 | 957 | ||
805 | 958 | ||
806 | int RecvWithTimeout (int socket_id, float timeout_in_seconds, char *outbuf, size_t outbuf_size, int flags) |
959 | int RecvWithTimeout (int socket_id, float timeout_in_seconds, char *outbuf, size_t outbuf_size, int flags) |
807 | { |
960 | { |