OSDN Git Service

無駄なobject_is_weapon_armour_ammo()呼び出しの削除.
[hengband/hengband.git] / src / report.c
index 5b399c1..055ef50 100644 (file)
 #include <signal.h>
 #endif
 
+/*
+ * internet resource value
+ */
+#define HTTP_PROXY ""                   /* Default proxy url */
+#define HTTP_PROXY_PORT 0               /* Default proxy port */
+#define HTTP_TIMEOUT    20              /* Timeout length (second) */
+#define SCORE_SERVER "www.kmc.gr.jp"    /* 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"
 #else
@@ -33,7 +42,9 @@
 #endif
 
 /* for debug */
-/*#define SCORE_PATH "http://www.kmc.gr.jp/~habu/local/scoretest/score.cgi" */
+#if 0
+#define SCORE_PATH "http://www.kmc.gr.jp/~habu/local/scoretest/score.cgi"
+#endif
 
 /*
  * simple buffer library
@@ -121,6 +132,26 @@ static int buf_sprintf(BUF *buf, const char *fmt, ...)
 
        if(!tmpbuf) return -1;
 
+#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
+
        ret = buf_append(buf, tmpbuf, strlen(tmpbuf));
 
        free(tmpbuf);
@@ -159,7 +190,7 @@ static int buf_search(BUF *buf, const char *str)
 {
        char *ret;
 
-       ret = strstr(buf->data, str);
+       ret = my_strstr(buf->data, str);
 
        if (!ret) return -1;
 
@@ -182,19 +213,19 @@ static BUF * buf_subbuf(BUF *buf, int pos1, size_t sz)
 }
 #endif
 
-static void http_post(int sd, char *url, BUF *buf)
+static void http_post(int sd, cptr url, BUF *buf)
 {
        BUF *output;
 
        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",
+       buf_sprintf(output, "POST %s HTTP/1.0\n", url);
+       buf_sprintf(output, "User-Agent: Hengband %d.%d.%d\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_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_append(output, buf->data, buf->size);
 
        soc_write(sd, output->data, output->size);
@@ -204,8 +235,6 @@ static void http_post(int sd, char *url, BUF *buf)
 /* ¥­¥ã¥é¥¯¥¿¥À¥ó¥×¤òºî¤Ã¤Æ BUF¤ËÊݸ */
 static errr make_dump(BUF* dumpbuf)
 {
-       errr make_character_dump(FILE *fff);
-
        char            buf[1024];
        FILE *fff;
        char file_name[1024];
@@ -234,7 +263,7 @@ 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 */
@@ -259,36 +288,57 @@ cptr make_screen_dump(void)
        byte a = 0, old_a = 0;
        char c = ' ';
 
-       char *html_head[] = {
+       static cptr html_head[] = {
                "<html>\n<body text=\"#ffffff\" bgcolor=\"#000000\">\n",
                "<pre>",
                0,
        };
-       char *html_foot[] = {
+       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 < 24; y++)
+       for (y = 0; y < hgt; y++)
        {
                /* Start the row */
                if (y != 0)
                        buf_sprintf(screen_buf, "\n");
 
                /* Dump each row */
-               for (x = 0; x < 79; x++)
+               for (x = 0; x < wid - 1; x++)
                {
                        int rv, gv, bv;
-                       char *cc = NULL;
+                       cptr cc = NULL;
                        /* Get the attr/char */
                        (void)(Term_what(x, y, &a, &c));
 
@@ -326,18 +376,31 @@ cptr make_screen_dump(void)
        /* Screen dump size is too big ? */
        if (screen_buf->size + 1> SCREEN_BUF_SIZE)
        {
-               buf_delete(screen_buf);
-               return (NULL);
+               ret = NULL;
        }
+       else
+       {
+               /* Terminate string */
+               buf_append(screen_buf, "", 1);
 
-       /* Terminate string */
-       buf_append(screen_buf, "", 1);
-
-       ret = string_make(screen_buf->data);
+               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;
 }
 
@@ -388,7 +451,7 @@ errr report_score(void)
        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);
+       buf_sprintf(score, "killer: %s\n", p_ptr->died_from);
        buf_sprintf(score, "-----charcter dump-----\n");
 
        make_dump(score);
@@ -432,7 +495,13 @@ errr report_score(void)
 #endif
                Term_fresh();
                
-               sd = connect_scoreserver();
+               /* ¥×¥í¥­¥·¤òÀßÄꤹ¤ë */
+               set_proxy(HTTP_PROXY, HTTP_PROXY_PORT);
+
+               /* Connect to the score server */
+               sd = connect_server(HTTP_TIMEOUT, SCORE_SERVER, SCORE_PORT);
+
+
                if (!(sd < 0)) break;
 #ifdef JP
                sprintf(buff, "¥¹¥³¥¢¡¦¥µ¡¼¥Ð¤Ø¤ÎÀܳ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£(%s)", soc_err());
@@ -443,9 +512,9 @@ errr report_score(void)
                (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;