diff options
| author | Fuwn <[email protected]> | 2024-06-12 09:08:06 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-06-12 09:08:06 -0700 |
| commit | ef737e951b7a8cc6546a4a3e0299b8a370c76346 (patch) | |
| tree | 917850eb56cd59b9eaaebdbc1ebbe5a5d270b786 /build | |
| parent | refactor(ShortLocationCommand): clearer delta notation (diff) | |
| download | worldserver-protobufs-ef737e951b7a8cc6546a4a3e0299b8a370c76346.tar.xz worldserver-protobufs-ef737e951b7a8cc6546a4a3e0299b8a370c76346.zip | |
feat(test.py): larger test suite
Diffstat (limited to 'build')
| -rw-r--r-- | build/test.py | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/build/test.py b/build/test.py index cf2d28c..ff89058 100644 --- a/build/test.py +++ b/build/test.py @@ -1,26 +1,58 @@ import network_packet_pb2 as network_packet from commands import buddy_list_notify_command_pb2 as buddy_list_notify_command +import command_pb2 as command request = network_packet.NetworkPacket() -request.length = 3 request.short_object_id = 0xFF -request.type = 0x0A +request.type = command.BUDDYLISTNOTIFYCMD request.buddy_list_notify_command.CopyFrom( buddy_list_notify_command.BuddyListNotifyCommand() ) request.buddy_list_notify_command.buddy_name = "Whirl" request.buddy_list_notify_command.logged_on = 1 +request.length = 3 + len(request.buddy_list_notify_command.buddy_name) + 1 + 1 -print(request.SerializeToString()) -print(request.WhichOneof("command")) +print(f"SerializeToString(): {request.SerializeToString()}") +print(f"request.WhichOneof('command'): {request.WhichOneof('command')}") +print() deserialised_request = network_packet.NetworkPacket() deserialised_request.ParseFromString(request.SerializeToString()) -print(deserialised_request.length) -print(deserialised_request.short_object_id) -print(deserialised_request.type) -print(deserialised_request.buddy_list_notify_command.buddy_name) -print(deserialised_request.buddy_list_notify_command.logged_on) +print(f"deserialised_request.length: {deserialised_request.length}") +print(f"deserialised_request.short_object_id: {deserialised_request.short_object_id}") +print(f"deserialised_request.type: {deserialised_request.type}") +print( + f"deserialised_request.buddy_list_notify_command.buddy_name: {deserialised_request.buddy_list_notify_command.buddy_name}" +) +print( + f"deserialised_request.buddy_list_notify_command.logged_on: {deserialised_request.buddy_list_notify_command.logged_on}" +) +print() + + +def parse_network_packet(raw_bytes): + net_packet = network_packet.NetworkPacket() + + net_packet.length = raw_bytes[0] + net_packet.short_object_id = raw_bytes[1] + net_packet.type = raw_bytes[2] + + command_type = net_packet.type + + match command_type: + case command.BUDDYLISTNOTIFYCMD: + print("This is a BuddyListNotifyCommand.") + case command.PROPREQCMD: + print("This is a PropRequestCommand.") + case _: + print(f"This is an unknown command type: {command_type}.") + + return net_packet + + +print(parse_network_packet(b"\x03\xff\x1e")) +print(parse_network_packet(b"\x03\x00\x1a")) +print(parse_network_packet(b"\x03\xff\x0a")) |