示例#1
0
        private void InviteMember(BasePlayer player, string username, Callback successCallback,
                                  Callback <InvitationError> errorCallback)
        {
            if (!this.crew.HasPower(player, CrewPower.MembersManagement))
            {
                errorCallback(InvitationError.NotAllowed);
                return;
            }

            this.crew.GetMembers(members =>
            {
                if (members.Count >= 25)
                {
                    errorCallback(InvitationError.LimitReached);
                    return;
                }

                var member = members.FirstOrDefault(it => it.Name == username);
                if (member != null)
                {
                    errorCallback(InvitationError.AlreadyAdded);
                    return;
                }

                CommonPlayer.GetId(this.PlayerIO.BigDB, username, userId =>
                {
                    if (userId == null)
                    {
                        errorCallback(InvitationError.PlayerNotFound);
                        return;
                    }

                    InvitationHelper.GetInvitation(this.PlayerIO.BigDB, InvitationType.Crew,
                                                   this.crewId, username, oldInvitation =>
                    {
                        if (oldInvitation.Exists)
                        {
                            errorCallback(InvitationError.AlreadySent);
                            return;
                        }

                        InvitationBlocking.IsCrewBlocked(this.PlayerIO.BigDB, username, this.crewId, blocked =>
                        {
                            if (blocked)
                            {
                                errorCallback(InvitationError.Blocked);
                                return;
                            }

                            var newInvitation = new DatabaseObject();
                            newInvitation.Set("Sender", this.crewId);
                            newInvitation.Set("Recipient", username);
                            newInvitation.Set("Status", (int)InvitationStatus.Pending);

                            InvitationHelper.CreateInvitation(this.PlayerIO.BigDB, InvitationType.Crew,
                                                              this.crewId, username,
                                                              invitation => successCallback());
                        });
                    });
                });
            });
        }
示例#2
0
        private void CreateInvitation(string recipientName,
                                      Callback successCallback, Callback <InvitationError> errorCallback)
        {
            if (this.name == recipientName)
            {
                errorCallback(InvitationError.SendingToSelf);
                return;
            }

            CommonPlayer.GetId(this.client.BigDB, recipientName, recipientId =>
            {
                if (recipientId == null)
                {
                    errorCallback(InvitationError.PlayerNotFound);
                    return;
                }

                this.GetFriendKeys(this.connectUserId, friends =>
                {
                    if (friends.Contains(recipientId))
                    {
                        errorCallback(InvitationError.AlreadyAdded);
                        return;
                    }

                    InvitationHelper.GetInvitation(this.client.BigDB, InvitationType.Friend,
                                                   this.name, recipientName, oldInvitation =>
                    {
                        if (oldInvitation.Exists)
                        {
                            errorCallback(InvitationError.AlreadySent);
                            return;
                        }

                        this.GetPendingInvitationsCount(pendingInvitationsCount =>
                        {
                            if (friends.Count + pendingInvitationsCount >= this.MaxFriendsAllowed)
                            {
                                errorCallback(InvitationError.LimitReached);
                                return;
                            }

                            InvitationHelper.GetInvitation(this.client.BigDB, InvitationType.Friend,
                                                           recipientName, this.name, invitationToMe =>
                            {
                                if (invitationToMe.Exists && invitationToMe.Status == InvitationStatus.Pending)
                                {
                                    invitationToMe.Status = InvitationStatus.Accepted;
                                    this.AddOrRemoveFriend(recipientId, true,
                                                           () => invitationToMe.Save(successCallback));
                                    return;
                                }

                                InvitationBlocking.IsUserBlocked(this.client.BigDB, recipientId, this.name,
                                                                 blocked =>
                                {
                                    if (blocked)
                                    {
                                        errorCallback(InvitationError.Blocked);
                                        return;
                                    }

                                    var newInvitation = new DatabaseObject();
                                    newInvitation.Set("Sender", this.name);
                                    newInvitation.Set("Recipient", recipientName);
                                    newInvitation.Set("Status", (int)InvitationStatus.Pending);

                                    InvitationHelper.CreateInvitation(this.client.BigDB,
                                                                      InvitationType.Friend,
                                                                      this.name, recipientName,
                                                                      invitation => successCallback());
                                });
                            });
                        });
                    });
                });
            });
        }