コード例 #1
0
ファイル: UGCHandler.cs プロジェクト: Etchavious/MapleServer2
    private static void HandleConfirmationPacket(GameSession session, PacketReader packet)
    {
        UGCType type = (UGCType)packet.ReadByte();

        packet.ReadByte();
        packet.ReadByte();
        packet.ReadInt();
        long accountId   = packet.ReadLong();
        long characterId = packet.ReadLong();

        packet.ReadInt();
        long   ugcUid  = packet.ReadLong();
        string ugcGuid = packet.ReadUnicodeString();

        Player player = session.Player;

        if (accountId != player.Account.Id || characterId != player.CharacterId || ugcUid == 0)
        {
            return;
        }

        UGC ugc = DatabaseManager.UGC.FindByUid(ugcUid);

        if (ugc is null || ugc.Guid != Guid.Parse(ugcGuid))
        {
            return;
        }

        session.Send(UGCPacket.SetUGCUrl(ugc));

        switch (type)
        {
        case UGCType.Furniture or UGCType.Item or UGCType.Mount:
            Item item = DatabaseManager.Items.FindByUgcUid(ugcUid);
            if (item is null)
            {
                return;
            }

            item.SetMetadataValues();

            player.Inventory.AddItem(session, item, true);
            switch (item.Ugc.Type)
            {
            case UGCType.Furniture:
                session.Send(UGCPacket.UpdateUGCFurnishing(player.FieldPlayer, item));
                break;

            case UGCType.Item:
                session.Send(UGCPacket.UpdateUGCItem(player.FieldPlayer, item));
                break;

            case UGCType.Mount:
                session.Send(UGCPacket.UpdateUGCMount(player.FieldPlayer, item));
                break;
            }

            break;

        case UGCType.GuildEmblem:
        {
            Guild guild = GameServer.GuildManager.GetGuildById(player.Guild.Id);

            guild.Emblem = ugc.Url;
            DatabaseManager.Guilds.UpdateEmblem(guild.Id, ugc.Url);

            guild.BroadcastPacketGuild(GuildPacket.ChangeEmblemUrl(ugc.Url));
            guild.BroadcastPacketGuild(GuildPacket.GuildNoticeEmblemChange(player.Name, ugc.Url));
            break;
        }

        case UGCType.GuildBanner:
        {
            Guild guild = GameServer.GuildManager.GetGuildById(player.Guild.Id);

            UGC oldUGCBanner = guild.Banners.FirstOrDefault(x => x.GuildPosterId == ugc.GuildPosterId);
            if (oldUGCBanner is not null)
            {
                guild.Banners.Remove(oldUGCBanner);
                DatabaseManager.UGC.Delete(oldUGCBanner.Uid);
            }

            guild.Banners.Add(ugc);
            DatabaseManager.Guilds.UpdateBanners(guild.Id, guild.Banners);

            guild.BroadcastPacketGuild(GuildPacket.UpdateBannerUrl(player, ugc));
            break;
        }

        case UGCType.Banner:
            UGCBanner ugcBanner = GameServer.UGCBannerManager.UpdateBannerSlots(ugc);
            if (ugcBanner is null)
            {
                return;
            }

            session.Send(UGCPacket.UpdateUGCBanner(ugcBanner));
            // TrophyManager.OnReserveBanner();
            break;
        }
    }