10 #include <sys/socket.h>
11 #include <arpa/inet.h>
12 #include <netinet/in.h>
14 #include <dragontype/number.h>
16 #define ever (;;) // infinite for loop with style
17 #define INBRACES(str) (str) ? "(" : "", (str) ? (str) : "", (str) ? ")" : "" // wrapper for printf to optionally add a message in braces if message is not NULL
18 #define CMPBOUNDS(x) ((x) == 0 ? 0 : (x) > 0 ? 1 : -1) // resolves to 1 if x > 0, 0 if x == 0 and -1 if x < 0
19 #define fallthrough __attribute__ ((fallthrough)) // prevent compiler warning about implicit fallthrough with style
20 #define unused __attribute__ ((unused))
21 #define U32(x) (((u32) 1 << 31) + (x))
23 extern const char *program_name; // this has to be set to program name on startup
25 void syscall_error(const char *err); // print system call related error message and exit
26 void internal_error(const char *err); // print general error message and exit
27 char *read_string(int fd, size_t bufsiz); // read from fd until \0 or EOF terminator
28 char *address_string(struct sockaddr_in6 *addr); // convert IPv6 address to human readable, return allocated buffer
29 void my_compress(const void *uncompressed, size_t uncompressed_size, char **compressed, size_t *compressed_size); // compress data using ZLib and store result(buffer allocated by malloc) in compressed
30 bool my_decompress(const char *compressed, size_t compressed_size, void *decompressed, size_t expected_decompressed_size); // decompress data and put result into decompressed, return false if decompressed size does not match expected_decompressed_size
31 bool within_simulation_distance(v3f64 player_pos, v3s32 block_pos, u32 simulation_distance); // return true if a player is close enough to a block to access it
32 f64 clamp(f64 v, f64 min, f64 max);
33 char *format_string(const char *format, ...);
34 void *buffer_read(unsigned char **buffer, size_t *bufsiz, size_t size);
35 void buffer_write(unsigned char **buffer, size_t *bufsiz, void *data, size_t size);