| 8 | 
   | 
 #include <stdbool.h> | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 9 | 
   | 
 #include <stdint.h> | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 10 | 
   | 
  | 
 
 
 
 
 
 
 
 
 | 11 | 
 + | 
 #define thread __thread | 
 
 
 
 
 
 
 
 
 | 12 | 
 + | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 13 | 
   | 
 #ifdef WIN32 | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 14 | 
   | 
 #include <winsock2.h> | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 15 | 
   | 
 #include "Flatline_Win32.h" | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 28 | 
   | 
 #define ioctlsocket ioctl | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 29 | 
   | 
 #endif | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 30 | 
   | 
  | 
 
 
 
 
 
 
 
 
 | 31 | 
 + | 
 #define pad1_size (sizeof(int64_t) - sizeof(short)) | 
 
 
 
 
 
 
 
 
 | 32 | 
 + | 
 #define pad2_size (128 - (sizeof(short) + pad1_size + sizeof(int64_t))) | 
 
 
 
 
 
 
 
 
 | 33 | 
 + | 
  | 
 
 
 
 
 
 
 
 
 | 34 | 
 + | 
 typedef struct { | 
 
 
 
 
 
 
 
 
 | 35 | 
 + | 
         short ss_family; | 
 
 
 
 
 
 
 
 
 | 36 | 
 + | 
         char pad1[pad1_size]; | 
 
 
 
 
 
 
 
 
 | 37 | 
 + | 
         uint64_t pad64; | 
 
 
 
 
 
 
 
 
 | 38 | 
 + | 
         char pad2[pad2_size]; | 
 
 
 
 
 
 
 
 
 | 39 | 
 + | 
 } sockaddr_storage; | 
 
 
 
 
 
 
 
 
 | 40 | 
 + | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 41 | 
   | 
 typedef struct sockaddr sockaddr; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 42 | 
   | 
 typedef struct sockaddr_in sockaddr_in; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 43 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 | 44 | 
 < | 
 bool Net_Listen(uint16_t port, bool (*packet_callback)(char* data, int datalen, int from)); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 45 | 
 < | 
 int Net_CreateSocket(uint16_t port); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 46 | 
 < | 
 bool Net_Send(int socket, int ip, uint16_t port, char* data, int datalen); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 47 | 
 < | 
 void Net_CloseSocket(int sock); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 44 | 
 > | 
 bool NetUDPServer_Listen(uint16_t port, bool (*packet_callback)(char* data, int datalen, int from)); | 
 
 
 
 
 
 | 45 | 
 > | 
 bool NetUDPServer_Send(sockaddr* address, char* data, int datalen) | 
 
 
 
 
 
 | 46 | 
 > | 
  | 
 
 
 
 
 
 | 47 | 
 > | 
 int NetUDPSocket_Create(uint16_t port); | 
 
 
 
 
 
 | 48 | 
 > | 
 bool NetUDPSocket_Send(int socket, int ip, uint16_t port, char* data, int datalen); | 
 
 
 
 
 
 | 49 | 
 > | 
 void NetUDPSocket_Close(int sock); | 
 
 
 
 
 
 | 50 | 
 > | 
  | 
 
 
 
 
 
 | 51 | 
 > | 
 typedef struct { | 
 
 
 
 
 
 | 52 | 
 > | 
         char signature[8]; | 
 
 
 
 
 
 | 53 | 
 > | 
         uint16_t protocol_version; | 
 
 
 
 
 
 | 54 | 
 > | 
         char data[0]; | 
 
 
 
 
 
 | 55 | 
 > | 
 } handshake_packet; | 
 
 
 
 
 
 | 56 | 
 > | 
  | 
 
 
 
 
 
 | 57 | 
 > | 
 typedef struct { | 
 
 
 
 
 
 | 58 | 
 > | 
         char country[2]; | 
 
 
 
 
 
 | 59 | 
 > | 
         char name[256]; | 
 
 
 
 
 
 | 60 | 
 > | 
 } connect_send; //signature="CONNECT\0" | 
 
 
 
 
 
 | 61 | 
 > | 
  | 
 
 
 
 
 
 | 62 | 
 > | 
 typedef struct { | 
 
 
 
 
 
 | 63 | 
 > | 
         char name[256]; | 
 
 
 
 
 
 | 64 | 
 > | 
         uint32_t numplayers; //signature="STATUS\0\0" | 
 
 
 
 
 
 | 65 | 
 > | 
 } status_recv; | 
 
 
 
 
 
 | 66 | 
 > | 
  | 
 
 
 
 
 
 | 67 | 
 > | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 | 68 | 
   | 
 bool FLrListen_PacketCallback(char* data, int datalen, int from); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 69 | 
   | 
 bool FLrListen_Run(); |