antizona

antizona - Minimalist 3D software-rendered multiplayer engine for GTA: San Andreas in pure C99
Log | Files | Refs | README

net.h (1088B)


      1 #ifndef NET_H
      2 #define NET_H
      3 
      4 #include <stdint.h>
      5 
      6 #define NET_PORT	7777
      7 #define NET_MAGIC	0x415A
      8 #define MAX_PLAYERS	64
      9 #define MAX_CHAT_LEN	128
     10 
     11 enum packet_type {
     12 	PKT_JOIN,
     13 	PKT_JOIN_ACK,
     14 	PKT_LEAVE,
     15 	PKT_SYNC,
     16 	PKT_WORLD_STATE,
     17 	PKT_CHAT
     18 };
     19 
     20 struct pkt_header {
     21 	uint16_t	magic;
     22 	uint8_t		type;
     23 	uint8_t		player_id;
     24 } __attribute__((packed));
     25 
     26 struct pkt_join {
     27 	struct pkt_header	hdr;
     28 	char			name[24];
     29 	uint16_t		skin;
     30 } __attribute__((packed));
     31 
     32 struct pkt_join_ack {
     33 	struct pkt_header	hdr;
     34 	uint8_t			your_id;
     35 	float			game_time;
     36 	uint8_t			game_weather;
     37 } __attribute__((packed));
     38 
     39 struct pkt_sync {
     40 	struct pkt_header	hdr;
     41 	float			x, y, z;
     42 	float			yaw;
     43 	uint16_t		skin;
     44 } __attribute__((packed));
     45 
     46 struct player_state {
     47 	uint8_t		id;
     48 	uint16_t	skin;
     49 	float		x, y, z;
     50 	float		yaw;
     51 } __attribute__((packed));
     52 
     53 struct pkt_world_state {
     54 	struct pkt_header	hdr;
     55 	uint8_t			player_count;
     56 	struct player_state	players[MAX_PLAYERS];
     57 } __attribute__((packed));
     58 
     59 struct pkt_chat {
     60 	struct pkt_header	hdr;
     61 	char			name[24];
     62 	char			msg[MAX_CHAT_LEN];
     63 } __attribute__((packed));
     64 
     65 #endif