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;
*/
#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>
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 */
#endif
AtExit(CleanupScreens);
- screens_dirty = 1;
RestoreSignals(NULL, &oldMask);
cbreak();
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)
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('|');
}
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();
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
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
+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)
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
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/
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.
-?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"
.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
.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.
.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>.
--- /dev/null
+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;
--- /dev/null
+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 */
--- /dev/null
+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)
--- /dev/null
+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)
--- /dev/null
+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);
+ }
+
--- /dev/null
+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>
--- /dev/null
+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>
--- /dev/null
+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>
--- /dev/null
+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
#!/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
#!/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
#!/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
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)"
#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" };
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;
int key;
char *p, *cmd;
- myLinesCleared = enemyLinesCleared = 0;
speed = stepDownInterval;
ResetBaseTime();
InitBoard(scr);
DropPiece(scr2);
break;
case NP_clear:
- {
- int cleared = ClearFullLines(scr2);
- if (cleared) {
- enemyLinesCleared += cleared;
- enemyTotalLinesCleared += cleared;
- ShowDisplayInfo();
- RefreshScreen();
- }
- }
+ ClearFullLines(scr2);
break;
case NP_insertJunk:
{
break;
case E_lostRobot:
case E_lostConn:
- wonLast = 1;
goto gameOver;
default:
break;
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) {
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;
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;
}
ExtFunc void InitNet(void)
{
- lostConn = 0;
- gotEndConn = 0;
AtExit(CloseNet);
}
#define DEFAULT_PORT 9284 /* Very arbitrary */
-#define DEFAULT_KEYS "jkl mspf^ln"
+#define DEFAULT_KEYS "jkl mspf^l"
/* Protocol versions */
#define MAJOR_VERSION 1
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];
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 */
{ 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];
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)
" -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"
ExtFunc volatile void fatal(char *msg)
{
- CleanupScreens ();
fprintf(stderr, "%s\n", msg);
exit(1);
}