### Teeworlds Integer Encoding Examples Source: https://ddnet.org/docs/libtw2/int Provides examples of how specific integers are encoded using the variable-length scheme. Note the encoding for 0, 1, -1, and 64, highlighting the sign flag and the use of multiple bytes for larger numbers. ```text 0 is encoded as `0000 0000`. 1 is encoded as `0000 0001`. -1 is encoded as `0100 0000` (note that the `bits` field is all zeros). 64 is encoded as `1000 0000 0000 0001`. ``` -------------------------------- ### Huffman Encoding Example: Grouping by Bytes Source: https://ddnet.org/docs/libtw2/huffman Shows the substituted bitstream grouped into bytes. This step prepares the data for padding and bit reversal. ```text 1000 1101 0001 0000 0101 0100 0111 0110 0 | | | | | 1st byte 2nd byte 3rd byte 4th byte 5th byte ``` -------------------------------- ### Huffman Encoding Example: Padding Source: https://ddnet.org/docs/libtw2/huffman Illustrates the padding of the bitstream with zeros to form complete bytes. This ensures the bitstream length is a multiple of 8. ```text 1000 1101 0001 0000 0101 0100 0111 0110 0000 0000 ^^^ ^^^^ ``` -------------------------------- ### Huffman Encoding Example: Initial Bytes Source: https://ddnet.org/docs/libtw2/huffman Shows the initial sequence of bytes to be encoded using Huffman compression. This sequence includes repeated zero bytes and a non-zero byte. ```text 00 01 00 02 00 80 00 ``` -------------------------------- ### Huffman Encoding Example: Substitution Source: https://ddnet.org/docs/libtw2/huffman Presents the byte sequence after applying Huffman substitution according to a predefined table. Each original byte is replaced by its corresponding bit sequence. ```text 1 0001 1 01000 1 00000 1 010100011101100 | | | | | | | | 00 01 00 02 00 80 00 EOF ``` -------------------------------- ### Huffman Encoding Example: Bit Reversal Source: https://ddnet.org/docs/libtw2/huffman Shows the final Huffman encoded byte stream after reversing the order of bits within each byte. This is the compressed representation of the original data. ```text 1011 0001 0000 1000 0010 1010 0110 1110 0000 0000 ``` -------------------------------- ### Huffman Encoding Example: Appending EOF Source: https://ddnet.org/docs/libtw2/huffman Demonstrates the addition of an EOF symbol to the byte sequence before Huffman substitution. This marks the end of the data stream for compression. ```text 00 01 00 02 00 80 00 EOF ``` -------------------------------- ### Envelope Item Data Structure Source: https://ddnet.org/docs/libtw2/map Describes the structure for envelope items, including version, channels, start point, number of points, and optional synchronized flag and name. ```plaintext item_data of envelope items: [1] version [1] channels [1] start_point [1] num_points extension without version change: [8] name: I32String version 2 extension: [1] synchronized: bool ``` -------------------------------- ### DDNet Datafile Item Type Structure Source: https://ddnet.org/docs/libtw2/datafile Describes the structure of an item type within a DDNet datafile. Each item type is identified by a unique type_id and specifies the start index and number of items belonging to that type. ```plaintext item_type: [4] type_id [4] start [4] num ``` -------------------------------- ### Demo Header Structure Source: https://ddnet.org/docs/libtw2/demo Contains network version, map information, demo type, and timestamp. 'net_version', 'map_name', 'type', and 'timestamp' are null-terminated strings. 'map_size', 'map_crc', and 'length' are signed big-endian 32-bit integers. ```text header: [ 64] net_version [ 64] map_name [ 4] map_size [ 4] map_crc [ 8] type [ 4] length [ 20] timestamp ``` -------------------------------- ### Demo File Structure Source: https://ddnet.org/docs/libtw2/demo Defines the main sections of a demo file and their byte offsets. The 'map' field size is determined by 'map_size' in the header. ```text demo: [ 8] version_header [168] header [260] _timeline_markers [ ] map [ ] data ``` -------------------------------- ### Version Header Structure Source: https://ddnet.org/docs/libtw2/demo Specifies the 'magic' string and version number at the beginning of a demo file. 'magic' is always 'TWDEMO\0'. ```text version_header: [ 7] magic [ 1] version ``` -------------------------------- ### DDNet Connect/Accept Packet Structure with Token Magic Source: https://ddnet.org/docs/libtw2/protocol Defines the structure for DDNet connect and connect-accept packets, which include a special token magic ('TKEN') and the connection token. These packets signal support for the DDNet token extension. ```protobuf packet_control_connect_connectaccept_ddnet: [24] packet_header [ 8] control_message [32] token_magic [32] token ``` -------------------------------- ### Connection State Diagram Source: https://ddnet.org/docs/libtw2/connection Illustrates the sequence of messages exchanged between the client and server during connection establishment and game entry. Useful for understanding the handshake process. ```text -> s:info <- s:map_change <----------------------+ [ -> s:request_map_data ] | [ <- s:map_data ] | -> s:ready | [ <- g:sv_motd ] | <- s:con_ready | -> g:client_start_info | [ <- g:sv_vote_clear_options ] | [ <- g:sv_tune_params ] | <- g:sv_ready_to_enter | -> s:enter_game | ingame --------------------------------+ ``` -------------------------------- ### Datafile Structure Source: https://ddnet.org/docs/libtw2/datafile Outlines the main components of a Teeworlds datafile. This structure is common across different versions. ```text datafile: [ 8] version_header [ 28] header [*12] item_types [* 4] item_offsets [* 4] data_offsets [* 4] _data_sizes [ ] items [ ] data ``` -------------------------------- ### Teeworlds Integer Encoding Bit Representation Source: https://ddnet.org/docs/libtw2/int Illustrates how the bits from the encoded bytes are combined to form the final integer, showing the little-endian order and the placement of bits from each byte. The padding bits in the last byte must be zero. ```text ES54 3210 Ecba 9876 Ejih gfed Eqpo nmlk PPPP utsr ^^ ^^^^ ^^^ ^^^^ ^^^ ^^^^ ^^^ ^^^^ ^^^^ ``` -------------------------------- ### Huffman Bitstream Representation Source: https://ddnet.org/docs/libtw2/huffman Illustrates the bit ordering after padding and reversal in Huffman compression. The first byte's bits are reversed, followed by the second byte's reversed bits. ```text 7654 3210 fecb da98 ... | | | second byte first byte ``` -------------------------------- ### Player Info Structure Source: https://ddnet.org/docs/libtw2/serverinfo_extended Defines the fields for player information. Use this structure to parse or construct player data. ```plaintext [str] name [str] clan [int] country [int] score [int] is_player [str] reserved ``` -------------------------------- ### Version Header Structure Source: https://ddnet.org/docs/libtw2/datafile Defines the structure of the version header, including the magic bytes and version number. Note the handling of potential big-endian issues. ```text version_header: [4] magic [4] version ``` -------------------------------- ### Huffman Coding Appendix Source: https://ddnet.org/docs/libtw2/huffman This section lists binary codes, potentially representing Huffman codes for characters or symbols. Each entry maps a two-character hexadecimal key to its corresponding binary string. ```text EOF: 010100011101100 00: 1 01: 0001 02: 01000 03: 01101000 04: 011110 05: 0110111 06: 0110110 07: 0111011 08: 00100 09: 0011001 0a: 0101111 0b: 01111111 0c: 0100111 0d: 011100 0e: 00101111 0f: 011101110 10: 0101011 11: 011001010 12: 0011101 13: 010101010 14: 00001111 15: 0111110110 16: 001011000 17: 001111100 18: 0000100 19: 001111001 1a: 010010000 1b: 000010110 1c: 010100000 1d: 0110011 1e: 01010011 1f: 0111010010 20: 001101011 21: 001100010 22: 010111011 23: 0110010111 24: 000011000 25: 010100010 26: 010110111 27: 010011010 28: 0110101 29: 01011100 2a: 010010001 2b: 0111111010 2c: 001011011 2d: 0110110101 2e: 0111010001 2f: 0110100110 30: 0111010111 31: 0111110010 32: 0111110100 33: 0101101011 34: 00111100010 35: 001110001011 36: 0111110101100 37: 010100011100 38: 001010111010 39: 000011100111 3a: 000010100101 3b: 001011100110 3c: 0111110000111 3d: 00101110000 3e: 0110010110100 3f: 010010101000 40: 01010010 41: 001111011 42: 0101101010 43: 0011000111 44: 0101100110 45: 0100110110 46: 0011110000 47: 0000111000 48: 0011111010 49: 00101001 4a: 0101010010 4b: 010101011 4c: 0011000011 4d: 0000101110 4e: 01100100001 4f: 01111110111 50: 01110101000 51: 01111101111 52: 01111100000 53: 0011011 54: 0010100001 55: 001101010 56: 01011101000 57: 01011000000 58: 0000110011 59: 01001010101 5a: 0101000111010 5b: 010110011110 5c: 0101110100111 5d: 001011100011 5e: 0011111011100 5f: 0101100111001 60: 0101100111000 61: 001110001010 62: 0110110100011 63: 0010101110001 64: 001110010001 65: 001110010000 66: 0010111001111 67: 0010111001110 68: 0111010110101 69: 0111010110100 6a: 0101100111011 6b: 0101100111010 6c: 01110101001000 6d: 001011100010 6e: 0111010110111 6f: 0110110100010 70: 0101110100110 71: 000011100110 72: 00001110010 73: 001011100101 74: 000010100100 75: 0110110100101 76: 01111101011010 77: 010100011101101 78: 0111010110110 79: 000010100111 7a: 0010101110000 7b: 0111010110001 7c: 0110110100100 7d: 001010101101 7e: 01110101001001 7f: 0011100011101 80: 00000 81: 0111111001 82: 001101001 83: 01111110110 84: 010110001 85: 01110111100 86: 010010100 87: 01110101011 88: 010110100 89: 01111100010 8a: 010011001 8b: 0010100000 8c: 001011010 8d: 01111110001 8e: 001111111 8f: 0011000110 90: 011001001 91: 01111110000 92: 001101000 93: 0000110010 94: 011000 95: 0101000110 96: 010011000 97: 01100100011 98: 001011001 99: 0100110111 9a: 010101000 9b: 01011101010 9c: 010010111 9d: 01111100011 9e: 001110011 9f: 0011100101 a0: 001111110 a1: 0101100001 a2: 0111110011 a3: 0111011111 a4: 011011011 a5: 001100000 a6: 011010010 a7: 0011000010 a8: 010110110 a9: 0110100111 aa: 010110010 ab: 0010101111 ac: 010010110 ad: 0000101111 ae: 001010110 af: 01111101110 b0: 00001101 b1: 001010100 b2: 000011101 b3: 01110101010 b4: 000010101 b5: 01100100010 b6: 010100001 b7: 01110100111 b8: 001010001 b9: 01110100110 ba: 001110000 bb: 01110111101 bc: 001111010 bd: 0111010000 be: 001011101 bf: 0101010011 c0: 010111010111 c1: 010010101101 c2: 001111000111 c3: 011011010011 c4: 001110010011 c5: 010111010110 c6: 011111000010 c7: 001111000110 c8: 011111010101 c9: 011011010000 ca: 001110010010 cb: 000010100110 cc: 010100011111 cd: 001111101101 ce: 011101010011 cf: 010010101100 d0: 010010101111 d1: 001111101100 d2: 011001011001 d3: 010111010010 d4: 000010100001 d5: 011001011000 d6: 010100011110 d7: 001010101100 d8: 00111000100 d9: 011001000001 da: 0111010110000 db: 001111101111 dc: 0101100000101 dd: 001010101111 de: 001010101110 df: 011001011011 e0: 001110001101 e1: 001010101001 e2: 0111010110011 e3: 001011100100 e4: 0011111011101 e5: 000010100000 e6: 011111010111 e7: 0101100000100 e8: 001010101000 e9: 0111010110010 ea: 001010111011 eb: 001010101011 ec: 0111110000110 ed: 011001000000 ee: 000010100011 ef: 001010101010 f0: 01111101011011 f1: 0011100011100 f2: 010110011111 f3: 010010101110 f4: 010010101001 f5: 000010100010 f6: 001110001100 f7: 0111110101001 f8: 01010001110111 f9: 0111110101000 fa: 0111010100101 fb: 001110001111 fc: 0110010110101 fd: 001010111001 fe: 010110000011 ff: 01001001 ``` -------------------------------- ### Version Item Data Structure Source: https://ddnet.org/docs/libtw2/map Defines the structure for version information in map items. All fields except 'settings' are optional. ```plaintext item_data of the only version item: [1] (item) version [1] opt &author: CString [1] opt &version: CString [1] opt &credits: CString [1] opt &license: CString [1] opt &settings: [CString] (DDNet only) ``` -------------------------------- ### Tick Chunk Header Format (Version 5) Source: https://ddnet.org/docs/libtw2/demo Format for chunk headers indicating a new tick in demo version 5. Includes 'is_tick', 'keyframe', 'inline_tick' to determine if tick delta is inline or absolute, and 'tick_delta'. ```text chunk_header_tick_first_5: [1] is_tick (set to 1 for tick markers) [1] keyframe [1] inline_tick [5] tick_delta 1kiD DDDD ``` -------------------------------- ### Chunk Structure Source: https://ddnet.org/docs/libtw2/demo Represents a data chunk within the demo file, consisting of a header and data. The header format varies based on whether it indicates a new tick. ```text chunk: [ ] chunk_header [ ] chunk_data ``` -------------------------------- ### Sounds Layer Item Data Extension Source: https://ddnet.org/docs/libtw2/map Extension for sound layers, detailing version, number of sources, data pointer, and sound name. ```plaintext item_data extension for sounds layers: [1] version [1] num_sources [1] &data: [SoundSource] [1] opt *sound [3] name: I32String ``` -------------------------------- ### Tick Chunk Header Format (Versions 3 & 4) Source: https://ddnet.org/docs/libtw2/demo Format for chunk headers indicating a new tick in demo versions 3 and 4. 'is_tick' is 1, 'keyframe' indicates a full snapshot, and 'tick_delta' specifies the time difference to the previous tick or 0 for an absolute tick. ```text chunk_header_tick_first_34: [1] is_tick (set to 1 for tick markers) [1] keyframe [6] tick_delta 1kDD DDDD ``` -------------------------------- ### Extended Server Info 'More' Packet Structure Source: https://ddnet.org/docs/libtw2/serverinfo_extended The structure for subsequent 'more' packets in an extended server info response. These packets are used to send additional player data that may not fit in the main packet. Packet numbers help detect duplicates. ```protobuf [ 10] padding [ 4] type [int] token [int] packet_no [str] reserved [ *] players ``` -------------------------------- ### Teeworlds 0.7.0+ Packet7 Header Structure Source: https://ddnet.org/docs/libtw2/packet7 Defines the bit fields for the standard packet7 header, including reserved bits, flags, acknowledgment, number of chunks, and token. Note that padding must be zeroed. ```plaintext packet7_header: [ 2] reserved [ 1] flag_connless [ 1] flag_compression [ 1] flag_request_resend [ 1] flag_control [10] ack [ 8] num_chunks [32] token RRff ffAA AAAA AAAA nnnn nnnn TTTT TTTT TTTT TTTT TTTT TTTT TTTT TTTT ``` -------------------------------- ### Extended Server Info Main Packet Structure Source: https://ddnet.org/docs/libtw2/serverinfo_extended The structure of the main packet for extended server information. This packet contains essential server details and player counts. Note that the 'players' field is variable in size. ```protobuf [ 10] padding [ 4] type [int] token [str] version [str] name [str] map [int] map_crc [int] map_size [str] game_type [int] flags [int] num_players [int] max_players [int] num_clients [int] max_clients [str] reserved [ *] players ``` -------------------------------- ### Teeworlds Packet Header Structure Source: https://ddnet.org/docs/libtw2/packet Defines the bit layout for a Teeworlds packet header, including compression, resend, connless, control flags, padding, acknowledgment, and chunk count. Note that padding must be zeroed. ```text packet_header: [ 1] flag_compression [ 1] flag_request_resend [ 1] flag_connless [ 1] flag_control [ 2] padding [10] ack [ 8] num_chunks FFFF ppAA AAAA AAAA nnnn nnnn ``` -------------------------------- ### Teeworlds Integer Encoding Format Source: https://ddnet.org/docs/libtw2/int Describes the structure of a variable-length encoded integer, including flags for extension and sign, and the distribution of bits across bytes. Always use the least amount of bytes possible and ensure padding is zeroed. ```text first_byte: [1] flag_extend [1] flag_sign [6] bits next_byte: [1] flag_extend [7] bits last_byte: [4] padding [4] bits int: first_byte [next_byte [next_byte [next_byte [last_byte]]]] ``` -------------------------------- ### Extended Server Info Request Packet Structure Source: https://ddnet.org/docs/libtw2/serverinfo_extended This is the UDP packet structure for requesting extended server information from a Teeworlds server. Ensure correct byte ordering and values for fields like magic_bytes and vanilla_request. ```protobuf [2] magic_bytes [2] extra_token [2] reserved [4] padding [4] vanilla_request [1] token ``` -------------------------------- ### Teeworlds 0.7.0+ Packet7 Header Connless Structure Source: https://ddnet.org/docs/libtw2/packet7 Defines the bit fields for the connless packet7 header. If flag_connless is set, other flags must not be set. Version must be set to 1. ```plaintext packet7_header_connless: [ 2] reserved [ 1] flag_connless [ 1] flag_compression [ 1] flag_request_resend [ 1] flag_control [ 2] version [32] token [32] response_token RRff ffVV TTTT TTTT TTTT TTTT TTTT TTTT TTTT TTTT rrrr rrrr rrrr rrrr rrrr rrrr rrrr rrrr ``` -------------------------------- ### Connection-Oriented Packet Structure Source: https://ddnet.org/docs/libtw2/protocol Outlines the general structure for connection-oriented packets, which include a header and a payload that may be compressed. Flags like `flag_resend` and `flag_compression` are important for reliable delivery and efficiency. ```plaintext packet_connected: [24] packet_header [ ] maybe_compressed_payload ``` -------------------------------- ### Tile Type Structure Source: https://ddnet.org/docs/libtw2/map The 'Tile' type structure used in vanilla and front layers. It includes an ID, flags, and a skip field for 0.7 compression. ```plaintext 'Tile' tile type (consisting of bytes, used by all vanilla layers and the front layer): [1] id [1] flags [1] skip [1] - unused ``` -------------------------------- ### Tune Tile Type Structure Source: https://ddnet.org/docs/libtw2/map The 'Tune' tile type structure, used for tuning zones. It includes a number to identify the zone. ```plaintext 'Tune' tile type (consisting of bytes): [1] number [1] id ``` -------------------------------- ### Bezier Curve Extension for Envelope Points Source: https://ddnet.org/docs/libtw2/map Provides additional fields for Bezier curve envelope points, including in-tangent and out-tangent deltas for both X and Y axes. ```plaintext bezier point extension: [4] in_tangent_dx [4] in_tangent_dy [4] out_tangent_dx [4] out_tangent_dy ``` -------------------------------- ### DDNet Control Packet Structure Source: https://ddnet.org/docs/libtw2/protocol Defines the structure for general DDNet control packets, including a packet header, control message, and a 32-bit token. This is used for various control communications. ```protobuf packet_control_ddnet: [24] packet_header [ 8] control_message [32] token ``` -------------------------------- ### DDNet Datafile Version 3/4 Header Structure Source: https://ddnet.org/docs/libtw2/datafile Defines the seven 32-bit signed integers that constitute the header for datafile versions 3 and 4. This includes fields for size, swap length, item counts, and data sizes. ```plaintext header: [4] size [4] swaplen [4] num_item_types [4] num_items [4] num_data [4] item_size [4] data_size ``` -------------------------------- ### Extended Server Info - Main Packet Source: https://ddnet.org/docs/libtw2/serverinfo_extended The structure of the main UDP packet containing extended server information. ```APIDOC ## Extended Server Info - Main Packet ### Description This is the primary UDP packet returned by the server containing extended information. ### Packet Structure - **padding** (10 bytes): Must be filled with 0xff bytes. - **type** (4 bytes): Must be the ASCII representation of "iext". - **token** (int): The token from the request. -1 if not sent upon request. - **version** (str): The server version. First three bytes must match client's version. - **name** (str): The server's name. - **map** (str): The current map name. - **map_crc** (int): The current map's CRC. - **map_size** (int): The current map's size in bytes. - **game_type** (str): The current gametype. - **flags** (int): Server flags. Bit 0 (value 1) indicates password protection. - **num_players** (int): Number of players currently on the server. - **max_players** (int): Maximum number of players the server can handle. - **num_clients** (int): Number of clients currently connected. - **max_clients** (int): Maximum number of clients the server can handle. - **reserved** (str): Reserved for future protocol versions, must be an empty string. - **players** (*): Player information (detailed below). ``` -------------------------------- ### Normal Chunk Header Format Source: https://ddnet.org/docs/libtw2/demo Format for chunk headers that do not indicate a new tick. 'is_tick' is 0, 'type' specifies chunk content (snapshot, message, snapshot delta), and 'size' indicates data length. ```text chunk_header_normal_first: [1] is_tick (set to 0 for normal chunks) [2] type [5] size 0ttS SSSS ``` -------------------------------- ### Extended Server Info - 'More' Packet Source: https://ddnet.org/docs/libtw2/serverinfo_extended The structure of subsequent UDP packets used to send additional player data if it doesn't fit in the main packet. ```APIDOC ## Extended Server Info - 'More' Packet ### Description This UDP packet is used to send additional player data when the main packet is insufficient. ### Packet Structure - **padding** (10 bytes): Must be filled with 0xff bytes. - **type** (4 bytes): Must be the ASCII representation of "iex+". - **token** (int): The token from the request. - **packet_no** (int): Packet number in the server info response (greater than 0, less than 64). - **reserved** (str): Reserved for future protocol versions, must be an empty string. - **players** (*): Additional player information. ``` -------------------------------- ### Teeworlds Control Message Types Source: https://ddnet.org/docs/libtw2/protocol Lists the defined types for control messages used in connection-oriented packets. These range from connection establishment (`connect`, `connectaccept`, `accept`) to maintenance (`keepalive`) and termination (`close`). ```plaintext keepalive = 0 connect = 1 connectaccept = 2 accept = 3 close = 4 ``` -------------------------------- ### Base Layer Item Data Structure Source: https://ddnet.org/docs/libtw2/map This is the base data structure for all layer items. It includes version, type, and flags. The detail flag is used in Quad-, Tile-, and Sound layers. ```plaintext item_data base for all layer items (different types have different extensions): [1] _version (not used, was uninitialized) [1] type [1] flags ``` -------------------------------- ### Tilemap Layer Item Data Extension Source: https://ddnet.org/docs/libtw2/map Extension for tilemap layers, including version, dimensions, color, and image data. DDNet specific extensions include data pointers for teleporters, speedups, and other special layers. ```plaintext item_data extension for tilemap layers: [1] version [1] width [1] height [1] flags [4] color: Color [1] opt *color_envelope [1] color_envelope_offset [1] opt *image [1] &data: 2d-array of the the tile type 'Tile' version 3 extension: [3] name: I32String DDNet extension (no version change): [1] opt &data_tele [1] opt &data_speedup [1] opt &data_front [1] opt &data_switch [1] opt &data_tune ``` -------------------------------- ### Sound Source Structure Definition Source: https://ddnet.org/docs/libtw2/map Defines the structure for a SoundSource in DDNet map data. Includes position, looping, panning, and sound falloff properties. ```plaintext SoundSource: [2] position: Point [1] looping: bool [1] panning: bool [1] delay (in seconds) [1] falloff: u8 [1] *position_envelope [1] position_envelope_offset [1] *sound_envelope [1] sound_envelope_offset [3] shape: SoundShape ``` -------------------------------- ### Timeline Markers Structure Source: https://ddnet.org/docs/libtw2/demo Used in demo versions 4 and 5 to store timeline markers. 'num_timeline_markers' indicates the count, and 'timeline_markers' is an array of 64 signed big-endian 32-bit integers. ```text _timeline_markers: [ 4] num_timeline_markers [256] timeline_markers ``` -------------------------------- ### Image Item Data Structure Source: https://ddnet.org/docs/libtw2/map Details the structure for image items, including dimensions, external flag, name, and optional pixel data. Version 2 introduces a 'variant' field for RGB/RGBA types. ```plaintext item_data of image items: [1] version [1] width [1] height [1] external: bool [1] &name: CString [1] opt &data: [Pixel] version 2 extension (Vanilla only): [1] variant ``` -------------------------------- ### Quads Layer Item Data Extension Source: https://ddnet.org/docs/libtw2/map Extension for quads layers, including version, number of quads, and image data. Version 2 adds a name field. ```plaintext item_data extension for quads layers: [1] version [1] num_quads [1] &data: [Quads] [1] opt *image version 2 extension: [3] name: I32String ``` -------------------------------- ### Teeworlds 0.7.0+ Chunk7 Header Vital Structure Source: https://ddnet.org/docs/libtw2/packet7 Defines the bit fields for a vital chunk7 header, including flags for resend and vital status, chunk size, and sequence number. Padding must be zeroed. ```plaintext chunk7_header_vital: [ 1] flag_resend [ 1] flag_vital [ 6] <---------- [ 2] sequence |-- size [ 6] <---------- [ 8] sequence FFss ssss SSss ssss SSSS SSSS ``` -------------------------------- ### DDNet Close Control Packet Structure Source: https://ddnet.org/docs/libtw2/protocol Specifies the format for DDNet control packets used to close a connection. It includes the standard header, message, token, and an optional close reason. ```protobuf packet_control_close_ddnet: [24] packet_header [ 8] control_message [ ] close_reason [32] token ``` -------------------------------- ### Close Control Packet Structure Source: https://ddnet.org/docs/libtw2/protocol Details the structure of the `close` control message, which can optionally include a UTF-8 encoded reason string for connection termination. ```plaintext packet_control_close: [24] packet_header [ 8] control_message [ ] reason ``` -------------------------------- ### UUID Index Item Structure Source: https://ddnet.org/docs/libtw2/map Details the structure of a UUID Index item, used in DDNet to map UUIDs to type_ids. ```text UUID Index Item structure: type_id: 0xffff id: type_id of the uuid item type that this item represents item_data: [3] UUID of the uuid item type that this item represents ``` -------------------------------- ### Switch Tile Type Structure Source: https://ddnet.org/docs/libtw2/map The 'Switch' tile type structure, used for switch tiles. It includes a number for interaction grouping, ID, flags, and delay. ```plaintext 'Switch' tile type (consisting of bytes): [1] number [1] id [1] flags [1] delay ``` -------------------------------- ### Speedup Tile Type Structure Source: https://ddnet.org/docs/libtw2/map The 'Speedup' tile type structure, used for speedup zones. It defines force, max speed, ID, and angle. ```plaintext 'Speedup' tile type (consisting of bytes): [1] force [1] max_speed [1] id [1] - unused padding byte [2] angle: i16 ``` -------------------------------- ### Version Item Data Source: https://ddnet.org/docs/libtw2/map Specifies the structure of the Version item, which contains the map version information. ```text item_data of the only version item: [1] version ``` -------------------------------- ### Sound Shape Definition Source: https://ddnet.org/docs/libtw2/map Defines the shape properties for a SoundSource, specifying whether it's a rectangle or circle and its dimensions. ```plaintext SoundShape: [1] kind [1] width / radius [1] height / - unused ``` -------------------------------- ### Teeworlds 0.7.0+ Chunk7 Header Non-Vital Structure Source: https://ddnet.org/docs/libtw2/packet7 Defines the bit fields for a non-vital chunk7 header, including flags for resend and vital status, and the size of the chunk. Padding must be zeroed. ```plaintext chunk7_header_nonvital: [ 1] flag_resend [ 1] flag_vital [ 6] <---------- [ 2] padding |-- size [ 6] <---------- FFss ssss PPss ssss ``` -------------------------------- ### DDNet Auto Mapper Item Data Structure Source: https://ddnet.org/docs/libtw2/map Details the structure for auto mapper items in DDNet. The '_version' field is unused. 'group' and 'layer' specify the group and layer index, respectively. The 'automatic' flag is at 2^0 in 'flags'. ```plaintext item_data of auto mapper items: [1] _version (not used, was uninitialized) [1] *group [1] *layer [1] opt config [1] seed [1] flags ``` -------------------------------- ### Extended Server Info Request Packet Source: https://ddnet.org/docs/libtw2/serverinfo_extended The structure of the UDP packet to request extended server information from a Teeworlds server. ```APIDOC ## Extended Server Info Request Packet ### Description This UDP packet is sent to a Teeworlds server to request extended information. ### Packet Structure - **magic_bytes** (2 bytes): Must be the ASCII representation of "xe". - **extra_token** (2 bytes): A 16-bit big-endian integer used in conjunction with the token. - **reserved** (2 bytes): Reserved for future protocol versions, must be zero. - **padding** (4 bytes): Must be filled with 0xff bytes. - **vanilla_request** (4 bytes): Must be the ASCII representation of "gie3". - **token** (1 byte): An arbitrary byte chosen by the client. ``` -------------------------------- ### DDNet Datafile Item Structure Source: https://ddnet.org/docs/libtw2/datafile Details the structure of an individual item within a DDNet datafile. Each item contains a combined type_id and id, its size, and the associated item data. ```plaintext item: [4] type_id__id [4] size [ ] item_data ``` -------------------------------- ### Sound Envelope Point Structure Source: https://ddnet.org/docs/libtw2/map Defines the data fields for a sound envelope point, including time, curve type, and volume. ```plaintext sound envelope point: [1] time [1] curve type [1] volume [3] - ``` -------------------------------- ### General Map Structure Source: https://ddnet.org/docs/libtw2/map Outlines the hierarchical organization of elements within a map datafile. ```text > Info > Images > Envelopes > Envelope Points > Groups > Layers > Auto Mappers (DDNet only) > Sounds (DDNet only) ``` -------------------------------- ### DDNet Map Group Item Data Structure Source: https://ddnet.org/docs/libtw2/map Defines the fields for item_data within map groups, including version-specific extensions for clipping and naming. Version 3 is the current standard for both Vanilla and DDNet. ```plaintext item_data of group items [1] version [1] x_offset [1] y_offset [1] x_parallax [1] y_parallax [1] start_layer [1] num_layers version 2 extension: [1] clipping: bool [1] clip_x [1] clip_y [1] clip_width [1] clip_height version 3 extension: [3] name: I32String ``` -------------------------------- ### DDNet Sound Item Data Structure Source: https://ddnet.org/docs/libtw2/map Defines the structure for sound items in DDNet. The 'external' field is always false, and 'data' points to opus sound data. Version 1 is used. ```plaintext item_data of sound items: [1] version [1] external: bool [1] &name: CString [1] &data [1] data_size ``` -------------------------------- ### Item Delta Structure Source: https://ddnet.org/docs/libtw2/snapshot Details the structure of an item delta, which describes changes to individual items within a snapshot. This includes type, ID, size, and the actual data delta. ```plaintext item_delta: [ 4] type_id [ 4] id [ 4] _size [*4] data_delta ``` -------------------------------- ### Teleporter Tile Type Structure Source: https://ddnet.org/docs/libtw2/map The 'Tele' tile type structure, used for teleporter entries and exits. It includes a number to group teleporters and an ID. ```plaintext 'Tele' tile type (consisting of bytes): [1] number [1] id ``` -------------------------------- ### Teeworlds Vital Chunk Header Structure Source: https://ddnet.org/docs/libtw2/packet Details the bit layout for vital chunk headers, including resend and vital flags, size, and sequence numbers. The sequence number is split into two parts, with the first part overlapping with the size field. ```text chunk_header_vital: [ 1] flag_resend [ 1] flag_vital [ 6] <---------- [ 4] sequence |-- size [ 4] <---------- [ 8] sequence part 2 FFss ssss SSSS ssss SSSS SSSS ``` -------------------------------- ### Teeworlds Non-Vital Chunk Header Structure Source: https://ddnet.org/docs/libtw2/packet Specifies the bit layout for non-vital chunk headers, including resend and vital flags, size, and padding. The size field is 6 bits. ```text chunk_header_nonvital: [ 1] flag_resend [ 1] flag_vital [ 6] <---------- [ 4] padding |-- size [ 4] <---------- FFss ssss PPPP ssss ``` -------------------------------- ### Snapshot Delta Structure Source: https://ddnet.org/docs/libtw2/snapshot Defines the structure of a snapshot delta, used to represent differences between two snapshots. This format is crucial for reconstructing the new snapshot state from an old one and a delta. ```plaintext snapshot_delta: [ 4] num_removed_items [ 4] num_item_deltas [ 4] _zero [*4] removed_item_keys [ ] item_deltas ``` -------------------------------- ### Connectionless Packet Structure Source: https://ddnet.org/docs/libtw2/protocol Defines the structure of a connectionless packet in the Teeworlds protocol. The reference implementation primarily checks the `flag_connless` header flag. ```plaintext packet_connless: [24] packet_header [24] padding [ ] payload ``` -------------------------------- ### Deprecated Sound Source Structure Source: https://ddnet.org/docs/libtw2/map Defines the structure for a deprecated SoundSource, which uses fewer bytes than the current SoundSource and omits panning and shape details. ```plaintext deprecated SoundSource: [2] position: Point [1] looping: bool [1] delay [1] radius [1] *position_envelope [1] position_envelope_offset [1] *sound_envelope [1] sound_envelope_offset ``` -------------------------------- ### Map Item Type IDs Source: https://ddnet.org/docs/libtw2/map Lists the type_id mappings for various elements within a map datafile. ```text type_id mappings: 0 -> Version 1 -> Info 2 -> Images 3 -> Envelopes 4 -> Groups 5 -> Layers 6 -> Envelope Points 7 -> Sounds (DDNet only) 0xffff -> UUID Index (see below, DDNet only) ``` -------------------------------- ### Position Envelope Point Structure Source: https://ddnet.org/docs/libtw2/map Defines the data fields for a position envelope point, including time, curve type, x, y, and rotation. ```plaintext position envelope point: [1] time [1] curve_type [1] x [1] y [1] rotation [1] - ``` -------------------------------- ### Color Envelope Point Structure Source: https://ddnet.org/docs/libtw2/map Defines the data fields for a color envelope point, including time, curve type, and RGBA color values. ```plaintext color envelope point: [1] time [1] curve type [4] color: I32Color ```