Exemple #1
0
        public void OnMessage(object sender, MessageEventArgs e)
        {
            try
            {
                var data = MessagePackSerializer.Deserialize <CommandData>(e.RawData);
                if (data.Type == "error")
                {
                    // errors contain aditional attributes
                    var error = MessagePackSerializer.Deserialize <CoflnetExceptionTransmit>(e.RawData);
                    OnError.Invoke(new CoflnetException(error));
                    return;
                }

                onMessage?.Invoke(data);

                // confirm receival
                SendCommand(
                    CommandData.CreateCommandData <ReceiveConfirm, ReceiveConfirmParams>(
                        ConnectedServerId,
                        new ReceiveConfirmParams(data.SenderId, data.MessageId)));
            }
            catch (System.Exception ex)
            {
                Logger.Error(ex.Message);
            }
        }
Exemple #2
0
        public override void Execute(CommandData data)
        {
            EntityId oldId;

            try
            {
                oldId = data.GetAs <CreationParamsBase>().options.OldId;
            }catch (Exception)
            {
                throw new CoflnetException("invalid_payload", "The payload of the command isn't of type CreationParamsBase nor derived from it");
            }
            var resource = CreateResource(data);

            resource.AssignId(data.CoreInstance.EntityManager);

            // make sure the owner is set
            resource.GetAccess().Owner = data.Recipient;

            // add the size to any data cap limit (tracking module)
            // TODO


            // it is possible that the return will not be received by the target in case it gets offline

            data.SendBack(CommandData.CreateCommandData <CreationResponseCommand, KeyValuePair <EntityId, EntityId> >
                              (data.SenderId, new KeyValuePair <EntityId, EntityId>(oldId, resource.Id)));
        }
Exemple #3
0
        public override void Execute(CommandData data)
        {
            var result = new PublicUserInfo();
            var user   = EntityManager.Instance.GetEntity <CoflnetUser> (data.Recipient);

            result.userName = user.UserName;
            result.GetAccess().Owner = user.Id;

            if (user.PrivacySettings["share-profile-picture"])
            {
                result.profilePicture = user.ProfileImage;
            }

            data.SendBack(CommandData.CreateCommandData <BasicInfoResponse, PublicUserInfo> (data.SenderId, result));
        }
Exemple #4
0
        public override void Execute(CommandData data)
        {
            RegisterUserRequest request = data.GetAs <RegisterUserRequest> ();

            // validate captcha Token
            // todo :)

            CoflnetUser user = CoflnetUser.Generate(request.clientId, data.CoreInstance.EntityManager);

            user.PrivacySettings = request.privacySettings;

            var response = new RegisterUserResponse();

            response.id     = user.Id;
            response.secret = user.Secret;


            data.SendBack(CommandData.CreateCommandData <RegisteredUser, RegisterUserResponse> (data.SenderId, response));
            //SendTo(data.sId, user.PublicId, "createdUser");
        }