public GsLiveSystemObserver(GSLiveType type)
 {
     _type  = type;
     _timer = new Timer
     {
         Interval = RestLimit,
         Enabled  = false
     };
     _timer.Elapsed += (sender, args) => { Reset(); };
     _timer.Start();
 }
Exemple #2
0
        internal static bool IsInternalAction(int action, GSLiveType type)
        {
            switch (type)
            {
            case GSLiveType.NotSet:
                break;

            case GSLiveType.TurnBased:
                return(IsInternalTbAction(action));

            case GSLiveType.RealTime:
                return(IsInternalRtAction(action));

            case GSLiveType.Command:
                return(IsInternalCAction(action));

            default:
                return(false);
            }

            return(false);
        }
Exemple #3
0
        internal void Connect(GSLiveType type, WebSocket webSocket)
        {
            _connection = webSocket;
            _connected  = false;
            _exception  = null;

            Thread.Sleep(_timeoutWaitMilliseconds);

            var thread = new Thread(BeginConnect)
            {
                Priority     = ThreadPriority.Highest,
                IsBackground = true
            };

            thread.Start();

            thread.Join(TimeoutThreadWaitMilliseconds);

            if (_connected)
            {
                thread.Interrupt();

                if (type == GSLiveType.Command)
                {
                    CommandEventHandlers.CommandClientConnected?.Invoke(type, new GTcpConnection
                    {
                        IsWs = true, WebSocket = _connection
                    });
                }
                else
                {
                    TurnBasedEventHandlers.TurnBasedClientConnected?.Invoke(type, new GTcpConnection
                    {
                        IsWs = true, WebSocket = _connection
                    });
                }

                return;
            }

            if (_exception != null)
            {
                thread.Interrupt();

                if (type == GSLiveType.Command)
                {
                    CommandEventHandlers.GsCommandClientError?.Invoke(null,
                                                                      new GameServiceException(_exception.Message));
                }
                else
                {
                    TurnBasedEventHandlers.GsTurnBasedClientError?.Invoke(null,
                                                                          new GameServiceException(_exception.Message));
                }

                return;
            }

            thread.Interrupt();

            if (type == GSLiveType.Command)
            {
                CommandEventHandlers.GsCommandClientError?.Invoke(null,
                                                                  new GameServiceException("WS connection timed out"));
            }
            else
            {
                TurnBasedEventHandlers.GsTurnBasedClientError?.Invoke(null,
                                                                      new GameServiceException("WS connection timed out"));
            }
        }