Skip to content

Commit

Permalink
fix(cosmetics): allow outfit skin updates
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzeva committed Dec 21, 2024
1 parent 8bb5388 commit de6c0b0
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/handlers/c2u/cosmetic/outfit/c2uCosmeticOutfitSkinUpdate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { and, eq } from "drizzle-orm";
import { db } from "~/db/index.js";
import { outfits } from "~/db/schema.js";
import { Handler } from "~/handlers/index.js";
import cosmeticOutfitSkinUpdate from "~/protocol/packets/cosmetic/outfit/cosmeticOutfitSkinUpdate.js";

export default {
def: cosmeticOutfitSkinUpdate,
async handle(client, packet) {
const { a: outfitId, b: skinTexture, c: skinId } = packet.body!;
console.log(skinId, skinTexture);

const outfit = (
await db
.select()
.from(outfits)
.where(
and(eq(outfits.id, outfitId), eq(outfits.ownerId, client.profile.id))
)
.limit(1)
)[0];

if (!outfit)
return await client.sendResponse(packet, false, "Outfit not found");

await db
.update(outfits)
.set({ skinId, skinTexture })
.where(
and(eq(outfits.id, outfitId), eq(outfits.ownerId, client.profile.id))
);

await client.sendResponse(packet);

await client.sendOutfitToSubscribers();

return { cancelled: true };
},
} as Handler<typeof cosmeticOutfitSkinUpdate>;
3 changes: 3 additions & 0 deletions src/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import c2uCosmeticOutfitDelete from "./c2u/cosmetic/outfit/c2uCosmeticOutfitDele
import c2uCosmeticOutfitEquippedCosmeticsUpdate from "./c2u/cosmetic/outfit/c2uCosmeticOutfitEquippedCosmeticsUpdate.js";
import c2uCosmeticOutfitNameUpdate from "./c2u/cosmetic/outfit/c2uCosmeticOutfitNameUpdate.js";
import c2uCosmeticOutfitSelect from "./c2u/cosmetic/outfit/c2uCosmeticOutfitSelect.js";
import c2uCosmeticOutfitSkinUpdate from "./c2u/cosmetic/outfit/c2uCosmeticOutfitSkinUpdate.js";
import c2uCosmeticOutfitUpdateFavoriteState from "./c2u/cosmetic/outfit/c2uCosmeticOutfitUpdateFavoriteState.js";
import c2uModsAnnounceHandler from "./c2u/mod/c2uModsAnnounceHandler.js";
import c2uSubscriptionUpdatePacket from "./c2u/subscription/c2uSubscriptionUpdatePacket.js";
Expand Down Expand Up @@ -43,6 +44,8 @@ export const clientToUpstreamHandlers = [
c2uCosmeticOutfitCreate,
c2uCosmeticOutfitSelect,
c2uCosmeticOutfitNameUpdate,
c2uCosmeticOutfitSkinUpdate,

c2uCosmeticOutfitUpdateFavoriteState,
c2uCosmeticEmoteWheelUpdate,
c2uCosmeticEmoteWheelSelect,
Expand Down
2 changes: 2 additions & 0 deletions src/protocol/packets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import cosmeticOutfitNameUpdate from "./packets/cosmetic/outfit/cosmeticOutfitNa
import cosmeticOutfitPopulate from "./packets/cosmetic/outfit/cosmeticOutfitPopulate.js";
import cosmeticOutfitSelect from "./packets/cosmetic/outfit/cosmeticOutfitSelect.js";
import cosmeticOutfitSelectedResponse from "./packets/cosmetic/outfit/cosmeticOutfitSelectedResponse.js";
import cosmeticOutfitSkinUpdate from "./packets/cosmetic/outfit/cosmeticOutfitSkinUpdate.js";
import cosmeticOutfitUpdateFavoriteState from "./packets/cosmetic/outfit/cosmeticOutfitUpdateFavoriteState.js";
import serverCosmeticAnimationTrigger from "./packets/cosmetic/serverCosmeticAnimationTrigger.js";
import modsAnnounce from "./packets/mod/modsAnnounce.js";
Expand Down Expand Up @@ -45,6 +46,7 @@ export const packetDefinitions: PacketDefinition<ZodObject<any, any, any>>[] = [
cosmeticOutfitCreate,
cosmeticOutfitSelect,
cosmeticOutfitNameUpdate,
cosmeticOutfitSkinUpdate,
cosmeticOutfitUpdateFavoriteState,
cosmeticOutfitSelectedResponse,
cosmeticEmoteWheelPopulate,
Expand Down
13 changes: 13 additions & 0 deletions src/protocol/packets/cosmetic/outfit/cosmeticOutfitSkinUpdate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { z } from "zod";
import { PacketDefinition } from "~/protocol/packets.js";

const schema = z.object({
a: z.string(), // outfit id
b: z.string().nullish(), // skin texture
c: z.string().nullish(), // skin id
});

export default {
className: "cosmetic.outfit.ClientCosmeticOutfitSkinUpdatePacket",
body: schema,
} as PacketDefinition<typeof schema>;

0 comments on commit de6c0b0

Please sign in to comment.