Ejemplo n.º 1
0
        public EmptyParameters?Handle(MessageData <ChangeUserProfilePropertiesRequestParameters> messageData, ref MessageSendOptions sendOptions)
        {
            var userId           = messageData.Parameters.UserId;
            var localId          = messageData.Parameters.LocalId;
            var serverType       = messageData.Parameters.ServerType;
            var connectionStatus = messageData.Parameters.ConnectionStatus;

            if (databaseUserProfileExistence.Exists(userId))
            {
                databaseUserProfilePropertiesUpdater.Update(userId, localId, serverType, connectionStatus);
            }
            else
            {
                databaseUserProfileCreator.Create(userId, localId, serverType, connectionStatus);
            }

            if (connectionStatus == ConnectionStatus.Connected)
            {
                usersContainer.Add(userId);
            }
            else
            {
                usersContainer.Remove(userId);
            }

            var parameters = new UserProfilePropertiesChangedEventParameters(userId, serverType);

            userProfilePropertiesChangesNotifier.Notify(parameters);
            return(null);
        }
        private void HandleUnexpectedShutdown()
        {
            var users = usersContainer.Get();

            foreach (var userId in users)
            {
                databaseUserProfilePropertiesUpdater.Update(userId, default(int), ServerType.Login, ConnectionStatus.Disconnected);

                var parameters = new UserProfilePropertiesChangedEventParameters(userId, ServerType.Login);
                userProfilePropertiesChangesNotifier.Notify(parameters);

                RemoveAuthorization(userId);
            }
        }
        public void Notify(UserProfilePropertiesChangedEventParameters parameters)
        {
            var userId    = parameters.UserId;
            var serverIds = userIdToServerIdConverter.Get(userId);

            if (serverIds == null)
            {
                LogUtils.Log($"Could not find server ids for user with id {userId}");
                return;
            }

            foreach (var serverId in serverIds)
            {
                var peerId = serverIdToPeerIdConverter.Get(serverId);
                if (!peerId.HasValue)
                {
                    continue;
                }

                if (peerId.Value == clientPeerProvider.PeerId)
                {
                    continue;
                }

                var peerWrapper = peerContainer.GetPeerWrapper(peerId.Value);
                if (peerWrapper == null)
                {
                    LogUtils.Log($"Could not find a peer wrapper of server with id {serverId}");
                    continue;
                }

                RaiseUserProfilePropertiesChanged(peerWrapper);
            }

            void RaiseUserProfilePropertiesChanged(IClientPeerWrapper peerWrapper)
            {
                var eventSenderWrapper = peerWrapper.PeerLogic.Components.GetComponent <IEventSenderWrapper>().AssertNotNull();

                eventSenderWrapper.Send((byte)UserProfileEvents.UserProfilePropertiesChanged, parameters, MessageSendOptions.DefaultReliable());
            }
        }