Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 1 | /* |
| 2 | * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>. |
||
| 3 | * It is copyright by its individual contributors, as recorded in the |
||
| 4 | * project's Git history. See COPYING.txt at the top level for license |
||
| 5 | * terms and a link to the Git history. |
||
| 6 | */ |
||
| 7 | /* |
||
| 8 | * |
||
| 9 | * Prototypes for UDP-protocol network management functions. |
||
| 10 | * |
||
| 11 | */ |
||
| 12 | |||
| 13 | #pragma once |
||
| 14 | #include "multi.h" |
||
| 15 | |||
| 16 | #ifdef __cplusplus |
||
| 17 | #include "pack.h" |
||
| 18 | #include "ntstring.h" |
||
| 19 | #include "fwd-window.h" |
||
| 20 | #include <array> |
||
| 21 | |||
| 22 | // Exported functions |
||
| 23 | #ifdef dsx |
||
| 24 | namespace dsx { |
||
| 25 | window_event_result net_udp_setup_game(void); |
||
| 26 | } |
||
| 27 | #endif |
||
| 28 | void net_udp_manual_join_game(); |
||
| 29 | void net_udp_list_join_game(); |
||
| 30 | int net_udp_objnum_is_past(objnum_t objnum); |
||
| 31 | #ifdef dsx |
||
| 32 | namespace dsx { |
||
| 33 | void net_udp_do_frame(int force, int listen); |
||
| 34 | } |
||
| 35 | #endif |
||
| 36 | void net_udp_send_data(const uint8_t *ptr, unsigned len, int priority); |
||
| 37 | #ifdef dsx |
||
| 38 | namespace dsx { |
||
| 39 | void net_udp_leave_game(); |
||
| 40 | int net_udp_endlevel(int *secret); |
||
| 41 | } |
||
| 42 | #endif |
||
| 43 | int net_udp_kmatrix_poll2( newmenu *menu,const d_event &event, const unused_newmenu_userdata_t *); |
||
| 44 | void net_udp_send_endlevel_packet(); |
||
| 45 | void net_udp_dump_player(const _sockaddr &dump_addr, int why); |
||
| 46 | void net_udp_disconnect_player(int playernum); |
||
| 47 | window_event_result net_udp_level_sync(); |
||
| 48 | void net_udp_send_mdata_direct(const ubyte *data, int data_len, int pnum, int priority); |
||
| 49 | void net_udp_send_netgame_update(); |
||
| 50 | |||
| 51 | // Some defines |
||
| 52 | // Our default port - easy to remember: D = 4, X = 24, X = 24 |
||
| 53 | constexpr uint16_t UDP_PORT_DEFAULT = 42424; |
||
| 54 | #define UDP_MANUAL_ADDR_DEFAULT "localhost" |
||
| 55 | #if DXX_USE_TRACKER |
||
| 56 | #ifndef TRACKER_ADDR_DEFAULT |
||
| 57 | /* Allow an alternate default at compile time */ |
||
| 58 | #define TRACKER_ADDR_DEFAULT "tracker.dxx-rebirth.com" |
||
| 59 | #endif |
||
| 60 | constexpr uint16_t TRACKER_PORT_DEFAULT = 9999; |
||
| 61 | #endif |
||
| 62 | #define UDP_MAX_NETGAMES 900 |
||
| 63 | namespace dcx { |
||
| 64 | constexpr std::integral_constant<unsigned, 12> UDP_NETGAMES_PPAGE{}; // Netgames on one page of Netlist |
||
| 65 | } |
||
| 66 | #define UDP_NETGAMES_PAGES 75 // Pages available on Netlist (UDP_MAX_NETGAMES/UDP_NETGAMES_PPAGE) |
||
| 67 | #define UDP_TIMEOUT (5*F1_0) // 5 seconds disconnect timeout |
||
| 68 | #define UDP_MDATA_STOR_QUEUE_SIZE 1024 // Store up to 1024 MDATA packets |
||
| 69 | #define UDP_MDATA_STOR_MIN_FREE_2JOIN 384 // have at least this many free packet slots before we let someone join the game |
||
| 70 | #define UDP_MDATA_PKT_NUM_MIN 1 // start from pkt_num 1 (0 is used to initialize the trace list) |
||
| 71 | #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 |
||
| 72 | |||
| 73 | // UDP-Packet identificators (ubyte) and their (max. sizes). |
||
| 74 | #define UPID_VERSION_DENY 1 // Netgame join or info has been denied due to version difference. |
||
| 75 | #define UPID_VERSION_DENY_SIZE 9 |
||
| 76 | #define UPID_GAME_INFO_REQ 2 // Requesting all info about a netgame. |
||
| 77 | #define UPID_GAME_INFO_REQ_SIZE 13 |
||
| 78 | #define UPID_GAME_INFO_LITE_REQ_SIZE 13 |
||
| 79 | #define UPID_GAME_INFO 3 // Packet containing all info about a netgame. |
||
| 80 | #define UPID_GAME_INFO_LITE_REQ 4 // Requesting lite info about a netgame. Used for discovering games. |
||
| 81 | #define UPID_GAME_INFO_LITE 5 // Packet containing lite netgame info. |
||
| 82 | #define UPID_GAME_INFO_SIZE_MAX (sizeof(netgame_info)) |
||
| 83 | #define UPID_GAME_INFO_LITE_SIZE_MAX (sizeof(UDP_netgame_info_lite)) |
||
| 84 | #define UPID_DUMP 6 // Packet containing why player cannot join this game. |
||
| 85 | #define UPID_DUMP_SIZE 2 |
||
| 86 | #define UPID_ADDPLAYER 7 // Packet from Host containing info about a new player. |
||
| 87 | #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. |
||
| 88 | #define UPID_QUIT_JOINING 9 // Packet from a player who suddenly quits joining. |
||
| 89 | #define UPID_SEQUENCE_SIZE (3 + (CALLSIGN_LEN+1)) |
||
| 90 | #define UPID_SYNC 10 // Packet from host containing full netgame info to sync players up. |
||
| 91 | #define UPID_OBJECT_DATA 11 // Packet from host containing object buffer. |
||
| 92 | #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. |
||
| 93 | #define UPID_PING_SIZE 37 |
||
| 94 | #define UPID_PONG 13 // Packet answer from client to UPID_PING. Contains the time the initial ping packet was sent. |
||
| 95 | #define UPID_PONG_SIZE 10 |
||
| 96 | #define UPID_ENDLEVEL_H 14 // Packet from Host to all Clients containing connect-states and kills information about everyone in the game. |
||
| 97 | #define UPID_ENDLEVEL_C 15 // Packet from Client to Host containing connect-state and kills information from this Client. |
||
| 98 | #define UPID_PDATA 16 // Packet from player containing his movement data. |
||
| 99 | #define UPID_PDATA_SIZE 49 |
||
| 100 | #define UPID_MDATA_PNORM 17 // Packet containing multi buffer from a player. Priority 0,1 - no ACK needed. |
||
| 101 | #define UPID_MDATA_PNEEDACK 18 // Packet containing multi buffer from a player. Priority 2 - ACK needed. Also contains pkt_num |
||
| 102 | #define UPID_MDATA_ACK 19 // ACK packet for UPID_MDATA_P1. |
||
| 103 | #define UPID_MAX_SIZE 1024 // Max size for a packet |
||
| 104 | #define UPID_MDATA_BUF_SIZE 454 |
||
| 105 | #if DXX_USE_TRACKER |
||
| 106 | #define UPID_TRACKER_REGISTER 21 // Register or update a game on the tracker. |
||
| 107 | #define UPID_TRACKER_REMOVE 22 // Remove our game from the tracker. |
||
| 108 | #define UPID_TRACKER_REQGAMES 23 // Request a list of all games stored on the tracker. |
||
| 109 | #define UPID_TRACKER_GAMEINFO 24 // Packet containing info about a game |
||
| 110 | #define UPID_TRACKER_ACK 25 // An ACK packet from the tracker |
||
| 111 | #define UPID_TRACKER_HOLEPUNCH 26 // Hole punching process. Sent from client to tracker to request hole punching from game host and received by host from tracker to initiate hole punching to requesting client |
||
| 112 | #endif |
||
| 113 | |||
| 114 | // Structure keeping lite game infos (for netlist, etc.) |
||
| 115 | #if defined(DXX_BUILD_DESCENT_I) || defined(DXX_BUILD_DESCENT_II) |
||
| 116 | struct UDP_netgame_info_lite : public prohibit_void_ptr<UDP_netgame_info_lite> |
||
| 117 | { |
||
| 118 | struct _sockaddr game_addr; |
||
| 119 | std::array<short, 3> program_iver; |
||
| 120 | fix GameID; |
||
| 121 | uint16_t TrackerGameID; |
||
| 122 | ntstring<NETGAME_NAME_LEN> game_name; |
||
| 123 | ntstring<MISSION_NAME_LEN> mission_title; |
||
| 124 | ntstring<8> mission_name; |
||
| 125 | int32_t levelnum; |
||
| 126 | ubyte gamemode; |
||
| 127 | ubyte RefusePlayers; |
||
| 128 | ubyte difficulty; |
||
| 129 | ubyte game_status; |
||
| 130 | ubyte numconnected; |
||
| 131 | ubyte max_numplayers; |
||
| 132 | bit_game_flags game_flag; |
||
| 133 | }; |
||
| 134 | #endif |
||
| 135 | |||
| 136 | struct UDP_sequence_packet : prohibit_void_ptr<UDP_sequence_packet> |
||
| 137 | { |
||
| 138 | ubyte type; |
||
| 139 | netplayer_info player; |
||
| 140 | }; |
||
| 141 | |||
| 142 | // packet structure for multi-buffer |
||
| 143 | struct UDP_mdata_info : prohibit_void_ptr<UDP_mdata_info> |
||
| 144 | { |
||
| 145 | ubyte type; |
||
| 146 | ubyte Player_num; |
||
| 147 | uint16_t mbuf_size; |
||
| 148 | uint32_t pkt_num; |
||
| 149 | std::array<uint8_t, UPID_MDATA_BUF_SIZE> mbuf; |
||
| 150 | }; |
||
| 151 | |||
| 152 | // structure to store MDATA to maybe resend |
||
| 153 | struct UDP_mdata_store : prohibit_void_ptr<UDP_mdata_store> |
||
| 154 | { |
||
| 155 | fix64 pkt_initial_timestamp; // initial timestamp to see if packet is outdated |
||
| 156 | std::array<fix64, MAX_PLAYERS> pkt_timestamp; // Packet timestamp |
||
| 157 | std::array<uint32_t, MAX_PLAYERS> pkt_num; // Packet number |
||
| 158 | sbyte used; |
||
| 159 | ubyte Player_num; // sender of this packet |
||
| 160 | uint16_t data_size; |
||
| 161 | std::array<uint8_t, MAX_PLAYERS> player_ack; // 0 if player has not ACK'd this packet, 1 if ACK'd or not connected |
||
| 162 | std::array<uint8_t, UPID_MDATA_BUF_SIZE> data; // extra data of a packet - contains all multibuf data we don't want to loose |
||
| 163 | }; |
||
| 164 | |||
| 165 | // 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 |
||
| 166 | struct UDP_mdata_check : public prohibit_void_ptr<UDP_mdata_check> |
||
| 167 | { |
||
| 168 | std::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 |
||
| 169 | int cur_slot; // index we can use for a new pkt_num |
||
| 170 | uint32_t pkt_num_torecv; // the next pkt_num we await for this player |
||
| 171 | uint32_t pkt_num_tosend; // the next pkt_num we want to send to another player |
||
| 172 | }; |
||
| 173 | |||
| 174 | #endif |