summaryrefslogtreecommitdiff
path: root/network
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-11-28 18:38:42 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-11-28 18:38:42 +0100
commite8aa9f50886b66d525307a58d71036e6fd3d4aa1 (patch)
treece6f59eecf1eb3e1ba2794166c09623d8a2d7d83 /network
parentc89f25f59aa493d95bcac8e75ca5cdd57a0403e7 (diff)
next commit
Diffstat (limited to 'network')
-rw-r--r--network/character_server.gd54
-rw-r--r--network/login_server.gd31
-rw-r--r--network/map_server.gd35
-rw-r--r--network/network.gd115
-rw-r--r--network/network.tscn6
5 files changed, 241 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
diff --git a/network/login_server.gd b/network/login_server.gd
new file mode 100644
index 0000000..bb7c093
--- /dev/null
+++ b/network/login_server.gd
@@ -0,0 +1,31 @@
+class_name LoginServer
+
+
+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()
+
+
+func login(username: String, password: String) -> LoginServerLoginSuccessPacket:
+ 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
diff --git a/network/map_server.gd b/network/map_server.gd
new file mode 100644
index 0000000..af46c6c
--- /dev/null
+++ b/network/map_server.gd
@@ -0,0 +1,35 @@
+class_name MapServer
+
+
+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()
+
+
+func login(account_id: int, character_id: int, login_id1: int, gender: Constants.Gender) -> MapServerLoginSuccessPacket:
+ var map_server_login_packet = MapServerLoginPacket.new()
+ map_server_login_packet.account_id = account_id
+ map_server_login_packet.character_id = character_id
+ map_server_login_packet.login_id1 = login_id1
+ map_server_login_packet.gender = gender
+
+ peer.put_data(map_server_login_packet.to_bytes())
+
+ peer.get_data(6) # in-between packet
+ peer.get_data(4) # in-between packet
+
+ var success = MapServerLoginSuccessPacket.from_bytes_via_peer(peer)
+ print(inst_to_dict(success))
+
+ return success
diff --git a/network/network.gd b/network/network.gd
new file mode 100644
index 0000000..25607a2
--- /dev/null
+++ b/network/network.gd
@@ -0,0 +1,115 @@
+extends Node
+
+
+#class LoginServer:
+ #var host: String
+ #var port: int = 6900
+ #var stream: PacketPeerStream = PacketPeerStream.new()
+ #var peer: StreamPeerTCP = StreamPeerTCP.new()
+ #
+ #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()
+
+#class CharacterServer:
+ #var host: String
+ #var port: int = 6121
+ #var stream: PacketPeerStream
+ #var peer: StreamPeerTCP
+
+#class MapServer:
+ #var host: String
+ #var port: int = 5121
+ #var stream: PacketPeerStream
+ #var peer: StreamPeerTCP
+
+static var login_server: LoginServer
+static var character_server: CharacterServer
+static var map_server: MapServer
+
+
+func _ready() -> void:
+ login_server = LoginServer.new("127.0.0.1")
+
+ #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
+ #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))
+ #
+ ## select character
+ #var select_character_packet = SelectCharacterPacket.new()
+ #select_character_packet.selected_slot = 0
+ #peer2.put_data(select_character_packet.to_bytes())
+ #
+ #var css = CharacterSelectionSuccessPacket.from_bytes_via_peer(peer2)
+ #print(inst_to_dict(css))
+ #
+ #
+ #stream3 = PacketPeerStream.new()
+ #peer3 = StreamPeerTCP.new()
+ #stream3.stream_peer = peer3
+ #
+ #peer3.connect_to_host(css.get_map_server_ip(), css.map_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 = css.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())
+ #
+ #print(peer3.get_data(6))#in-between packet
+ #print(peer3.get_data(4))#in-between packet
+ #
+ #var msls = MapServerLoginSuccessPacket.from_bytes_via_peer(peer3)
+ #print(inst_to_dict(msls))
+ #print(msls.get_position())
+
+ var file = FileAccess.open("res://data/data.grf", FileAccess.READ)
+ var signature = file.get_buffer("Master of Magic".length())
+ print(signature.get_string_from_utf8())
+ print(file.get_16())
+ print(file.get_32())
diff --git a/network/network.tscn b/network/network.tscn
new file mode 100644
index 0000000..46463de
--- /dev/null
+++ b/network/network.tscn
@@ -0,0 +1,6 @@
+[gd_scene load_steps=2 format=3 uid="uid://t8bawt4nmflc"]
+
+[ext_resource type="Script" path="res://network/network.gd" id="1_iyygl"]
+
+[node name="Network" type="Node"]
+script = ExtResource("1_iyygl")