forked from LiardeauxQ/r-type
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rfc.txt
606 lines (380 loc) · 18.7 KB
/
rfc.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
Internet Engineering Task Force A. Kilian Perrier, Ed.
Internet-Draft EPITECH
Intended status: Experimental December 2015
Expires: June 3, 2016
Binary protocol for the R-Type project
Abstract
This document describes the binary protocol used for the R-Type
project.
Status of This Memo
This Internet-Draft is submitted in full conformance with the
provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF). Note that other groups may also distribute
working documents as Internet-Drafts. The list of current Internet-
Drafts is at http://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months
and may be updated, replaced, or obsoleted by other documents at any
time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress."
This Internet-Draft will expire on June 3, 2016.
Copyright Notice
Copyright (c) 2015 IETF Trust and the persons identified as the
document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents
(http://trustee.ietf.org/license-info) in effect on the date of
publication of this document. Please review these documents
carefully, as they describe your rights and restrictions with respect
to this document. Code Components extracted from this document must
include Simplified BSD License text as described in Section 4.e of
the Trust Legal Provisions and are provided without warranty as
described in the Simplified BSD License.
Kilian Perrier Expires June 3, 2016 [Page 1]
Internet-Draft Abbreviated Title December 2015
Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1. Requirements Language . . . . . . . . . . . . . . . . . . 2
2. Data Format . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1. Header . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2. Body . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3. TCP Communications . . . . . . . . . . . . . . . . . . . . . 3
3.1. ERROR . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.2. CREATE_GAME . . . . . . . . . . . . . . . . . . . . . . . 4
3.3. JOIN_GAME . . . . . . . . . . . . . . . . . . . . . . . . 4
3.4. ROOM_INFO . . . . . . . . . . . . . . . . . . . . . . . . 5
3.5. ROOM_PLAYER_JOIN, ROOM_PLAYER_QUIT . . . . . . . . . . . 6
3.6. ROOM_PLAYER_STATE . . . . . . . . . . . . . . . . . . . . 6
3.7. GAME_START . . . . . . . . . . . . . . . . . . . . . . . 7
3.8. LIST_STAGES . . . . . . . . . . . . . . . . . . . . . . . 7
3.9. LIST_OF_STAGES . . . . . . . . . . . . . . . . . . . . . 7
3.10. LIST_GAMES . . . . . . . . . . . . . . . . . . . . . . . 8
3.11. LIST_OF_GAMES . . . . . . . . . . . . . . . . . . . . . . 8
4. UDP Communications . . . . . . . . . . . . . . . . . . . . . 8
4.1. GAME_READY . . . . . . . . . . . . . . . . . . . . . . . 8
4.2. FIRE_ENTITY . . . . . . . . . . . . . . . . . . . . . . . 9
4.3. STATE_ENTITY . . . . . . . . . . . . . . . . . . . . . . 9
4.4. MOVE . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.5. SYNC_DIST . . . . . . . . . . . . . . . . . . . . . . . . 10
5. Security Considerations . . . . . . . . . . . . . . . . . . . 10
6. References . . . . . . . . . . . . . . . . . . . . . . . . . 10
6.1. Normative References . . . . . . . . . . . . . . . . . . 10
6.2. Informative References . . . . . . . . . . . . . . . . . 10
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 10
1. Introduction
This memo documents every aspect of the binary protocol used in the
R-Type game.
Every package will be documented below, classified by its network
protocol it MUST be sent with: TCP (described in RFC 0793 [RFC0793])
or UDP (described in RFC 0768 [RFC0768]).
1.1. Requirements Language
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in RFC 2119 [RFC2119].
Kilian Perrier Expires June 3, 2016 [Page 2]
Internet-Draft Abbreviated Title December 2015
2. Data Format
Each packet, regardless of it's network protocol MUST be preceded by
a common header described below.
+-------------------+
| MESSAGE |
| +---------------+ |
| | HEADER | BODY | |
| +---------------+ |
+-------------------+
2.1. Header
+--------------+-------------+-------------+
| magic_number | packet_id | packet_size |
+--------------+-------------+-------------+
| 4 bytes | 4 bytes | 4 bytes |
+--------------+-------------+-------------+
Structure of a header
The header is composed of a magic number which SHOULD be used to do a
primary sanity check of the packet.
The value of magic_number MUST be 0x522d5459 (ASCII R-TY)
The packet_size is used to allocate memory for the message and handle
it properly.
The hashed_name is used to know in which packet it must be deserialized.
2.2. Body
+-----------------------------------------------------------------------+
| BODY |
| +------------------------------+ +------------------------------+ |
| | type | type_info | data | | type | type_info | data | ... |
| +------------------------------+ +------------------------------+ ... |
| | 1 bytes | depend | depend | | 1 bytes | depend | depend | ... |
| +------------------------------+ +------------------------------+ |
+-----------------------------------------------------------------------+
Each packet contains a BODY, which contain sub-body.
Each sub-body contain the type to be deserialized, the type_info linked
to the previously defined type and the data.
type_info marked as None has a len of 0.
2.2.0. Char
type: 0x1
type_info: None
size: 1 byte
2.2.2. Int
type: 0x2
type_info: None
size: 8 bytes
2.2.3. Float
type: 0x3
type_info: None
size: 8 bytes
2.2.4. List
type: 0x4
type_info:
type: uint8_t
length: uint64_t (8 bytes)
size: `type.size` * `length`
For example "Hello, World" string is serialized as:
type: 0x4
type_info:
type: 0x1
length: 0xC
size: 0xC
3. TCP Communications
The following packets MUST be implemented as described below.
Strings MUST be null terminated.
Each packet MUST be preceded by a common header.
The TCP protocol is used for all communication that is not a direct
game action.
In other words, every command related to the management of a room
MUST be sent using the TCP network protocol
Kilian Perrier Expires June 3, 2016 [Page 3]
Internet-Draft Abbreviated Title December 2015
This protocol has been chosen to provide a reliable communication
tunnel between a client and the server during crucial actions, where
packet loss is not tolerable (unlike game actions).
3.1. ERROR
Command code: 0x00
Direction: client <=> server
This command is sent whenever an error was found during the
processing of an other command.
+--------------+------------+
| command_code | error_code |
+--------------+------------+
| uint8_t | uint8_t |
+--------------+------------+
Structure of a ERROR message
3.2. CREATE_GAME
Command code: 0x01
Direction: client => server
Error codes:
0x01: A room with this name already exists
This command allows the client to create a room to which other
clients can join and prepare before actually playing.
The client creating the room becomes the owner of the said room.
In case of success, the server answers with a ROOM_INFO packet.
+--------------+--------------+--------------+
| name | password | nickname |
+--------------+--------------+--------------+
| uint8_t[256] | uint8_t[256] | uint8_t[256] |
+--------------+--------------+--------------+
Structure of a CREATE_GAME message
3.3. JOIN_GAME
Command code: 0x02
Direction: client => server
Kilian Perrier Expires June 3, 2016 [Page 4]
Internet-Draft Abbreviated Title December 2015
Error codes:
0x01: Unknown room
0x02: Wrong password / no password provided for a private room
0x03: Nickname is already taken
0x04: Game is full
This command allows a client to join an existing room. The
associated game must be waiting for clients (i.e. not started) for
this command to succeed. The client MUST provide a valid id_game
(fetch-able from the LIST_OF_GAMES packet).
If the room is protected by a password, the client can provide it
with the password field, or leave it empty.
The client MUST choose a unique and valid nickname.
Upon success, the server answers with a ROOM_INFO packet.
+----------+--------------+--------------+
| id_game | password | nickname |
+----------+--------------+--------------+
| uint32_t | uint8_t[256] | uint8_t[256] |
+----------+--------------+--------------+
Structure of a JOIN_GAME message
3.4. ROOM_INFO
Command code: 0x03
Direction: server => client
This packet is sent by the server when a client successfully joins a
room (either with CREATE_GAME or JOIN_GAME).
+----------+--------------+------------+-------------+-----------+
| id_game | name | nb_players | max_players | id_player |
+----------+--------------+------------+-------------+-----------+
| uint32_t | uint8_t[256] | uint8_t | uint8_t | uint8_t |
+----------+--------------+------------+-------------+-----------+
Structure of a ROOM_INFO message
This packet is then followed by nb_players times the following data
structure:
Kilian Perrier Expires June 3, 2016 [Page 5]
Internet-Draft Abbreviated Title December 2015
+-----------+--------------+----------+
| id_player | nickname | is_ready |
+-----------+--------------+----------+
| uint8_t | uint8_t[256] | uint8_t |
+-----------+--------------+----------+
PLAYER_INFO data structure
3.5. ROOM_PLAYER_JOIN, ROOM_PLAYER_QUIT
Command codes:
0x04 - ROOM_PLAYER_JOIN
0x05 - ROOM_PLAYER_QUIT
Direction: server => client
ROOM_PLAYER_JOIN: This packet is sent to every client in a room when
a new client joins the room.
ROOM_PLAYER_QUIT: This packet is sent to every client in a room when
a new client quits the room.
+-----------+--------------+----------+
| id_player | nickname | is_ready |
+-----------+--------------+----------+
| uint8_t | uint8_t[256] | uint8_t |
+-----------+--------------+----------+
Structure of a ROOM_PLAYER_JOIN or ROOM_PLAYER_QUIT message
3.6. ROOM_PLAYER_STATE
Command code: 0x06
Direction: client <=> server
Error codes:
0x03: Nickname is already taken
This packet is sent from the server to every client when a client
changes its state (ready or not).
This packet is also sent from a client to the server to change a
client's state. The server MUST answer with a ROOM_PLAYER_STATE
packet confirming the action.
Kilian Perrier Expires June 3, 2016 [Page 6]
Internet-Draft Abbreviated Title December 2015
+-----------+--------------+----------+
| id_player | nickname | is_ready |
+-----------+--------------+----------+
| uint8_t | uint8_t[256] | uint8_t |
+-----------+--------------+----------+
Structure of a ROOM_PLAYER_STATE message
3.7. GAME_START
Command code: 0x07
Direction: server => client
This packet is sent to every client in the room when the server
decides that the game should start. The message provides an UDP port
which MUST be opened on the server for the clients to connect with
the GAME_READY packet described later.
+----------+
| udp_port |
+----------+
| uint16_t |
+----------+
Structure of a GAME_START message
3.8. LIST_STAGES
Command code: 0x08
Direction: client => server
3.9. LIST_OF_STAGES
Command code: 0x09
Direction: server => client
+----------+-----------------+
| nb_games | games |
+----------+-----------------+
| uint32_t | game_list_info* |
+----------+-----------------+
Structure of a LIST_OF_STAGES message
Kilian Perrier Expires June 3, 2016 [Page 7]
Internet-Draft Abbreviated Title December 2015
+----------+--------------+------------+------------+-------------+
| id_game | name | is_private | nb_players | max_players |
+----------+--------------+------------+------------+-------------+
| uint32_t | uint8_t[256] | uint8_t | uint8_t | uint8_t |
+----------+--------------+------------+------------+-------------+
game_list_info
3.10. LIST_GAMES
Command code: 0x0A
Direction: client => server
3.11. LIST_OF_GAMES
Command code: 0x0B
Direction: server => client
+----------+-----------------+
| nb_games | games |
+----------+-----------------+
| uint32_t | game_list_info* |
+----------+-----------------+
Structure of a LIST_OF_GAMES message
+----------+--------------+------------+------------+-------------+
| id_game | name | is_private | nb_players | max_players |
+----------+--------------+------------+------------+-------------+
| uint32_t | uint8_t[256] | uint8_t | uint8_t | uint8_t |
+----------+--------------+------------+------------+-------------+
game_list_info
4. UDP Communications
The following packets MUST be implemented as described below.
Strings MUST be null terminated.
Each packet MUST be preceded by a common header.
4.1. GAME_READY
Command code: 0x0C
Direction: client => server
Kilian Perrier Expires June 3, 2016 [Page 8]
Internet-Draft Abbreviated Title December 2015
+-----------+
| id_player |
+-----------+
| uint8_t |
+-----------+
Structure of a GAME_READY message
4.2. FIRE_ENTITY
Command code: 0x0D
Direction: client => server
+---------------+----------+
| id_new_entity | type |
+---------------+----------+
| uint16_t | FireType |
+---------------+----------+
Structure of a FIRE_ENTITY message
4.3. STATE_ENTITY
Command code: 0x0E
Direction: server => client
+-----------+--------------------+--------------------+----------+
| id_entity | position | velocity | angle |
+-----------+--------------------+--------------------+----------+
| uint16_t | vector2d<uint32_t> | vector2d<uint32_t> | uint16_t |
+-----------+--------------------+--------------------+----------+
Structure of a STATE_ENTITY message
4.4. MOVE
Command code: 0x0F
Direction: client => server
+-----------+
| dir |
+-----------+
| Direction |
+-----------+
Structure of a MOVE message
Kilian Perrier Expires June 3, 2016 [Page 9]
Internet-Draft Abbreviated Title December 2015
4.5. SYNC_DIST
Command code: 0x10
Direction: server => client
+----------+
| dist |
+----------+
| uint64_t |
+----------+
Structure of a SYNC_DIST message
5. Security Considerations
This RFC raises no security issues. However, security protocols are
subject to the fundamental networking truths.
6. References
6.1. Normative References
[min_ref] authSurName, authInitials., "Minimal Reference", 2006.
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
Requirement Levels", BCP 14, RFC 2119,
DOI 10.17487/RFC2119, March 1997,
<http://www.rfc-editor.org/info/rfc2119>.
6.2. Informative References
[RFC0768] Postel, J., "User Datagram Protocol", STD 6, RFC 768,
DOI 10.17487/RFC0768, August 1980,
<http://www.rfc-editor.org/info/rfc768>.
[RFC0793] Postel, J., "Transmission Control Protocol", STD 7,
RFC 793, DOI 10.17487/RFC0793, September 1981,
<http://www.rfc-editor.org/info/rfc793>.
Author's Address
Kilian Perrier (editor)
EPITECH
156 Rue Paul Bert
Lyon 69003
FR
Email: [email protected]
Kilian Perrier Expires June 3, 2016 [Page 10]