diff --git a/Manager/Sources/RDMUICManager/BuildController.swift b/Manager/Sources/RDMUICManager/BuildController.swift index 29221f36..32ad0120 100644 --- a/Manager/Sources/RDMUICManager/BuildController.swift +++ b/Manager/Sources/RDMUICManager/BuildController.swift @@ -197,7 +197,7 @@ class BuildController { "startupLocationLon=\(device.startupLocationLon)", "encounterMaxWait=\(device.encounterMaxWait)", "encounterDelay=\(device.encounterDelay)", "fastIV=\(device.fastIV)", "ultraIV=\(device.ultraIV)", "deployEggs=\(device.deployEggs)", "token=\(device.token)", "ultraQuests=\(device.ultraQuests)", - "attachScreenshots=\(device.attachScreenshots)" + "attachScreenshots=\(device.attachScreenshots)", "appKey=\(device.appKey)" ) var contains = true diff --git a/Manager/Sources/RDMUICManager/CLI.swift b/Manager/Sources/RDMUICManager/CLI.swift index cecf2698..fa1de7a6 100644 --- a/Manager/Sources/RDMUICManager/CLI.swift +++ b/Manager/Sources/RDMUICManager/CLI.swift @@ -168,6 +168,7 @@ class CLI { Ultra Quests: \(device.ultraQuests.toBool()) Enabled: \(device.enabled.toBool()) AttachScreenshots: \(device.attachScreenshots.toBool()) + App Key: \(device.appKey) """ print(row + "\n") @@ -317,6 +318,11 @@ class CLI { defaultDevice.attachScreenshots = attachScreenshots!.toInt() } + let appKey = askInput("Default App Key (empty = \(defaultDevice.appKey))") + if appKey != "" { + defaultDevice.appKey = appKey + } + do { try defaultDevice.save() clear() @@ -473,6 +479,11 @@ class CLI { attachScreenshots = defaultDevice.attachScreenshots } + var appKey = askInput("App Key (empty = \(defaultDevice.appKey))") + if appKey == "" { + appKey = defaultDevice.appKey + } + device.uuid = uuid device.name = name device.backendURL = backendURL @@ -502,6 +513,7 @@ class CLI { device.ultraQuests = ultraQuests! device.enabled = enabled! device.attachScreenshots = attachScreenshots! + device.appKey = appKey do { try device.create() @@ -674,6 +686,11 @@ class CLI { device.attachScreenshots = attachScreenshots!.toInt() } + let appKey = askInput("App Key (empty = \(device.appKey))") + if appKey != "" { + device.appKey = appKey + } + do { try device.save() clear() diff --git a/Manager/Sources/RDMUICManager/Device.swift b/Manager/Sources/RDMUICManager/Device.swift index b3b3cd22..6078bc4a 100644 --- a/Manager/Sources/RDMUICManager/Device.swift +++ b/Manager/Sources/RDMUICManager/Device.swift @@ -53,6 +53,7 @@ class Device: SQLiteStORM, Equatable, Hashable { var ultraQuests: Int var enabled: Int var attachScreenshots: Int + var appKey: String override init() { self.uuid = "" @@ -84,6 +85,7 @@ class Device: SQLiteStORM, Equatable, Hashable { self.ultraQuests = 0 self.enabled = 1 self.attachScreenshots = 0 + self.appKey = "" super.init() } @@ -92,7 +94,7 @@ class Device: SQLiteStORM, Equatable, Hashable { targetMaxDistance: Double, itemFullCount: Int, questFullCount: Int, itemsPerStop: Int, minDelayLogout: Double, maxNoQuestCount: Int, maxFailedCount: Int, maxEmptyGMO: Int, startupLocationLat: Double, startupLocationLon: Double, encounterMaxWait: Int, encounterDelay: Double, fastIV: Int, ultraIV: Int, - deployEggs: Int, token: String, ultraQuests: Int, enabled: Int, attachScreenshots: Int) { + deployEggs: Int, token: String, ultraQuests: Int, enabled: Int, attachScreenshots: Int, appKey: String) { self.uuid = uuid self.name = name self.backendURL = backendURL @@ -122,6 +124,7 @@ class Device: SQLiteStORM, Equatable, Hashable { self.ultraQuests = ultraQuests self.enabled = enabled self.attachScreenshots = attachScreenshots + self.appKey = appKey super.init() } @@ -159,6 +162,7 @@ class Device: SQLiteStORM, Equatable, Hashable { ultraQuests = this.data["ultraQuests"] as? Int ?? 0 enabled = this.data["enabled"] as? Int ?? 1 attachScreenshots = this.data["attachScreenshots"] as? Int ?? 0 + appKey = this.data["appKey"] as? String ?? "" } static func getAll() -> [Device] { diff --git a/RealDeviceMap-UIControl.xcodeproj/xcshareddata/xcschemes/RealDeviceMap-UIControl.xcscheme b/RealDeviceMap-UIControl.xcodeproj/xcshareddata/xcschemes/RealDeviceMap-UIControl.xcscheme index 6158c29b..64dfee2b 100644 --- a/RealDeviceMap-UIControl.xcodeproj/xcshareddata/xcschemes/RealDeviceMap-UIControl.xcscheme +++ b/RealDeviceMap-UIControl.xcodeproj/xcshareddata/xcschemes/RealDeviceMap-UIControl.xcscheme @@ -208,6 +208,11 @@ value = "$(attachScreenshots)" isEnabled = "YES"> + + diff --git a/RealDeviceMap-UIControl/Config.swift b/RealDeviceMap-UIControl/Config.swift index 7982e5a9..d9bfae1c 100644 --- a/RealDeviceMap-UIControl/Config.swift +++ b/RealDeviceMap-UIControl/Config.swift @@ -39,6 +39,7 @@ class Config { var ultraQuests: Bool var enabled: Bool var attachScreenshots: Bool + var appKey: String init() { @@ -74,6 +75,7 @@ class Config { ultraQuests = enviroment["ultraQuests"]?.toBool() ?? false enabled = enviroment["enabled"]?.toBool() ?? true attachScreenshots = enviroment["attachScreenshots"]?.toBool() ?? false + appKey = enviroment["appKey"] ?? "" } } diff --git a/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift b/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift index b3b48c62..5da98ed1 100644 --- a/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift +++ b/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift @@ -987,6 +987,23 @@ class RealDeviceMap_UIControlUITests: XCTestCase { return HTTPResponse(.ok) } + func handleConfigRequest(request: HTTPRequest) -> HTTPResponse { + let responseData: [String: Any] = [ + "key": self.config.appKey ?? "", + "loc": "", // optional + "endpoints": [""] // optional + ] + do { + let jsonData = try JSONSerialization.data(withJSONObject: responseData, options: .prettyPrinted) + let jsonString = String(data: jsonData, encoding: .utf8) ?? "" + let response = HTTPResponse(content: jsonString) + response.headers = ["Content-Type": "application/json"] + return response + } catch { + return HTTPResponse(.internalServerError) + } + } + func part8Main() { if shouldExit || ((username == nil || isLoggedIn == false) && config.enableAccountManager) { @@ -1969,6 +1986,8 @@ class RealDeviceMap_UIControlUITests: XCTestCase { self.server.route(.post, "loc", self.handleLocRequest) self.server.route(.get, "data", self.handleDataRequest) self.server.route(.post, "data", self.handleDataRequest) + self.server.route(.get, "config", self.handleConfigRequest) + self.server.route(.post, "config", self.handleConfigRequest) self.lock.lock() self.currentLocation = self.config.startupLocation