Skip to content

Commit ba76b33

Browse files
committed
Reach keep alive state in 0.6
1 parent 6386966 commit ba76b33

6 files changed

+54
-11
lines changed

src/data/logger.asm

+2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ l_s_logger equ $ - s_logger
4343

4444
; null terminated C strings
4545

46+
c_invalid_length_ddnet_only db "error: got unexpected packet length for 0.6 connection. Only servers with ddnet security tokens are supported in 0.6", 0x00
4647
c_connect6 db "connecting using 0.6 ddnet protocol to ", 0x00
4748
c_connect7 db "connecting using 0.7 protocol to ", 0x00
4849
c_map_change db "got map change. new map: ", 0x00
4950
c_motd db "motd", 0x00
5051
c_chat db "chat", 0x00
5152
c_broadcast db "broadcast", 0x00
5253
c_client db "client", 0x00
54+
c_error db "error", 0x00

src/data/teeworlds.asm

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ MSG_CTRL_TOKEN equ 5
1111
MSG6_CTRL_KEEPALIVE equ 0
1212
MSG6_CTRL_CONNECT equ 1
1313
MSG6_CTRL_CONNECTACCEPT equ 2
14-
; MSG6_CTRL_ACCEPT equ 3 ; UNUSED!
14+
MSG6_CTRL_ACCEPT equ 3
1515
MSG6_CTRL_CLOSE equ 4
1616

1717
MSG_SYSTEM_NULL equ 0

src/logger.asm

+18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
; vim: set tabstop=4:softtabstop=4:shiftwidth=4
22
; vim: set expandtab:
33

4+
throw_c_str:
5+
; throw_c_str [rax]
6+
; rax = null terminated string with error message
7+
; logs with log level error and terminates the process
8+
mov r9, rax
9+
mov rax, c_error
10+
mov rdi, r9
11+
call log_error
12+
exit 1
13+
ret
14+
415
build_log_line:
516
; log_info [rax]
617
; rax = null terminated label
@@ -78,6 +89,13 @@ log_info:
7889
pop_registers
7990
ret
8091

92+
log_error:
93+
; log_error [rax]
94+
; rax = null terminated label
95+
; rdi = null terminated string
96+
call log_info
97+
ret
98+
8199
log_debug:
82100
; log_debug [rax]
83101
; rax = null terminated label

src/packet_packer.asm

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ send_packet6:
7575
call set_packet_header
7676

7777
; append ddnet security token at the end of all packet payloads
78-
packet6_pack_raw token, 4
78+
packet6_pack_raw peer_token, 4
7979

8080
; buf
8181
mov rax, udp_send_buf

src/receive_control6.asm

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
on_ctrl6_msg_connect_accept:
2-
; ignore cursed token only ddnet servers send
3-
; https://github.com/ddnet/ddnet/issues/8805
2+
; in addition to checking the length
3+
; we could also check for the "TKEN"
4+
; magic in front of the token
45

5-
; mov rax, [udp_recv_buf + 8]
6-
; mov [peer_token], rax
6+
mov eax, dword [udp_read_len]
7+
cmp eax, 12
8+
je .len_ok
9+
mov rax, c_invalid_length_ddnet_only
10+
call throw_c_str
11+
.len_ok:
12+
13+
mov rax, [udp_recv6_buf + PACKET6_HEADER_LEN + 5]
14+
mov [peer_token], eax
15+
print_label s_got_peer_token
16+
mov rax, peer_token
17+
mov rdi, 4
18+
call print_hexdump
19+
call print_newline
720

821
print_label s_got_accept
22+
call send_ctrl6_msg_ack_accept
923
; call send_msg_info
1024

1125
jmp on_ctrl6_message_end

src/send_control.asm

+14-5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@ send_ctrl_close:
3030
send_ctrl_msg_connect6:
3131
push rax
3232

33-
mov byte [token+0], 0xff
34-
mov byte [token+1], 0xff
35-
mov byte [token+2], 0xff
36-
mov byte [token+3], 0xff
3733

38-
packet6_pack_byte MSG_CTRL_CONNECT
34+
packet6_pack_byte MSG6_CTRL_CONNECT
3935
packet6_pack_raw MAGIC_TKEN, 4
4036

4137
mov byte [out_packet_header_flags], PACKETFLAG6_CONTROL
@@ -45,6 +41,19 @@ send_ctrl_msg_connect6:
4541
pop rax
4642
ret
4743

44+
send_ctrl6_msg_ack_accept:
45+
push rax
46+
47+
packet6_pack_byte MSG6_CTRL_ACCEPT
48+
; packet6_pack_raw [peer_token], 4
49+
50+
mov byte [out_packet_header_flags], PACKETFLAG6_CONTROL
51+
mov byte [out_packet_header_num_chunks], 0
52+
call send_packet
53+
54+
pop rax
55+
ret
56+
4857
send_ctrl_msg_connect:
4958
push rax
5059
mov al, byte [connection_version]

0 commit comments

Comments
 (0)