1 /* 2 * Copyright (C) 1998 Mark Baysinger (mbaysing@ucsd.edu) 3 * Copyright (C) 1998,1999,2000,2001 Ross Combs (rocombs@cs.nmsu.edu) 4 * 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. 9 * 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. 14 * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 */ 19 #ifndef INCLUDED_GAME_TYPES 20 #define INCLUDED_GAME_TYPES 21 22 #ifdef GAME_INTERNAL_ACCESS 23 24 #ifdef JUST_NEED_TYPES 25 # ifdef TIME_WITH_SYS_TIME 26 # include <sys/time.h> 27 # include <time.h> 28 # else 29 # ifdef HAVE_SYS_TIME_H 30 # include <sys/time.h> 31 # else 32 # include <time.h> 33 # endif 34 # endif 35 # include "account.h" 36 # include "connection.h" 37 # include "common/tag.h" 38 # include "common/elist.h" 39 #else 40 # define JUST_NEED_TYPES 41 # ifdef TIME_WITH_SYS_TIME 42 # include <sys/time.h> 43 # include <time.h> 44 # else 45 # ifdef HAVE_SYS_TIME_H 46 # include <sys/time.h> 47 # else 48 # include <time.h> 49 # endif 50 # endif 51 # include "account.h" 52 # include "connection.h" 53 # include "common/tag.h" 54 # include "common/elist.h" 55 # undef JUST_NEED_TYPES 56 #endif 57 58 #endif 59 60 typedef enum 61 { 62 game_type_none, 63 game_type_all, 64 game_type_topvbot, 65 game_type_melee, 66 game_type_ffa, 67 game_type_oneonone, 68 game_type_ctf, 69 game_type_greed, 70 game_type_slaughter, 71 game_type_sdeath, 72 game_type_ladder, 73 game_type_ironman, 74 game_type_mapset, 75 game_type_teammelee, 76 game_type_teamffa, 77 game_type_teamctf, 78 game_type_pgl, 79 game_type_diablo, 80 game_type_diablo2open, 81 game_type_diablo2closed, 82 game_type_anongame 83 } t_game_type; 84 85 typedef enum 86 { 87 game_status_started, 88 game_status_full, 89 game_status_open, 90 game_status_done, 91 game_status_loaded 92 } t_game_status; 93 94 typedef enum 95 { 96 game_result_none, 97 game_result_win, 98 game_result_loss, 99 game_result_draw, 100 game_result_disconnect, 101 game_result_observer, 102 game_result_playing 103 } t_game_result; 104 105 typedef enum 106 { 107 game_option_none, 108 game_option_melee_normal, 109 game_option_ffa_normal, 110 game_option_oneonone_normal, 111 game_option_ctf_normal, 112 game_option_greed_10000, 113 game_option_greed_7500, 114 game_option_greed_5000, 115 game_option_greed_2500, 116 game_option_slaughter_60, 117 game_option_slaughter_45, 118 game_option_slaughter_30, 119 game_option_slaughter_15, 120 game_option_sdeath_normal, 121 game_option_ladder_countasloss, 122 game_option_ladder_nopenalty, 123 game_option_mapset_normal, 124 game_option_teammelee_4, 125 game_option_teammelee_3, 126 game_option_teammelee_2, 127 game_option_teamffa_4, 128 game_option_teamffa_3, 129 game_option_teamffa_2, 130 game_option_teamctf_4, 131 game_option_teamctf_3, 132 game_option_teamctf_2, 133 game_option_topvbot_7, 134 game_option_topvbot_6, 135 game_option_topvbot_5, 136 game_option_topvbot_4, 137 game_option_topvbot_3, 138 game_option_topvbot_2, 139 game_option_topvbot_1 140 } t_game_option; 141 142 typedef enum 143 { 144 game_maptype_none, 145 game_maptype_selfmade, 146 game_maptype_blizzard, 147 game_maptype_ladder, 148 game_maptype_pgl, 149 game_maptype_kbk, 150 game_maptype_compusa 151 } t_game_maptype; 152 153 typedef enum 154 { 155 game_tileset_none, 156 game_tileset_badlands, 157 game_tileset_space, 158 game_tileset_installation, 159 game_tileset_ashworld, 160 game_tileset_jungle, 161 game_tileset_desert, 162 game_tileset_ice, 163 game_tileset_twilight 164 } t_game_tileset; 165 166 typedef enum 167 { 168 game_speed_none, 169 game_speed_slowest, 170 game_speed_slower, 171 game_speed_slow, 172 game_speed_normal, 173 game_speed_fast, 174 game_speed_faster, 175 game_speed_fastest 176 } t_game_speed; 177 178 typedef enum 179 { 180 game_difficulty_none, 181 game_difficulty_normal, 182 game_difficulty_nightmare, 183 game_difficulty_hell, 184 game_difficulty_hardcore_normal, 185 game_difficulty_hardcore_nightmare, 186 game_difficulty_hardcore_hell 187 } t_game_difficulty; 188 189 typedef enum { 190 game_flag_none, 191 game_flag_private 192 } t_game_flag; 193 194 typedef struct game 195 #ifdef GAME_INTERNAL_ACCESS 196 { 197 char const * name; 198 char const * pass; 199 char const * info; 200 t_game_type type; 201 unsigned int realm; 202 char const * realmname; 203 t_clienttag clienttag; /* type of client (STAR, SEXP, etc) */ 204 unsigned int addr; /* host IP */ 205 unsigned short port; /* host port */ 206 int startver; 207 unsigned long version; 208 t_game_status status; 209 unsigned int ref; /* current number of players */ 210 unsigned int count; /* max number of players */ 211 unsigned int id; 212 char const * mapname; 213 t_game_option option; 214 t_game_maptype maptype; 215 t_game_tileset tileset; 216 t_game_speed speed; 217 unsigned int mapsize_x; 218 unsigned int mapsize_y; 219 unsigned int maxplayers; 220 221 t_connection * owner; 222 t_connection * * connections; 223 t_account * * players; 224 t_game_result * results; 225 t_game_result * * reported_results; 226 char const * * report_heads; 227 char const * * report_bodies; 228 229 time_t create_time; 230 time_t start_time; 231 time_t lastaccess_time; 232 int bad; /* if 1, then the results will be ignored */ 233 t_game_difficulty difficulty; 234 char const * description; 235 t_game_flag flag; 236 t_elist glist_link; 237 } 238 #endif 239 t_game; 240 241 typedef int (*t_glist_func)(t_game *, void *); 242 243 #endif 244 245 246 #ifndef JUST_NEED_TYPES 247 #ifndef INCLUDED_GAME_PROTOS 248 #define INCLUDED_GAME_PROTOS 249 250 #define MAX_GAME_EMPTY_TIME 300 251 #define STARTVER_UNKNOWN 0 252 #define STARTVER_GW1 1 253 #define STARTVER_GW3 3 254 #define STARTVER_GW4 4 255 #define STARTVER_REALM1 104 256 257 #define JUST_NEED_TYPES 258 #ifdef TIME_WITH_SYS_TIME 259 # include <sys/time.h> 260 # include <time.h> 261 #else 262 # ifdef HAVE_SYS_TIME_H 263 # include <sys/time.h> 264 # else 265 # include <time.h> 266 # endif 267 #endif 268 #include "account.h" 269 #include "connection.h" 270 #include "common/list.h" 271 #include "common/tag.h" 272 #undef JUST_NEED_TYPES 273 274 extern char const * game_type_get_str(t_game_type type) ; 275 extern char const * game_status_get_str(t_game_status status) ; 276 extern char const * game_result_get_str(t_game_result result) ; 277 extern char const * game_option_get_str(t_game_option option) ; 278 extern char const * game_maptype_get_str(t_game_maptype maptype) ; 279 extern char const * game_tileset_get_str(t_game_tileset tileset) ; 280 extern char const * game_speed_get_str(t_game_speed speed) ; 281 extern char const * game_difficulty_get_str(t_game_difficulty difficulty) ; 282 extern t_game * game_create(char const * name, char const * pass, char const * info, t_game_type type, int startver, t_clienttag clienttag,unsigned long gameversion) ; 283 extern unsigned int game_get_id(t_game const * game); 284 extern char const * game_get_name(t_game const * game); 285 extern t_game_type game_get_type(t_game const * game); 286 extern t_game_maptype game_get_maptype(t_game const * game); 287 extern int game_set_maptype(t_game * game, t_game_maptype maptype); 288 extern t_game_tileset game_get_tileset(t_game const * game); 289 extern int game_set_tileset(t_game * game, t_game_tileset tileset); 290 extern t_game_speed game_get_speed(t_game const * game); 291 extern int game_set_speed(t_game * game, t_game_speed speed); 292 extern unsigned int game_get_mapsize_x(t_game const * game); 293 extern int game_set_mapsize_x(t_game * game, unsigned int x); 294 extern unsigned int game_get_mapsize_y(t_game const * game); 295 extern int game_set_mapsize_y(t_game * game, unsigned int y); 296 extern unsigned int game_get_maxplayers(t_game const * game); 297 extern int game_set_maxplayers(t_game * game, unsigned int maxplayers); 298 extern unsigned int game_get_difficulty(t_game const * game); 299 extern int game_set_difficulty(t_game * game, unsigned int difficulty); 300 extern char const * game_get_description(t_game const * game); 301 extern int game_set_description(t_game * game, char const * description); 302 extern char const * game_get_pass(t_game const * game); 303 extern char const * game_get_info(t_game const * game); 304 extern unsigned long game_get_version(t_game const * game); 305 extern int game_get_startver(t_game const * game); 306 extern unsigned int game_get_ref(t_game const * game); 307 extern unsigned int game_get_count(t_game const * game); 308 extern void game_set_status(t_game * game, t_game_status status); 309 extern t_game_status game_get_status(t_game const * game); 310 extern unsigned int game_get_addr(t_game const * game); 311 extern unsigned short game_get_port(t_game const * game); 312 extern unsigned int game_get_latency(t_game const * game); 313 extern t_connection * game_get_player_conn(t_game const * game, unsigned int i); 314 extern t_clienttag game_get_clienttag(t_game const * game); 315 extern int game_add_player(t_game * game, char const * pass, int startver, t_connection * c); 316 extern int game_del_player(t_game * game, t_connection * c); 317 extern t_account * game_get_player(t_game * game, unsigned int i); 318 extern int game_set_report(t_game * game, t_account * account, char const * head, char const * body); 319 extern int game_set_reported_results(t_game * game, t_account * account, t_game_result * results); 320 extern int game_set_self_report(t_game * game, t_account * account, t_game_result result); 321 extern t_game_result * game_get_reported_results(t_game * game, t_account * account); 322 extern char const * game_get_mapname(t_game const * game); 323 extern int game_set_mapname(t_game * game, char const * mapname); 324 extern t_connection * game_get_owner(t_game const * game); 325 extern time_t game_get_create_time(t_game const * game); 326 extern time_t game_get_start_time(t_game const * game); 327 extern int game_set_option(t_game * game, t_game_option option); 328 extern t_game_option game_get_option(t_game const * game); 329 extern int gamelist_create(void); 330 extern int gamelist_destroy(void); 331 extern int gamelist_get_length(void); 332 extern t_game * gamelist_find_game(char const * name, t_clienttag ctag, t_game_type type); 333 extern t_game * gamelist_find_game_byid(unsigned int id); 334 extern void gamelist_traverse(t_glist_func cb, void *data); 335 extern int gamelist_total_games(void); 336 extern int game_set_realm(t_game * game, unsigned int realm); 337 extern unsigned int game_get_realm(t_game const * game); 338 extern char const * game_get_realmname(t_game const * game); 339 extern int game_set_realmname(t_game * game, char const * realmname); 340 extern void gamelist_check_voidgame(void); 341 extern void game_set_flag(t_game * game, t_game_flag flag); 342 extern t_game_flag game_get_flag(t_game const * game); 343 extern int game_get_count_by_clienttag(t_clienttag ct); 344 extern int game_is_ladder(t_game *game); 345 346 #endif 347 #endif 348