summaryrefslogtreecommitdiff
path: root/main.gd
blob: 0396244e4f38f2fd540522665acfb54e1d557a46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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())