2 * Netris -- A free networked version of T*tris
3 * Copyright (C) 1994-1996,1999 Mark H. Weaver <mhw@netris.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #define version_string "0.8"
32 #ifdef NOEXT //prevent re-declaration
38 #ifdef HAS_SIGPROCMASK
39 typedef sigset_t MySigSet;
45 * The following definitions are to ensure network compatibility even if
46 * the sizes of ints and shorts are different. I'm not sure exactly how
47 * to deal with this problem, so I've added an abstraction layer.
50 typedef short netint2;
53 #define hton2(x) htons(x)
54 #define hton4(x) htonl(x)
55 #define ntoh2(x) ntohs(x)
56 #define ntoh4(x) ntohl(x)
58 /* Protocol versions */
59 #define MAJOR_VERSION 1
60 #define PROTOCOL_VERSION 4
62 #define DEFAULT_PORT 9284 /* Very arbitrary */
64 #define CONFIG_FILE "netris.conf"
66 //#define DEFAULT_KEYS "hlkj mfp^ltq"
67 //#define DEFAULT_KEYS "4685 2fp^l^mq"
68 #define DEFAULT_KEYS "dcaf b^fp^l^mq"
70 #define MAX_BOARD_WIDTH 32
71 #define MAX_BOARD_HEIGHT 64
72 #define MAX_SCREENS 9 //8 players
75 #define EM_alarm 000001
78 #define EM_connect 000020
81 typedef enum _GameType { GT_onePlayer, GT_classicTwo, GT_len } GameType;
82 typedef enum _BlockTypeA {
84 BT_S, BT_L, BT_I, BT_O, BT_Z, BT_J, BT_T,
87 typedef enum _FDType { FT_read, FT_write, FT_except, FT_len } FDType;
88 typedef enum _MyEventType {
89 E_none, E_alarm, E_key, E_connect, E_net, E_lostConn
91 typedef enum _NetPacketType {
92 NP_endConn, //client/server quits
93 NP_byeBye, //unused atm
94 NP_error, //handshake error
95 NP_hello, //check versions
96 NP_gamedata, //game options
98 NP_start, //game ok to start
99 NP_pause, //player (un)pauses
100 NP_stop, //game ended
101 NP_newPlayer, //add new player
102 NP_team, //player switched teams
103 NP_argghhh, //player died
104 NP_part, //player left
106 NP_msg, //chat message
108 NP_newPiece, //new piece info
109 NP_rotright, //rotate piece clockwise
110 NP_rotleft, //rotate piece counterclockwise
111 NP_left, //move piece left
112 NP_right, //move piece right
113 NP_down, //move piece one down
114 NP_drop, //drop piece to bottom
115 NP_clear, //line cleared
116 NP_insertJunk, //player added junk
118 NP_giveJunk //player has to add junk
127 typedef struct _MyEvent {
140 typedef MyEventType (*EventGenFunc)(struct _EventGenRec *gen, MyEvent *event);
142 typedef struct _EventGenRec {
143 struct _EventGenRec *next;
151 int bufSize, bufGoal;
154 MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event);
156 /* NP_startConn flags */
165 int boardHeight, boardWidth, boardVisible;
167 char curShape, nextShape;
171 int pieces, lines, adds;
173 char host[256]; //last
175 EXT _Player Players[MAX_SCREENS];
178 EXT int spied; //in player.flags
180 #define DEFAULT_INTERVAL 1000000 /* Step-down interval in microseconds */
182 #define SPEEDMINIMUM 40000
194 #define MSG_WIDTH 128
196 EXT GameType game; // => Game.type
198 EXT short port; // => just in game.c, parameter to inet connect