921 lines
35 KiB
C#
921 lines
35 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.NetworkInformation;
|
|
using Analytics;
|
|
|
|
using Audio;
|
|
|
|
using LightJSON;
|
|
|
|
using Localization;
|
|
|
|
using Network;
|
|
using Online;
|
|
using ResourceLoading;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.Assertions;
|
|
|
|
namespace ConsoleConnection
|
|
{
|
|
[RequireComponent(typeof(ConsoleDiscoveringManager))]
|
|
public class ConnectionManager : MonoBehaviour
|
|
{
|
|
// Singleton Instance
|
|
public static ConnectionManager Instance { get; private set; }
|
|
|
|
public int UpsellFirstSession = 2; // don't display upsell before session X
|
|
public int UpsellFrequency = 2; // every X game sessions
|
|
public int UpsellMaxPopups = 3;
|
|
|
|
private bool _displayWizards = true;
|
|
|
|
private int pairingNb = 0;
|
|
|
|
private ConsoleDiscoveringManager _consoleDiscoveringManager = null;
|
|
|
|
public int GameVersion {
|
|
get { return _gameVersion; }
|
|
}
|
|
|
|
public ConsoleServer.ConsoleType? ConsoleType {
|
|
get { return _consoleType; }
|
|
}
|
|
|
|
public string PairingCode
|
|
{
|
|
get { return _pairingCode; }
|
|
}
|
|
|
|
private ConsoleServer.ConsoleType? _consoleType = null;
|
|
private int _gameVersion = 0;
|
|
private string _pairingCode = null;
|
|
private bool _pressAShown = false;
|
|
private bool _sameNetworkShown = false;
|
|
private HttpEngine_BestHTTP.HTTPReqStateStatusCode connectionError;
|
|
public bool pairingScreenShowed = false;
|
|
|
|
public delegate void ConsoleDiscoveryStarted();
|
|
public event ConsoleDiscoveryStarted OnConsoleDiscoveryStarted;
|
|
|
|
public delegate void ConsoleDiscoveryFailed(DiscoveryError discoveryFailed);
|
|
public event ConsoleDiscoveryFailed OnConsoleDiscoveryFailed;
|
|
|
|
public enum DiscoveryError {NoWifi, Timeout}
|
|
|
|
public delegate void ConsoleDiscoveryFinished(List<ConsoleServer> consoleDiscoveryFiltered);
|
|
public event ConsoleDiscoveryFinished OnConsoleDiscoveryFinished;
|
|
|
|
void Awake()
|
|
{
|
|
Assert.IsNull(Instance);
|
|
Instance = this;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
_consoleDiscoveringManager = GetComponent<ConsoleDiscoveringManager>();
|
|
_consoleDiscoveringManager.OnCompleted += OnDiscoveryCompleted;
|
|
|
|
ConsoleNetworkManager.Instance.OnConsoleConnected += OnConsoleConnected;
|
|
ConsoleNetworkManager.Instance.OnConsoleDisconnected += OnConsoleDisconnected;
|
|
ConsoleNetworkManager.Instance.OnPunchPairing += OnPunchPairing;
|
|
ConsoleNetworkManager.Instance.OnProfileMessageReceived += NewProfileReceived;
|
|
ConsoleNetworkManager.Instance.OnTriggerTransition += OnTriggerTransition;
|
|
ConsoleNetworkManager.Instance.OnPopupShouldDisappear += OnPopupShouldDisappear;
|
|
ConsoleNetworkManager.Instance.OnShortcutSetup += OnShortcutSetup;
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
_consoleDiscoveringManager.OnCompleted -= OnDiscoveryCompleted;
|
|
|
|
ConsoleNetworkManager.Instance.OnConsoleConnected -= OnConsoleConnected;
|
|
ConsoleNetworkManager.Instance.OnConsoleDisconnected -= OnConsoleDisconnected;
|
|
ConsoleNetworkManager.Instance.OnPunchPairing -= OnPunchPairing;
|
|
ConsoleNetworkManager.Instance.OnProfileMessageReceived -= NewProfileReceived;
|
|
ConsoleNetworkManager.Instance.OnTriggerTransition -= OnTriggerTransition;
|
|
ConsoleNetworkManager.Instance.OnPopupShouldDisappear -= OnPopupShouldDisappear;
|
|
ConsoleNetworkManager.Instance.OnShortcutSetup -= OnShortcutSetup;
|
|
}
|
|
|
|
private bool IsWifiConnected()
|
|
{
|
|
return (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork);
|
|
}
|
|
|
|
public void StartBackgroundDiscovery()
|
|
{
|
|
if (_consoleDiscoveringManager.IsSearching)
|
|
return;
|
|
|
|
if (OnConsoleDiscoveryStarted != null)
|
|
OnConsoleDiscoveryStarted();
|
|
|
|
if (!IsWifiConnected())
|
|
{
|
|
if(OnConsoleDiscoveryFailed != null)
|
|
OnConsoleDiscoveryFailed(DiscoveryError.NoWifi);
|
|
|
|
return;
|
|
}
|
|
|
|
_displayWizards = false;
|
|
_consoleDiscoveringManager.Discover(_pairingCode);
|
|
}
|
|
|
|
public void LaunchConnectionFlow()
|
|
{
|
|
if (!IsWifiConnected())
|
|
{
|
|
var wifiPopup = UiBuilder.Instance.BuildWifiPopup();
|
|
Statistics.NewWizardScreen("WifiPopup");
|
|
UiManager.Instance.DisplayAppPopupScreen(wifiPopup);
|
|
return;
|
|
}
|
|
|
|
// if discovery is already in progress, stop it first
|
|
if (_consoleDiscoveringManager.IsSearching)
|
|
_consoleDiscoveringManager.Cancel();
|
|
|
|
UiManager.Instance.PrepareScreenTransition();
|
|
|
|
_displayWizards = true;
|
|
pairingNb++;
|
|
_consoleDiscoveringManager.Discover(_pairingCode);
|
|
}
|
|
|
|
public void OnDiscoveryCompleted(List<ConsoleServer> Consoles, HttpEngine_BestHTTP.HTTPReqStateStatusCode connectionError)
|
|
{
|
|
// Calling the event with the filtered console list
|
|
if(OnConsoleDiscoveryFinished != null)
|
|
OnConsoleDiscoveryFinished(Consoles);
|
|
|
|
if (!_displayWizards)
|
|
{
|
|
// exit here if we're just doing a background discovery
|
|
return;
|
|
}
|
|
|
|
var filteredConsoleList = Consoles.Where(console =>
|
|
((_consoleType == null) || (_consoleType.Value == console.Platform))
|
|
&& ((_pairingCode == null) || (_pairingCode == console.PairingCode))
|
|
&& ((_gameVersion == 0) || (_gameVersion == TitleDatabase.ExtractGameVersion(console.TitleId)))
|
|
).ToList();
|
|
|
|
this.connectionError = connectionError;
|
|
DisplayWizardFilterdConsole(filteredConsoleList);
|
|
}
|
|
|
|
private void DisplayWizardFilterdConsole(List<ConsoleServer> filteredConsoleList)
|
|
{
|
|
switch (filteredConsoleList.Count)
|
|
{
|
|
case 0: ShowAppropriateHelpWizardScreen(); break; // no console found
|
|
case 1:
|
|
|
|
if (connectionError != null)
|
|
{
|
|
Debug.LogError(connectionError.reqState + " " + connectionError.statusCode);
|
|
return;
|
|
}
|
|
|
|
var console = filteredConsoleList[0];
|
|
ConnectToConsole(console);
|
|
Statistics.SetWizardPairingMethod("Auto-Connect");
|
|
|
|
var version = TitleDatabase.ExtractGameVersion(console.TitleId);
|
|
|
|
// We set the game version to prevent having the helping wizard badly set afterward
|
|
_gameVersion = version;
|
|
break; // auto-connect when exactly one console is found
|
|
default: ShowSelectYourConsoleScreen(filteredConsoleList); break; // multiple consoles
|
|
};
|
|
}
|
|
|
|
public void ConnectToConsole(ConsoleServer console)
|
|
{
|
|
_consoleType = console.Platform;
|
|
_gameVersion = TitleDatabase.ExtractGameVersion(console.TitleId);
|
|
_pairingCode = console.PairingCode;
|
|
UiManager.Instance.pairingCode = console.PairingCode;
|
|
|
|
if ((_gameVersion == 0) || (TitleDatabase.IsVersionCompatibleWithConsoleAndPhone(_gameVersion, _consoleType.Value) != TitleDatabase.Compatibility.Compatible))
|
|
ShowAppropriateHelpWizardScreen();
|
|
else
|
|
{
|
|
Manager.Get().ResourceServer = console;
|
|
|
|
UiManager.Instance.PrepareScreenTransition();
|
|
|
|
ShortcutModel.enabled = true;
|
|
|
|
// anonymous/guest connection
|
|
ConsoleNetworkManager.Instance.Connect(console);
|
|
}
|
|
}
|
|
|
|
void OnConsoleConnected(int gameVersion, string titleID, int protocolVersion, string platformName, string consoleName)
|
|
{
|
|
// Only setting the stats if no console was found / no title put because we're still connecting
|
|
if(Statistics.wizardStartingConsoleNumber == "No console") {
|
|
Statistics.wizardStartingConsoleNumber = gameVersion.ToString();
|
|
}
|
|
|
|
if(Statistics.wizardStartingVersion == "+ 0 Game") {
|
|
Statistics.wizardStartingVersion = platformName;
|
|
}
|
|
|
|
Statistics.CloseWizardSession("ConnectionSucceed", true);
|
|
|
|
// Use shared console server data as a fallback (some data can be missing when connecting manually)
|
|
ConsoleServer console = Manager.Get().ResourceServer;
|
|
|
|
consoleName = string.IsNullOrEmpty(consoleName) ? console.DisplayName : consoleName;
|
|
titleID = string.IsNullOrEmpty(titleID) ? console.TitleId : titleID;
|
|
|
|
_consoleType = TitleDatabase.ExtractConsoleType(titleID);
|
|
_gameVersion = TitleDatabase.ExtractGameVersion(titleID);
|
|
|
|
// update console server
|
|
if (_consoleType != null)
|
|
console.Platform = _consoleType.Value;
|
|
|
|
console.DisplayName = consoleName;
|
|
console.TitleId = titleID;
|
|
|
|
// Save statistics
|
|
Statistics.LaunchJdControllerSession(console.Platform.ToString(), consoleName, gameVersion, titleID, protocolVersion, pairingNb);
|
|
pairingNb = 0;
|
|
|
|
var maxGameVersion = Math.Max(gameVersion, PlayerPrefs.GetInt("MaxJDVersion", 0));
|
|
PlayerPrefs.SetInt("MaxJDVersion", maxGameVersion);
|
|
|
|
// remove loading popup
|
|
UiManager.Instance.DisplayAppPopupScreen(null);
|
|
ShortcutModel.enabled = false;
|
|
}
|
|
|
|
void OnConsoleDisconnected(string errorMessage, bool hadConnection)
|
|
{
|
|
Debug.Log("disconnected:" + errorMessage);
|
|
|
|
if (hadConnection == false)
|
|
{
|
|
ShowAppropriateHelpWizardScreen();
|
|
UiManager.Instance.DisplayGamePopupScreen(null);
|
|
UiManager.Instance.DisplayWaitingScreen(null);
|
|
UiManager.Instance.UndisplayTransition();
|
|
}
|
|
else
|
|
{
|
|
ResetWizardValues();
|
|
UiManager.Instance.pairingCode = string.Empty;
|
|
Statistics.CloseJdControllerSession();
|
|
|
|
DisplayLandingScreen();
|
|
UiManager.Instance.DisplayGamePopupScreen(null);
|
|
UiManager.Instance.DisplayWaitingScreen(null);
|
|
|
|
var errorPopup = UiBuilder.Instance.BuildErrorPopup(errorMessage);
|
|
UiManager.Instance.DisplayAppPopupScreen(errorPopup, 5.0f, false, AudioManager.SoundIds.NotifWarning);
|
|
}
|
|
}
|
|
|
|
static bool bSendOnlyBestLocalIp= false;
|
|
|
|
void OnPunchPairing(ushort localPort, string consoleIP)
|
|
{
|
|
if(bSendOnlyBestLocalIp)
|
|
{
|
|
//Debug.LogError("PUNCH PARING GETTING BEST LOCAL IP FROM CONSOLE SUB NETWORK ");
|
|
var localIp = GetLocalIpAddress(consoleIP);
|
|
if(localIp!=null)
|
|
{
|
|
// signal JMCS that the phone is listening
|
|
OnlineEngine.Session.InitiatePunchPairing(_pairingCode, localIp, localPort)
|
|
.Finally(() => {
|
|
});
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//Debug.LogError("PUNCH PARING SENDING ALL POSSIBLE LOCAL IPs ");
|
|
var AllIpAddresses = GetAllLocalIpAddressesFromNetworkInterface();
|
|
|
|
foreach (var IP in AllIpAddresses)
|
|
{
|
|
OnlineEngine.Session.InitiatePunchPairing(_pairingCode, IP.ToString(), localPort)
|
|
.Finally(() => {
|
|
// Ignore the result of this query:
|
|
// - if it succeeded, we still need to wait for the other side to successfully connect
|
|
// to establish the full connection
|
|
// - if it failed, the error will come from the lower level Accept() timing out
|
|
//
|
|
// In any case, the success or error will come from the ConsoleNetworkManager.Connect() call,
|
|
// which is consistent with the non-punching case and unifies the flow for
|
|
// upper architectural layers.
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
private string GetLocalIpAddress(string optionalConsoleIpAddress)
|
|
{
|
|
//first get the list of IP addresses, in 2 ways
|
|
var AllIpAddresses = GetAllLocalIpAddressesFromNetworkInterface(); // OR else : var AllIpAddresses = GetAllLocalIpAddressesFromDNS();
|
|
|
|
if (AllIpAddresses.Count == 0)
|
|
{
|
|
Debug.LogError("Couldn't find any device local IP address, pairing will fail.");
|
|
return null;
|
|
}
|
|
|
|
// then get the best IP in 2 ways
|
|
var ipAddressFromConsoleNetwork = GetLocalIPFromBestSubNetwork(AllIpAddresses,optionalConsoleIpAddress);
|
|
|
|
|
|
//return which better IP to use
|
|
if(ipAddressFromConsoleNetwork!=null)
|
|
return ipAddressFromConsoleNetwork;
|
|
else
|
|
return GetLowestLocalIPAddress(AllIpAddresses);
|
|
}
|
|
|
|
static private bool IsPrivateIpAddress(IPAddress ip)
|
|
{
|
|
int[] ipParts = ip.ToString().Split(new String[] { "." }, StringSplitOptions.RemoveEmptyEntries)
|
|
.Select(s => int.Parse(s)).ToArray();
|
|
|
|
// in private ip range
|
|
return (ipParts[0] == 10 ||
|
|
(ipParts[0] == 192 && ipParts[1] == 168) ||
|
|
(ipParts[0] == 172 && (ipParts[1] >= 16 && ipParts[1] <= 31)));
|
|
}
|
|
|
|
static private bool IsValidIpAddress(IPAddress ip)
|
|
{
|
|
return ((ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
|
|
&& (ip != IPAddress.Loopback)
|
|
&& IsPrivateIpAddress(ip));
|
|
}
|
|
|
|
private List<IPAddress> GetAllLocalIpAddressesFromDNS()
|
|
{
|
|
List<IPAddress> result = new List<IPAddress>();
|
|
// Debug.Log("--Addresses from DNS--");
|
|
foreach (var ip in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
|
|
{
|
|
if(IsValidIpAddress(ip))
|
|
{
|
|
// Debug.Log(ip);
|
|
result.Add(ip);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private List<IPAddress> GetAllLocalIpAddressesFromNetworkInterface()
|
|
{
|
|
List<IPAddress> result = new List<IPAddress>();
|
|
|
|
//Debug.LogError("--Addresses from Network Interface--");
|
|
foreach (var itf in NetworkInterface.GetAllNetworkInterfaces())
|
|
{
|
|
//Debug.LogError("(NetType '" + itf.NetworkInterfaceType + "'):" + itf.Name);
|
|
var unicastAddresses = itf.GetIPProperties().UnicastAddresses;
|
|
foreach (var add in unicastAddresses)
|
|
{
|
|
if (IsValidIpAddress(add.Address))
|
|
{
|
|
//Debug.LogError(" ->: "+ add.Address+ "(NetType '" + itf.NetworkInterfaceType + "'):" + itf.Name);
|
|
result.Add(add.Address);
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private string GetLowestLocalIPAddress(List<IPAddress> AddressList)
|
|
{
|
|
//Debug.LogError("Sorting local IPs by order of first byte...");
|
|
var candidateIPs = new Dictionary<uint, string>();
|
|
var candidateIPsAsInt = new List<uint>();
|
|
|
|
foreach (var ip in AddressList)
|
|
{
|
|
// Get the address as bytes, and convert it as an int.
|
|
var bytes = ip.GetAddressBytes();
|
|
uint AddressAsInt = ((uint)(bytes[0] << 24)) | ((uint)(bytes[1] << 16)) | ((uint)(bytes[2] << 8)) | (bytes[3]);
|
|
|
|
if (!candidateIPsAsInt.Contains(AddressAsInt))
|
|
{
|
|
// Store the address as integer, and a link to the ip as string in a dictionary
|
|
candidateIPsAsInt.Add(AddressAsInt);
|
|
candidateIPs.Add(AddressAsInt, ip.ToString());
|
|
}
|
|
}
|
|
|
|
if (candidateIPsAsInt.Count > 0)
|
|
{
|
|
// Sort the list of addresses as integers, to get the fist one , ie the lower address ("10.xxx" before "192.xxx")
|
|
candidateIPsAsInt.Sort();
|
|
|
|
/* int i = 0;
|
|
foreach (var ipInt in candidateIPsAsInt)
|
|
{
|
|
Debug.LogError("Address"+i+": "+ candidateIPs[ipInt]+ ((i==0)? "--> best IP address. ":"."));
|
|
i++;
|
|
}*/
|
|
return candidateIPs[candidateIPsAsInt[0]];
|
|
}
|
|
|
|
Debug.LogError("Couldn't find any device local IP address, pairing will fail.");
|
|
return null;
|
|
}
|
|
|
|
|
|
private string GetLocalIPFromBestSubNetwork(List<IPAddress> AddressList, string optionalConsoleIpAddress)
|
|
{
|
|
//Debug.LogError("Getting local IP in the same sub Network as " + optionalConsoleIpAddress + "....");
|
|
|
|
// First : get the console address first 3 bytes
|
|
// optionalConsoleIpAddress is smthg like AA.BB.CC.xx
|
|
uint[] consoleAddressByte = {0,0,0 };
|
|
if(optionalConsoleIpAddress!=null && optionalConsoleIpAddress!="")
|
|
{
|
|
string[] consoleAddressByteAsString = optionalConsoleIpAddress.Split('.');
|
|
for (int i=0; i<3;i++)
|
|
{
|
|
UInt32.TryParse(consoleAddressByteAsString[i], out consoleAddressByte[i]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//What to do in this case ? ....
|
|
//Debug.LogError("Console IP is not set ! Couldn't find the device local IP address in the console network, pairing will fail.");
|
|
return null;
|
|
}
|
|
|
|
List<IPAddress> SearchedIPs = null;
|
|
List<IPAddress> resultIPs = null;
|
|
int ByteNb = 0;
|
|
IPAddress DefaultIPWhenNoMatch= null;
|
|
|
|
// Loop on the 3 bytes:
|
|
// We try to find an adresse that looks like AA.BB.CC.yy
|
|
// we search addresses that have the same first byte as console (AA)
|
|
//Among them, we search addresses that have the same second byte as console (BB),and then the same third byte (CC)
|
|
|
|
// When we have no result , we break and take the default IP that matched the loop before
|
|
// When we have only one result , we return it
|
|
// when we have more than one result , we loop again on the next byte
|
|
while (ByteNb<3)
|
|
{
|
|
if(ByteNb==0)
|
|
{
|
|
SearchedIPs= new List<IPAddress>(AddressList);
|
|
}
|
|
else
|
|
{
|
|
SearchedIPs = new List<IPAddress>(resultIPs);
|
|
DefaultIPWhenNoMatch = SearchedIPs[0];
|
|
}
|
|
|
|
resultIPs = new List<IPAddress>();
|
|
foreach (var add in SearchedIPs)
|
|
{
|
|
if(add.GetAddressBytes()[ByteNb] == consoleAddressByte[ByteNb])
|
|
{
|
|
resultIPs.Add(add);
|
|
}
|
|
}
|
|
|
|
//either no result or just one result : break and return the best result
|
|
if (resultIPs.Count < 2)
|
|
break;
|
|
|
|
//else do the loop on the next byte
|
|
ByteNb++;
|
|
}
|
|
|
|
if(resultIPs.Count>0)
|
|
{
|
|
//Debug.LogError("IP From console network found :" + resultIPs[0]);
|
|
return resultIPs[0].ToString();
|
|
}
|
|
else // no exact match , we get the one that matches best
|
|
{
|
|
if (DefaultIPWhenNoMatch!=null)
|
|
{
|
|
//Debug.LogError("IP From console network found :" + DefaultIPWhenNoMatch);
|
|
return DefaultIPWhenNoMatch.ToString();
|
|
}
|
|
else
|
|
{
|
|
//Debug.LogError("Couldn't find the device local IP address in the console network.");
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void DisplayLandingScreen()
|
|
{
|
|
var newScreen = UiBuilder.Instance.BuildLandingScreen();
|
|
UiManager.Instance.DisplayUIScreen(newScreen);
|
|
}
|
|
|
|
public void ShowAppropriateHelpWizardScreen()
|
|
{
|
|
UiManager.Instance.UndisplayTransition();
|
|
Statistics.wizardStartingConsoleNumber = _consoleType.HasValue ? _consoleType + "Console" : "No Console";
|
|
Statistics.wizardStartingVersion = (_gameVersion != 0) ? " + " + _gameVersion.ToString() : " + 0 Game";
|
|
|
|
if (_gameVersion == 0)
|
|
{
|
|
ShowSelectYourGameScreen();
|
|
return;
|
|
}
|
|
|
|
// If we're on 2020, the pairing was not showed and no console is currently avaiable or a Stadia one, we force this flow.
|
|
if (_gameVersion >= 2020 && !pairingScreenShowed && (!_consoleType.HasValue || _consoleType.Value == ConsoleServer.ConsoleType.GGP))
|
|
{
|
|
if (string.IsNullOrEmpty(_pairingCode))
|
|
{
|
|
ShowPairingCodeScreen();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (connectionError != null)
|
|
{
|
|
// Display the dual popup.
|
|
HandleErrorCode();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!_consoleType.HasValue)
|
|
{
|
|
ShowSelectYourPlatformScreen();
|
|
return;
|
|
}
|
|
|
|
// Specific Stadia case where we only troubleshot the pairing code, and not the rest (Wifi console issue ...)
|
|
if(_consoleType.Value == ConsoleServer.ConsoleType.GGP)
|
|
{
|
|
_consoleType = null;
|
|
ShowPairingCodeScreen();
|
|
return;
|
|
}
|
|
|
|
TitleDatabase.Compatibility compatibility = TitleDatabase.IsVersionCompatibleWithConsoleAndPhone(_gameVersion, _consoleType.Value);
|
|
Debug.Log("Compatibility found: " + compatibility);
|
|
switch (compatibility)
|
|
{
|
|
case TitleDatabase.Compatibility.Compatible:
|
|
break;
|
|
case TitleDatabase.Compatibility.IncompatibleGame:
|
|
ShowIncompatibleGameErrorScreen();
|
|
return;
|
|
case TitleDatabase.Compatibility.IncompatiblePhone:
|
|
ShowWizardErrorScreen(LocalizationManager.Instance.GetLocalizedString(12974), "ErrorIncompatiblePhone"); // WP
|
|
return;
|
|
}
|
|
|
|
if (!_pressAShown && string.IsNullOrEmpty(_pairingCode))
|
|
{
|
|
// Since JD 2020, it's a pairing code, and not local networking
|
|
ShowPressAScreen();
|
|
return;
|
|
}
|
|
|
|
if (_sameNetworkShown == false)
|
|
{
|
|
if ((_consoleType == ConsoleServer.ConsoleType.WIIU) || (_consoleType == ConsoleServer.ConsoleType.NX))
|
|
ShowNintendoOnlineScreen();
|
|
else
|
|
ShowSameNetworkScreen();
|
|
return;
|
|
}
|
|
|
|
ShowFailScreen();
|
|
}
|
|
|
|
private void HandleErrorCode()
|
|
{
|
|
if (connectionError == null)
|
|
{
|
|
ShowErrorPairingScreen();
|
|
return;
|
|
}
|
|
|
|
if (connectionError.reqState == BestHTTP.HTTPRequestStates.Finished)
|
|
{
|
|
switch (connectionError.statusCode)
|
|
{
|
|
case 400:
|
|
ShowErrorPairingScreen();
|
|
Debug.Log("ConnectionManager : Request error");
|
|
break;
|
|
case 404:
|
|
ShowErrorPairingScreen();
|
|
Debug.Log("ConnectionManager : Pairing code not found");
|
|
break;
|
|
case 503:
|
|
string maintenanceTextDesc = LocalizationManager.Instance.GetLocalizedString(20000429);
|
|
var maintenanceErrorPopup = UiBuilder.Instance.BuildErrorPopup(maintenanceTextDesc);
|
|
UiManager.Instance.DisplayAppPopupScreen(maintenanceErrorPopup, 0, false, AudioManager.SoundIds.NotifWarning);
|
|
Debug.Log("ConnectionManager : Ubiserver maintenance");
|
|
break;
|
|
default:
|
|
string ubisoftServerErrorTxt = LocalizationManager.Instance.GetLocalizedString(20002027);
|
|
var ubisoftServerErrorPopup = UiBuilder.Instance.BuildErrorPopup(ubisoftServerErrorTxt);
|
|
UiManager.Instance.DisplayAppPopupScreen(ubisoftServerErrorPopup, 0, false, AudioManager.SoundIds.NotifWarning);
|
|
Debug.Log("ConnectionManager : Ubisoft server error");
|
|
break;
|
|
}
|
|
|
|
}
|
|
else if (connectionError.reqState == BestHTTP.HTTPRequestStates.ConnectionTimedOut ||
|
|
connectionError.reqState == BestHTTP.HTTPRequestStates.TimedOut)
|
|
{
|
|
string timeoutTxt = Localization.LocalizationManager.Instance.GetLocalizedString(20002020);
|
|
var timeOutPopup = UiBuilder.Instance.BuildErrorPopup(timeoutTxt);
|
|
UiManager.Instance.DisplayAppPopupScreen(timeOutPopup);
|
|
Debug.Log("ConnectionManager : Connection timeout");
|
|
}
|
|
}
|
|
|
|
void ShowSelectYourPlatformScreen()
|
|
{
|
|
var platformScreen = UiBuilder.Instance.BuildSelectYourPlatformScreen();
|
|
Statistics.NewWizardScreen("SelectYourPlatform");
|
|
UiManager.Instance.DisplayAppPopupScreen(platformScreen, 0, true);
|
|
}
|
|
|
|
void ShowSelectYourConsoleScreen(List<ConsoleServer> consoles)
|
|
{
|
|
var selectYourConsoleScreen = UiBuilder.Instance.BuildSelectYourConsoleScreen(consoles);
|
|
|
|
// Statistics
|
|
Statistics.wizardStartingConsoleNumber = "Multi console";
|
|
Statistics.wizardStartingVersion = string.Empty;
|
|
|
|
Statistics.NewWizardScreen("SelectYourConsole");
|
|
UiManager.Instance.UndisplayTransition();
|
|
UiManager.Instance.DisplayAppPopupScreen(selectYourConsoleScreen, 0, true);
|
|
}
|
|
|
|
public void ShowSelectYourGameScreen()
|
|
{
|
|
var selectYourGameScreen = UiBuilder.Instance.BuildSelectYourGameVersionScreen();
|
|
Statistics.NewWizardScreen("SelectYourGame");
|
|
UiManager.Instance.DisplayAppPopupScreen(selectYourGameScreen, 0, true);
|
|
}
|
|
|
|
public void ShowPressAScreen()
|
|
{
|
|
var pressAScreen = UiBuilder.Instance.BuildPressAScreen(_gameVersion, _consoleType.Value);
|
|
Statistics.NewWizardScreen("PressA");
|
|
UiManager.Instance.DisplayAppPopupScreen(pressAScreen, 0, true);
|
|
}
|
|
|
|
public void ShowSameNetworkScreen()
|
|
{
|
|
if(_consoleType == null) {
|
|
UiManager.Instance.DisplayLanding();
|
|
return;
|
|
}
|
|
|
|
var sameNetworkScreen = UiBuilder.Instance.BuildSameNetworkScreen(_consoleType.Value);
|
|
Statistics.NewWizardScreen("SameNetwork");
|
|
UiManager.Instance.DisplayAppPopupScreen(sameNetworkScreen, 0, true);
|
|
}
|
|
|
|
public void ShowNetworkAboutScreen()
|
|
{
|
|
var networkAboutScreen = UiBuilder.Instance.BuildNetworkAboutScreen(_consoleType.Value);
|
|
Statistics.NewWizardScreen("NetworkAbout");
|
|
UiManager.Instance.DisplayAppPopupScreen(networkAboutScreen, 0, true);
|
|
}
|
|
|
|
public void ShowFailScreen()
|
|
{
|
|
var failScreen = UiBuilder.Instance.BuildFailScreen();
|
|
Statistics.NewWizardScreen("Fail");
|
|
UiManager.Instance.DisplayAppPopupScreen(failScreen, 0, true);
|
|
}
|
|
|
|
public void ShowPairingCodeScreen()
|
|
{
|
|
var pairingContentPrefab = UiBuilder.Instance.BuildPairingContentPrefab();
|
|
Statistics.NewWizardScreen("PairingCode");
|
|
UiManager.Instance.DisplayAppPopupScreen(pairingContentPrefab, 0, true);
|
|
}
|
|
|
|
public void ShowErrorPairingScreen()
|
|
{
|
|
var duoScreen = UiBuilder.Instance.BuildErrorPairingPrefab(_gameVersion);
|
|
Statistics.NewWizardScreen("ErrorPairingScreen");
|
|
UiManager.Instance.DisplayAppPopupScreen(duoScreen, 0, true);
|
|
}
|
|
|
|
public void ShowIncompatibleGameErrorScreen()
|
|
{
|
|
string platformName = UiBuilder.PlatformList.Find(p => p.Type == _consoleType).DropdownName;
|
|
Dictionary<string, string> customValues = new Dictionary<string, string>
|
|
{
|
|
{ "PLATFORM", platformName },
|
|
{ "GAMEVERSION", _gameVersion.ToString() }
|
|
};
|
|
|
|
ShowWizardErrorScreen(LocalizationManager.Instance.GetLocalizedString(12976, customValues), "ErrorIncompatibleConsoleGame" + platformName + "JD" + _gameVersion.ToString());
|
|
}
|
|
|
|
public void ShowWizardErrorScreen(string errorContentMessage, string trackingScreenName)
|
|
{
|
|
var wizardErrorScreen = UiBuilder.Instance.BuildWizardErrorScreen(errorContentMessage);
|
|
Statistics.NewWizardScreen(trackingScreenName);
|
|
UiManager.Instance.DisplayAppPopupScreen(wizardErrorScreen, 0, true);
|
|
}
|
|
|
|
public void ShowNintendoOnlineScreen()
|
|
{
|
|
var screen = UiBuilder.Instance.BuildNintendoOnlineScreen(_consoleType.Value);
|
|
Statistics.NewWizardScreen("NintendoOnline" + _consoleType.Value);
|
|
UiManager.Instance.DisplayAppPopupScreen(screen, 0, true);
|
|
}
|
|
|
|
#region Game commands
|
|
|
|
void NewProfileReceived(JSON profileMessage)
|
|
{
|
|
// not all profile switch are shown on the screen
|
|
if (JSONParseHelper.ShowOnScreen(profileMessage))
|
|
{
|
|
var additionalMessage = profileMessage.GetFieldAsString("additionalMessage");
|
|
var showConfirmButton = profileMessage.GetFieldAsBool("showConfirmButton");
|
|
var profileScreen = UiBuilder.Instance.BuildProfileScreen(additionalMessage, showConfirmButton);
|
|
|
|
UiManager.Instance.DisplayAppPopupScreen(profileScreen, showConfirmButton ? 0.0f : 4.0f, false, AudioManager.SoundIds.NoSound);
|
|
}
|
|
}
|
|
|
|
void OnTriggerTransition(string displayText)
|
|
{
|
|
UiManager.Instance.PrepareScreenTransition();
|
|
}
|
|
|
|
void OnPopupShouldDisappear()
|
|
{
|
|
UiManager.Instance.DisplayGamePopupScreen(null);
|
|
}
|
|
|
|
void OnShortcutSetup(bool isEnabled)
|
|
{
|
|
ShortcutModel.enabled = isEnabled;
|
|
}
|
|
|
|
#endregion
|
|
|
|
public void OnConsoleSelected(ConsoleServer consoleServer)
|
|
{
|
|
_consoleType = consoleServer.Platform;
|
|
_gameVersion = TitleDatabase.ExtractGameVersion(consoleServer.TitleId);
|
|
_pairingCode = consoleServer.PairingCode;
|
|
|
|
if (_gameVersion != 0 && TitleDatabase.IsVersionCompatibleWithConsoleAndPhone(_gameVersion, _consoleType.Value) == TitleDatabase.Compatibility.Compatible)
|
|
LaunchConnectionFlow();
|
|
else
|
|
ShowAppropriateHelpWizardScreen();
|
|
}
|
|
|
|
public void OnPlatformSelected(ConsoleServer.ConsoleType? platform)
|
|
{
|
|
if (!platform.HasValue)
|
|
{
|
|
ShowWizardErrorScreen(LocalizationManager.Instance.GetLocalizedString(12970), "ErrorPlatformNotSupported"); // Console not supported message
|
|
return;
|
|
}
|
|
|
|
_consoleType = platform;
|
|
|
|
var gameList = TitleDatabase.GetPlatformAvailableVersions(_consoleType.Value);
|
|
if (gameList.Length == 1)
|
|
_gameVersion = gameList.First();
|
|
|
|
ShowAppropriateHelpWizardScreen();
|
|
}
|
|
|
|
public void OnGameSelected(int gameVersion)
|
|
{
|
|
if (gameVersion == 0)
|
|
{
|
|
ShowWizardErrorScreen(LocalizationManager.Instance.GetLocalizedString(12971), "ErrorGameVersionNotSupported"); // Version not supported message
|
|
return;
|
|
}
|
|
|
|
PlayerPrefs.SetInt("ChooseYourConsole", gameVersion);
|
|
PlayerPrefs.Save();
|
|
|
|
_gameVersion = gameVersion;
|
|
ShowAppropriateHelpWizardScreen();
|
|
}
|
|
|
|
public void OnShowAssistant()
|
|
{
|
|
pairingScreenShowed = true;
|
|
ShowAppropriateHelpWizardScreen();
|
|
}
|
|
|
|
public void OnPressAValidated()
|
|
{
|
|
_pressAShown = true;
|
|
LaunchConnectionFlow();
|
|
}
|
|
|
|
public void OnSameNetworkOkValidated()
|
|
{
|
|
_sameNetworkShown = true;
|
|
LaunchConnectionFlow();
|
|
}
|
|
|
|
public void OnSameNetworkDontKnowClicked()
|
|
{
|
|
ShowNetworkAboutScreen();
|
|
}
|
|
|
|
public void OnNetworkAboutOkValidated()
|
|
{
|
|
_sameNetworkShown = true;
|
|
LaunchConnectionFlow();
|
|
}
|
|
|
|
public void OnPressPairingScreenValidated(string pairingCode)
|
|
{
|
|
_pairingCode = pairingCode;
|
|
LaunchConnectionFlow();
|
|
}
|
|
|
|
public void OnFailScreenRetry()
|
|
{
|
|
ResetWizardValues();
|
|
LaunchConnectionFlow();
|
|
}
|
|
|
|
public void ResetWizardValues()
|
|
{
|
|
ResetConsoleType();
|
|
ResetGameVersion();
|
|
ResetPairingCode();
|
|
ResetPressAShow();
|
|
ResetSameNetworkShown();
|
|
pairingScreenShowed = false;
|
|
connectionError = null;
|
|
}
|
|
|
|
public void ResetConsoleType()
|
|
{
|
|
_consoleType = null;
|
|
}
|
|
|
|
public void ResetGameVersion()
|
|
{
|
|
_gameVersion = 0;
|
|
}
|
|
|
|
public void ResetPairingCode()
|
|
{
|
|
_pairingCode = null;
|
|
}
|
|
|
|
public void ResetPressAShow()
|
|
{
|
|
_pressAShown = false;
|
|
}
|
|
|
|
public void ResetSameNetworkShown()
|
|
{
|
|
_sameNetworkShown = false;
|
|
}
|
|
|
|
public void LaunchWifiSettings()
|
|
{
|
|
#if UNITY_EDITOR
|
|
Debug.Log("Opening Wi-Fi settings doesn't work on Editor!");
|
|
#elif UNITY_ANDROID
|
|
AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
|
|
AndroidJavaObject activityContext = activityClass.GetStatic<AndroidJavaObject>("currentActivity");
|
|
AndroidJavaObject wifiIntent = new AndroidJavaObject("android.content.Intent", "android.settings.WIFI_SETTINGS");
|
|
activityContext.Call("startActivity", wifiIntent);
|
|
|
|
//we don't enter this block right now because the button is hidden on non-Android platform
|
|
//because it doesn't work on iOS ( and WP) currently, only app settings can be specified this way via OpenURL.
|
|
#endif
|
|
}
|
|
}
|
|
}
|