summaryrefslogtreecommitdiff
path: root/packets/character_selection_success_packet.gd
blob: f483d9eb7ae5d58beea351fc5f0ed6c93a815352 (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
class_name CharacterSelectionSuccessPacket
extends Packet


static var header := 0x0ac5


## Byte Type: u32
## Byte Length: 4
var character_id: int

## Byte Type: u8
## Byte Length: 16
var map_name: String

## Byte Type: u32
## Byte Length: 4
var map_server_ip: PackedByteArray

## Byte Type: u16
## Byte Length: 2
var map_server_port: int

## Byte Type: u8
## Byte Length: 128
var unknown: PackedByteArray


func get_map_server_ip():
	return "%s.%s.%s.%s" % [
		map_server_ip.decode_u8(0),
		map_server_ip.decode_u8(1),
		map_server_ip.decode_u8(2),
		map_server_ip.decode_u8(3)
	]


static func from_bytes(bytes: PackedByteArray):
	var packet = CharacterSelectionSuccessPacket.new()
	
	packet.character_id = bytes.decode_u32(0)
	packet.map_name = bytes.slice(4, 4 + 16).get_string_from_utf8()
	packet.map_server_ip = bytes.slice(20, 20 + 4)
	packet.map_server_port = bytes.decode_u16(24)
	packet.unknown = bytes.slice(26)
	
	return packet

static func from_bytes_via_peer(peer: StreamPeer):
	var _header = peer.get_data(2)
	var remaining_bytes = peer.get_data(peer.get_available_bytes())
	
	return from_bytes(remaining_bytes[1])