blob: 4d3433be3d65deb6359fa8ee89dbb1e9ebd17e98 (
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
|
class_name CharacterServer
extends Server
signal logged_in(packet: CharacterServerLoginSuccessPacket)
signal logged_in_character_list(packet: CharacterServerLoginSuccessCharacterListPacket)
signal requested_character_list(packet: RequestCharacterListSuccessPacket)
signal selected_character(packet: CharacterSelectionSuccessPacket)
@warning_ignore("shadowed_variable_base_class")
func _init(host: String, port: int = 6121) -> void:
super._init(host, port)
func login(account_id: int, login_id1: int, login_id2: int, gender: Constants.Gender):
var character_server_login_packet = CharacterServerLoginPacket.new()
character_server_login_packet.account_id = account_id
character_server_login_packet.login_id1 = login_id1
character_server_login_packet.login_id2 = login_id2
character_server_login_packet.gender = gender
peer.put_data(character_server_login_packet.to_bytes())
peer.get_data(4) # in-between packet
var login_success_packet = await received_packet
if login_success_packet is CharacterServerLoginSuccessPacket:
print(inst_to_dict(login_success_packet))
logged_in.emit(login_success_packet)
var character_list_packet = await received_packet
if character_list_packet is CharacterServerLoginSuccessCharacterListPacket:
print(inst_to_dict(character_list_packet))
print(inst_to_dict(character_list_packet.character_information[0]))
logged_in_character_list.emit(character_list_packet)
func request_character_list():
var request_character_list_packet = RequestCharacterListPacket.new()
peer.put_data(request_character_list_packet.to_bytes())
var packet = await received_packet
if packet is RequestCharacterListSuccessPacket:
print(inst_to_dict(packet), inst_to_dict(packet.character_information[0]))
requested_character_list.emit(packet)
func select_character(slot: int):
var select_character_packet = SelectCharacterPacket.new()
select_character_packet.selected_slot = slot
peer.put_data(select_character_packet.to_bytes())
var packet = await received_packet
if packet is CharacterSelectionSuccessPacket:
print(inst_to_dict(packet))
selected_character.emit(packet)
func get_keep_alive_timer() -> Timer:
var character_server_keep_alive_timer = Timer.new()
character_server_keep_alive_timer.name = "CharacterServerKeepAliveTimer"
character_server_keep_alive_timer.autostart = true
character_server_keep_alive_timer.one_shot = false
character_server_keep_alive_timer.wait_time = 12.0
character_server_keep_alive_timer.timeout.connect(func():
var character_server_keep_alive_packet := CharacterServerKeepAlivePacket.new()
send(character_server_keep_alive_packet)
)
return character_server_keep_alive_timer
|