diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-11-28 18:38:42 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-11-28 18:38:42 +0100 |
commit | e8aa9f50886b66d525307a58d71036e6fd3d4aa1 (patch) | |
tree | ce6f59eecf1eb3e1ba2794166c09623d8a2d7d83 /network/character_server.gd | |
parent | c89f25f59aa493d95bcac8e75ca5cdd57a0403e7 (diff) |
next commit
Diffstat (limited to 'network/character_server.gd')
-rw-r--r-- | network/character_server.gd | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/network/character_server.gd b/network/character_server.gd new file mode 100644 index 0000000..e710639 --- /dev/null +++ b/network/character_server.gd @@ -0,0 +1,54 @@ +class_name CharacterServer + + +var host: String +var port: int = 6121 +var stream: PacketPeerStream = PacketPeerStream.new() +var peer: StreamPeerTCP = StreamPeerTCP.new() + + +@warning_ignore("shadowed_variable") +func _init(host: String, port: int = 6121) -> void: + self.host = host + self.port = port + + stream.stream_peer = peer + peer.connect_to_host(host, port) + peer.poll() + + +func login(account_id: int, login_id1: int, login_id2: int, gender: Constants.Gender) -> CharacterServerLoginSuccessPacket: + var character_server_login_packet = CharacterServerLoginPacket.new() + character_server_login_packet.account_id = account_id + character_server_login_packet.login_id1 = login_id1 + character_server_login_packet.login_id2 = login_id2 + character_server_login_packet.gender = gender + + peer.put_data(character_server_login_packet.to_bytes()) + + var success = CharacterServerLoginSuccessPacket.from_bytes_via_peer(peer) + print(inst_to_dict(success)) + + return success + + +func request_character_list() -> RequestCharacterListSuccessPacket: + var request_character_list_packet = RequestCharacterListPacket.new() + peer.put_data(request_character_list_packet.to_bytes()) + + var success = RequestCharacterListSuccessPacket.from_bytes_via_peer(peer) + print(inst_to_dict(success)) + + return success + + +func select_character(slot: int) -> CharacterSelectionSuccessPacket: + var select_character_packet = SelectCharacterPacket.new() + select_character_packet.selected_slot = slot + + peer.put_data(select_character_packet.to_bytes()) + + var success = CharacterSelectionSuccessPacket.from_bytes_via_peer(peer) + print(inst_to_dict(success)) + + return success |