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 static BUF* buf_new(void)
65 if ((p = malloc(sizeof(BUF))) == NULL)
69 p->max_size = BUFSIZE;
70 if ((p->data = malloc(BUFSIZE)) == NULL)
78 static void buf_delete(BUF *b)
84 static int buf_append(BUF *buf, const char *data, size_t size)
86 while (buf->size + size > buf->max_size)
89 if ((tmp = malloc(buf->max_size * 2)) == NULL) return -1;
91 memcpy(tmp, buf->data, buf->max_size);
98 memcpy(buf->data + buf->size, data, size);
104 static int buf_sprintf(BUF *buf, const char *fmt, ...)
111 #if defined(HAVE_VSNPRINTF)
112 ret = vsnprintf(tmpbuf, sizeof(tmpbuf), fmt, ap);
114 ret = vsprintf(tmpbuf, fmt, ap);
118 if (ret < 0) return -1;
120 #if ('\r' == 0x0a && '\n' == 0x0d)
123 * Originally '\r'= CR (= 0x0d) and '\n'= LF (= 0x0a)
124 * But for MPW (Macintosh Programers Workbench), these
125 * are reversed so that '\r'=LF and '\n'=CR unless the
126 * -noMapCR option is not defined.
128 * We need to swap back these here since the score
129 * dump text should be written using LF as the end of
133 for (ptr = tmpbuf; *ptr; ptr++)
135 if (0x0d == *ptr) *ptr = 0x0a;
140 ret = buf_append(buf, tmpbuf, strlen(tmpbuf));
146 static int buf_read(BUF *buf, int fd)
154 tmp = calloc( BUFSIZE , sizeof(char) );
157 while ((len = read(fd, tmp, BUFSIZE)) > 0)
158 buf_append(buf, tmp, len);
165 static int buf_write(BUF *buf, int fd)
167 write(fd, buf->data, buf->size);
172 static int buf_search(BUF *buf, const char *str)
176 ret = my_strstr(buf->data, str);
180 return ret - buf->data;
183 static BUF * buf_subbuf(BUF *buf, int pos1, size_t sz)
187 if (pos1 < 0) return NULL;
191 if (sz <= 0) sz = buf->size - pos1;
193 buf_append(ret, buf->data + pos1, sz);
199 static void http_post(int sd, cptr url, BUF *buf)
204 buf_sprintf(output, "POST %s HTTP/1.0\n", url);
205 buf_sprintf(output, "User-Agent: Hengband %d.%d.%d\n",
206 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
208 buf_sprintf(output, "Content-Length: %d\n", buf->size);
209 buf_sprintf(output, "Content-Encoding: binary\n");
210 buf_sprintf(output, "Content-Type: application/octet-stream\n");
211 buf_sprintf(output, "\n");
212 buf_append(output, buf->data, buf->size);
214 soc_write(sd, output->data, output->size);
218 /* ¥¥ã¥é¥¯¥¿¥À¥ó¥×¤òºî¤Ã¤Æ BUF¤ËÊݸ */
219 static errr make_dump(BUF* dumpbuf)
223 char file_name[1024];
225 /* Open a new file */
226 fff = my_fopen_temp(file_name, 1024);
230 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
232 msg_format("Failed to create temporary file %s.", file_name);
238 /* °ìö°ì»þ¥Õ¥¡¥¤¥ë¤òºî¤ë¡£Ä̾ï¤Î¥À¥ó¥×½ÐÎϤȶ¦Ä̲½¤¹¤ë¤¿¤á¡£ */
239 (void)make_character_dump(fff);
245 fff = my_fopen(file_name, "r");
247 while (fgets(buf, 1024, fff))
249 (void)buf_sprintf(dumpbuf, "%s", buf);
255 /* Remove the file */
263 * Make screen dump to buffer
265 cptr make_screen_dump(void)
271 byte a = 0, old_a = 0;
274 static cptr html_head[] = {
275 "<html>\n<body text=\"#ffffff\" bgcolor=\"#000000\">\n",
279 static cptr html_foot[] = {
281 "</body>\n</html>\n",
285 bool old_use_graphics = use_graphics;
289 Term_get_size(&wid, &hgt);
292 screen_buf = buf_new();
293 if (screen_buf == NULL) return (NULL);
295 if (old_use_graphics)
297 /* Clear -more- prompt first */
300 use_graphics = FALSE;
303 /* Redraw everything */
304 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
310 for (i = 0; html_head[i]; i++)
311 buf_sprintf(screen_buf, html_head[i]);
313 /* Dump the screen */
314 for (y = 0; y < hgt; y++)
318 buf_sprintf(screen_buf, "\n");
321 for (x = 0; x < wid - 1; x++)
325 /* Get the attr/char */
326 (void)(Term_what(x, y, &a, &c));
330 case '&': cc = "&"; break;
331 case '<': cc = "<"; break;
332 case '>': cc = ">"; break;
334 case 0x1f: c = '.'; break;
335 case 0x7f: c = (a == 0x09) ? '%' : '#'; break;
340 if ((y == 0 && x == 0) || a != old_a) {
341 rv = angband_color_table[a][1];
342 gv = angband_color_table[a][2];
343 bv = angband_color_table[a][3];
344 buf_sprintf(screen_buf, "%s<font color=\"#%02x%02x%02x\">",
345 ((y == 0 && x == 0) ? "" : "</font>"), rv, gv, bv);
349 buf_sprintf(screen_buf, "%s", cc);
351 buf_sprintf(screen_buf, "%c", c);
354 buf_sprintf(screen_buf, "</font>");
356 for (i = 0; html_foot[i]; i++)
357 buf_sprintf(screen_buf, html_foot[i]);
359 /* Screen dump size is too big ? */
360 if (screen_buf->size + 1> SCREEN_BUF_SIZE)
366 /* Terminate string */
367 buf_append(screen_buf, "", 1);
369 ret = string_make(screen_buf->data);
373 buf_delete(screen_buf);
375 if (old_use_graphics)
380 /* Redraw everything */
381 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
391 errr report_score(void)
401 WORD wVersionRequested =(WORD) (( 1) | ( 1 << 8));
406 char seikakutmp[128];
411 sprintf(seikakutmp, "%s%s", ap_ptr->title, (ap_ptr->no ? "¤Î" : ""));
413 sprintf(seikakutmp, "%s ", ap_ptr->title);
416 buf_sprintf(score, "name: %s\n", player_name);
418 buf_sprintf(score, "version: ÊѶòÈÚÅÜ %d.%d.%d\n",
419 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
421 buf_sprintf(score, "version: Hengband %d.%d.%d\n",
422 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
424 buf_sprintf(score, "score: %d\n", total_points());
425 buf_sprintf(score, "level: %d\n", p_ptr->lev);
426 buf_sprintf(score, "depth: %d\n", dun_level);
427 buf_sprintf(score, "maxlv: %d\n", p_ptr->max_plv);
428 buf_sprintf(score, "maxdp: %d\n", max_dlv[DUNGEON_ANGBAND]);
429 buf_sprintf(score, "au: %d\n", p_ptr->au);
430 buf_sprintf(score, "turns: %d\n", turn_real(turn));
431 buf_sprintf(score, "sex: %d\n", p_ptr->psex);
432 buf_sprintf(score, "race: %s\n", rp_ptr->title);
433 buf_sprintf(score, "class: %s\n", cp_ptr->title);
434 buf_sprintf(score, "seikaku: %s\n", seikakutmp);
435 buf_sprintf(score, "realm1: %s\n", realm_names[p_ptr->realm1]);
436 buf_sprintf(score, "realm2: %s\n", realm_names[p_ptr->realm2]);
437 buf_sprintf(score, "killer: %s\n", p_ptr->died_from);
438 buf_sprintf(score, "-----charcter dump-----\n");
444 buf_sprintf(score, "-----screen shot-----\n");
445 buf_append(score, screen_dump, strlen(screen_dump));
449 if (WSAStartup(wVersionRequested, &wsaData))
451 msg_print("Report: WSAStartup failed.");
457 #if TARGET_API_MAC_CARBON
458 err = InitOpenTransportInContext(kInitOTForApplicationMask, NULL);
460 err = InitOpenTransport();
464 msg_print("Report: OpenTransport failed.");
475 prt("ÀܳÃæ...", 0, 0);
477 prt("connecting...", 0, 0);
481 /* ¥×¥í¥¥·¤òÀßÄꤹ¤ë */
482 set_proxy(HTTP_PROXY, HTTP_PROXY_PORT);
484 /* Connect to the score server */
485 sd = connect_server(HTTP_TIMEOUT, SCORE_SERVER, SCORE_PORT);
488 if (!(sd < 0)) break;
490 sprintf(buff, "¥¹¥³¥¢¡¦¥µ¡¼¥Ð¤Ø¤ÎÀܳ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£(%s)", soc_err());
492 sprintf(buff, "Failed to connect to the score server.(%s)", soc_err());
498 if (!get_check_strict("¤â¤¦°ìÅÙÀܳ¤ò»î¤ß¤Þ¤¹¤«? ", CHECK_NO_HISTORY))
500 if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
508 prt("¥¹¥³¥¢Á÷¿®Ãæ...", 0, 0);
510 prt("Sending the score...", 0, 0);
513 http_post(sd, SCORE_PATH, score);
515 disconnect_server(sd);
522 #if TARGET_API_MAC_CARBON
523 CloseOpenTransportInContext(NULL);
525 CloseOpenTransport();
532 #endif /* WORLD_SCORE */