Skip to content

Commit

Permalink
clean up start_client function (#37)
Browse files Browse the repository at this point in the history
* add constructor for ConnectionRequestPacket

* use get_serialized_data method for ConnectionRequestPacket

* rearrange some things in start_client function
  • Loading branch information
Sid-Bhatia-0 committed Mar 23, 2024
1 parent d922226 commit 9af3bbe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
23 changes: 6 additions & 17 deletions netcode/simulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,28 +153,17 @@ function start_client(auth_server_address, username, password)
error("Invalid connect token packet received")
end

app_server_address = get_inetaddr(first(connect_token_packet.netcode_addresses))

@info "Client obtained app_server_address" app_server_address
connection_request_packet = ConnectionRequestPacket(connect_token_packet)
pprint(connection_request_packet)

socket = Sockets.UDPSocket()

connection_request_packet = ConnectionRequestPacket(
PACKET_TYPE_CONNECTION_REQUEST_PACKET,
connect_token_packet.netcode_version_info,
connect_token_packet.protocol_id,
connect_token_packet.expire_timestamp,
connect_token_packet.nonce,
connect_token_packet.encrypted_private_connect_token_data,
)
size_of_connection_request_packet = get_serialized_size(connection_request_packet)
io_connection_request_packet = IOBuffer(maxsize = size_of_connection_request_packet)
connection_request_packet_length = write(io_connection_request_packet, connection_request_packet)
@assert connection_request_packet_length == size_of_connection_request_packet
connection_request_packet_data = get_serialized_data(connection_request_packet)

pprint(connection_request_packet)
app_server_address = get_inetaddr(first(connect_token_packet.netcode_addresses))
@info "Client obtained app_server_address" app_server_address

Sockets.send(socket, app_server_address.host, app_server_address.port, io_connection_request_packet.data)
Sockets.send(socket, app_server_address.host, app_server_address.port, connection_request_packet_data)

return nothing
end
Expand Down
11 changes: 11 additions & 0 deletions netcode/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,14 @@ function ConnectTokenPacket(connect_token_info::ConnectTokenInfo)
connect_token_info.server_to_client_key,
)
end

function ConnectionRequestPacket(connect_token_packet::ConnectTokenPacket)
return ConnectionRequestPacket(
PACKET_TYPE_CONNECTION_REQUEST_PACKET,
connect_token_packet.netcode_version_info,
connect_token_packet.protocol_id,
connect_token_packet.expire_timestamp,
connect_token_packet.nonce,
connect_token_packet.encrypted_private_connect_token_data,
)
end

0 comments on commit 9af3bbe

Please sign in to comment.