]> icculus.org git repositories - taylor/freespace2.git/blob - include/gtrack.h
add basic support for getting though firewalls
[taylor/freespace2.git] / include / gtrack.h
1 /*
2  * Copyright (C) Volition, Inc. 2005.  All rights reserved.
3  * 
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on the 
6  * source.
7  *
8 */
9
10 #ifndef _gtrack_header
11 #define _gtrack_header
12
13 //Game Tracker client code header
14
15 #ifdef MAKE_FS1
16 #define GAMEPORT        3440
17 #else
18 #define GAMEPORT        7802
19 #endif
20
21 #define MAX_NET_RETRIES 30
22 #define NET_ACK_TIMEOUT 2500
23 #define NET_GAME_TIMEOUT 300                    //time in seconds
24
25 #ifndef MAKE_FS1
26 #define MAX_GAME_DATA_SIZE      500
27 #else
28 #define MAX_GAME_DATA_SIZE      700
29 #endif
30
31 #define MAX_GENERIC_GAME_NAME_LEN       32
32
33 #define MAX_GAME_LISTS_PER_PACKET       10
34
35 #define CHANNEL_LEN     33
36
37 #define MAX_FREESPACE_PLAYERS   16
38 #define MAX_FREESPACE_PLAYER_NAME_LEN   32
39 #define MAX_FREESPACE_MISSION_NAME_LEN  32
40 #define MAX_FREESPACE_PLAYERS   16
41
42 #define GNT_SERVER_ACK                  0
43 #define GNT_CLIENT_ACK                  1
44 #define GNT_GAMESTARTED         2
45 #define GNT_GAMEOVER                    3
46 #define GNT_GAMEUPDATE                  4
47 #define GNT_GAMELIST_REQ                5
48 #define GNT_GAMELIST_DATA               6
49 #define GNT_GAME_COUNT_REQ      7
50 #define GNT_GAME_COUNT_DATA     8
51 #define GNT_PEER_PING                   9
52
53 #define GT_FREESPACE                    1
54 #define GT_DESCENT3                             2
55 #define GT_TUBERACER                    3
56 #define GT_FREESPACE2                   4
57 #define GT_UNUSED                               0
58
59 #ifndef MAKE_FS1
60 #define GAME_HEADER_ONLY_SIZE           (sizeof(game_packet_header)-MAX_GAME_DATA_SIZE)
61 #else
62 // header struct not packed in FS1, add 3 bytes padding
63 #define GAME_HEADER_ONLY_SIZE           (sizeof(game_packet_header)-MAX_GAME_DATA_SIZE+3)
64 #endif
65
66 #pragma pack(push, 1)
67         typedef struct {
68                 unsigned int len;                               //Length of entire packet;
69                 unsigned char game_type;        //1==freespace (GT_FREESPACE), 2==D3, 3==tuberacer, etc.
70                 char junk[16];                          // not used but need constant size for compatibility (SOCKADDR_IN       addr);
71                 int     type;   //Used to specify what to do ie. Add a new net game (GNT_GAMESTARTED), remove a net game (game over), etc.
72                 unsigned int    sig;    //Unique identifier for client ACKs (The server always fills this in, the client responds)
73
74                 char data[MAX_GAME_DATA_SIZE];
75         } game_packet_header;
76 #pragma pack(pop)
77
78 #ifdef MAKE_FS1
79
80 typedef struct {
81         char    game_name[MAX_GENERIC_GAME_NAME_LEN];
82         int     difficulty;
83         int     type;                   //game type;
84         int     state;
85         int     max_players;
86         int     current_num_players;
87         char    mission_name[MAX_FREESPACE_MISSION_NAME_LEN];
88 //      char    mission_file[MAX_FREESPACE_MISSION_FILE_LEN];
89 //      char    mission_url[MAX_FREESPACE_MISSION_URL_LEN];
90         char    players[MAX_FREESPACE_PLAYERS][MAX_FREESPACE_PLAYER_NAME_LEN];
91         int     player_rank[MAX_FREESPACE_PLAYERS];
92         char    channel[CHANNEL_LEN];
93         char    pad[3];         // 3-byte padding for size/alignment
94 } freespace_net_game_data;
95
96 #define pxo_net_game_data freespace_net_game_data
97
98 #else
99
100 typedef struct {
101         char    game_name[MAX_GENERIC_GAME_NAME_LEN];
102         int     difficulty;
103         int     type;                   //game type;
104         int     state;
105         int     max_players;
106         int     current_num_players;
107         char    mission_name[MAX_FREESPACE_MISSION_NAME_LEN];
108         char    channel[CHANNEL_LEN];
109         char    pad[3];         // 3-byte padding for size/alignment
110 } freespace2_net_game_data;
111
112 #define pxo_net_game_data freespace2_net_game_data
113
114 #endif
115
116 typedef struct _active_games{
117         int game_type; //ie. GT_FREESPACE GT_DESCENT3, etc.
118         struct sockaddr addr;
119         unsigned int last_update;       //Time we last got an update from this game
120         char    data[MAX_GAME_DATA_SIZE]; //memory to hold the game specific data
121         _active_games *next;
122 } active_games;
123
124 typedef struct {
125         unsigned char game_type;
126         char game_name[MAX_GAME_LISTS_PER_PACKET][MAX_GENERIC_GAME_NAME_LEN];
127         char pad[3];    // ..needs 3-byte padding here for alignment..
128         unsigned int    game_server[MAX_GAME_LISTS_PER_PACKET];
129         unsigned short port[MAX_GAME_LISTS_PER_PACKET];
130 } game_list;
131
132 typedef struct {
133         int     rank;                                                           // Try to find opponents with a rank similar to this
134         char channel[CHANNEL_LEN];                      // only give us games in this channel   
135         char pad[3];                                    // 3-bytes padding for size/alignment
136 } filter_game_list_struct;
137
138
139 //Function prototypes
140
141 int InitGameTrackerClient(int gametype);
142 void IdleGameTracker();
143 void UpdateGameData(void *buffer);
144 game_list * GetGameList();
145 void RequestGameList();
146 void RequestGameListWithFilter(void *filter);
147 void RequestGameCountWithFilter(void *filter);
148
149 // void SendGameOver();
150 //Start New 7-9-98
151 int SendGameOver();
152 //End New 7-9-98
153
154 void StartTrackerGame(void *buffer);
155
156 void AckPacket(int sig);
157
158 //Definitions
159 #define MAX_GAME_BUFFERS        20                                      //Thats a lot considering 20 games per game_list struct
160
161 #define TRACKER_UPDATE_INTERVAL                 300             //300 seconds
162 #define TRACKER_RESEND_TIME                             2000            //2000ms
163
164
165 #endif