summaryrefslogtreecommitdiff
path: root/packets/character_server_information.gd
diff options
context:
space:
mode:
Diffstat (limited to 'packets/character_server_information.gd')
-rw-r--r--packets/character_server_information.gd70
1 files changed, 70 insertions, 0 deletions
diff --git a/packets/character_server_information.gd b/packets/character_server_information.gd
new file mode 100644
index 0000000..f67b065
--- /dev/null
+++ b/packets/character_server_information.gd
@@ -0,0 +1,70 @@
+class_name CharacterServerInformation
+extends PacketChunk
+
+
+## Byte Type: u32
+## Byte Length: 4
+var server_ip: PackedByteArray
+
+## Byte Type: u16
+## Byte Length: 2
+var server_port: int
+
+## Byte Type: u8
+## Byte Length: 20
+var server_name: String
+
+## Byte Type: u16
+## Byte Length: 2
+var user_count: int
+
+## Byte Type: u16
+## Byte Length: 2
+var server_type: int
+
+## Byte Type: u16
+## Byte Length: 2
+var display_new: int
+
+## Byte Type: u8
+## Byte Length: 128
+var unknown: PackedByteArray
+
+
+func _init() -> void:
+ byte_length = 160
+
+
+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).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():
+ var chunk = from_bytes(bytes.slice(offset))
+ array.append(chunk)
+ offset += chunk.byte_length
+
+ return array