summaryrefslogtreecommitdiff
path: root/network/login_server.gd
blob: 715c73c21c962f3bf38acc360429c86e4fca646b (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
class_name LoginServer
extends Server


signal logged_in(packet: LoginServerLoginSuccessPacket)


@warning_ignore("shadowed_variable_base_class")
func _init(host: String, port: int = 6900) -> void:
	super._init(host, port)


func login(username: String, password: String):
	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 packet = await received_packet
	if packet is LoginServerLoginSuccessPacket:
		print(inst_to_dict(packet))
		logged_in.emit(packet)


func get_keep_alive_timer() -> Timer:
	var login_server_keep_alive_timer = Timer.new()
	login_server_keep_alive_timer.name = "LoginServerKeepAliveTimer"
	login_server_keep_alive_timer.autostart = true
	login_server_keep_alive_timer.one_shot = false
	login_server_keep_alive_timer.wait_time = 30.0 # 60.0
	
	login_server_keep_alive_timer.timeout.connect(func():
		var login_server_keep_alive_packet := LoginServerKeepAlivePacket.new()
		login_server_keep_alive_packet.user_name = "dweipert"
		send(login_server_keep_alive_packet)
	)
	
	return login_server_keep_alive_timer