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.
19 * $Id: netris.h,v 1.28 1999/05/16 06:56:29 mhw Exp $
32 #define version_string "0.8"
34 #ifdef NOEXT //prevent re-declaration
40 #ifdef HAS_SIGPROCMASK
41 typedef sigset_t MySigSet;
47 * The following definitions are to ensure network compatibility even if
48 * the sizes of ints and shorts are different. I'm not sure exactly how
49 * to deal with this problem, so I've added an abstraction layer.
52 typedef short netint2;
55 #define hton2(x) htons(x)
56 #define hton4(x) htonl(x)
57 #define ntoh2(x) ntohs(x)
58 #define ntoh4(x) ntohl(x)
60 /* Protocol versions */
61 #define MAJOR_VERSION 1
62 #define PROTOCOL_VERSION 4
64 #define DEFAULT_PORT 9284 /* Very arbitrary */
66 #define CONFIG_FILE "netris.conf"
68 //#define DEFAULT_KEYS "hlkj mfp^lq"
69 //#define DEFAULT_KEYS "4685 2fp^lq"
70 #define DEFAULT_KEYS "dcaf b^fp^lq"
72 #define MAX_BOARD_WIDTH 32
73 #define MAX_BOARD_HEIGHT 64
74 #define MAX_SCREENS 9 //8 players
77 #define EM_alarm 000001
80 #define EM_connect 000020
83 typedef enum _GameType { GT_onePlayer, GT_classicTwo, GT_len } GameType;
84 typedef enum _BlockTypeA {
86 BT_green, BT_cyan, BT_blue, BT_magenta, BT_red, BT_yellow, BT_white,
89 typedef enum _Dir { D_down, D_right, D_up, D_left } Dir;
90 typedef enum _Cmd { C_end, C_forw, C_back, C_left, C_right, C_plot } Cmd;
91 typedef enum _FDType { FT_read, FT_write, FT_except, FT_len } FDType;
92 typedef enum _MyEventType {
93 E_none, E_alarm, E_key, E_connect, E_net, E_lostConn
95 typedef enum _NetPacketType {
96 NP_endConn, //client/server quits
97 NP_byeBye, //unused atm
98 NP_error, //handshake error
99 NP_hello, //check versions
100 NP_gamedata, //game options
102 NP_start, //game ok to start
103 NP_pause, //player (un)pauses
104 NP_stop, //game ended
105 NP_newPlayer, //add new player
106 NP_team, //player switched teams
107 NP_argghhh, //player died
108 NP_part, //player left
110 NP_msg, //chat message
112 NP_newPiece, //new piece info
113 NP_rotright, //rotate piece clockwise
114 NP_rotleft, //rotate piece counterclockwise
115 NP_left, //move piece left
116 NP_right, //move piece right
117 NP_down, //move piece one down
118 NP_drop, //drop piece to bottom
119 NP_clear, //line cleared
120 NP_insertJunk, //player added junk
122 NP_giveJunk //player has to add junk
131 typedef struct _MyEvent {
144 typedef MyEventType (*EventGenFunc)(struct _EventGenRec *gen, MyEvent *event);
146 typedef struct _EventGenRec {
147 struct _EventGenRec *next;
155 int bufSize, bufGoal;
158 MyEventType NetGenFunc(EventGenRec *gen, MyEvent *event);
160 typedef struct _Shape {
164 /* NP_startConn flags */
173 int boardHeight, boardWidth, boardVisible;
175 char curShape, nextShape;
179 int pieces, lines, adds;
181 char host[256]; //last
183 EXT _Player Players[MAX_SCREENS];
186 EXT int spied; //in player.flags
188 #define DEFAULT_INTERVAL 1000000 /* Step-down interval in microseconds */
190 #define SPEEDMINIMUM 40000
202 #define MSG_WIDTH 128
204 EXT GameType game; // => Game.type
206 EXT short port; // => just in game.c, parameter to inet connect