OSDN Git Service

[Refactor] #37353 コメント整理 / Refactor comments.
[hengband/hengband.git] / src / report.c
index bd509e7..016762e 100644 (file)
@@ -1,6 +1,11 @@
-/* File: report.c */
+/*!
+ * @file report.c
+ * @brief スコアサーバ転送機能の実装
+ * @date 2014/07/14
+ * @author Hengband Team
+ */
 
-#define _GNU_SOURCE
+#define _GNU_SOURCE /*!< 未使用*/
 #include "angband.h"
 
 #ifdef WORLD_SCORE
 #include <signal.h>
 #endif
 
+/*
+ * internet resource value
+ */
+#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 "hengband.osdn.jp" /*!< デフォルトのスコアサーバURL / Default score server url */
+#define SCORE_PORT 80                   /*!< デフォルトのスコアサーバポート / Default score server port */
+
 #ifdef JP
-#define SCORE_PATH "http://www.kmc.gr.jp/~habu/local/hengscore/score.cgi"
+#define SCORE_PATH "http://hengband.osdn.jp/score/register_score.php" /*!< スコア開示URL */
 #else
-#define SCORE_PATH "http://www.kmc.gr.jp/~habu/local/hengscore-en/score.cgi"
+#define SCORE_PATH "http://moon.kmc.gr.jp/hengband/hengscore-en/score.cgi" /*!< スコア開示URL */
 #endif
 
 /* for debug */
-//#define SCORE_PATH "http://www.kmc.gr.jp/~habu/local/scoretest/score.cgi"
+#if 0
+#define SCORE_PATH "http://moon.kmc.gr.jp/hengband/scoretest/score.cgi" /*!< スコア開示URL */
+#endif
 
 /*
-  simple buffer library
* simple buffer library
  */
-
-typedef struct _buf{
-  size_t max_size;
-  size_t size;
-  char *data;
+typedef struct {
+       size_t max_size;
+       size_t size;
+       char *data;
 } BUF;
 
-#define        BUFSIZE (65536)
-
-#if defined(WINDOWS) || defined(SUNOS4) || defined(MACINTOSH) || defined(SGI)
-#define vasprintf      Vasprintf
-#endif
+#define        BUFSIZE (65536) /*!< スコアサーバ転送バッファサイズ */
 
-#ifdef SUNOS4
-static int Vasprintf(char **buf, const char *fmt, va_list ap)
-{
-    int ret;
-
-    *buf = malloc(BUFSIZE);
-
-    ret = vsnprintf(*buf, BUFSIZE, fmt, ap);
-
-    return ret;
-}
-#endif
-
-#if defined(WINDOWS) || defined(MACINTOSH) || defined(SGI)
-static int Vasprintf(char **buf, const char *fmt, va_list ap)
+/*!
+ * @brief 転送用バッファの確保
+ * @return 確保したバッファの参照ポインタ
+ */
+static BUF* buf_new(void)
 {
-    int ret;
-    *buf = malloc(BUFSIZE * 4);
+       BUF *p;
 
-    ret = vsprintf(*buf, fmt, ap);
+       if ((p = malloc(sizeof(BUF))) == NULL)
+               return NULL;
 
-    return ret;
-}
-#endif
-
-static BUF* buf_new(void)
-{
-    BUF *p;
-
-    p = malloc(sizeof(BUF));
-    if((p = malloc(sizeof(BUF))) == NULL)
-       return NULL;
-
-    p->size = 0;
-    p->max_size = BUFSIZE;
-    if((p->data = malloc(BUFSIZE)) == NULL){
-       free(p);
-       return NULL;
-    }
-    return p;
+       p->size = 0;
+       p->max_size = BUFSIZE;
+       if ((p->data = malloc(BUFSIZE)) == NULL)
+       {
+               free(p);
+               return NULL;
+       }
+       return p;
 }
 
-#if 0
+/*!
+ * @brief 転送用バッファの解放
+ * @param b 解放するバッファの参照ポインタ
+ */
 static void buf_delete(BUF *b)
 {
-    free(b->data);
-    free(b);
+       free(b->data);
+       free(b);
 }
-#endif
 
+/*!
+ * @brief 転送用バッファにデータを追加する
+ * @param buf 追加先バッファの参照ポインタ
+ * @param data 追加元データ
+ * @param size 追加サイズ
+ * @return 追加後のバッファ容量
+ */
 static int buf_append(BUF *buf, const char *data, size_t size)
 {
-    while(buf->size + size > buf->max_size){
-       char *tmp;
-       if((tmp = malloc(buf->max_size * 2)) == NULL) return -1;
+       while (buf->size + size > buf->max_size)
+       {
+               char *tmp;
+               if ((tmp = malloc(buf->max_size * 2)) == NULL) return -1;
 
-       memcpy(tmp, buf->data, buf->max_size);
-       free(buf->data);
+               memcpy(tmp, buf->data, buf->max_size);
+               free(buf->data);
 
-       buf->data = tmp;
+               buf->data = tmp;
 
-       buf->max_size *= 2;
-    }
-    memcpy(buf->data + buf->size, data, size);
-    buf->size += size;
+               buf->max_size *= 2;
+       }
+       memcpy(buf->data + buf->size, data, size);
+       buf->size += size;
 
-    return buf->size;
+       return buf->size;
 }
 
+/*!
+ * @brief 転送用バッファにフォーマット指定した文字列データを追加する
+ * @param buf 追加先バッファの参照ポインタ
+ * @param fmt 文字列フォーマット
+ * @return 追加後のバッファ容量
+ */
 static int buf_sprintf(BUF *buf, const char *fmt, ...)
 {
-    int                ret;
-    char       *tmpbuf;
-    va_list    ap;
+       int             ret;
+       char    tmpbuf[8192];
+       va_list ap;
 
-    va_start(ap, fmt);
-    vasprintf(&tmpbuf, fmt, ap);
-    va_end(ap);
+       va_start(ap, fmt);
+#if defined(HAVE_VSNPRINTF)
+       ret = vsnprintf(tmpbuf, sizeof(tmpbuf), fmt, ap);
+#else
+       ret = vsprintf(tmpbuf, fmt, ap);
+#endif
+       va_end(ap);
 
-    if(!tmpbuf)
-       return -1;
+       if (ret < 0) return -1;
 
-    ret = buf_append(buf, tmpbuf, strlen(tmpbuf));
+#if ('\r' == 0x0a && '\n' == 0x0d)
+       {
+               /*
+                * Originally '\r'= CR (= 0x0d) and '\n'= LF (= 0x0a)
+                * But for MPW (Macintosh Programers Workbench), these
+                * are reversed so that '\r'=LF and '\n'=CR unless the
+                * -noMapCR option is not defined.
+                *
+                * We need to swap back these here since the score
+                * dump text should be written using LF as the end of
+                * line.
+                */
+               char *ptr;
+               for (ptr = tmpbuf; *ptr; ptr++)
+               {
+                       if (0x0d == *ptr) *ptr = 0x0a;
+               }
+       }
+#endif
 
-    free(tmpbuf);
+       ret = buf_append(buf, tmpbuf, strlen(tmpbuf));
 
-    return ret;
+       return ret;
 }
 
 #if 0
 static int buf_read(BUF *buf, int fd)
 {
-    int len;
+       int len;
 #ifndef MACINTOSH
-    char tmp[BUFSIZE];
+       char tmp[BUFSIZE];
 #else
        char *tmp;
        
        tmp = calloc( BUFSIZE , sizeof(char) );
 #endif
 
-    while((len = read(fd, tmp, BUFSIZE)) > 0)
-       buf_append(buf, tmp, len);
+       while ((len = read(fd, tmp, BUFSIZE)) > 0)
+               buf_append(buf, tmp, len);
 
-    return buf->size;
+       return buf->size;
 }
 #endif
 
 #if 0
 static int buf_write(BUF *buf, int fd)
 {
-    write(fd, buf->data, buf->size);
+       write(fd, buf->data, buf->size);
 
-    return buf->size;
+       return buf->size;
 }
 
 static int buf_search(BUF *buf, const char *str)
 {
-    char *ret;
+       char *ret;
 
-    ret = strstr(buf->data, str);
+       ret = my_strstr(buf->data, str);
 
-    if(!ret)
-       return -1;
+       if (!ret) return -1;
 
-    return ret - buf->data;
+       return ret - buf->data;
 }
 
 static BUF * buf_subbuf(BUF *buf, int pos1, size_t sz)
 {
-    BUF *ret;
+       BUF *ret;
 
-    if(pos1 < 0)
-       return NULL;
+       if (pos1 < 0) return NULL;
 
-    ret = buf_new();
+       ret = buf_new();
 
-    if(sz <= 0)
-       sz = buf->size - pos1;
+       if (sz <= 0) sz = buf->size - pos1;
 
-    buf_append(ret, buf->data + pos1, sz);
+       buf_append(ret, buf->data + pos1, sz);
 
-    return ret;
+       return ret;
 }
 #endif
 
-static void http_post(int sd, char *url, BUF *buf)
+/*!
+ * @brief HTTPによるダンプ内容伝送
+ * @param sd ソケットID
+ * @param url 伝送先URL
+ * @param buf 伝送内容バッファ
+ * @return なし
+ */
+static bool http_post(int sd, cptr url, BUF *buf)
 {
-  BUF *output;
+       BUF *output;
+       char response_buf[1024] = "";
+       const char *HTTP_RESPONSE_CODE_OK = "HTTP/1.1 200 OK";
 
-  output = buf_new();
-  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);
+       output = buf_new();
+       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\r\n", buf->size);
-  buf_sprintf(output, "Content-Encoding: binary\r\n");
-  buf_sprintf(output, "Content-Type: application/octet-stream\r\n");
-  buf_sprintf(output, "\r\n");
-  buf_append(output, buf->data, buf->size);
+       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_write(sd, output->data, output->size);
 
+       soc_read(sd, response_buf, sizeof(response_buf));
 
-/* ¥­¥ã¥é¥¯¥¿¥À¥ó¥×¤òºî¤Ã¤Æ BUF¤ËÊݸ */
+       return strncmp(response_buf, HTTP_RESPONSE_CODE_OK, strlen(HTTP_RESPONSE_CODE_OK)) == 0;
+}
+
+/*!
+ * @brief キャラクタダンプを作って BUFに保存
+ * @param dumpbuf 伝送内容バッファ
+ * @return エラーコード
+ */
 static errr make_dump(BUF* dumpbuf)
 {
-       errr make_character_dump(FILE *fff);
-
        char            buf[1024];
        FILE *fff;
        char file_name[1024];
 
        /* Open a new file */
        fff = my_fopen_temp(file_name, 1024);
-       if (!fff) {
+       if (!fff)
+       {
 #ifdef JP
-           msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
+               msg_format("一時ファイル %s を作成できませんでした。", file_name);
 #else
-           msg_format("Failed to create temporary file %s.", file_name);
+               msg_format("Failed to create temporary file %s.", file_name);
 #endif
-           msg_print(NULL);
-           return 1;
+               msg_print(NULL);
+               return 1;
        }
 
-       /* °ìö°ì»þ¥Õ¥¡¥¤¥ë¤òºî¤ë¡£Ä̾ï¤Î¥À¥ó¥×½ÐÎϤȶ¦Ä̲½¤¹¤ë¤¿¤á¡£ */
+       /* 一旦一時ファイルを作る。通常のダンプ出力と共通化するため。 */
        (void)make_character_dump(fff);
 
        /* Close the file */
@@ -248,9 +296,12 @@ static errr make_dump(BUF* dumpbuf)
 
        while (fgets(buf, 1024, fff))
        {
-               (void)buf_append(dumpbuf, buf, strlen(buf));
+               (void)buf_sprintf(dumpbuf, "%s", buf);
        }
 
+       /* Close the file */
+       my_fclose(fff);
+
        /* Remove the file */
        fd_kill(file_name);
 
@@ -258,6 +309,141 @@ static errr make_dump(BUF* dumpbuf)
        return (0);
 }
 
+/*!
+ * @brief スクリーンダンプを作成する/ Make screen dump to buffer
+ * @return 作成したスクリーンダンプの参照ポインタ
+ */
+cptr make_screen_dump(void)
+{
+       BUF *screen_buf;
+       int y, x, i;
+       cptr ret;
+
+       TERM_COLOR a = 0, old_a = 0;
+       char c = ' ';
+
+       static cptr html_head[] = {
+               "<html>\n<body text=\"#ffffff\" bgcolor=\"#000000\">\n",
+               "<pre>",
+               0,
+       };
+       static cptr html_foot[] = {
+               "</pre>\n",
+               "</body>\n</html>\n",
+               0,
+       };
+
+       bool old_use_graphics = use_graphics;
+
+       int wid, hgt;
+
+       Term_get_size(&wid, &hgt);
+
+       /* Alloc buffer */
+       screen_buf = buf_new();
+       if (screen_buf == NULL) return (NULL);
+
+       if (old_use_graphics)
+       {
+               /* Clear -more- prompt first */
+               msg_print(NULL);
+
+               use_graphics = FALSE;
+               reset_visuals();
+
+               /* Redraw everything */
+               p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
+
+               /* Hack -- update */
+               handle_stuff();
+       }
+
+       for (i = 0; html_head[i]; i++)
+               buf_sprintf(screen_buf, html_head[i]);
+
+       /* Dump the screen */
+       for (y = 0; y < hgt; y++)
+       {
+               /* Start the row */
+               if (y != 0)
+                       buf_sprintf(screen_buf, "\n");
+
+               /* Dump each row */
+               for (x = 0; x < wid - 1; x++)
+               {
+                       int rv, gv, bv;
+                       cptr cc = NULL;
+                       /* Get the attr/char */
+                       (void)(Term_what(x, y, &a, &c));
+
+                       switch (c)
+                       {
+                       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;
+#endif
+                       }
+
+                       a = a & 0x0F;
+                       if ((y == 0 && x == 0) || a != old_a) {
+                               rv = angband_color_table[a][1];
+                               gv = angband_color_table[a][2];
+                               bv = angband_color_table[a][3];
+                               buf_sprintf(screen_buf, "%s<font color=\"#%02x%02x%02x\">", 
+                                           ((y == 0 && x == 0) ? "" : "</font>"), rv, gv, bv);
+                               old_a = a;
+                       }
+                       if (cc)
+                               buf_sprintf(screen_buf, "%s", cc);
+                       else
+                               buf_sprintf(screen_buf, "%c", c);
+               }
+       }
+       buf_sprintf(screen_buf, "</font>");
+
+       for (i = 0; html_foot[i]; i++)
+               buf_sprintf(screen_buf, html_foot[i]);
+
+       /* Screen dump size is too big ? */
+       if (screen_buf->size + 1> SCREEN_BUF_MAX_SIZE)
+       {
+               ret = NULL;
+       }
+       else
+       {
+               /* Terminate string */
+               buf_append(screen_buf, "", 1);
+
+               ret = string_make(screen_buf->data);
+       }
+
+       /* Free buffer */
+       buf_delete(screen_buf);
+
+       if (old_use_graphics)
+       {
+               use_graphics = TRUE;
+               reset_visuals();
+
+               /* Redraw everything */
+               p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
+
+               /* Hack -- update */
+               handle_stuff();
+       }
+
+       return ret;
+}
+
+/*!
+ * @brief スコア転送処理のメインルーチン
+ * @return エラーコード
+ */
 errr report_score(void)
 {
 #ifdef MACINTOSH
@@ -267,66 +453,60 @@ errr report_score(void)
 #endif
 
 #ifdef WINDOWS
-    WSADATA wsaData;
-    WORD wVersionRequested =(WORD) (( 1) |  ( 1 << 8));
+       WSADATA wsaData;
+       WORD wVersionRequested =(WORD) (( 1) |  ( 1 << 8));
 #endif
 
+       BUF *score;
+       int sd;
+       char seikakutmp[128];
 
-  BUF *score;
-  int sd;
-  char date[10];
-  char seikakutmp[128];
-  time_t ct = time(NULL);
-
-  score = buf_new();
+       score = buf_new();
 
 #ifdef JP
-  sprintf(seikakutmp, "%s%s", ap_ptr->title, (ap_ptr->no ? "¤Î" : ""));
+       sprintf(seikakutmp, "%s%s", ap_ptr->title, (ap_ptr->no ? "の" : ""));
 #else
-  sprintf(seikakutmp, "%s ", ap_ptr->title);
+       sprintf(seikakutmp, "%s ", ap_ptr->title);
 #endif
 
-  /* HiperMegaHack -- Ê¸»ú¥³¡¼¥É¤òÁ÷¤ë */
-#if defined(EUC)
-  buf_sprintf(score, "code: 0\n");
-#elif defined(SJIS)
-  buf_sprintf(score, "code: 1\n");
-#elif defined(JIS)
-  buf_sprintf(score, "code: 2\n");
-#endif
-  buf_sprintf(score, "name: %s\n", player_name);
+       buf_sprintf(score, "name: %s\n", p_ptr->name);
 #ifdef JP
-  buf_sprintf(score, "version: ÊѶòÈÚÅÜ %d.%d.%d\n",
-             FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
+       buf_sprintf(score, "version: 変愚蛮怒 %d.%d.%d\n",
+                   FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
 #else
-  buf_sprintf(score, "version: Hengband %d.%d.%d\n",
-             FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
+       buf_sprintf(score, "version: Hengband %d.%d.%d\n",
+                   FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
 #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, "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, "sex: %d\n", p_ptr->psex);
-  buf_sprintf(score, "race: %s\n", rp_ptr->title);
-  buf_sprintf(score, "class: %s\n", cp_ptr->title);
-  buf_sprintf(score, "seikaku: %s\n", seikakutmp);
-  buf_sprintf(score, "realm1: %s\n", realm_names[p_ptr->realm1]);
-  buf_sprintf(score, "realm2: %s\n", realm_names[p_ptr->realm2]);
-  buf_sprintf(score, "killer: %s\n", died_from);
-  strftime(date, 9, "%y/%m/%d", localtime(&ct));
-  buf_sprintf(score, "date: %s\n", date);
-  buf_sprintf(score, "-----charcter dump-----\n");
-
-  make_dump(score);
-
+       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, "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, "sex: %d\n", p_ptr->psex);
+       buf_sprintf(score, "race: %s\n", rp_ptr->title);
+       buf_sprintf(score, "class: %s\n", cp_ptr->title);
+       buf_sprintf(score, "seikaku: %s\n", seikakutmp);
+       buf_sprintf(score, "realm1: %s\n", realm_names[p_ptr->realm1]);
+       buf_sprintf(score, "realm2: %s\n", realm_names[p_ptr->realm2]);
+       buf_sprintf(score, "killer: %s\n", p_ptr->died_from);
+       buf_sprintf(score, "-----charcter dump-----\n");
+
+       make_dump(score);
+
+       if (screen_dump)
+       {
+               buf_sprintf(score, "-----screen shot-----\n");
+               buf_append(score, screen_dump, strlen(screen_dump));
+       }
+       
 #ifdef WINDOWS
-    if(WSAStartup(wVersionRequested, &wsaData)){
-       msg_print("Report: WSAStartup failed.");
-       goto report_end;
-    }
+       if (WSAStartup(wVersionRequested, &wsaData))
+       {
+               msg_print("Report: WSAStartup failed.");
+               goto report_end;
+       }
 #endif
 
 #ifdef MACINTOSH
@@ -335,7 +515,8 @@ errr report_score(void)
 #else
        err = InitOpenTransport();
 #endif
-       if (err != noErr){
+       if (err != noErr)
+       {
                msg_print("Report: OpenTransport failed.");
                return 1;
        }
@@ -343,45 +524,79 @@ errr report_score(void)
 
        Term_clear();
 
-       while(1)
+       while (1)
        {
                char buff[160];
 #ifdef JP
-               prt("ÀܳÃæ...", 0, 0);
+               prt("接続中...", 0, 0);
 #else
                prt("connecting...", 0, 0);
 #endif
                Term_fresh();
                
-               sd = connect_scoreserver();
-               if (!(sd < 0)) break;
+               /* プロキシを設定する */
+               set_proxy(HTTP_PROXY, HTTP_PROXY_PORT);
+
+               /* Connect to the score server */
+               sd = connect_server(HTTP_TIMEOUT, SCORE_SERVER, SCORE_PORT);
+
+
+               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("¤â¤¦°ìÅÙÀܳ¤ò»î¤ß¤Þ¤¹¤«? "))
+                       if (!get_check_strict("もう一度接続を試みますか? ", CHECK_NO_HISTORY))
 #else
-               if(!get_check("Try again? "))
+                       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);
-       
-       disconnect_server(sd);
+               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;
+       }
+
  report_end:
 #ifdef WINDOWS
        WSACleanup();
@@ -399,7 +614,3 @@ errr report_score(void)
 }
 
 #endif /* WORLD_SCORE */
-
-
-
-