13 #elif defined(MACINTOSH)
14 #include <OpenTransport.h>
15 #include <OpenTptInternet.h>
17 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
31 static int proxy_port;
34 static InetSvcRef inet_services = nil;
35 static EndpointRef ep = kOTInvalidEndpointRef;
38 #if 0 /* ¤È¤ê¤¢¤¨¤º¸½ºß¤Ï»È¤ï¤Ê¤¤¡£by Habu*/
47 homeurl = malloc(strlen(s) + 1);
64 static char buf[BUFSIZ];
66 if(proxy && proxy[0]){
68 snprintf(buf, sizeof(buf), "%s:%d", proxy, proxy_port);
70 _snprintf(buf, sizeof(buf), "%s:%d", proxy, proxy_port);
72 buf[sizeof(buf)-1] = '\0';
91 int soc_read(int sd, char *buf, size_t sz)
94 return read(sd, buf, sz);
96 return recv(sd, buf, sz, 0);
102 /* ¥×¥í¥¥·¥µ¡¼¥Ð¤Î¥¢¥É¥ì¥¹¤ò¤ò¥Õ¥¡¥¤¥ë¤«¤éÆɤó¤ÇÀßÄꤹ¤ë */
103 void set_proxy(char *default_url, int default_port)
115 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, "proxy.prf");
117 /* ¥Õ¥¡¥¤¥ë¤«¤éÀßÄê¤òÆɤࡣ */
118 fp = my_fopen(buf, "r");
122 /* ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Ê¤¤¾ì¹ç¤Ï¥Ç¥Õ¥©¥ë¥È¤òÀßÄê */
124 proxy_port = default_port;
128 while (my_fgets(fp, buf, sizeof(buf))==0)
130 if (buf[0] != '#' && buf[0] != '\0') break;
135 /* ¥Ý¥¤¥ó¥¿¤òÍÑ°Õ¡£ */
138 /* "http://" ¤«¤é»Ï¤Þ¤Ã¤Æ¤¤¤ë¾ì¹ç¤Ï¤½¤ÎÉôʬ¤ò¥«¥Ã¥È¤¹¤ë¡£ */
140 if (!strnicmp(s, "http://", 7))
144 #elif defined(MACINTOSH)
145 strncpy( tmp , s , 7 );
146 for ( i = 0 ; i < 7 ; i++ )
148 if ( isalpha(tmp[i]) )
149 tmp[i]= tolower(tmp[i]);
151 if (!strncmp(s, "http://", 7))
156 if (!strncasecmp(s, "http://", 7))
162 /* ʸ»úÎó¤ÎŤµ¤òÄ´¤Ù¡¢É¬Íפʥá¥â¥ê¤ò³ÎÊÝ */
164 proxy = malloc(len + 1);
166 /* ¥Ý¡¼¥ÈÈֹ椬¤¢¤ë¤«¤É¤¦¤«¤òÄ´¤Ù¡¢¤¢¤ì¤Ðproxy_port¤ËÀßÄê¡£ */
168 while (len > 0 && isdigit(s[len]))
170 if (len > 0 && s[len] == ':' && s[len + 1] != '\0')
174 proxy_port = atoi(s + (len + 1));
179 proxy_port = default_port;
182 /* ¥×¥í¥¥·¤Î¥¢¥É¥ì¥¹¤òproxy¤Ë¥³¥Ô¡¼ */
189 /* ¥½¥±¥Ã¥È¤Ë¥Ð¥Ã¥Õ¥¡¤ÎÆâÍƤò½ñ¤¹þ¤à */
190 int soc_write(int sd, char *buf, size_t sz)
201 nwritten = send(sd, buf, nleft, 0);
208 #else /* !MACINTOSH */
212 OTSnd(ep, (void *) buf, sz, 0);
218 #if 0 /* ¤ª¤½¤é¤¯»È¤ï¤Ê¤¤ */
219 int soc_write_str(int sd, char *buf)
221 return soc_write(sd, buf, strlen(buf));
225 #if !defined(WINDOWS) && !defined(MACINTOSH)
226 static sigjmp_buf env;
227 static void (*sig_int_saved)(int);
228 static void (*sig_alm_saved)(int);
231 static void restore_signal(void)
233 #if !defined(WINDOWS) && !defined(MACINTOSH)
234 struct itimerval val0;
236 /* itimer¥ê¥»¥Ã¥ÈÍÑ */
237 val0.it_interval.tv_sec = 0;
238 val0.it_interval.tv_usec = 0;
239 val0.it_value.tv_sec = 0;
240 val0.it_value.tv_usec = 0;
243 setitimer(ITIMER_REAL, &val0, NULL);
244 signal(SIGALRM, sig_alm_saved);
245 signal(SIGINT, sig_int_saved);
250 #if !defined(WINDOWS) && !defined(MACINTOSH)
251 static void interrupt_report(int sig)
254 siglongjmp(env, sig);
259 /* ¥µ¡¼¥Ð¤Ë¥³¥Í¥¯¥È¤¹¤ë´Ø¿ô¡£ */
260 int connect_server(int timeout, const char *host, int port)
264 struct sockaddr_in to;
268 struct itimerval val;
272 val.it_interval.tv_sec = 0;
273 val.it_interval.tv_usec = 0;
274 val.it_value.tv_sec = timeout;
275 val.it_value.tv_usec = 0;
277 /* ¥¿¥¤¥à¥¢¥¦¥È¡¢¤â¤·¤¯¤ÏÃæÃǤ·¤¿»þ¤Î½èÍý¡£ */
278 if ((ret = sigsetjmp(env,1)) != 0)
282 errstr = "¥¨¥é¡¼: ¥¿¥¤¥à¥¢¥¦¥È";
284 errstr = "¥¨¥é¡¼: ¥¤¥ó¥¿¥é¥×¥È";
287 errstr = "Error : time out";
289 errstr = "Error : interupted";
293 sig_int_saved = signal(SIGINT, interrupt_report);
294 sig_alm_saved = signal(SIGALRM, interrupt_report);
296 /* ¥¿¥¤¥à¥¢¥¦¥È¤Î»þ´Ö¤òÀßÄê */
297 setitimer(ITIMER_REAL, &val, NULL);
299 /* Unused in Windows */
303 /* ¥×¥í¥¥·¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ì¤Ð¥×¥í¥¥·¤Ë·Ò¤° */
304 if (proxy && proxy[0])
306 if ((hp = gethostbyname(proxy)) == NULL)
309 errstr = "¥¨¥é¡¼: ¥×¥í¥¥·¤Î¥¢¥É¥ì¥¹¤¬ÉÔÀµ¤Ç¤¹";
311 errstr = "Error : wrong proxy addres";
319 else if ((hp = gethostbyname(host)) == NULL)
322 errstr = "¥¨¥é¡¼: ¥µ¡¼¥Ð¤Î¥¢¥É¥ì¥¹¤¬ÉÔÀµ¤Ç¤¹";
324 errstr = "Error : wrong server adress";
332 memset(&to, 0, sizeof(to));
333 memcpy(&to.sin_addr, hp->h_addr_list[0], hp->h_length);
335 to.sin_family = AF_INET;
337 if(proxy && proxy[0] && proxy_port)
338 to.sin_port = htons((unsigned short int)proxy_port);
340 to.sin_port = htons((unsigned short int)port);
343 if ((sd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
345 if ((sd = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
349 errstr = "¥¨¥é¡¼: ¥½¥±¥Ã¥È¤òÀ¸À®¤Ç¤¤Þ¤»¤ó";
351 errstr = "Error : cannot create socket.";
357 if (connect(sd, (struct sockaddr *)&to, sizeof(to)) < 0)
360 errstr = "¥¨¥é¡¼: ¥µ¡¼¥Ð¤ËÀܳ¤Ç¤¤Þ¤»¤ó";
362 errstr = "Error : failed to connect server";
378 #else /* !MACINTOSH */
380 /* ¥µ¡¼¥Ð¤Ë¥³¥Í¥¯¥È¤¹¤ë´Ø¿ô¡£ Mac */
383 InetHostInfo response;
387 Boolean bind = false;
389 memset(&response, 0, sizeof(response));
391 #if TARGET_API_MAC_CARBON
392 inet_services = OTOpenInternetServicesInContext(kDefaultInternetServicesPath, 0, &err, NULL);
394 inet_services = OTOpenInternetServices(kDefaultInternetServicesPath, 0, &err);
399 if (proxy && proxy[0])
401 err = OTInetStringToAddress(inet_services, proxy, &response);
405 err = OTInetStringToAddress(inet_services, (char *)host, &response);
410 host_addr = response.addrs[0];
414 errstr = "error: bad score server!\n";
417 #if TARGET_API_MAC_CARBON
418 ep = (void *)OTOpenEndpointInContext(OTCreateConfiguration(kTCPName), 0, nil, &err, NULL);
420 ep = (void *)OTOpenEndpoint(OTCreateConfiguration(kTCPName), 0, nil, &err);
425 err = OTBind(ep, nil, nil);
426 bind = (err == noErr);
430 if (proxy && proxy[0] && proxy_port)
431 OTInitInetAddress(&inAddr, proxy_port, host_addr);
433 OTInitInetAddress(&inAddr, port, host_addr);
435 sndCall.addr.len = sizeof(InetAddress);
436 sndCall.addr.buf = (unsigned char*) &inAddr;
437 sndCall.opt.buf = nil; /* no connection options */
439 sndCall.udata.buf = nil; /* no connection data */
440 sndCall.udata.len = 0;
441 sndCall.sequence = 0; /* ignored by OTConnect */
443 err = OTConnect(ep, &sndCall, NULL);
447 errstr = "error: cannot connect score server!\n";
459 if (ep != kOTInvalidEndpointRef)
464 if (inet_services != nil)
466 OTCloseProvider(inet_services);
478 int disconnect_server(int sd)
481 return closesocket(sd);
482 #elif defined(MACINTOSH)
483 if (ep != kOTInvalidEndpointRef)
488 if (inet_services != nil)
490 OTCloseProvider(inet_services);
502 #endif /* WORLD_SCORE */