pkgsrc/games/xtris/patches/patch-ad
hubertf 397e340b06 Add xtris-1.15:
xtris is a version of an classical popular game, for any number of
players, for the X Window system.

xtris is a true client/server game (as opposed to a centralized game
managing multiple displays), which makes it particularily responsive and
bandwith-effective.

Submitted by Oliver Paulzen <opp@muffin.org> in private mail.
2002-01-25 17:47:19 +00:00

102 lines
2.3 KiB
Text

$NetBSD: patch-ad,v 1.1.1.1 2002/01/25 17:47:19 hubertf Exp $
--- xtris.c.orig Sun Dec 14 19:40:04 1997
+++ xtris.c
@@ -1633,10 +1633,11 @@
fprintf(stderr, "Can't start bot '%s'.\n",
#ifdef XTRISPATH
- XTRISPATH "/xtbot");
+ XTRISPATH "/xtbot"
#else
- "xtbot");
+ "xtbot"
#endif
+ );
_exit(1);
case -1:
@@ -2674,11 +2675,11 @@
fprintf(stderr, "Can't start server '%s'.\n",
#ifdef XTRISPATH
- XTRISPATH "/xtserv");
+ XTRISPATH "/xtserv"
#else
- "xtserv");
+ "xtserv"
#endif
-
+ );
_exit(1);
case -1:
@@ -2690,11 +2691,60 @@
}
void connect2server(char *h) {
+#ifdef INET6
+ struct addrinfo hints, *res0, *res;
+ int gai;
+ struct sockaddr_storage s;
+ char serv_buf[NI_MAXSERV];
+ char str_buf[512];
+#else
struct hostent *hp;
struct sockaddr_in s;
+#endif
struct protoent *tcpproto;
int on = 1, i;
+#ifdef INET6
+ snprintf(serv_buf, sizeof(serv_buf) , "%d", port);
+ serv_buf[sizeof(serv_buf)-1] = '\0';
+ for (i=0; i<7; i++){
+ memset (&hints, 0, sizeof(hints));
+ hints.ai_family = PF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ gai = getaddrinfo(h, serv_buf, &hints, &res0);
+ if (gai){
+ snprintf(str_buf, sizeof(str_buf)-1,
+ "getaddrinfo(): %s", gai_strerror(gai));
+ fatal(str_buf);
+ }
+ for (res=res0; res; res=res->ai_next){
+ sfd = socket(res->ai_family, res->ai_socktype, 0);
+ if (sfd < 0) continue;
+ if ((tcpproto = getprotobyname("tcp")) != NULL)
+ setsockopt(sfd, tcpproto->p_proto, TCP_NODELAY, (char *)&on, sizeof(int));
+ if (connect(sfd, res->ai_addr, res->ai_addrlen) < 0){
+ close(sfd);
+ sfd = -1;
+ continue;
+ }
+ break;
+ }
+ freeaddrinfo(res0);
+ if (sfd >= 0) break;
+ if (!h){
+ if (i==0){
+ printf("No xtris server on localhost - starting up one ...\n");
+ startserver();
+ }
+ u_sleep(500000);
+ continue;
+ }
+ else
+ break;
+ }
+ if (sfd < 0)
+ fatal("Can't connect to server");
+#else
if (h) {
if ((s.sin_addr.s_addr = inet_addr(h)) == -1) {
hp = gethostbyname(h);
@@ -2729,6 +2779,7 @@
fatal("Can't connect to server");
} else fatal("Can't connect to server");
}
+#endif
}
void sigchld() {