trackinfos werden zu beginn von rundenstart aktualisiert und danach nur wenn ein spieler joint
parent
5531b57018
commit
0bc4012774
|
|
@ -62,13 +62,11 @@ public class GameController {
|
||||||
userAccessTokens.put(username, playerAccessToken);
|
userAccessTokens.put(username, playerAccessToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!userAccessTokens.containsKey(username)) {
|
||||||
if (accessToken == null) {
|
ctx.status(401).result("Zugriffstoken für Benutzer " + username + " nicht gefunden.");
|
||||||
ctx.status(401).result("Zugriffstoken fehlt oder ist ungültig");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var devices = authService.getDevices(userAccessTokens.get(username));
|
||||||
var devices = authService.getDevices(accessToken);
|
|
||||||
ctx.json(devices);
|
ctx.json(devices);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ public class SpotifyAuthService {
|
||||||
return tempApi.authorizationCodeUri()
|
return tempApi.authorizationCodeUri()
|
||||||
.scope(scope)
|
.scope(scope)
|
||||||
.state(user) // Der Benutzername wird im State mitgegeben
|
.state(user) // Der Benutzername wird im State mitgegeben
|
||||||
.show_dialog(true)
|
//.show_dialog(true)
|
||||||
.build()
|
.build()
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,14 +88,36 @@ public class GameWebSocketHandler {
|
||||||
.flatMap(List::stream)
|
.flatMap(List::stream)
|
||||||
.toList();
|
.toList();
|
||||||
System.out.println("AlltracksCache für Spiel " + gameId + " hat " + allTracks.size() + " Songs (rundenstart)");
|
System.out.println("AlltracksCache für Spiel " + gameId + " hat " + allTracks.size() + " Songs (rundenstart)");
|
||||||
|
//Trackinfos für alle Spieler sammeln
|
||||||
|
|
||||||
|
if(playerTrackInfoCache.containsKey(gameId)){
|
||||||
|
// Wenn der Cache schon existiert, dann nur die Trackinfos nutzen
|
||||||
|
System.out.println("TrackInfosCache für Spiel " + gameId + " existiert bereits (rundenstart)");
|
||||||
|
// prüfen ob ein neuer spieler dazugekommen ist
|
||||||
|
if( allPlayerTracks.size() > playerTrackInfoCache.get(gameId).size()) {
|
||||||
|
System.out.println("Neuer Spieler hinzugefügt, Trackinfos werden aktualisiert (rundenstart)");
|
||||||
|
Map<String, List<String>> allTrackInfos = service.getTrackInfos(allPlayerTracks);
|
||||||
|
// Cache für Trackinfos pro Spiel-ID aktualisieren
|
||||||
|
playerTrackInfoCache.put(gameId, allTrackInfos);
|
||||||
|
} else {
|
||||||
|
System.out.println("Keine neuen Spieler, Trackinfos bleiben unverändert (rundenstart)");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Wenn der Cache nicht existiert, dann Trackinfos sammeln
|
||||||
|
System.out.println("TrackInfosCache für Spiel " + gameId + " wird erstellt (rundenstart)");
|
||||||
|
Map<String, List<String>> allTrackInfos = service.getTrackInfos(allPlayerTracks);
|
||||||
|
// Cache für Trackinfos pro Spiel-ID
|
||||||
|
playerTrackInfoCache.put(gameId, allTrackInfos);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("TrackInfosCache für Spiel " + gameId + " hat " + playerTrackInfoCache.get(gameId).size() + " Spieler (rundenstart)");
|
||||||
|
|
||||||
|
|
||||||
if (!allTracks.isEmpty()) {
|
if (!allTracks.isEmpty()) {
|
||||||
service.startRound(gameId, allTracks);
|
service.startRound(gameId, allTracks);
|
||||||
}
|
}
|
||||||
// Trackinfos für alle Spieler sammeln
|
//
|
||||||
//Map<String, List<String>> allTrackInfos = service.getTrackInfos(allPlayerTracks);
|
|
||||||
// Cache für Trackinfos pro Spiel-ID
|
|
||||||
//playerTrackInfoCache.put(gameId, allTrackInfos);
|
|
||||||
//System.out.println("TrackInfosCache für Spiel " + gameId + " hat " + allTrackInfos.size() + " Spieler (rundenstart)");
|
|
||||||
broadcastRoundStart(gameId);
|
broadcastRoundStart(gameId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -165,8 +187,9 @@ private void broadcastRoundResult(String gameId) {
|
||||||
broadcastToAll(gameId, msg);
|
broadcastToAll(gameId, msg);
|
||||||
|
|
||||||
// Prüfe auf Gewinner
|
// Prüfe auf Gewinner
|
||||||
|
int score = 6; // Punktestand für den Gewinn
|
||||||
String winner = scores.entrySet().stream()
|
String winner = scores.entrySet().stream()
|
||||||
.filter(e -> e.getValue() >= 6)
|
.filter(e -> e.getValue() >= score)
|
||||||
.map(Map.Entry::getKey)
|
.map(Map.Entry::getKey)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue