1 /* 2 * This program is free software; you can redistribute it and/or modify 3 * it under the terms of the GNU General Public License as published by 4 * the Free Software Foundation; either version 2 of the License, or 5 * (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU Library General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 */ 16 #ifndef _NETPLAY_H 17 #define _NETPLAY_H 18 19 #include "hugod.h" 20 21 #ifdef __cplusplus 22 extern "C" 23 { 24 #endif 25 26 extern const int PACKET_IDENTIFIER; 27 28 extern const int PACKET_IDENTIFICATION_ID; 29 extern const int PACKET_IDENTIFICATION_ACKNOWLEDGE_ID; 30 extern const int PACKET_STATUS_ID; 31 extern const int PACKET_DIGEST_ID; 32 extern const int PACKET_INTERNET_DIGEST_ID; 33 34 extern const int PACKET_IDENTIFICATION_NUMBER_REQUESTED_SLOTS; 35 extern const int PACKET_IDENTIFICATION_INPUT_DEVICE_INDEX; 36 extern const int PACKET_IDENTIFICATION_INPUT_DEVICE_NUMBER; 37 extern const int PACKET_IDENTIFICATION_CHECKSUM; 38 extern const int PACKET_IDENTIFICATION_LENGTH; 39 40 extern const int PACKET_IDENTIFICATION_ACKNOWLEDGE_NUMBER_ALLOCATED_SLOTS; 41 extern const int PACKET_IDENTIFICATION_ACKNOWLEDGE_CHECKSUM; 42 extern const int PACKET_IDENTIFICATION_ACKNOWLEDGE_LENGTH; 43 44 extern const int PACKET_STATUS_FRAME_NUMBER; 45 extern const int PACKET_STATUS_INPUT_DEVICE_INDEX; 46 extern const int PACKET_STATUS_INPUT_DEVICE_NUMBER; 47 extern const int PACKET_STATUS_CHECKSUM; 48 extern const int PACKET_STATUS_LENGTH; 49 50 extern const int PACKET_INTERNET_DIGEST_FRAME_NUMBER; 51 extern const int PACKET_INTERNET_DIGEST_NUMBER_DIGEST; 52 extern const int PACKET_INTERNET_DIGEST_DIGEST_INDEX; 53 extern const int PACKET_INTERNET_DIGEST_DIGEST_NUMBER; 54 extern const int PACKET_INTERNET_DIGEST_BASE_LENGTH; 55 extern const int PACKET_INTERNET_DIGEST_INCREMENT_LENGTH; 56 57 extern const int MAX_NUMBER_PLAYER; 58 59 extern const int MIN_NUMBER_PLAYER; 60 61 extern const int SERVER_SOCKET_TIMEOUT; 62 extern const int CLIENT_SOCKET_TIMEOUT; 63 extern const int CLIENT_SOCKET_INTERNET_TIMEOUT; 64 65 66 extern const int CLIENT_PACKET_SIZE; 67 extern const int SERVER_PACKET_SIZE; 68 69 extern const int DEFAULT_SERVER_PORT; 70 71 extern const int DIGEST_SIZE; 72 73 //! Initialize the network 74 /*! 75 * @return 0 in case of success 76 */ 77 int init_network (); 78 79 //! Releases ressources allocated for the network communication 80 void shutdown_network (); 81 82 //! Compute the checksum for an array of byte 83 unsigned char compute_checksum (unsigned char *data, int index_min, 84 int index_max); 85 86 //! Return the number of available slots 87 int count_remaining_slot (global_status_type * global_status, 88 global_option_type * global_option); 89 90 //! Send a packet to acknowledge identification 91 void send_identification_acknowledge_packet (global_status_type * 92 global_status, 93 int number_allocated_slots); 94 95 //! Compute the packet as if it was an identification one and eventually send a reply 96 void identify_client (global_status_type * global_status, 97 global_option_type * global_option); 98 99 //! Stores an incoming packet for local processing 100 int read_incoming_server_packet (global_status_type * global_status); 101 102 //! Handles client requests using the accurate but greedy way 103 void serve_clients_lan_protocol (global_status_type * global_status, 104 global_option_type * global_option); 105 106 //! Handles client request using the inaccrute but fast way 107 void serve_clients_internet_protocol (global_status_type * global_status, 108 global_option_type * global_option); 109 110 #ifdef __cplusplus 111 } 112 #endif 113 114 #endif /* _NETPLAY_H */ 115