Trades
packets6 packets
Trading (trade.TradeXtCommManager, answered in gui.TradeManager). A trade is one player asking for one of another's items and offering some of their own:
- The one asking sends
tiwith action 0; the other is senttiwith status 0, the offer. - The other accepts or declines with action 1. A decline ends the trade with a status of 2 or more; an accept sends status 1 with stage 0, asking for a last confirmation (action 3).
- When it is done, status 1 with a stage other than 0 lists what each side received and lost.
Items are named by their place in the owner's inventory (invIdx). Clothing, den items and pets are listed apart, each in its own layout; the same item is written in a different order in different messages, which each reader below follows exactly.
Hearing and sending packets
What the game sends is heard on phantom.packets.client, and what the server sends on phantom.packets.server. watch hears a packet after it has gone through; on hears it first and may change or drop it; send sends one to that end. See Packets.
Overview
| Packet | Command | Way | What it is |
|---|---|---|---|
TradeListRequest | tl | game → server | The player asks for someone’s trade list. |
TradeList | tl | server → game | The server sends someone’s trade list. |
TradeListChange | ts | game → server | The player changes their trade list. |
TradeBusy | tb | game → server | The player starts or stops being busy with a trade. |
TradeActionRequest | ti | game → server | The player asks for a trade, answers one, withdraws or confirms. |
TradeResult | ti | server → game | Someone offers a trade, or a trade is accepted, done or ends. |
TradeListRequest
Asks for someone's trade list (sendTradeListRequest, from the buddy card).
Fields
| Field | Type | |
|---|---|---|
userName | string | The player whose trade list to send, by username. |
room | number | The room the message was sent in, as the SmartFox room id; -1 when it names none. |
Example
// Each time the game sends it to the server, after it has gone through.
const stop = phantom.packets.client.watch(packets.TradeListRequest, (packet) => {
console.log(packet.userName);
});TradeList
Someone's trade list (TradeManager.onTradeListReceived): their username, then clothing, den items and pets, each a count and that many items.
clothing <defId>%<invIdx>%<color> den item <defId>%<invIdx>%<version>%<approved>%<uniqueImageId>%<creatorDbId>%<creatorUuid> pet <defId>%<invIdx>%<createdAt>%<bits1>%<bits2>%<bits3>%<name>%<trait>%<toy>%<food>
For the player's own list the client keeps only each item's place, skipping the same fields.
Fields
| Field | Type | |
|---|---|---|
userName | string | The player whose trade list it is, by username. |
clothing | { defId: number; invIdx: number; color: number; }[] | The clothing on the list, after its count: defId, invIdx and color each. |
den | { version: number; approved: boolean; uniqueImageId: string; creatorDbId: number; creatorUuid: string; defId: number; invIdx: number; }[] | The den items on the list, after their count (TradeDenItem). |
pets | { traitDefId: number; toyDefId: number; foodDefId: number; defId: number; invIdx: number; createdAt: number; bits: [number, number, number]; name: string; }[] | The pets on the list, after their count (TradePet). |
room | number | The room the message was sent in, as the SmartFox room id; -1 when it names none. |
Example
// Each time the server sends it to the game, after it has gone through.
const stop = phantom.packets.server.watch(packets.TradeList, (packet) => {
console.log(packet.userName, packet.clothing, packet.den);
});TradeListChange
Changes the player's trade list (sendTradeSetRequest, from TradeManager.changeTradeList): the items taken off, then the items put on, each a count and <itemType>%<invIdx> pairs.
Fields
| Field | Type | |
|---|---|---|
removed | InventoryRef[] | The items taken off the list, after their count. |
added | InventoryRef[] | The items put on the list, after their count. |
room | number | The room the message was sent in, as the SmartFox room id; -1 when it names none. |
Example
// Each time the game sends it to the server, after it has gone through.
const stop = phantom.packets.client.watch(packets.TradeListChange, (packet) => {
console.log(packet.removed, packet.added);
});TradeBusy
Whether the player is busy trading (sendTradeBusyRequest): set when a trade window opens, and cleared whenever one closes.
Fields
| Field | Type | |
|---|---|---|
busy | boolean | The player is busy trading: true as a trade window opens, false as one closes. |
room | number | The room the message was sent in, as the SmartFox room id; -1 when it names none. |
Example
// Each time the game sends it to the server, after it has gone through.
const stop = phantom.packets.client.watch(packets.TradeBusy, (packet) => {
console.log(packet.busy);
});TradeActionRequest
A trade action (TradeXtCommManager), told apart by its first field:
0 %<userName>%<itemType>%<invIdx>%<clothing>%<den>%<audio>%<pets>%<invIdx>... sendTradeItemsRequest 1 %<response> sendTradeItemAcceptOrReject 2 sendTradeItemCancel 3 %<confirm> sendConfirmTrade
In a request, den counts the den items that are not audio items and audio the rest; the places that follow are the clothing's, then every den item's, then the pets'.
Fields
| Field | Type | |
|---|---|---|
action | "request" | "respond" | "cancel" | "confirm" | Asks for someone's item, offering some of the player's own. |
room | number | The room the message was sent in, as the SmartFox room id; -1 when it names none. |
Example
// Each time the game sends it to the server, after it has gone through.
const stop = phantom.packets.client.watch(packets.TradeActionRequest, (packet) => {
console.log(packet.action);
});TradeResult
What happens to a trade (TradeXtCommManager.handleXtReply, TradeManager.onTradeItemsResponse), by its status:
- 0, an offer (
displayTradeRequested):<userName>%<moderation>%<wantedKind>%<wantedInvIdx>%<clothing>%<den>%<pets>%...then clothing as<defId>%<color>, den items as<defId>%<version>%<approved>%<uniqueImageId>%<creatorDbId>%<creatorUuid>and pets as<createdAt>%<defId>%<invIdx>%<bits1>%<bits2>%<bits3>%<trait>%<toy>%<food>%<name>. - 1, accepted: a stage; 0 asks for confirmation (
displayTradeConfirmPopup). Otherwise the trade is done (displayTradeDone): a count of received items, each its type (0 clothing<defId>%<invIdx>%<color>, 1 den item<invIdx>%<defId>%<version>%<approved>%<uniqueImageId>%<creatorDbId>%<creatorUuid>, 2 pet<createdAt>%<invIdx>%<defId>%<bits1>%<bits2>%<bits3>%<trait>%<toy>%<food>%<name>), then a count of removed items as<type>%<invIdx>. - 6, closed: nothing more is read.
- 7, on another server: the room to join to reach the other player.
- Any other:
<userName>%<moderation>, for the message shown.
The client reads the moderation flag of an offer nowhere; it is named for the same field of the failures, where it decides whether the username is shown. Fields the client does not read are kept in extra.
Fields
| Field | Type | |
|---|---|---|
kind | "failed" | "confirm" | "offer" | "completed" | "closed" | "different-server" | What happened to the trade, which decides the other fields. |
status | number | The status the server sent (TRADE_STATUS). |
room | number | The room the message was sent in, as the SmartFox room id; -1 when it names none. |
Example
// Each time the server sends it to the game, after it has gone through.
const stop = phantom.packets.server.watch(packets.TradeResult, (packet) => {
console.log(packet.kind, packet.status);
});