OSDN Git Service

Revert "Merge branch 'master' of git.osdn.net:/gitroot/hengband/hengband"
[hengband/hengband.git] / src / report.c
index 7517652..ad5d1da 100644 (file)
 #define HTTP_PROXY ""                   /*!< デフォルトのプロキシURL / Default proxy url */
 #define HTTP_PROXY_PORT 0               /*!< デフォルトのプロキシポート / Default proxy port */
 #define HTTP_TIMEOUT    20              /*!< デフォルトのタイムアウト時間(秒) / Timeout length (second) */
-#define SCORE_SERVER "moon.kmc.gr.jp"   /*!< デフォルトのスコアサーバURL / Default score server url */
+#define SCORE_SERVER "hengband.osdn.jp" /*!< デフォルトのスコアサーバURL / Default score server url */
 #define SCORE_PORT 80                   /*!< デフォルトのスコアサーバポート / Default score server port */
 
 #ifdef JP
-#define SCORE_PATH "http://moon.kmc.gr.jp/hengband/hengscore/score.cgi" /*!< スコア開示URL */
+#define SCORE_PATH "http://hengband.osdn.jp/score/register_score.php" /*!< スコア開示URL */
 #else
 #define SCORE_PATH "http://moon.kmc.gr.jp/hengband/hengscore-en/score.cgi" /*!< スコア開示URL */
 #endif
@@ -100,7 +100,7 @@ static void buf_delete(BUF *b)
  * @param size 追加サイズ
  * @return 追加後のバッファ容量
  */
-static int buf_append(BUF *buf, const char *data, size_t size)
+static int buf_append(BUF *buf, concptr data, size_t size)
 {
        while (buf->size + size > buf->max_size)
        {
@@ -126,7 +126,7 @@ static int buf_append(BUF *buf, const char *data, size_t size)
  * @param fmt 文字列フォーマット
  * @return 追加後のバッファ容量
  */
-static int buf_sprintf(BUF *buf, const char *fmt, ...)
+static int buf_sprintf(BUF *buf, concptr fmt, ...)
 {
        int             ret;
        char    tmpbuf[8192];
@@ -194,7 +194,7 @@ static int buf_write(BUF *buf, int fd)
        return buf->size;
 }
 
-static int buf_search(BUF *buf, const char *str)
+static int buf_search(BUF *buf, concptr str)
 {
        char *ret;
 
@@ -228,22 +228,37 @@ static BUF * buf_subbuf(BUF *buf, int pos1, size_t sz)
  * @param buf 伝送内容バッファ
  * @return なし
  */
-static void http_post(int sd, cptr url, BUF *buf)
+static bool http_post(int sd, concptr url, BUF *buf)
 {
        BUF *output;
+       char response_buf[1024] = "";
+       concptr HTTP_RESPONSE_CODE_OK = "HTTP/1.1 200 OK";
 
        output = buf_new();
-       buf_sprintf(output, "POST %s HTTP/1.0\n", url);
-       buf_sprintf(output, "User-Agent: Hengband %d.%d.%d\n",
+       buf_sprintf(output, "POST %s HTTP/1.0\r\n", url);
+       buf_sprintf(output, "User-Agent: Hengband %d.%d.%d\r\n",
                    FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
 
-       buf_sprintf(output, "Content-Length: %d\n", buf->size);
-       buf_sprintf(output, "Content-Encoding: binary\n");
-       buf_sprintf(output, "Content-Type: application/octet-stream\n");
-       buf_sprintf(output, "\n");
+       buf_sprintf(output, "Content-Length: %d\r\n", buf->size);
+       buf_sprintf(output, "Content-Encoding: binary\r\n");
+#ifdef JP
+#ifdef SJIS
+       buf_sprintf(output, "Content-Type: text/plain; charset=SHIFT_JIS\r\n");
+#endif
+#ifdef EUC
+       buf_sprintf(output, "Content-Type: text/plain; charset=EUC-JP\r\n");
+#endif
+#else
+       buf_sprintf(output, "Content-Type: text/plain; charset=ASCII\r\n");
+#endif
+       buf_sprintf(output, "\r\n");
        buf_append(output, buf->data, buf->size);
 
        soc_write(sd, output->data, output->size);
+
+       soc_read(sd, response_buf, sizeof(response_buf));
+
+       return strncmp(response_buf, HTTP_RESPONSE_CODE_OK, strlen(HTTP_RESPONSE_CODE_OK)) == 0;
 }
 
 /*!
@@ -255,7 +270,7 @@ static errr make_dump(BUF* dumpbuf)
 {
        char            buf[1024];
        FILE *fff;
-       char file_name[1024];
+       GAME_TEXT file_name[1024];
 
        /* Open a new file */
        fff = my_fopen_temp(file_name, 1024);
@@ -272,8 +287,6 @@ static errr make_dump(BUF* dumpbuf)
 
        /* 一旦一時ファイルを作る。通常のダンプ出力と共通化するため。 */
        (void)make_character_dump(fff);
-
-       /* Close the file */
        my_fclose(fff);
 
        /* Open for read */
@@ -283,11 +296,7 @@ static errr make_dump(BUF* dumpbuf)
        {
                (void)buf_sprintf(dumpbuf, "%s", buf);
        }
-
-       /* Close the file */
        my_fclose(fff);
-
-       /* Remove the file */
        fd_kill(file_name);
 
        /* Success */
@@ -298,21 +307,21 @@ static errr make_dump(BUF* dumpbuf)
  * @brief スクリーンダンプを作成する/ Make screen dump to buffer
  * @return 作成したスクリーンダンプの参照ポインタ
  */
-cptr make_screen_dump(void)
+concptr make_screen_dump(void)
 {
        BUF *screen_buf;
        int y, x, i;
-       cptr ret;
+       concptr ret;
 
-       byte a = 0, old_a = 0;
-       char c = ' ';
+       TERM_COLOR a = 0, old_a = 0;
+       SYMBOL_CODE c = ' ';
 
-       static cptr html_head[] = {
+       static concptr html_head[] = {
                "<html>\n<body text=\"#ffffff\" bgcolor=\"#000000\">\n",
                "<pre>",
                0,
        };
-       static cptr html_foot[] = {
+       static concptr html_foot[] = {
                "</pre>\n",
                "</body>\n</html>\n",
                0,
@@ -336,10 +345,7 @@ cptr make_screen_dump(void)
                use_graphics = FALSE;
                reset_visuals();
 
-               /* Redraw everything */
                p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
-
-               /* Hack -- update */
                handle_stuff();
        }
 
@@ -357,7 +363,7 @@ cptr make_screen_dump(void)
                for (x = 0; x < wid - 1; x++)
                {
                        int rv, gv, bv;
-                       cptr cc = NULL;
+                       concptr cc = NULL;
                        /* Get the attr/char */
                        (void)(Term_what(x, y, &a, &c));
 
@@ -366,6 +372,8 @@ cptr make_screen_dump(void)
                        case '&': cc = "&amp;"; break;
                        case '<': cc = "&lt;"; break;
                        case '>': cc = "&gt;"; break;
+                       case '"': cc = "&quot;"; break;
+                       case '\'': cc = "&#39;"; break;
 #ifdef WINDOWS
                        case 0x1f: c = '.'; break;
                        case 0x7f: c = (a == 0x09) ? '%' : '#'; break;
@@ -393,7 +401,7 @@ cptr make_screen_dump(void)
                buf_sprintf(screen_buf, html_foot[i]);
 
        /* Screen dump size is too big ? */
-       if (screen_buf->size + 1> SCREEN_BUF_SIZE)
+       if (screen_buf->size + 1> SCREEN_BUF_MAX_SIZE)
        {
                ret = NULL;
        }
@@ -413,10 +421,7 @@ cptr make_screen_dump(void)
                use_graphics = TRUE;
                reset_visuals();
 
-               /* Redraw everything */
                p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
-
-               /* Hack -- update */
                handle_stuff();
        }
 
@@ -462,11 +467,11 @@ errr report_score(void)
 #endif
        buf_sprintf(score, "score: %d\n", total_points());
        buf_sprintf(score, "level: %d\n", p_ptr->lev);
-       buf_sprintf(score, "depth: %d\n", dun_level);
+       buf_sprintf(score, "depth: %d\n", current_floor_ptr->dun_level);
        buf_sprintf(score, "maxlv: %d\n", p_ptr->max_plv);
        buf_sprintf(score, "maxdp: %d\n", max_dlv[DUNGEON_ANGBAND]);
        buf_sprintf(score, "au: %d\n", p_ptr->au);
-       buf_sprintf(score, "turns: %d\n", turn_real(turn));
+       buf_sprintf(score, "turns: %d\n", turn_real(current_world_ptr->game_turn));
        buf_sprintf(score, "sex: %d\n", p_ptr->psex);
        buf_sprintf(score, "race: %s\n", rp_ptr->title);
        buf_sprintf(score, "class: %s\n", cp_ptr->title);
@@ -524,34 +529,62 @@ errr report_score(void)
                sd = connect_server(HTTP_TIMEOUT, SCORE_SERVER, SCORE_PORT);
 
 
-               if (!(sd < 0)) break;
+               if (sd < 0) {
 #ifdef JP
-               sprintf(buff, "スコア・サーバへの接続に失敗しました。(%s)", soc_err());
+                       sprintf(buff, "スコア・サーバへの接続に失敗しました。(%s)", soc_err());
 #else
-               sprintf(buff, "Failed to connect to the score server.(%s)", soc_err());
+                       sprintf(buff, "Failed to connect to the score server.(%s)", soc_err());
 #endif
-               prt(buff, 0, 0);
-               (void)inkey();
-               
+                       prt(buff, 0, 0);
+                       (void)inkey();
+
 #ifdef JP
-               if (!get_check_strict("もう一度接続を試みますか? ", CHECK_NO_HISTORY))
+                       if (!get_check_strict("もう一度接続を試みますか? ", CHECK_NO_HISTORY))
 #else
-               if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
+                       if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
 #endif
-               {
-                       err = 1;
-                       goto report_end;
+                       {
+                               err = 1;
+                               goto report_end;
+                       }
+
+                       continue;
                }
-       }
+
 #ifdef JP
-       prt("スコア送信中...", 0, 0);
+               prt("スコア送信中...", 0, 0);
 #else
-       prt("Sending the score...", 0, 0);
+               prt("Sending the score...", 0, 0);
 #endif
-       Term_fresh();
-       http_post(sd, SCORE_PATH, score);
+               Term_fresh();
+
+               if (!http_post(sd, SCORE_PATH, score)) {
+                       disconnect_server(sd);
+#ifdef JP
+                       sprintf(buff, "スコア・サーバへの送信に失敗しました。");
+#else
+                       sprintf(buff, "Failed to send to the score server.");
+#endif
+                       prt(buff, 0, 0);
+                       (void)inkey();
+
+#ifdef JP
+                       if (!get_check_strict("もう一度接続を試みますか? ", CHECK_NO_HISTORY))
+#else
+                       if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
+#endif
+                       {
+                               err = 1;
+                               goto report_end;
+                       }
+
+                       continue;
+               }
+
+               disconnect_server(sd);
+               break;
+       }
 
-       disconnect_server(sd);
  report_end:
 #ifdef WINDOWS
        WSACleanup();