2009-11-24 09:48:53 +00:00
/*
*
* Prototypes for UDP - protocol network management functions .
*
*/
# include "multi.h"
// Exported functions
2010-04-04 09:41:53 +00:00
int net_udp_setup_game ( void ) ;
2009-11-24 09:48:53 +00:00
void net_udp_manual_join_game ( ) ;
2010-06-29 16:41:08 +00:00
void net_udp_list_join_game ( ) ;
2009-11-24 09:48:53 +00:00
int net_udp_objnum_is_past ( int objnum ) ;
void net_udp_do_frame ( int force , int listen ) ;
void net_udp_send_data ( ubyte * ptr , int len , int priority ) ;
void net_udp_leave_game ( ) ;
int net_udp_endlevel ( int * secret ) ;
2010-01-07 14:49:07 +00:00
int net_udp_kmatrix_poll1 ( newmenu * menu , d_event * event , void * userdata ) ;
int net_udp_kmatrix_poll2 ( newmenu * menu , d_event * event , void * userdata ) ;
2009-11-24 09:48:53 +00:00
void net_udp_send_endlevel_packet ( ) ;
void net_udp_dump_player ( struct _sockaddr dump_addr , int why ) ;
void net_udp_disconnect_player ( int playernum ) ;
int net_udp_level_sync ( ) ;
2011-05-25 13:25:06 +00:00
void net_udp_send_mdata_direct ( ubyte * data , int data_len , int pnum , int priority ) ;
2009-11-24 09:48:53 +00:00
// Some defines
2010-06-29 16:41:08 +00:00
# ifdef IPv6
2010-12-22 13:53:23 +00:00
# define UDP_MCASTv6_ADDR "ff02::1"
2010-06-29 16:41:08 +00:00
# endif
2010-12-22 13:53:23 +00:00
# define UDP_BCAST_ADDR "255.255.255.255"
2009-11-24 09:48:53 +00:00
# define UDP_PORT_DEFAULT 42424 // Our default port - easy to remember: D = 4, X = 24, X = 24
2011-06-30 23:01:06 +00:00
# define UDP_MANUAL_ADDR_DEFAULT "localhost"
# ifdef USE_TRACKER
# define TRACKER_ADDR_DEFAULT "dxxtracker.reenigne.net"
# define TRACKER_PORT_DEFAULT 42420
# endif
2009-11-24 09:48:53 +00:00
# define UDP_REQ_ID "D1XR" // ID string for a request packet
2011-07-15 09:46:04 +00:00
# define UDP_MAX_NETGAMES 900
2009-11-24 09:48:53 +00:00
# define UDP_NETGAMES_PPAGE 12 // Netgames on one page of Netlist
2011-07-15 09:46:04 +00:00
# define UDP_NETGAMES_PAGES 75 // Pages available on Netlist (UDP_MAX_NETGAMES/UDP_NETGAMES_PPAGE)
2012-05-10 16:53:59 +00:00
# define UDP_TIMEOUT (5*F1_0) // 5 seconds disconnect timeout
2011-11-02 00:04:38 +00:00
# define UDP_MDATA_STOR_QUEUE_SIZE 500 // Store up to 500 MDATA packets
2009-11-24 09:48:53 +00:00
2011-04-12 22:19:46 +00:00
// UDP-Packet identificators (ubyte) and their (max. sizes).
# define UPID_VERSION_DENY 1 // Netgame join or info has been denied due to version difference.
2011-11-02 00:04:38 +00:00
# define UPID_VERSION_DENY_SIZE 9
2011-04-12 22:19:46 +00:00
# define UPID_GAME_INFO_REQ 2 // Requesting all info about a netgame.
2011-11-02 00:04:38 +00:00
# define UPID_GAME_INFO_REQ_SIZE 13
2011-11-03 13:26:43 +00:00
# define UPID_GAME_INFO_LITE_REQ_SIZE 11
2011-04-12 22:19:46 +00:00
# define UPID_GAME_INFO 3 // Packet containing all info about a netgame.
2011-11-02 00:04:38 +00:00
# define UPID_GAME_INFO_SIZE 505
2011-04-12 22:19:46 +00:00
# define UPID_GAME_INFO_LITE_REQ 4 // Requesting lite info about a netgame. Used for discovering games.
# define UPID_GAME_INFO_LITE 5 // Packet containing lite netgame info.
# define UPID_GAME_INFO_LITE_SIZE 69
# define UPID_DUMP 6 // Packet containing why player cannot join this game.
# define UPID_DUMP_SIZE 2
# define UPID_ADDPLAYER 7 // Packet from Host containing info about a new player.
# define UPID_REQUEST 8 // New player says: "I want to be inside of you!" (haha, sorry I could not resist) / Packet containing request to join the game actually.
# define UPID_QUIT_JOINING 9 // Packet from a player who suddenly quits joining.
2011-11-02 00:04:38 +00:00
# define UPID_SEQUENCE_SIZE 12
2011-04-12 22:19:46 +00:00
# define UPID_SYNC 10 // Packet from host containing full netgame info to sync players up.
# define UPID_OBJECT_DATA 11 // Packet from host containing object buffer.
# define UPID_PING 12 // Packet from host containing his GameTime and the Ping list. Client returns this time to host as UPID_PONG and adapts the ping list.
# define UPID_PING_SIZE 37
# define UPID_PONG 13 // Packet answer from client to UPID_PING. Contains the time the initial ping packet was sent.
# define UPID_PONG_SIZE 10
# define UPID_ENDLEVEL_H 14 // Packet from Host to all Clients containing connect-states and kills information about everyone in the game.
# define UPID_ENDLEVEL_C 15 // Packet from Client to Host containing connect-state and kills information from this Client.
2012-03-29 08:15:58 +00:00
# define UPID_PDATA 16 // Packet from player containing his movement data.
# define UPID_MDATA_PNORM 17 // Packet containing multi buffer from a player. Priority 0,1 - no ACK needed.
# define UPID_MDATA_PNEEDACK 18 // Packet containing multi buffer from a player. Priority 2 - ACK needed. Also contains pkt_num
# define UPID_MDATA_ACK 19 // ACK packet for UPID_MDATA_P1.
2011-04-12 22:19:46 +00:00
# define UPID_MAX_SIZE 1024 // Max size for a packet
# define UPID_MDATA_BUF_SIZE 454
2011-04-05 00:24:30 +00:00
# ifdef USE_TRACKER
2011-04-12 22:19:46 +00:00
# define UPID_TRACKER_VERIFY 21 // The tracker has successfully gotten a hold of us
# define UPID_TRACKER_INCGAME 22 // The tracker is sending us some game info
2011-04-05 00:24:30 +00:00
# endif
2009-11-24 09:48:53 +00:00
// Structure keeping lite game infos (for netlist, etc.)
typedef struct UDP_netgame_info_lite
{
2010-12-22 13:53:23 +00:00
struct _sockaddr game_addr ;
short program_iver [ 3 ] ;
2011-04-11 22:45:06 +00:00
fix GameID ;
2009-11-24 09:48:53 +00:00
char game_name [ NETGAME_NAME_LEN + 1 ] ;
char mission_title [ MISSION_NAME_LEN + 1 ] ;
char mission_name [ 9 ] ;
int32_t levelnum ;
ubyte gamemode ;
2010-12-22 13:53:23 +00:00
ubyte RefusePlayers ;
2009-11-24 09:48:53 +00:00
ubyte difficulty ;
ubyte game_status ;
2010-07-08 06:37:23 +00:00
ubyte numconnected ;
2009-11-24 09:48:53 +00:00
ubyte max_numplayers ;
ubyte game_flags ;
} __pack__ UDP_netgame_info_lite ;
typedef struct UDP_sequence_packet
{
2011-04-12 22:19:46 +00:00
ubyte type ;
netplayer_info player ;
2009-11-24 09:48:53 +00:00
} __pack__ UDP_sequence_packet ;
// player position packet structure
typedef struct UDP_frame_info
{
2011-04-12 22:19:46 +00:00
ubyte type ;
ubyte Player_num ;
ubyte connected ;
ubyte obj_render_type ;
shortpos pos ;
2009-11-24 09:48:53 +00:00
} __pack__ UDP_frame_info ;
// packet structure for multi-buffer
typedef struct UDP_mdata_info
{
2011-04-12 22:19:46 +00:00
ubyte type ;
ubyte Player_num ;
uint32_t pkt_num ;
ushort mbuf_size ;
ubyte mbuf [ UPID_MDATA_BUF_SIZE ] ;
2009-11-24 09:48:53 +00:00
} __pack__ UDP_mdata_info ;
// structure to store MDATA to maybe resend
typedef struct UDP_mdata_store
{
2011-04-12 22:19:46 +00:00
int used ;
fix64 pkt_initial_timestamp ; // initial timestamp to see if packet is outdated
fix64 pkt_timestamp [ MAX_PLAYERS ] ; // Packet timestamp
int pkt_num ; // Packet number
ubyte Player_num ; // sender of this packet
ubyte player_ack [ MAX_PLAYERS ] ; // 0 if player has not ACK'd this packet, 1 if ACK'd or not connected
ubyte data [ UPID_MDATA_BUF_SIZE ] ; // extra data of a packet - contains all multibuf data we don't want to loose
ushort data_size ;
2009-11-24 09:48:53 +00:00
} __pack__ UDP_mdata_store ;
// structure to keep track of MDATA packets we've already got
typedef struct UDP_mdata_recv
{
2011-04-12 22:19:46 +00:00
int pkt_num [ UDP_MDATA_STOR_QUEUE_SIZE ] ;
int cur_slot ; // index we can use for a new pkt_num
2009-11-24 09:48:53 +00:00
} __pack__ UDP_mdata_recv ;