Exemple #1
0
        protected virtual void OnPendingPlayerConnecting(ValidateAuthTicketResponse_t callback, ref bool isValid, ref string explanation)
        {
            if (m_PendingUsers.Any(d => d.SteamId == callback.m_SteamID))
            {
                return;
            }

            if (!isValid)
            {
                return;
            }

            //todo check if it is working, if not this should be patched
            var isPendingValid    = isValid;
            var rejectExplanation = explanation;

            AsyncHelper.RunSync(async() =>
            {
                var steamPending = Provider.pending.FirstOrDefault(d => d.playerID.steamID == callback.m_SteamID);
                if (steamPending == null)
                {
                    return;
                }

                var pendingUser = new UnturnedPendingUser(this, m_UserDataStore, steamPending);
                var userData    = await m_UserDataStore.GetUserDataAsync(pendingUser.Id, pendingUser.Type);
                if (userData != null)
                {
                    userData.LastSeen        = DateTime.Now;
                    userData.LastDisplayName = pendingUser.DisplayName;
                    await m_UserDataStore.SetUserDataAsync(userData);
                }
                else
                {
                    await m_DataSeeder.SeedUserDataAsync(pendingUser.Id, pendingUser.Type, pendingUser.DisplayName);
                    await m_EventBus.EmitAsync(m_Runtime, this, new UserFirstConnectEvent(pendingUser));
                }

                m_PendingUsers.Add(pendingUser);

                var userConnectingEvent = new UserConnectEvent(pendingUser);
                await m_EventBus.EmitAsync(m_Runtime, this, userConnectingEvent);

                if (!string.IsNullOrEmpty(userConnectingEvent.RejectionReason))
                {
                    isPendingValid    = false;
                    rejectExplanation = userConnectingEvent.RejectionReason;
                }

                if (userConnectingEvent.IsCancelled)
                {
                    isPendingValid = false;
                }
            });

            isValid     = isPendingValid;
            explanation = rejectExplanation;
        }
Exemple #2
0
        protected virtual void OnPendingPlayerConnected(ValidateAuthTicketResponse_t callback, ref bool isvalid, ref string explanation)
        {
            var isvalid_     = isvalid;
            var explanation_ = explanation;

            AsyncHelper.RunSync(async() =>
            {
                if (!isvalid_)
                {
                    return;
                }

                var steamPending = Provider.pending.First(d => d.playerID.steamID == callback.m_SteamID);
                var pendingUser  = new UnturnedPendingUser(steamPending);
                await m_DataSeeder.SeedUserDataAsync(pendingUser.Id, pendingUser.Type, pendingUser.DisplayName);

                var userData             = await m_UserDataStore.GetUserDataAsync(pendingUser.Type, pendingUser.Id);
                userData.LastSeen        = DateTime.Now;
                userData.LastDisplayName = pendingUser.DisplayName;
                await m_UserDataStore.SaveUserDataAsync(userData);

                pendingUser.PersistentData = userData.Data;
                m_PendingUsers.Add(pendingUser);

                var userConnectingEvent = new UserConnectingEvent(pendingUser);
                await m_EventBus.EmitAsync(m_Runtime, this, userConnectingEvent);

                if (!string.IsNullOrEmpty(userConnectingEvent.RejectionReason))
                {
                    isvalid_     = false;
                    explanation_ = userConnectingEvent.RejectionReason;
                }

                if (userConnectingEvent.IsCancelled)
                {
                    isvalid_ = false;
                }
            });

            isvalid     = isvalid_;
            explanation = explanation_;
        }
Exemple #3
0
        public async Task HandleEventAsync(object sender, UnturnedPlayerDeathEvent @event)
        {
            await UniTask.SwitchToMainThread();

            var id       = @event.Player.EntityInstanceId;
            var position = @event.Player.Transform.Position.ToSerializableVector();

            UniTask.RunOnThreadPool(async() =>
            {
                var userData = await m_UserDataStore.GetUserDataAsync(id, KnownActorTypes.Player);
                if (userData == null)
                {
                    var displayName = @event.Player.SteamPlayer.playerID.characterName;

                    await m_UserDataSeeder.SeedUserDataAsync(id, KnownActorTypes.Player, displayName,
                                                             new() { { "deathLocation", position } });

                    return;
                }

                userData.Data["deathLocation"] = position;
                await m_UserDataStore.SetUserDataAsync(userData);
            }).Forget();
        }
Exemple #4
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;
        }