public void OnJoinedRoom()
        {
            if (_joinRoomOp == null && _createAndJoinRoomOp == null)
            {
                return;
            }
            Debug.Log(
                $"[HOLONET] ROOMS - OnJoinedRoom {PhotonNetwork.CurrentRoom}, players count: {PhotonNetwork.CurrentRoom.PlayerCount}");
            HoloNetAppModule.instance.OnConnectedToRoom();

            if (_joinRoomOp != null)
            {
                _joinRoomOp.isDone = true;
                _joinRoomOp.InvokeCallback();
                _joinRoomOp = null;
            }
            else if (_createAndJoinRoomOp != null)
            {
                _createAndJoinRoomOp.isDone = true;
                _createAndJoinRoomOp.InvokeCallback();
                _createAndJoinRoomOp = null;
            }

            HoloNetAppModule.instance.rooms.SetCurrentRoom(ConvertToHolonetRoom(PhotonNetwork.CurrentRoom));
        }
Esempio n. 2
0
        public AsyncOp WaitAndApplySyncState(Action <AsyncOp> callback)
        {
            var asyncOp = new AsyncOp();

            asyncOp.callback = callback;
            AppController.instance.StartCoroutine(WaitAndApplySyncStateCor(asyncOp));
            return(asyncOp);
        }
Esempio n. 3
0
 public void GetAll(Action <Category[]> onSuccess)
 {
     AsyncOp.Get(
         asyncOp: () => _restConnection.Get(RestCallsConstants.Category),
         onSuccess: restResult => onSuccess(OnCategoriesLoadSuccess(restResult)),
         onCancel: () => onSuccess(LoadStoredLocally()),
         onFailure: e => onSuccess(LoadStoredLocally())
         ).Run();
 }
Esempio n. 4
0
 private void LoadExpendituresFromServer()
 {
     AsyncOp.Get(
         asyncOp: () => _restConnection.Get(RestCallsConstants.Expenditure),
         onSuccess: x => JsonConvert.DeserializeObject <Expenditure[]>(x.Content).Foreach(AddExpenditureLocally),
         onFailure: x => { },
         onCancel: () => { }
         ).Run();
 }
Esempio n. 5
0
 private void UploadToServer(Expenditure[] itemsToUpload)
 {
     if (itemsToUpload.Any())
     {
         AsyncOp.Get(
             asyncOp: () => _restConnection.Post(RestCallsConstants.Expenditure, itemsToUpload),
             onSuccess: x => { _localDatabase.ClearUnsynchronizedItems(); },
             onFailure: x => { },
             onCancel: () => { }
             ).Run();
     }
 }
Esempio n. 6
0
        void LoadConfigScene()
        {
            // TODO: Emscripten seems to have problems loading statics so reading
            // from ConfigurationScene.Guid will pretty reliably come back as all zeros
            var configGuid = new Hash128("46b433b264c69cbd39f04ad2e5d12be8"); // ConfigurationScene.Guid;

            m_ConfigScene = m_SceneSystem.LoadSceneAsync(configGuid, new SceneSystem.LoadParameters()
            {
                AutoLoad = true, Flags = SceneLoadFlags.LoadAdditive
            });
            m_CatalogOp = IOService.RequestAsyncRead(SceneSystem.GetSceneInfoPath());
        }
 public void OnCreateRoomFailed(short returnCode, string message)
 {
     if (_createAndJoinRoomOp == null)
     {
         return;
     }
     Debug.Log($"[HOLONET] ROOMS - OnCreateRoomFailed {message}");
     _createAndJoinRoomOp.isDone       = true;
     _createAndJoinRoomOp.error        = HoloNetError.CREATE_ROOM_FAILED;
     _createAndJoinRoomOp.debugMessage = $"Create Room Failed, ServerCode: {returnCode}, Message:{message}";
     _createAndJoinRoomOp.InvokeCallback();
     _createAndJoinRoomOp = null;
 }
 public void OnJoinRoomFailed(short returnCode, string message)
 {
     if (_joinRoomOp == null)
     {
         return;
     }
     Debug.Log($"[HOLONET] ROOMS - OnJoinRoomFailed {message}. photon return code {returnCode} ");
     _joinRoomOp.isDone       = true;
     _joinRoomOp.error        = HoloNetError.JOIN_ROOM_FAILED;
     _joinRoomOp.debugMessage = $"Join Room Failed, ServerCode: {returnCode}, Message:{message}";
     _joinRoomOp.InvokeCallback();
     _joinRoomOp = null;
 }
        public AsyncOp Disconnect(Action <AsyncOp> callback = null)
        {
            Debug.Log($"[HOLONET] NETWORK - Disconnecting");
            if (_currentNetworkOp != null)
            {
                return(CreateFail(HoloNetError.ANOTHER_NETWORK_OPERATION_IN_PRORESS, callback));
            }

            PhotonNetwork.Disconnect();
            _currentNetworkOp          = new AsyncOp();
            _currentNetworkOp.callback = callback;
            return(_currentNetworkOp);
        }
Esempio n. 10
0
        bool WaitForOpCompletion(AsyncOp op, int timeoutMS = 5000)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            while (op.GetStatus() == Status.InProgress && stopwatch.ElapsedMilliseconds < timeoutMS)
            {
                Baselib.LowLevel.Binding.Baselib_Thread_YieldExecution();
            }

            return(op.GetStatus() != Status.InProgress);
        }
        public void OnDisconnected(DisconnectCause cause)
        {
            if (_currentNetworkOp != null)
            {
                _currentNetworkOp.isDone       = true;
                _currentNetworkOp.error        = HoloNetError.DISCONNECTED_FROM_PROVIDER;
                _currentNetworkOp.debugMessage = $"Disconnected from provider, DisconnectCause: {cause}";
                _currentNetworkOp.InvokeCallback();
                _currentNetworkOp = null;
            }

            HoloNetAppModule.instance.messenger.Publish(NetDisconnectMessage.Create(cause.ToString()));
        }
Esempio n. 12
0
 public void Add(Expenditure expenditure)
 {
     AddExpenditureLocally(expenditure);
     AsyncOp.Get(
         asyncOp: () => _restConnection.Post(RestCallsConstants.Expenditure, expenditure.AsArray()),
         onSuccess: x => { },
         onFailure: x => _localDatabase.Insert(new UnsynchronizedItem {
         Id = expenditure.Id
     }),
         onCancel: () => _localDatabase.Insert(new UnsynchronizedItem {
         Id = expenditure.Id
     })
         ).Run();
 }
Esempio n. 13
0
        public unsafe void AsyncOpFailure()
        {
            var op = new AsyncOp();

            Assert.AreEqual(op.GetStatus(), Status.NotStarted);
            Assert.AreEqual(op.GetErrorStatus(), ErrorStatus.None);

            op = IOService.RequestAsyncRead("IDoNotExist");
            Assert.IsTrue(WaitForOpCompletion(op));
            Assert.AreEqual(op.GetStatus(), Status.Failure);
            Assert.AreEqual(op.GetErrorStatus(), ErrorStatus.FileNotFound);

            op.Dispose();
        }
 public void OnJoinedLobby()
 {
     if (_connectAsyncOp == null)
     {
         return;
     }
     Debug.Log($"[HOLONET] NETWORK - Connected to Lobby {PhotonNetwork.CurrentLobby}");
     if (_connectAsyncOp != null)
     {
         _connectAsyncOp.isDone = true;
         _connectAsyncOp.InvokeCallback();
         _connectAsyncOp = null;
     }
 }
        public AsyncOp JoinRoom(string id, Action <AsyncOp> callback = null)
        {
            Debug.Log($"[HOLONET] ROOMS - JoinRoom");
            if (!canExecuteOperation)
            {
                return(CreateFail(HoloNetError.ANOTHER_ROOM_OPERATION_IN_PRORESS, callback));
            }
            if (!PhotonNetwork.JoinRoom(id))
            {
                return(CreateFail(HoloNetError.PROVIDER_NOT_READY, callback));
            }

            _joinRoomOp          = new AsyncOp();
            _joinRoomOp.callback = callback;
            return(_joinRoomOp);
        }
        public AsyncOp Connect(Action <AsyncOp> callback = null)
        {
            Debug.Log($"[HOLONET] NETWORK - Connecting");
            if (!canExecuteNetworkOperations)
            {
                return(CreateFail(HoloNetError.ANOTHER_NETWORK_OPERATION_IN_PRORESS, callback));
            }

            if (!PhotonNetwork.ConnectUsingSettings())
            {
                return(CreateFail(HoloNetError.ALREADY_CONNECTED, callback));
            }

            _connectAsyncOp          = new AsyncOp();
            _connectAsyncOp.callback = callback;
            return(_connectAsyncOp);
        }
Esempio n. 17
0
        public IEnumerator WaitAndApplySyncStateCor(AsyncOp asyncOp)
        {
            if (!HoloNetPlayer.Local.isServer)
            {
                while (!HasStateToApply())
                {
                    yield return(null);
                }
                var snapshotCreationTime =
                    roomStateToApply.creationTime;
                ApplyState();
                HoloNetAppModule.instance.messenger.ClearAllMessagesBefore(snapshotCreationTime);
            }

            asyncOp.isDone = true;
            asyncOp.InvokeCallback();
        }
        public AsyncOp LeaveRoom(Action <AsyncOp> callback = null)
        {
            Debug.Log($"[HOLONET] ROOMS - LeaveRoom");
            if (!canExecuteOperation)
            {
                return(CreateFail(HoloNetError.ANOTHER_ROOM_OPERATION_IN_PRORESS, callback));
            }


            if (!PhotonNetwork.LeaveRoom(false))
            {
                return(CreateFail(HoloNetError.PROVIDER_NOT_READY, callback));
            }

            _leaveRoomOp          = new AsyncOp();
            _leaveRoomOp.callback = callback;
            return(_leaveRoomOp);
        }
        public AsyncOp CreateAndJoinRoom(RoomSettings settings, Action <AsyncOp> callback = null)
        {
            Debug.Log($"[HOLONET] ROOMS - CreateRoom");
            if (!canExecuteOperation)
            {
                return(CreateFail(HoloNetError.ANOTHER_ROOM_OPERATION_IN_PRORESS, callback));
            }

            if (!PhotonNetwork.CreateRoom(null, ConvertToPhotonRoomOptions(settings),
                                          new TypedLobby("Default", LobbyType.SqlLobby)))
            {
                _createAndJoinRoomOp.error = HoloNetError.CREATE_ROOM_FAILED;
            }

            _createAndJoinRoomOp          = new AsyncOp();
            _createAndJoinRoomOp.callback = callback;
            return(_createAndJoinRoomOp);
        }
Esempio n. 20
0
        public unsafe void AsyncOpSuccess()
        {
            var op = new AsyncOp();

            Assert.AreEqual(op.GetStatus(), Status.NotStarted);
            Assert.AreEqual(op.GetErrorStatus(), ErrorStatus.None);

            op = IOService.RequestAsyncRead(kTestDataPath);

            Assert.IsTrue(WaitForOpCompletion(op));
            Assert.AreEqual(op.GetStatus(), Status.Success);
            Assert.AreEqual(op.GetErrorStatus(), ErrorStatus.None);

            op.GetData(out var data, out var sizeInBytes);
            for (int i = 0; i < sizeInBytes; ++i)
            {
                Assert.AreEqual((int)data[i], i);
            }

            op.Dispose();
        }
        internal static void RequestLoadAndPollSceneMetaData(EntityManager EntityManager, Entity sceneEntity, Hash128 sceneGUID)
        {
            var sceneHeaderPath = EntityScenesPaths.GetLoadPath(sceneGUID, EntityScenesPaths.PathType.EntitiesHeader, -1);

            RequestSceneHeader requestSceneHeader;

            if (!EntityManager.HasComponent <RequestSceneHeader>(sceneEntity))
            {
                requestSceneHeader.IOHandle = IOService.RequestAsyncRead(sceneHeaderPath).m_Handle;
                EntityManager.AddComponentData(sceneEntity, requestSceneHeader);
            }
            else
            {
                requestSceneHeader = EntityManager.GetComponentData <RequestSceneHeader>(sceneEntity);
            }

            var asyncOp = new AsyncOp()
            {
                m_Handle = requestSceneHeader.IOHandle
            };
            var sceneHeaderStatus = asyncOp.GetStatus();

            if (sceneHeaderStatus <= AsyncOp.Status.InProgress)
            {
                return;
            }

            if (sceneHeaderStatus != AsyncOp.Status.Success)
            {
                Debug.LogError($"Loading Entity Scene failed because the entity header file could not be read: guid={sceneGUID}.");
            }

            // Even if the file doesn't exist we want to stop continously trying to load the scene metadata
            EntityManager.AddComponentData(sceneEntity, new SceneMetaDataLoaded()
            {
                Success = sceneHeaderStatus == AsyncOp.Status.Success
            });
        }
        public unsafe static bool ResolveSceneSections(EntityManager EntityManager, Entity sceneEntity, Hash128 sceneGUID, RequestSceneLoaded requestSceneLoaded, Hash128 artifactHash)
        {
            // Resolve first (Even if the file doesn't exist we want to stop continously trying to load the section)
            var bufLen = EntityManager.AddBuffer <ResolvedSectionEntity>(sceneEntity).Length;

            Assert.AreEqual(0, bufLen);

            var sceneHeaderPath = "";

#if UNITY_EDITOR
            string[] paths = null;
#endif

            bool useStreamingAssetPath = true;
#if !UNITY_DOTSRUNTIME
            useStreamingAssetPath = SceneBundleHandle.UseAssetBundles;
#endif
            if (useStreamingAssetPath)
            {
                sceneHeaderPath = EntityScenesPaths.GetLoadPath(sceneGUID, EntityScenesPaths.PathType.EntitiesHeader, -1);
            }
            else
            {
#if UNITY_EDITOR
                AssetDatabaseCompatibility.GetArtifactPaths(artifactHash, out paths);
                sceneHeaderPath = EntityScenesPaths.GetLoadPathFromArtifactPaths(paths, EntityScenesPaths.PathType.EntitiesHeader);
#endif
            }

            EntityManager.AddComponentData(sceneEntity, new ResolvedSceneHash {
                ArtifactHash = artifactHash
            });

            var group = EntityManager.AddBuffer <LinkedEntityGroup>(sceneEntity);
            Assert.AreEqual(0, group.Length);
            group.Add(sceneEntity);

            // @TODO: AsyncReadManager currently crashes with empty path.
            //        It should be possible to remove this after that is fixed.
            if (String.IsNullOrEmpty(sceneHeaderPath))
            {
#if UNITY_EDITOR
                var scenePath = AssetDatabaseCompatibility.GuidToPath(sceneGUID);
                var logPath   = System.IO.Path.GetFullPath(System.IO.Path.Combine(UnityEngine.Application.dataPath, "../Logs"));
                Debug.LogError($"Loading Entity Scene failed because the entity header file couldn't be resolved. This might be caused by a failed import of the entity scene. Please take a look at the SubScene MonoBehaviour that references this scene or at the asset import worker log in {logPath}. scenePath={scenePath} guid={sceneGUID}");
#else
                Debug.LogError($"Loading Entity Scene failed because the entity header file couldn't be resolved: guid={sceneGUID}.");
#endif
                return(false);
            }

#if !UNITY_DOTSRUNTIME
            if (!BlobAssetReference <SceneMetaData> .TryRead(sceneHeaderPath, SceneMetaDataSerializeUtility.CurrentFileFormatVersion, out var sceneMetaDataRef))
            {
#if UNITY_EDITOR
                Debug.LogError($"Loading Entity Scene failed because the entity header file was an old version or doesn't exist: guid={sceneGUID} path={sceneHeaderPath}");
#else
                Debug.LogError($"Loading Entity Scene failed because the entity header file was an old version or doesn't exist: {sceneGUID}\nNOTE: In order to load SubScenes in the player you have to use the new BuildConfiguration asset based workflow to build & run your player.\n{sceneHeaderPath}");
#endif
                return(false);
            }
#else
            Assert.IsTrue(EntityManager.HasComponent <RequestSceneHeader>(sceneEntity), "You may only resolve a scene if the entity has a RequestSceneHeader component");
            Assert.IsTrue(EntityManager.HasComponent <SceneMetaDataLoaded>(sceneEntity), "You may only resolve a scene if the entity has a SceneMetaDataLoaded component");
            var sceneMetaDataLoaded = EntityManager.GetComponentData <SceneMetaDataLoaded>(sceneEntity);
            if (!sceneMetaDataLoaded.Success)
            {
                return(false);
            }

            var requestSceneHeader = EntityManager.GetComponentData <RequestSceneHeader>(sceneEntity);
            var sceneMetaDataRef   = default(BlobAssetReference <SceneMetaData>);
            var asyncOp            = new AsyncOp()
            {
                m_Handle = requestSceneHeader.IOHandle
            };
            using (asyncOp)
            {
                unsafe
                {
                    asyncOp.GetData(out var sceneData, out var sceneDataSize);

                    if (!BlobAssetReference <SceneMetaData> .TryRead(sceneData, SceneMetaDataSerializeUtility.CurrentFileFormatVersion, out sceneMetaDataRef))
                    {
                        Debug.LogError($"Loading Entity Scene failed because the entity header file was an old version or doesn't exist: {sceneGUID}\nNOTE: In order to load SubScenes in the player you have to use the new BuildConfiguration asset based workflow to build & run your player.\n{sceneHeaderPath}");
                        return(false);
                    }
                }
            }
#endif

            ref var sceneMetaData = ref sceneMetaDataRef.Value;