OSDN Git Service

スコアサーバのOSDN移設に伴うサーバアドレス・URLの変更
authorHabu <habu@users.sourceforge.jp>
Sat, 10 Mar 2018 15:07:02 +0000 (00:07 +0900)
committerHabu <habu@users.sourceforge.jp>
Thu, 15 Mar 2018 11:54:39 +0000 (20:54 +0900)
加えてサーバからのレスポンスコードで送信失敗のチェックを行う

src/externs.h
src/inet.c
src/report.c

index 0203bbc..3c75828 100644 (file)
@@ -1770,6 +1770,7 @@ extern cptr make_screen_dump(void);
 
 /* inet.c */
 extern int soc_write(int sd, char *buf, size_t sz);
 
 /* inet.c */
 extern int soc_write(int sd, char *buf, size_t sz);
+extern int soc_read(int sd, char *buf, size_t sz);
 extern void set_proxy(char *default_url, int default_port);
 extern int connect_server(int timeout, const char *host, int port);
 extern int disconnect_server(int sd);
 extern void set_proxy(char *default_url, int default_port);
 extern int connect_server(int timeout, const char *host, int port);
 extern int disconnect_server(int sd);
index 1bcec65..5c52880 100644 (file)
@@ -211,6 +211,31 @@ int soc_write(int sd, char *buf, size_t sz)
        return sz;
 }
 
        return sz;
 }
 
+int soc_read(int sd, char *buf, size_t sz)
+{
+#ifndef MACINTOSH
+       int nleft, nread = 0;
+
+       nleft = sz;
+
+       while (nleft > 0) {
+               int n;
+               n = recv(sd, buf + nread, nleft, 0);
+               if (n <= 0)
+                       return (nread);
+               nleft -= n;
+               nread += n;
+       }
+#else /* !MACINTOSH */
+
+       OTResult bytesSent;
+
+       OTSnd(ep, (void *)buf, sz, 0);
+
+#endif
+       return nread;
+}
+
 #if 0 /* おそらく使わない */
 int soc_write_str(int sd, char *buf)
 {
 #if 0 /* おそらく使わない */
 int soc_write_str(int sd, char *buf)
 {
index 7517652..7d9bf83 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 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_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
 #else
 #define SCORE_PATH "http://moon.kmc.gr.jp/hengband/hengscore-en/score.cgi" /*!< スコア開示URL */
 #endif
@@ -228,22 +228,37 @@ static BUF * buf_subbuf(BUF *buf, int pos1, size_t sz)
  * @param buf 伝送内容バッファ
  * @return なし
  */
  * @param buf 伝送内容バッファ
  * @return なし
  */
-static void http_post(int sd, cptr url, BUF *buf)
+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();
 
        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);
 
                    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);
        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;
 }
 
 /*!
 }
 
 /*!
@@ -524,34 +539,62 @@ errr report_score(void)
                sd = connect_server(HTTP_TIMEOUT, SCORE_SERVER, SCORE_PORT);
 
 
                sd = connect_server(HTTP_TIMEOUT, SCORE_SERVER, SCORE_PORT);
 
 
-               if (!(sd < 0)) break;
+               if (sd < 0) {
 #ifdef JP
 #ifdef JP
-               sprintf(buff, "スコア・サーバへの接続に失敗しました。(%s)", soc_err());
+                       sprintf(buff, "スコア・サーバへの接続に失敗しました。(%s)", soc_err());
 #else
 #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
 #endif
-               prt(buff, 0, 0);
-               (void)inkey();
-               
+                       prt(buff, 0, 0);
+                       (void)inkey();
+
 #ifdef JP
 #ifdef JP
-               if (!get_check_strict("もう一度接続を試みますか? ", CHECK_NO_HISTORY))
+                       if (!get_check_strict("もう一度接続を試みますか? ", CHECK_NO_HISTORY))
 #else
 #else
-               if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
+                       if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
 #endif
 #endif
-               {
-                       err = 1;
-                       goto report_end;
+                       {
+                               err = 1;
+                               goto report_end;
+                       }
+
+                       continue;
                }
                }
-       }
+
 #ifdef JP
 #ifdef JP
-       prt("スコア送信中...", 0, 0);
+               prt("スコア送信中...", 0, 0);
 #else
 #else
-       prt("Sending the score...", 0, 0);
+               prt("Sending the score...", 0, 0);
 #endif
 #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();
  report_end:
 #ifdef WINDOWS
        WSACleanup();