summaryrefslogtreecommitdiff
path: root/games/xtris/patches/patch-ad
blob: 32ca82af6b2746dc12c05d2033d28c972a600ed5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
$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() {