public void UpdateMemberRole(Gang gang, Character member, GangRole newRole)
        {
            var res = Db.Query().CommandText("update gangmembers set role = @newRole where gangid = @gangId and memberid = @memberId")
                      .SetParameter("@gangId", gang.Id)
                      .SetParameter("@memberId", member.Id)
                      .SetParameter("@newRole", (int)newRole)
                      .ExecuteNonQuery();

            if (res == 0)
            {
                throw new PerpetuumException(ErrorCodes.SQLUpdateError);
            }
        }
Ejemplo n.º 2
0
        public bool HasRole(Character member, GangRole role)
        {
            if (member == Leader)
            {
                return(true);
            }

            if (!_members.TryGetValue(member, out GangRole currentRole))
            {
                return(false);
            }

            return(currentRole.HasFlag(role));
        }
Ejemplo n.º 3
0
        public void SetRole(Gang gang, Character member, GangRole newRole)
        {
            if (gang.Leader == member)
            {
                return;
            }

            if (!gang.IsMember(member))
            {
                throw new PerpetuumException(ErrorCodes.CharacterNotInTheCurrentGang);
            }

            _gangRepository.UpdateMemberRole(gang, member, newRole);

            void Finish()
            {
                gang.SetMember(member, newRole);
                Message.Builder.SetCommand(Commands.GangSetRole).WithData(new Dictionary <string, object>
                {
                    { k.memberID, member.Id },
                    { k.role, (int)newRole }
                }).ToCharacters(gang.GetMembers()).Send();

                var channelMemberRole = gang.HasRole(member, GangRole.Assistant) ? ChannelMemberRole.Operator : ChannelMemberRole.Undefined;

                _channelManager.SetMemberRole(gang.ChannelName, member, channelMemberRole);
            }

            if (Transaction.Current == null)
            {
                Transaction.Current.OnCommited(Finish);
            }
            else
            {
                Finish();
            }
        }
Ejemplo n.º 4
0
 public void SetMember(Character member, GangRole role = GangRole.Undefined)
 {
     _members[member] = role;
 }