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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
extends Control
var account_information: LoginServerLoginSuccessPacket
var character_server_information: Array
var current_character_server_idx := -1
var current_character_slot_idx := -1
var current_character_information: CharacterInformation
@onready var username: LineEdit = %Username
@onready var password: LineEdit = %Password
func _ready() -> void:
switch_screen(%Login)
$BackgroundMusic.play()
func switch_screen(screen: Node):
for node in get_children():
if node is CenterContainer:
node.visible = false
screen.visible = true
func _on_login_pressed() -> void:
SoundManager.sound_button_click.play()
Network.login_server = LoginServer.new("127.0.0.1")
Network.login_server.establish_connection()
if Network.login_server.get_status() == Error.FAILED:
Client.show_message_window("Couldn't connect to server at 127.0.0.1", "Connection Error", %Login/Window, SIDE_BOTTOM)
return
var response = await Network.login_server.login(username.text, password.text)
if response is LoginFailedPacket:
var message := ""
if response.reason == Constants.LoginFailedReason.ServerClosed:
message = "Server closed connection"
elif response.reason == Constants.LoginFailedReason.AlreadyLoggedIn:
message = "Already logged in"
elif response.reason == Constants.LoginFailedReason.AlreadyOnline:
message = "Already online"
Client.show_message_window(message, "Login Error", %Login/Window, SIDE_BOTTOM)
return
account_information = response
character_server_information = account_information.character_server_information
Client.account.id = account_information.account_id
get_tree().root.add_child(Network.login_server.get_keep_alive_timer())
for node in %CharacterServerList.get_children():
node.queue_free()
for idx in character_server_information.size():
var info: CharacterServerInformation = character_server_information[idx]
var select_character_server: Button = preload("res://ui/login/character_server_button.tscn").instantiate()
select_character_server.text = "%s (%d)" % [info.server_name, info.user_count]
select_character_server.pressed.connect(_on_character_server_login_pressed.bind(info, idx))
%CharacterServerList.add_child(select_character_server)
if idx == 0:
current_character_server_idx = 0
select_character_server.grab_focus()
# TODO: if setting is true to skip character server selection when only one server is available
#if character_server_information.size() == 1:
#(%CharacterServerList.get_child(0) as Button).pressed.emit()
#else:
#switch_screen(%CharacterServer)
switch_screen(%CharacterServer)
func _on_character_server_login_pressed(character_server_info: CharacterServerInformation, idx: int) -> void:
if idx != current_character_server_idx:
current_character_server_idx = idx
return
SoundManager.sound_button_click.play()
Network.character_server = CharacterServer.new(
character_server_info.get_server_ip(),
character_server_info.server_port
)
Network.character_server.establish_connection()
var response := await Network.character_server.login(
account_information.account_id,
account_information.login_id1,
account_information.login_id2,
account_information.gender
)
if response.login is CharacterSelectionFailedPacket:
Client.show_message_window(
"Connection rejected from server \"%s\" at %s" % [
character_server_info.server_name, character_server_info.get_server_ip()
],
"Connection Error", %CharacterServer/Window, SIDE_BOTTOM
)
return
get_tree().root.add_child(Network.character_server.get_keep_alive_timer())
var character_list: CharacterServerLoginSuccessCharacterListPacket = response.character_list
var login_character_list := LoginCharacterList.from_character_list_login_packet(character_list)
%CharacterSelectionList.login_character_list = login_character_list
%CharacterSelectionList.selected.connect(func(slot_idx: int):
current_character_slot_idx = slot_idx
%CharacterSelectionSlotLabel.text = "%s/%s" % [str(slot_idx + 1), login_character_list.slot_count]
var info = login_character_list.get_info_for_slot(slot_idx)
if info:
current_character_information = info
else:
current_character_information = null
)
%CharacterSelectionList.requested_login.connect(func(slot_idx: int):
_on_character_selected_pressed(slot_idx)
)
# pre-select first character
%CharacterSelectionList.select(0)
switch_screen(%CharacterSelection)
func _on_character_selected_pressed(slot_idx: int):
SoundManager.sound_button_click.play()
Network.character_server.select_character(slot_idx)
var selected_character = await Network.character_server.selected_character
if selected_character is CharacterSelectionFailedPacket:
# TODO: show error
return
Client.character.name = current_character_information.name
Client.character.info = current_character_information
Network.map_server = MapServer.new(
selected_character.get_map_server_ip(),
selected_character.map_server_port
)
Network.map_server.establish_connection()
Network.map_server.login(
account_information.account_id,
current_character_information.character_id,
account_information.login_id1,
account_information.gender
)
var _logged_in = await Network.map_server.logged_in
get_tree().change_scene_to_file(
#"res://client_data/data/%s.tscn" % current_character_information.get_map_name()
"res://extractor/test/pay_dun00.tscn"
)
func _on_character_server_back_button_pressed() -> void:
SoundManager.sound_button_click.play()
switch_screen(%Login)
func _on_character_server_next_button_pressed() -> void:
(%CharacterServerList.get_child(0) as Button).pressed.emit()
func _on_character_selection_back_button_pressed() -> void:
SoundManager.sound_button_click.play()
switch_screen(%CharacterServer)
func _on_character_login_pressed() -> void:
_on_character_selected_pressed(current_character_slot_idx)
|