15 #elif defined(MACINTOSH)
16 #include <OpenTransport.h>
17 #include <OpenTptInternet.h>
19 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <netinet/in.h>
30 * internet resource value
32 #define HTTP_PROXY "" /* Default proxy url */
33 #define HTTP_PROXY_PORT 0 /* Default proxy port */
34 #define HTTP_TIMEOUT 20 /* Timeout length (second) */
35 #define SCORE_SERVER "www.kmc.gr.jp" /* Default score server url */
36 #define SCORE_PORT 80 /* Default score server port */
39 #define SCORE_PATH "http://www.kmc.gr.jp/~habu/local/hengscore/score.cgi"
41 #define SCORE_PATH "http://www.kmc.gr.jp/~habu/local/hengscore-en/score.cgi"
46 #define SCORE_PATH "http://www.kmc.gr.jp/~habu/local/scoretest/score.cgi"
50 * simple buffer library
59 #define BUFSIZE (65536)
61 #ifndef HAVE_VASPRINTF
62 #define vasprintf Vasprintf
64 static int Vasprintf(char **buf, const char *fmt, va_list ap)
67 static char static_buf[8192];
71 #if defined(HAVE_VSNPRINTF)
72 ret = vsnprintf(*buf, sizeof(static_buf), fmt, ap);
74 ret = vsprintf(*buf, fmt, ap);
79 #endif /* ifndef HAVE_VASPRINTF */
81 static BUF* buf_new(void)
85 if ((p = malloc(sizeof(BUF))) == NULL)
89 p->max_size = BUFSIZE;
90 if ((p->data = malloc(BUFSIZE)) == NULL)
98 static void buf_delete(BUF *b)
104 static int buf_append(BUF *buf, const char *data, size_t size)
106 while (buf->size + size > buf->max_size)
109 if ((tmp = malloc(buf->max_size * 2)) == NULL) return -1;
111 memcpy(tmp, buf->data, buf->max_size);
118 memcpy(buf->data + buf->size, data, size);
124 static int buf_sprintf(BUF *buf, const char *fmt, ...)
131 ret = vasprintf(&tmpbuf, fmt, ap);
134 if (ret < 0) return -1;
136 #if ('\r' == 0x0a && '\n' == 0x0d)
139 * Originally '\r'= CR (= 0x0d) and '\n'= LF (= 0x0a)
140 * But for MPW (Macintosh Programers Workbench), these
141 * are reversed so that '\r'=LF and '\n'=CR unless the
142 * -noMapCR option is not defined.
144 * We need to swap back these here since the score
145 * dump text should be written using LF as the end of
149 for (ptr = tmpbuf; *ptr; ptr++)
151 if (0x0d == *ptr) *ptr = 0x0a;
156 ret = buf_append(buf, tmpbuf, strlen(tmpbuf));
164 static int buf_read(BUF *buf, int fd)
172 tmp = calloc( BUFSIZE , sizeof(char) );
175 while ((len = read(fd, tmp, BUFSIZE)) > 0)
176 buf_append(buf, tmp, len);
183 static int buf_write(BUF *buf, int fd)
185 write(fd, buf->data, buf->size);
190 static int buf_search(BUF *buf, const char *str)
194 ret = my_strstr(buf->data, str);
198 return ret - buf->data;
201 static BUF * buf_subbuf(BUF *buf, int pos1, size_t sz)
205 if (pos1 < 0) return NULL;
209 if (sz <= 0) sz = buf->size - pos1;
211 buf_append(ret, buf->data + pos1, sz);
217 static void http_post(int sd, cptr url, BUF *buf)
222 buf_sprintf(output, "POST %s HTTP/1.0\n", url);
223 buf_sprintf(output, "User-Agent: Hengband %d.%d.%d\n",
224 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
226 buf_sprintf(output, "Content-Length: %d\n", buf->size);
227 buf_sprintf(output, "Content-Encoding: binary\n");
228 buf_sprintf(output, "Content-Type: application/octet-stream\n");
229 buf_sprintf(output, "\n");
230 buf_append(output, buf->data, buf->size);
232 soc_write(sd, output->data, output->size);
236 /* ¥¥ã¥é¥¯¥¿¥À¥ó¥×¤òºî¤Ã¤Æ BUF¤ËÊݸ */
237 static errr make_dump(BUF* dumpbuf)
241 char file_name[1024];
243 /* Open a new file */
244 fff = my_fopen_temp(file_name, 1024);
248 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
250 msg_format("Failed to create temporary file %s.", file_name);
256 /* °ìö°ì»þ¥Õ¥¡¥¤¥ë¤òºî¤ë¡£Ä̾ï¤Î¥À¥ó¥×½ÐÎϤȶ¦Ä̲½¤¹¤ë¤¿¤á¡£ */
257 (void)make_character_dump(fff);
263 fff = my_fopen(file_name, "r");
265 while (fgets(buf, 1024, fff))
267 (void)buf_sprintf(dumpbuf, "%s", buf);
273 /* Remove the file */
281 * Make screen dump to buffer
283 cptr make_screen_dump(void)
289 byte a = 0, old_a = 0;
292 static cptr html_head[] = {
293 "<html>\n<body text=\"#ffffff\" bgcolor=\"#000000\">\n",
297 static cptr html_foot[] = {
299 "</body>\n</html>\n",
303 bool old_use_graphics = use_graphics;
307 Term_get_size(&wid, &hgt);
310 screen_buf = buf_new();
311 if (screen_buf == NULL) return (NULL);
313 if (old_use_graphics)
315 /* Clear -more- prompt first */
318 use_graphics = FALSE;
321 /* Redraw everything */
322 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
328 for (i = 0; html_head[i]; i++)
329 buf_sprintf(screen_buf, html_head[i]);
331 /* Dump the screen */
332 for (y = 0; y < hgt; y++)
336 buf_sprintf(screen_buf, "\n");
339 for (x = 0; x < wid - 1; x++)
343 /* Get the attr/char */
344 (void)(Term_what(x, y, &a, &c));
348 case '&': cc = "&"; break;
349 case '<': cc = "<"; break;
350 case '>': cc = ">"; break;
352 case 0x1f: c = '.'; break;
353 case 0x7f: c = (a == 0x09) ? '%' : '#'; break;
358 if ((y == 0 && x == 0) || a != old_a) {
359 rv = angband_color_table[a][1];
360 gv = angband_color_table[a][2];
361 bv = angband_color_table[a][3];
362 buf_sprintf(screen_buf, "%s<font color=\"#%02x%02x%02x\">",
363 ((y == 0 && x == 0) ? "" : "</font>"), rv, gv, bv);
367 buf_sprintf(screen_buf, "%s", cc);
369 buf_sprintf(screen_buf, "%c", c);
372 buf_sprintf(screen_buf, "</font>");
374 for (i = 0; html_foot[i]; i++)
375 buf_sprintf(screen_buf, html_foot[i]);
377 /* Screen dump size is too big ? */
378 if (screen_buf->size + 1> SCREEN_BUF_SIZE)
384 /* Terminate string */
385 buf_append(screen_buf, "", 1);
387 ret = string_make(screen_buf->data);
391 buf_delete(screen_buf);
393 if (old_use_graphics)
398 /* Redraw everything */
399 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
409 errr report_score(void)
419 WORD wVersionRequested =(WORD) (( 1) | ( 1 << 8));
424 char seikakutmp[128];
429 sprintf(seikakutmp, "%s%s", ap_ptr->title, (ap_ptr->no ? "¤Î" : ""));
431 sprintf(seikakutmp, "%s ", ap_ptr->title);
434 buf_sprintf(score, "name: %s\n", player_name);
436 buf_sprintf(score, "version: ÊѶòÈÚÅÜ %d.%d.%d\n",
437 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
439 buf_sprintf(score, "version: Hengband %d.%d.%d\n",
440 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
442 buf_sprintf(score, "score: %d\n", total_points());
443 buf_sprintf(score, "level: %d\n", p_ptr->lev);
444 buf_sprintf(score, "depth: %d\n", dun_level);
445 buf_sprintf(score, "maxlv: %d\n", p_ptr->max_plv);
446 buf_sprintf(score, "maxdp: %d\n", max_dlv[DUNGEON_ANGBAND]);
447 buf_sprintf(score, "au: %d\n", p_ptr->au);
448 buf_sprintf(score, "turns: %d\n", turn_real(turn));
449 buf_sprintf(score, "sex: %d\n", p_ptr->psex);
450 buf_sprintf(score, "race: %s\n", rp_ptr->title);
451 buf_sprintf(score, "class: %s\n", cp_ptr->title);
452 buf_sprintf(score, "seikaku: %s\n", seikakutmp);
453 buf_sprintf(score, "realm1: %s\n", realm_names[p_ptr->realm1]);
454 buf_sprintf(score, "realm2: %s\n", realm_names[p_ptr->realm2]);
455 buf_sprintf(score, "killer: %s\n", p_ptr->died_from);
456 buf_sprintf(score, "-----charcter dump-----\n");
462 buf_sprintf(score, "-----screen shot-----\n");
463 buf_append(score, screen_dump, strlen(screen_dump));
467 if (WSAStartup(wVersionRequested, &wsaData))
469 msg_print("Report: WSAStartup failed.");
475 #if TARGET_API_MAC_CARBON
476 err = InitOpenTransportInContext(kInitOTForApplicationMask, NULL);
478 err = InitOpenTransport();
482 msg_print("Report: OpenTransport failed.");
493 prt("ÀܳÃæ...", 0, 0);
495 prt("connecting...", 0, 0);
499 /* ¥×¥í¥¥·¤òÀßÄꤹ¤ë */
500 set_proxy(HTTP_PROXY, HTTP_PROXY_PORT);
502 /* Connect to the score server */
503 sd = connect_server(HTTP_TIMEOUT, SCORE_SERVER, SCORE_PORT);
506 if (!(sd < 0)) break;
508 sprintf(buff, "¥¹¥³¥¢¡¦¥µ¡¼¥Ð¤Ø¤ÎÀܳ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£(%s)", soc_err());
510 sprintf(buff, "Failed to connect to the score server.(%s)", soc_err());
516 if (!get_check_strict("¤â¤¦°ìÅÙÀܳ¤ò»î¤ß¤Þ¤¹¤«? ", CHECK_NO_HISTORY))
518 if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
526 prt("¥¹¥³¥¢Á÷¿®Ãæ...", 0, 0);
528 prt("Sending the score...", 0, 0);
531 http_post(sd, SCORE_PATH, score);
533 disconnect_server(sd);
540 #if TARGET_API_MAC_CARBON
541 CloseOpenTransportInContext(NULL);
543 CloseOpenTransport();
550 #endif /* WORLD_SCORE */