Skip to content

Commit bcf6f18

Browse files
committed
Draft totally work in progress 0.6 ctrl msg receiving
1 parent 8eee4e1 commit bcf6f18

File tree

6 files changed

+99
-1
lines changed

6 files changed

+99
-1
lines changed

Diff for: src/data/teeworlds.asm

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ MSG_CTRL_ACCEPT equ 2
88
MSG_CTRL_CLOSE equ 4
99
MSG_CTRL_TOKEN equ 5
1010

11+
MSG6_CTRL_KEEPALIVE equ 0
12+
MSG6_CTRL_CONNECT equ 1
13+
MSG6_CTRL_CONNECTACCEPT equ 2
14+
; MSG6_CTRL_ACCEPT equ 3 ; UNUSED!
15+
MSG6_CTRL_CLOSE equ 4
16+
1117
MSG_SYSTEM_NULL equ 0
1218
MSG_SYSTEM_INFO equ 1
1319
MSG_SYSTEM_MAP_CHANGE equ 2

Diff for: src/on_packet.asm

+9-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,15 @@ on_packet_end:
154154
ret
155155

156156
on_packet6:
157-
puts "0.6 not implemented yet"
157+
158+
push rax
159+
mov rax, udp_recv_buf
160+
call unpack_packet_header6
161+
pop rax
162+
163+
is_packet_in_flag PACKETFLAG6_CONTROL
164+
je on_ctrl6_message
165+
158166
jmp on_packet_end
159167

160168
on_packet7:

Diff for: src/packet_header.asm

+28
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,31 @@ unpack_packet_header:
3535
pop_registers
3636
ret
3737

38+
unpack_packet_header6:
39+
; unpack_packet_header6 [rax]
40+
; rax = buffer to unpack
41+
; warning this is not getting the ddnet security token!
42+
; because it is at the end of the payload
43+
; so it is parsed at a later point in time
44+
push_registers
45+
46+
; dereference pointer
47+
mov rcx, [rax]
48+
; move 1 byte at offset 0
49+
mov byte [in_packet_header_flags], cl
50+
51+
; dereference pointer
52+
mov rcx, [rax + 2]
53+
; move 1 byte at offset 2
54+
mov byte [in_packet_header_num_chunks], cl
55+
56+
; explicitly empty the token field to avoid confusion
57+
; we do not know the token yet!
58+
mov byte [in_packet_header_token+0], 0xff
59+
mov byte [in_packet_header_token+1], 0xff
60+
mov byte [in_packet_header_token+2], 0xff
61+
mov byte [in_packet_header_token+3], 0xff
62+
63+
pop_registers
64+
ret
65+

Diff for: src/receive_control6.asm

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
on_ctrl6_msg_connect_accept:
2+
; ignore cursed token only ddnet servers send
3+
; https://github.com/ddnet/ddnet/issues/8805
4+
5+
; mov rax, [udp_recv_buf + 8]
6+
; mov [peer_token], rax
7+
8+
print_label s_got_accept
9+
; call send_msg_info
10+
11+
jmp on_ctrl6_message_end
12+
13+
on_ctrl6_msg_close:
14+
push rax
15+
16+
mov rax, [packet_payload + 1]
17+
cmp rax, 0
18+
je .on_ctrl6_msg_close_no_reason
19+
20+
.on_ctrl6_msg_close_reason:
21+
print_label s_got_disconnect_with_reason
22+
lea rax, [packet_payload + 1]
23+
print_c_str rax
24+
call print_newline
25+
jmp .on_ctrl6_msg_close_end
26+
27+
.on_ctrl6_msg_close_no_reason:
28+
print_label s_got_disconnect
29+
30+
.on_ctrl6_msg_close_end:
31+
exit 0
32+
pop rax
33+
jmp on_ctrl6_message_end
34+
35+
on_ctrl6_message:
36+
push_registers ; popped in on_ctrl6_message_end
37+
38+
print_label s_got_ctrl_msg
39+
40+
mov al, [udp_recv_buf + PACKET_HEADER_LEN]
41+
call println_uint32
42+
43+
cmp al, MSG6_CTRL_CONNECTACCEPT
44+
je on_ctrl6_msg_connect_accept
45+
cmp al, MSG6_CTRL_CLOSE
46+
je on_ctrl6_msg_close
47+
48+
print_label s_unknown_ctrl_msg
49+
call println_uint32
50+
51+
on_ctrl6_message_end:
52+
pop_registers ; pushed in on_ctrl6_message
53+
jmp on_packet_end
54+

Diff for: src/teeworlds_asmr.asm

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ section .text
140140
%include "src/send_system.asm"
141141
%include "src/send_game.asm"
142142
%include "src/receive_control.asm"
143+
%include "src/receive_control6.asm"
143144
%include "src/system.asm"
144145
%include "src/string.asm"
145146
%include "src/packet_header.asm"

Diff for: tests/assert.asm

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ section .text
7373
%include "src/send_system.asm"
7474
%include "src/send_game.asm"
7575
%include "src/receive_control.asm"
76+
%include "src/receive_control6.asm"
7677
%include "src/system.asm"
7778
%include "src/string.asm"
7879
%include "src/packet_header.asm"

0 commit comments

Comments
 (0)