summaryrefslogtreecommitdiff
path: root/network
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-11-30 12:46:08 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-11-30 12:46:08 +0100
commitd560f77811d4fc6f29bf477356a6d2e58dda0be1 (patch)
tree3ac2c4267b5c88e40849416115977574e9f09a83 /network
parent313afffce7a823c30acf4853b083f9ca5132e879 (diff)
next commit
Diffstat (limited to 'network')
-rw-r--r--network/character_server.gd42
-rw-r--r--network/login_server.gd27
-rw-r--r--network/map_server.gd31
-rw-r--r--network/server.gd44
4 files changed, 61 insertions, 83 deletions
diff --git a/network/character_server.gd b/network/character_server.gd
index f629283..4831b36 100644
--- a/network/character_server.gd
+++ b/network/character_server.gd
@@ -1,38 +1,16 @@
class_name CharacterServer
+extends Server
-signal received_packet(packet: Packet)
signal logged_in(packet: CharacterServerLoginSuccessPacket)
+signal logged_in_character_list(packet: CharacterServerLoginSuccessCharacterListPacket)
signal requested_character_list(packet: RequestCharacterListSuccessPacket)
signal selected_character(packet: CharacterSelectionSuccessPacket)
-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()
-
-
-## 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)
+ super._init(host, port)
func login(account_id: int, login_id1: int, login_id2: int, gender: Constants.Gender):
@@ -46,10 +24,16 @@ func login(account_id: int, login_id1: int, login_id2: int, gender: Constants.Ge
peer.get_data(4) # in-between packet
- var packet = await received_packet
- if packet is CharacterServerLoginSuccessPacket:
- print(inst_to_dict(packet))
- logged_in.emit(packet)
+ var login_success_packet = await received_packet
+ if login_success_packet is CharacterServerLoginSuccessPacket:
+ print(inst_to_dict(login_success_packet))
+ logged_in.emit(login_success_packet)
+
+ var character_list_packet = await received_packet
+ if character_list_packet is CharacterServerLoginSuccessCharacterListPacket:
+ print(inst_to_dict(character_list_packet))
+ print(inst_to_dict(character_list_packet.character_information[0]))
+ logged_in_character_list.emit(character_list_packet)
func request_character_list():
diff --git a/network/login_server.gd b/network/login_server.gd
index 6d878c4..238a183 100644
--- a/network/login_server.gd
+++ b/network/login_server.gd
@@ -1,36 +1,13 @@
class_name LoginServer
+extends Server
-signal received_packet(packet: Packet)
signal logged_in(packet: LoginServerLoginSuccessPacket)
-var host: String
-var port: int = 6900
-var stream: PacketPeerStream = PacketPeerStream.new()
-var peer: StreamPeerTCP = StreamPeerTCP.new()
-
@warning_ignore("shadowed_variable")
func _init(host: String, port: int = 6900) -> void:
- self.host = host
- self.port = port
-
- stream.stream_peer = peer
- peer.connect_to_host(host, port)
- peer.poll()
-
-
-## 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)
+ super._init(host, port)
func login(username: String, password: String):
diff --git a/network/map_server.gd b/network/map_server.gd
index f4dacc1..1f74055 100644
--- a/network/map_server.gd
+++ b/network/map_server.gd
@@ -1,40 +1,13 @@
class_name MapServer
+extends Server
-signal received_packet(packet: Packet)
signal logged_in(packet: MapServerLoginSuccessPacket)
-var host: String
-var port: int = 5121
-var stream: PacketPeerStream = PacketPeerStream.new()
-var peer: StreamPeerTCP = StreamPeerTCP.new()
-
@warning_ignore("shadowed_variable")
func _init(host: String, port: int = 5121) -> void:
- self.host = host
- self.port = port
-
- stream.stream_peer = peer
- peer.connect_to_host(host, port)
- peer.poll()
-
-
-## 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:
- var header = raw_packet.decode_u16(0)
- var packet_type = Constants.PacketDB[header]
- if packet_type.BYTE_LENGTH > 0:
- raw_packet += peer.get_data(packet_type.BYTE_LENGTH - 2)[1]
- else:
- raw_packet += peer.get_data(peer.get_available_bytes())[1]
- var packet = packet_type.from_bytes(raw_packet)
-
- received_packet.emit(packet)
+ super._init(host, port)
func login(account_id: int, character_id: int, login_id1: int, gender: Constants.Gender):
diff --git a/network/server.gd b/network/server.gd
new file mode 100644
index 0000000..e46e797
--- /dev/null
+++ b/network/server.gd
@@ -0,0 +1,44 @@
+class_name Server
+
+
+signal received_packet(packet: Packet)
+
+var host: String
+var port: int
+var peer: StreamPeerTCP = StreamPeerTCP.new()
+
+
+@warning_ignore("shadowed_variable")
+func _init(host: String, port: int) -> void:
+ self.host = host
+ self.port = port
+
+ peer.connect_to_host(host, port)
+ peer.poll()
+
+
+## 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:
+ var header = raw_packet.decode_u16(0)
+
+ if Constants.PacketDB.has(header):
+ var packet_type = Constants.PacketDB[header]
+
+ if packet_type.BYTE_LENGTH > 0:
+ raw_packet += peer.get_partial_data(packet_type.BYTE_LENGTH - 2)[1]
+ else:
+ var packet_length: PackedByteArray = peer.get_data(2)[1]
+
+ raw_packet += packet_length
+ raw_packet += peer.get_data(packet_length.decode_u16(0) - 4)[1]
+
+ var packet = packet_type.from_bytes(raw_packet)
+
+ received_packet.emit(packet)
+ else:
+ raw_packet.reverse()
+ print("Received unknown packet with header ", raw_packet.hex_encode())