Club Penguin:Client

From HashNet Wiki
Jump to: navigation, search
Club Penguin Flash Client shell.swf ActionScript

The Club Penguin Client is the original client used to play Club Penguin. Written in Adobe Flash with ActionScript.

Useful ActionScript code snippets

Sending packets

Sometimes sending packets can be useful, for example setting up encrypted chat, or requesting captcha verification, etc.

This can be achieved through airtower.swf using the following snippet:

// Send "Hello World!" to chat.

var AIRTOWER = _global.getCurrentAirtower();
var extension = AIRTOWER.PLAY_EXT; // "s"
var command = AIRTOWER.MESSAGE_HANDLER + "#" + AIRTOWER.SEND_MESSAGE; // "m#sm"
var message = "Hello World!";

//AIRTOWER.send("s","m#sm",[message],"str",-1);
AIRTOWER.send(extension, command, [message], "str", -1);

The resulting packet looks like: %xt%s%m#sm%356%1316248%Hello World!%

Handling packets

Here's how to handle an incoming packet by adding a listener using airtower.swf:

// Define a function to handle the airtower callback
function handleSpecial(data) {
    // Do something.
    // 'data' is an array of data
    // from the server.
}

var AIRTOWER = _global.getCurrentAirtower();
var SHELL = _global.getCurrentShell();

// Add listener
AIRTOWER.addListener("specialcmd",handleSpecial);

Useful variable references

Usually a local object of shell.swf, interface.swf, and airtower.swf is referenced as:

var SHELL = _global.getCurrentShell();
var ENGINE = _global.getCurrentEngine();
var INTERFACE = _global.getCurrentInterface();
var AIRTOWER = _global.getCurrentAirtower();

Interface chat restriction

In interface.swf:

if (isModerator()) {
    DOCK.chat_mc.chat_input.restrict = "a-z A-Z 0-9 z-A ! ?!\'/\"??\\\\[email protected]#$%\\^&*()\\-+_=[]{}<>\\|:;,.\n\t";
} else {
    DOCK.chat_mc.chat_input.restrict = "a-z A-Z 0-9 z-A ! ?!\'/\"??,.\n\t";
}

Use a swf-dependency from shell.swf

This calls the sendEncryptedMessage(txt) function inside of the chatenc.swf dependency loaded from the /v2/client/dependencies.json file.

this.dependencyHolder.chatenc.sendEncryptedMessage(txt);

Get player details

Get local player details as an Object.

var SHELL = _global.getCurrentShell();
var obj = SHELL.getMyPlayerObject();
var head = obj.head;
var face = obj.face;
var neck = obj.neck;
var body = obj.body;
var hand = obj.hand;
var feet = obj.feet;
var color_id = obj.colour_id;
var nickname = obj.nickname;
var room_id = SHELL.getCurrentRoomId();


ActionScript functions/variables (airtower.swf)

Function Description
addListener(type, func, scope) Add a handler, type being the packet type, normally "s", func being the callback function.
removeListener(type, func) Remove a handler.
connectToRedemption(server_ip, server_port, connect_to_world_response) Connect to a redemption server.
connectToWorld(server_ip, server_port, connect_to_world_response) Connect to a world server.
send(extension, command, arr, type, room_id) Send an XT packet.
disconnect() Disconnect from the current server.
getLoginHash() Return the hash to be used for the login server.
hex_md5(str) Return a MD5 hash of str.
encryptPassword(pass) Return a hashed string of pass.


STRING_TYPE Value: "str".
XML_TYPE Value: "xml".
PLAY_EXT Value: "s".
GAME_EXT Value: "z".
NAVIGATION Value: "j".
PLAYER_HANDLER Value: "u".
ITEM_HANDLER Value: "i".
IGNORE_HANDLER Value: "n".
BUDDY_HANDLER Value: "b".
TOY_HANDLER Value: "t".
TABLE_HANDLER Value: "a".
IGLOO_HANDLER Value: "g".
PET_HANDLER Value: "p".
MESSAGE_HANDLER Value: "m".
MAIL_HANDLER Value: "l".
SURVEY_HANDLER Value: "e".
WADDLE Value: "w".
SETTING_HANDLER Value: "s".
MODERATION_HANDLER Value: "o".
NINJA_HANDLER Value: "ni".
ROOM_HANDLER Value: "r".
REDEMPTION Value: "red".
REDEMPTION_JOIN_WORLD Value: "rjs".
HANDLE_LOGIN Value: "l".
HANDLE_ALERT Value: "a".
HANDLE_ERROR Value: "e".
GET_BUDDY_LIST Value: "gb".
GET_IGNORE_LIST Value: "gn".
GET_PLAYER Value: "gp".
GET_ROOM_LIST Value: "gr".
GET_TABLE Value: "gt".
JOIN_WORLD Value: "js".
JOIN_ROOM Value: "jr".
REFRESH_ROOM Value: "grs".
LOAD_PLAYER Value: "lp".
ADD_PLAYER Value: "ap".
REMOVE_PLAYER Value: "rp".
UPDATE_PLAYER Value: "up".
PLAYER_MOVE Value: "sp".
PLAYER_FRAME Value: "sf".
PLAYER_ACTION Value: "sa".
OPEN_BOOK Value: "at".
CLOSE_BOOK Value: "rt".
THROW_BALL Value: "sb".
JOIN_GAME Value: "jg".
SEND_MESSAGE Value: "sm".
SEND_BLOCKED_MESSAGE Value: "mm".
SEND_EMOTE Value: "se".
SEND_JOKE Value: "sj".
SEND_SAFE_MESSAGE Value: "ss".
SEND_LINE_MESSAGE Value: "sl".
SEND_QUICK_MESSAGE Value: "sq".
SEND_TOUR_GUIDE_MESSAGE Value: "sg".
COIN_DIG_UPDATE Value: "cdu".
GET_INVENTORY_LIST Value: "gi".
MAIL_START_ENGINE Value: "mst".
GET_MAIL Value: "mg".
SEND_MAIL Value: "ms".
RECEIVE_MAIL Value: "mr".
DELETE_MAIL Value: "md".
DELETE_MAIL_FROM_PLAYER Value: "mdp".
GET_MAIL_DETAILS Value: "mgd".
MAIL_CHECKED Value: "mc".
GAME_OVER Value: "zo".
BUY_INVENTORY Value: "ai".
CHECK_INVENTORY Value: "qi".
ADD_IGNORE Value: "an".
REMOVE_IGNORE Value: "rn".
REMOVE_BUDDY Value: "rb".
REQUEST_BUDDY Value: "br".
ACCEPT_BUDDY Value: "ba".
BUDDY_ONLINE Value: "bon".
BUDDY_OFFLINE Value: "bof".
FIND_BUDDY Value: "bf".
GET_PLAYER_OBJECT Value: "gp".
REPORT_PLAYER Value: "r".
UPDATE_PLAYER_COLOUR Value: "upc".
UPDATE_PLAYER_HEAD Value: "uph".
UPDATE_PLAYER_FACE Value: "upf".
UPDATE_PLAYER_NECK Value: "upn".
UPDATE_PLAYER_BODY Value: "upb".
UPDATE_PLAYER_HAND Value: "upa".
UPDATE_PLAYER_FEET Value: "upe".
UPDATE_PLAYER_FLAG Value: "upl".
UPDATE_PLAYER_PHOTO Value: "upp".
UPDATE_PLAYER_REMOVE Value: "upr".
GET_FURNITURE_LIST Value: "gf".
UPDATE_ROOM Value: "up".
UPDATE_FLOOR Value: "ag".
UPDATE_IGLOO_TYPE Value: "au".
UNLOCK_IGLOO Value: "or".
LOCK_IGLOO Value: "cr".
UPDATE_IGLOO_MUSIC Value: "um".
GET_IGLOO_DETAILS Value: "gm".
JOIN_PLAYER_IGLOO Value: "jp".
SAVE_IGLOO_FURNITURE Value: "ur".
GET_IGLOO_LIST Value: "gr".
BUY_FURNITURE Value: "af".
SEND_IGLOO Value: "sig".
GET_OWNED_IGLOOS Value: "go".
ACTIVATE_IGLOO Value: "ao".
GET_MY_PLAYER_PUFFLES Value: "pgu".
GET_PLAYER_PUFFLES Value: "pg".
PUFFLE_FRAME Value: "ps".
PUFFLE_MOVE Value: "pm".
REST_PUFFLE Value: "pr".
BATH_PUFFLE Value: "pb".
PLAY_PUFFLE Value: "pp".
FEED_PUFFLE Value: "pf".
WALK_PUFFLE Value: "pw".
TREAT_PUFFLE Value: "pt".
INTERACTION_PLAY Value: "ip".
INTERACTION_REST Value: "ir".
INTERACTION_FEED Value: "if".
PUFFLE_INIT_INTERACTION_PLAY Value: "pip".
PUFFLE_INIT_INTERACTION_REST Value: "pir".
ADOPT_PUFFLE Value: "pn".
UPDATE_TABLE Value: "ut".
GET_TABLE_POPULATION Value: "gt".
JOIN_TABLE Value: "jt".
LEAVE_TABLE Value: "lt".
UPDATE_WADDLE Value: "uw".
GET_WADDLE_POPULATION Value: "gw".
JOIN_WADDLE Value: "jw".
LEAVE_WADDLE Value: "lw".
START_WADDLE Value: "sw".
SEND_WADDLE Value: "jx".
SPY_PHONE_REQUEST Value: "spy".
HEARTBEAT Value: "h".
TIMEOUT Value: "t".
MODERATOR_ACTION Value: "ma".
KICK Value: "k".
MUTE Value: "m".
BAN Value: "b".
SEND_MASCOT_MESSAGE Value: "sma".
DONATE Value: "dc".
POLL Value: "spl".
CONNECTION_LOST Value: "con".
GET_CARDS Value: "gcd".
GET_NINJA_LEVEL Value: "gnl".
GET_FIRE_LEVEL Value: "gfl".
GET_WATER_LEVEL Value: "gwl".
GET_NINJA_RANKS Value: "gnr".
GET_LAST_REVISION Value: "glr".
LOGIN_ZONE Value: "w1".
SERVER_ZONE Value: "w1".
server_ip
server_port
username
password
playerId
is_logged_in
server
isRedemption


ActionScript functions/variables (interface.swf)

Function Description
getPlayerId() Alias to SHELL.getMyPlayerId();
getPlayerNickname() Alias to SHELL.getMyPlayerNickname();
getCoins() Alias to SHELL.getMyPlayerTotalCoins();
isMember() Alias to SHELL.isMyPlayerMember();
isModerator() Returns a boolean, true if the player is a moderator, otherwise false.
isSafeMode() Alias to SHELL.isMyPlayerSafeMode();
isSecretAgent() Alias to SHELL.isMyPlayerSecretAgent();
isItemInInventory(item_id) Alias to SHELL.isItemInMyInventory(item_id);
isBuddy(player_id) Alias to SHELL.isPlayerBuddyById(player_id);
isBuddyOnline(player_id) Alias to SHELL.isBuddyOnlineById(player_id);
isIgnored(player_id) Alias to SHELL.isPlayerIgnoredById(player_id);
getBuddyList()
getIgnoreList()
getItemList() Alias to SHELL.getMyInventoryArray();
getLog() Alias to SHELL.getChatLog();
getCurrentNews()
sendJoke() Properly send a joke to the server and show it on the client locally as well.
findPlayer(playerID) Alias to SHELL.getPlayerLocationById(playerID); with a call to showPrompt("wait");
showPrompt(style, message, file, positiveSelectionCallback, negativeSelectionCallback) Possible style's ["question", "ok", "ok_big", "wait", "game", "igloo", "shop", "coin", "input", "warn", "AS3_error"]
showScopedPrompt(style, message, file, sendFunction, scope) Possible style's ["question", "ok", "wait", "game", "igloo", "shop", "coin", "input", "warn"]
isItemOnPlayer(itemID) Return boolean true if the itemID is on the players: colour_id, head, face, neck, body, hand, feet, flag_id, or photo_id.
message_separator By default set to ": ".
phone_list A list of available places the EPF phone can teleport you to. By default set to ["town","coffee","book","dance","lounge","shop","village","lodge","attic","mtn","plaza","pet","stage","pizza","beach","light","beacon","dock","forts","rink","boiler","berg","cave","mine","shack","forest","cove"].

ActionScript functions/variables (shell.swf)

Example usage:

var SHELL = _global.getCurrentShell();
var my_id = SHELL.getMyPlayerId();
Function Description
getMyPlayerObject() Returns a object containing basic player information. Such as head, face, neck, body, hand, feet, colour_id, nickname, username, player_id, flag_id, photo_id, x, y, frame, is_member, total_membership_days.
getBasePath() Returns a object of the base path of the game files. (https://media1.cpcontinued.com/v2/)
getClientPath() Returns a object of the base path of the game files. (https://media1.cpcontinued.com/v2/client)
getLocalizedString(str) Returns a localized string of an index, for example; "boiler" -> "Boiler Room". However for an unknown string; "abcd" -> "**abcd**" is returned.
getPenguinStandardTime() Return the current time in penguin standard time.
showErrorPrompt(window_size, message, button_label, button_action, error_code) Display an error prompt to the screen with a callback function call to button_action.
closeErrorPrompt() Gracefully clode the current error prompt. (calls hideErrorPrompt()).
showLoading(message, listener) Show the loading screen with the message specified.
showLoadingProgress(message, bytesLoaded, bytesTotal) Show the loading screen with a progress bar and a message specified.
hideLoading() Gracefully close the current loading screen.
loadSWF(mc, path, initFunction, startFunction, errorFunction, progressFunction, options)
isValidString(txt) Returns true if txt string length is greater than 1, not empty, not undefined, not null, and not "undefined".
getRandomFromArray(how_many, in_array) Return how_many number of elements from inside in_array in a random order.
randBetween(from, to) Return a random number from a minimum of from and a maximum of to inclusive.
ucFirst(str) Return a string upper-casing the first character.
getCurrentRoomId() Return the current room id.
getCurrentServerRoomId() Return the current server room id.
startMusicById(music_id) Start playing background music from the int music_id representing a swf file name. For example 950 is a town party theme.
startRoomMusic() Start playing the background music of the current room the player is in.
stopMusic() Stop music playing.
sendJoinRoom(room_name, xpos, ypos) Send a join room request by room_name, to the positions xpos and ypos.
getPostcardCrumbs()
getPostcardCategoryList()
getPostcardCount()
getMyPlayerHex() Get player color ID as hex.
getMyPlayerId() Get player ID (initialized after successful login)
sendThrowBall(xpos, ypos) Send a snowball throw to xpos and ypos.
getMyPlayerTotalCoins()
isMyPlayerSafeMode()
getMyPlayerUsername()
getMyPlayerDaysOld()
getMinutesPlayed()
isEPFAgent()
isEPFRecruit()
getMyInventoryList()
isItemInMyInventory()
addItemToInventory(itemID)
removeItemFromInventory(itemID)
getPlayerHexFromId(id) Get hex color from color id.
unlockIgloo() Make player igloo to public.
lockIgloo() Make player igloo private.
getIsRoomIgloo() Return boolean if the current room is an igloo.
getCurrentIglooType()
getCurrentIglooFloorId()
getIglooMusicId()
sendMessage(msg) Send a chat message.
sendEmote(emote_id) Send an emote by the emote_id.
sendJoke(joke_id) Send a joke by the joke_id.
sendSafeMessage(safe_id) Send a safe message by the safe_id.
sendMascotMessage(line_id) Send a mascot message by the line_id.
sendTourGuideMessage(room_id) Send a safe message by the safe_id.
mutePlayerById(player_id)
kickPlayerById(player_id)
banPlayerById(player_id)
sendMail(recipient_id, postcard_id) Send postcard postcard_id to recipient_id, calls AIRTOWER.send(AIRTOWER.PLAY_EXT,AIRTOWER.MAIL_HANDLER + "#" + AIRTOWER.SEND_MAIL,[recipient_id,postcard_id],"str",getCurrentServerRoomId()); and increments total_sent_messages++;
getLoginServer()
getRedemptionServer()
isPlayerInChatLog(player_id)
getCurrentRoomService()
getEquipmentService()
getEPFService()
getMailService()
getStampManager()
DEBUG_MODE true if debugging is enabled, false if debugging is disabled.