TEST: Change Host Identifier to displayName, since the ID is not working for some odd reasons
This commit is contained in:
parent
570099911f
commit
cfe01cde54
@ -45,8 +45,11 @@ class TimerComponent: GKComponent {
|
||||
|
||||
if(isFinished()){
|
||||
self.labelNode.text = "Synching"
|
||||
if !MultiplayerNetwork.sharedInstance.isSending {
|
||||
MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.localPlayerMoves)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
|
@ -114,17 +114,15 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
||||
let jsonDecoder = JSONDecoder()
|
||||
|
||||
if let playerMoves = try? jsonDecoder.decode([PlayerMove].self, from: data) {
|
||||
DataService.sharedInstance.addRemotePlayerMoves(playerID: player.gamePlayerID, playerMoves: playerMoves)
|
||||
DataService.sharedInstance.addRemotePlayerMoves(playerID: player.displayName, playerMoves: playerMoves)
|
||||
}
|
||||
|
||||
if let message = try? jsonDecoder.decode(Host.self, from: data) {
|
||||
if !self.isServer {
|
||||
DataService.sharedInstance.gameHost = message
|
||||
print("LocalID: \(GKLocalPlayer.local.gamePlayerID)")
|
||||
print("Name: \(player.displayName)")
|
||||
print("ServerID: \(message.playerID)")
|
||||
}
|
||||
|
||||
}
|
||||
MultiplayerNetwork.sharedInstance.isSending = false
|
||||
}
|
||||
|
||||
/*
|
||||
@ -171,10 +169,11 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
||||
self.mpMatchStarted = true
|
||||
|
||||
if player == GKLocalPlayer.local {
|
||||
print("ich bin host")
|
||||
self.isServer = true
|
||||
self.spieler1 = player
|
||||
self.nameSpieler1 = self.spieler1!.displayName
|
||||
DataService.sharedInstance.setGameHost(host: Host(playerID: player!.gamePlayerID))
|
||||
DataService.sharedInstance.setGameHost(host: Host(playerID: player!.displayName))
|
||||
} else {
|
||||
self.isServer = false
|
||||
}
|
||||
|
@ -8,9 +8,11 @@
|
||||
|
||||
import GameplayKit
|
||||
import Foundation
|
||||
import GameKit
|
||||
|
||||
class MultiplayerNetwork{
|
||||
static let sharedInstance = MultiplayerNetwork()
|
||||
var isSending = false
|
||||
|
||||
func sendData(data: Data) {
|
||||
let mmHelper = MatchmakingHelper.sharedInstance
|
||||
@ -25,11 +27,16 @@ class MultiplayerNetwork{
|
||||
|
||||
func sendDataToHost(data: Data) {
|
||||
let mmHelper = MatchmakingHelper.sharedInstance
|
||||
let hostGKPlayer = MatchmakingHelper.sharedInstance.mpMatch?.players.filter{ $0.gamePlayerID == DataService.sharedInstance.gameHost?.playerID}
|
||||
for player in mmHelper.mpMatch!.players {
|
||||
print(player.displayName)
|
||||
}
|
||||
print(DataService.sharedInstance.gameHost!.playerID)
|
||||
|
||||
let hostGKPlayer = MatchmakingHelper.sharedInstance.mpMatch?.players.filter{ $0.displayName == DataService.sharedInstance.gameHost!.playerID}[0]
|
||||
|
||||
if let multiplayerMatch = mmHelper.mpMatch{
|
||||
do {
|
||||
try multiplayerMatch.send(data, to: hostGKPlayer!, dataMode: .reliable)
|
||||
try multiplayerMatch.send(data, to: [hostGKPlayer!], dataMode: .reliable)
|
||||
} catch {
|
||||
print("Tim war mal wieder am Werk der Krasse")
|
||||
}
|
||||
@ -37,7 +44,8 @@ class MultiplayerNetwork{
|
||||
}
|
||||
|
||||
func sendPlayerMoves(playerMoves: [PlayerMove]) {
|
||||
if !MatchmakingHelper.sharedInstance.isServer {
|
||||
if MatchmakingHelper.sharedInstance.isServer == false {
|
||||
self.isSending = true
|
||||
let encoder = JSONEncoder()
|
||||
let encoded = (try? encoder.encode(playerMoves))!
|
||||
sendDataToHost(data: encoded)
|
||||
|
Loading…
Reference in New Issue
Block a user