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 #define SCORE_PATH "http://www.kmc.gr.jp/~habu/local/hengscore/score.cgi"
32 #define SCORE_PATH "http://www.kmc.gr.jp/~habu/local/hengscore-en/score.cgi"
37 #define SCORE_PATH "http://www.kmc.gr.jp/~habu/local/scoretest/score.cgi"
41 * simple buffer library
50 #define BUFSIZE (65536)
52 #ifndef HAVE_VASPRINTF
53 #define vasprintf Vasprintf
55 static int Vasprintf(char **buf, const char *fmt, va_list ap)
61 #if defined(HAVE_VSNPRINTF)
62 ret = vsnprintf(*buf, 1024, fmt, ap);
64 ret = vsprintf(*buf, fmt, ap);
69 #endif /* ifndef HAVE_VASPRINTF */
71 static BUF* buf_new(void)
75 if ((p = malloc(sizeof(BUF))) == NULL)
79 p->max_size = BUFSIZE;
80 if ((p->data = malloc(BUFSIZE)) == NULL)
88 static void buf_delete(BUF *b)
94 static int buf_append(BUF *buf, const char *data, size_t size)
96 while (buf->size + size > buf->max_size)
99 if ((tmp = malloc(buf->max_size * 2)) == NULL) return -1;
101 memcpy(tmp, buf->data, buf->max_size);
108 memcpy(buf->data + buf->size, data, size);
114 static int buf_sprintf(BUF *buf, const char *fmt, ...)
121 vasprintf(&tmpbuf, fmt, ap);
124 if(!tmpbuf) return -1;
128 /* '\n' is 0x0D and '\r' is 0x0A in MPW. Swap back these. */
130 for (ptr = tmpbuf; *ptr; ptr++)
131 if ('\n' == *ptr) *ptr = '\r';
135 ret = buf_append(buf, tmpbuf, strlen(tmpbuf));
143 static int buf_read(BUF *buf, int fd)
151 tmp = calloc( BUFSIZE , sizeof(char) );
154 while ((len = read(fd, tmp, BUFSIZE)) > 0)
155 buf_append(buf, tmp, len);
162 static int buf_write(BUF *buf, int fd)
164 write(fd, buf->data, buf->size);
169 static int buf_search(BUF *buf, const char *str)
173 ret = strstr(buf->data, str);
177 return ret - buf->data;
180 static BUF * buf_subbuf(BUF *buf, int pos1, size_t sz)
184 if (pos1 < 0) return NULL;
188 if (sz <= 0) sz = buf->size - pos1;
190 buf_append(ret, buf->data + pos1, sz);
196 static void http_post(int sd, cptr url, BUF *buf)
201 buf_sprintf(output, "POST %s HTTP/1.0\n", url);
202 buf_sprintf(output, "User-Agent: Hengband %d.%d.%d\n",
203 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
205 buf_sprintf(output, "Content-Length: %d\n", buf->size);
206 buf_sprintf(output, "Content-Encoding: binary\n");
207 buf_sprintf(output, "Content-Type: application/octet-stream\n");
208 buf_sprintf(output, "\n");
209 buf_append(output, buf->data, buf->size);
211 soc_write(sd, output->data, output->size);
215 /* ¥¥ã¥é¥¯¥¿¥À¥ó¥×¤òºî¤Ã¤Æ BUF¤ËÊݸ */
216 static errr make_dump(BUF* dumpbuf)
220 char file_name[1024];
222 /* Open a new file */
223 fff = my_fopen_temp(file_name, 1024);
227 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", file_name);
229 msg_format("Failed to create temporary file %s.", file_name);
235 /* °ìö°ì»þ¥Õ¥¡¥¤¥ë¤òºî¤ë¡£Ä̾ï¤Î¥À¥ó¥×½ÐÎϤȶ¦Ä̲½¤¹¤ë¤¿¤á¡£ */
236 (void)make_character_dump(fff);
242 fff = my_fopen(file_name, "r");
244 while (fgets(buf, 1024, fff))
246 (void)buf_sprintf(dumpbuf, "%s", buf);
252 /* Remove the file */
260 * Make screen dump to buffer
262 cptr make_screen_dump(void)
268 byte a = 0, old_a = 0;
271 static cptr html_head[] = {
272 "<html>\n<body text=\"#ffffff\" bgcolor=\"#000000\">\n",
276 static cptr html_foot[] = {
278 "</body>\n</html>\n",
282 bool old_use_graphics = use_graphics;
286 Term_get_size(&wid, &hgt);
289 screen_buf = buf_new();
290 if (screen_buf == NULL) return (NULL);
292 if (old_use_graphics)
294 use_graphics = FALSE;
297 /* Redraw everything */
298 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
304 for (i = 0; html_head[i]; i++)
305 buf_sprintf(screen_buf, html_head[i]);
307 /* Dump the screen */
308 for (y = 0; y < hgt; y++)
312 buf_sprintf(screen_buf, "\n");
315 for (x = 0; x < wid - 1; x++)
319 /* Get the attr/char */
320 (void)(Term_what(x, y, &a, &c));
324 case '&': cc = "&"; break;
325 case '<': cc = "<"; break;
326 case '>': cc = ">"; break;
328 case 0x1f: c = '.'; break;
329 case 0x7f: c = (a == 0x09) ? '%' : '#'; break;
334 if ((y == 0 && x == 0) || a != old_a) {
335 rv = angband_color_table[a][1];
336 gv = angband_color_table[a][2];
337 bv = angband_color_table[a][3];
338 buf_sprintf(screen_buf, "%s<font color=\"#%02x%02x%02x\">",
339 ((y == 0 && x == 0) ? "" : "</font>"), rv, gv, bv);
343 buf_sprintf(screen_buf, "%s", cc);
345 buf_sprintf(screen_buf, "%c", c);
348 buf_sprintf(screen_buf, "</font>");
350 for (i = 0; html_foot[i]; i++)
351 buf_sprintf(screen_buf, html_foot[i]);
353 /* Screen dump size is too big ? */
354 if (screen_buf->size + 1> SCREEN_BUF_SIZE)
360 /* Terminate string */
361 buf_append(screen_buf, "", 1);
363 ret = string_make(screen_buf->data);
367 buf_delete(screen_buf);
369 if (old_use_graphics)
374 /* Redraw everything */
375 p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIPPY);
385 errr report_score(void)
395 WORD wVersionRequested =(WORD) (( 1) | ( 1 << 8));
400 char seikakutmp[128];
405 sprintf(seikakutmp, "%s%s", ap_ptr->title, (ap_ptr->no ? "¤Î" : ""));
407 sprintf(seikakutmp, "%s ", ap_ptr->title);
410 buf_sprintf(score, "name: %s\n", player_name);
412 buf_sprintf(score, "version: ÊѶòÈÚÅÜ %d.%d.%d\n",
413 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
415 buf_sprintf(score, "version: Hengband %d.%d.%d\n",
416 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
418 buf_sprintf(score, "score: %d\n", total_points());
419 buf_sprintf(score, "level: %d\n", p_ptr->lev);
420 buf_sprintf(score, "depth: %d\n", dun_level);
421 buf_sprintf(score, "maxlv: %d\n", p_ptr->max_plv);
422 buf_sprintf(score, "maxdp: %d\n", max_dlv[DUNGEON_ANGBAND]);
423 buf_sprintf(score, "au: %d\n", p_ptr->au);
424 buf_sprintf(score, "turns: %d\n", turn_real(turn));
425 buf_sprintf(score, "sex: %d\n", p_ptr->psex);
426 buf_sprintf(score, "race: %s\n", rp_ptr->title);
427 buf_sprintf(score, "class: %s\n", cp_ptr->title);
428 buf_sprintf(score, "seikaku: %s\n", seikakutmp);
429 buf_sprintf(score, "realm1: %s\n", realm_names[p_ptr->realm1]);
430 buf_sprintf(score, "realm2: %s\n", realm_names[p_ptr->realm2]);
431 buf_sprintf(score, "killer: %s\n", p_ptr->died_from);
432 buf_sprintf(score, "-----charcter dump-----\n");
438 buf_sprintf(score, "-----screen shot-----\n");
439 buf_append(score, screen_dump, strlen(screen_dump));
443 if (WSAStartup(wVersionRequested, &wsaData))
445 msg_print("Report: WSAStartup failed.");
451 #if TARGET_API_MAC_CARBON
452 err = InitOpenTransportInContext(kInitOTForApplicationMask, NULL);
454 err = InitOpenTransport();
458 msg_print("Report: OpenTransport failed.");
469 prt("ÀܳÃæ...", 0, 0);
471 prt("connecting...", 0, 0);
475 sd = connect_scoreserver();
476 if (!(sd < 0)) break;
478 sprintf(buff, "¥¹¥³¥¢¡¦¥µ¡¼¥Ð¤Ø¤ÎÀܳ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£(%s)", soc_err());
480 sprintf(buff, "Failed to connect to the score server.(%s)", soc_err());
486 if (!get_check_strict("¤â¤¦°ìÅÙÀܳ¤ò»î¤ß¤Þ¤¹¤«? ", CHECK_NO_HISTORY))
488 if (!get_check_strict("Try again? ", CHECK_NO_HISTORY))
496 prt("¥¹¥³¥¢Á÷¿®Ãæ...", 0, 0);
498 prt("Sending the score...", 0, 0);
501 http_post(sd, SCORE_PATH, score);
503 disconnect_server(sd);
510 #if TARGET_API_MAC_CARBON
511 CloseOpenTransportInContext(NULL);
513 CloseOpenTransport();
520 #endif /* WORLD_SCORE */