summaryrefslogtreecommitdiff
path: root/network/map_server.gd
blob: 24f0181896df9babb4367dda4f0c689c9ead8757 (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
class_name MapServer
extends Server


signal logged_in(packet: MapServerLoginSuccessPacket)
signal received_server_message(packet: ServerMessagePacket)
signal received_broadcast_formatted_message(packet: BroadcastFormattedMessagePacket)


@warning_ignore("shadowed_variable")
func _init(host: String, port: int = 5121) -> void:
	super._init(host, port)
	_setup_signals()


func _setup_signals():
	received_packet.connect(func(packet: Packet):
		if packet is ServerMessagePacket:
			received_server_message.emit(packet)
			
		if packet is BroadcastFormattedMessagePacket:
			received_broadcast_formatted_message.emit(packet)
	)


func login(account_id: int, character_id: int, login_id1: int, gender: Constants.Gender):
	var map_server_login_packet = MapServerLoginPacket.new()
	map_server_login_packet.account_id = account_id
	map_server_login_packet.character_id = character_id
	map_server_login_packet.login_id1 = login_id1
	map_server_login_packet.gender = gender
	
	peer.put_data(map_server_login_packet.to_bytes())
	
	peer.get_data(6) # in-between packet # 0x0283
	peer.get_data(4) # in-between packet # 0x0b18
	
	var packet = await received_packet
	if packet is MapServerLoginSuccessPacket:
		print(inst_to_dict(packet))
		logged_in.emit(packet)