Refer a friend
packets8 packets
Refer a friend (buddy.ReferAFriendXtCommManager): the player's own referral code, the players who joined with it, and, for a new account, naming the player who referred them. The client asks from the buddy list's refer a friend and "how did you hear about us" buttons (buddy.ReferAFriend, buddy.HowDidYouHear, buddy.BuddyList). Every answer opens with a status, where 1 is success.
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 |
|---|---|---|---|
ReferralCodeRequest | refc | game → server | The player asks for their refer a friend code. |
ReferralCode | refc | server → game | The server sends the player’s refer a friend code. |
ReferralHasAssociateRequest | refh | game → server | The player asks whether they have named who referred them. |
ReferralHasAssociate | refh | server → game | The server says whether the player has named who referred them. |
ReferralAssociate | refa | game → server | The player names who referred them. |
ReferralAssociateResult | refa | server → game | The server says whether the player’s referrer was recorded. |
ReferralListRequest | refr | game → server | The player asks for the players who joined with their code. |
ReferralList | refr | server → game | The server sends the players who joined with the player’s code. |
ReferralCodeRequest
Asks for the player's referral code (sendCodeRequest, from ReferAFriend.onPopupLoaded).
Fields
| Field | Type | |
|---|---|---|
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.ReferralCodeRequest, (packet) => {
console.log('referral.code-request');
});ReferralCode
The player's referral code (codeRequestResponse, read by ReferAFriend.onCodeRequestComplete):
%xt%refc%<room>%<status>%<code>%
The client keeps the code (ReferAFriend.code) and builds the link it copies from it, https://buddy.animaljam.com/<code>. Any status but 1 shows a popup that something went wrong.
Fields
| Field | Type | |
|---|---|---|
status | number | 1 when there is a code; anything else is a failure. |
code | string | null | The code, or null when the server sent none. |
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.ReferralCode, (packet) => {
console.log(packet.status, packet.code);
});ReferralHasAssociateRequest
Asks whether the player has already named who referred them (sendHasReferralAssociate), which BuddyList asks as the buddy list opens for an account three days old or younger.
Fields
| Field | Type | |
|---|---|---|
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.ReferralHasAssociateRequest, (packet) => {
console.log('referral.has-associate-request');
});ReferralHasAssociate
Whether the player has named who referred them (referralHasAssociateResponse, read by BuddyList.onHasReferralAssociationResponse): 1 shows the refer a friend button, anything else the "how did you hear about us" button that names a referrer.
Fields
| Field | Type | |
|---|---|---|
status | number | 1 when the player already has a referrer; anything else when they may still name one. |
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.ReferralHasAssociate, (packet) => {
console.log(packet.status);
});ReferralAssociate
Names the player who referred this one (sendReferralAssociation, from HowDidYouHear.onSubmitBtn). The client sends it only for a name of two characters or more that is a valid username and not the player's own.
Fields
| Field | Type | |
|---|---|---|
userName | string | The referrer's username, as the player typed it. |
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.ReferralAssociate, (packet) => {
console.log(packet.userName);
});ReferralAssociateResult
Whether the referrer was recorded (referralAssociationResponse, read by HowDidYouHear.onReferralAssociationComplete): 1 recorded (translation 32508), -1 refused with a message of its own (translation 32507), and anything else a failure (translation 22626).
Fields
| Field | Type | |
|---|---|---|
status | number | 1 recorded, -1 refused, anything else a failure. |
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.ReferralAssociateResult, (packet) => {
console.log(packet.status);
});ReferralListRequest
Asks for the players who joined with the player's code (sendReferralReferralsRequest). The "my referrals" panel asks for page 1 in pages of 8 (ReferAFriend.buildReferralsList), then the next page each time it is scrolled to the end.
Fields
| Field | Type | |
|---|---|---|
page | number | The page wanted, from 1. |
pageSize | number | How many referrals make a page. |
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.ReferralListRequest, (packet) => {
console.log(packet.page, packet.pageSize);
});ReferralList
The players who joined with the player's code (referralReferralsResponse, read by ReferAFriend.onReferralsListResponse):
%xt%refr%<room>%<status>%{"referrals":[{"name":...,"moderatedUserName":..., "namebarData":...,"account_type":...}]}%
The list is JSON; the client reads it only for status 1, and asks for more while it holds at least page * pageSize of them.
Fields
| Field | Type | |
|---|---|---|
status | number | 1 when there is a list; anything else is a failure, and the client asks for no more. |
referrals | Referral[] | null | The referrals, read from the JSON; null when the server sent none. |
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.ReferralList, (packet) => {
console.log(packet.status, packet.referrals);
});