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