2019-05-30 17:10:50 -07:00
|
|
|
//
|
|
|
|
|
// ServerProtocol.swift
|
|
|
|
|
// AltServer
|
|
|
|
|
//
|
|
|
|
|
// Created by Riley Testut on 5/24/19.
|
|
|
|
|
// Copyright © 2019 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
|
|
public let ALTServerServiceType = "_altserver._tcp"
|
|
|
|
|
|
|
|
|
|
// Can only automatically conform ALTServerError.Code to Codable, not ALTServerError itself
|
|
|
|
|
extension ALTServerError.Code: Codable {}
|
|
|
|
|
|
2019-06-21 11:20:03 -07:00
|
|
|
protocol ServerMessage: Codable
|
2019-05-30 17:10:50 -07:00
|
|
|
{
|
2019-06-21 11:20:03 -07:00
|
|
|
var version: Int { get }
|
|
|
|
|
var identifier: String { get }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct PrepareAppRequest: ServerMessage
|
|
|
|
|
{
|
|
|
|
|
public var version = 1
|
|
|
|
|
public var identifier = "PrepareApp"
|
|
|
|
|
|
2019-05-30 17:10:50 -07:00
|
|
|
public var udid: String
|
|
|
|
|
public var contentSize: Int
|
|
|
|
|
|
|
|
|
|
public init(udid: String, contentSize: Int)
|
|
|
|
|
{
|
|
|
|
|
self.udid = udid
|
|
|
|
|
self.contentSize = contentSize
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-21 11:20:03 -07:00
|
|
|
public struct BeginInstallationRequest: ServerMessage
|
2019-05-30 17:10:50 -07:00
|
|
|
{
|
2019-06-21 11:20:03 -07:00
|
|
|
public var version = 1
|
|
|
|
|
public var identifier = "BeginInstallation"
|
|
|
|
|
|
|
|
|
|
public init()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct ServerResponse: ServerMessage
|
|
|
|
|
{
|
|
|
|
|
public var version = 1
|
|
|
|
|
public var identifier = "ServerResponse"
|
|
|
|
|
|
2019-06-10 15:03:47 -07:00
|
|
|
public var progress: Double
|
|
|
|
|
|
2019-05-30 17:10:50 -07:00
|
|
|
public var error: ALTServerError? {
|
|
|
|
|
get {
|
|
|
|
|
guard let code = self.errorCode else { return nil }
|
|
|
|
|
return ALTServerError(code)
|
|
|
|
|
}
|
|
|
|
|
set {
|
|
|
|
|
self.errorCode = newValue?.code
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private var errorCode: ALTServerError.Code?
|
|
|
|
|
|
2019-06-10 15:03:47 -07:00
|
|
|
public init(progress: Double, error: ALTServerError?)
|
2019-05-30 17:10:50 -07:00
|
|
|
{
|
2019-06-10 15:03:47 -07:00
|
|
|
self.progress = progress
|
2019-05-30 17:10:50 -07:00
|
|
|
self.error = error
|
|
|
|
|
}
|
|
|
|
|
}
|