public void Init()
        {
            if (_connGateway == null)
            {
                switch (GameService.CommandInfo.Protocol)
                {
                case GsEncryptor.TcpSec:
                    _connGateway = new GsTcpClient();
                    break;

                case GsEncryptor.WebSocketSec:
                    _connGateway = new GsWebSocketClient();
                    break;
                }

                if (_connGateway != null)
                {
                    _connGateway.DataReceived += OnDataReceived;
                }
            }

            _cancellationToken = new CancellationTokenSource();


            if (IsInitializing)
            {
                return;
            }

            IsInitializing = true;
            PingUtil.Stop();
            _connGateway?.Init(GameService.CommandInfo, GameService.CommandInfo.Cipher);
        }
Ejemplo n.º 2
0
        internal TurnBasedHandler(StartPayload payload)
        {
            switch (payload.Area.Protocol)
            {
            case GsEncryptor.TcpSec:
                _connGateway = new GsTcpClient(payload.Area);
                break;

            case GsEncryptor.WebSocketSec:
                _connGateway = new GsWebSocketClient(payload.Area);
                break;
            }

            CurrentRoom = payload.Room;
            _connGateway.DataReceived += OnDataReceived;

            _cancellationToken = new CancellationTokenSource();
            _observer          = new GsLiveSystemObserver(GSLiveType.TurnBased);
            _callerUtil        = new ObjectCallerUtil(TurnBasedConst.ConnectivityCheckInterval, null);
            _isDisposed        = false;


            // Set Internal Event Handlers
            TurnBasedEventHandlers.TurnBasedPing              += OnPing;
            TurnBasedEventHandlers.TurnBasedAuthorized        += OnAuth;
            TurnBasedEventHandlers.LeftDispose                += OnLeftDispose;
            TurnBasedEventHandlers.GsTurnBasedClientConnected += OnGsTcpClientConnected;
            TurnBasedEventHandlers.GsTurnBasedClientError     += OnGsTcpClientError;
            TurnBasedEventHandlers.TurnBasedMirror            += TurnBasedMirror;
            _callerUtil.Caller += RequestPing;


            InitRequestMessageHandlers();
            InitResponseMessageHandlers();

            DebugUtil.LogNormal <TurnBasedHandler>(DebugLocation.TurnBased, "Constructor", "TurnBasedHandler Init");
        }