diff --git a/GoldWars/GoldWars/MatchmakingHelper.swift b/GoldWars/GoldWars/MatchmakingHelper.swift index 16b2fee..bc557c3 100644 --- a/GoldWars/GoldWars/MatchmakingHelper.swift +++ b/GoldWars/GoldWars/MatchmakingHelper.swift @@ -111,12 +111,13 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe /* Vom match erhaltene Spielerdaten */ - private func match(match: GKMatch!, didReceiveData data: NSData!,fromPlayer playerID: String!) { - if mpMatch != match { return } + private func match(match: GKMatch!, didReceiveData data: Data,fromPlayer playerID: String!) { print("Daten empfangen!") + if mpMatch != match { return } + let pointer = UnsafeMutablePointer.allocate(capacity: MemoryLayout.size) - data.getBytes(pointer, length: MemoryLayout.size) + let message = pointer.move() switch message.messageType{ @@ -128,7 +129,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe } - delegate?.matchReceivedData(match: match, data: data, fromPlayer: playerID) + //delegate?.matchReceivedData(match: match, data: data, fromPlayer: playerID) } diff --git a/GoldWars/GoldWars/MessageProtocol.swift b/GoldWars/GoldWars/MessageProtocol.swift index 62d7e3d..f47f0cd 100644 --- a/GoldWars/GoldWars/MessageProtocol.swift +++ b/GoldWars/GoldWars/MessageProtocol.swift @@ -37,11 +37,11 @@ class MultiplayerNetwork: NSObject{ static let sharedInstance = MultiplayerNetwork() - func sendData(data: NSData) { + func sendData(data: Data) { let mmHelper = MatchmakingHelper.sharedInstance if let multiplayerMatch = mmHelper.mpMatch { do { - try multiplayerMatch.sendData(toAllPlayers: data as Data, with: .reliable) + try multiplayerMatch.sendData(toAllPlayers: data, with: .reliable) } catch { print("Tim war am Werk") } @@ -52,7 +52,7 @@ class MultiplayerNetwork: NSObject{ var playerMoveMsg = PlayerMove(messageType: MessageType.PlayerMove, unitCount: unitcount) - let data = NSData(bytes: &playerMoveMsg, length: MemoryLayout.size) + let data = Data(bytes: &playerMoveMsg, count: MemoryLayout.size) sendData(data: data) }