|
@@ -52,6 +52,10 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
internal int SetupNewOnlineGame(int limitPerQuestion, int limitPerPlayer, int toWin, List<InviteSearchResult> inviteUsers, List<int> selectedCategories) {
|
|
internal int SetupNewOnlineGame(int limitPerQuestion, int limitPerPlayer, int toWin, List<InviteSearchResult> inviteUsers, List<int> selectedCategories) {
|
|
|
List<int> playerIds = new List<int>();
|
|
List<int> playerIds = new List<int>();
|
|
|
inviteUsers.ForEach(i => playerIds.Add(i.GetId()));
|
|
inviteUsers.ForEach(i => playerIds.Add(i.GetId()));
|
|
|
|
|
+
|
|
|
|
|
+ List<string> playerNames = new List<String>();
|
|
|
|
|
+ inviteUsers.ForEach(i => playerNames.Add(i.GetName()));
|
|
|
|
|
+
|
|
|
int currentUser = Database.Instance.GetSignedInUser().Key;
|
|
int currentUser = Database.Instance.GetSignedInUser().Key;
|
|
|
playerIds.Add(currentUser);
|
|
playerIds.Add(currentUser);
|
|
|
|
|
|
|
@@ -70,6 +74,7 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (Int32.TryParse(response, out int newGameId)) {
|
|
if (Int32.TryParse(response, out int newGameId)) {
|
|
|
|
|
+ SendInviteForNewGame(newGameId, playerNames, Database.Instance.GetSignedInUser().Value);
|
|
|
return newGameId;
|
|
return newGameId;
|
|
|
} else {
|
|
} else {
|
|
|
Debug.Log("Failed to get new game id with response " + response);
|
|
Debug.Log("Failed to get new game id with response " + response);
|
|
@@ -227,7 +232,7 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
form.AddField("player" + index++, player.Key);
|
|
form.AddField("player" + index++, player.Key);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- CallDatabase("FirebaseCaller.php", form);
|
|
|
|
|
|
|
+ CallOnlineDatabaseWithResponse("FirebaseCaller.php", form);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void Start() {
|
|
private void Start() {
|
|
@@ -312,8 +317,8 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
if (gameId != currentGameId) { // Spel ej i listan
|
|
if (gameId != currentGameId) { // Spel ej i listan
|
|
|
if (ogs != null) { // lägg till spel i listan, inte första gången
|
|
if (ogs != null) { // lägg till spel i listan, inte första gången
|
|
|
SetGlobalGameInfo(userName, ogs, gameId, prevGame);
|
|
SetGlobalGameInfo(userName, ogs, gameId, prevGame);
|
|
|
- if (ogs.GameStatus == null) {
|
|
|
|
|
- ogs.SetGameStatus(game.status);
|
|
|
|
|
|
|
+ if (ogs.GameStatus == null || ogs.GameStatus.Equals("")) {
|
|
|
|
|
+ ogs.SetGameStatus(prevGame.status);
|
|
|
}
|
|
}
|
|
|
games.Add(ogs);
|
|
games.Add(ogs);
|
|
|
}
|
|
}
|
|
@@ -339,7 +344,7 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
|
|
|
|
|
SetGameStatus(ogs, signedInUser, og.onlineGamesList[og.onlineGamesList.Count - 1]);
|
|
SetGameStatus(ogs, signedInUser, og.onlineGamesList[og.onlineGamesList.Count - 1]);
|
|
|
SetGlobalGameInfo(userName, ogs, gameId, og.onlineGamesList[og.onlineGamesList.Count - 1]);
|
|
SetGlobalGameInfo(userName, ogs, gameId, og.onlineGamesList[og.onlineGamesList.Count - 1]);
|
|
|
- if (ogs.GameStatus == null) {
|
|
|
|
|
|
|
+ if (ogs.GameStatus == null || ogs.GameStatus.Equals("")) {
|
|
|
ogs.SetGameStatus(og.onlineGamesList[og.onlineGamesList.Count - 1].status);
|
|
ogs.SetGameStatus(og.onlineGamesList[og.onlineGamesList.Count - 1].status);
|
|
|
}
|
|
}
|
|
|
games.Add(ogs);
|
|
games.Add(ogs);
|
|
@@ -354,8 +359,6 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
} else if (game.status.Equals("PENDING")) {
|
|
} else if (game.status.Equals("PENDING")) {
|
|
|
if (game.userId.Equals(signedInUser.Key.ToString()) && game.playerStatus.Equals("WAITING")) {
|
|
if (game.userId.Equals(signedInUser.Key.ToString()) && game.playerStatus.Equals("WAITING")) {
|
|
|
ogs.SetGameStatus("INVITED");
|
|
ogs.SetGameStatus("INVITED");
|
|
|
- } else {
|
|
|
|
|
- ogs.SetGameStatus("PENDING");
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -367,10 +370,7 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
} else if (game.status.Equals("PENDING")) {
|
|
} else if (game.status.Equals("PENDING")) {
|
|
|
if (game.userId.Equals(signedInUser.Key.ToString()) && game.playerStatus.Equals("WAITING")) {
|
|
if (game.userId.Equals(signedInUser.Key.ToString()) && game.playerStatus.Equals("WAITING")) {
|
|
|
ogs.SetGameStatus("INVITED");
|
|
ogs.SetGameStatus("INVITED");
|
|
|
- } else {
|
|
|
|
|
- ogs.SetGameStatus("PENDING");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -674,11 +674,11 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
{
|
|
{
|
|
|
sb.AppendLine(player.Key + " (" + player.Value + ")");
|
|
sb.AppendLine(player.Key + " (" + player.Value + ")");
|
|
|
}
|
|
}
|
|
|
- String message = String.Format(LocalizationManager.Instance.GetText("FCM_NEXT_PLAYER_MESSAGE"),sb.ToString());
|
|
|
|
|
|
|
+ String message = String.Format(LocalizationManager.Instance.GetText("FCM_NEXT_PLAYER_MESSAGE"), sb.ToString());
|
|
|
form.AddField("message", message);
|
|
form.AddField("message", message);
|
|
|
form.AddField("type", "FCMNextPlayer");
|
|
form.AddField("type", "FCMNextPlayer");
|
|
|
|
|
|
|
|
- CallDatabase("FirebaseCaller.php", form);
|
|
|
|
|
|
|
+ CallOnlineDatabaseWithResponse("FirebaseCaller.php", form);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
internal void SendInviteForNewGame(int gameId, List<String> Players, String inviter) {
|
|
internal void SendInviteForNewGame(int gameId, List<String> Players, String inviter) {
|
|
@@ -693,7 +693,7 @@ public class OnlineDatabase : MonoBehaviour {
|
|
|
form.AddField("title", LocalizationManager.Instance.GetText("FCM_NEW_GAME_TITLE"));
|
|
form.AddField("title", LocalizationManager.Instance.GetText("FCM_NEW_GAME_TITLE"));
|
|
|
form.AddField("message", String.Format(LocalizationManager.Instance.GetText("FCM_NEW_GAME_MESSAGE"), inviter));
|
|
form.AddField("message", String.Format(LocalizationManager.Instance.GetText("FCM_NEW_GAME_MESSAGE"), inviter));
|
|
|
form.AddField("type", "InviteMessage");
|
|
form.AddField("type", "InviteMessage");
|
|
|
- CallDatabase("FirebaseCaller.php", form);
|
|
|
|
|
|
|
+ CallOnlineDatabaseWithResponse("FirebaseCaller.php", form);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|