diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-11-29 21:54:32 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-11-29 21:54:32 +0100 |
commit | 313afffce7a823c30acf4853b083f9ca5132e879 (patch) | |
tree | 5a7370392ebd39314612166b35e6f53e67441c0b /network/login_server.gd | |
parent | e8aa9f50886b66d525307a58d71036e6fd3d4aa1 (diff) |
next commit
Diffstat (limited to 'network/login_server.gd')
-rw-r--r-- | network/login_server.gd | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/network/login_server.gd b/network/login_server.gd index bb7c093..6d878c4 100644 --- a/network/login_server.gd +++ b/network/login_server.gd @@ -1,6 +1,9 @@ class_name LoginServer +signal received_packet(packet: Packet) +signal logged_in(packet: LoginServerLoginSuccessPacket) + var host: String var port: int = 6900 var stream: PacketPeerStream = PacketPeerStream.new() @@ -17,15 +20,27 @@ func _init(host: String, port: int = 6900) -> void: peer.poll() -func login(username: String, password: String) -> LoginServerLoginSuccessPacket: +## Emits [signal received_packet]. +func listen() -> void: + if peer.get_status() == StreamPeerTCP.Status.STATUS_CONNECTED: + var raw_packet: PackedByteArray = peer.get_partial_data(2)[1] + if raw_packet.size() > 0: + raw_packet += peer.get_data(peer.get_available_bytes())[1] + var header = raw_packet.decode_u16(0) + var packet_type = Constants.PacketDB[header] + var packet = packet_type.from_bytes(raw_packet) + + received_packet.emit(packet) + + +func login(username: String, password: String): var login_server_login_packet = LoginServerLoginPacket.new() login_server_login_packet.username = username login_server_login_packet.password = password peer.put_data(login_server_login_packet.to_bytes()) - var success = LoginServerLoginSuccessPacket.from_bytes_via_peer(peer) - var character_server_information: CharacterServerInformation = success.character_server_information[0] - print(inst_to_dict(success), inst_to_dict(character_server_information)) - - return success + var packet = await received_packet + if packet is LoginServerLoginSuccessPacket: + print(inst_to_dict(packet)) + logged_in.emit(packet) |