OSDN Git Service

Revert "Merge branch 'master' of git.osdn.net:/gitroot/hengband/hengband"
[hengband/hengband.git] / src / report.c
index 3c6d70d..ad5d1da 100644 (file)
@@ -5,15 +5,8 @@
  * @author Hengband Team
  */
 
+#define _GNU_SOURCE /*!< 未使用*/
 #include "angband.h"
-#include "core.h"
-#include "inet.h"
-#include "dungeon.h"
-
-#include "player-personality.h"
-#include "character-dump.h"
-#include "world.h"
-#include "term.h"
 
 #ifdef WORLD_SCORE
 
@@ -24,6 +17,9 @@
 
 #if defined(WINDOWS)
 #include <winsock.h>
+#elif defined(MACINTOSH)
+#include <OpenTransport.h>
+#include <OpenTptInternet.h>
 #else
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -35,8 +31,6 @@
 #include <signal.h>
 #endif
 
-concptr screen_dump = NULL;
-
 /*
  * internet resource value
  */
@@ -52,9 +46,14 @@ concptr screen_dump = NULL;
 #define SCORE_PATH "http://moon.kmc.gr.jp/hengband/hengscore-en/score.cgi" /*!< スコア開示URL */
 #endif
 
- /*
-  * simple buffer library
-  */
+/* for debug */
+#if 0
+#define SCORE_PATH "http://moon.kmc.gr.jp/hengband/scoretest/score.cgi" /*!< スコア開示URL */
+#endif
+
+/*
+ * simple buffer library
+ */
 typedef struct {
        size_t max_size;
        size_t size;
@@ -70,22 +69,20 @@ typedef struct {
 static BUF* buf_new(void)
 {
        BUF *p;
-       p = malloc(sizeof(BUF));
-       if (!p) return NULL;
+
+       if ((p = malloc(sizeof(BUF))) == NULL)
+               return NULL;
 
        p->size = 0;
        p->max_size = BUFSIZE;
-       p->data = malloc(BUFSIZE);
-       if (!p->data)
+       if ((p->data = malloc(BUFSIZE)) == NULL)
        {
                free(p);
                return NULL;
        }
-
        return p;
 }
 
-
 /*!
  * @brief 転送用バッファの解放
  * @param b 解放するバッファの参照ポインタ
@@ -96,7 +93,6 @@ static void buf_delete(BUF *b)
        free(b);
 }
 
-
 /*!
  * @brief 転送用バッファにデータを追加する
  * @param buf 追加先バッファの参照ポインタ
@@ -124,7 +120,6 @@ static int buf_append(BUF *buf, concptr data, size_t size)
        return buf->size;
 }
 
-
 /*!
  * @brief 転送用バッファにフォーマット指定した文字列データを追加する
  * @param buf 追加先バッファの参照ポインタ
@@ -172,6 +167,59 @@ static int buf_sprintf(BUF *buf, concptr fmt, ...)
        return ret;
 }
 
+#if 0
+static int buf_read(BUF *buf, int fd)
+{
+       int len;
+#ifndef MACINTOSH
+       char tmp[BUFSIZE];
+#else
+       char *tmp;
+       
+       tmp = calloc( BUFSIZE , sizeof(char) );
+#endif
+
+       while ((len = read(fd, tmp, BUFSIZE)) > 0)
+               buf_append(buf, tmp, len);
+
+       return buf->size;
+}
+#endif
+
+#if 0
+static int buf_write(BUF *buf, int fd)
+{
+       write(fd, buf->data, buf->size);
+
+       return buf->size;
+}
+
+static int buf_search(BUF *buf, concptr str)
+{
+       char *ret;
+
+       ret = my_strstr(buf->data, str);
+
+       if (!ret) return -1;
+
+       return ret - buf->data;
+}
+
+static BUF * buf_subbuf(BUF *buf, int pos1, size_t sz)
+{
+       BUF *ret;
+
+       if (pos1 < 0) return NULL;
+
+       ret = buf_new();
+
+       if (sz <= 0) sz = buf->size - pos1;
+
+       buf_append(ret, buf->data + pos1, sz);
+
+       return ret;
+}
+#endif
 
 /*!
  * @brief HTTPによるダンプ内容伝送
@@ -189,7 +237,7 @@ static bool http_post(int sd, concptr url, BUF *buf)
        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);
+                   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");
@@ -213,14 +261,12 @@ static bool http_post(int sd, concptr url, BUF *buf)
        return strncmp(response_buf, HTTP_RESPONSE_CODE_OK, strlen(HTTP_RESPONSE_CODE_OK)) == 0;
 }
 
-
 /*!
  * @brief キャラクタダンプを作って BUFに保存
- * @param creature_ptr プレーヤーへの参照ポインタ
  * @param dumpbuf 伝送内容バッファ
  * @return エラーコード
  */
-static errr make_dump(player_type *creature_ptr, BUF* dumpbuf, void(*update_playtime)(void), display_player_pf display_player, map_name_pf map_name)
+static errr make_dump(BUF* dumpbuf)
 {
        char            buf[1024];
        FILE *fff;
@@ -240,7 +286,7 @@ static errr make_dump(player_type *creature_ptr, BUF* dumpbuf, void(*update_play
        }
 
        /* 一旦一時ファイルを作る。通常のダンプ出力と共通化するため。 */
-       make_character_dump(creature_ptr, fff, update_playtime, display_player, map_name);
+       (void)make_character_dump(fff);
        my_fclose(fff);
 
        /* Open for read */
@@ -254,16 +300,22 @@ static errr make_dump(player_type *creature_ptr, BUF* dumpbuf, void(*update_play
        fd_kill(file_name);
 
        /* Success */
-       return 0;
+       return (0);
 }
 
-
 /*!
  * @brief スクリーンダンプを作成する/ Make screen dump to buffer
  * @return 作成したスクリーンダンプの参照ポインタ
  */
-concptr make_screen_dump(player_type *creature_ptr)
+concptr make_screen_dump(void)
 {
+       BUF *screen_buf;
+       int y, x, i;
+       concptr ret;
+
+       TERM_COLOR a = 0, old_a = 0;
+       SYMBOL_CODE c = ' ';
+
        static concptr html_head[] = {
                "<html>\n<body text=\"#ffffff\" bgcolor=\"#000000\">\n",
                "<pre>",
@@ -275,41 +327,40 @@ concptr make_screen_dump(player_type *creature_ptr)
                0,
        };
 
+       bool old_use_graphics = use_graphics;
+
        int wid, hgt;
+
        Term_get_size(&wid, &hgt);
 
        /* Alloc buffer */
-       BUF *screen_buf;
        screen_buf = buf_new();
        if (screen_buf == NULL) return (NULL);
 
-       bool old_use_graphics = use_graphics;
        if (old_use_graphics)
        {
                /* Clear -more- prompt first */
                msg_print(NULL);
 
                use_graphics = FALSE;
-               reset_visuals(creature_ptr);
+               reset_visuals();
 
-               creature_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
-               handle_stuff(creature_ptr);
+               p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
+               handle_stuff();
        }
 
-       for (int i = 0; html_head[i]; i++)
+       for (i = 0; html_head[i]; i++)
                buf_sprintf(screen_buf, html_head[i]);
 
        /* Dump the screen */
-       for (int y = 0; y < hgt; y++)
+       for (y = 0; y < hgt; y++)
        {
                /* Start the row */
                if (y != 0)
                        buf_sprintf(screen_buf, "\n");
 
                /* Dump each row */
-               TERM_COLOR a = 0, old_a = 0;
-               SYMBOL_CODE c = ' ';
-               for (int x = 0; x < wid - 1; x++)
+               for (x = 0; x < wid - 1; x++)
                {
                        int rv, gv, bv;
                        concptr cc = NULL;
@@ -334,26 +385,23 @@ concptr make_screen_dump(player_type *creature_ptr)
                                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);
+                               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 (int i = 0; html_foot[i]; i++)
+       for (i = 0; html_foot[i]; i++)
                buf_sprintf(screen_buf, html_foot[i]);
 
        /* Screen dump size is too big ? */
-       concptr ret;
-       if (screen_buf->size + 1 > SCREEN_BUF_MAX_SIZE)
+       if (screen_buf->size + 1> SCREEN_BUF_MAX_SIZE)
        {
                ret = NULL;
        }
@@ -368,87 +416,103 @@ concptr make_screen_dump(player_type *creature_ptr)
        /* Free buffer */
        buf_delete(screen_buf);
 
-       if (!old_use_graphics) return ret;
+       if (old_use_graphics)
+       {
+               use_graphics = TRUE;
+               reset_visuals();
 
-       use_graphics = TRUE;
-       reset_visuals(creature_ptr);
+               p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
+               handle_stuff();
+       }
 
-       creature_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
-       handle_stuff(creature_ptr);
        return ret;
 }
 
-
 /*!
- * todo メッセージは言語選択の関数マクロで何とかならんか?
  * @brief スコア転送処理のメインルーチン
- * @param creature_ptr プレーヤーへの参照ポインタ
- * @return 正常終了の時0、異常があったら1
+ * @return エラーコード
  */
-errr report_score(player_type *creature_ptr, void(*update_playtime)(void), display_player_pf display_player, map_name_pf map_name)
+errr report_score(void)
 {
+#ifdef MACINTOSH
+       OSStatus err;
+#else
+       errr err = 0;
+#endif
+
 #ifdef WINDOWS
        WSADATA wsaData;
-       WORD wVersionRequested = (WORD)((1) | (1 << 8));
+       WORD wVersionRequested =(WORD) (( 1) |  ( 1 << 8));
 #endif
 
        BUF *score;
+       int sd;
+       char seikakutmp[128];
+
        score = buf_new();
 
-       char seikakutmp[128];
 #ifdef JP
        sprintf(seikakutmp, "%s%s", ap_ptr->title, (ap_ptr->no ? "の" : ""));
 #else
        sprintf(seikakutmp, "%s ", ap_ptr->title);
 #endif
 
-       buf_sprintf(score, "name: %s\n", creature_ptr->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);
+                   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);
+                   FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
 #endif
-       buf_sprintf(score, "score: %d\n", calc_score(creature_ptr));
-       buf_sprintf(score, "level: %d\n", creature_ptr->lev);
-       buf_sprintf(score, "depth: %d\n", creature_ptr->current_floor_ptr->dun_level);
-       buf_sprintf(score, "maxlv: %d\n", creature_ptr->max_plv);
+       buf_sprintf(score, "score: %d\n", total_points());
+       buf_sprintf(score, "level: %d\n", p_ptr->lev);
+       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", creature_ptr->au);
-       buf_sprintf(score, "turns: %d\n", turn_real(creature_ptr, current_world_ptr->game_turn));
-       buf_sprintf(score, "sex: %d\n", creature_ptr->psex);
+       buf_sprintf(score, "au: %d\n", p_ptr->au);
+       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);
        buf_sprintf(score, "seikaku: %s\n", seikakutmp);
-       buf_sprintf(score, "realm1: %s\n", realm_names[creature_ptr->realm1]);
-       buf_sprintf(score, "realm2: %s\n", realm_names[creature_ptr->realm2]);
-       buf_sprintf(score, "killer: %s\n", creature_ptr->died_from);
+       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(creature_ptr, score, update_playtime, display_player, map_name);
+       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.");
-#ifdef WINDOWS
-               WSACleanup();
+               goto report_end;
+       }
 #endif
+
+#ifdef MACINTOSH
+#if TARGET_API_MAC_CARBON
+       err = InitOpenTransportInContext(kInitOTForApplicationMask, NULL);
+#else
+       err = InitOpenTransport();
+#endif
+       if (err != noErr)
+       {
+               msg_print("Report: OpenTransport failed.");
                return 1;
        }
 #endif
 
        Term_clear();
 
-       int sd;
-       while (TRUE)
+       while (1)
        {
                char buff[160];
 #ifdef JP
@@ -457,7 +521,7 @@ errr report_score(player_type *creature_ptr, void(*update_playtime)(void), displ
                prt("connecting...", 0, 0);
 #endif
                Term_fresh();
-
+               
                /* プロキシを設定する */
                set_proxy(HTTP_PROXY, HTTP_PROXY_PORT);
 
@@ -480,10 +544,8 @@ errr report_score(player_type *creature_ptr, void(*update_playtime)(void), displ
                        if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
 #endif
                        {
-#ifdef WINDOWS
-                               WSACleanup();
-#endif
-                               return 1;
+                               err = 1;
+                               goto report_end;
                        }
 
                        continue;
@@ -512,10 +574,8 @@ errr report_score(player_type *creature_ptr, void(*update_playtime)(void), displ
                        if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
 #endif
                        {
-#ifdef WINDOWS
-                               WSACleanup();
-#endif
-                               return 1;
+                               err = 1;
+                               goto report_end;
                        }
 
                        continue;
@@ -525,10 +585,20 @@ errr report_score(player_type *creature_ptr, void(*update_playtime)(void), displ
                break;
        }
 
+ report_end:
 #ifdef WINDOWS
        WSACleanup();
 #endif
 
-       return 0;
+#ifdef MACINTOSH
+#if TARGET_API_MAC_CARBON
+       CloseOpenTransportInContext(NULL);
+#else
+       CloseOpenTransport();
+#endif
+#endif
+
+       return err;
 }
+
 #endif /* WORLD_SCORE */