public void Dispose(bool isGraceful)
        {
            try
            {
                if (_isDisposed)
                {
                    DebugUtil.LogNormal <RealTimeHandler>(DebugLocation.RealTime, "Dispose",
                                                          "RealTimeHandler Already Disposed");
                    return;
                }

                _isDisposed = true;
                GsLiveRealTime.InAutoMatch = false;

                _observer?.Dispose();
                _dataObserver?.Dispose();
                _keepAliveSender?.Dispose();

                ObserverCompacterUtil.Dispose();

                _connGateway?.StopReceiving(isGraceful, false);
            }
            catch (Exception)
            {
                // ignored
            }
            finally
            {
                _connGateway = null;
                CurrentRoom  = null;
                MemberId     = null;
                AuthHash     = null;
                PlayerHash   = -1;
                PacketLost   = 0;
                Rtt          = 0;

                RealTimeEventHandlers.Authorized         = null;
                RealTimeEventHandlers.MemberId           = null;
                RealTimeEventHandlers.GProtocolConnected = null;
                RealTimeEventHandlers.LeftDispose        = null;
                RealTimeEventHandlers.PeerConfig         = null;

                try
                {
                    GC.SuppressFinalize(this);
                }
                catch (Exception)
                {
                    // ignored
                }

                DebugUtil.LogNormal <RealTimeHandler>(DebugLocation.RealTime, "Dispose", "RealTimeHandler Dispose Done");
            }
        }
        private void OnAuth(object sender, long playerHash)
        {
            GsLiveRealTime.InAutoMatch = false;

            if (PlayerHash != -1)
            {
                PlayerHash = playerHash;
                DebugUtil.LogNormal <RealTimeHandler>(DebugLocation.RealTime, "OnAuth",
                                                      "RealTimeHandler Reconnect Done");

                try
                {
                    if (GameService.HandlerType == EventHandlerType.NativeContext)
                    {
                        RealTimeEventHandlers.Reconnected?.Invoke(null, ReconnectStatus.Connected);
                    }
                    else
                    {
                        GameService.SynchronizationContext?.Send(
                            delegate { RealTimeEventHandlers.Reconnected?.Invoke(null, ReconnectStatus.Connected); },
                            null);
                    }
                }
                catch (Exception)
                {
                    // ignored
                }

                return;
            }

            PlayerHash = playerHash;

            ObserverCompacterUtil.Init();
            _keepAliveSender?.Start();

            GsSerializer.CurrentPlayerJoinRoom?.Invoke(this, null);

            DebugUtil.LogNormal <RealTimeHandler>(DebugLocation.RealTime, "OnAuth", "RealTimeHandler OnAuth Done");
        }
Esempio n. 3
0
        internal override void SendObserver(byte[] caller, byte[] data)
        {
            if (GameService.IsGuest)
            {
                throw new GameServiceException("This Function Not Working In Guest Mode").LogException <GsLiveRealTime>(
                          DebugLocation.RealTime, "SendObserver");
            }
            if (data == null)
            {
                throw new GameServiceException("caller or data Cant Be Null").LogException <GsLiveRealTime>(
                          DebugLocation.RealTime, "SendObserver");
            }
            if (GameService.GSLive.GetGsHandler().RealTimeHandler == null)
            {
                throw new GameServiceException("You Must Create or Join Room First").LogException <GsLiveRealTime>(
                          DebugLocation.RealTime, "SendObserver");
            }

            ObserverCompacterUtil.AddToQueue(new DataPayload {
                Payload = data, ExtraData = caller
            });
        }