Skip to content

Commit

Permalink
pretty printing (#35)
Browse files Browse the repository at this point in the history
* add package GarishPrint to project files

* use GarishPrint to pretty print connect_token_info

* add and use function pprint
  • Loading branch information
Sid-Bhatia-0 authored Mar 23, 2024
1 parent e305d4d commit fde199a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
19 changes: 18 additions & 1 deletion netcode/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.2"
manifest_format = "2.0"
project_hash = "f8fb4032b8baeb42816bf4a9511b6900c0c28364"
project_hash = "af9c0f989b862f48925f57c8ff67696e79b4f253"

[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
Expand Down Expand Up @@ -46,6 +46,12 @@ git-tree-sha1 = "6cbbd4d241d7e6579ab354737f4dd95ca43946e1"
uuid = "f0e56b4a-5159-44fe-b623-3e5288b988bb"
version = "2.4.1"

[[deps.Configurations]]
deps = ["ExproniconLite", "OrderedCollections", "TOML"]
git-tree-sha1 = "4358750bb58a3caefd5f37a4a0c5bfdbbf075252"
uuid = "5218b696-f38b-4ac9-8b61-a12ec717816d"
version = "0.17.6"

[[deps.Crayons]]
git-tree-sha1 = "249fe38abf76d48563e2f4556bebd215aa317e15"
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
Expand Down Expand Up @@ -88,13 +94,24 @@ git-tree-sha1 = "dcb08a0d93ec0b1cdc4af184b26b591e9695423a"
uuid = "460bff9d-24e4-43bc-9d9f-a8973cb893f4"
version = "0.1.10"

[[deps.ExproniconLite]]
git-tree-sha1 = "5552cf384e4577c5dd2db57d7086a4a41747dbb9"
uuid = "55351af7-c7e9-48d6-89ff-24e801d99491"
version = "0.10.6"

[[deps.FileWatching]]
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"

[[deps.Future]]
deps = ["Random"]
uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"

[[deps.GarishPrint]]
deps = ["Configurations", "Preferences"]
git-tree-sha1 = "41136d24cc02c4d7c2b8c8982823fedac66d0a45"
uuid = "b0ab02a7-8576-43f7-aa76-eaa7c3897c54"
version = "0.5.1"

[[deps.HTTP]]
deps = ["Base64", "CodecZlib", "ConcurrentUtilities", "Dates", "ExceptionUnwrapping", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"]
git-tree-sha1 = "995f762e0182ebc50548c434c171a5bb6635f8e4"
Expand Down
1 change: 1 addition & 0 deletions netcode/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
GarishPrint = "b0ab02a7-8576-43f7-aa76-eaa7c3897c54"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Expand Down
13 changes: 12 additions & 1 deletion netcode/simulate.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Base64
import DataFrames as DF
import GarishPrint as GP
import HTTP
import Random
import SHA
Expand Down Expand Up @@ -41,6 +42,12 @@ const USER_DATA = DF.DataFrame(username = ["user$(i)" for i in 1:3], salt = ["$(
const CLIENT_USERNAME = "user1"
const CLIENT_PASSWORD = "password1"

function pprint(x)
GP.pprint(x)
println()
return nothing
end

function get_time(reference_time)
# get time (in units of nanoseconds) since reference_time
# places an upper bound on how much time can the program be running until time wraps around giving meaningless values
Expand Down Expand Up @@ -110,6 +117,7 @@ function start_game_server(game_server_address, room_size)

if !isnothing(connection_request_packet)
@info "Received PACKET_TYPE_CONNECTION_REQUEST_PACKET"
pprint(connection_request_packet)

for i in 1:room_size
if !room[i].is_used
Expand Down Expand Up @@ -164,6 +172,8 @@ function start_client(auth_server_address, username, password)
connection_request_packet_length = write(io_connection_request_packet, connection_request_packet)
@assert connection_request_packet_length == size_of_connection_request_packet

pprint(connection_request_packet)

Sockets.send(socket, game_server_address.host, game_server_address.port, io_connection_request_packet.data)

return nothing
Expand All @@ -187,7 +197,8 @@ function auth_handler(request)
else
if bytes2hex(SHA.sha3_256(hashed_password * USER_DATA[i, :salt])) == USER_DATA[i, :hashed_salted_hashed_password]
connect_token_info = ConnectTokenInfo(i)
@info "connect_token_info struct data" connect_token_info.netcode_version_info connect_token_info.protocol_id connect_token_info.create_timestamp connect_token_info.expire_timestamp connect_token_info.nonce connect_token_info.timeout_seconds connect_token_info.client_id connect_token_info.netcode_addresses connect_token_info.client_to_server_key connect_token_info.server_to_client_key connect_token_info.user_data SERVER_SIDE_SHARED_KEY SIZE_OF_HMAC SIZE_OF_ENCRYPTED_PRIVATE_CONNECT_TOKEN_DATA SIZE_OF_CONNECT_TOKEN_PACKET

pprint(connect_token_info)

connect_token_packet = ConnectTokenPacket(connect_token_info)

Expand Down

0 comments on commit fde199a

Please sign in to comment.