Package-Name: tetrinet
Homepage: http://tetrinet.or.cz/
Source: http://tetrinet.or.cz//(tetrinet-(\d+(\.\d+)+)\.tar\.bz2)/[\0-\377]*(tetrinet-(\d+(.\d+)+).tar.bz2) $2 http://tetrinet.or.cz/download/$1
Zap-Before-Install: 1
Repack:
	tar xjvfp "$(SOURCE)"
Compile:
	cp -pf AUTHORS Change* README TODO "$(PREFIX)/"
	$(MAKE)
	mkdir -p "$(PREFIX)"/bin
	cp -pf tetrinet tetrinet-server "$(PREFIX)"/bin/
Install:
	$(MAKE) instbin BIN="tetrinet tetrinet-server"
Patch: <<EOT
######## begin server lines patch
--- server.c.old	2003-09-08 01:29:29 +0900
+++ server.c	2005-01-27 16:45:15 +0900
@@ -31,6 +31,10 @@
 
 static int quit = 0;
 
+static time_t add_line_when = 0;  /*mp*/
+static time_t time_before_adding_lines = 60;  /*mp*/
+static time_t time_between_adding_lines = 10;  /*mp*/
+
 static int listen_sock = -1;
 #ifdef HAVE_IPV6
 static int listen_sock6 = -1;
@@ -171,6 +175,9 @@
 		winlist[i].games = atoi(t+1);
 		i++;
 	    }
+	} else if (strcmp(s, "addlineswhen") == 0) {  /*mp*/
+	    time_before_adding_lines = 60*atoi(strtok(NULL, " "));
+	    time_between_adding_lines = atoi(strtok(NULL, " "));
 	}
     }
     fclose(f);
@@ -223,6 +230,7 @@
 
     fprintf(f, "linuxmode %d\n", linuxmode);
     fprintf(f, "ipv6_only %d\n", ipv6_only);
+    fprintf(f, "addlineswhen %d %d\n", time_before_adding_lines / 60, time_between_adding_lines);  /*mp*/
 
     fclose(f);
 }
@@ -602,6 +610,7 @@
 	}
 	playing_game = 1;
 	game_paused = 0;
+	add_line_when = time(NULL) + time_before_adding_lines;  /*mp*/
 	for (i = 1; i <= 6; i++) {
 	    if (player_socks[i-1] < 0)
 		continue;
@@ -811,6 +820,7 @@
 {
     fd_set fds;
     int i, fd, maxfd;
+    struct timeval timeout;  /*mp*/
 
     FD_ZERO(&fds);
     if (listen_sock >= 0)
@@ -834,7 +844,8 @@
 	}
     }
 
-    if (select(maxfd+1, &fds, NULL, NULL, NULL) <= 0)
+    timeout.tv_sec = 0L; timeout.tv_usec = 500L;  /*mp*/
+    if (select(maxfd+1, &fds, NULL, NULL, &timeout) <= 0)  /*mp*/
 	return;
 
     if (listen_sock >= 0 && FD_ISSET(listen_sock, &fds)) {
@@ -949,8 +960,15 @@
 
     if ((i = init()) != 0)
 	return i;
-    while (!quit)
+    static time_t now;  /*mp*/
+    while (!quit) {  /*mp*/
 	check_sockets();
+	time(&now);  /*mp*/
+	if(playing_game && add_line_when <= now) {  /*mp*/
+	    send_to_all("sb 0 cs1 0");
+	    add_line_when += time_between_adding_lines;
+	};
+    };  /*mp*/
     write_config();
     if (listen_sock >= 0)
 	close(listen_sock);
######## end server lines patch
######## rest is brute force decryption
--- server.c~	2003-09-08 01:29:29 +0900
+++ server.c	2003-11-20 19:47:38 +0900
@@ -886,37 +886,54 @@
 	    continue;
 	sgets(buf, sizeof(buf), fd);
 	if (player_socks[i] < 0) {
-	    /* Messy decoding stuff */
-	    char iphashbuf[16], newbuf[1024];
-	    unsigned char *ip;
-	    int j, c, d;
+	    if (strncmp(buf,"tetrisstart ",12) != 0) {
+		/* Messy decoding stuff */
+		char iphashbuf[16], newbuf[1024];
+#ifdef NO_BRUTE_FORCE_DECRYPTION
+		unsigned char *ip;
+#else
+		int hashval;
+#endif
+		int j, c, d;
 
-	    if (strlen(buf) < 2*13) {	/* "tetrisstart " + initial byte */
-		close(fd);
-		player_socks[i] = -1;
-		continue;
-	    }
-	    ip = player_ips[i];
-	    sprintf(iphashbuf, "%d", ip[0]*54 + ip[1]*41 + ip[2]*29 + ip[3]*17);
-	    c = xtoi(buf);
-	    for (j = 2; buf[j] && buf[j+1]; j += 2) {
-		int temp;
-		temp = d = xtoi(buf+j);
-		d ^= iphashbuf[((j/2)-1) % strlen(iphashbuf)];
-		d += 255 - c;
-		d %= 255;
-		newbuf[j/2-1] = d;
-		c = temp;
-	    }
-	    newbuf[j/2-1] = 0;
-	    if (strncmp(newbuf, "tetrisstart ", 12) != 0) {
-		close(fd);
-		player_socks[i] = -1;
-		continue;
-	    }
-	    /* Buffers should be the same size, but let's be paranoid */
-	    strncpy(buf, newbuf, sizeof(buf));
-	    buf[sizeof(buf)-1] = 0;
+		if (strlen(buf) < 2*13) {  /* "tetrisstart " + initial byte */
+		    close(fd);
+		    player_socks[i] = -1;
+		    continue;
+		}
+#ifdef NO_BRUTE_FORCE_DECRYPTION
+		ip = player_ips[i];
+		sprintf(iphashbuf, "%d",
+			ip[0]*54 + ip[1]*41 + ip[2]*29 + ip[3]*17);
+#else
+		for (hashval = 0; hashval < 35956; hashval++) {
+		    sprintf(iphashbuf, "%d", hashval);
+#endif
+		    c = xtoi(buf);
+		    for (j = 2; buf[j] && buf[j+1]; j += 2) {
+			int temp;
+			temp = d = xtoi(buf+j);
+			d ^= iphashbuf[((j/2)-1) % strlen(iphashbuf)];
+			d += 255 - c;
+			d %= 255;
+			newbuf[j/2-1] = d;
+			c = temp;
+		    }
+		    newbuf[j/2-1] = 0;
+#ifndef NO_BRUTE_FORCE_DECRYPTION
+		    if(strncmp(newbuf,"tetrisstart ",12) == 0)
+			break;
+		} /* for (hashval) */
+#endif
+		if (strncmp(newbuf, "tetrisstart ", 12) != 0) {
+		    close(fd);
+		    player_socks[i] = -1;
+		    continue;
+		}
+		/* Buffers should be the same size, but let's be paranoid */
+		strncpy(buf, newbuf, sizeof(buf));
+		buf[sizeof(buf)-1] = 0;
+	    } /* if encrypted */
 	    player_socks[i] = fd;  /* Has now registered */
 	} /* if client not registered */
 	if (!server_parse(i+1, buf)) {
EOT

/pkg/tetrinet/
/usr/bin/tetrinet
/usr/bin/tetrinet-server
