コード例 #1
0
ファイル: Client.cs プロジェクト: wraikny/SquirrelayServer
        /// <summary>
        /// Update the client to handle messages from the server.
        /// </summary>
        public void Update()
        {
            if (_manager.IsRunning)
            {
                _manager?.PollEvents();
            }

            if (!IsStarted || !IsConnected)
            {
                return;
            }

            List <Exception>?exceptions = null;

            while (_updateContext.TryDequeue(out var action))
            {
                NetDebug.Logger?.WriteNet(NetLogLevel.Info, $"Client updateContext");
                try
                {
                    action?.Invoke();
                }
                catch (Exception e)
                {
                    exceptions ??= new List <Exception>();
                    exceptions.Add(e);
                }
            }

            foreach (var m in _gameMessages)
            {
                try
                {
                    var message = MessagePackSerializer.Deserialize <TMsg>(m.Data, _clientsSerializerOptions);

                    try
                    {
                        _listener.OnGameMessageReceived(m.ClientId, m.ElapsedSeconds, message);
                    }
                    catch (Exception e)
                    {
                        exceptions ??= new List <Exception>();
                        exceptions.Add(e);
                    }
                }
                catch
                {
                    NetDebug.Logger?.WriteNet(NetLogLevel.Error, $"Failed to deserialize gameMessage from client({m.ClientId}).");
                }
            }

            _gameMessages.Clear();

            if (exceptions is { })