aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Models/Server.swift
blob: b39f1c40a91b3603b877323a6862981bd06c04c8 (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
import SwiftUI

struct Server: Identifiable, Equatable, Hashable, Codable {
  static let defaultPort: Int = 5500
  
  let id: UUID
  let name: String?
  let description: String?
  let users: Int
  let address: String
  let port: Int
  
  init(name: String?, description: String?, address: String, port: Int, users: Int = 0) {
    self.id = UUID()
    self.name = name
    self.description = description
    self.address = address.lowercased()
    self.port = port
    self.users = users
  }
  
  func hash(into hasher: inout Hasher) {
    hasher.combine(self.id)
  }
  
  static func == (lhs: Server, rhs: Server) -> Bool {
    return (lhs.address == rhs.address) && (lhs.port == rhs.port)
  }
}