summaryrefslogtreecommitdiff
path: root/login.gd
blob: c00e3cff67bf04471885d2b5c33a927b37c059f3 (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
extends Control


var account_information: LoginServerLoginSuccessPacket
var character_server_information: Array

var current_character_information: CharacterInformation


func _ready() -> void:
	switch_screen(%Login)
	$AudioStreamPlayer2.play()


func switch_screen(screen: Node):
	for node in get_children():
		if node is Control:
			node.visible = false
	
	screen.visible = true


func _on_login_pressed() -> void:
	$AudioStreamPlayer.play()
	Network.login_server.login(%Username.text, %Password.text)
	
	account_information = await Network.login_server.logged_in
	character_server_information = account_information.character_server_information
	
	for node in %CharacterServerList.get_children():
		node.queue_free()
	
	for info: CharacterServerInformation in character_server_information:
		var select_character_server = Button.new()
		select_character_server.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
		select_character_server.text = info.server_name
		select_character_server.pressed.connect(_on_character_server_login_pressed.bind(info))
		%CharacterServerList.add_child(select_character_server)
	
	switch_screen(%CharacterServer)


func _on_character_server_login_pressed(character_server_info: CharacterServerInformation) -> void:
	$AudioStreamPlayer.play()
	Network.character_server = CharacterServer.new(
		character_server_info.get_server_ip(),
		character_server_info.server_port
	)
	
	Network.character_server.login(
		account_information.account_id,
		account_information.login_id1,
		account_information.login_id2,
		account_information.gender
	)
	
	var _response = await Network.character_server.logged_in
	var response: CharacterServerLoginSuccessCharacterListPacket = await Network.character_server.logged_in_character_list
	
	for slot_idx in response.character_information.size():
		var info: CharacterInformation = response.character_information[slot_idx]
		var character = Button.new()
		character.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
		character.text = info.name
		character.pressed.connect(func():
			current_character_information = info
			_on_character_selected_pressed(slot_idx)
		)
		%CharacterList.add_child(character)
	
	switch_screen(%CharacterSelection)


func _on_character_selected_pressed(slot_idx: int):
	$AudioStreamPlayer.play()
	Network.character_server.select_character(slot_idx)
	
	var packet = await Network.character_server.selected_character
	if packet is CharacterSelectionSuccessPacket:
		Network.map_server = MapServer.new(
			packet.get_map_server_ip(),
			packet.map_server_port
		)
		
		Network.map_server.login(
			account_information.account_id,
			current_character_information.character_id,
			account_information.login_id1,
			account_information.gender
		)
		var _response = await Network.map_server.logged_in
	
	# TODO: switch to game :)