示例#1
0
        /// <summary>
        ///     Initialize new <see cref="Libuv2kConnection"/>.
        /// </summary>
        /// <param name="noDelay"></param>
        /// <param name="client"></param>
        public Libuv2kConnection(bool noDelay, TcpStream client = null)
        {
            _cancellationToken = new CancellationTokenSource();

            if (client == null)
            {
                _clientLoop = new Loop();
                _client     = new TcpStream(_clientLoop);

                _ = UniTask.RunOnThreadPool(Tick, false, _cancellationToken.Token);
            }
            else
            {
                _client = client;

                // setup callbacks
                client.onMessage = OnLibuvClientMessage;
                client.onError   = OnLibuvClientError;
                client.onClosed  = OnLibuvClientClosed;
            }

            _ = UniTask.RunOnThreadPool(ProcessOutgoingMessages, false, _cancellationToken.Token);

            _client.NoDelay(noDelay);
        }
示例#2
0
        protected async UniTask HandshakeAsync(int bits)
        {
            // in the very first message we must mine a hashcash token
            // and send that as a hello
            // the server won't accept connections otherwise
            string applicationName = Application.productName;

            HashCash token = await UniTask.RunOnThreadPool(() => HashCash.Mine(applicationName, bits));

            byte[] hello  = new byte[1000];
            int    length = HashCashEncoding.Encode(hello, 0, token);

            var data = new ArraySegment <byte>(hello, 0, length);

            // send a greeting and see if the server replies
            await SendAsync(data);

            var stream = new MemoryStream();

            try
            {
                await ReceiveAsync(stream);
            }
            catch (Exception e)
            {
                throw new InvalidDataException("Unable to establish connection, no Handshake message received.", e);
            }
        }
示例#3
0
        /// <summary>
        /// 获取服务器子包信息
        /// </summary>
        /// <param name="serverUrl"></param>
        /// <param name="callback"></param>
        public void GetServerSubPackageInfos(string serverUrl, Action <Dictionary <string, string> > callback)
        {
            //下载资源位置必须为Persistent
            var t = UniTask.RunOnThreadPool(() =>
            {
                GetServerVersionInfo(serverUrl, callback);
            });

            Debug.Log("test:------------------------");
        }
示例#4
0
 /// <summary>
 /// 开始版本控制
 /// </summary>
 /// <param name="updateMode"></param>
 /// <param name="serverConfigUrl"></param>
 /// <param name="assetsPackageName">分包名,如果不填则为下载所有</param>
 /// <param name="onProccess">下载进度</param>
 /// <param name="onTaskEndCallback">结果回调</param>
 public void UpdateAssets(UpdateMode updateMode, string serverConfigUrl, string assetsPackageName = "", Action <AssetItem, List <AssetItem> > onDownloadProccess = null,
                          Action <RetStatus, string> onTaskEndCallback = null)
 {
     //下载资源位置必须为Persistent
     UniTask.RunOnThreadPool(() =>
     {
         //开始版本控制逻辑
         StartVersionControl(updateMode, serverConfigUrl, BApplication.persistentDataPath, assetsPackageName, onDownloadProccess, onTaskEndCallback);
     });
 }
示例#5
0
 public static UniTask <MoveGenerator> Run(Field field, Piece spawned, Piece?unhold)
 {
     return(UniTask.RunOnThreadPool(() => {
         var gen = new MoveGenerator(field);
         gen.Generate(spawned);
         if (unhold != null)
         {
             gen.Generate(unhold.Value);
         }
         return gen;
     }));
 }
示例#6
0
        /// <summary>
        ///     Initialize new <see cref="Server"/>.
        /// </summary>
        /// <param name="port">The port we want to bind listening connections on.</param>
        /// <param name="transport">Transport to attach to.</param>
        public Server(int port, Transport transport)
        {
            _cancellationToken = new CancellationTokenSource();

            _serverLoop = new Loop();

            ListenAsync(port);

            _transport = transport;

            _ = UniTask.RunOnThreadPool(Tick, false, _cancellationToken.Token);

            _transport.Started.Invoke();
        }
示例#7
0
        public AfkChecker(IEventBus eventBus, NewEssentials plugin, IConfiguration configuration,
                          IStringLocalizer stringLocalizer, IUnturnedUserDirectory unturnedUserDirectory, IPermissionChecker permissionChecker)
        {
            m_EventBus              = eventBus;
            m_Configuration         = configuration;
            m_StringLocalizer       = stringLocalizer;
            m_UnturnedUserDirectory = unturnedUserDirectory;
            m_PermissionChecker     = permissionChecker;
            m_ServiceRunning        = true;

            m_EventListener = m_EventBus.Subscribe <UnturnedUserConnectedEvent>(plugin, OnPlayerJoin);

            UniTask.RunOnThreadPool(CheckAfkPlayers);
        }
示例#8
0
        private void UpdateLastSeen(string id, string type)
        {
            UniTask.RunOnThreadPool(async() =>
            {
                var userData = await m_UserDataStore.GetUserDataAsync(id, type);
                if (userData == null)
                {
                    return;
                }

                userData.LastSeen = DateTime.Now;
                await m_UserDataStore.SetUserDataAsync(userData);
            }).Forget();
        }
示例#9
0
        protected virtual void OnPendingPlayerConnecting(ValidateAuthTicketResponse_t callback, ref bool isValid,
                                                         ref string?explanation)
        {
            var user = GetUser(callback.m_SteamID);

            if (user != null || m_PendingUsers.Any(d => d.SteamId == callback.m_SteamID))
            {
                return;
            }

            var steamPending = Provider.pending.FirstOrDefault(d => d.playerID.steamID == callback.m_SteamID);

            if (steamPending == null)
            {
                return;
            }

            var pendingUser = new UnturnedPendingUser(this, m_UserDataStore, steamPending);

            m_PendingUsers.Add(pendingUser);

            var isPendingValid    = isValid;
            var rejectExplanation = explanation;

            AsyncHelper.RunSync(async() =>
            {
                UnturnedUserConnectingEvent userEvent;

                var userData = await m_UserDataStore.GetUserDataAsync(pendingUser.Id, pendingUser.Type);
                if (userData != null)
                {
                    userEvent = new UnturnedUserConnectingEvent(pendingUser);

                    userData.LastSeen        = DateTime.Now;
                    userData.LastDisplayName = pendingUser.DisplayName;
                    UniTask.RunOnThreadPool(() => m_UserDataStore.SetUserDataAsync(userData)).Forget();
                }
                else
                {
                    userEvent = new UnturnedUserFirstConnectingEvent(pendingUser);
                    UniTask.RunOnThreadPool(() => m_DataSeeder.SeedUserDataAsync(pendingUser.Id, pendingUser.Type, pendingUser.DisplayName)).Forget();
                }

                userEvent.IsCancelled = !isPendingValid;
                if (rejectExplanation != null)
                {
                    await userEvent.RejectAsync(rejectExplanation);
                }

                await m_EventBus.EmitAsync(m_Runtime, this, userEvent);
                if (!string.IsNullOrEmpty(userEvent.RejectionReason))
                {
                    isPendingValid    = false;
                    rejectExplanation = userEvent.RejectionReason;
                }
                else if (userEvent.IsCancelled)
                {
                    isPendingValid = false;
                }
            });
            isValid     = isPendingValid;
            explanation = rejectExplanation;
        }