5 * @author Hengband Team
8 #define _GNU_SOURCE /*!< 未使用*/
20 #elif defined(MACINTOSH)
21 #include <OpenTransport.h>
22 #include <OpenTptInternet.h>
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <netinet/in.h>
35 * internet resource value
37 #define HTTP_PROXY "" /*!< デフォルトのプロキシURL / Default proxy url */
38 #define HTTP_PROXY_PORT 0 /*!< デフォルトのプロキシポート / Default proxy port */
39 #define HTTP_TIMEOUT 20 /*!< デフォルトのタイムアウト時間(秒) / Timeout length (second) */
40 #define SCORE_SERVER "moon.kmc.gr.jp" /*!< デフォルトのスコアサーバURL / Default score server url */
41 #define SCORE_PORT 80 /*!< デフォルトのスコアサーバポート / Default score server port */
44 #define SCORE_PATH "http://moon.kmc.gr.jp/hengband/hengscore/score.cgi" /*!< スコア開示URL */
46 #define SCORE_PATH "http://moon.kmc.gr.jp/hengband/hengscore-en/score.cgi" /*!< スコア開示URL */
51 #define SCORE_PATH "http://moon.kmc.gr.jp/hengband/scoretest/score.cgi" /*!< スコア開示URL */
55 * simple buffer library
64 #define BUFSIZE (65536) /*!< スコアサーバ転送バッファサイズ */
66 static BUF* buf_new(void)
70 if ((p = malloc(sizeof(BUF))) == NULL)
74 p->max_size = BUFSIZE;
75 if ((p->data = malloc(BUFSIZE)) == NULL)
83 static void buf_delete(BUF *b)
89 static int buf_append(BUF *buf, const char *data, size_t size)
91 while (buf->size + size > buf->max_size)
94 if ((tmp = malloc(buf->max_size * 2)) == NULL) return -1;
96 memcpy(tmp, buf->data, buf->max_size);
103 memcpy(buf->data + buf->size, data, size);
109 static int buf_sprintf(BUF *buf, const char *fmt, ...)
116 #if defined(HAVE_VSNPRINTF)
117 ret = vsnprintf(tmpbuf, sizeof(tmpbuf), fmt, ap);
119 ret = vsprintf(tmpbuf, fmt, ap);
123 if (ret < 0) return -1;
125 #if ('\r' == 0x0a && '\n' == 0x0d)
128 * Originally '\r'= CR (= 0x0d) and '\n'= LF (= 0x0a)
129 * But for MPW (Macintosh Programers Workbench), these
130 * are reversed so that '\r'=LF and '\n'=CR unless the
131 * -noMapCR option is not defined.
133 * We need to swap back these here since the score
134 * dump text should be written using LF as the end of
138 for (ptr = tmpbuf; *ptr; ptr++)
140 if (0x0d == *ptr) *ptr = 0x0a;
145 ret = buf_append(buf, tmpbuf, strlen(tmpbuf));
151 static int buf_read(BUF *buf, int fd)
159 tmp = calloc( BUFSIZE , sizeof(char) );
162 while ((len = read(fd, tmp, BUFSIZE)) > 0)
163 buf_append(buf, tmp, len);
170 static int buf_write(BUF *buf, int fd)
172 write(fd, buf->data, buf->size);
177 static int buf_search(BUF *buf, const char *str)
181 ret = my_strstr(buf->data, str);
185 return ret - buf->data;
188 static BUF * buf_subbuf(BUF *buf, int pos1, size_t sz)
192 if (pos1 < 0) return NULL;
196 if (sz <= 0) sz = buf->size - pos1;
198 buf_append(ret, buf->data + pos1, sz);
204 static void http_post(int sd, cptr url, BUF *buf)
209 buf_sprintf(output, "POST %s HTTP/1.0\n", url);
210 buf_sprintf(output, "User-Agent: Hengband %d.%d.%d\n",
211 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
213 buf_sprintf(output, "Content-Length: %d\n", buf->size);
214 buf_sprintf(output, "Content-Encoding: binary\n");
215 buf_sprintf(output, "Content-Type: application/octet-stream\n");
216 buf_sprintf(output, "\n");
217 buf_append(output, buf->data, buf->size);
219 soc_write(sd, output->data, output->size);
223 /* キャラクタダンプを作って BUFに保存 */
224 static errr make_dump(BUF* dumpbuf)
228 char file_name[1024];
230 /* Open a new file */
231 fff = my_fopen_temp(file_name, 1024);
235 msg_format("一時ファイル %s を作成できませんでした。", file_name);
237 msg_format("Failed to create temporary file %s.", file_name);
243 /* 一旦一時ファイルを作る。通常のダンプ出力と共通化するため。 */
244 (void)make_character_dump(fff);
250 fff = my_fopen(file_name, "r");
252 while (fgets(buf, 1024, fff))
254 (void)buf_sprintf(dumpbuf, "%s", buf);
260 /* Remove the file */
268 * Make screen dump to buffer
270 cptr make_screen_dump(void)
276 byte a = 0, old_a = 0;
279 static cptr html_head[] = {
280 "<html>\n<body text=\"#ffffff\" bgcolor=\"#000000\">\n",
284 static cptr html_foot[] = {
286 "</body>\n</html>\n",
290 bool old_use_graphics = use_graphics;
294 Term_get_size(&wid, &hgt);
297 screen_buf = buf_new();
298 if (screen_buf == NULL) return (NULL);
300 if (old_use_graphics)
302 /* Clear -more- prompt first */
305 use_graphics = FALSE;
308 /* Redraw everything */
309 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
315 for (i = 0; html_head[i]; i++)
316 buf_sprintf(screen_buf, html_head[i]);
318 /* Dump the screen */
319 for (y = 0; y < hgt; y++)
323 buf_sprintf(screen_buf, "\n");
326 for (x = 0; x < wid - 1; x++)
330 /* Get the attr/char */
331 (void)(Term_what(x, y, &a, &c));
335 case '&': cc = "&"; break;
336 case '<': cc = "<"; break;
337 case '>': cc = ">"; break;
339 case 0x1f: c = '.'; break;
340 case 0x7f: c = (a == 0x09) ? '%' : '#'; break;
345 if ((y == 0 && x == 0) || a != old_a) {
346 rv = angband_color_table[a][1];
347 gv = angband_color_table[a][2];
348 bv = angband_color_table[a][3];
349 buf_sprintf(screen_buf, "%s<font color=\"#%02x%02x%02x\">",
350 ((y == 0 && x == 0) ? "" : "</font>"), rv, gv, bv);
354 buf_sprintf(screen_buf, "%s", cc);
356 buf_sprintf(screen_buf, "%c", c);
359 buf_sprintf(screen_buf, "</font>");
361 for (i = 0; html_foot[i]; i++)
362 buf_sprintf(screen_buf, html_foot[i]);
364 /* Screen dump size is too big ? */
365 if (screen_buf->size + 1> SCREEN_BUF_SIZE)
371 /* Terminate string */
372 buf_append(screen_buf, "", 1);
374 ret = string_make(screen_buf->data);
378 buf_delete(screen_buf);
380 if (old_use_graphics)
385 /* Redraw everything */
386 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
396 errr report_score(void)
406 WORD wVersionRequested =(WORD) (( 1) | ( 1 << 8));
411 char seikakutmp[128];
416 sprintf(seikakutmp, "%s%s", ap_ptr->title, (ap_ptr->no ? "の" : ""));
418 sprintf(seikakutmp, "%s ", ap_ptr->title);
421 buf_sprintf(score, "name: %s\n", player_name);
423 buf_sprintf(score, "version: 変愚蛮怒 %d.%d.%d\n",
424 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
426 buf_sprintf(score, "version: Hengband %d.%d.%d\n",
427 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
429 buf_sprintf(score, "score: %d\n", total_points());
430 buf_sprintf(score, "level: %d\n", p_ptr->lev);
431 buf_sprintf(score, "depth: %d\n", dun_level);
432 buf_sprintf(score, "maxlv: %d\n", p_ptr->max_plv);
433 buf_sprintf(score, "maxdp: %d\n", max_dlv[DUNGEON_ANGBAND]);
434 buf_sprintf(score, "au: %d\n", p_ptr->au);
435 buf_sprintf(score, "turns: %d\n", turn_real(turn));
436 buf_sprintf(score, "sex: %d\n", p_ptr->psex);
437 buf_sprintf(score, "race: %s\n", rp_ptr->title);
438 buf_sprintf(score, "class: %s\n", cp_ptr->title);
439 buf_sprintf(score, "seikaku: %s\n", seikakutmp);
440 buf_sprintf(score, "realm1: %s\n", realm_names[p_ptr->realm1]);
441 buf_sprintf(score, "realm2: %s\n", realm_names[p_ptr->realm2]);
442 buf_sprintf(score, "killer: %s\n", p_ptr->died_from);
443 buf_sprintf(score, "-----charcter dump-----\n");
449 buf_sprintf(score, "-----screen shot-----\n");
450 buf_append(score, screen_dump, strlen(screen_dump));
454 if (WSAStartup(wVersionRequested, &wsaData))
456 msg_print("Report: WSAStartup failed.");
462 #if TARGET_API_MAC_CARBON
463 err = InitOpenTransportInContext(kInitOTForApplicationMask, NULL);
465 err = InitOpenTransport();
469 msg_print("Report: OpenTransport failed.");
482 prt("connecting...", 0, 0);
487 set_proxy(HTTP_PROXY, HTTP_PROXY_PORT);
489 /* Connect to the score server */
490 sd = connect_server(HTTP_TIMEOUT, SCORE_SERVER, SCORE_PORT);
493 if (!(sd < 0)) break;
495 sprintf(buff, "スコア・サーバへの接続に失敗しました。(%s)", soc_err());
497 sprintf(buff, "Failed to connect to the score server.(%s)", soc_err());
503 if (!get_check_strict("もう一度接続を試みますか? ", CHECK_NO_HISTORY))
505 if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
513 prt("スコア送信中...", 0, 0);
515 prt("Sending the score...", 0, 0);
518 http_post(sd, SCORE_PATH, score);
520 disconnect_server(sd);
527 #if TARGET_API_MAC_CARBON
528 CloseOpenTransportInContext(NULL);
530 CloseOpenTransport();
537 #endif /* WORLD_SCORE */