Skip to content

Commit

Permalink
Correctly parse the servers accept connect in 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Dec 17, 2024
1 parent bcf6f18 commit 6386966
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/bss/teeworlds.asm
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ socket resb 4
; the compression flag
; if the compression flag is set there will be a decompressed payload in
; the label decompressed_packet_payload
udp_recv_buf resb 7
udp_recv_buf resb PACKET_HEADER_LEN
packet_payload resb NET_MAX_PACKETSIZE ; 1400

; 0.6.4 packet header offsets
udp_recv6_buf resb PACKET6_HEADER_LEN
packet6_payload resb NET_MAX_PACKETSIZE ; 1400

; only set if the packet is compressed
; otherwise look at the label packet_payload
decompressed_packet_payload resb NET_MAX_PAYLOAD ; 1391
Expand Down
2 changes: 1 addition & 1 deletion src/on_packet.asm
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ on_packet_end:
on_packet6:

push rax
mov rax, udp_recv_buf
mov rax, udp_recv6_buf
call unpack_packet_header6
pop rax

Expand Down
6 changes: 3 additions & 3 deletions src/receive_control6.asm
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ on_ctrl6_msg_connect_accept:
on_ctrl6_msg_close:
push rax

mov rax, [packet_payload + 1]
mov rax, [packet6_payload + 1]
cmp rax, 0
je .on_ctrl6_msg_close_no_reason

.on_ctrl6_msg_close_reason:
print_label s_got_disconnect_with_reason
lea rax, [packet_payload + 1]
lea rax, [packet6_payload + 1]
print_c_str rax
call print_newline
jmp .on_ctrl6_msg_close_end
Expand All @@ -37,7 +37,7 @@ on_ctrl6_message:

print_label s_got_ctrl_msg

mov al, [udp_recv_buf + PACKET_HEADER_LEN]
mov al, [udp_recv6_buf + PACKET6_HEADER_LEN]
call println_uint32

cmp al, MSG6_CTRL_CONNECTACCEPT
Expand Down
17 changes: 16 additions & 1 deletion src/teeworlds_asmr.asm
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,24 @@ section .text
%include "src/client_info.asm"
%include "src/on_chat.asm"

get_recv_buf:
; returns into rax either `udp_recv_buf` or `udp_recv6_buf`
; depending on the current connection version
mov al, byte [connection_version]
cmp al, 7
je .version7
.version6:
mov rax, udp_recv6_buf
jmp .end
.version7:
mov rax, udp_recv_buf
.end:
ret

print_udp:
print_label s_got_udp
; hexdump
mov rax, udp_recv_buf
call get_recv_buf
mov rdi, [udp_read_len]
call print_hexdump
call print_newline
Expand All @@ -178,6 +192,7 @@ on_udp_packet:

pump_network:
; print_label s_non_blocking_read
call get_recv_buf
call recv_udp
mov rax, [udp_read_len]
test rax, rax
Expand Down
16 changes: 13 additions & 3 deletions src/udp.asm
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,24 @@ open_socket:
ret

recv_udp:
; recv_udp
; recv_udp [rax]
; rax = buffer to write to
;
; example call:
;
; mov rax, udp_recv_buf
; call recv_udp
;
; listens for udp packet on the
; `socket` and fills the `udp_recv_buf`
; `socket` and fills the buffer in rax
; which usually is `udp_recv_buf` or `udp_recv6_buf`
push_registers
; output buffer
mov r9, rax

mov rax, SYS_RECVFROM
movzx rdi, byte [socket] ; then only set the lowest byte
lea rsi, udp_recv_buf
mov rsi, r9 ; pointer to buffer `udp_recv_buf` or `udp_recv6_buf`
mov rdx, NET_MAX_PACKETSIZE
; flags
xor r10, r10
Expand Down

0 comments on commit 6386966

Please sign in to comment.