This is an autogenerated patch header for a single-debian-patch file. The
delta against upstream is either kept as a single patch, or maintained
in some VCS, and exported as a single patch instead of more manageable
atomic patches.

--- tetrinetx-1.13.16.orig/bin/game.conf
+++ tetrinetx-1.13.16/bin/game.conf
@@ -8,10 +8,10 @@
 # Any text after a # is ignored, and can be used as comments.
 
 # pidfile [game.pid] - Where should the Process ID be written
-pidfile=game.pid
+pidfile=/var/run/tetrinetx/game.pid
 
 # bindip [0.0.0.0] - What IP should server be bound to (0.0.0.0 means all)
-bindip=0.0.0.0
+#bindip=0.0.0.0
 
 # maxchannels [1] - How many channels should be available on server
 maxchannels=8
--- tetrinetx-1.13.16.orig/bin/game.secure
+++ tetrinetx-1.13.16/bin/game.secure
@@ -8,15 +8,15 @@
 # Any text after a # is ignored, and can be used as comments.
 
 # op_password [] - Typing /op <thispassword> will give player op status
-op_password=pass4word
+#op_password=pass4word
 
 # query_password [] - For query irc client
-query_password=pass4word
+#query_password=pass4word
 
 # spec_password [] - Use this as team name for gameplay watch
-spec_password=pass4word
+#spec_password=pass4word
 
 # spec_op_password [] - Use this as team name for gameplay watch with extended capability (unused in this release)
-spec_op_password=pass4word
+#spec_op_password=pass4word
 
 # End of File
--- tetrinetx-1.13.16.orig/src/config.h
+++ tetrinetx-1.13.16/src/config.h
@@ -1,22 +1,17 @@
-/*
-  config.h
-  
-  Definitions in here are pretty safe to modify. Generally user defined
-  stuff anyway ;)
-  
-*/
+// CONFIG
+#define FILE_MOTD		"/etc/tetrinetx/game.motd"
+#define FILE_PMOTD		"/etc/tetrinetx/game.pmotd"
+#define FILE_CONF		"/etc/tetrinetx/game.conf"
+#define FILE_BAN		"/etc/tetrinetx/game.ban"
+#define FILE_ALLOW		"/etc/tetrinetx/game.allow"
+#define FILE_SECURE		"/etc/tetrinetx/game.secure"
+#define FILE_BAN_COMPROMISE	"/etc/tetrinetx/game.ban.compromise"
 
-/* Location of the various external files */
-#define FILE_MOTD    "game.motd"	/* Message of the Day File */
-#define FILE_PMOTD    "game.pmotd"	/* Playback motd */
-#define FILE_CONF    "game.conf"	/* Game configuration File */
-#define FILE_WINLIST "game.winlist"	/* Winlist storage file */
-#define FILE_WINLIST2 "game.winlist2"	/* Winlist storage file */
-#define FILE_WINLIST3 "game.winlist3"	/* Winlist storage file */
+// LOG & PID
+#define FILE_LOG		"/var/log/tetrinetx/game.log"
+#define FILE_PID		"/var/run/tetrinetx/game.pid"
 
-#define FILE_BAN     "game.ban"		/* List of Banned IP's */
-#define FILE_BAN_COMPROMISE     "game.ban.compromise"	/* List of Banned IP's */
-#define FILE_ALLOW   "game.allow"	/* List of allow IP's */
-#define FILE_LOG     "game.log"		/* Logfile */
-#define FILE_PID     "game.pid"		/* Default PID */
-#define FILE_SECURE  "game.secure"	/* Security file */
+// SCORES
+#define FILE_WINLIST		"/var/games/tetrinetx/game.winlist"
+#define FILE_WINLIST2		"/var/games/tetrinetx/game.winlist2"
+#define FILE_WINLIST3		"/var/games/tetrinetx/game.winlist3"
--- tetrinetx-1.13.16.orig/src/main.c
+++ tetrinetx-1.13.16/src/main.c
@@ -200,15 +200,23 @@ int is_valid_channelname(char *p)
 
 char is_explicit_banned(struct net_t *n)
   { /* I should use regex, but I've not used it before, and it was late. Easier to write a quick one of my own */
+#ifdef USE_IPV6
+    char ip_str[INET6_ADDRSTRLEN], host[INET6_ADDRSTRLEN];
+#else
     char ip_str[UHOSTLEN+1], host[UHOSTLEN+1];
     char n1[4], n2[4], n3[4], n4[4];
+#endif
     int i, j; int found;
    
+#ifdef USE_IPV6
+    inet_ntop(AF_INET6, &n->addr, (char *)ip_str, INET6_ADDRSTRLEN);
+#else
     sprintf(n1,"%lu", (unsigned long)(n->addr&0xff000000)/(unsigned long)0x1000000);
     sprintf(n2,"%lu", (unsigned long)(n->addr&0x00ff0000)/(unsigned long)0x10000);
     sprintf(n3,"%lu", (unsigned long)(n->addr&0x0000ff00)/(unsigned long)0x100);
     sprintf(n4,"%lu", (unsigned long)n->addr&0x000000ff);
     sprintf(ip_str, "%s.%s.%s.%s", n1, n2, n3, n4);
+#endif
 
     found = 0;
     i = 0;
@@ -228,8 +236,12 @@ char is_explicit_banned(struct net_t *n)
 
 int is_banned(struct net_t *n)
   { /* I should use regex, but I've not used it before, and it was late. Easier to write a quick one of my own */
+#ifdef USE_IPV6
+    char ip_str[INET6_ADDRSTRLEN], host[INET6_ADDRSTRLEN];
+#else
     char ip_str[UHOSTLEN+1], host[UHOSTLEN+1];
     char n1[4], n2[4], n3[4], n4[4];
+#endif
     int i, j; int found, allow;
    
     allow = 0;
@@ -247,11 +259,15 @@ int is_banned(struct net_t *n)
 	return(0);
 		
 	
+#ifdef USE_IPV6
+    inet_ntop(AF_INET6, &n->addr, (char *)ip_str, INET6_ADDRSTRLEN);
+#else
     sprintf(n1,"%lu", (unsigned long)(n->addr&0xff000000)/(unsigned long)0x1000000);
     sprintf(n2,"%lu", (unsigned long)(n->addr&0x00ff0000)/(unsigned long)0x10000);
     sprintf(n3,"%lu", (unsigned long)(n->addr&0x0000ff00)/(unsigned long)0x100);
     sprintf(n4,"%lu", (unsigned long)n->addr&0x000000ff);
     sprintf(ip_str, "%s.%s.%s.%s", n1, n2, n3, n4);
+#endif
 
     found = 0;
     i = 0;
@@ -404,7 +420,11 @@ void init_telnet_port()
     gnet=malloc(sizeof(struct net_t));
     gnet->next=NULL;
     n=gnet;
+#ifdef USE_IPV6
+    getmyip(&n->addr);
+#else
     n->addr=getmyip();
+#endif
     n->type=NET_TELNET;
     n->channel = malloc(sizeof(struct channel_t));
     n->channel->name[0] = '\0';
@@ -452,7 +472,11 @@ void init_query_port()
   /* no existing entry */
   n->next = malloc(sizeof(struct net_t));
   n = n->next;
+#ifdef USE_IPV6
+  getmyip(&n->addr);
+#else
   n->addr=getmyip();
+#endif
   n->type=NET_QUERY;
   n->next=NULL;
   n->channel = malloc(sizeof(struct channel_t));
@@ -496,7 +520,11 @@ void init_playback_port()
   /* no existing entry */
   n->next = malloc(sizeof(struct net_t));
   n = n->next;
+#ifdef USE_IPV6
+  getmyip(&n->addr);
+#else
   n->addr=getmyip();
+#endif
   n->type=NET_PLAYBACK;
   n->next=NULL;
   n->channel = malloc(sizeof(struct channel_t));
@@ -2317,6 +2345,19 @@ int net_query_playerquery(struct net_t *
         return 1;
 }
 
+#ifdef USE_IPV6
+int net_query_IPconvert(struct net_t *n, char *host)
+{
+	char ip_str[INET6_ADDRSTRLEN];
+
+	inet_ntop(AF_INET6, &n->addr, (char *)ip_str, INET6_ADDRSTRLEN);
+	if (n->host[0] == 0 || strlen(n->host) >= UHOSTLEN)
+		sprintf(host, "%s",ip_str);
+	else
+		strcpy(host, n->host);
+	return 1;
+}
+#else
 int net_query_IPconvert(struct net_t *n, char *host)
 {
 	unsigned char x1, x2, x3, x4;
@@ -2333,6 +2374,7 @@ int net_query_IPconvert(struct net_t *n,
 		strcpy(host, n->host);
 	return 1;
 }
+#endif
 
 /* Trim weird useless chars at the end */
 int net_query_TrimStr(char *p)
@@ -3468,8 +3510,12 @@ void net_query_init(struct net_t *n, cha
 /* Someone has just connected. So lets answer them */
 void net_query(struct net_t *n, char *buf)
 {
+#ifdef USE_IPV6
+	struct in6_addr ip;
+#else
 	IP ip;
 	/* unsigned char x1, x2, x3, x4; */
+#endif
 	struct net_t *net;
 
 	net=malloc(sizeof(struct net_t));
@@ -3481,7 +3527,11 @@ void net_query(struct net_t *n, char *bu
 	net->sock=answer(n->sock,&ip,0);
 	setopt(net->sock, 0);
 
+#ifdef USE_IPV6
+	memcpy(&net->addr, &ip, sizeof(ip));
+#else
 	net->addr=ip;
+#endif
 	net->port=n->port;
 	net->securitylevel=LEVEL_NORMAL;
 	net->status=STAT_NOTPLAYING;
@@ -3490,6 +3540,9 @@ void net_query(struct net_t *n, char *bu
 	strcpy(net->nick, "(telnet)");
 	do_async_dns(net);
 	net->type = NET_WAITINGFORDNS;
+#ifdef USE_IPV6
+net_donedns(net);
+#endif
 }
 
 void net_query_donedns (struct net_t *net) {
@@ -3646,8 +3699,12 @@ int net_playback_isvalidnick(char *p)
 /* Someone has just connected. So lets answer them */
 void net_playback(struct net_t *n, char *buf)
 {
+#ifdef USE_IPV6
+	struct in6_addr ip;
+#else
         IP ip;
         /* unsigned char x1, x2, x3, x4; */
+#endif
         struct net_t *net;
 
         net=malloc(sizeof(struct net_t));
@@ -3659,7 +3716,11 @@ void net_playback(struct net_t *n, char
         net->sock=answer(n->sock,&ip,0);
 		setopt(net->sock, 0);
 
+#ifdef USE_IPV6
+	memcpy(&net->addr, &ip, sizeof(ip));
+#else
         net->addr=ip;
+#endif
         net->port=n->port;
         net->securitylevel=LEVEL_NORMAL;
         net->status=STAT_NOTPLAYING;
@@ -3669,6 +3730,9 @@ void net_playback(struct net_t *n, char
         strcpy(net->nick, "(telnet)");
 		do_async_dns(net);
 		net->type = NET_WAITINGFORDNS;
+#ifdef USE_IPV6
+net_donedns(net);
+#endif
 }
 
 void net_playback_donedns(struct net_t *net) {
@@ -4348,7 +4412,11 @@ void net_telnet_init(struct net_t *n, ch
 /* Someone has just connected. So lets answer them */
 void net_telnet(struct net_t *n, char *buf)
   {
+#ifdef USE_IPV6
+    static struct in6_addr ip;
+#else
     unsigned long ip;
+#endif
     struct net_t *net;
 
 
@@ -4361,7 +4429,11 @@ void net_telnet(struct net_t *n, char *b
       net->sock=answer(n->sock,&ip,0);
 	setopt(net->sock, 0);
     /* Save the port stuff */
+#ifdef USE_IPV6
+    memcpy(&net->addr, &ip, sizeof(ip));
+#else
     net->addr=ip;
+#endif
     net->port=n->port;
     net->securitylevel=LEVEL_NORMAL;
     net->status=STAT_NOTPLAYING;
@@ -4373,11 +4445,23 @@ void net_telnet(struct net_t *n, char *b
     net->timeout_ingame = 30;
 	do_async_dns(net);
     net->type = NET_WAITINGFORDNS;
+#ifdef USE_IPV6
+net_donedns(net);
+#endif
 	/* net has not been added to socket list */
 	/* EOF on this will be EOF on unknown socket */
 	
 }
 
+#ifdef USE_IPV6
+void do_async_dns (struct net_t *n) {
+	char ip_str[INET6_ADDRSTRLEN];
+
+	inet_ntop(AF_INET6, &n->addr, (char *)ip_str, INET6_ADDRSTRLEN);
+	sprintf(n->host, "%s", ip_str);
+	sprintf(n->ip, "%s", ip_str);
+}
+#else
 void do_async_dns (struct net_t *n) {
 	char n1[4], n2[4], n3[4], n4[4];
 	char buf[1024];
@@ -4393,11 +4477,14 @@ void do_async_dns (struct net_t *n) {
 	res_id = query_do(buf);
 	add_rnet(n, res_id);
 }
+#endif
 
 void net_donedns(struct net_t *net) {
 
 	if (net->type != NET_WAITINGFORDNS) return;
+#ifndef USE_IPV6
 	rem_rnet(net);
+#endif
     switch(net->port) {
     	case TELNET_PORT: { net_telnet_donedns (net); break; }
     	case QUERY_PORT:  { net_query_donedns (net); break; }
--- tetrinetx-1.13.16.orig/src/main.h
+++ tetrinetx-1.13.16/src/main.h
@@ -47,7 +47,11 @@
 
 /* Defines */
 #define TETVERSION "1.13"		/* What Tetrinet version we are for */
-#define SERVERBUILD "16+qirc-1.40b"	/* What build we are at */
+#ifdef USE_IPV6
+#define SERVERBUILD "16+qirc-1.40c-IPv6"	/* What build we are at */
+#else
+#define SERVERBUILD "16+qirc-1.40c"	/* What build we are at */
+#endif
 #define NICKLEN 30			/* Maximum length of Nickname */
 #define VERLEN 10			/* Maximum length of Tetrinet version */
 #define UHOSTLEN 121			/* Maximum length of Hostname */
@@ -240,7 +244,11 @@ struct game_t {
 
 struct net_t {
   int sock; 				/* Socket this player is on */
+#ifdef USE_IPV6
+  struct in6_addr addr;
+#else
   IP addr; 				/* IP address of player */
+#endif
   unsigned int port; 			/* Port number they connected to */
   char nick[NICKLEN+1];			/* Nickname of player */
   char team[TEAMLEN+1]; 		/* Teamname of player */
--- tetrinetx-1.13.16.orig/src/net.c
+++ tetrinetx-1.13.16/src/net.c
@@ -6,21 +6,25 @@
 
 
 /* i read somewhere that memcpy() is broken on some machines */
-/* it's easy to replace, so i'm not gonna take any chances, because it's
-*/
+/* it's easy to replace, so i'm not gonna take any chances, because it's */
 /* pretty important that it work correctly here */
-void my_memcpy(dest,src,len)
+/* XXX until the contrary is proved, I'll use ISO C functions instead of
+ * my_*. */
+/* void my_memcpy(dest,src,len)
 char *dest,*src; int len;
 {
   while (len--) *dest++=*src++;
 }
+*/
 
 /* bzero() is bsd-only, so here's one for non-bsd systems */
+/* XXX but memset is ISO C, replaced.
 void my_bzero(dest,len)
 char *dest; int len;
 {
   while (len--) *dest++=0;
 }
+*/
 
 /* initialize the socklist */
 void init_net()
@@ -52,14 +56,39 @@ int expmem_net()
 void getmyhostname(s)
 char *s;
 {
-  struct hostent *hp; char *p;
+  /* struct hostent *hp; */
+  char *p;
  
-  p=getenv("HOSTNAME"); if (p!=NULL) {
-    strncpy(s,p, UHOSTLEN);
-    s[UHOSTLEN] = 0;
-    if (strchr(s,'.')!=NULL) return;
+  if ( (p=getenv("HOSTNAME")) != NULL )
+  {
+    strncpy(s, p, UHOSTLEN);
+    s[UHOSTLEN] = '\0';
+    if (strchr(s,'.') == NULL)
+    {
+	    strncat(s,".localnet", UHOSTLEN - strlen(s));
+	    setenv("HOSTNAME",(const char*)s, 1);
+    }
+    return;
   }
-  gethostname(s,80);
+  else if (gethostname(s,MAXHOSTNAMELEN) == 0)
+  {
+		s[UHOSTLEN] = '\0';
+    if (strchr(s,'.') == NULL)
+    {
+	    strncat(s,".localnet", UHOSTLEN - strlen(s));
+	    setenv("HOSTNAME",(const char*)s, 1);
+    }
+    return;
+  }
+  else
+  {
+	memset(s,'\0',UHOSTLEN);
+	strncpy(s, "localhost.localnet", UHOSTLEN);
+	s[UHOSTLEN] = '\0';
+	setenv("HOSTNAME",(const char*)s,1);
+	return;
+  }
+/*  gethostname(s,MAXHOSTNAMELEN);
   if (strchr(s,'.')!=NULL) return;
   hp=gethostbyname(s);
   if (hp==NULL)
@@ -73,9 +102,27 @@ char *s;
   s[UHOSTLEN] = 0;
   if (strchr(s,'.')==NULL)
     fatal("Can't determine your hostname!",0);   
+*/
 }
 
 /* get my ip number */
+#ifdef USE_IPV6
+void getmyip(struct in6_addr *ip)
+{
+  struct addrinfo hints, *res;
+  char s[121];
+
+  gethostname(s,120);
+  memset(&hints, 0, sizeof(hints));
+  hints.ai_family = AF_UNSPEC;
+  hints.ai_socktype = SOCK_STREAM;
+  if (getaddrinfo(s, NULL, &hints, &res)) {
+    fatal("Hostname self-lookup failed.",0);
+  }
+  memcpy(ip, res->ai_addr, res->ai_addrlen);
+  freeaddrinfo(res);
+}
+#else
 IP getmyip()
 {
   struct hostent *hp; char s[121]; IP ip; struct in_addr *in;
@@ -88,6 +135,7 @@ IP getmyip()
   ip=(IP)(in->s_addr);
   return ip;
 }
+#endif
 
 void neterror(s)
 char *s;
@@ -185,7 +233,13 @@ int parm, x;
 int getsock(options)
 int options;
 {
-  int sock=socket(AF_INET,SOCK_STREAM,0);
+  int sock;
+#ifdef USE_IPV6
+  if ( (sock = socket(AF_INET6,SOCK_STREAM,0)) <0 )
+	  sock=socket(AF_INET,SOCK_STREAM,0);
+#else
+  sock=socket(AF_INET,SOCK_STREAM,0);
+#endif
   if (sock<0) fatal("Can't open a socket at all!",0);
   setsock(sock,options); return sock;
 }
@@ -228,10 +282,28 @@ int sock;
 int open_listen_socket(port,bindip)
 int *port; char *bindip;
 {
+#ifdef USE_IPV6
+  int sock,addrlen; struct sockaddr_in6 name;
+
+  sock=getsock(SOCK_LISTEN);
+  memset((char *)&name,'\0',sizeof(struct sockaddr_in6));
+  name.sin6_family=AF_INET6;
+  name.sin6_port=htons(*port);   /* 0 = just assign us a port */
+  if (bind(sock,(struct sockaddr *)&name,sizeof(name))<0) {
+printf("ERROR\n");
+    killsock(sock); return -1;
+  }
+  /* what port are we on? */
+  addrlen=sizeof(name);
+  if (getsockname(sock,(struct sockaddr *)&name,&addrlen)<0) {
+    killsock(sock); return -1;
+  }
+  *port=ntohs(name.sin6_port);
+#else
   int sock,addrlen; struct sockaddr_in name;
 
   sock=getsock(SOCK_LISTEN);
-  my_bzero((char *)&name,sizeof(struct sockaddr_in));
+  memset((char *)&name,'\0',sizeof(struct sockaddr_in));
   name.sin_family=AF_INET;
   name.sin_port=htons(*port);   /* 0 = just assign us a port */
   name.sin_addr.s_addr=getip(bindip);
@@ -246,6 +318,7 @@ printf("ERROR\n");
     killsock(sock); return -1;
   }
   *port=ntohs(name.sin_port);
+#endif
   if (listen(sock,5)<0) { printf("Erk\n"); killsock(sock); return -1; }
   return sock;
 }
@@ -280,19 +353,28 @@ unsigned long ip;
 
 /* short routine to answer a connect received on a socket made previously
 */
+#ifdef USE_IPV6
 int answer(sock,ip,binary)
-int sock; unsigned long *ip; int binary;
+int sock; struct in6_addr *ip; int binary;
 {
-  int new_sock,addrlen; struct sockaddr_in from;
-  addrlen=sizeof(struct sockaddr);
+  int new_sock,addrlen; struct sockaddr_in6 from;
+  addrlen=sizeof(struct sockaddr_in6);
   new_sock=accept(sock,(struct sockaddr *)&from,&addrlen);
   if (new_sock<0) return -1;
-  *ip=from.sin_addr.s_addr;
-  *ip=ntohl(*ip);
+  memcpy(ip, &from.sin6_addr, sizeof(struct in6_addr));
+  /* set up all the normal socket crap */
+  // setsock(new_sock,(binary ? SOCK_BINARY : 0));
+  return new_sock;
+}
+#else
+int answer(sock,ip,binary)
+int sock; unsigned long *ip; int binary;
+{
   /* set up all the normal socket crap */
   // setsock(new_sock,(binary ? SOCK_BINARY : 0));
   return new_sock;
 }
+#endif
 
 /* attempts to read from all the sockets in socklist */
 /* fills s with up to 1023 bytes if available, and returns 0 */
@@ -437,7 +519,7 @@ char *s; int *len;
     s[0]=0; return slist->sock;
   }
   if (slist->flags & SOCK_BINARY) {
-    my_memcpy(s,xx,*len);
+    memcpy(s,xx,*len);
     return slist->sock;      
   }
   if (slist->flags & SOCK_LISTEN) return slist->sock;
--- tetrinetx-1.13.16.orig/src/net.h
+++ tetrinetx-1.13.16/src/net.h
@@ -37,6 +37,9 @@
 #define SOCK_NONSOCK    0x10    /* used for file i/o on debug */
 #define SOCK_STRONGCONN 0x20    /* don't report success until sure */   
 
+/* some hard-coded values are better with #define :) */
+#define MAXHOSTNAMELEN	80
+
 /* this is used by the net module to keep track of sockets and what's
    queued on them */
 struct sock_list {
@@ -51,15 +54,10 @@ struct sock_list {
 /*#define MAXSOCKS MAXNET*2*/
 struct sock_list *socklist;  /* enough to be safe */   
 
-/* i read somewhere that memcpy() is broken on some machines */
-/* it's easy to replace, so i'm not gonna take any chances, because it's
-*/
-/* pretty important that it work correctly here */
+/* XXX: deleted, see .c for explanations.
 void my_memcpy(char *dest,char *src,int len);
-
-
-/* bzero() is bsd-only, so here's one for non-bsd systems */
 void my_bzero(char *dest,int len);
+*/
 
 
 /* initialize the socklist */
@@ -75,7 +73,11 @@ void getmyhostname(char *s);
 
 
 /* get my ip number */
+#ifdef USE_IPV6
+void getmyip(struct in6_addr *ip);
+#else
 IP getmyip(void);
+#endif
 
 
 void neterror(char *s);
@@ -106,7 +108,11 @@ char *hostnamefromip(unsigned long ip);
 */
 /* by open_listen ... returns hostname of the caller & the new socket */
 /* does NOT dispose of old "public" socket! */
+#ifdef USE_IPV6
+int answer(int sock,struct in6_addr *ip,int binary);
+#else
 int answer(int sock,unsigned long *ip,int binary);
+#endif
 
 
 /* attempts to read from all the sockets in socklist */
