summaryrefslogtreecommitdiff
path: root/network/login_server.gd
blob: bb7c093c409c1da5c47ab6c2b88443a90d2599b3 (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
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