2014-06-01 17:55:23 +00:00
/*
* This file is part of the DXX - Rebirth project < http : //www.dxx-rebirth.com/>.
* It is copyright by its individual contributors , as recorded in the
* project ' s Git history . See COPYING . txt at the top level for license
* terms and a link to the Git history .
*/
2009-11-24 09:48:53 +00:00
/*
*
* Prototypes for UDP - protocol network management functions .
*
*/
2012-11-11 22:12:51 +00:00
# pragma once
2009-11-24 09:48:53 +00:00
# include "multi.h"
2012-11-11 22:12:51 +00:00
# ifdef __cplusplus
2014-06-26 02:27:16 +00:00
# include "pack.h"
2014-07-04 04:12:45 +00:00
# include "compiler-array.h"
2014-12-22 04:35:48 +00:00
# include "ntstring.h"
2012-11-11 22:12:51 +00:00
2009-11-24 09:48:53 +00:00
// 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 ( ) ;
2013-12-29 04:28:07 +00:00
int net_udp_objnum_is_past ( objnum_t objnum ) ;
2009-11-24 09:48:53 +00:00
void net_udp_do_frame ( int force , int listen ) ;
2013-03-30 19:41:33 +00:00
void net_udp_send_data ( const ubyte * ptr , int len , int priority ) ;
2009-11-24 09:48:53 +00:00
void net_udp_leave_game ( ) ;
int net_udp_endlevel ( int * secret ) ;
2014-10-16 02:13:09 +00:00
int net_udp_kmatrix_poll1 ( newmenu * menu , const d_event & event , const unused_newmenu_userdata_t * ) ;
int net_udp_kmatrix_poll2 ( newmenu * menu , const d_event & event , const unused_newmenu_userdata_t * ) ;
2009-11-24 09:48:53 +00:00
void net_udp_send_endlevel_packet ( ) ;
2014-10-18 23:37:34 +00:00
void net_udp_dump_player ( const _sockaddr & dump_addr , int why ) ;
2009-11-24 09:48:53 +00:00
void net_udp_disconnect_player ( int playernum ) ;
int net_udp_level_sync ( ) ;
2014-10-17 02:23:40 +00:00
void net_udp_send_mdata_direct ( const ubyte * data , int data_len , int pnum , int priority ) ;
2013-03-03 01:03:33 +00:00
void net_udp_send_netgame_update ( ) ;
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"
2015-02-08 17:43:29 +00:00
// Our default port - easy to remember: D = 4, X = 24, X = 24
const uint16_t UDP_PORT_DEFAULT = 42424 ;
2011-06-30 23:01:06 +00:00
# define UDP_MANUAL_ADDR_DEFAULT "localhost"
# ifdef USE_TRACKER
2015-02-08 17:43:29 +00:00
# ifndef TRACKER_ADDR_DEFAULT
/* Allow an alternate default at compile time */
2011-06-30 23:01:06 +00:00
# define TRACKER_ADDR_DEFAULT "dxxtracker.reenigne.net"
2015-02-08 17:43:29 +00:00
# endif
const uint16_t TRACKER_PORT_DEFAULT = 42420 ;
2011-06-30 23:01:06 +00:00
# endif
2013-03-03 01:03:33 +00:00
# if defined(DXX_BUILD_DESCENT_I)
2009-11-24 09:48:53 +00:00
# define UDP_REQ_ID "D1XR" // ID string for a request packet
2013-03-03 01:03:33 +00:00
# elif defined(DXX_BUILD_DESCENT_II)
# define UDP_REQ_ID "D2XR" // ID string for a request packet
# endif
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
2014-06-24 12:49:18 +00:00
# define UDP_MDATA_STOR_QUEUE_SIZE 1024 // Store up to 1024 MDATA packets
# define UDP_MDATA_STOR_MIN_FREE_2JOIN 384 // have at least this many free packet slots before we let someone join the game
# define UDP_MDATA_PKT_NUM_MIN 1 // start from pkt_num 1 (0 is used to initialize the trace list)
# define UDP_MDATA_PKT_NUM_MAX (UDP_MDATA_STOR_QUEUE_SIZE*100) // the max value for pkt_num. roll over when we go any higher. this should be smaller than INT_MAX
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
2015-03-20 21:31:22 +00:00
# define UPID_GAME_INFO_LITE_REQ_SIZE 13
2011-04-12 22:19:46 +00:00
# define UPID_GAME_INFO 3 // Packet containing all info about a netgame.
# 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.
2015-02-21 17:21:34 +00:00
# define UPID_GAME_INFO_SIZE_MAX (sizeof(netgame_info))
# define UPID_GAME_INFO_LITE_SIZE_MAX (sizeof(UDP_netgame_info_lite))
2011-04-12 22:19:46 +00:00
# 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.
2013-04-18 13:14:16 +00:00
# define UPID_SEQUENCE_SIZE (3 + (CALLSIGN_LEN+1))
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.
2013-12-09 13:00:23 +00:00
# define UPID_PDATA_SIZE 49
2012-03-29 08:15:58 +00:00
# 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.)
2014-06-21 23:55:24 +00:00
struct UDP_netgame_info_lite : public prohibit_void_ptr < UDP_netgame_info_lite >
2009-11-24 09:48:53 +00:00
{
2010-12-22 13:53:23 +00:00
struct _sockaddr game_addr ;
2015-04-02 02:36:52 +00:00
array < short , 3 > program_iver ;
2011-04-11 22:45:06 +00:00
fix GameID ;
2014-12-22 04:35:48 +00:00
ntstring < NETGAME_NAME_LEN > game_name ;
2014-12-22 04:35:48 +00:00
ntstring < MISSION_NAME_LEN > mission_title ;
2015-01-03 23:44:32 +00:00
ntstring < 8 > mission_name ;
2009-11-24 09:48:53 +00:00
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 ;
2013-08-24 16:33:51 +00:00
bit_game_flags game_flag ;
2014-06-21 23:55:24 +00:00
} ;
2009-11-24 09:48:53 +00:00
2014-06-26 02:27:16 +00:00
struct UDP_sequence_packet : prohibit_void_ptr < UDP_sequence_packet >
2009-11-24 09:48:53 +00:00
{
2011-04-12 22:19:46 +00:00
ubyte type ;
netplayer_info player ;
2014-06-26 02:27:16 +00:00
} ;
2009-11-24 09:48:53 +00:00
// packet structure for multi-buffer
2014-06-26 02:27:16 +00:00
struct UDP_mdata_info : prohibit_void_ptr < UDP_mdata_info >
2009-11-24 09:48:53 +00:00
{
2011-04-12 22:19:46 +00:00
ubyte type ;
ubyte Player_num ;
2015-02-28 19:36:01 +00:00
uint16_t mbuf_size ;
2011-04-12 22:19:46 +00:00
uint32_t pkt_num ;
2015-02-28 19:36:01 +00:00
array < uint8_t , UPID_MDATA_BUF_SIZE > mbuf ;
2014-06-26 02:27:16 +00:00
} ;
2009-11-24 09:48:53 +00:00
// structure to store MDATA to maybe resend
2014-06-26 02:27:16 +00:00
struct UDP_mdata_store : prohibit_void_ptr < UDP_mdata_store >
2009-11-24 09:48:53 +00:00
{
2014-06-24 12:49:18 +00:00
fix64 pkt_initial_timestamp ; // initial timestamp to see if packet is outdated
2015-04-02 02:36:52 +00:00
array < fix64 , MAX_PLAYERS > pkt_timestamp ; // Packet timestamp
array < uint32_t , MAX_PLAYERS > pkt_num ; // Packet number
2015-02-28 19:36:01 +00:00
sbyte used ;
2014-06-24 12:49:18 +00:00
ubyte Player_num ; // sender of this packet
2015-02-28 19:36:01 +00:00
uint16_t data_size ;
2015-04-02 02:36:52 +00:00
array < uint8_t , MAX_PLAYERS > player_ack ; // 0 if player has not ACK'd this packet, 1 if ACK'd or not connected
2015-02-28 19:36:01 +00:00
array < uint8_t , UPID_MDATA_BUF_SIZE > data ; // extra data of a packet - contains all multibuf data we don't want to loose
2014-06-26 02:27:16 +00:00
} ;
2009-11-24 09:48:53 +00:00
2014-06-24 12:49:18 +00:00
// structure to keep track of MDATA packets we already got, which we expect from another player and the pkt_num for the next packet we want to send to another player
struct UDP_mdata_check : public prohibit_void_ptr < UDP_mdata_check >
2009-11-24 09:48:53 +00:00
{
2014-07-04 04:12:45 +00:00
array < uint32_t , UDP_MDATA_STOR_QUEUE_SIZE > pkt_num ; // all those we got just recently, so we can ignore them if we get them again
2014-06-24 12:49:18 +00:00
int cur_slot ; // index we can use for a new pkt_num
uint32_t pkt_num_torecv ; // the next pkt_num we await for this player
uint32_t pkt_num_tosend ; // the next pkt_num we want to send to another player
2014-06-21 23:55:24 +00:00
} ;
2012-11-11 22:12:51 +00:00
# endif