1 /* 2 * XPilot NG, a multiplayer space war game. 3 * 4 * Copyright (C) 1991-2001 by 5 * 6 * Bj�rn Stabell <bjoern@xpilot.org> 7 * Ken Ronny Schouten <ken@xpilot.org> 8 * Bert Gijsbers <bert@xpilot.org> 9 * Dick Balaska <dick@xpilot.org> 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 */ 25 26 #ifndef META_H 27 #define META_H 28 29 /* 30 * max number of servers we can find on the local network. 31 */ 32 #define MAX_LOCAL_SERVERS 10 33 34 /* 35 * Some constants for describing access to the meta servers. 36 * XXX These are also defined in some other file. 37 */ 38 #define NUM_METAS 2 39 #define META_PROG_PORT 4401 40 #define META_USER_PORT 4400 41 #define NUM_META_DATA_FIELDS 18 42 #define META_INIT_SOCK {-2, {0, 0}, 0, {0, 0, 0}, NULL, NULL} 43 44 #define PING_UNKNOWN 10000 /* never transmitted a ping to it */ 45 #define PING_NORESP 9999 /* never responded to our ping */ 46 #define PING_SLOW 9998 /* responded to first ping after 47 * we had already retried (ie slow!) */ 48 49 /* 50 * Access the data field of one of the servers 51 * which is listed by the meta servers. 52 */ 53 #define SI_DATA(it) ((server_info_t *)LI_DATA(it)) 54 55 /********************** Data Structures *********************/ 56 57 /* 58 * All the fields for a server in one line of meta output. 59 * the strings in this structure should really be an array 60 * of char pointers to reduce the amount of code. 61 */ 62 struct ServerInfo { 63 char *version, 64 *hostname, 65 *users_str, 66 *mapname, 67 *mapsize, 68 *author, 69 *status, 70 *bases_str, 71 *fps_str, 72 *playlist, 73 *sound, 74 *teambases_str, 75 *timing, *ip_str, *freebases, *queue_str, *domain, pingtime_str[5]; 76 unsigned port, 77 ip, users, bases, fps, uptime, teambases, queue, pingtime; 78 struct timeval start; 79 unsigned char serial; 80 }; 81 82 extern list_t server_list; 83 extern time_t server_list_creation_time; 84 extern list_iter_t server_it; 85 86 typedef struct ServerInfo server_info_t; 87 88 /* 89 * Here we hold the servers which are listed by the meta servers. 90 * We record the time we contacted Meta so as to not overload Meta. 91 * server_it is an iterator pointing at the first server for the next page. 92 */ 93 94 95 enum MetaState { 96 MetaConnecting = 0, 97 MetaReadable = 1, 98 MetaReceiving = 2 99 }; 100 101 /* 102 * Structure describing a meta server. 103 * Hostname, IP address, and socket filedescriptor. 104 */ 105 106 struct Meta { 107 char name[MAX_HOST_LEN]; 108 char addr[16]; 109 sock_t sock; 110 enum MetaState state; /* connecting, readable, receiving */ 111 }; 112 113 114 void Delete_server_list(void); 115 void Delete_server_info(server_info_t * sip); 116 void string_to_lower(char *s); 117 char *Get_domain_from_hostname(char *host_name); 118 int Welcome_sort_server_list(void); 119 int Add_server_info(server_info_t * sip); 120 char *my_strtok(char *buf, const char *sep); 121 void Add_meta_line(char *meta_line); 122 void Meta_connect(int *connections_ptr, int *maxfd_ptr); 123 void Meta_dns_lookup(void); 124 void Ping_servers(void); 125 int Get_meta_data(char *errorstr); 126 127 #endif 128 129 130