diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-11-28 00:45:30 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-11-28 00:45:30 +0100 |
commit | c89f25f59aa493d95bcac8e75ca5cdd57a0403e7 (patch) | |
tree | e1eb14f3b27ab8bcce68551424fe49a4f7d376af |
initial commit
-rw-r--r-- | .gitattributes | 2 | ||||
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | character_information.gd | 32 | ||||
-rw-r--r-- | character_server_information.gd | 52 | ||||
-rw-r--r-- | constants.gd | 8 | ||||
-rw-r--r-- | icon.svg | 1 | ||||
-rw-r--r-- | icon.svg.import | 37 | ||||
-rw-r--r-- | main.gd | 94 | ||||
-rw-r--r-- | main.tscn | 6 | ||||
-rw-r--r-- | packets/character_server_login_packet.gd | 32 | ||||
-rw-r--r-- | packets/character_server_login_success_packet.gd | 44 | ||||
-rw-r--r-- | packets/login_server_login_packet.gd | 34 | ||||
-rw-r--r-- | packets/login_server_login_success_packet.gd | 54 | ||||
-rw-r--r-- | packets/map_server_login_packet.gd | 36 | ||||
-rw-r--r-- | packets/packet.gd | 1 | ||||
-rw-r--r-- | packets/request_character_list_packet.gd | 8 | ||||
-rw-r--r-- | packets/request_character_list_success_packet.gd | 19 | ||||
-rw-r--r-- | project.godot | 16 |
18 files changed, 479 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0af181c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Godot 4+ specific ignores +.godot/ +/android/ diff --git a/character_information.gd b/character_information.gd new file mode 100644 index 0000000..101f74f --- /dev/null +++ b/character_information.gd @@ -0,0 +1,32 @@ +class_name CharacterInformation + + +## Byte Length: 4 +var character_id: int + +## Byte Length: 8 +var experience: int + +## Byte Length: 4 +var money: int + + +static func from_bytes(bytes: PackedByteArray): + var info = CharacterInformation.new() + + info.character_id = bytes.decode_u32(0) + info.experience = bytes.decode_s64(4) + info.money = bytes.decode_s32(12) + + return info + + +static func array_from_bytes(bytes: PackedByteArray) -> Array: + var array = [] + + var offset = 0 + while offset < bytes.size(): + array.append(from_bytes(bytes.slice(offset))) + offset += 175 + + return array diff --git a/character_server_information.gd b/character_server_information.gd new file mode 100644 index 0000000..9ede3b6 --- /dev/null +++ b/character_server_information.gd @@ -0,0 +1,52 @@ +class_name CharacterServerInformation + + +## Byte Length: 4 +var server_ip: PackedByteArray + +## Byte Length: 2 +var server_port: int + +## Byte Length: 20 +var server_name: String + +## Byte Length: 2 +var user_count: int + +## Byte Length: 2 +var server_type: int + +## Byte Length: 2 +var display_new: int + +## Byte Length: 128 +var unknown: PackedByteArray + + +func get_server_ip(): + return "%s.%s.%s.%s" % [server_ip.decode_u8(0), server_ip.decode_u8(1), server_ip.decode_u8(2), server_ip.decode_u8(3)] + + +static func from_bytes(bytes: PackedByteArray): + var info = CharacterServerInformation.new() + + info.server_ip = bytes.slice(0, 4) + info.server_port = bytes.decode_u16(4) + info.server_name = bytes.slice(6, 6 + 20 - 1).get_string_from_utf8() + info.user_count = bytes.decode_u16(26) + info.server_type = bytes.decode_u16(28) + info.display_new = bytes.decode_u16(30) + info.unknown = bytes.slice(32) + + return info + + +static func array_from_bytes(bytes: PackedByteArray) -> Array: + var array = [] + + var offset = 0 + while offset < bytes.size(): + array.append(from_bytes(bytes.slice(offset))) + offset += 160 + + return array diff --git a/constants.gd b/constants.gd new file mode 100644 index 0000000..7e1a37d --- /dev/null +++ b/constants.gd @@ -0,0 +1,8 @@ +class_name Constants + +enum Gender { + Female, + Male, + Both, + Server, +} diff --git a/icon.svg b/icon.svg new file mode 100644 index 0000000..9d8b7fa --- /dev/null +++ b/icon.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>
\ No newline at end of file diff --git a/icon.svg.import b/icon.svg.import new file mode 100644 index 0000000..e69137a --- /dev/null +++ b/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bsl37m74gym45" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false @@ -0,0 +1,94 @@ +extends Node2D + + +class LoginServer: + var host: String + var port: int = 6900 + +class CharacterServer: + var host: String + var port: int = 6121 + +class MapServer: + var host: String + var port: int = 5121 + +var stream: PacketPeerStream +var peer: StreamPeerTCP + +var stream2: PacketPeerStream +var peer2: StreamPeerTCP + +var stream3: PacketPeerStream +var peer3: StreamPeerTCP + + +func _ready() -> void: + stream = PacketPeerStream.new() + peer = StreamPeerTCP.new() + stream.stream_peer = peer + + peer.connect_to_host("127.0.0.1", 6900) + while peer.get_status() != StreamPeerTCP.STATUS_CONNECTED: + print("status: ", peer.get_status(), " polling: ", peer.poll()) + print("working status: ", peer.get_status()) + + var login_server_login_packet = LoginServerLoginPacket.new() + login_server_login_packet.username = "dweipert" + login_server_login_packet.password = "ragnarok" + + peer.put_data(login_server_login_packet.to_bytes()) + + var p = LoginServerLoginSuccessPacket.from_bytes_via_peer(peer) + var character_server_information: CharacterServerInformation = p.character_server_information[0] + print(inst_to_dict(p), inst_to_dict(character_server_information)) + + + stream2 = PacketPeerStream.new() + peer2 = StreamPeerTCP.new() + stream2.stream_peer = peer2 + + peer2.connect_to_host(character_server_information.get_server_ip(), character_server_information.server_port) + while peer2.get_status() != StreamPeerTCP.STATUS_CONNECTED: + print("status: ", peer2.get_status(), " polling: ", peer2.poll()) + print("working status: ", peer2.get_status()) + + var character_server_login_packet = CharacterServerLoginPacket.new() + character_server_login_packet.account_id = p.account_id + character_server_login_packet.login_id1 = p.login_id1 + character_server_login_packet.login_id2 = p.login_id2 + character_server_login_packet.gender = p.gender + + print(inst_to_dict(character_server_login_packet)) + peer2.put_data(character_server_login_packet.to_bytes()) + + var c = CharacterServerLoginSuccessPacket.from_bytes_via_peer(peer2) + print(inst_to_dict(c)) + + # get character list first + var request_character_list_packet = RequestCharacterListPacket.new() + peer2.put_data(request_character_list_packet.to_bytes()) + + var rcl = RequestCharacterListSuccessPacket.from_bytes_via_peer(peer2) + var character_information: CharacterInformation = rcl.character_information[0] + print(inst_to_dict(rcl), inst_to_dict(character_information)) + + + #stream3 = PacketPeerStream.new() + #peer3 = StreamPeerTCP.new() + #stream3.stream_peer = peer3 + # + #peer3.connect_to_host(character_server_information.get_server_ip(), character_server_information.server_port) + #while peer3.get_status() != StreamPeerTCP.STATUS_CONNECTED: + #print("status: ", peer3.get_status(), " polling: ", peer3.poll()) + #print("working status: ", peer3.get_status()) + # + #var map_server_login_packet = MapServerLoginPacket.new() + #map_server_login_packet.account_id = p.account_id + #map_server_login_packet.character_id = character_information.character_id + #map_server_login_packet.login_id1 = p.login_id1 + #map_server_login_packet.gender = p.gender + # + #peer3.put_data(map_server_login_packet.to_bytes()) + #peer3.get_data(1) + #peer3.get_data(peer3.get_available_bytes()) diff --git a/main.tscn b/main.tscn new file mode 100644 index 0000000..8f545ff --- /dev/null +++ b/main.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://t8bawt4nmflc"] + +[ext_resource type="Script" path="res://main.gd" id="1_py1bq"] + +[node name="Main" type="Node2D"] +script = ExtResource("1_py1bq") diff --git a/packets/character_server_login_packet.gd b/packets/character_server_login_packet.gd new file mode 100644 index 0000000..e6ba07b --- /dev/null +++ b/packets/character_server_login_packet.gd @@ -0,0 +1,32 @@ +class_name CharacterServerLoginPacket +extends Packet + + +## Byte Length: 4 +var account_id: int + +## Byte Length: 4 +var login_id1: int + +## Byte Length: 4 +var login_id2: int + +## Byte Length: 2 +var unknown: int + +## Byte Length: 1 +var gender: Constants.Gender + + +func to_bytes(): + var header = PackedByteArray([101, 0]) + + var payload = PackedByteArray([]) + payload.resize(15) + payload.encode_u32(0, account_id) + payload.encode_u32(4, login_id1) + payload.encode_u32(8, login_id2) + payload.encode_u16(12, unknown) + payload.encode_u8(14, gender) + + return header + payload diff --git a/packets/character_server_login_success_packet.gd b/packets/character_server_login_success_packet.gd new file mode 100644 index 0000000..800e218 --- /dev/null +++ b/packets/character_server_login_success_packet.gd @@ -0,0 +1,44 @@ +class_name CharacterServerLoginSuccessPacket +extends Packet + + +## Byte Length: 2 +var unknown: int + +## Byte Length: 1 +var normal_slot_count: int + +## Byte Length: 1 +var vip_slot_count: int + +## Byte Length: 1 +var billing_slot_count: int + +## Byte Length: 1 +var producible_slot_count: int + +## Byte Length: 1 +var valid_slot: int + +## Byte Length: 20 +var unused: PackedByteArray + + +static func from_bytes(bytes: PackedByteArray): + var packet = CharacterServerLoginSuccessPacket.new() + + packet.unknown = bytes.decode_u16(0) + packet.normal_slot_count = bytes.decode_u8(2) + packet.vip_slot_count = bytes.decode_u8(3) + packet.billing_slot_count = bytes.decode_u8(4) + packet.producible_slot_count = bytes.decode_u8(5) + packet.valid_slot = bytes.decode_u8(6) + packet.unused = bytes.slice(7, 7 + 20) + + return packet + +static func from_bytes_via_peer(peer: StreamPeer): + var _header = peer.get_data(6) + var remaining_bytes = peer.get_data(peer.get_available_bytes()) + + return from_bytes(remaining_bytes[1]) diff --git a/packets/login_server_login_packet.gd b/packets/login_server_login_packet.gd new file mode 100644 index 0000000..29f23cd --- /dev/null +++ b/packets/login_server_login_packet.gd @@ -0,0 +1,34 @@ +class_name LoginServerLoginPacket +extends Packet + + +## Byte Length: 4 +var version: int = 0 + +## Byte Length: 24 +var username: String + +## Byte Length: 24 +var password: String + +## Byte Length: 1 +var client_type: int = 0 + + +func to_bytes(): + var header = PackedByteArray([100, 0]) + + var username_bytes = username.to_utf8_buffer() + username_bytes.resize(24) + + var password_bytes = password.to_utf8_buffer() + password_bytes.resize(24) + + var payload = PackedByteArray([]) + payload.resize(4) + payload.encode_u32(0, version) + payload.append_array(username_bytes) + payload.append_array(password_bytes) + payload.append(client_type) + + return header + payload diff --git a/packets/login_server_login_success_packet.gd b/packets/login_server_login_success_packet.gd new file mode 100644 index 0000000..3d74289 --- /dev/null +++ b/packets/login_server_login_success_packet.gd @@ -0,0 +1,54 @@ +class_name LoginServerLoginSuccessPacket +extends Packet + + +## Byte Length: 4 +var login_id1: int + +## Byte Length: 4 +var account_id: int + +## Byte Length: 4 +var login_id2: int + +## Deprecated and always 0 on rAthena +## Byte Length: 4 +var ip_address: PackedByteArray + +## Deprecated and always 0 on rAthena +## Byte Length: 24 +var name: String + +## Always 0 on rAthena +## Byte Length: 2 +var unknown: int + +## Byte Length: 1 +var gender: Constants.Gender + +## Byte Length: 17 +var auth_token: String + +var character_server_information: Array + + +static func from_bytes(bytes: PackedByteArray): + var packet = LoginServerLoginSuccessPacket.new() + + packet.login_id1 = bytes.decode_u32(0) + packet.account_id = bytes.decode_u32(4) + packet.login_id2 = bytes.decode_u32(8) + packet.ip_address = bytes.slice(12, 16) + packet.name = bytes.slice(16, 16 + 24).get_string_from_utf8() + packet.unknown = bytes.decode_u16(40) + packet.gender = bytes[42] + packet.auth_token = bytes.slice(43, 43 + 17 - 1).get_string_from_utf8() + packet.character_server_information = CharacterServerInformation.array_from_bytes(bytes.slice(60)) + + return packet + +static func from_bytes_via_peer(peer: StreamPeer): + var _header = peer.get_data(4) + var remaining_bytes = peer.get_data(peer.get_available_bytes()) + + return from_bytes(remaining_bytes[1]) diff --git a/packets/map_server_login_packet.gd b/packets/map_server_login_packet.gd new file mode 100644 index 0000000..62af086 --- /dev/null +++ b/packets/map_server_login_packet.gd @@ -0,0 +1,36 @@ +class_name MapServerLoginPacket +extends Packet + + +## Byte Length: 4 +var account_id: int + +## Byte Length: 4 +var character_id: int + +## Byte Length: 4 +var login_id1: int + +## Byte Length: 4 +var client_tick: int = 100 + +## Byte Length: 1 +var gender: Constants.Gender + +## Byte Length: 4 +var unknown: int = 0 + + +func to_bytes(): + var header = PackedByteArray([54, 4]) + + var payload = PackedByteArray([]) + payload.resize(21) + payload.encode_u32(0, account_id) + payload.encode_u32(4, character_id) + payload.encode_u32(8, login_id1) + payload.encode_u32(12, client_tick) + payload.encode_u8(16, gender) + payload.encode_u32(17, unknown) + + return header + payload diff --git a/packets/packet.gd b/packets/packet.gd new file mode 100644 index 0000000..ea1621c --- /dev/null +++ b/packets/packet.gd @@ -0,0 +1 @@ +class_name Packet diff --git a/packets/request_character_list_packet.gd b/packets/request_character_list_packet.gd new file mode 100644 index 0000000..eca61ad --- /dev/null +++ b/packets/request_character_list_packet.gd @@ -0,0 +1,8 @@ +class_name RequestCharacterListPacket +extends Packet + + +func to_bytes(): + var header = PackedByteArray([161, 9]) + + return header diff --git a/packets/request_character_list_success_packet.gd b/packets/request_character_list_success_packet.gd new file mode 100644 index 0000000..0b6cea8 --- /dev/null +++ b/packets/request_character_list_success_packet.gd @@ -0,0 +1,19 @@ +class_name RequestCharacterListSuccessPacket +extends Packet + + +var character_information: Array + + +static func from_bytes(bytes: PackedByteArray): + var packet = RequestCharacterListSuccessPacket.new() + + packet.character_information = CharacterInformation.array_from_bytes(bytes) + + return packet + +static func from_bytes_via_peer(peer: StreamPeer): + var _header = peer.get_data(4) + var remaining_bytes = peer.get_data(peer.get_available_bytes()) + + return from_bytes(remaining_bytes[1]) diff --git a/project.godot b/project.godot new file mode 100644 index 0000000..b2c4014 --- /dev/null +++ b/project.godot @@ -0,0 +1,16 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="Minerva" +run/main_scene="res://main.tscn" +config/features=PackedStringArray("4.3", "Forward Plus") +config/icon="res://icon.svg" |