Ejemplo n.º 1
0
        public void Ignore(string name)
        {
            if (name.Length <= 0 || name.Equals(_player.Name, StringComparison.OrdinalIgnoreCase))
            {
                _player.SendLocalizeString("", ChatLogFilters.CHATLOGFILTERS_USER_ERROR, Localized_text.TEXT_SN_FRIENDSLIST_ERR_ADD_SELF);
                return;
            }

            string charName    = Player.AsCharacterName(name);
            uint   characterId = CharMgr.GetCharacterId(charName);

            // Character didn't exist
            if (characterId == 0)
            {
                _player.SendLocalizeString("", ChatLogFilters.CHATLOGFILTERS_USER_ERROR, Localized_text.TEXT_SN_LISTS_ERR_PLAYER_NOT_FOUND);
                return;
            }
            bool applyIgnore = true;

            lock (_ignoreCharacterIds)
                if (_ignoreCharacterIds.ContainsKey(characterId))
                {
                    applyIgnore = false;
                }

            if (applyIgnore)
            {
                AddIgnore(characterId, name);
            }
            else
            {
                RemoveIgnore(characterId, name);
            }
        }
Ejemplo n.º 2
0
        public void RemoveFriend(string name)
        {
            uint characterId = CharMgr.GetCharacterId(Player.AsCharacterName(name));

            Character_social social;

            lock (_friendCharacterIds)
                _friendCharacterIds.TryGetValue(characterId, out social);

            if (social == null)
            {
                _player.SendLocalizeString("", ChatLogFilters.CHATLOGFILTERS_USER_ERROR, Localized_text.TEXT_SN_LISTS_ERR_PLAYER_NOT_FOUND);
                return;
            }

            PacketOut Out = new PacketOut((byte)Opcodes.F_SOCIAL_NETWORK);

            Out.WriteUInt16(0);
            Out.WriteByte((byte)SocialListType.SOCIAL_FRIEND);
            Out.WriteByte(1); // Count
            Out.WriteByte(1);
            Out.WriteUInt32(social.DistCharacterId);

            _player.SendPacket(Out);

            _player.SendLocalizeString(social.DistName, ChatLogFilters.CHATLOGFILTERS_SAY, Localized_text.TEXT_SN_FRIEND_REMOVE);

            if (social.Ignore > 0)
            {
                social.Friend = 0;
                CharMgr.Database.SaveObject(social);
            }
            else
            {
                lock (_player.Info.Socials)
                {
                    if (_player.Info.Socials.Contains(social))
                    {
                        _player.Info.Socials.Remove(social);
                    }
                }
                CharMgr.Database.DeleteObject(social);
            }

            lock (_friendCharacterIds)
                _friendCharacterIds.Remove(social.DistCharacterId);

            //CharMgr.Database.ForceSave();
        }
Ejemplo n.º 3
0
        public void AddFriend(string name)
        {
            if (name.Length <= 0 || name.Equals(_player.Name, StringComparison.OrdinalIgnoreCase))
            {
                _player.SendLocalizeString("", ChatLogFilters.CHATLOGFILTERS_USER_ERROR, Localized_text.TEXT_SN_FRIENDSLIST_ERR_ADD_SELF);
                return;
            }

            string charName    = Player.AsCharacterName(name);
            uint   characterId = CharMgr.GetCharacterId(charName);

            // Character didn't exist
            if (characterId == 0)
            {
                _player.SendLocalizeString("", ChatLogFilters.CHATLOGFILTERS_USER_ERROR, Localized_text.TEXT_SN_LISTS_ERR_PLAYER_NOT_FOUND);
                return;
            }

            // Lift any ignore when friending someone
            if (HasIgnore(characterId))
            {
                RemoveIgnore(characterId, name);
            }

            // Check for existing friend
            lock (_friendCharacterIds)
            {
                if (_friendCharacterIds.ContainsKey(characterId))
                {
                    _player.SendLocalizeString("", ChatLogFilters.CHATLOGFILTERS_USER_ERROR, Localized_text.TEXT_SN_FRIENDSLIST_ERR_EXISTS);
                    return;
                }
            }

            // Players may not add a GM as a friend unless the GM friended them first
            Character charInfo = CharMgr.GetCharacter(characterId, false);

            if (charInfo != null && _player.GmLevel == 0)
            {
                Account acct = Program.AcctMgr.GetAccountById(charInfo.AccountId);

                if (acct != null && acct.GmLevel > 1)
                {
                    lock (charInfo.Socials)
                    {
                        if (!charInfo.Socials.Any(soc => soc.DistCharacterId == _player.Info.CharacterId && soc.Friend == 1))
                        {
                            _player.SendClientMessage("To prevent abuse of the Friends list for staff harassment, you may not friend staff members unless they friend you first.", ChatLogFilters.CHATLOGFILTERS_CSR_TELL_RECEIVE);
                            return;
                        }
                    }
                }
            }

            Character_social social = new Character_social
            {
                CharacterId     = _player.Info.CharacterId,
                DistName        = charName,
                DistCharacterId = characterId,
                Friend          = 1,
                Ignore          = 0
            };

            CharMgr.Database.AddObject(social);
            _player.Info.Socials.Add(social);

            lock (_friendCharacterIds)
                _friendCharacterIds.Add(characterId, social);

            //CharMgr.Database.ForceSave();

            SendSocialList(social, SocialListType.SOCIAL_FRIEND);
            _player.SendLocalizeString(charName, ChatLogFilters.CHATLOGFILTERS_SAY, Localized_text.TEXT_SN_FRIENDSLIST_ADD_SUCCESS);

            Player distPlayer = Player.GetPlayer(name);

            if (distPlayer != null)
            {
                distPlayer.SendLocalizeString(_player.Name, ChatLogFilters.CHATLOGFILTERS_SAY, Localized_text.TEXT_X_FRIENDED_YOU);
                SendFriend(distPlayer, true);
            }
        }