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)
70 #if defined(HAVE_VSNPRINTF)
71 ret = vsnprintf(*buf, 1024, fmt, ap);
73 ret = vsprintf(*buf, fmt, ap);
78 #endif /* ifndef HAVE_VASPRINTF */
80 static BUF* buf_new(void)
84 if ((p = malloc(sizeof(BUF))) == NULL)
88 p->max_size = BUFSIZE;
89 if ((p->data = malloc(BUFSIZE)) == NULL)
97 static void buf_delete(BUF *b)
103 static int buf_append(BUF *buf, const char *data, size_t size)
105 while (buf->size + size > buf->max_size)
108 if ((tmp = malloc(buf->max_size * 2)) == NULL) return -1;
110 memcpy(tmp, buf->data, buf->max_size);
117 memcpy(buf->data + buf->size, data, size);
123 static int buf_sprintf(BUF *buf, const char *fmt, ...)
130 vasprintf(&tmpbuf, fmt, ap);
133 if(!tmpbuf) return -1;
135 #if ('\r' == 0x0a && '\n' == 0x0d)
138 * Originally '\r'= CR (= 0x0d) and '\n'= LF (= 0x0a)
139 * But for MPW (Macintosh Programers Workbench), these
140 * are reversed so that '\r'=LF and '\n'=CR unless the
141 * -noMapCR option is not defined.
143 * We need to swap back these here since the score
144 * dump text should be written using LF as the end of
148 for (ptr = tmpbuf; *ptr; ptr++)
150 if (0x0d == *ptr) *ptr = 0x0a;
155 ret = buf_append(buf, tmpbuf, strlen(tmpbuf));
163 static int buf_read(BUF *buf, int fd)
171 tmp = calloc( BUFSIZE , sizeof(char) );
174 while ((len = read(fd, tmp, BUFSIZE)) > 0)
175 buf_append(buf, tmp, len);
182 static int buf_write(BUF *buf, int fd)
184 write(fd, buf->data, buf->size);
189 static int buf_search(BUF *buf, const char *str)
193 ret = my_strstr(buf->data, str);
197 return ret - buf->data;
200 static BUF * buf_subbuf(BUF *buf, int pos1, size_t sz)
204 if (pos1 < 0) return NULL;
208 if (sz <= 0) sz = buf->size - pos1;
210 buf_append(ret, buf->data + pos1, sz);
216 static void http_post(int sd, cptr url, BUF *buf)
221 buf_sprintf(output, "POST %s HTTP/1.0\n", url);
222 buf_sprintf(output, "User-Agent: Hengband %d.%d.%d\n",
223 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
225 buf_sprintf(output, "Content-Length: %d\n", buf->size);
226 buf_sprintf(output, "Content-Encoding: binary\n");
227 buf_sprintf(output, "Content-Type: application/octet-stream\n");
228 buf_sprintf(output, "\n");
229 buf_append(output, buf->data, buf->size);
231 soc_write(sd, output->data, output->size);
235 /* ¥¥ã¥é¥¯¥¿¥À¥ó¥×¤òºî¤Ã¤Æ BUF¤ËÊݸ */
236 static errr make_dump(BUF* dumpbuf)
240 char file_name[1024];
242 /* Open a new file */
243 fff = my_fopen_temp(file_name, 1024);
247 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
249 msg_format("Failed to create temporary file %s.", file_name);
255 /* °ìö°ì»þ¥Õ¥¡¥¤¥ë¤òºî¤ë¡£Ä̾ï¤Î¥À¥ó¥×½ÐÎϤȶ¦Ä̲½¤¹¤ë¤¿¤á¡£ */
256 (void)make_character_dump(fff);
262 fff = my_fopen(file_name, "r");
264 while (fgets(buf, 1024, fff))
266 (void)buf_sprintf(dumpbuf, "%s", buf);
272 /* Remove the file */
280 * Make screen dump to buffer
282 cptr make_screen_dump(void)
288 byte a = 0, old_a = 0;
291 static cptr html_head[] = {
292 "<html>\n<body text=\"#ffffff\" bgcolor=\"#000000\">\n",
296 static cptr html_foot[] = {
298 "</body>\n</html>\n",
302 bool old_use_graphics = use_graphics;
306 Term_get_size(&wid, &hgt);
309 screen_buf = buf_new();
310 if (screen_buf == NULL) return (NULL);
312 if (old_use_graphics)
314 /* Clear -more- prompt first */
317 use_graphics = FALSE;
320 /* Redraw everything */
321 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
327 for (i = 0; html_head[i]; i++)
328 buf_sprintf(screen_buf, html_head[i]);
330 /* Dump the screen */
331 for (y = 0; y < hgt; y++)
335 buf_sprintf(screen_buf, "\n");
338 for (x = 0; x < wid - 1; x++)
342 /* Get the attr/char */
343 (void)(Term_what(x, y, &a, &c));
347 case '&': cc = "&"; break;
348 case '<': cc = "<"; break;
349 case '>': cc = ">"; break;
351 case 0x1f: c = '.'; break;
352 case 0x7f: c = (a == 0x09) ? '%' : '#'; break;
357 if ((y == 0 && x == 0) || a != old_a) {
358 rv = angband_color_table[a][1];
359 gv = angband_color_table[a][2];
360 bv = angband_color_table[a][3];
361 buf_sprintf(screen_buf, "%s<font color=\"#%02x%02x%02x\">",
362 ((y == 0 && x == 0) ? "" : "</font>"), rv, gv, bv);
366 buf_sprintf(screen_buf, "%s", cc);
368 buf_sprintf(screen_buf, "%c", c);
371 buf_sprintf(screen_buf, "</font>");
373 for (i = 0; html_foot[i]; i++)
374 buf_sprintf(screen_buf, html_foot[i]);
376 /* Screen dump size is too big ? */
377 if (screen_buf->size + 1> SCREEN_BUF_SIZE)
383 /* Terminate string */
384 buf_append(screen_buf, "", 1);
386 ret = string_make(screen_buf->data);
390 buf_delete(screen_buf);
392 if (old_use_graphics)
397 /* Redraw everything */
398 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
408 errr report_score(void)
418 WORD wVersionRequested =(WORD) (( 1) | ( 1 << 8));
423 char seikakutmp[128];
428 sprintf(seikakutmp, "%s%s", ap_ptr->title, (ap_ptr->no ? "¤Î" : ""));
430 sprintf(seikakutmp, "%s ", ap_ptr->title);
433 buf_sprintf(score, "name: %s\n", player_name);
435 buf_sprintf(score, "version: ÊѶòÈÚÅÜ %d.%d.%d\n",
436 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
438 buf_sprintf(score, "version: Hengband %d.%d.%d\n",
439 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
441 buf_sprintf(score, "score: %d\n", total_points());
442 buf_sprintf(score, "level: %d\n", p_ptr->lev);
443 buf_sprintf(score, "depth: %d\n", dun_level);
444 buf_sprintf(score, "maxlv: %d\n", p_ptr->max_plv);
445 buf_sprintf(score, "maxdp: %d\n", max_dlv[DUNGEON_ANGBAND]);
446 buf_sprintf(score, "au: %d\n", p_ptr->au);
447 buf_sprintf(score, "turns: %d\n", turn_real(turn));
448 buf_sprintf(score, "sex: %d\n", p_ptr->psex);
449 buf_sprintf(score, "race: %s\n", rp_ptr->title);
450 buf_sprintf(score, "class: %s\n", cp_ptr->title);
451 buf_sprintf(score, "seikaku: %s\n", seikakutmp);
452 buf_sprintf(score, "realm1: %s\n", realm_names[p_ptr->realm1]);
453 buf_sprintf(score, "realm2: %s\n", realm_names[p_ptr->realm2]);
454 buf_sprintf(score, "killer: %s\n", p_ptr->died_from);
455 buf_sprintf(score, "-----charcter dump-----\n");
461 buf_sprintf(score, "-----screen shot-----\n");
462 buf_append(score, screen_dump, strlen(screen_dump));
466 if (WSAStartup(wVersionRequested, &wsaData))
468 msg_print("Report: WSAStartup failed.");
474 #if TARGET_API_MAC_CARBON
475 err = InitOpenTransportInContext(kInitOTForApplicationMask, NULL);
477 err = InitOpenTransport();
481 msg_print("Report: OpenTransport failed.");
492 prt("ÀܳÃæ...", 0, 0);
494 prt("connecting...", 0, 0);
498 /* ¥×¥í¥¥·¤òÀßÄꤹ¤ë */
499 set_proxy(HTTP_PROXY, HTTP_PROXY_PORT);
501 /* Connect to the score server */
502 sd = connect_server(HTTP_TIMEOUT, SCORE_SERVER, SCORE_PORT);
505 if (!(sd < 0)) break;
507 sprintf(buff, "¥¹¥³¥¢¡¦¥µ¡¼¥Ð¤Ø¤ÎÀܳ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£(%s)", soc_err());
509 sprintf(buff, "Failed to connect to the score server.(%s)", soc_err());
515 if (!get_check_strict("¤â¤¦°ìÅÙÀܳ¤ò»î¤ß¤Þ¤¹¤«? ", CHECK_NO_HISTORY))
517 if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
525 prt("¥¹¥³¥¢Á÷¿®Ãæ...", 0, 0);
527 prt("Sending the score...", 0, 0);
530 http_post(sd, SCORE_PATH, score);
532 disconnect_server(sd);
539 #if TARGET_API_MAC_CARBON
540 CloseOpenTransportInContext(NULL);
542 CloseOpenTransport();
549 #endif /* WORLD_SCORE */