1 #ifndef PACKET_H_
2 #define PACKET_H_ 1
3 
4 enum packet_type
5 {
6   /* Server messages */
7   packet_create_game = 0x00,
8   packet_join_game = 0x01,
9   packet_start_game = 0x02,
10   packet_abort_game = 0x03,
11   packet_join_random_game = 0x04,
12   packet_identify = 0x05,
13   packet_login = 0x07,
14   packet_chat = 0x08,
15   packet_message = 0x09,
16   packet_eventlog = 0x0a,
17   packet_logout = 0x0b,
18   packet_please_reconnect = 0x0a,
19 
20   /* Client messages */
21   packet_movement = 0x10
22 };
23 
24 enum message
25 {
26   message_unknown_user = 0x00,
27   message_incorrect_password = 0x01,
28   message_login_ok = 0x02,
29 };
30 
31 struct network_mbubble
32 {
33   unsigned char x[4];
34   unsigned char y[4];
35   unsigned char velx[4];
36   unsigned char vely[4];
37   unsigned char falling;
38   unsigned char color;
39 };
40 
41 #define EVENT_SHOOT 0x80UL
42 #define EVENT_EVIL  0x40UL
43 #define EVENT_LEFT  0x20UL
44 #define EVENT_RIGHT 0x10UL
45 #define EVENT_START 0x08UL
46 #define EVENT_WIN   0x04UL
47 #define EVENT_LOSE  0x02UL
48 
49 struct event
50 {
51   unsigned char tick[3];
52   unsigned char data;
53 };
54 
55 struct data_packet
56 {
57   unsigned short payload_size;
58   unsigned char packet_type;
59 
60   union
61   {
62     struct
63     {
64       char name[32];
65     } create_game;
66 
67     struct
68     {
69       char name[32];
70     } join_game;
71 
72     struct
73     {
74       unsigned char registered_only;
75     } join_random_game;
76 
77     struct
78     {
79       unsigned char seed[4];
80       unsigned char other_host[4];
81       unsigned char port_lo;
82       unsigned char port_hi;
83       unsigned char is_server;
84       unsigned char peer_version;
85     } start_game;
86 
87     struct
88     {
89       char reason[32];
90     } abort_game;
91 
92     struct
93     {
94       char game[32];
95       unsigned char port_lo;
96       unsigned char port_hi;
97       char id[32];
98     } identify;
99 
100     struct
101     {
102       unsigned char angle[4];
103       unsigned char flags;
104       unsigned char bubbles;
105 
106       unsigned char field[53];
107       unsigned char mbubble_count;
108       struct network_mbubble mbubbles[128];
109     } movement;
110 
111     struct
112     {
113       char username[16];
114       char password[16];
115     } login;
116 
117     struct
118     {
119       unsigned char is_private;
120       unsigned char message[536];
121     } chat;
122 
123     struct
124     {
125       unsigned char idx;
126     } message;
127 
128     struct
129     {
130       struct event events[256];
131     } eventlog;
132 
133     unsigned char padding[65535];
134   };
135 };
136 
137 #endif /* PACKET_H_ */
138