summaryrefslogtreecommitdiff
path: root/network/character_server.gd
blob: e710639aadcb668551e29fdf6fd0019c90eb7b1b (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
class_name CharacterServer


var host: String
var port: int = 6121
var stream: PacketPeerStream = PacketPeerStream.new()
var peer: StreamPeerTCP = StreamPeerTCP.new()


@warning_ignore("shadowed_variable")
func _init(host: String, port: int = 6121) -> void:
	self.host = host
	self.port = port
	
	stream.stream_peer = peer
	peer.connect_to_host(host, port)
	peer.poll()


func login(account_id: int, login_id1: int, login_id2: int, gender: Constants.Gender) -> CharacterServerLoginSuccessPacket:
	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())
	
	var success = CharacterServerLoginSuccessPacket.from_bytes_via_peer(peer)
	print(inst_to_dict(success))
	
	return success


func request_character_list() -> RequestCharacterListSuccessPacket:
	var request_character_list_packet = RequestCharacterListPacket.new()
	peer.put_data(request_character_list_packet.to_bytes())
	
	var success = RequestCharacterListSuccessPacket.from_bytes_via_peer(peer)
	print(inst_to_dict(success))
	
	return success


func select_character(slot: int) -> CharacterSelectionSuccessPacket:
	var select_character_packet = SelectCharacterPacket.new()
	select_character_packet.selected_slot = slot
	
	peer.put_data(select_character_packet.to_bytes())
	
	var success = CharacterSelectionSuccessPacket.from_bytes_via_peer(peer)
	print(inst_to_dict(success))
	
	return success