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"
36 /*#define SCORE_PATH "http://www.kmc.gr.jp/~habu/local/scoretest/score.cgi" */
39 * simple buffer library
48 #define BUFSIZE (65536)
50 #ifndef HAVE_VASPRINTF
51 #define vasprintf Vasprintf
53 static int Vasprintf(char **buf, const char *fmt, va_list ap)
59 #if defined(HAVE_VSNPRINTF)
60 ret = vsnprintf(*buf, 1024, fmt, ap);
62 ret = vsprintf(*buf, fmt, ap);
67 #endif /* ifndef HAVE_VASPRINTF */
69 static BUF* buf_new(void)
73 if ((p = malloc(sizeof(BUF))) == NULL)
77 p->max_size = BUFSIZE;
78 if ((p->data = malloc(BUFSIZE)) == NULL)
86 static void buf_delete(BUF *b)
92 static int buf_append(BUF *buf, const char *data, size_t size)
94 while (buf->size + size > buf->max_size)
97 if ((tmp = malloc(buf->max_size * 2)) == NULL) return -1;
99 memcpy(tmp, buf->data, buf->max_size);
106 memcpy(buf->data + buf->size, data, size);
112 static int buf_sprintf(BUF *buf, const char *fmt, ...)
119 vasprintf(&tmpbuf, fmt, ap);
122 if(!tmpbuf) return -1;
126 /* '\n' is 0x0D and '\r' is 0x0A in MPW. Swap back these. */
128 for (ptr = tmpbuf; *ptr; ptr++)
129 if ('\n' == *ptr) *ptr = '\r';
133 ret = buf_append(buf, tmpbuf, strlen(tmpbuf));
141 static int buf_read(BUF *buf, int fd)
149 tmp = calloc( BUFSIZE , sizeof(char) );
152 while ((len = read(fd, tmp, BUFSIZE)) > 0)
153 buf_append(buf, tmp, len);
160 static int buf_write(BUF *buf, int fd)
162 write(fd, buf->data, buf->size);
167 static int buf_search(BUF *buf, const char *str)
171 ret = strstr(buf->data, str);
175 return ret - buf->data;
178 static BUF * buf_subbuf(BUF *buf, int pos1, size_t sz)
182 if (pos1 < 0) return NULL;
186 if (sz <= 0) sz = buf->size - pos1;
188 buf_append(ret, buf->data + pos1, sz);
194 static void http_post(int sd, char *url, BUF *buf)
199 buf_sprintf(output, "POST %s HTTP/1.0\n", url);
200 buf_sprintf(output, "User-Agent: Hengband %d.%d.%d\n",
201 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
203 buf_sprintf(output, "Content-Length: %d\n", buf->size);
204 buf_sprintf(output, "Content-Encoding: binary\n");
205 buf_sprintf(output, "Content-Type: application/octet-stream\n");
206 buf_sprintf(output, "\n");
207 buf_append(output, buf->data, buf->size);
209 soc_write(sd, output->data, output->size);
213 /* ¥¥ã¥é¥¯¥¿¥À¥ó¥×¤òºî¤Ã¤Æ BUF¤ËÊݸ */
214 static errr make_dump(BUF* dumpbuf)
216 errr make_character_dump(FILE *fff);
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 char *html_head[] = {
272 "<html>\n<body text=\"#ffffff\" bgcolor=\"#000000\">\n",
276 static char *html_foot[] = {
278 "</body>\n</html>\n",
286 screen_buf = buf_new();
287 if (screen_buf == NULL) return (NULL);
289 for (i = 0; html_head[i]; i++)
290 buf_sprintf(screen_buf, html_head[i]);
292 /* Dump the screen */
293 for (y = 0; y < 24; y++)
297 buf_sprintf(screen_buf, "\n");
300 for (x = 0; x < 79; x++)
304 /* Get the attr/char */
305 (void)(Term_what(x, y, &a, &c));
309 case '&': cc = "&"; break;
310 case '<': cc = "<"; break;
311 case '>': cc = ">"; break;
313 case 0x1f: c = '.'; break;
314 case 0x7f: c = (a == 0x09) ? '%' : '#'; break;
319 if ((y == 0 && x == 0) || a != old_a) {
320 rv = angband_color_table[a][1];
321 gv = angband_color_table[a][2];
322 bv = angband_color_table[a][3];
323 buf_sprintf(screen_buf, "%s<font color=\"#%02x%02x%02x\">",
324 ((y == 0 && x == 0) ? "" : "</font>"), rv, gv, bv);
328 buf_sprintf(screen_buf, "%s", cc);
330 buf_sprintf(screen_buf, "%c", c);
333 buf_sprintf(screen_buf, "</font>");
335 for (i = 0; html_foot[i]; i++)
336 buf_sprintf(screen_buf, html_foot[i]);
338 /* Screen dump size is too big ? */
339 if (screen_buf->size + 1> SCREEN_BUF_SIZE)
341 buf_delete(screen_buf);
345 /* Terminate string */
346 buf_append(screen_buf, "", 1);
348 ret = string_make(screen_buf->data);
351 buf_delete(screen_buf);
357 errr report_score(void)
367 WORD wVersionRequested =(WORD) (( 1) | ( 1 << 8));
372 char seikakutmp[128];
377 sprintf(seikakutmp, "%s%s", ap_ptr->title, (ap_ptr->no ? "¤Î" : ""));
379 sprintf(seikakutmp, "%s ", ap_ptr->title);
382 buf_sprintf(score, "name: %s\n", player_name);
384 buf_sprintf(score, "version: ÊѶòÈÚÅÜ %d.%d.%d\n",
385 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
387 buf_sprintf(score, "version: Hengband %d.%d.%d\n",
388 FAKE_VER_MAJOR-10, FAKE_VER_MINOR, FAKE_VER_PATCH);
390 buf_sprintf(score, "score: %d\n", total_points());
391 buf_sprintf(score, "level: %d\n", p_ptr->lev);
392 buf_sprintf(score, "depth: %d\n", dun_level);
393 buf_sprintf(score, "maxlv: %d\n", p_ptr->max_plv);
394 buf_sprintf(score, "maxdp: %d\n", max_dlv[DUNGEON_ANGBAND]);
395 buf_sprintf(score, "au: %d\n", p_ptr->au);
396 buf_sprintf(score, "turns: %d\n", turn_real(turn));
397 buf_sprintf(score, "sex: %d\n", p_ptr->psex);
398 buf_sprintf(score, "race: %s\n", rp_ptr->title);
399 buf_sprintf(score, "class: %s\n", cp_ptr->title);
400 buf_sprintf(score, "seikaku: %s\n", seikakutmp);
401 buf_sprintf(score, "realm1: %s\n", realm_names[p_ptr->realm1]);
402 buf_sprintf(score, "realm2: %s\n", realm_names[p_ptr->realm2]);
403 buf_sprintf(score, "killer: %s\n", died_from);
404 buf_sprintf(score, "-----charcter dump-----\n");
410 buf_sprintf(score, "-----screen shot-----\n");
411 buf_append(score, screen_dump, strlen(screen_dump));
415 if (WSAStartup(wVersionRequested, &wsaData))
417 msg_print("Report: WSAStartup failed.");
423 #if TARGET_API_MAC_CARBON
424 err = InitOpenTransportInContext(kInitOTForApplicationMask, NULL);
426 err = InitOpenTransport();
430 msg_print("Report: OpenTransport failed.");
441 prt("ÀܳÃæ...", 0, 0);
443 prt("connecting...", 0, 0);
447 sd = connect_scoreserver();
448 if (!(sd < 0)) break;
450 sprintf(buff, "¥¹¥³¥¢¡¦¥µ¡¼¥Ð¤Ø¤ÎÀܳ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£(%s)", soc_err());
452 sprintf(buff, "Failed to connect to the score server.(%s)", soc_err());
458 if (!get_check("¤â¤¦°ìÅÙÀܳ¤ò»î¤ß¤Þ¤¹¤«? "))
460 if (!get_check("Try again? "))
468 prt("¥¹¥³¥¢Á÷¿®Ãæ...", 0, 0);
470 prt("Sending the score...", 0, 0);
473 http_post(sd, SCORE_PATH, score);
475 disconnect_server(sd);
482 #if TARGET_API_MAC_CARBON
483 CloseOpenTransportInContext(NULL);
485 CloseOpenTransport();
492 #endif /* WORLD_SCORE */