1 #ifndef _HUGOD_H 2 #define _HUGOD_H 3 4 /* 5 * -- Client -> Server packets types : 6 * 7 * - Identification : 8 * 9 * Byte 0 : Identifier = 0x55 10 * Byte 1 : Number of requested slots (1-5) 11 * Byte 2-6 : Remote (client) input device number (unused entries are ignored) 12 * Byte 7 : Checksum on bytes 0-6 (algorithm described later) 13 * 14 * - In-game device status ( == request for others status for this frame ) 15 * Byte 0 : Identifier = 0xC2 16 * Byte 1-4 : Frame number (network endianess encoded) 17 * (*) NOTE : in internet protocol version, the frame number is used to indicate a request. 18 * If null, there's no special request done. 19 * Byte 5-9 : Remote (client) input device status 20 * Only devices which were declared as used has to be filled, remaining is ignored 21 * Byte 10 : Checksum on bytes 0-9 (algorithm described soon) 22 * 23 * -- Server -> Client packets types : 24 * 25 * - Identification acknowledge 26 * 27 * Byte 0 : Identifier = 0x96 28 * Byte 1 : Number of slots really allocated 29 * Byte 2 : Checksum on bytes 0-1 (algorithm described very soon) 30 * 31 * - Digest (LAN PROTOCOL) 32 * 33 * Byte 0 : Identifier = 0x3B 34 * Byte 1-4 : Frame number (network endianess encoded) 35 * Byte 5-9 : Digest of the input device status 36 * Byte 10 : Checksum on bytes 0-9 (algorithm described extremely soon) 37 * 38 * - Digest (INTERNET PROTOCOL) 39 * 40 * Byte 0 : Identifier = 0x1F 41 * Byte 1-4 : Frame number of the first digest sent (network endianess encoded) 42 * Byte 5 : Number of digest sent (>=1) 43 * Byte 6-10 : 1st digest of the input device status 44 * (Byte 11-15 : 2nd digest if any) 45 * (...) 46 * Last byte (6 + 5 * number of digest sent) : Checksum on previous bytes (algorithm described in an almost past future) 47 * 48 * -- Now, it's time to ... hmmm... let's see. Oh, yeah, checksum algorithm. 49 * 50 * It's mean to be quick and easy, not a real error checking 51 * 52 * byte checksum = 0; 53 * for each byte to check, do checksum ^= current_byte; rotate left checksum 54 * that's all folks 55 */ 56 57 #include <SDL_net.h> 58 #include "config.h" 59 #include "cleantyp.h" 60 61 #ifdef __cplusplus 62 extern "C" 63 { 64 #endif 65 66 /*! 67 * Structure used to distinguish a remote (client) device. It uses the ip endpoint 68 * designation and the number of the device on client's side 69 */ 70 typedef struct 71 { 72 IPaddress address; 73 char remote_input_device; 74 } input_mapping_type; 75 76 typedef enum { LAN_PROTOCOL_TYPE, INTERNET_PROTOCOL_TYPE } type_server_type; 77 78 typedef struct 79 { 80 char number_player; 81 int server_port; 82 type_server_type type_server; 83 } global_option_type; 84 85 typedef struct 86 { 87 IPaddress address; 88 char allocated_slots; 89 } allocation_request_type; 90 91 typedef enum 92 { UNIDENTIFIED, WAITING, READY } client_status_type; 93 94 typedef struct 95 { 96 UInt32 frame_number; 97 int number_identified_players; 98 input_mapping_type input_mapping[5]; //!< 5 stands for MAX_NUMBER_PLAYER 99 UChar input_value[5]; //!< 5 stands for MAX_NUMBER_PLAYER 100 client_status_type player_status[5]; //!< 5 stands for MAX_NUMBER_PLAYER 101 UDPsocket server_socket; 102 UDPpacket *current_packet; //!< current packet computed from client 103 UDPpacket *digest_packet; //!< summary packet to send to clients 104 SDLNet_SocketSet server_socket_set; //!< A singleton set used to check activity passively 105 int number_allocation_request; 106 allocation_request_type allocation_request[5]; //!< 5 stands for MAX_NUMBER_PLAYER 107 double start_time; //!< In seconds 108 UInt32 next_frame_to_send[5]; //!< 5 stands for MAX_NUMBER_PLAYER 109 UInt32 next_frame_asked[5]; //!< 5 stands for MAX_NUMBER_PLAYER 110 } global_status_type; 111 112 #ifdef __cplusplus 113 } 114 #endif 115 116 #endif /* _HUGO_SERVER_H */ 117