Ejemplo n.º 1
0
        public void DeleteGuild(ObjectGuid guildId)
        {
            SQLTransaction    trans = new SQLTransaction();
            PreparedStatement stmt;
            var guildDic = _membershipRequestsByGuild.LookupByKey(guildId);

            if (guildDic != null)
            {
                foreach (var guid in guildDic.Keys)
                {
                    stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_GUILD_FINDER_APPLICANT);
                    stmt.AddValue(0, guildId.GetCounter());
                    stmt.AddValue(1, guid.GetCounter());
                    trans.Append(stmt);

                    if (_membershipRequestsByPlayer.ContainsKey(guid))
                    {
                        var playerDic = _membershipRequestsByPlayer.LookupByKey(guid);
                        playerDic.Remove(guildId);
                        if (playerDic.Empty())
                        {
                            _membershipRequestsByPlayer.Remove(guid);
                        }
                    }

                    // Notify the applicant his submition has been removed
                    Player player = Global.ObjAccessor.FindPlayer(guid);
                    if (player)
                    {
                        SendMembershipRequestListUpdate(player);
                    }
                }
            }

            stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_GUILD_FINDER_GUILD_SETTINGS);
            stmt.AddValue(0, guildId.GetCounter());
            trans.Append(stmt);

            DB.Characters.CommitTransaction(trans);

            _membershipRequestsByGuild.Remove(guildId);
            _guildSettings.Remove(guildId);

            // Notify the guild master the list changed (even if he's not a GM any more, not sure if needed)
            Guild guild = Global.GuildMgr.GetGuildById(guildId.GetCounter());

            if (guild)
            {
                SendApplicantListUpdate(guild);
            }
        }
        public static void DeleteFromDB(ObjectGuid guid)
        {
            SQLTransaction trans = new();

            PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHAR_QUESTSTATUS_OBJECTIVES_CRITERIA);

            stmt.AddValue(0, guid.GetCounter());
            trans.Append(stmt);

            stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHAR_QUESTSTATUS_OBJECTIVES_CRITERIA_PROGRESS);
            stmt.AddValue(0, guid.GetCounter());
            trans.Append(stmt);

            DB.Characters.CommitTransaction(trans);
        }
Ejemplo n.º 3
0
        public void SetCaptain(ObjectGuid guid)
        {
            // Disable remove/promote buttons
            Player oldCaptain = Global.ObjAccessor.FindPlayer(GetCaptain());

            if (oldCaptain)
            {
                oldCaptain.SetArenaTeamInfoField(GetSlot(), ArenaTeamInfoType.Member, 1);
            }

            // Set new captain
            CaptainGuid = guid;

            // Update database
            PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_ARENA_TEAM_CAPTAIN);

            stmt.AddValue(0, guid.GetCounter());
            stmt.AddValue(1, GetId());
            DB.Characters.Execute(stmt);

            // Enable remove/promote buttons
            Player newCaptain = Global.ObjAccessor.FindPlayer(guid);

            if (newCaptain)
            {
                newCaptain.SetArenaTeamInfoField(GetSlot(), ArenaTeamInfoType.Member, 0);
                if (oldCaptain)
                {
                    Log.outDebug(LogFilter.Arena, "Player: {0} [GUID: {1}] promoted player: {2} [GUID: {3}] to leader of arena team [Id: {4}, Name: {5}] [Type: {6}].",
                                 oldCaptain.GetName(), oldCaptain.GetGUID().ToString(), newCaptain.GetName(),
                                 newCaptain.GetGUID().ToString(), GetId(), GetName(), GetArenaType());
                }
            }
        }
Ejemplo n.º 4
0
        public void DelMember(ObjectGuid guid, bool cleanDb)
        {
            // Remove member from team
            foreach (var member in Members)
            {
                if (member.Guid == guid)
                {
                    Members.Remove(member);
                    break;
                }
            }

            // Remove arena team info from player data
            Player player = Global.ObjAccessor.FindPlayer(guid);

            if (player)
            {
                // delete all info regarding this team
                for (uint i = 0; i < (int)ArenaTeamInfoType.End; ++i)
                {
                    player.SetArenaTeamInfoField(GetSlot(), (ArenaTeamInfoType)i, 0);
                }
                Log.outDebug(LogFilter.Arena, "Player: {0} [GUID: {1}] left arena team type: {2} [Id: {3}, Name: {4}].", player.GetName(), player.GetGUID().ToString(), GetArenaType(), GetId(), GetName());
            }

            // Only used for single member deletion, for arena team disband we use a single query for more efficiency
            if (cleanDb)
            {
                PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_ARENA_TEAM_MEMBER);
                stmt.AddValue(0, GetId());
                stmt.AddValue(1, guid.GetCounter());
                DB.Characters.Execute(stmt);
            }
        }
Ejemplo n.º 5
0
        public void AddMembershipRequest(ObjectGuid guildGuid, MembershipRequest request)
        {
            _membershipRequestsByGuild[guildGuid][request.GetPlayerGUID()]  = request;
            _membershipRequestsByPlayer[request.GetPlayerGUID()][guildGuid] = request;

            SQLTransaction    trans = new SQLTransaction();
            PreparedStatement stmt  = DB.Characters.GetPreparedStatement(CharStatements.REP_GUILD_FINDER_APPLICANT);

            stmt.AddValue(0, request.GetGuildGuid());
            stmt.AddValue(1, request.GetPlayerGUID());
            stmt.AddValue(2, request.GetAvailability());
            stmt.AddValue(3, request.GetClassRoles());
            stmt.AddValue(4, request.GetInterests());
            stmt.AddValue(5, request.GetComment());
            stmt.AddValue(6, request.GetSubmitTime());
            trans.Append(stmt);
            DB.Characters.CommitTransaction(trans);

            // Notify the applicant his submittion has been added
            Player player = Global.ObjAccessor.FindPlayer(request.GetPlayerGUID());

            if (player)
            {
                SendMembershipRequestListUpdate(player);
            }

            // Notify the guild master and officers the list changed
            Guild guild = Global.GuildMgr.GetGuildById(guildGuid.GetCounter());

            if (guild)
            {
                SendApplicantListUpdate(guild);
            }
        }
Ejemplo n.º 6
0
        public MailReceiver(Player receiver, ObjectGuid receiverGuid)
        {
            m_receiver         = receiver;
            m_receiver_lowguid = receiverGuid.GetCounter();

            Cypher.Assert(!receiver || receiver.GetGUID() == receiverGuid);
        }
Ejemplo n.º 7
0
        public static void HandleCharacterLevel(Player player, ObjectGuid playerGuid, int oldLevel, int newLevel, CommandHandler handler)
        {
            if (player)
            {
                player.GiveLevel((uint)newLevel);
                player.InitTalentForLevel();
                player.SetXP(0);

                if (handler.NeedReportToTarget(player))
                {
                    if (oldLevel == newLevel)
                    {
                        player.SendSysMessage(CypherStrings.YoursLevelProgressReset, handler.GetNameLink());
                    }
                    else if (oldLevel < newLevel)
                    {
                        player.SendSysMessage(CypherStrings.YoursLevelUp, handler.GetNameLink(), newLevel);
                    }
                    else                                                // if (oldlevel > newlevel)
                    {
                        player.SendSysMessage(CypherStrings.YoursLevelDown, handler.GetNameLink(), newLevel);
                    }
                }
            }
            else
            {
                // Update level and reset XP, everything else will be updated at login
                PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_LEVEL);
                stmt.AddValue(0, newLevel);
                stmt.AddValue(1, playerGuid.GetCounter());
                DB.Characters.Execute(stmt);
            }
        }
Ejemplo n.º 8
0
 public override void MovementInform(MovementGeneratorType moveType, uint data)
 {
     if (moveType == MovementGeneratorType.Follow && data == _summonerGuid.GetCounter())
     {
         me.CastSpell((Unit)null, SpellIds.DarkOffering, false);
         me.DespawnOrUnsummon(1000);
     }
 }
Ejemplo n.º 9
0
        public void SendStablePet(ObjectGuid guid)
        {
            PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_PET_SLOTS_DETAIL);

            stmt.AddValue(0, guid.GetCounter());
            stmt.AddValue(1, PetSaveMode.FirstStableSlot);
            stmt.AddValue(2, PetSaveMode.LastStableSlot);

            _queryProcessor.AddQuery(DB.Characters.AsyncQuery(stmt).WithCallback(SendStablePetCallback, guid));
        }
Ejemplo n.º 10
0
        public ulong extractLowGuidFromLink(StringArguments args, ref HighGuid guidHigh)
        {
            int type;

            string[] guidKeys =
            {
                "Hplayer",
                "Hcreature",
                "Hgameobject"
            };
            // |color|Hcreature:creature_guid|h[name]|h|r
            // |color|Hgameobject:go_guid|h[name]|h|r
            // |color|Hplayer:name|h[name]|h|r
            string idS = extractKeyFromLink(args, guidKeys, out type);
            if (string.IsNullOrEmpty(idS))
                return 0;

            switch (type)
            {
                case 0:
                    {
                        guidHigh = HighGuid.Player;
                        if (!ObjectManager.NormalizePlayerName(ref idS))
                            return 0;

                        Player player = Global.ObjAccessor.FindPlayerByName(idS);
                        if (player)
                            return player.GetGUID().GetCounter();

                        ObjectGuid guid = Global.CharacterCacheStorage.GetCharacterGuidByName(idS);
                        if (guid.IsEmpty())
                            return 0;

                        return guid.GetCounter();
                    }
                case 1:
                    {
                        guidHigh = HighGuid.Creature;
                        if (!ulong.TryParse(idS, out ulong lowguid))
                            return 0;
                        return lowguid;
                    }
                case 2:
                    {
                        guidHigh = HighGuid.GameObject;
                        if (!ulong.TryParse(idS, out ulong lowguid))
                            return 0;
                        return lowguid;
                    }
            }

            // unknown type?
            return 0;
        }
Ejemplo n.º 11
0
        public void SendPetitionQuery(ObjectGuid petitionGUID)
        {
            ObjectGuid ownerGUID = ObjectGuid.Empty;
            string     title     = "NO_NAME_FOR_GUID";

            QueryPetitionResponse responsePacket = new QueryPetitionResponse();

            responsePacket.PetitionID = (uint)petitionGUID.GetCounter();  // PetitionID (in Trinity always same as GUID_LOPART(petition guid))

            PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_PETITION);

            stmt.AddValue(0, petitionGUID.GetCounter());
            SQLResult result = DB.Characters.Query(stmt);

            if (!result.IsEmpty())
            {
                ownerGUID = ObjectGuid.Create(HighGuid.Player, result.Read <ulong>(0));
                title     = result.Read <string>(1);
            }
            else
            {
                Log.outDebug(LogFilter.Network, "CMSG_PETITION_Select failed for petition ({0})", petitionGUID.ToString());
                return;
            }

            int reqSignatures = WorldConfig.GetIntValue(WorldCfg.MinPetitionSigns);

            PetitionInfo petitionInfo = new PetitionInfo();

            petitionInfo.PetitionID    = (int)petitionGUID.GetCounter();
            petitionInfo.Petitioner    = ownerGUID;
            petitionInfo.MinSignatures = reqSignatures;
            petitionInfo.MaxSignatures = reqSignatures;
            petitionInfo.Title         = title;

            responsePacket.Allow = true;
            responsePacket.Info  = petitionInfo;

            SendPacket(responsePacket);
        }
Ejemplo n.º 12
0
        public bool Create(ObjectGuid captainGuid, byte _type, string arenaTeamName, uint backgroundColor, byte emblemStyle, uint emblemColor, byte borderStyle, uint borderColor)
        {
            // Check if captain is present
            if (!Global.ObjAccessor.FindPlayer(captainGuid))
            {
                return(false);
            }

            // Check if arena team name is already taken
            if (Global.ArenaTeamMgr.GetArenaTeamByName(arenaTeamName) != null)
            {
                return(false);
            }

            // Generate new arena team id
            teamId = Global.ArenaTeamMgr.GenerateArenaTeamId();

            // Assign member variables
            CaptainGuid     = captainGuid;
            type            = _type;
            TeamName        = arenaTeamName;
            BackgroundColor = backgroundColor;
            EmblemStyle     = emblemStyle;
            EmblemColor     = emblemColor;
            BorderStyle     = borderStyle;
            BorderColor     = borderColor;
            ulong captainLowGuid = captainGuid.GetCounter();

            // Save arena team to db
            PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_ARENA_TEAM);

            stmt.AddValue(0, teamId);
            stmt.AddValue(1, TeamName);
            stmt.AddValue(2, captainLowGuid);
            stmt.AddValue(3, type);
            stmt.AddValue(4, stats.Rating);
            stmt.AddValue(5, BackgroundColor);
            stmt.AddValue(6, EmblemStyle);
            stmt.AddValue(7, EmblemColor);
            stmt.AddValue(8, BorderStyle);
            stmt.AddValue(9, BorderColor);
            DB.Characters.Execute(stmt);

            // Add captain as member
            AddMember(CaptainGuid);

            Log.outDebug(LogFilter.Arena, "New ArenaTeam created Id: {0}, Name: {1} Type: {2} Captain low GUID: {3}", GetId(), GetName(), GetArenaType(), captainLowGuid);
            return(true);
        }
Ejemplo n.º 13
0
        public Guild GetGuildByGuid(ObjectGuid guid)
        {
            // Full guids are only used when receiving/sending data to client
            // everywhere else guild id is used
            if (guid.IsGuild())
            {
                ulong guildId = guid.GetCounter();
                if (guildId != 0)
                {
                    return(GetGuildById(guildId));
                }
            }

            return(null);
        }
Ejemplo n.º 14
0
        public void RemoveMembershipRequest(ObjectGuid playerId, ObjectGuid guildId)
        {
            if (_membershipRequestsByGuild.ContainsKey(guildId))
            {
                var guildDic = _membershipRequestsByGuild[guildId];
                guildDic.Remove(playerId);
                if (guildDic.Empty())
                {
                    _membershipRequestsByGuild.Remove(guildId);
                }
            }

            var playerDic = _membershipRequestsByPlayer.LookupByKey(playerId);

            if (playerDic != null)
            {
                playerDic.Remove(guildId);
                if (playerDic.Empty())
                {
                    _membershipRequestsByPlayer.Remove(playerId);
                }
            }

            SQLTransaction    trans = new SQLTransaction();
            PreparedStatement stmt  = DB.Characters.GetPreparedStatement(CharStatements.DEL_GUILD_FINDER_APPLICANT);

            stmt.AddValue(0, guildId.GetCounter());
            stmt.AddValue(1, playerId.GetCounter());
            trans.Append(stmt);

            DB.Characters.CommitTransaction(trans);

            // Notify the applicant his submittion has been removed
            Player player = Global.ObjAccessor.FindPlayer(playerId);

            if (player)
            {
                SendMembershipRequestListUpdate(player);
            }

            // Notify the guild master and officers the list changed
            Guild guild = Global.GuildMgr.GetGuildByGuid(guildId);

            if (guild)
            {
                SendApplicantListUpdate(guild);
            }
        }
Ejemplo n.º 15
0
        public override void SaveToDB()
        {
            var trans = new SQLTransaction();

            byte idx = 0;
            PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.REP_GM_COMPLAINT);

            stmt.AddValue(idx, _id);
            stmt.AddValue(++idx, _playerGuid.GetCounter());
            stmt.AddValue(++idx, _note);
            stmt.AddValue(++idx, _createTime);
            stmt.AddValue(++idx, _mapId);
            stmt.AddValue(++idx, _pos.X);
            stmt.AddValue(++idx, _pos.Y);
            stmt.AddValue(++idx, _pos.Z);
            stmt.AddValue(++idx, _facing);
            stmt.AddValue(++idx, _targetCharacterGuid.GetCounter());
            stmt.AddValue(++idx, (byte)_complaintType);
            if (_chatLog.ReportLineIndex.HasValue)
            {
                stmt.AddValue(++idx, _chatLog.ReportLineIndex.Value);
            }
            else
            {
                stmt.AddValue(++idx, -1); // empty ReportLineIndex
            }
            stmt.AddValue(++idx, _closedBy.GetCounter());
            stmt.AddValue(++idx, _assignedTo.GetCounter());
            stmt.AddValue(++idx, _comment);
            trans.Append(stmt);

            uint lineIndex = 0;

            foreach (var c in _chatLog.Lines)
            {
                idx  = 0;
                stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_GM_COMPLAINT_CHATLINE);
                stmt.AddValue(idx, _id);
                stmt.AddValue(++idx, lineIndex);
                stmt.AddValue(++idx, c.Timestamp);
                stmt.AddValue(++idx, c.Text);

                trans.Append(stmt);
                ++lineIndex;
            }

            DB.Characters.CommitTransaction(trans);
        }
Ejemplo n.º 16
0
        void HandleOpenWrappedItemCallback(ushort pos, ObjectGuid itemGuid, SQLResult result)
        {
            if (!GetPlayer())
            {
                return;
            }

            Item item = GetPlayer().GetItemByPos(pos);

            if (!item)
            {
                return;
            }

            if (item.GetGUID() != itemGuid || !item.IsWrapped()) // during getting result, gift was swapped with another item
            {
                return;
            }

            if (result.IsEmpty())
            {
                Log.outError(LogFilter.Network, $"Wrapped item {item.GetGUID()} don't have record in character_gifts table and will deleted");
                GetPlayer().DestroyItem(item.GetBagSlot(), item.GetSlot(), true);
                return;
            }

            SQLTransaction trans = new();

            uint entry = result.Read <uint>(0);
            uint flags = result.Read <uint>(1);

            item.SetGiftCreator(ObjectGuid.Empty);
            item.SetEntry(entry);
            item.SetItemFlags((ItemFieldFlags)flags);
            item.SetMaxDurability(item.GetTemplate().MaxDurability);
            item.SetState(ItemUpdateState.Changed, GetPlayer());

            GetPlayer().SaveInventoryAndGoldToDB(trans);

            PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_GIFT);

            stmt.AddValue(0, itemGuid.GetCounter());
            trans.Append(stmt);

            DB.Characters.CommitTransaction(trans);
        }
Ejemplo n.º 17
0
        public override void MovementInform(MovementGeneratorType type, uint id)
        {
            ObjectGuid guid = _instance.GetGuidData(BossIds.Xt002);

            if (type == MovementGeneratorType.Follow && id == guid.GetCounter())
            {
                Creature xt002 = ObjectAccessor.GetCreature(me, guid);
                if (xt002)
                {
                    if (me.IsWithinMeleeRange(xt002))
                    {
                        DoCast(xt002, SpellIds.ScrapbotRideVehicle);
                        // Unapply vehicle aura again
                        xt002.RemoveAurasDueToSpell(SpellIds.ScrapbotRideVehicle);
                        me.DespawnOrUnsummon();
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public void RemoveAllMembershipRequestsFromPlayer(ObjectGuid playerId)
        {
            var playerDic = _membershipRequestsByPlayer.LookupByKey(playerId);

            if (playerDic == null)
            {
                return;
            }

            SQLTransaction trans = new SQLTransaction();

            foreach (var guid in playerDic.Keys)
            {
                PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_GUILD_FINDER_APPLICANT);
                stmt.AddValue(0, guid.GetCounter());
                stmt.AddValue(1, playerId.GetCounter());
                trans.Append(stmt);


                // Notify the guild master and officers the list changed
                Guild guild = Global.GuildMgr.GetGuildByGuid(guid);
                if (guild)
                {
                    SendApplicantListUpdate(guild);
                }

                if (!_membershipRequestsByGuild.ContainsKey(guid))
                {
                    continue;
                }

                var guildDic = _membershipRequestsByGuild[guid];
                guildDic.Remove(playerId);
                if (guildDic.Empty())
                {
                    _membershipRequestsByGuild.Remove(guid);
                }
            }

            DB.Characters.CommitTransaction(trans);
            _membershipRequestsByPlayer.Remove(playerId);
        }
Ejemplo n.º 19
0
        public ulong extractLowGuidFromLink(StringArguments args, ref HighGuid guidHigh)
        {
            int type;

            string[] guidKeys =
            {
                "Hplayer",
                "Hcreature",
                "Hgameobject"
            };
            // |color|Hcreature:creature_guid|h[name]|h|r
            // |color|Hgameobject:go_guid|h[name]|h|r
            // |color|Hplayer:name|h[name]|h|r
            string idS = extractKeyFromLink(args, guidKeys, out type);

            if (string.IsNullOrEmpty(idS))
            {
                return(0);
            }

            switch (type)
            {
            case 0:
            {
                guidHigh = HighGuid.Player;
                if (!ObjectManager.NormalizePlayerName(ref idS))
                {
                    return(0);
                }

                Player player = Global.ObjAccessor.FindPlayerByName(idS);
                if (player)
                {
                    return(player.GetGUID().GetCounter());
                }

                ObjectGuid guid = ObjectManager.GetPlayerGUIDByName(idS);
                if (guid.IsEmpty())
                {
                    return(0);
                }

                return(guid.GetCounter());
            }

            case 1:
            {
                guidHigh = HighGuid.Creature;
                ulong lowguid = ulong.Parse(idS);
                return(lowguid);
            }

            case 2:
            {
                guidHigh = HighGuid.GameObject;
                ulong lowguid = ulong.Parse(idS);
                return(lowguid);
            }
            }

            // unknown type?
            return(0);
        }
Ejemplo n.º 20
0
        void HandleSendMail(SendMail packet)
        {
            if (packet.Info.Attachments.Count > SharedConst.MaxMailItems)                      // client limit
            {
                GetPlayer().SendMailResult(0, MailResponseType.Send, MailResponseResult.TooManyAttachments);
                return;
            }

            if (!CanOpenMailBox(packet.Info.Mailbox))
            {
                return;
            }

            if (string.IsNullOrEmpty(packet.Info.Target))
            {
                return;
            }

            Player player = GetPlayer();

            if (player.getLevel() < WorldConfig.GetIntValue(WorldCfg.MailLevelReq))
            {
                SendNotification(CypherStrings.MailSenderReq, WorldConfig.GetIntValue(WorldCfg.MailLevelReq));
                return;
            }

            ObjectGuid receiverGuid = ObjectGuid.Empty;

            if (ObjectManager.NormalizePlayerName(ref packet.Info.Target))
            {
                receiverGuid = Global.CharacterCacheStorage.GetCharacterGuidByName(packet.Info.Target);
            }

            if (receiverGuid.IsEmpty())
            {
                Log.outInfo(LogFilter.Network, "Player {0} is sending mail to {1} (GUID: not existed!) with subject {2}" +
                            "and body {3} includes {4} items, {5} copper and {6} COD copper with StationeryID = {7}",
                            GetPlayerInfo(), packet.Info.Target, packet.Info.Subject, packet.Info.Body,
                            packet.Info.Attachments.Count, packet.Info.SendMoney, packet.Info.Cod, packet.Info.StationeryID);
                player.SendMailResult(0, MailResponseType.Send, MailResponseResult.RecipientNotFound);
                return;
            }

            if (packet.Info.SendMoney < 0)
            {
                GetPlayer().SendMailResult(0, MailResponseType.Send, MailResponseResult.InternalError);
                Log.outWarn(LogFilter.Server, "Player {0} attempted to send mail to {1} ({2}) with negative money value (SendMoney: {3})",
                            GetPlayerInfo(), packet.Info.Target, receiverGuid.ToString(), packet.Info.SendMoney);
                return;
            }

            if (packet.Info.Cod < 0)
            {
                GetPlayer().SendMailResult(0, MailResponseType.Send, MailResponseResult.InternalError);
                Log.outWarn(LogFilter.Server, "Player {0} attempted to send mail to {1} ({2}) with negative COD value (Cod: {3})",
                            GetPlayerInfo(), packet.Info.Target, receiverGuid.ToString(), packet.Info.Cod);
                return;
            }

            Log.outInfo(LogFilter.Network, "Player {0} is sending mail to {1} ({2}) with subject {3} and body {4}" +
                        "includes {5} items, {6} copper and {7} COD copper with StationeryID = {8}",
                        GetPlayerInfo(), packet.Info.Target, receiverGuid.ToString(), packet.Info.Subject,
                        packet.Info.Body, packet.Info.Attachments.Count, packet.Info.SendMoney, packet.Info.Cod, packet.Info.StationeryID);

            if (player.GetGUID() == receiverGuid)
            {
                player.SendMailResult(0, MailResponseType.Send, MailResponseResult.CannotSendToSelf);
                return;
            }

            uint cost = (uint)(!packet.Info.Attachments.Empty() ? 30 * packet.Info.Attachments.Count : 30);  // price hardcoded in client

            long reqmoney = cost + packet.Info.SendMoney;

            // Check for overflow
            if (reqmoney < packet.Info.SendMoney)
            {
                player.SendMailResult(0, MailResponseType.Send, MailResponseResult.NotEnoughMoney);
                return;
            }

            if (!player.HasEnoughMoney(reqmoney) && !player.IsGameMaster())
            {
                player.SendMailResult(0, MailResponseType.Send, MailResponseResult.NotEnoughMoney);
                return;
            }

            Player receiver = Global.ObjAccessor.FindPlayer(receiverGuid);

            Team receiverTeam          = 0;
            byte mailsCount            = 0;                       //do not allow to send to one player more than 100 mails
            byte receiverLevel         = 0;
            uint receiverAccountId     = 0;
            uint receiverBnetAccountId = 0;

            if (receiver)
            {
                receiverTeam          = receiver.GetTeam();
                mailsCount            = (byte)receiver.GetMails().Count;
                receiverLevel         = (byte)receiver.getLevel();
                receiverAccountId     = receiver.GetSession().GetAccountId();
                receiverBnetAccountId = receiver.GetSession().GetBattlenetAccountId();
            }
            else
            {
                CharacterCacheEntry characterInfo = Global.CharacterCacheStorage.GetCharacterCacheByGuid(receiverGuid);
                if (characterInfo != null)
                {
                    receiverTeam      = Player.TeamForRace(characterInfo.RaceId);
                    receiverLevel     = characterInfo.Level;
                    receiverAccountId = characterInfo.AccountId;
                }

                PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_MAIL_COUNT);
                stmt.AddValue(0, receiverGuid.GetCounter());

                SQLResult result = DB.Characters.Query(stmt);
                if (!result.IsEmpty())
                {
                    mailsCount = (byte)result.Read <ulong>(0);
                }

                receiverBnetAccountId = Global.BNetAccountMgr.GetIdByGameAccount(receiverAccountId);
            }

            // do not allow to have more than 100 mails in mailbox.. mails count is in opcode byte!!! - so max can be 255..
            if (mailsCount > 100)
            {
                player.SendMailResult(0, MailResponseType.Send, MailResponseResult.RecipientCapReached);
                return;
            }

            // test the receiver's Faction... or all items are account bound
            bool accountBound = !packet.Info.Attachments.Empty();

            foreach (var att in packet.Info.Attachments)
            {
                Item item = player.GetItemByGuid(att.ItemGUID);
                if (item)
                {
                    ItemTemplate itemProto = item.GetTemplate();
                    if (itemProto == null || !itemProto.GetFlags().HasAnyFlag(ItemFlags.IsBoundToAccount))
                    {
                        accountBound = false;
                        break;
                    }
                }
            }

            if (!accountBound && player.GetTeam() != receiverTeam && !HasPermission(RBACPermissions.TwoSideInteractionMail))
            {
                player.SendMailResult(0, MailResponseType.Send, MailResponseResult.NotYourTeam);
                return;
            }

            if (receiverLevel < WorldConfig.GetIntValue(WorldCfg.MailLevelReq))
            {
                SendNotification(CypherStrings.MailReceiverReq, WorldConfig.GetIntValue(WorldCfg.MailLevelReq));
                return;
            }

            List <Item> items = new List <Item>();

            foreach (var att in packet.Info.Attachments)
            {
                if (att.ItemGUID.IsEmpty())
                {
                    player.SendMailResult(0, MailResponseType.Send, MailResponseResult.MailAttachmentInvalid);
                    return;
                }

                Item item = player.GetItemByGuid(att.ItemGUID);

                // prevent sending bag with items (cheat: can be placed in bag after adding equipped empty bag to mail)
                if (!item)
                {
                    player.SendMailResult(0, MailResponseType.Send, MailResponseResult.MailAttachmentInvalid);
                    return;
                }

                if (!item.CanBeTraded(true))
                {
                    player.SendMailResult(0, MailResponseType.Send, MailResponseResult.EquipError, InventoryResult.MailBoundItem);
                    return;
                }

                if (item.IsBoundAccountWide() && item.IsSoulBound() && player.GetSession().GetAccountId() != receiverAccountId)
                {
                    if (!item.IsBattlenetAccountBound() || player.GetSession().GetBattlenetAccountId() == 0 || player.GetSession().GetBattlenetAccountId() != receiverBnetAccountId)
                    {
                        player.SendMailResult(0, MailResponseType.Send, MailResponseResult.EquipError, InventoryResult.NotSameAccount);
                        return;
                    }
                }

                if (item.GetTemplate().GetFlags().HasAnyFlag(ItemFlags.Conjured) || item.m_itemData.Expiration != 0)
                {
                    player.SendMailResult(0, MailResponseType.Send, MailResponseResult.EquipError, InventoryResult.MailBoundItem);
                    return;
                }

                if (packet.Info.Cod != 0 && item.HasItemFlag(ItemFieldFlags.Wrapped))
                {
                    player.SendMailResult(0, MailResponseType.Send, MailResponseResult.CantSendWrappedCod);
                    return;
                }

                if (item.IsNotEmptyBag())
                {
                    player.SendMailResult(0, MailResponseType.Send, MailResponseResult.EquipError, InventoryResult.DestroyNonemptyBag);
                    return;
                }

                items.Add(item);
            }

            player.SendMailResult(0, MailResponseType.Send, MailResponseResult.Ok);

            player.ModifyMoney(-reqmoney);
            player.UpdateCriteria(CriteriaTypes.GoldSpentForMail, cost);

            bool needItemDelay = false;

            MailDraft draft = new MailDraft(packet.Info.Subject, packet.Info.Body);

            SQLTransaction trans = new SQLTransaction();

            if (!packet.Info.Attachments.Empty() || packet.Info.SendMoney > 0)
            {
                bool log = HasPermission(RBACPermissions.LogGmTrade);
                if (!packet.Info.Attachments.Empty())
                {
                    foreach (var item in items)
                    {
                        if (log)
                        {
                            Log.outCommand(GetAccountId(), "GM {0} ({1}) (Account: {2}) mail item: {3} (Entry: {4} Count: {5}) to player: {6} ({7}) (Account: {8})",
                                           GetPlayerName(), GetPlayer().GetGUID().ToString(), GetAccountId(), item.GetTemplate().GetName(), item.GetEntry(), item.GetCount(),
                                           packet.Info.Target, receiverGuid.ToString(), receiverAccountId);
                        }

                        item.SetNotRefundable(GetPlayer()); // makes the item no longer refundable
                        player.MoveItemFromInventory(item.GetBagSlot(), item.GetSlot(), true);

                        item.DeleteFromInventoryDB(trans);     // deletes item from character's inventory
                        item.SetOwnerGUID(receiverGuid);
                        item.SetState(ItemUpdateState.Changed);
                        item.SaveToDB(trans);                  // recursive and not have transaction guard into self, item not in inventory and can be save standalone

                        draft.AddItem(item);
                    }

                    // if item send to character at another account, then apply item delivery delay
                    needItemDelay = player.GetSession().GetAccountId() != receiverAccountId;
                }

                if (log && packet.Info.SendMoney > 0)
                {
                    Log.outCommand(GetAccountId(), "GM {0} ({1}) (Account: {{2}) mail money: {3} to player: {4} ({5}) (Account: {6})",
                                   GetPlayerName(), GetPlayer().GetGUID().ToString(), GetAccountId(), packet.Info.SendMoney, packet.Info.Target, receiverGuid.ToString(), receiverAccountId);
                }
            }

            // If theres is an item, there is a one hour delivery delay if sent to another account's character.
            uint deliver_delay = needItemDelay ? WorldConfig.GetUIntValue(WorldCfg.MailDeliveryDelay) : 0;

            // Mail sent between guild members arrives instantly
            Guild guild = Global.GuildMgr.GetGuildById(player.GetGuildId());

            if (guild)
            {
                if (guild.IsMember(receiverGuid))
                {
                    deliver_delay = 0;
                }
            }

            // don't ask for COD if there are no items
            if (packet.Info.Attachments.Empty())
            {
                packet.Info.Cod = 0;
            }

            // will delete item or place to receiver mail list
            draft.AddMoney((ulong)packet.Info.SendMoney).AddCOD((uint)packet.Info.Cod).SendMailTo(trans, new MailReceiver(receiver, receiverGuid.GetCounter()), new MailSender(player), string.IsNullOrEmpty(packet.Info.Body) ? MailCheckMask.Copied : MailCheckMask.HasBody, deliver_delay);

            player.SaveInventoryAndGoldToDB(trans);
            DB.Characters.CommitTransaction(trans);
        }
Ejemplo n.º 21
0
        public bool AddMember(ObjectGuid playerGuid)
        {
            string playerName;
            Class  playerClass;

            // Check if arena team is full (Can't have more than type * 2 players)
            if (GetMembersSize() >= GetArenaType() * 2)
            {
                return(false);
            }

            // Get player name and class either from db or ObjectMgr
            CharacterInfo characterInfo;
            Player        player = Global.ObjAccessor.FindPlayer(playerGuid);

            if (player)
            {
                playerClass = player.GetClass();
                playerName  = player.GetName();
            }
            else if ((characterInfo = Global.WorldMgr.GetCharacterInfo(playerGuid)) != null)
            {
                playerName  = characterInfo.Name;
                playerClass = characterInfo.ClassID;
            }
            else
            {
                return(false);
            }

            // Check if player is already in a similar arena team
            if ((player && player.GetArenaTeamId(GetSlot()) != 0) || Player.GetArenaTeamIdFromDB(playerGuid, GetArenaType()) != 0)
            {
                Log.outDebug(LogFilter.Arena, "Arena: {0} {1} already has an arena team of type {2}", playerGuid.ToString(), playerName, GetArenaType());
                return(false);
            }

            // Set player's personal rating
            uint personalRating = 0;

            if (WorldConfig.GetIntValue(WorldCfg.ArenaStartPersonalRating) > 0)
            {
                personalRating = WorldConfig.GetUIntValue(WorldCfg.ArenaStartPersonalRating);
            }
            else if (GetRating() >= 1000)
            {
                personalRating = 1000;
            }

            // Try to get player's match maker rating from db and fall back to config setting if not found
            PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_MATCH_MAKER_RATING);

            stmt.AddValue(0, playerGuid.GetCounter());
            stmt.AddValue(1, GetSlot());
            SQLResult result = DB.Characters.Query(stmt);

            uint matchMakerRating;

            if (!result.IsEmpty())
            {
                matchMakerRating = result.Read <ushort>(0);
            }
            else
            {
                matchMakerRating = WorldConfig.GetUIntValue(WorldCfg.ArenaStartMatchmakerRating);
            }

            // Remove all player signatures from other petitions
            // This will prevent player from joining too many arena teams and corrupt arena team data integrity
            //Player.RemovePetitionsAndSigns(playerGuid, GetArenaType());

            // Feed data to the struct
            ArenaTeamMember newMember = new ArenaTeamMember();

            newMember.Name             = playerName;
            newMember.Guid             = playerGuid;
            newMember.Class            = (byte)playerClass;
            newMember.SeasonGames      = 0;
            newMember.WeekGames        = 0;
            newMember.SeasonWins       = 0;
            newMember.WeekWins         = 0;
            newMember.PersonalRating   = (ushort)(uint)0;
            newMember.MatchMakerRating = (ushort)matchMakerRating;

            Members.Add(newMember);

            // Save player's arena team membership to db
            stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_ARENA_TEAM_MEMBER);
            stmt.AddValue(0, teamId);
            stmt.AddValue(1, playerGuid.GetCounter());
            DB.Characters.Execute(stmt);

            // Inform player if online
            if (player)
            {
                player.SetInArenaTeam(teamId, GetSlot(), GetArenaType());
                player.SetArenaTeamIdInvited(0);

                // Hide promote/remove buttons
                if (CaptainGuid != playerGuid)
                {
                    player.SetArenaTeamInfoField(GetSlot(), ArenaTeamInfoType.Member, 1);
                }
            }

            Log.outDebug(LogFilter.Arena, "Player: {0} [{1}] joined arena team type: {2} [Id: {3}, Name: {4}].", playerName, playerGuid.ToString(), GetArenaType(), GetId(), GetName());

            return(true);
        }
Ejemplo n.º 22
0
        void HandleSignPetition(SignPetition packet)
        {
            PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_PETITION_SIGNATURES);

            stmt.AddValue(0, packet.PetitionGUID.GetCounter());
            stmt.AddValue(1, packet.PetitionGUID.GetCounter());
            SQLResult result = DB.Characters.Query(stmt);

            if (result.IsEmpty())
            {
                Log.outError(LogFilter.Network, "Petition {0} is not found for player {1} {2}", packet.PetitionGUID.ToString(), GetPlayer().GetGUID().ToString(), GetPlayer().GetName());
                return;
            }

            ObjectGuid ownerGuid = ObjectGuid.Create(HighGuid.Player, result.Read <ulong>(0));
            ulong      signs     = result.Read <ulong>(1);

            if (ownerGuid == GetPlayer().GetGUID())
            {
                return;
            }

            // not let enemies sign guild charter
            if (!WorldConfig.GetBoolValue(WorldCfg.AllowTwoSideInteractionGuild) && GetPlayer().GetTeam() != Global.CharacterCacheStorage.GetCharacterTeamByGuid(ownerGuid))
            {
                Guild.SendCommandResult(this, GuildCommandType.CreateGuild, GuildCommandError.NotAllied);
                return;
            }

            if (GetPlayer().GetGuildId() != 0)
            {
                Guild.SendCommandResult(this, GuildCommandType.InvitePlayer, GuildCommandError.AlreadyInGuild_S, GetPlayer().GetName());
                return;
            }
            if (GetPlayer().GetGuildIdInvited() != 0)
            {
                Guild.SendCommandResult(this, GuildCommandType.InvitePlayer, GuildCommandError.AlreadyInvitedToGuild_S, GetPlayer().GetName());
                return;
            }

            // Client doesn't allow to sign petition two times by one character, but not check sign by another character from same account
            // not allow sign another player from already sign player account
            stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_PETITION_SIG_BY_ACCOUNT);
            stmt.AddValue(0, GetAccountId());
            stmt.AddValue(1, packet.PetitionGUID.GetCounter());
            result = DB.Characters.Query(stmt);

            PetitionSignResults signResult = new PetitionSignResults();

            signResult.Player = GetPlayer().GetGUID();
            signResult.Item   = packet.PetitionGUID;

            if (!result.IsEmpty())
            {
                signResult.Error = PetitionSigns.AlreadySigned;

                // close at signer side
                SendPacket(signResult);
                return;
            }

            stmt = DB.Characters.GetPreparedStatement(CharStatements.INS_PETITION_SIGNATURE);
            stmt.AddValue(0, ownerGuid.GetCounter());
            stmt.AddValue(1, packet.PetitionGUID.GetCounter());
            stmt.AddValue(2, GetPlayer().GetGUID().GetCounter());
            stmt.AddValue(3, GetAccountId());
            DB.Characters.Execute(stmt);

            Log.outDebug(LogFilter.Network, "PETITION SIGN: {0} by player: {1} ({2} Account: {3})", packet.PetitionGUID.ToString(), GetPlayer().GetName(), GetPlayer().GetGUID().ToString(), GetAccountId());

            signResult.Error = PetitionSigns.Ok;

            // close at signer side
            SendPacket(signResult);

            Item item = _player.GetItemByGuid(packet.PetitionGUID);

            if (item != null)
            {
                item.SetPetitionNumSignatures((uint)signs);
                item.SetState(ItemUpdateState.Changed, _player);
            }

            // update for owner if online
            Player owner = Global.ObjAccessor.FindPlayer(ownerGuid);

            if (owner)
            {
                owner.SendPacket(signResult);
            }
        }
Ejemplo n.º 23
0
 public BattlePet GetPet(ObjectGuid guid)
 {
     return(_pets.LookupByKey(guid.GetCounter()));
 }
Ejemplo n.º 24
0
 public Group GetGroupByGUID(ObjectGuid groupId)
 {
     return(GroupStore.LookupByKey(groupId.GetCounter()));
 }