diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..019b148 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,31 @@ +name: Test + +on: + push: + branches: [main] + pull_request: + branches: ['*'] + +jobs: + macos: + name: build + runs-on: macos-13 + env: + DEVELOPER_DIR: /Applications/Xcode_15.0.app/Contents/Developer + + steps: + - name: Checkout steamworks SDK + uses: actions/checkout@v3 + with: + repository: johnfairh/steamworks-swift-sdk + path: steamworks-sdk + + - name: Checkout spacewar + uses: actions/checkout@v3 + with: + path: spacewar + + - name: Build + run: | + cd steamworks-sdk && make install && cd .. + cd spacewar && swift build diff --git a/Package.resolved b/Package.resolved index e18ce03..8c818c4 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/johnfairh/steamworks-swift", "state" : { - "revision" : "d65d442139b042ce1172de95b915e9974c7d7fa7", - "version" : "0.3.0" + "revision" : "a127c38e25b1222d945c77a358638c4eea882e0e", + "version" : "0.4.0" } }, { @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-log.git", "state" : { - "revision" : "32e8d724467f8fe623624570367e3d50c5638e46", - "version" : "1.5.2" + "revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed", + "version" : "1.5.3" } }, { @@ -23,8 +23,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/johnfairh/TMLEngines", "state" : { - "revision" : "51a2ff3056ff60d3ebc6df1f3d8504d02b7c8ef3", - "version" : "1.3.0" + "revision" : "6ba327419697ce9e150f6c782a59fa7b4ea89124", + "version" : "1.3.1" } } ], diff --git a/Package.swift b/Package.swift index f972330..bb91498 100644 --- a/Package.swift +++ b/Package.swift @@ -9,7 +9,7 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/johnfairh/steamworks-swift", - from: "0.3.0"), + from: "0.4.0"), .package(url: "https://github.com/johnfairh/TMLEngines", from: "1.2.0") ], diff --git a/Sources/SpaceWar/App.swift b/Sources/SpaceWar/App.swift index 1d98238..41019d7 100644 --- a/Sources/SpaceWar/App.swift +++ b/Sources/SpaceWar/App.swift @@ -17,7 +17,7 @@ import Dispatch struct SpaceWarApp: App { init() { // Some nonsense to simulate a library that probably doesn't exist - Steamworks_InstallCEGHooks(initCEG: Steamworks_InitCEGLibrary, termCEG: Steamworks_TermCEGLibrary) + SteamAPI.installCEGHooks(initCEG: Steamworks_InitCEGLibrary, termCEG: Steamworks_TermCEGLibrary) #if SWIFT_PACKAGE // Some nonsense to make the app work properly when built outside of Xcode. diff --git a/Sources/SpaceWar/Controller.swift b/Sources/SpaceWar/Controller.swift index 86e40c3..c1ed926 100644 --- a/Sources/SpaceWar/Controller.swift +++ b/Sources/SpaceWar/Controller.swift @@ -211,7 +211,7 @@ final class Controller { // MARK: Effects /// Set the LED color on the controller, if supported by controller - func setColor(_ color: Color2D, flags: SteamControllerLEDFlag) { + func setColor(_ color: Color2D, flags: SteamInputLEDFlag) { let channels = color.integerChannels steam.input.setLEDColor(handle: activeControllerHandle, colorR: UInt8(channels.r), diff --git a/Sources/SpaceWar/SpaceWarClientConnection.swift b/Sources/SpaceWar/SpaceWarClientConnection.swift index d3ba446..8b90070 100644 --- a/Sources/SpaceWar/SpaceWarClientConnection.swift +++ b/Sources/SpaceWar/SpaceWarClientConnection.swift @@ -84,7 +84,9 @@ final class SpaceWarClientConnection { private(set) var connectionError: String? /// The net connection for the current connection/attempted connection, or nil if none private(set) var netConnection: HSteamNetConnection? - /// The Steam ID of the game server, or nil if not connected/don't know yet + /// The server steam ID we've been asked to connect to + private(set) var serverSteamIDFromBrowser: SteamID? + /// The actual Steam ID of the game server, or nil if not connected/don't know yet private(set) var serverSteamID: SteamID? /// The name of the server, if known private(set) var serverName: String? @@ -102,8 +104,9 @@ final class SpaceWarClientConnection { precondition(state == .notConnected || state == .pingingServer, "Server connection already busy: \(state)") OutputDebugString("ClientConnection \(state) -> connectingP2P") state = .connectingP2P - serverSteamID = steamID - + serverSteamIDFromBrowser = steamID // save this, what we connected to + serverSteamID = steamID // for now, may overwrite in a response + if !FAKE_NET_USE { let identity = SteamNetworkingIdentity(steamID) netConnection = steam.networkingSockets.connectP2P(identityRemote: identity, remoteVirtualPort: 0, options: []) @@ -308,7 +311,16 @@ final class SpaceWarClientConnection { // this lets our friends connect to this game via their friends list updateRichPresence() - let authStatus = steam.user.getAuthSessionTicket() + // if the server Steam ID was aquired from another source ( m_steamIDGameServerFromBrowser ) + // then use it as the identity + // if it only came from the server itself, then use the IP address + let identity: SteamNetworkingIdentity + if serverSteamID == serverSteamIDFromBrowser { + identity = .init(serverSteamID!) + } else { + identity = .init(SteamNetworkingIPAddr(ipv4: serverIP!, port: serverPort!)) + } + let authStatus = steam.user.getAuthSessionTicket(steamNetworkingIdentity: identity) if authStatus.ticketSize < 1 { OutputDebugString("Warning: Looks like GetAuthSessionTicket didn't give us a good ticket") }