d1x->d2x
[btb/d2x.git] / main / network.h
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  * $Source: /cvs/cvsroot/d2x/main/network.h,v $
16  * $Revision: 1.6 $
17  * $Author: bradleyb $
18  * $Date: 2002-02-14 09:24:19 $
19  *
20  * FIXME: put description here
21  *
22  * $Log: not supported by cvs2svn $
23  * Revision 1.5  2002/02/13 10:39:22  bradleyb
24  * Lotsa networking stuff from d1x
25  *
26  * Revision 1.4  2001/10/25 02:15:57  bradleyb
27  * conditionalize including multi.h and network.h, fix backslashes
28  *
29  *
30  */
31
32 #ifndef _NETWORK_H
33 #define _NETWORK_H
34
35 #include "gameseq.h"
36 #include "multi.h"
37 #include "newmenu.h"
38
39 #define NETSTAT_MENU                                    0
40 #define NETSTAT_PLAYING                         1
41 #define NETSTAT_BROWSING                        2
42 #define NETSTAT_WAITING                         3
43 #define NETSTAT_STARTING                        4
44 #define NETSTAT_ENDLEVEL                        5
45
46 #define CONNECT_DISCONNECTED            0
47 #define CONNECT_PLAYING                         1
48 #define CONNECT_WAITING                         2
49 #define CONNECT_DIED_IN_MINE            3
50 #define CONNECT_FOUND_SECRET            4
51 #define CONNECT_ESCAPE_TUNNEL           5
52 #define CONNECT_END_MENU                        6
53
54 #define MAX_ACTIVE_NETGAMES                     12
55
56 #define NETGAMEIPX                              1
57 #define NETGAMETCP                              2
58
59 // defines and other things for appletalk/ipx games on mac
60
61 #define IPX_GAME                1
62 #define APPLETALK_GAME  2
63 #ifdef MACINTOSH
64 extern int Network_game_type;
65 #else
66 #define Network_game_type IPX_GAME
67 #endif
68
69 typedef struct sequence_packet {
70         ubyte                                   type;
71         int                                     Security;
72    ubyte pad1[3];
73         netplayer_info          player;
74 } __pack__ sequence_packet;
75
76 #define NET_XDATA_SIZE 454
77
78
79 // frame info is aligned -- 01/18/96 -- MWA
80 // if you change this structure -- be sure to keep
81 // alignment:
82 //              bytes on byte boundries
83 //              shorts on even byte boundries
84 //              ints on even byte boundries
85
86 typedef struct frame_info {
87         ubyte                           type;                                           // What type of packet
88         ubyte                           pad[3];                                 // Pad out length of frame_info packet
89         int                             numpackets;                     
90         vms_vector              obj_pos;
91         vms_matrix              obj_orient;
92         vms_vector              phys_velocity;
93         vms_vector              phys_rotvel;
94         short                           obj_segnum;
95         ushort                  data_size;              // Size of data appended to the net packet
96         ubyte                           playernum;
97         ubyte                           obj_render_type;
98         ubyte                           level_num;
99         ubyte                           data[NET_XDATA_SIZE];           // extra data to be tacked on the end
100 } __pack__ frame_info;
101
102 // short_frame_info is not aligned -- 01/18/96 -- MWA
103 // won't align because of shortpos.  Shortpos needs
104 // to stay in current form.
105
106 typedef struct short_frame_info {
107         ubyte                           type;                                           // What type of packet
108         ubyte                           pad[3];                                 // Pad out length of frame_info packet
109         int                             numpackets;                     
110         shortpos                        thepos;
111         ushort                  data_size;              // Size of data appended to the net packet
112         ubyte                           playernum;
113         ubyte                           obj_render_type;
114         ubyte                           level_num;
115         ubyte                           data[NET_XDATA_SIZE];           // extra data to be tacked on the end
116 } __pack__ short_frame_info;
117
118 void network_start_game();
119 void network_join_game();
120 void network_rejoin_game();
121 void network_leave_game();
122 int network_endlevel(int *secret);
123 void network_endlevel_poll2( int nitems, struct newmenu_item * menus, int * key, int citem );
124
125 int network_level_sync();
126 void network_send_endlevel_packet();
127
128 int network_delete_extra_objects();
129 int network_find_max_net_players();
130 int network_objnum_is_past(int objnum);
131 char * network_get_player_name( int objnum );
132 void network_send_endlevel_sub(int player_num);
133
134 void network_disconnect_player(int playernum);
135
136 extern int NetGameType;
137 extern int Network_send_objects;
138 extern int Network_send_objnum;
139 extern int PacketUrgent;
140 extern int Network_rejoined;
141
142 extern int Network_new_game;
143 extern int Network_status;
144
145 extern fix LastPacketTime[MAX_PLAYERS];
146
147 extern ushort my_segments_checksum;
148
149 extern int Network_initial_pps;
150 extern int Network_initial_shortpackets;
151
152 // By putting an up-to-20-char-message into Network_message and 
153 // setting Network_message_reciever to the player num you want to
154 // send it to (100 for broadcast) the next frame the player will
155 // get your message.
156
157 // Call once at the beginning of a frame
158 void network_do_frame(int force, int listen);
159
160 // Tacks data of length 'len' onto the end of the next
161 // packet that we're transmitting.
162 void network_send_data( ubyte * ptr, int len, int urgent );
163
164 void network_send_objects(void);
165 void network_dump_player(ubyte * server, ubyte *node, int why);
166 void network_send_game_info(sequence_packet *their);
167
168 int GetMyNetRanking();
169 int HoardEquipped();
170
171 #define PID_LITE_INFO                           43
172 #define PID_SEND_ALL_GAMEINFO                   44
173 #define PID_PLAYERSINFO                         45
174 #define PID_REQUEST                             46
175 #define PID_SYNC                                47
176 #define PID_PDATA                               48
177 #define PID_ADDPLAYER                           49
178 #define PID_DUMP                                51
179 #define PID_ENDLEVEL                            52
180 #define PID_QUIT_JOINING                        54
181 #define PID_OBJECT_DATA                         55
182 #define PID_GAME_LIST                           56
183 #define PID_GAME_INFO                           57
184 #define PID_PING_SEND                           58
185 #define PID_PING_RETURN                         59
186 #define PID_GAME_UPDATE                         60
187 #define PID_ENDLEVEL_SHORT                      61
188 #define PID_NAKED_PDATA                         62
189 #define PID_GAME_PLAYERS                        63
190 #define PID_NAMES_RETURN                        64
191
192 #define PID_SHORTPDATA                          42
193 #define PID_D2X_GAME_INFO_REQ                   65
194 #define PID_D2X_GAME_LITE                       68
195 #define PID_PDATA_SHORT2                        70
196
197 #define NETGAME_ANARCHY                         0
198 #define NETGAME_TEAM_ANARCHY                    1
199 #define NETGAME_ROBOT_ANARCHY                   2
200 #define NETGAME_COOPERATIVE                     3
201 #define NETGAME_CAPTURE_FLAG                    4
202 #define NETGAME_HOARD                           5
203 #define NETGAME_TEAM_HOARD                      6
204
205 typedef struct endlevel_info {
206         ubyte                                   type;
207         ubyte                                   player_num;
208         byte                                    connected;
209         ubyte                                   seconds_left;
210         short                                   kill_matrix[MAX_PLAYERS][MAX_PLAYERS];
211         short                                   kills;
212         short                                   killed;
213 } __pack__ endlevel_info;
214
215 #endif