]> git.deb.at Git - pkg/netris.git/commitdiff
Imported Debian patch 0.52-7 debian/0.52-7
authorGerfried Fuchs <rhonda@debian.at>
Fri, 30 May 2008 06:34:31 +0000 (08:34 +0200)
committerGerfried Fuchs <rhonda@debian.at>
Wed, 14 Jul 2010 19:42:45 +0000 (21:42 +0200)
24 files changed:
board.c
curses.c
debian/changelog
debian/control
debian/copyright
debian/menu
debian/netris-sample-robot.6
debian/patches/01_multi-games-with-scoring [new file with mode: 0644]
debian/patches/02_line-count-patch [new file with mode: 0644]
debian/patches/03_staircase-effect-fix [new file with mode: 0644]
debian/patches/04_robot-close-fixup [new file with mode: 0644]
debian/patches/05_init-static-vars [new file with mode: 0644]
debian/patches/06_curses.c-include-term.h [new file with mode: 0644]
debian/patches/07_curses.c-include-time.h [new file with mode: 0644]
debian/patches/08_various-fixes [new file with mode: 0644]
debian/patches/series [new file with mode: 0644]
debian/postinst
debian/postrm
debian/rules
game.c
inet.c
netris.h
robot.c
util.c

diff --git a/board.c b/board.c
index 621677c1a8002f196aad0a0c130df5f062815a61..d1cb66bb2b12caadc07fa176a788e5e1dc245012 100644 (file)
--- a/board.c
+++ b/board.c
@@ -36,19 +36,6 @@ static int oldFalling[MAX_SCREENS][MAX_BOARD_WIDTH];
 
 ExtFunc void InitBoard(int scr)
 {
-       int s,w,h;
-
-       for(s = 0 ; s < MAX_SCREENS ; s++)
-               for(h = 0 ; h < MAX_BOARD_HEIGHT ; h++)
-                       for(w = 0 ; w < MAX_BOARD_WIDTH ; w++) {
-                               board[s][h][w] = 0;
-                               oldBoard[s][h][w] = 0;
-                               changed[s][h] = 0;
-                               falling[s][w] = 0;
-                               oldFalling[s][w] = 0;
-                       }
-                               
-
        boardHeight[scr] = MAX_BOARD_HEIGHT;
        boardVisible[scr] = 20;
        boardWidth[scr] = 10;
index dc708bd4b4ce5f03d1c6dc0cb8a389c78e348cc5..14e9ce47e32b796ab3c61732d65e5b18a366974f 100644 (file)
--- a/curses.c
+++ b/curses.c
  */
 
 #include "netris.h"
-#include <time.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <term.h>
 #include <curses.h>
 #include <string.h>
 #include <stdlib.h>
@@ -59,7 +57,6 @@ static EventGenRec keyGen =
 static int boardYPos[MAX_SCREENS], boardXPos[MAX_SCREENS];
 static int statusYPos, statusXPos;
 static int haveColor;
-static int screens_dirty = 0;
 
 static char *term_vi;  /* String to make cursor invisible */
 static char *term_ve;  /* String to make cursor visible */
@@ -101,7 +98,6 @@ ExtFunc void InitScreens(void)
 #endif
 
        AtExit(CleanupScreens);
-       screens_dirty = 1;
        RestoreSignals(NULL, &oldMask);
 
        cbreak();
@@ -120,12 +116,9 @@ ExtFunc void InitScreens(void)
 
 ExtFunc void CleanupScreens(void)
 {
-       if (screens_dirty) {
-               RemoveEventGen(&keyGen);
-               endwin();
-               OutputTermStr(term_ve, 1);
-               screens_dirty = 0;
-       }
+       RemoveEventGen(&keyGen);
+       endwin();
+       OutputTermStr(term_ve, 1);
 }
 
 ExtFunc void GetTermcapInfo(void)
@@ -208,8 +201,6 @@ ExtFunc void InitScreen(int scr)
        for (y = boardVisible[scr] - 1; y >= 0; --y) {
                move(boardYPos[scr] - y, boardXPos[scr] - 1);
                addch('|');
-               for (x = boardWidth[scr] - 1; x >= 0; --x)
-                       addstr("  ");
                move(boardYPos[scr] - y, boardXPos[scr] + 2 * boardWidth[scr]);
                addch('|');
        }
@@ -265,29 +256,6 @@ ExtFunc void PlotUnderline(int scr, int x, int flag)
 
 ExtFunc void ShowDisplayInfo(void)
 {
-       if (game == GT_classicTwo) {
-               move(statusYPos - 5, statusXPos);
-               printw("Enemy lines: %3d/%4d", enemyLinesCleared, enemyTotalLinesCleared);
-       }
-       move(statusYPos - 4, statusXPos);
-       printw("My lines:    %3d/%4d", myLinesCleared, myTotalLinesCleared);
-       move(statusYPos - 3, statusXPos);
-       printw("Won:  %3d", won);
-       move(statusYPos - 2, statusXPos);
-       printw("Lost: %3d", lost);
-
-       move(statusYPos - 1, statusXPos);
-       switch(gameState) {
-       case STATE_WAIT_CONNECTION:
-               addstr("Waiting for opponent...      ");
-               break;
-       case STATE_WAIT_KEYPRESS:
-               addstr("Press the key for a new game.");
-               break;
-       default:
-               addstr("                             ");
-       }
-
        move(statusYPos - 9, statusXPos);
        printw("Seed: %d", initSeed);
        clrtoeol();
@@ -295,7 +263,7 @@ ExtFunc void ShowDisplayInfo(void)
        printw("Speed: %dms", speed / 1000);
        clrtoeol();
        if (robotEnable) {
-               move(statusYPos - 7, statusXPos);
+               move(statusYPos - 6, statusXPos);
                if (fairRobot)
                        addstr("Controlled by a fair robot");
                else
@@ -303,7 +271,7 @@ ExtFunc void ShowDisplayInfo(void)
                clrtoeol();
        }
        if (opponentFlags & SCF_usingRobot) {
-               move(statusYPos - 6, statusXPos);
+               move(statusYPos - 5, statusXPos);
                if (opponentFlags & SCF_fairRobot)
                        addstr("The opponent is a fair robot");
                else
index a1e40ec02f1168978b13b180cb95e85ea15b4922..46ef7feca5788ba6e7da70b139dee41286ef155e 100644 (file)
@@ -1,3 +1,29 @@
+netris (0.52-7) unstable; urgency=low
+
+  * The "once every release" release.
+  * Moved patches to quilt, split them into:
+    - multi-games-with-scoring: allow multiple games in a row without
+      restarting.
+    - line-count-patch: patch to display cleared line counts
+    - staircase-effect-fix: fix displaying of error messages
+    - robot-close-fixup: Small fix for CloseRobot function to close only if a
+      robot is used.
+    - init-static-vars: initialize lostConn and gotEndConn static var in
+      InitNet function.
+    - curses.c-include-term.h: patch to fix function call that otherwise use
+      implicit pointer conversion.
+    - curses.c-include-time.h: patch to fix segfault on amd64.
+  * New patches:
+    - various-fixes: various small changes to fix compile warnings
+  * Linked to GPL-2 in copyright file directly, added hint for later versions.
+  * Added copyright informations into the debianization scripts.
+  * Added Homepage: control field.
+  * Updated package to Standards-Version 3.7.3, updating menu section for that.
+  * Don't ignore make clean errors anymore.
+  * Small cosmetic updates to the netris-sample-robot manpage.
+
+ -- Gerfried Fuchs <rhonda@debian.at>  Fri, 30 May 2008 08:34:31 +0200
+
 netris (0.52-6) unstable; urgency=low
 
   * #include <time.h> in curses.c (closes: #345305)
index d097518ecea57f7e164a1848f475b67444de0217..11d13ab8885a8a78145728be7999cd75c31e4ba8 100644 (file)
@@ -1,9 +1,10 @@
 Source: netris
 Section: games
 Priority: optional
-Maintainer: Gerfried Fuchs <alfie@debian.org>
-Build-Depends: libncurses5-dev
-Standards-Version: 3.7.2
+Maintainer: Gerfried Fuchs <rhonda@debian.at>
+Build-Depends: libncurses5-dev, quilt
+Standards-Version: 3.7.3
+Homepage: http://netris.org/
 
 Package: netris
 Architecture: any
index 63c4f910991ce1b9b8d167f6bcd2d62217c453a4..4f411d71769cfb2df65b7246d61b4fd2fc44810b 100644 (file)
@@ -1,5 +1,6 @@
 This package was first debianized by Gergely Madarasz <gorgo@caesar.elte.hu> on
 Wed,  6 Aug 1997 22:10:42 +0200.
+It is maintained since 2002 by Gerfried Fuchs <rhonda@debian.at>.
 
 It was downloaded from ftp://ftp.netris.org/pub/netris/
 
@@ -21,4 +22,8 @@ It was downloaded from ftp://ftp.netris.org/pub/netris/
     Boston, MA 02110-1301 USA.
 
 On Debian GNU/Linux systems, the complete text of the GNU General
-Public License can be found in `/usr/share/common-licenses/GPL'.
+Public License version 2 can be found in `/usr/share/common-licenses/GPL-2',
+later versions can be found in the same directory.
+
+The Debian packaging is (C) 2002-2008 Gerfried Fuchs <rhonda@debian.at>,
+licensed the same way as netris itself.
index 604f85209318b04332515c3b270e8120f9ac38f0..8565c31adb1a4f59c79decbd8b92a77dcbdb65cb 100644 (file)
@@ -1,2 +1,2 @@
-?package(netris):needs="text" section="Games/Tetris-like" title="Netris" \
+?package(netris):needs="text" section="Games/Blocks" title="Netris" \
   command="/usr/games/netris" longtitle="Networked Tetris"
index f43a1837ca2826f7b3f194262ba59bfe1a4ee10d..552e0ee3489e4d0e099018c31fe3e09f6c24cf3c 100644 (file)
@@ -1,11 +1,11 @@
 .TH netris-sample-robot 6 "16 Feb 2002" "0.5" "Netris Sample Robot"
 .SH "NAME"
-netris-sample-robot \- sample robot for netris
+netris\-sample\-robot \- sample robot for netris
 .SH "SYNOPSIS"
 .B netris-sample-robot
 .RB [\| \-l \|]
 .SH "DESCRIPTION"
-The netris-sample-robot is a sample implementation of the robot protocol. It
+The netris\-sample\-robot is a sample implementation of the robot protocol. It
 plays quite well but isn't too hard to beat. The robot should be started from
 netris with the option
 .B \-r
@@ -21,8 +21,8 @@ in the current working directory. If it can't it bails out.
 
 .SH "EXAMPLES"
 .TP
-To start the netris-sample-robot waiting for another connection with logfile use the following line:
-netris -w -r 'netris-sample-robot -l'
+To start the netris\-sample\-robot waiting for another connection with logfile use the following line:
+netris \-w \-r 'netris\-sample\-robot \-l'
 .P
 You then just have to start netris somewhere else which connects to that robot.
 
@@ -30,10 +30,10 @@ You then just have to start netris somewhere else which connects to that robot.
 .BR netris (6)
 
 .SH "BUGS"
-One known bug of the netris-sample-robot is that it hangs quite often. This was
-already filed as a bugreport against the package so please refrain from doing
-so again.  If you have an idea why this happens or know a solution how to fix
-it feel free to mail me.
+One known bug of the netris\-sample\-robot is that it hangs quite often.
+This was already filed as a bugreport against the package so please
+refrain from doing so again. If you have an idea why this happens or
+know a solution how to fix it feel free to mail us.
 
 .SH "AUTHORS"
 Netris was written by Mark H. Weaver <mhw@netris.org>.
diff --git a/debian/patches/01_multi-games-with-scoring b/debian/patches/01_multi-games-with-scoring
new file mode 100644 (file)
index 0000000..3d08e9c
--- /dev/null
@@ -0,0 +1,406 @@
+Index: netris-0.52/curses.c
+===================================================================
+--- netris-0.52.orig/curses.c
++++ netris-0.52/curses.c
+@@ -201,6 +201,8 @@ ExtFunc void InitScreen(int scr)
+       for (y = boardVisible[scr] - 1; y >= 0; --y) {
+               move(boardYPos[scr] - y, boardXPos[scr] - 1);
+               addch('|');
++              for (x = boardWidth[scr] - 1; x >= 0; --x)
++                      addstr("  ");
+               move(boardYPos[scr] - y, boardXPos[scr] + 2 * boardWidth[scr]);
+               addch('|');
+       }
+@@ -256,6 +258,23 @@ ExtFunc void PlotUnderline(int scr, int 
+ ExtFunc void ShowDisplayInfo(void)
+ {
++      move(statusYPos - 3, statusXPos);
++      printw("Won:  %3d", won);
++      move(statusYPos - 2, statusXPos);
++      printw("Lost: %3d", lost);
++
++      move(statusYPos - 1, statusXPos);
++      switch(gameState) {
++      case STATE_WAIT_CONNECTION:
++              addstr("Waiting for opponent...      ");
++              break;
++      case STATE_WAIT_KEYPRESS:
++              addstr("Press the key for a new game.");
++              break;
++      default:
++              addstr("                             ");
++      }
++
+       move(statusYPos - 9, statusXPos);
+       printw("Seed: %d", initSeed);
+       clrtoeol();
+Index: netris-0.52/netris.h
+===================================================================
+--- netris-0.52.orig/netris.h
++++ netris-0.52/netris.h
+@@ -65,7 +65,7 @@ typedef long netint4;
+ #define DEFAULT_PORT 9284     /* Very arbitrary */
+-#define DEFAULT_KEYS "jkl mspf^l"
++#define DEFAULT_KEYS "jkl mspf^ln"
+ /* Protocol versions */
+ #define MAJOR_VERSION         1       
+@@ -152,6 +152,13 @@ typedef struct _ShapeOption {
+ typedef int (*ShapeDrawFunc)(int scr, int y, int x,
+                                       BlockType type, void *data);
++enum States {
++      STATE_STARTING,
++      STATE_PLAYING,
++      STATE_WAIT_CONNECTION,
++      STATE_WAIT_KEYPRESS
++};
++
+ EXT GameType game;
+ EXT int boardHeight[MAX_SCREENS];
+ EXT int boardVisible[MAX_SCREENS], boardWidth[MAX_SCREENS];
+@@ -167,6 +174,9 @@ EXT long stepDownInterval, speed;
+ EXT int myFlags, opponentFlags;
++EXT int won, lost;
++EXT enum States gameState;
++
+ EXT char scratch[1024];
+ extern ShapeOption stdOptions[];
+Index: netris-0.52/util.c
+===================================================================
+--- netris-0.52.orig/util.c
++++ netris-0.52/util.c
+@@ -74,7 +74,7 @@ ExtFunc void Usage(void)
+         "  -p <port>  Set port number (default is %d)\n"
+         "  -k <keys>  Remap keys.  The argument is a prefix of the string\n"
+         "               containing the keys in order: left, rotate, right, drop,\n"
+-        "               down-faster, toggle-spying, pause, faster, redraw.\n"
++        "               down-faster, toggle-spying, pause, faster, redraw, new.\n"
+         "               \"^\" prefixes controls.  (default is \"%s\")\n"
+         "  -i <sec>   Set the step-down interval, in seconds\n"
+         "  -r <robot> Execute <robot> (a command) as a robot controlling\n"
+Index: netris-0.52/game.c
+===================================================================
+--- netris-0.52.orig/game.c
++++ netris-0.52/game.c
+@@ -28,11 +28,11 @@
+ #include <netinet/in.h>
+ enum { KT_left, KT_rotate, KT_right, KT_drop, KT_down,
+-      KT_toggleSpy, KT_pause, KT_faster, KT_redraw, KT_numKeys };
++      KT_toggleSpy, KT_pause, KT_faster, KT_redraw, KT_new, KT_numKeys };
+ static char *keyNames[KT_numKeys+1] = {
+       "Left", "Rotate", "Right", "Drop", "Down", "ToggleSpy", "Pause",
+-      "Faster", "Redraw", NULL };
++      "Faster", "Redraw", "New", NULL };
+ static char *gameNames[GT_len] = { "OnePlayer", "ClassicTwo" };
+@@ -40,6 +40,10 @@ static char keyTable[KT_numKeys+1];
+ static int dropModeEnable = 0;
+ static char *robotProg;
++static int wonLast = 0;
++int lost = 0, won = 0;
++enum States gameState = STATE_STARTING;
++
+ ExtFunc void MapKeys(char *newKeys)
+ {
+       int i, k, ch;
+@@ -323,6 +327,7 @@ ExtFunc void OneGame(int scr, int scr2)
+                                       break;
+                               case E_lostRobot:
+                               case E_lostConn:
++                                      wonLast = 1;
+                                       goto gameOver;
+                               default:
+                                       break;
+@@ -350,14 +355,17 @@ ExtFunc void OneGame(int scr, int scr2)
+                       SendPacket(NP_giveJunk, sizeof(data), data);
+               }
+       }
++      wonLast = 0;
++
+ gameOver:
+       SetITimer(0, 0);
+ }
+ ExtFunc int main(int argc, char **argv)
+ {
+-      int initConn = 0, waitConn = 0, ch;
++      int initConn = 0, waitConn = 0, ch, done = 0;
+       char *hostStr = NULL, *portStr = NULL;
++      MyEvent event;
+       standoutEnable = colorEnable = 1;
+       stepDownInterval = DEFAULT_INTERVAL;
+@@ -422,112 +430,139 @@ ExtFunc int main(int argc, char **argv)
+       if (fairRobot && !robotEnable)
+               fatal("You can't use the -F option without the -r option");
+       InitUtil();
+-      if (robotEnable)
+-              InitRobot(robotProg);
+-      InitNet();
+       InitScreens();
+-      if (initConn || waitConn) {
+-              MyEvent event;
+-
+-              game = GT_classicTwo;
+-              if (initConn)
+-                      InitiateConnection(hostStr, portStr);
+-              else if (waitConn)
+-                      WaitForConnection(portStr);
+-              {
+-                      netint4 data[2];
+-                      int major;
+-
+-                      data[0] = hton4(MAJOR_VERSION);
+-                      data[1] = hton4(PROTOCOL_VERSION);
+-                      SendPacket(NP_version, sizeof(data), data);
+-                      if (WaitMyEvent(&event, EM_net) != E_net)
+-                              fatal("Network negotiation failed");
+-                      memcpy(data, event.u.net.data, sizeof(data));
+-                      major = ntoh4(data[0]);
+-                      protocolVersion = ntoh4(data[1]);
+-                      if (event.u.net.type != NP_version || major < MAJOR_VERSION)
+-                              fatal("Your opponent is using an old, incompatible version\n"
+-                                      "of Netris.  They should get the latest version.");
+-                      if (major > MAJOR_VERSION)
+-                              fatal("Your opponent is using an newer, incompatible version\n"
+-                                      "of Netris.  Get the latest version.");
+-                      if (protocolVersion > PROTOCOL_VERSION)
+-                              protocolVersion = PROTOCOL_VERSION;
+-              }
+-              if (protocolVersion < 3 && stepDownInterval != DEFAULT_INTERVAL)
+-                      fatal("Your opponent's version of Netris predates the -i option.\n"
+-                                      "For fairness, you shouldn't use the -i option either.");
+-              {
+-                      netint4 data[3];
+-                      int len;
+-                      int seed;
++      while(!done) {
++              if (robotEnable)
++                      InitRobot(robotProg);
++              InitNet();
++              if (!initSeed)
++                      SRandom(time(0));
++              if (initConn || waitConn) {
++                      game = GT_classicTwo;
++                      if(gameState != STATE_STARTING) {
++                              gameState = STATE_WAIT_CONNECTION;
++                              ShowDisplayInfo();
++                              RefreshScreen();
++                      }
++                      if (initConn)
++                              InitiateConnection(hostStr, portStr);
++                      else if (waitConn)
++                              WaitForConnection(portStr);
++                      gameState = STATE_PLAYING;
++                      ShowDisplayInfo();
++                      RefreshScreen();
++                      {
++                              netint4 data[2];
++                              int major;
++
++                              data[0] = hton4(MAJOR_VERSION);
++                              data[1] = hton4(PROTOCOL_VERSION);
++                              SendPacket(NP_version, sizeof(data), data);
++                              if (WaitMyEvent(&event, EM_net) != E_net)
++                                      fatal("Network negotiation failed");
++                              memcpy(data, event.u.net.data, sizeof(data));
++                              major = ntoh4(data[0]);
++                              protocolVersion = ntoh4(data[1]);
++                              if (event.u.net.type != NP_version || major < MAJOR_VERSION)
++                                      fatal("Your opponent is using an old, incompatible version\n"
++                                            "of Netris.  They should get the latest version.");
++                              if (major > MAJOR_VERSION)
++                                      fatal("Your opponent is using an newer, incompatible version\n"
++                                            "of Netris.  Get the latest version.");
++                              if (protocolVersion > PROTOCOL_VERSION)
++                                      protocolVersion = PROTOCOL_VERSION;
++                      }
++                      if (protocolVersion < 3 && stepDownInterval != DEFAULT_INTERVAL)
++                              fatal("Your opponent's version of Netris predates the -i option.\n"
++                                    "For fairness, you shouldn't use the -i option either.");
++                      {
++                              netint4 data[3];
++                              int len;
++                              int seed;
+-                      if (protocolVersion >= 3)
+-                              len = sizeof(data);
+-                      else
+-                              len = sizeof(netint4[2]);
+-                      if ((myFlags & SCF_setSeed))
+-                              seed = initSeed;
+-                      else
+-                              seed = time(0);
+-                      if (waitConn)
+-                              SRandom(seed);
+-                      data[0] = hton4(myFlags);
+-                      data[1] = hton4(seed);
+-                      data[2] = hton4(stepDownInterval);
+-                      SendPacket(NP_startConn, len, data);
+-                      if (WaitMyEvent(&event, EM_net) != E_net ||
+-                                      event.u.net.type != NP_startConn)
+-                              fatal("Network negotiation failed");
+-                      memcpy(data, event.u.net.data, len);
+-                      opponentFlags = ntoh4(data[0]);
+-                      seed = ntoh4(data[1]);
+-                      if (initConn) {
+-                              if ((opponentFlags & SCF_setSeed) != (myFlags & SCF_setSeed))
+-                                      fatal("If one player sets the random number seed, "
+-                                                      "both must.");
+-                              if ((myFlags & SCF_setSeed) && seed != initSeed)
+-                                      fatal("Both players have set the random number seed, "
+-                                                      "and they are unequal.");
+-                              if (protocolVersion >= 3 && stepDownInterval != ntoh4(data[2]))
+-                                      fatal("Your opponent is using a different step-down "
+-                                              "interval (-i).\nYou must both use the same one.");
+-                              SRandom(seed);
++                              if (protocolVersion >= 3)
++                                      len = sizeof(data);
++                              else
++                                      len = sizeof(netint4[2]);
++                              if ((myFlags & SCF_setSeed))
++                                      seed = initSeed;
++                              else
++                                      seed = time(0);
++                              if (waitConn)
++                                      SRandom(seed);
++                              data[0] = hton4(myFlags);
++                              data[1] = hton4(seed);
++                              data[2] = hton4(stepDownInterval);
++                              SendPacket(NP_startConn, len, data);
++                              if (WaitMyEvent(&event, EM_net) != E_net ||
++                                  event.u.net.type != NP_startConn)
++                                      fatal("Network negotiation failed");
++                              memcpy(data, event.u.net.data, len);
++                              opponentFlags = ntoh4(data[0]);
++                              seed = ntoh4(data[1]);
++                              if (initConn) {
++                                      if ((opponentFlags & SCF_setSeed) != (myFlags & SCF_setSeed))
++                                              fatal("If one player sets the random number seed, "
++                                                    "both must.");
++                                      if ((myFlags & SCF_setSeed) && seed != initSeed)
++                                              fatal("Both players have set the random number seed, "
++                                                    "and they are unequal.");
++                                      if (protocolVersion >= 3 && stepDownInterval != ntoh4(data[2]))
++                                              fatal("Your opponent is using a different step-down "
++                                                    "interval (-i).\nYou must both use the same one.");
++                                      SRandom(seed);
++                              }
++                      }
++                      {
++                              char *userName;
++                              int len, i;
++
++                              userName = getenv("LOGNAME");
++                              if (!userName || !userName[0])
++                                      userName = getenv("USER");
++                              if (!userName || !userName[0])
++                                      strcpy(userName, "???");
++                              len = strlen(userName)+1;
++                              if (len > sizeof(opponentName))
++                                      len = sizeof(opponentName);
++                              SendPacket(NP_userName, len, userName);
++                              if (WaitMyEvent(&event, EM_net) != E_net ||
++                                  event.u.net.type != NP_userName)
++                                      fatal("Network negotiation failed");
++                              strncpy(opponentName, event.u.net.data,
++                                      sizeof(opponentName)-1);
++                              opponentName[sizeof(opponentName)-1] = 0;
++                              for (i = 0; opponentName[i]; ++i)
++                                      if (!isprint(opponentName[i]))
++                                              opponentName[i] = '?';
++                              for (i = 0; opponentHost[i]; ++i)
++                                      if (!isprint(opponentHost[i]))
++                                              opponentHost[i] = '?';
+                       }
++                      OneGame(0, 1);
+               }
+-              {
+-                      char *userName;
+-                      int len, i;
+-
+-                      userName = getenv("LOGNAME");
+-                      if (!userName || !userName[0])
+-                              userName = getenv("USER");
+-                      if (!userName || !userName[0])
+-                              strcpy(userName, "???");
+-                      len = strlen(userName)+1;
+-                      if (len > sizeof(opponentName))
+-                              len = sizeof(opponentName);
+-                      SendPacket(NP_userName, len, userName);
+-                      if (WaitMyEvent(&event, EM_net) != E_net ||
+-                                      event.u.net.type != NP_userName)
+-                              fatal("Network negotiation failed");
+-                      strncpy(opponentName, event.u.net.data,
+-                              sizeof(opponentName)-1);
+-                      opponentName[sizeof(opponentName)-1] = 0;
+-                      for (i = 0; opponentName[i]; ++i)
+-                              if (!isprint(opponentName[i]))
+-                                      opponentName[i] = '?';
+-                      for (i = 0; opponentHost[i]; ++i)
+-                              if (!isprint(opponentHost[i]))
+-                                      opponentHost[i] = '?';
++              else {
++                      game = GT_onePlayer;
++                      OneGame(0, -1);
++              }
++              if (wonLast) {
++                      won++;
++              } else {
++                      lost++;
++                      WaitMyEvent(&event, EM_net);
++              }
++              CloseNet();
++              if (robotEnable) {
++                      CloseRobot();
++              } else {
++                      gameState = STATE_WAIT_KEYPRESS;
++                      ShowDisplayInfo();
++                      RefreshScreen();
++                      while(getchar() != keyTable[KT_new])
++                              ;
+               }
+-              OneGame(0, 1);
+-      }
+-      else {
+-              game = GT_onePlayer;
+-              OneGame(0, -1);
+       }
++
+       return 0;
+ }
+Index: netris-0.52/board.c
+===================================================================
+--- netris-0.52.orig/board.c
++++ netris-0.52/board.c
+@@ -36,6 +36,18 @@ static int oldFalling[MAX_SCREENS][MAX_B
+ ExtFunc void InitBoard(int scr)
+ {
++      int s,w,h;
++
++      for(s = 0 ; s < MAX_SCREENS ; s++)
++              for(h = 0 ; h < MAX_BOARD_HEIGHT ; h++)
++                      for(w = 0 ; w < MAX_BOARD_WIDTH ; w++) {
++                              board[s][h][w] = 0;
++                              oldBoard[s][h][w] = 0;
++                              changed[s][h] = 0;
++                              falling[s][w] = 0;
++                              oldFalling[s][w] = 0;
++                      }
++
+       boardHeight[scr] = MAX_BOARD_HEIGHT;
+       boardVisible[scr] = 20;
+       boardWidth[scr] = 10;
diff --git a/debian/patches/02_line-count-patch b/debian/patches/02_line-count-patch
new file mode 100644 (file)
index 0000000..eefc7b4
--- /dev/null
@@ -0,0 +1,97 @@
+Author: Piotr Krukowiecki <piotrwww@krukowiecki.net>   vim:ft=diff:
+Description: patch to display line counter, BTS #304224
+
+Index: netris-0.52/curses.c
+===================================================================
+--- netris-0.52.orig/curses.c
++++ netris-0.52/curses.c
+@@ -258,6 +258,12 @@ ExtFunc void PlotUnderline(int scr, int 
+ ExtFunc void ShowDisplayInfo(void)
+ {
++      if (game == GT_classicTwo) {
++              move(statusYPos - 5, statusXPos);
++              printw("Enemy lines: %3d/%4d", enemyLinesCleared, enemyTotalLinesCleared);
++      }
++      move(statusYPos - 4, statusXPos);
++      printw("My lines:    %3d/%4d", myLinesCleared, myTotalLinesCleared);
+       move(statusYPos - 3, statusXPos);
+       printw("Won:  %3d", won);
+       move(statusYPos - 2, statusXPos);
+@@ -282,7 +288,7 @@ ExtFunc void ShowDisplayInfo(void)
+       printw("Speed: %dms", speed / 1000);
+       clrtoeol();
+       if (robotEnable) {
+-              move(statusYPos - 6, statusXPos);
++              move(statusYPos - 7, statusXPos);
+               if (fairRobot)
+                       addstr("Controlled by a fair robot");
+               else
+@@ -290,7 +296,7 @@ ExtFunc void ShowDisplayInfo(void)
+               clrtoeol();
+       }
+       if (opponentFlags & SCF_usingRobot) {
+-              move(statusYPos - 5, statusXPos);
++              move(statusYPos - 6, statusXPos);
+               if (opponentFlags & SCF_fairRobot)
+                       addstr("The opponent is a fair robot");
+               else
+Index: netris-0.52/game.c
+===================================================================
+--- netris-0.52.orig/game.c
++++ netris-0.52/game.c
+@@ -103,6 +103,7 @@ ExtFunc void OneGame(int scr, int scr2)
+       int key;
+       char *p, *cmd;
++      myLinesCleared = enemyLinesCleared = 0;
+       speed = stepDownInterval;
+       ResetBaseTime();
+       InitBoard(scr);
+@@ -297,7 +298,15 @@ ExtFunc void OneGame(int scr, int scr2)
+                                                       DropPiece(scr2);
+                                                       break;
+                                               case NP_clear:
+-                                                      ClearFullLines(scr2);
++                                                      {
++                                                              int cleared = ClearFullLines(scr2);
++                                                              if (cleared) {
++                                                                      enemyLinesCleared += cleared;
++                                                                      enemyTotalLinesCleared += cleared;
++                                                                      ShowDisplayInfo();
++                                                                      RefreshScreen();
++                                                              }
++                                                      }
+                                                       break;
+                                               case NP_insertJunk:
+                                               {
+@@ -343,7 +352,12 @@ ExtFunc void OneGame(int scr, int scr2)
+       nextPiece:
+               dropMode = 0;
+               FreezePiece(scr);
+-              linesCleared = ClearFullLines(scr);
++              myLinesCleared += linesCleared = ClearFullLines(scr);
++              myTotalLinesCleared += linesCleared;
++              if (linesCleared) {
++                      ShowDisplayInfo();
++                      RefreshScreen();
++              }
+               if (linesCleared > 0 && spied)
+                       SendPacket(NP_clear, 0, NULL);
+               if (game == GT_classicTwo && linesCleared > 1) {
+Index: netris-0.52/netris.h
+===================================================================
+--- netris-0.52.orig/netris.h
++++ netris-0.52/netris.h
+@@ -182,6 +182,11 @@ EXT char scratch[1024];
+ extern ShapeOption stdOptions[];
+ extern char *version_string;
++EXT int myLinesCleared;
++EXT int enemyLinesCleared;
++EXT int myTotalLinesCleared;
++EXT int enemyTotalLinesCleared;
++
+ #include "proto.h"
+ #endif /* NETRIS_H */
diff --git a/debian/patches/03_staircase-effect-fix b/debian/patches/03_staircase-effect-fix
new file mode 100644 (file)
index 0000000..514e867
--- /dev/null
@@ -0,0 +1,51 @@
+Author: Per von Zweigbergk <pvz@e.kth.se>      vim:ft=diff:
+Description: fix staircase effect in error message, BTS #83039
+
+Index: netris-0.52/util.c
+===================================================================
+--- netris-0.52.orig/util.c
++++ netris-0.52/util.c
+@@ -267,6 +267,7 @@ ExtFunc volatile void die(char *msg)
+ ExtFunc volatile void fatal(char *msg)
+ {
++      CleanupScreens ();
+       fprintf(stderr, "%s\n", msg);
+       exit(1);
+ }
+Index: netris-0.52/curses.c
+===================================================================
+--- netris-0.52.orig/curses.c
++++ netris-0.52/curses.c
+@@ -57,6 +57,7 @@ static EventGenRec keyGen =
+ static int boardYPos[MAX_SCREENS], boardXPos[MAX_SCREENS];
+ static int statusYPos, statusXPos;
+ static int haveColor;
++static int screens_dirty = 0;
+ static char *term_vi; /* String to make cursor invisible */
+ static char *term_ve; /* String to make cursor visible */
+@@ -98,6 +99,7 @@ ExtFunc void InitScreens(void)
+ #endif
+       AtExit(CleanupScreens);
++      screens_dirty = 1;
+       RestoreSignals(NULL, &oldMask);
+       cbreak();
+@@ -116,9 +118,12 @@ ExtFunc void InitScreens(void)
+ ExtFunc void CleanupScreens(void)
+ {
+-      RemoveEventGen(&keyGen);
+-      endwin();
+-      OutputTermStr(term_ve, 1);
++      if (screens_dirty) {
++              RemoveEventGen(&keyGen);
++              endwin();
++              OutputTermStr(term_ve, 1);
++              screens_dirty = 0;
++      }
+ }
+ ExtFunc void GetTermcapInfo(void)
diff --git a/debian/patches/04_robot-close-fixup b/debian/patches/04_robot-close-fixup
new file mode 100644 (file)
index 0000000..74cfec4
--- /dev/null
@@ -0,0 +1,31 @@
+Index: netris-0.52/robot.c
+===================================================================
+--- netris-0.52.orig/robot.c
++++ netris-0.52/robot.c
+@@ -35,7 +35,7 @@ static EventGenRec robotGen =
+               { NULL, 0, FT_read, -1, RobotGenFunc, EM_robot };
+ static int robotProcess;
+-static FILE *toRobot;
++static FILE *toRobot = NULL;
+ static int toRobotFd, fromRobotFd;
+ static char robotBuf[128];
+@@ -112,10 +112,13 @@ ExtFunc void RobotTimeStamp(void)
+ ExtFunc void CloseRobot(void)
+ {
+       RemoveEventGen(&robotGen);
+-      if (robotProcess > 0)
+-              RobotCmd(1, "Exit\n");
+-      fclose(toRobot);
+-      close(fromRobotFd);
++      if(toRobot) {
++              if (robotProcess > 0)
++                      RobotCmd(1, "Exit\n");
++              fclose(toRobot);
++              close(fromRobotFd);
++              toRobot = NULL;
++      }
+ }
+ static MyEventType RobotGenFunc(EventGenRec *gen, MyEvent *event)
diff --git a/debian/patches/05_init-static-vars b/debian/patches/05_init-static-vars
new file mode 100644 (file)
index 0000000..cf3bec3
--- /dev/null
@@ -0,0 +1,13 @@
+Index: netris-0.52/inet.c
+===================================================================
+--- netris-0.52.orig/inet.c
++++ netris-0.52/inet.c
+@@ -42,6 +42,8 @@ static int isServer, lostConn, gotEndCon
+ ExtFunc void InitNet(void)
+ {
++      lostConn = 0;
++      gotEndConn = 0;
+       AtExit(CloseNet);
+ }
diff --git a/debian/patches/06_curses.c-include-term.h b/debian/patches/06_curses.c-include-term.h
new file mode 100644 (file)
index 0000000..88aafcb
--- /dev/null
@@ -0,0 +1,15 @@
+Author: David Mosberger <David.Mosberger@acm.org>      vim:ft=diff:
+Description: #include <term.h> to avoid implicit pointer conversion, BTS #325926
+
+Index: netris-0.52/curses.c
+===================================================================
+--- netris-0.52.orig/curses.c
++++ netris-0.52/curses.c
+@@ -22,6 +22,7 @@
+ #include "netris.h"
+ #include <sys/types.h>
+ #include <unistd.h>
++#include <term.h>
+ #include <curses.h>
+ #include <string.h>
+ #include <stdlib.h>
diff --git a/debian/patches/07_curses.c-include-time.h b/debian/patches/07_curses.c-include-time.h
new file mode 100644 (file)
index 0000000..e9c25df
--- /dev/null
@@ -0,0 +1,15 @@
+Author: Brian Brazil <bbrazil@netsoc.tcd.ie>   vim:ft=diff:
+Description: #include <time.h> to avoid segfault on amd64, BTS #345305
+
+Index: netris-0.52/curses.c
+===================================================================
+--- netris-0.52.orig/curses.c
++++ netris-0.52/curses.c
+@@ -20,6 +20,7 @@
+  */
+ #include "netris.h"
++#include <time.h>
+ #include <sys/types.h>
+ #include <unistd.h>
+ #include <term.h>
diff --git a/debian/patches/08_various-fixes b/debian/patches/08_various-fixes
new file mode 100644 (file)
index 0000000..a145ee8
--- /dev/null
@@ -0,0 +1,37 @@
+Index: netris-0.52/game.c
+===================================================================
+--- netris-0.52.orig/game.c
++++ netris-0.52/game.c
+@@ -21,6 +21,7 @@
+ #define NOEXT
+ #include "netris.h"
++#include <time.h>
+ #include <stdlib.h>
+ #include <ctype.h>
+ #include <string.h>
+Index: netris-0.52/inet.c
+===================================================================
+--- netris-0.52.orig/inet.c
++++ netris-0.52/inet.c
+@@ -52,7 +52,7 @@ ExtFunc int WaitForConnection(char *port
+       struct sockaddr_in addr;
+       struct hostent *host;
+       int sockListen;
+-      int addrLen;
++      socklen_t addrLen;
+       short port;
+       int val1;
+       struct linger val2;
+Index: netris-0.52/util.c
+===================================================================
+--- netris-0.52.orig/util.c
++++ netris-0.52/util.c
+@@ -20,6 +20,7 @@
+  */
+ #include "netris.h"
++#include <time.h>
+ #include <stdarg.h>
+ #include <stdlib.h>
+ #include <string.h>
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644 (file)
index 0000000..0ebda8e
--- /dev/null
@@ -0,0 +1,8 @@
+01_multi-games-with-scoring
+02_line-count-patch
+03_staircase-effect-fix
+04_robot-close-fixup
+05_init-static-vars
+06_curses.c-include-term.h
+07_curses.c-include-time.h
+08_various-fixes
index 32be2bddc7a91134b2f4ecc3ecefa7db97802f1c..2487d92d0d2010f2f6ede943d2908b8585b237cd 100644 (file)
@@ -1,5 +1,7 @@
 #!/bin/sh -e
 # postinst script for netris
+# copyright 2002++ by Gerfried Fuchs <rhonda@debian.at>
+# Licenced the same way as netris itself
 
 if [ "$1" != configure ]; then
        exit 0
index cc7789d165ec9ef01cf0da248b37195a3e6f8dca..ca83453f7979fd21c52b62ac872dd5624c4f7348 100644 (file)
@@ -1,5 +1,7 @@
 #!/bin/sh -e
 # postrm script for netris
+# copyright 2002++ by Gerfried Fuchs <rhonda@debian.at>
+# Licenced the same way as netris itself
 
 if [ -x /usr/bin/update-menus ]; then
        update-menus
index 3267cbb325f52ca981fed58b37bdf40b4c030083..38168531204b4e0aea0cea353962e0288013e7a5 100755 (executable)
@@ -1,5 +1,7 @@
 #!/usr/bin/make -f
 # rules file for netris
+# copyright 2002++ by Gerfried Fuchs <rhonda@debian.at>
+# Licenced the same way as netris itself
 
 COPT = -g
 INSTALL = install
@@ -18,17 +20,19 @@ ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
 endif
 
 
-clean:
+include /usr/share/quilt/quilt.make
+
+clean: unpatch
        $(checkdir)
        $(checkroot)
        -rm -rf debian/netris debian/substvars debian/files \
                build-stamp install-stamp config.h .depend
-       -$(MAKE) clean
+       [ ! -f Makefile ] || $(MAKE) clean
        -rm -rf Makefile
 
 
 build: build-stamp
-build-stamp:
+build-stamp: patch
        $(checkdir)
        ./Configure -g
        $(MAKE) COPT="$(COPT)"
diff --git a/game.c b/game.c
index e57e7ca802c47ee976181ce22befe4b0d1b39def..b40c12948035f365d4fc7a5a5463bd57c33577dc 100644 (file)
--- a/game.c
+++ b/game.c
 #include <netinet/in.h>
 
 enum { KT_left, KT_rotate, KT_right, KT_drop, KT_down,
-       KT_toggleSpy, KT_pause, KT_faster, KT_redraw, KT_new, KT_numKeys };
+       KT_toggleSpy, KT_pause, KT_faster, KT_redraw, KT_numKeys };
 
 static char *keyNames[KT_numKeys+1] = {
        "Left", "Rotate", "Right", "Drop", "Down", "ToggleSpy", "Pause",
-       "Faster", "Redraw", "New", NULL };
+       "Faster", "Redraw", NULL };
 
 static char *gameNames[GT_len] = { "OnePlayer", "ClassicTwo" };
 
@@ -40,10 +40,6 @@ static char keyTable[KT_numKeys+1];
 static int dropModeEnable = 0;
 static char *robotProg;
 
-static int wonLast = 0;
-int lost = 0, won = 0;
-enum States gameState = STATE_STARTING;
-
 ExtFunc void MapKeys(char *newKeys)
 {
        int i, k, ch;
@@ -103,7 +99,6 @@ ExtFunc void OneGame(int scr, int scr2)
        int key;
        char *p, *cmd;
 
-       myLinesCleared = enemyLinesCleared = 0;
        speed = stepDownInterval;
        ResetBaseTime();
        InitBoard(scr);
@@ -298,15 +293,7 @@ ExtFunc void OneGame(int scr, int scr2)
                                                        DropPiece(scr2);
                                                        break;
                                                case NP_clear:
-                                                       {
-                                                               int cleared = ClearFullLines(scr2);
-                                                               if (cleared) {
-                                                                       enemyLinesCleared += cleared;
-                                                                       enemyTotalLinesCleared += cleared;
-                                                                       ShowDisplayInfo();
-                                                                       RefreshScreen();
-                                                               }
-                                                       }
+                                                       ClearFullLines(scr2);
                                                        break;
                                                case NP_insertJunk:
                                                {
@@ -336,7 +323,6 @@ ExtFunc void OneGame(int scr, int scr2)
                                        break;
                                case E_lostRobot:
                                case E_lostConn:
-                                       wonLast = 1;
                                        goto gameOver;
                                default:
                                        break;
@@ -352,12 +338,7 @@ ExtFunc void OneGame(int scr, int scr2)
        nextPiece:
                dropMode = 0;
                FreezePiece(scr);
-               myLinesCleared += linesCleared = ClearFullLines(scr);           
-               myTotalLinesCleared += linesCleared;
-               if (linesCleared) {
-                       ShowDisplayInfo();
-                       RefreshScreen();
-               }
+               linesCleared = ClearFullLines(scr);
                if (linesCleared > 0 && spied)
                        SendPacket(NP_clear, 0, NULL);
                if (game == GT_classicTwo && linesCleared > 1) {
@@ -369,17 +350,14 @@ ExtFunc void OneGame(int scr, int scr2)
                        SendPacket(NP_giveJunk, sizeof(data), data);
                }
        }
-       wonLast = 0;
-
 gameOver:
        SetITimer(0, 0);
 }
 
 ExtFunc int main(int argc, char **argv)
 {
-       int initConn = 0, waitConn = 0, ch, done = 0;
+       int initConn = 0, waitConn = 0, ch;
        char *hostStr = NULL, *portStr = NULL;
-       MyEvent event;
 
        standoutEnable = colorEnable = 1;
        stepDownInterval = DEFAULT_INTERVAL;
@@ -444,139 +422,112 @@ ExtFunc int main(int argc, char **argv)
        if (fairRobot && !robotEnable)
                fatal("You can't use the -F option without the -r option");
        InitUtil();
-       InitScreens();  
-       while(!done) {
-               if (robotEnable)
-                       InitRobot(robotProg);
-               InitNet();
-               if (!initSeed)
-                       SRandom(time(0));
-               if (initConn || waitConn) {
-                       game = GT_classicTwo;
-                       if(gameState != STATE_STARTING) {
-                               gameState = STATE_WAIT_CONNECTION;
-                               ShowDisplayInfo();
-                               RefreshScreen();
-                       }
-                       if (initConn)
-                               InitiateConnection(hostStr, portStr);
-                       else if (waitConn)
-                               WaitForConnection(portStr);
-                       gameState = STATE_PLAYING;
-                       ShowDisplayInfo();
-                       RefreshScreen();
-                       {
-                               netint4 data[2];
-                               int major;
-                               
-                               data[0] = hton4(MAJOR_VERSION);
-                               data[1] = hton4(PROTOCOL_VERSION);
-                               SendPacket(NP_version, sizeof(data), data);
-                               if (WaitMyEvent(&event, EM_net) != E_net)
-                                       fatal("Network negotiation failed");
-                               memcpy(data, event.u.net.data, sizeof(data));
-                               major = ntoh4(data[0]);
-                               protocolVersion = ntoh4(data[1]);
-                               if (event.u.net.type != NP_version || major < MAJOR_VERSION)
-                                       fatal("Your opponent is using an old, incompatible version\n"
-                                             "of Netris.  They should get the latest version.");
-                               if (major > MAJOR_VERSION)
-                                       fatal("Your opponent is using an newer, incompatible version\n"
-                                             "of Netris.  Get the latest version.");
-                               if (protocolVersion > PROTOCOL_VERSION)
-                                       protocolVersion = PROTOCOL_VERSION;
-                       }
-                       if (protocolVersion < 3 && stepDownInterval != DEFAULT_INTERVAL)
-                               fatal("Your opponent's version of Netris predates the -i option.\n"
-                                     "For fairness, you shouldn't use the -i option either.");
-                       {
-                               netint4 data[3];
-                               int len;
-                               int seed;
-                               
-                               if (protocolVersion >= 3)
-                                       len = sizeof(data);
-                               else
-                                       len = sizeof(netint4[2]);
-                               if ((myFlags & SCF_setSeed))
-                                       seed = initSeed;
-                               else
-                                       seed = time(0);
-                               if (waitConn)
-                                       SRandom(seed);
-                               data[0] = hton4(myFlags);
-                               data[1] = hton4(seed);
-                               data[2] = hton4(stepDownInterval);
-                               SendPacket(NP_startConn, len, data);
-                               if (WaitMyEvent(&event, EM_net) != E_net ||
-                                   event.u.net.type != NP_startConn)
-                                       fatal("Network negotiation failed");
-                               memcpy(data, event.u.net.data, len);
-                               opponentFlags = ntoh4(data[0]);
-                               seed = ntoh4(data[1]);
-                               if (initConn) {
-                                       if ((opponentFlags & SCF_setSeed) != (myFlags & SCF_setSeed))
-                                               fatal("If one player sets the random number seed, "
-                                                     "both must.");
-                                       if ((myFlags & SCF_setSeed) && seed != initSeed)
-                                               fatal("Both players have set the random number seed, "
-                                                     "and they are unequal.");
-                                       if (protocolVersion >= 3 && stepDownInterval != ntoh4(data[2]))
-                                               fatal("Your opponent is using a different step-down "
-                                                     "interval (-i).\nYou must both use the same one.");
-                                       SRandom(seed);
-                               }
-                       }
-                       {
-                               char *userName;
-                               int len, i;
+       if (robotEnable)
+               InitRobot(robotProg);
+       InitNet();
+       InitScreens();
+       if (initConn || waitConn) {
+               MyEvent event;
 
-                               userName = getenv("LOGNAME");
-                               if (!userName || !userName[0])
-                                       userName = getenv("USER");
-                               if (!userName || !userName[0])
-                                       strcpy(userName, "???");
-                               len = strlen(userName)+1;
-                               if (len > sizeof(opponentName))
-                                       len = sizeof(opponentName);
-                               SendPacket(NP_userName, len, userName);
-                               if (WaitMyEvent(&event, EM_net) != E_net ||
-                                   event.u.net.type != NP_userName)
-                                       fatal("Network negotiation failed");
-                               strncpy(opponentName, event.u.net.data,
-                                       sizeof(opponentName)-1);
-                               opponentName[sizeof(opponentName)-1] = 0;
-                               for (i = 0; opponentName[i]; ++i)
-                                       if (!isprint(opponentName[i]))
-                                               opponentName[i] = '?';
-                               for (i = 0; opponentHost[i]; ++i)
-                                       if (!isprint(opponentHost[i]))
-                                               opponentHost[i] = '?';
-                       }
-                       OneGame(0, 1);
-               }
-               else {
-                       game = GT_onePlayer;
-                       OneGame(0, -1);
+               game = GT_classicTwo;
+               if (initConn)
+                       InitiateConnection(hostStr, portStr);
+               else if (waitConn)
+                       WaitForConnection(portStr);
+               {
+                       netint4 data[2];
+                       int major;
+
+                       data[0] = hton4(MAJOR_VERSION);
+                       data[1] = hton4(PROTOCOL_VERSION);
+                       SendPacket(NP_version, sizeof(data), data);
+                       if (WaitMyEvent(&event, EM_net) != E_net)
+                               fatal("Network negotiation failed");
+                       memcpy(data, event.u.net.data, sizeof(data));
+                       major = ntoh4(data[0]);
+                       protocolVersion = ntoh4(data[1]);
+                       if (event.u.net.type != NP_version || major < MAJOR_VERSION)
+                               fatal("Your opponent is using an old, incompatible version\n"
+                                       "of Netris.  They should get the latest version.");
+                       if (major > MAJOR_VERSION)
+                               fatal("Your opponent is using an newer, incompatible version\n"
+                                       "of Netris.  Get the latest version.");
+                       if (protocolVersion > PROTOCOL_VERSION)
+                               protocolVersion = PROTOCOL_VERSION;
                }
-               if (wonLast) {
-                       won++;
-               } else {
-                       lost++;
-                       WaitMyEvent(&event, EM_net);
+               if (protocolVersion < 3 && stepDownInterval != DEFAULT_INTERVAL)
+                       fatal("Your opponent's version of Netris predates the -i option.\n"
+                                       "For fairness, you shouldn't use the -i option either.");
+               {
+                       netint4 data[3];
+                       int len;
+                       int seed;
+
+                       if (protocolVersion >= 3)
+                               len = sizeof(data);
+                       else
+                               len = sizeof(netint4[2]);
+                       if ((myFlags & SCF_setSeed))
+                               seed = initSeed;
+                       else
+                               seed = time(0);
+                       if (waitConn)
+                               SRandom(seed);
+                       data[0] = hton4(myFlags);
+                       data[1] = hton4(seed);
+                       data[2] = hton4(stepDownInterval);
+                       SendPacket(NP_startConn, len, data);
+                       if (WaitMyEvent(&event, EM_net) != E_net ||
+                                       event.u.net.type != NP_startConn)
+                               fatal("Network negotiation failed");
+                       memcpy(data, event.u.net.data, len);
+                       opponentFlags = ntoh4(data[0]);
+                       seed = ntoh4(data[1]);
+                       if (initConn) {
+                               if ((opponentFlags & SCF_setSeed) != (myFlags & SCF_setSeed))
+                                       fatal("If one player sets the random number seed, "
+                                                       "both must.");
+                               if ((myFlags & SCF_setSeed) && seed != initSeed)
+                                       fatal("Both players have set the random number seed, "
+                                                       "and they are unequal.");
+                               if (protocolVersion >= 3 && stepDownInterval != ntoh4(data[2]))
+                                       fatal("Your opponent is using a different step-down "
+                                               "interval (-i).\nYou must both use the same one.");
+                               SRandom(seed);
+                       }
                }
-               CloseNet();
-               if (robotEnable) {
-                       CloseRobot();
-               } else {
-                       gameState = STATE_WAIT_KEYPRESS;
-                       ShowDisplayInfo();
-                       RefreshScreen();
-                       while(getchar() != keyTable[KT_new])
-                               ;
+               {
+                       char *userName;
+                       int len, i;
+
+                       userName = getenv("LOGNAME");
+                       if (!userName || !userName[0])
+                               userName = getenv("USER");
+                       if (!userName || !userName[0])
+                               strcpy(userName, "???");
+                       len = strlen(userName)+1;
+                       if (len > sizeof(opponentName))
+                               len = sizeof(opponentName);
+                       SendPacket(NP_userName, len, userName);
+                       if (WaitMyEvent(&event, EM_net) != E_net ||
+                                       event.u.net.type != NP_userName)
+                               fatal("Network negotiation failed");
+                       strncpy(opponentName, event.u.net.data,
+                               sizeof(opponentName)-1);
+                       opponentName[sizeof(opponentName)-1] = 0;
+                       for (i = 0; opponentName[i]; ++i)
+                               if (!isprint(opponentName[i]))
+                                       opponentName[i] = '?';
+                       for (i = 0; opponentHost[i]; ++i)
+                               if (!isprint(opponentHost[i]))
+                                       opponentHost[i] = '?';
                }
+               OneGame(0, 1);
+       }
+       else {
+               game = GT_onePlayer;
+               OneGame(0, -1);
        }
-
        return 0;
 }
 
diff --git a/inet.c b/inet.c
index 068cb8915cf1249a64a0dc3540b88b09e6ae4ce0..a8d9a9d9149c9b67e3c05516d1b040f970cad8f1 100644 (file)
--- a/inet.c
+++ b/inet.c
@@ -42,8 +42,6 @@ static int isServer, lostConn, gotEndConn;
 
 ExtFunc void InitNet(void)
 {
-       lostConn = 0;
-       gotEndConn = 0;
        AtExit(CloseNet);
 }
 
index db746e5341e23bd5060dbe19ca3082e4c1d1c1dc..45d61bf1764f9ab2d32e1181e6ba2c44bb0670cb 100644 (file)
--- a/netris.h
+++ b/netris.h
@@ -65,7 +65,7 @@ typedef long netint4;
 
 #define DEFAULT_PORT 9284      /* Very arbitrary */
 
-#define DEFAULT_KEYS "jkl mspf^ln"
+#define DEFAULT_KEYS "jkl mspf^l"
 
 /* Protocol versions */
 #define MAJOR_VERSION          1       
@@ -152,13 +152,6 @@ typedef struct _ShapeOption {
 typedef int (*ShapeDrawFunc)(int scr, int y, int x,
                                        BlockType type, void *data);
 
-enum States {
-       STATE_STARTING,
-       STATE_PLAYING,
-       STATE_WAIT_CONNECTION,
-       STATE_WAIT_KEYPRESS
-};
-
 EXT GameType game;
 EXT int boardHeight[MAX_SCREENS];
 EXT int boardVisible[MAX_SCREENS], boardWidth[MAX_SCREENS];
@@ -174,19 +167,11 @@ EXT long stepDownInterval, speed;
 
 EXT int myFlags, opponentFlags;
 
-EXT int won, lost;
-EXT enum States gameState;
-
 EXT char scratch[1024];
 
 extern ShapeOption stdOptions[];
 extern char *version_string;
 
-EXT int myLinesCleared;
-EXT int enemyLinesCleared;
-EXT int myTotalLinesCleared;
-EXT int enemyTotalLinesCleared;
-
 #include "proto.h"
 
 #endif /* NETRIS_H */
diff --git a/robot.c b/robot.c
index cbd5cb22902a0a8cf91f9ea54e1584b20d2e869d..23875a3bd4b9984bf0c1815e95e7970c5f8318e2 100644 (file)
--- a/robot.c
+++ b/robot.c
@@ -35,7 +35,7 @@ static EventGenRec robotGen =
                { NULL, 0, FT_read, -1, RobotGenFunc, EM_robot };
 
 static int robotProcess;
-static FILE *toRobot = NULL;
+static FILE *toRobot;
 static int toRobotFd, fromRobotFd;
 
 static char robotBuf[128];
@@ -112,13 +112,10 @@ ExtFunc void RobotTimeStamp(void)
 ExtFunc void CloseRobot(void)
 {
        RemoveEventGen(&robotGen);
-       if(toRobot) {
-               if (robotProcess > 0)
-                       RobotCmd(1, "Exit\n");
-               fclose(toRobot);
-               close(fromRobotFd);
-               toRobot = NULL;
-       }
+       if (robotProcess > 0)
+               RobotCmd(1, "Exit\n");
+       fclose(toRobot);
+       close(fromRobotFd);
 }
 
 static MyEventType RobotGenFunc(EventGenRec *gen, MyEvent *event)
diff --git a/util.c b/util.c
index 1fcae892547acfebc98d20556955c4c57ab7a2b0..cb7f4211dc1d2cd966da27f97ebfaca5e3e6422b 100644 (file)
--- a/util.c
+++ b/util.c
@@ -74,7 +74,7 @@ ExtFunc void Usage(void)
          "  -p <port>  Set port number (default is %d)\n"
          "  -k <keys>  Remap keys.  The argument is a prefix of the string\n"
          "               containing the keys in order: left, rotate, right, drop,\n"
-         "               down-faster, toggle-spying, pause, faster, redraw, new.\n"
+         "               down-faster, toggle-spying, pause, faster, redraw.\n"
          "               \"^\" prefixes controls.  (default is \"%s\")\n"
          "  -i <sec>   Set the step-down interval, in seconds\n"
          "  -r <robot> Execute <robot> (a command) as a robot controlling\n"
@@ -267,7 +267,6 @@ ExtFunc volatile void die(char *msg)
 
 ExtFunc volatile void fatal(char *msg)
 {
-       CleanupScreens ();
        fprintf(stderr, "%s\n", msg);
        exit(1);
 }