Exemplo n.º 1
0
        protected SteamNetworkClientBase(SteamNetworkConfig config) : base(config)
        {
            config = GetConfig <SteamNetworkConfig>();
            Socket = config.SocketClient();
            Socket.MessageReceived += ReceiveAsync;
            Socket.Disconnected    += async(_, ex) =>
            {
                await DisconnectAsync().ConfigureAwait(false);
                await _socketDisconnected(ex.Exception).ConfigureAwait(false);
            };
            _stateLock           = new SemaphoreSlim(1, 1);
            _connectionStateLock = new SemaphoreSlim(1, 1);
            NetLog = LogManager.CreateLogger("Net");
            _jobs  = new JobManager <NetworkMessage>(NetLog);
            _connectionManagers = new List <Server>();

            _connection = new ConnectionManager(_connectionStateLock, LogManager.CreateLogger("CM"), ConnectionTimeout,
                                                OnConnectingInternalAsync, OnDisconnectingInternalAsync, (x) => _socketDisconnected = x);

            _defaultSteamId = SteamId.CreateAnonymousUser(config.DefaultUniverse);

            _connection.Disconnected += async(_, args) =>
            {
                await Disconnected.TimedInvokeAsync(this, args, TaskTimeout, NetLog).ConfigureAwait(false);
            };
            _connection.Connected += async(_, __) =>
            {
                await Connected.TimedInvokeAsync(this, EventArgs.Empty, TaskTimeout, NetLog).ConfigureAwait(false);
            };

            HighPrioritySubscribe(MessageType.Multi, ProcessMulti);
            HighPrioritySubscribe(MessageType.ChannelEncryptRequest, ProcessEncryptRequest);
            HighPrioritySubscribe(MessageType.ChannelEncryptResult, ProcessEncryptResult);
            HighPrioritySubscribe(MessageType.JobHeartbeat, ProcessJobHeartbeat);
            HighPrioritySubscribe(MessageType.DestJobFailed, ProcessFailedJob);

            Resolver = config.ReceiveMethodResolver == null ? new DefaultReceiveMethodResolver() : config.ReceiveMethodResolver() ?? new DefaultReceiveMethodResolver();

            foreach (MethodInfo method in this.GetAllTypes().Select(t => t.GetTypeInfo()).SelectMany(t => t.DeclaredMethods))
            {
                var attribute = method.GetCustomAttribute <MessageReceiverAttribute>();
                if (attribute != null)
                {
                    if (Resolver.TryResolve(method, this, out MessageReceiver receiver))
                    {
                        Subscribe(attribute.Type, receiver);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new <see cref="SteamNetworkClient"/> with the specified config
        /// </summary>
        /// <param name="config"></param>
        public SteamNetworkClient(SteamNetworkConfig config) : base(config)
        {
            CellId = config.CellId > uint.MaxValue || config.CellId < uint.MinValue ? 0 : config.CellId;

            _friends = new FriendsList(this);
        }