1 /* 2 * OpenTyrian: A modern cross-platform port of Tyrian 3 * Copyright (C) 2007-2009 The OpenTyrian Development Team 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 */ 19 #ifndef NETWORK_H 20 #define NETWORK_H 21 22 #include "opentyr.h" 23 24 #include "SDL.h" 25 #ifdef WITH_NETWORK 26 # include "SDL_net.h" 27 #endif 28 29 30 #define PACKET_ACKNOWLEDGE 0x00 // 31 #define PACKET_KEEP_ALIVE 0x01 // 32 33 #define PACKET_CONNECT 0x10 // version, delay, episodes, player_number, name 34 #define PACKET_DETAILS 0x11 // episode, difficulty 35 36 #define PACKET_QUIT 0x20 // 37 #define PACKET_WAITING 0x21 // 38 #define PACKET_BUSY 0x22 // 39 40 #define PACKET_GAME_QUIT 0x30 // 41 #define PACKET_GAME_PAUSE 0x31 // 42 #define PACKET_GAME_MENU 0x32 // 43 44 #define PACKET_STATE_RESEND 0x40 // state_id 45 #define PACKET_STATE 0x41 // <state> (not acknowledged) 46 #define PACKET_STATE_XOR 0x42 // <xor state> (not acknowledged) 47 48 extern bool isNetworkGame; 49 extern int network_delay; 50 51 extern char *network_opponent_host; 52 extern Uint16 network_player_port, network_opponent_port; 53 extern char *network_player_name, *network_opponent_name; 54 55 #ifdef WITH_NETWORK 56 extern UDPpacket *packet_out_temp; 57 extern UDPpacket *packet_in[], *packet_out[], 58 *packet_state_in[], *packet_state_out[]; 59 #endif 60 61 extern uint thisPlayerNum; 62 extern JE_boolean haltGame; 63 extern JE_boolean moveOk; 64 extern JE_boolean pauseRequest, skipLevelRequest, helpRequest, nortShipRequest; 65 extern JE_boolean yourInGameMenuRequest, inGameMenuRequest; 66 67 #ifdef WITH_NETWORK 68 void network_prepare( Uint16 type ); 69 bool network_send( int len ); 70 71 int network_check( void ); 72 bool network_update( void ); 73 74 bool network_is_sync( void ); 75 76 void network_state_prepare( void ); 77 int network_state_send( void ); 78 bool network_state_update( void ); 79 bool network_state_is_reset( void ); 80 void network_state_reset( void ); 81 82 int network_connect( void ); 83 void network_tyrian_halt( unsigned int err, bool attempt_sync ); 84 85 int network_init( void ); 86 87 void JE_clearSpecialRequests( void ); 88 89 #define NETWORK_KEEP_ALIVE() \ 90 if (isNetworkGame) \ 91 network_check(); 92 93 #else 94 95 #define NETWORK_KEEP_ALIVE() 96 97 #endif 98 99 100 #endif /* NETWORK_H */ 101 102