diff options
| author | Dustin Mierau <dustin@mierau.me> | 2024-01-16 20:34:42 -0800 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2024-01-16 20:34:42 -0800 |
| commit | 8e85fbbdadcb993cd270ff4bf60d2280b9e7ad56 (patch) | |
| tree | f8e6d2ac7a0b709fab8b6e5b4b6ae5d5eb01a341 /Hotline | |
| parent | 993788879f6998f28c5305e14ea863b69b626a98 (diff) | |
Cleanup HotlineTrackerClient header parsing by moving to byte consumption API
Diffstat (limited to 'Hotline')
| -rw-r--r-- | Hotline/Hotline/HotlineTrackerClient.swift | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Hotline/Hotline/HotlineTrackerClient.swift b/Hotline/Hotline/HotlineTrackerClient.swift index d7653df..36ed628 100644 --- a/Hotline/Hotline/HotlineTrackerClient.swift +++ b/Hotline/Hotline/HotlineTrackerClient.swift @@ -117,14 +117,21 @@ class HotlineTrackerClient { return } - let header: [UInt8] = self.socket.read(count: 8) - if header.count != 8 { + var header: [UInt8] = self.socket.read(count: 8) + + guard let messageType = header.consumeUInt16(), + let dataLength = header.consumeUInt16(), + let numberOfServers = header.consumeUInt16(), + let numberOfServers2 = header.consumeUInt16() else { + self.socket.close() return } - self.expectedDataLength = Int(header[2]) * 0xFF + Int(header[3]) - self.expectedDataLength -= 4 - self.serverCount = Int(header[4]) * 256 + Int(header[5]) + print("HotlineTrackerClient: Received response header ", messageType, dataLength, numberOfServers, numberOfServers2) + + self.expectedDataLength = Int(dataLength) + self.expectedDataLength -= 4 // Remove the size of the two server count fields + self.serverCount = Int(numberOfServers) self.stage = .listing self.receiveListing() @@ -176,7 +183,6 @@ class HotlineTrackerClient { } self.servers = foundServers - self.stage = .done self.socket.close() } |