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 mnfp^ltq"
67 //#define DEFAULT_KEYS "4685 02fp^l^mq"
68 #define DEFAULT_KEYS "dcaf xb^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 _BlockTypeA {
83 BT_S, BT_L, BT_I, BT_O, BT_Z, BT_J, BT_T,
86 typedef enum _FDType { FT_read, FT_write, FT_except, FT_len } FDType;
87 typedef enum _MyEventType {
88 E_none, E_alarm, E_key, E_connect, E_net, E_lostConn
90 typedef enum _NetPacketType {
91 NP_endConn, //client/server quits
92 NP_byeBye, //unused atm
93 NP_error, //handshake error
94 NP_hello, //check versions
95 NP_gamedata, //game options
97 NP_start, //game ok to start
98 NP_pause, //player (un)pauses
100 NP_newPlayer, //add new player
101 NP_team, //player switched teams
102 NP_argghhh, //player died
103 NP_part, //player left
105 NP_msg, //chat message
107 NP_newPiece, //new piece info
108 NP_rotright, //rotate piece clockwise
109 NP_rotleft, //rotate piece counterclockwise
110 NP_left, //move piece left
111 NP_right, //move piece right
112 NP_down, //move piece one down
113 NP_drop, //drop piece to bottom
114 NP_clear, //line cleared
115 NP_insertJunk, //player added junk
117 NP_giveJunk //player has to add junk
126 typedef struct _MyEvent {
135 typedef MyEventType (*EventGenFunc)(struct _EventGenRec *gen, MyEvent *event);
137 typedef struct _EventGenRec {
138 struct _EventGenRec *next;
146 int bufSize, bufGoal;
149 MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event);
151 /* NP_startConn flags */
159 int boardHeight, boardWidth, boardVisible;
161 char curShape, nextShape;
165 int pieces, lines, adds;
167 char host[256]; //last
169 EXT _Player Players[MAX_SCREENS];
172 EXT int spied; //in player.flags
174 #define DEFAULT_INTERVAL 1000000 /* Step-down interval in microseconds */
176 #define SPEEDMINIMUM 40000
178 typedef enum _GameType { GT_onePlayer, GT_classicTwo, GT_len } GameType;
190 #define MSG_WIDTH 128
192 EXT short port; // => just in client.c, parameter to inet connect
194 static const char *teamname[] = {
195 "", "Green", "Cyan", "Blue", "Purple",
196 "Red", "Grey", "White", "*Orange"