diff options
author | David Athay <ko2fan@gmail.com> | 2009-02-11 09:30:26 +0000 |
---|---|---|
committer | David Athay <ko2fan@gmail.com> | 2009-02-11 09:30:26 +0000 |
commit | 91111ca5d13072ea3b834e23835df9c077329e39 (patch) | |
tree | f0af8dd08b766164835cf9b5412a9aa3267dbad7 /src/net | |
parent | 8046bb2626b30fecdcea54eb0aa3349cdb7d277b (diff) | |
parent | 63ac001daa7dfc0735dfefd9c2829c8786b4edaf (diff) | |
download | mana-91111ca5d13072ea3b834e23835df9c077329e39.tar.gz mana-91111ca5d13072ea3b834e23835df9c077329e39.tar.bz2 mana-91111ca5d13072ea3b834e23835df9c077329e39.tar.xz mana-91111ca5d13072ea3b834e23835df9c077329e39.zip |
Merge branch 'master' of git@gitorious.org:tmw/eathena
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/beinghandler.cpp | 93 | ||||
-rw-r--r-- | src/net/beinghandler.h | 2 | ||||
-rw-r--r-- | src/net/buysellhandler.cpp | 17 | ||||
-rw-r--r-- | src/net/charserverhandler.cpp | 79 | ||||
-rw-r--r-- | src/net/chathandler.cpp | 8 | ||||
-rw-r--r-- | src/net/equipmenthandler.cpp | 51 | ||||
-rw-r--r-- | src/net/inventoryhandler.cpp | 136 | ||||
-rw-r--r-- | src/net/itemhandler.cpp | 1 | ||||
-rw-r--r-- | src/net/loginhandler.cpp | 60 | ||||
-rw-r--r-- | src/net/loginhandler.h | 3 | ||||
-rw-r--r-- | src/net/maploginhandler.cpp | 29 | ||||
-rw-r--r-- | src/net/messagehandler.cpp | 3 | ||||
-rw-r--r-- | src/net/messagein.cpp | 26 | ||||
-rw-r--r-- | src/net/messagein.h | 22 | ||||
-rw-r--r-- | src/net/messageout.cpp | 5 | ||||
-rw-r--r-- | src/net/network.cpp | 22 | ||||
-rw-r--r-- | src/net/network.h | 57 | ||||
-rw-r--r-- | src/net/npchandler.cpp | 15 | ||||
-rw-r--r-- | src/net/partyhandler.cpp | 122 | ||||
-rw-r--r-- | src/net/partyhandler.h | 39 | ||||
-rw-r--r-- | src/net/playerhandler.cpp | 92 | ||||
-rw-r--r-- | src/net/protocol.h | 43 | ||||
-rw-r--r-- | src/net/skillhandler.cpp | 3 | ||||
-rw-r--r-- | src/net/tradehandler.cpp | 47 |
24 files changed, 634 insertions, 341 deletions
diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index e0ade2ae..0db8fcbf 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -19,24 +19,23 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "beinghandler.h" - +#include <iostream> #include <SDL_types.h> +#include "beinghandler.h" #include "messagein.h" #include "protocol.h" #include "../being.h" #include "../beingmanager.h" +#include "../effectmanager.h" #include "../game.h" #include "../localplayer.h" #include "../log.h" -#include "../main.h" +#include "../npc.h" #include "../particle.h" -#include "../sound.h" -#include <iostream> #include "../player_relations.h" -#include "../npc.h" +#include "../sound.h" const int EMOTION_TIME = 150; /**< Duration of emotion icon */ @@ -73,6 +72,7 @@ void BeingHandler::handleMessage(MessageIn *msg) Uint16 headTop, headMid, headBottom; Uint16 shoes, gloves; Uint16 weapon, shield; + Uint16 gmstatus; Sint16 param1; int stunMode; Uint32 statusEffects; @@ -211,22 +211,17 @@ void BeingHandler::handleMessage(MessageIn *msg) if (!dstBeing) break; + // If this is player's current target, clear it. if (dstBeing == player_node->getTarget()) - { player_node->stopAttack(); - } if (dstBeing == current_npc) current_npc = NULL; if (msg->readInt8() == 1) - { dstBeing->setAction(Being::DEAD); - } else - { beingManager->destroyBeing(dstBeing); - } break; @@ -244,28 +239,26 @@ void BeingHandler::handleMessage(MessageIn *msg) switch (type) { case 0x0a: // Critical Damage - if (dstBeing) { - dstBeing->controlParticle(particleEngine->addEffect( - "graphics/particles/crit.particle.xml", 0, 0)); - } + if (dstBeing) + dstBeing->showCrit(); case 0x00: // Damage - if (dstBeing) { + if (dstBeing) dstBeing->takeDamage(param1); - } - if (srcBeing) { + if (srcBeing) srcBeing->handleAttack(dstBeing, param1); - } break; case 0x02: // Sit - if (srcBeing) { + if (srcBeing) + { srcBeing->mFrame = 0; srcBeing->setAction(Being::SIT); } break; case 0x03: // Stand up - if (srcBeing) { + if (srcBeing) + { srcBeing->mFrame = 0; srcBeing->setAction(Being::STAND); } @@ -279,8 +272,9 @@ void BeingHandler::handleMessage(MessageIn *msg) break; int effectType = msg->readInt32(); + Being* being = beingManager->findBeing(id); - beingManager->findBeing(id)->triggerEffect(effectType); + effectManager->trigger(effectType, being); break; } @@ -450,18 +444,22 @@ void BeingHandler::handleMessage(MessageIn *msg) dstBeing->setDirection(dir); } - msg->readInt16(); // GM status + gmstatus = msg->readInt16(); + if (gmstatus & 0x80) + dstBeing->setGM(); if (msg->getId() == SMSG_PLAYER_UPDATE_1) { - switch (msg->readInt8()) { - - case 1: dstBeing->setAction(Being::DEAD); - break; - - case 2: dstBeing->setAction(Being::SIT); - break; - + switch (msg->readInt8()) + { + case 1: + if (dstBeing->getType() != Being::NPC) + dstBeing->setAction(Being::DEAD); + break; + + case 2: + dstBeing->setAction(Being::SIT); + break; } } else if (msg->getId() == SMSG_PLAYER_MOVE) @@ -482,16 +480,16 @@ void BeingHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STOP: /* - * Instruction from server to stop walking at x, y. - * - * Some people like having this enabled. Others absolutely - * despise it. So I'm setting to so that it only affects the - * local player if the person has set a key "EnableSync" to "1" - * in their config.xml file. - * - * This packet will be honored for all other beings, regardless - * of the config setting. - */ + * Instruction from server to stop walking at x, y. + * + * Some people like having this enabled. Others absolutely + * despise it. So I'm setting to so that it only affects the + * local player if the person has set a key "EnableSync" to "1" + * in their config.xml file. + * + * This packet will be honored for all other beings, regardless + * of the config setting. + */ id = msg->readInt32(); if (mSync || id != player_node->getId()) { @@ -509,11 +507,11 @@ void BeingHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_MOVE_TO_ATTACK: /* - * This is an *advisory* message, telling the client that - * it needs to move the character before attacking - * a target (out of range, obstruction in line of fire). - * We can safely ignore this... - */ + * This is an *advisory* message, telling the client that + * it needs to move the character before attacking + * a target (out of range, obstruction in line of fire). + * We can safely ignore this... + */ break; case 0x0119: @@ -544,4 +542,3 @@ void BeingHandler::handleMessage(MessageIn *msg) break; } } - diff --git a/src/net/beinghandler.h b/src/net/beinghandler.h index f72f0380..54b82075 100644 --- a/src/net/beinghandler.h +++ b/src/net/beinghandler.h @@ -27,7 +27,7 @@ class BeingHandler : public MessageHandler { public: - BeingHandler(bool); + BeingHandler(bool enableSync); void handleMessage(MessageIn *msg); diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index b7f3ecd4..67c79ec4 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -19,10 +19,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "buysellhandler.h" - #include <SDL_types.h> +#include "buysellhandler.h" #include "messagein.h" #include "protocol.h" @@ -36,9 +35,11 @@ #include "../gui/chat.h" #include "../gui/sell.h" +#include "../utils/gettext.h" + extern BuyDialog *buyDialog; -extern SellDialog *sellDialog; extern Window *buySellDialog; +extern SellDialog *sellDialog; BuySellHandler::BuySellHandler() { @@ -105,27 +106,27 @@ void BuySellHandler::handleMessage(MessageIn *msg) } } else { - chatWindow->chatLog("Nothing to sell", BY_SERVER); + chatWindow->chatLog(_("Nothing to sell"), BY_SERVER); current_npc = 0; } break; case SMSG_NPC_BUY_RESPONSE: if (msg->readInt8() == 0) { - chatWindow->chatLog("Thanks for buying", BY_SERVER); + chatWindow->chatLog(_("Thanks for buying"), BY_SERVER); } else { // Reset player money since buy dialog already assumed purchase // would go fine buyDialog->setMoney(player_node->mGp); - chatWindow->chatLog("Unable to buy", BY_SERVER); + chatWindow->chatLog(_("Unable to buy"), BY_SERVER); } break; case SMSG_NPC_SELL_RESPONSE: if (msg->readInt8() == 0) { - chatWindow->chatLog("Thanks for selling", BY_SERVER); + chatWindow->chatLog(_("Thanks for selling"), BY_SERVER); } else { - chatWindow->chatLog("Unable to sell", BY_SERVER); + chatWindow->chatLog(_("Unable to sell"), BY_SERVER); } break; } diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index cfa52c38..932cf705 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -20,9 +20,7 @@ */ #include "charserverhandler.h" - #include "messagein.h" -#include "network.h" #include "protocol.h" #include "../game.h" @@ -31,13 +29,17 @@ #include "../logindata.h" #include "../main.h" -#include "../gui/ok_dialog.h" #include "../gui/char_select.h" +#include "../gui/ok_dialog.h" + +#include "../utils/gettext.h" +#include "../utils/tostring.h" CharServerHandler::CharServerHandler(): mCharCreateDialog(0) { static const Uint16 _messages[] = { + SMSG_CONNECTION_PROBLEM, 0x006b, 0x006c, 0x006d, @@ -45,7 +47,6 @@ CharServerHandler::CharServerHandler(): 0x006f, 0x0070, 0x0071, - 0x0081, 0 }; handledMessages = _messages; @@ -53,16 +54,45 @@ CharServerHandler::CharServerHandler(): void CharServerHandler::handleMessage(MessageIn *msg) { - int slot; + int slot, flags, code; LocalPlayer *tempPlayer; logger->log("CharServerHandler: Packet ID: %x, Length: %d", msg->getId(), msg->getLength()); switch (msg->getId()) { + case SMSG_CONNECTION_PROBLEM: + code = msg->readInt8(); + logger->log("Connection problem: %i", code); + + switch (code) { + case 0: + errorMessage = _("Authentication failed"); + break; + case 1: + errorMessage = _("Map server(s) offline"); + break; + case 2: + errorMessage = _("This account is already logged in"); + break; + case 3: + errorMessage = _("Speed hack detected"); + break; + case 8: + errorMessage = _("Duplicated login"); + break; + default: + errorMessage = _("Unknown connection error"); + break; + } + state = ERROR_STATE; + break; + case 0x006b: - // Skip length word and an additional mysterious 20 bytes - msg->skip(2 + 20); + msg->skip(2); // Length word + flags = msg->readInt32(); // Aethyra extensions flags + logger->log("Server flags are: %x", flags); + msg->skip(16); // Unused // Derive number of characters from message length n_character = (msg->getLength() - 24) / 106; @@ -73,7 +103,7 @@ void CharServerHandler::handleMessage(MessageIn *msg) mCharInfo->select(slot); mCharInfo->setEntry(tempPlayer); logger->log("CharServer: Player: %s (%d)", - tempPlayer->getName().c_str(), slot); + tempPlayer->getName().c_str(), slot); } state = CHAR_SELECT_STATE; @@ -82,13 +112,13 @@ void CharServerHandler::handleMessage(MessageIn *msg) case 0x006c: switch (msg->readInt8()) { case 0: - errorMessage = "Access denied"; + errorMessage = _("Access denied"); break; case 1: - errorMessage = "Cannot use this ID"; + errorMessage = _("Cannot use this ID"); break; default: - errorMessage = "Unknown failure to select character"; + errorMessage = _("Unknown failure to select character"); break; } mCharInfo->unlock(); @@ -110,8 +140,8 @@ void CharServerHandler::handleMessage(MessageIn *msg) break; case 0x006e: - new OkDialog("Error", "Failed to create character. Most likely" - " the name is already taken."); + new OkDialog(_("Error"), _("Failed to create character. Most likely" + " the name is already taken.")); if (mCharCreateDialog) mCharCreateDialog->unlock(); @@ -122,12 +152,12 @@ void CharServerHandler::handleMessage(MessageIn *msg) mCharInfo->setEntry(0); mCharInfo->unlock(); n_character--; - new OkDialog("Info", "Player deleted"); + new OkDialog(_("Info"), _("Player deleted")); break; case 0x0070: mCharInfo->unlock(); - new OkDialog("Error", "Failed to delete character."); + new OkDialog(_("Error"), _("Failed to delete character.")); break; case 0x0071: @@ -154,25 +184,6 @@ void CharServerHandler::handleMessage(MessageIn *msg) mCharInfo->select(slot); state = CONNECTING_STATE; break; - - case 0x0081: - switch (msg->readInt8()) { - case 1: - errorMessage = "Map server offline"; - break; - case 3: - errorMessage = "Speed hack detected"; - break; - case 8: - errorMessage = "Duplicated login"; - break; - default: - errorMessage = "Unknown error with 0x0081"; - break; - } - mCharInfo->unlock(); - state = ERROR_STATE; - break; } } diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index d25d4bcd..25877907 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -19,11 +19,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "chathandler.h" - #include <SDL_types.h> #include <string> +#include "chathandler.h" #include "messagein.h" #include "protocol.h" @@ -34,6 +33,7 @@ #include "../gui/chat.h" +#include "../utils/gettext.h" #include "../utils/tostring.h" #include "../utils/trim.h" @@ -73,10 +73,10 @@ void ChatHandler::handleMessage(MessageIn *msg) //chatWindow->chatLog("Whisper sent", BY_SERVER); break; case 0x01: - chatWindow->chatLog("Whisper could not be sent, user is offline", BY_SERVER); + chatWindow->chatLog(_("Whisper could not be sent, user is offline"), BY_SERVER); break; case 0x02: - chatWindow->chatLog("Whisper could not be sent, ignored by user", BY_SERVER); + chatWindow->chatLog(_("Whisper could not be sent, ignored by user"), BY_SERVER); break; } break; diff --git a/src/net/equipmenthandler.cpp b/src/net/equipmenthandler.cpp index e5bbf6fe..9a3c396a 100644 --- a/src/net/equipmenthandler.cpp +++ b/src/net/equipmenthandler.cpp @@ -20,11 +20,9 @@ */ #include "equipmenthandler.h" - #include "messagein.h" #include "protocol.h" -#include "../beingmanager.h" #include "../equipment.h" #include "../inventory.h" #include "../item.h" @@ -33,6 +31,8 @@ #include "../gui/chat.h" +#include "../utils/gettext.h" + EquipmentHandler::EquipmentHandler() { static const Uint16 _messages[] = { @@ -98,7 +98,7 @@ void EquipmentHandler::handleMessage(MessageIn *msg) logger->log("Equipping: %i %i %i", index, equipPoint, type); if (!type) { - chatWindow->chatLog("Unable to equip.", BY_SERVER); + chatWindow->chatLog(_("Unable to equip."), BY_SERVER); break; } @@ -107,7 +107,10 @@ void EquipmentHandler::handleMessage(MessageIn *msg) break; } - // Unequip any existing equipped item in this position + /* + * An item may occupy more than 1 slot. If so, it's + * only shown as equipped on the *first* slot. + */ mask = 1; position = 0; while (!(equipPoint & mask)) { @@ -115,7 +118,10 @@ void EquipmentHandler::handleMessage(MessageIn *msg) position++; } logger->log("Position %i", position); - item = player_node->getInventory()->getItem(player_node->mEquipment->getEquipment(position)); + + item = player_node->getInventory()->getItem(player_node->mEquipment->getEquipment(position)); + + // Unequip any existing equipped item in this position if (item) { item->setEquipped(false); } @@ -130,7 +136,7 @@ void EquipmentHandler::handleMessage(MessageIn *msg) type = msg->readInt8(); if (!type) { - chatWindow->chatLog("Unable to unequip.", BY_SERVER); + chatWindow->chatLog(_("Unable to unequip."), BY_SERVER); break; } @@ -152,24 +158,11 @@ void EquipmentHandler::handleMessage(MessageIn *msg) item->setEquipped(false); - switch (item->getId()) { - case 529: - case 1199: - player_node->mEquipment->setArrows(0); - break; - case 521: - case 522: - case 530: - case 536: - case 1200: - case 1201: - player_node->setSprite(Being::WEAPON_SPRITE, 0); - // TODO: Why this break? Shouldn't a weapon be - // unequipped in inventory too? - break; - default: - player_node->mEquipment->removeEquipment(position); - break; + if (equipPoint & 0x8000) { // Arrows + player_node->mEquipment->setArrows(0); + } + else { + player_node->mEquipment->removeEquipment(position); } logger->log("Unequipping: %i %i(%i) %i", index, equipPoint, type, position); @@ -186,12 +179,12 @@ void EquipmentHandler::handleMessage(MessageIn *msg) break; item = inventory->getItem(index); - if (!item) - break; - item->setEquipped(true); - player_node->mEquipment->setArrows(index); - logger->log("Arrows equipped: %i", index); + if (item) { + item->setEquipped(true); + player_node->mEquipment->setArrows(index); + logger->log("Arrows equipped: %i", index); + } break; } } diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index cd9b5ce0..46f03e28 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -19,22 +19,24 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "inventoryhandler.h" - #include <SDL_types.h> +#include "inventoryhandler.h" #include "messagein.h" #include "protocol.h" -#include "../resources/iteminfo.h" +#include "../inventory.h" #include "../item.h" #include "../itemshortcut.h" #include "../localplayer.h" #include "../log.h" -#include "../inventory.h" #include "../gui/chat.h" +#include "../resources/iteminfo.h" + +#include "../utils/gettext.h" +#include "../utils/strprintf.h" #include "../utils/tostring.h" InventoryHandler::InventoryHandler() @@ -45,6 +47,12 @@ InventoryHandler::InventoryHandler() SMSG_PLAYER_INVENTORY_REMOVE, SMSG_PLAYER_INVENTORY_USE, SMSG_ITEM_USE_RESPONSE, + SMSG_PLAYER_STORAGE_ITEMS, + SMSG_PLAYER_STORAGE_EQUIP, + SMSG_PLAYER_STORAGE_STATUS, + SMSG_PLAYER_STORAGE_ADD, + SMSG_PLAYER_STORAGE_REMOVE, + SMSG_PLAYER_STORAGE_CLOSE, 0 }; handledMessages = _messages; @@ -53,35 +61,69 @@ InventoryHandler::InventoryHandler() void InventoryHandler::handleMessage(MessageIn *msg) { Sint32 number; - Sint16 index, amount, itemId, equipType; + Sint16 index, amount, itemId, equipType, arrow; + Sint16 identified, cards[4], itemType; Inventory *inventory = player_node->getInventory(); + Inventory *storage = player_node->getStorage(); switch (msg->getId()) { case SMSG_PLAYER_INVENTORY: - // Only called on map load / warp. First reset all items - // to not load them twice on map change. - inventory->clear(); + case SMSG_PLAYER_STORAGE_ITEMS: + case SMSG_PLAYER_STORAGE_EQUIP: + switch (msg->getId()) { + case SMSG_PLAYER_INVENTORY: + // Clear inventory - this will be a complete refresh + inventory->clear(); + break; + case SMSG_PLAYER_STORAGE_ITEMS: + /* + * This packet will always be followed by a + * SMSG_PLAYER_STORAGE_EQUIP packet. The two packets + * together comprise a complete refresh of storage, so + * clear storage here + */ + storage->clear(); + logger->log("Received SMSG_PLAYER_STORAGE_ITEMS"); + break; + default: + logger->log("Received SMSG_PLAYER_STORAGE_EQUIP"); + break; + } msg->readInt16(); // length number = (msg->getLength() - 4) / 18; - for (int loop = 0; loop < number; loop++) - { + for (int loop = 0; loop < number; loop++) { index = msg->readInt16(); itemId = msg->readInt16(); - msg->readInt8(); // type - msg->readInt8(); // identify flag - amount = msg->readInt16(); - msg->skip(2); // unknown - msg->skip(8); // card (4 shorts) - - inventory->setItem(index, itemId, amount, false); - - // Trick because arrows are not considered equipment - if (itemId == 1199 || itemId == 529) - { - if (Item *item = inventory->getItem(index)) - item->setEquipment(true); + itemType = msg->readInt8(); + identified = msg->readInt8(); + if (msg->getId() == SMSG_PLAYER_STORAGE_EQUIP) { + amount = 1; + msg->readInt16(); // Equip Point? + } else { + amount = msg->readInt16(); + } + arrow = msg->readInt16(); + if (msg->getId() == SMSG_PLAYER_STORAGE_EQUIP) { + msg->readInt8(); // Attribute (broken) + msg->readInt8(); // Refine level + } + for (int i = 0; i < 4; i++) + cards[i] = msg->readInt16(); + + if (msg->getId() == SMSG_PLAYER_INVENTORY) { + inventory->setItem(index, itemId, amount, false); + + // Trick because arrows are not considered equipment + if (arrow & 0x8000) { + if (Item *item = inventory->getItem(index)) + item->setEquipment(true); + } + } else { + logger->log("Index:%d, ID:%d, Type:%d, Identified:%d, Qty:%d, Cards:%d, %d, %d, %d", + index, itemId, itemType, identified, amount, cards[0], cards[1], cards[2], cards[3]); + storage->setItem(index, itemId, amount, false); } } break; @@ -90,21 +132,22 @@ void InventoryHandler::handleMessage(MessageIn *msg) index = msg->readInt16(); amount = msg->readInt16(); itemId = msg->readInt16(); - msg->readInt8(); // identify flag + identified = msg->readInt8(); msg->readInt8(); // attribute msg->readInt8(); // refine - msg->skip(8); // card + for (int i = 0; i < 4; i++) + cards[i] = msg->readInt16(); equipType = msg->readInt16(); - msg->readInt8(); // type + itemType = msg->readInt8(); if (msg->readInt8() > 0) { - chatWindow->chatLog("Unable to pick up item", BY_SERVER); + chatWindow->chatLog(_("Unable to pick up item"), BY_SERVER); } else { const ItemInfo &itemInfo = ItemDB::get(itemId); const std::string amountStr = (amount > 1) ? toString(amount) : "a"; - chatWindow->chatLog("You picked up " + amountStr + " " + - itemInfo.getName(), BY_SERVER); + chatWindow->chatLog(strprintf(_("You picked up %s %s"), + amountStr.c_str(), itemInfo.getName().c_str()), BY_SERVER); if (Item *item = inventory->getItem(index)) { item->setId(itemId); @@ -141,11 +184,44 @@ void InventoryHandler::handleMessage(MessageIn *msg) amount = msg->readInt16(); if (msg->readInt8() == 0) { - chatWindow->chatLog("Failed to use item", BY_SERVER); + chatWindow->chatLog(_("Failed to use item"), BY_SERVER); } else { if (Item *item = inventory->getItem(index)) item->setQuantity(amount); } break; + + case SMSG_PLAYER_STORAGE_STATUS: + /* + * Basic slots used vs total slots info + * We don't really need this information, but this is + * the closest we get to an "Open Storage" packet + * from the server. It always comes after the two + * SMSG_PLAYER_STORAGE_... packets that update + * storage contents. + */ + logger->log("Received SMSG_PLAYER_STORAGE_STATUS"); + player_node->setInStorage(true); + break; + + case SMSG_PLAYER_STORAGE_ADD: + /* + * Move an item into storage + */ + break; + + case SMSG_PLAYER_STORAGE_REMOVE: + /* + * Move an item out of storage + */ + break; + + case SMSG_PLAYER_STORAGE_CLOSE: + /* + * Storage access has been closed + */ + player_node->setInStorage(false); + logger->log("Received SMSG_PLAYER_STORAGE_CLOSE"); + break; } } diff --git a/src/net/itemhandler.cpp b/src/net/itemhandler.cpp index 03313a55..8c4af4e4 100644 --- a/src/net/itemhandler.cpp +++ b/src/net/itemhandler.cpp @@ -20,7 +20,6 @@ */ #include "itemhandler.h" - #include "messagein.h" #include "protocol.h" diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp index 646c5f3c..41314d16 100644 --- a/src/net/loginhandler.cpp +++ b/src/net/loginhandler.cpp @@ -20,9 +20,7 @@ */ #include "loginhandler.h" - #include "messagein.h" -#include "network.h" #include "protocol.h" #include "../log.h" @@ -30,11 +28,16 @@ #include "../main.h" #include "../serverinfo.h" +#include "../utils/gettext.h" +#include "../utils/strprintf.h" +#include "../utils/tostring.h" + extern SERVER_INFO **server_info; LoginHandler::LoginHandler() { static const Uint16 _messages[] = { + SMSG_CONNECTION_PROBLEM, SMSG_UPDATE_HOST, 0x0069, 0x006a, @@ -45,9 +48,32 @@ LoginHandler::LoginHandler() void LoginHandler::handleMessage(MessageIn *msg) { + int code; + switch (msg->getId()) { - case 0x0063: + case SMSG_CONNECTION_PROBLEM: + code = msg->readInt8(); + logger->log("Connection problem: %i", code); + + switch (code) { + case 0: + errorMessage = _("Authentication failed"); + break; + case 1: + errorMessage = _("No servers available"); + break; + case 2: + errorMessage = _("This account is already logged in"); + break; + default: + errorMessage = _("Unknown connection error"); + break; + } + state = ERROR_STATE; + break; + + case SMSG_UPDATE_HOST: int len; len = msg->readInt16() - 4; @@ -91,35 +117,39 @@ void LoginHandler::handleMessage(MessageIn *msg) break; case 0x006a: - int loginError = msg->readInt8(); - logger->log("Login::error code: %i", loginError); + code = msg->readInt8(); + logger->log("Login::error code: %i", code); - switch (loginError) { + switch (code) { case 0: - errorMessage = "Unregistered ID"; + errorMessage = _("Unregistered ID"); break; case 1: - errorMessage = "Wrong password"; + errorMessage = _("Wrong password"); break; case 2: - errorMessage = "Account expired"; + errorMessage = _("Account expired"); break; case 3: - errorMessage = "Rejected from server"; + errorMessage = _("Rejected from server"); break; case 4: - errorMessage = "You have been permanently banned from the game. Please contact the GM Team"; + errorMessage = _("You have been permanently banned from the" + " game. Please contact the GM Team"); break; case 6: - errorMessage = "You have been temporarily banned from the game until " - + msg->readString(20) + ".\n Please contact the GM team via the forums"; + errorMessage = strprintf(_("You have been temporarily " + "banned from the game until %s.\n" + " Please contact the GM team via " + "the forums"), + msg->readString(20).c_str()); break; case 9: - errorMessage = "This user name is already taken"; + errorMessage = _("This user name is already taken"); break; default: - errorMessage = "Unknown error"; + errorMessage = _("Unknown error"); break; } state = ERROR_STATE; diff --git a/src/net/loginhandler.h b/src/net/loginhandler.h index a380c767..df86b634 100644 --- a/src/net/loginhandler.h +++ b/src/net/loginhandler.h @@ -22,9 +22,10 @@ #ifndef NET_LOGINHANDLER_H #define NET_LOGINHANDLER_H -#include "messagehandler.h" #include <string> +#include "messagehandler.h" + struct LoginData; class LoginHandler : public MessageHandler diff --git a/src/net/maploginhandler.cpp b/src/net/maploginhandler.cpp index 0d349a6d..b5192bd7 100644 --- a/src/net/maploginhandler.cpp +++ b/src/net/maploginhandler.cpp @@ -20,7 +20,6 @@ */ #include "maploginhandler.h" - #include "messagein.h" #include "protocol.h" @@ -28,11 +27,13 @@ #include "../log.h" #include "../main.h" +#include "../utils/gettext.h" + MapLoginHandler::MapLoginHandler() { static const Uint16 _messages[] = { + SMSG_CONNECTION_PROBLEM, SMSG_LOGIN_SUCCESS, - 0x0081, 0 }; handledMessages = _messages; @@ -40,10 +41,29 @@ MapLoginHandler::MapLoginHandler() void MapLoginHandler::handleMessage(MessageIn *msg) { + int code; unsigned char direction; switch (msg->getId()) { + case SMSG_CONNECTION_PROBLEM: + code = msg->readInt8(); + logger->log("Connection problem: %i", code); + + switch (code) { + case 0: + errorMessage = _("Authentication failed"); + break; + case 2: + errorMessage = _("This account is already logged in"); + break; + default: + errorMessage = _("Unknown connection error"); + break; + } + state = ERROR_STATE; + break; + case SMSG_LOGIN_SUCCESS: msg->readInt32(); // server tick msg->readCoordinates(player_node->mX, player_node->mY, direction); @@ -52,10 +72,5 @@ void MapLoginHandler::handleMessage(MessageIn *msg) player_node->mX, player_node->mY, direction); state = GAME_STATE; break; - - case 0x0081: - logger->log("Warning: Map server D/C"); - state = ERROR_STATE; - break; } } diff --git a/src/net/messagehandler.cpp b/src/net/messagehandler.cpp index 063532d4..f1561a31 100644 --- a/src/net/messagehandler.cpp +++ b/src/net/messagehandler.cpp @@ -19,10 +19,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "messagehandler.h" - #include <cassert> +#include "messagehandler.h" #include "network.h" MessageHandler::MessageHandler(): diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index cbcde3fe..a288d936 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -19,17 +19,16 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "messagein.h" - #include <cassert> #include <SDL.h> #include <SDL_endian.h> +#include "messagein.h" + #define MAKEWORD(low,high) \ ((unsigned short)(((unsigned char)(low)) | \ ((unsigned short)((unsigned char)(high))) << 8)) - MessageIn::MessageIn(const char *data, unsigned int length): mData(data), mLength(length), @@ -39,15 +38,13 @@ MessageIn::MessageIn(const char *data, unsigned int length): mId = readInt16(); } -Sint8 -MessageIn::readInt8() +Sint8 MessageIn::readInt8() { assert(mPos < mLength); return mData[mPos++]; } -Sint16 -MessageIn::readInt16() +Sint16 MessageIn::readInt16() { assert(mPos + 2 <= mLength); mPos += 2; @@ -58,8 +55,7 @@ MessageIn::readInt16() #endif } -Sint32 -MessageIn::readInt32() +Sint32 MessageIn::readInt32() { assert(mPos + 4 <= mLength); mPos += 4; @@ -70,8 +66,7 @@ MessageIn::readInt32() #endif } -void -MessageIn::readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction) +void MessageIn::readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction) { assert(mPos + 3 <= mLength); @@ -120,8 +115,7 @@ MessageIn::readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction) mPos += 3; } -void -MessageIn::readCoordinatePair(Uint16 &srcX, Uint16 &srcY, +void MessageIn::readCoordinatePair(Uint16 &srcX, Uint16 &srcY, Uint16 &dstX, Uint16 &dstY) { assert(mPos + 5 <= mLength); @@ -143,15 +137,13 @@ MessageIn::readCoordinatePair(Uint16 &srcX, Uint16 &srcY, mPos += 5; } -void -MessageIn::skip(unsigned int length) +void MessageIn::skip(unsigned int length) { assert(mPos + length <= mLength); mPos += length; } -std::string -MessageIn::readString(int length) +std::string MessageIn::readString(int length) { // Get string length if (length < 0) { diff --git a/src/net/messagein.h b/src/net/messagein.h index 1788aa97..0ff6e78a 100644 --- a/src/net/messagein.h +++ b/src/net/messagein.h @@ -22,8 +22,8 @@ #ifndef MESSAGEIN_ #define MESSAGEIN_ -#include <string> #include <SDL_types.h> +#include <string> /** * Used for parsing an incoming message. @@ -43,14 +43,12 @@ class MessageIn /** * Returns the message ID. */ - short - getId() { return mId; } + short getId() { return mId; } /** * Returns the message length. */ - unsigned int - getLength() { return mLength; } + unsigned int getLength() { return mLength; } Sint8 readInt8(); /**< Reads a byte. */ Sint16 readInt16(); /**< Reads a short. */ @@ -60,30 +58,26 @@ class MessageIn * Reads a special 3 byte block used by eAthena, containing x and y * coordinates and direction. */ - void - readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction); + void readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction); /** * Reads a special 5 byte block used by eAthena, containing a source * and destination coordinate pair. */ - void - readCoordinatePair(Uint16 &srcX, Uint16 &srcY, - Uint16 &dstX, Uint16 &dstY); + void readCoordinatePair(Uint16 &srcX, Uint16 &srcY, + Uint16 &dstX, Uint16 &dstY); /** * Skips a given number of bytes. */ - void - skip(unsigned int length); + void skip(unsigned int length); /** * Reads a string. If a length is not given (-1), it is assumed * that the length of the string is stored in a short at the * start of the string. */ - std::string - readString(int length = -1); + std::string readString(int length = -1); private: const char* mData; /**< The message data. */ diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 8f361e5e..bf4957be 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -20,13 +20,12 @@ */ #include <cstring> -#include <string> #include <SDL.h> #include <SDL_endian.h> - -#include "network.h" +#include <string> #include "messageout.h" +#include "network.h" MessageOut::MessageOut(Network *network): mNetwork(network), diff --git a/src/net/network.cpp b/src/net/network.cpp index 1463c696..059da779 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -19,14 +19,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "network.h" +#include <sstream> #include "messagehandler.h" #include "messagein.h" +#include "network.h" #include "../log.h" - -#include <sstream> +#include "../utils/tostring.h" /** Warning: buffers and other variables are shared, so there can be only one connection active at a time */ @@ -419,21 +419,7 @@ void Network::receive() SDLNet_FreeSocketSet(set); } -char *iptostring(int address) -{ - static char asciiIP[16]; - - sprintf(asciiIP, "%i.%i.%i.%i", - (unsigned char)(address), - (unsigned char)(address >> 8), - (unsigned char)(address >> 16), - (unsigned char)(address >> 24)); - - return asciiIP; -} - -void -Network::setError(const std::string& error) +void Network::setError(const std::string& error) { logger->log("Network error: %s", error.c_str()); mError = error; diff --git a/src/net/network.h b/src/net/network.h index c942a819..02fe7538 100644 --- a/src/net/network.h +++ b/src/net/network.h @@ -48,47 +48,33 @@ class Network ~Network(); - bool - connect(const std::string &address, short port); + bool connect(const std::string &address, short port); - void - disconnect(); + void disconnect(); - void - registerHandler(MessageHandler *handler); + void registerHandler(MessageHandler *handler); - void - unregisterHandler(MessageHandler *handler); + void unregisterHandler(MessageHandler *handler); - void - clearHandlers(); + void clearHandlers(); - int - getState() const { return mState; } + int getState() const { return mState; } - const std::string& - getError() const { return mError; } + const std::string& getError() const { return mError; } - bool - isConnected() const { return mState == CONNECTED; } + bool isConnected() const { return mState == CONNECTED; } - int - getInSize() const { return mInSize; } + int getInSize() const { return mInSize; } - void - skip(int len); + void skip(int len); - bool - messageReady(); + bool messageReady(); - MessageIn - getNextMessage(); + MessageIn getNextMessage(); - void - dispatchMessages(); + void dispatchMessages(); - void - flush(); + void flush(); // ERROR replaced by NET_ERROR because already defined in Windows enum { @@ -100,17 +86,13 @@ class Network }; protected: - void - setError(const std::string& error); + void setError(const std::string& error); - Uint16 - readWord(int pos); + Uint16 readWord(int pos); - bool - realConnect(); + bool realConnect(); - void - receive(); + void receive(); TCPsocket mSocket; @@ -133,7 +115,4 @@ class Network MessageHandlers mMessageHandlers; }; -/** Convert an address from int format to string */ -char *iptostring(int address); - #endif diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index b0314e47..ea03537f 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -19,18 +19,18 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "npchandler.h" - #include "messagein.h" +#include "npchandler.h" #include "protocol.h" #include "../beingmanager.h" +#include "../localplayer.h" #include "../npc.h" +#include "../gui/npc_text.h" #include "../gui/npcintegerdialog.h" #include "../gui/npclistdialog.h" #include "../gui/npcstringdialog.h" -#include "../gui/npc_text.h" extern NpcIntegerDialog *npcIntegerDialog; extern NpcListDialog *npcListDialog; @@ -60,6 +60,7 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_CHOICE: msg->readInt16(); // length id = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id)); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(true); @@ -68,17 +69,17 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_MESSAGE: msg->readInt16(); // length id = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id)); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(false); npcTextDialog->setVisible(true); break; - case SMSG_NPC_CLOSE: + case SMSG_NPC_CLOSE: id = msg->readInt32(); - dynamic_cast<NPC*>(beingManager->findBeing(id)); if (current_npc == dynamic_cast<NPC*>(beingManager->findBeing(id))) - current_npc = NULL; + current_npc = NULL; break; case SMSG_NPC_NEXT: @@ -91,6 +92,7 @@ void NPCHandler::handleMessage(MessageIn *msg) current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id)); npcIntegerDialog->setRange(0, 2147483647); npcIntegerDialog->setVisible(true); + npcIntegerDialog->requestFocus(); break; case SMSG_NPC_STR_INPUT: @@ -99,6 +101,7 @@ void NPCHandler::handleMessage(MessageIn *msg) current_npc = dynamic_cast<NPC*>(beingManager->findBeing(id)); npcStringDialog->setValue(""); npcStringDialog->setVisible(true); + npcStringDialog->requestFocus(); break; } } diff --git a/src/net/partyhandler.cpp b/src/net/partyhandler.cpp new file mode 100644 index 00000000..fe7db55d --- /dev/null +++ b/src/net/partyhandler.cpp @@ -0,0 +1,122 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <guichan/actionlistener.hpp> + +#include "partyhandler.h" +#include "protocol.h" +#include "messagein.h" + +#include "../gui/chat.h" +#include "../gui/confirm_dialog.h" + +#include "../beingmanager.h" +#include "../party.h" + +PartyHandler::PartyHandler(Party *party) : mParty(party) +{ + static const Uint16 _messages[] = { + SMSG_PARTY_CREATE, + SMSG_PARTY_INFO, + SMSG_PARTY_INVITE, + SMSG_PARTY_INVITED, + SMSG_PARTY_SETTINGS, + SMSG_PARTY_MEMBER_INFO, + SMSG_PARTY_LEAVE, + SMSG_PARTY_UPDATE_HP, + SMSG_PARTY_UPDATE_COORDS, + SMSG_PARTY_MESSAGE, + 0 + }; + handledMessages = _messages; +} + +void PartyHandler::handleMessage(MessageIn *msg) +{ + switch (msg->getId()) + { + case SMSG_PARTY_CREATE: + mParty->createResponse(msg->readInt8()); + break; + case SMSG_PARTY_INFO: + break; + case SMSG_PARTY_INVITE: + { + std::string nick = msg->readString(24); + int status = msg->readInt8(); + mParty->inviteResponse(nick, status); + break; + } + case SMSG_PARTY_INVITED: + { + int id = msg->readInt32(); + Being *being = beingManager->findBeing(id); + if (!being) + { + break; + } + std::string nick; + int gender = 0; + std::string partyName = ""; + if (being->getType() != Being::PLAYER) + { + nick = ""; + } + else + { + nick = being->getName(); + gender = being->getGender(); + partyName = msg->readString(24); + } + mParty->invitedAsk(nick, gender, partyName); + break; + } + case SMSG_PARTY_SETTINGS: + break; + case SMSG_PARTY_MEMBER_INFO: + break; + case SMSG_PARTY_LEAVE: + { + /*int id = */msg->readInt32(); + std::string nick = msg->readString(24); + /*int fail = */msg->readInt8(); + mParty->leftResponse(nick); + break; + } + case SMSG_PARTY_UPDATE_HP: + break; + case SMSG_PARTY_UPDATE_COORDS: + break; + case SMSG_PARTY_MESSAGE: + { // new block to enable local variables + int msgLength = msg->readInt16() - 8; + if (msgLength <= 0) + { + return; + } + int id = msg->readInt32(); + Being *being = beingManager->findBeing(id); + std::string chatMsg = msg->readString(msgLength); + mParty->receiveChat(being, chatMsg); + } + break; + } +} diff --git a/src/net/partyhandler.h b/src/net/partyhandler.h new file mode 100644 index 00000000..048da9b1 --- /dev/null +++ b/src/net/partyhandler.h @@ -0,0 +1,39 @@ +/* + * The Mana World + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PARTYHANDLER_H +#define PARTYHANDLER_H + +#include "messagehandler.h" + +class Party; + +class PartyHandler : public MessageHandler +{ + public: + PartyHandler(Party *party); + + void handleMessage(MessageIn *msg); + private: + Party *mParty; +}; + +#endif diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 5d989a66..470a4aa4 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -19,16 +19,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "playerhandler.h" - #include "messagein.h" +#include "playerhandler.h" #include "protocol.h" #include "../engine.h" #include "../localplayer.h" #include "../log.h" #include "../npc.h" -#include "../utils/tostring.h" #include "../gui/buy.h" #include "../gui/chat.h" @@ -40,6 +38,9 @@ #include "../gui/skill.h" #include "../gui/viewport.h" +#include "../utils/tostring.h" +#include "../utils/gettext.h" + // TODO Move somewhere else OkDialog *weightNotice = NULL; OkDialog *deathNotice = NULL; @@ -51,7 +52,7 @@ extern SellDialog *sellDialog; extern Window *buySellDialog; static const int MAP_TELEPORT_SCROLL_DISTANCE = 8; /* Max. distance we are willing to scroll after a teleport; - ** everything beyond will reset the port hard. */ + * everything beyond will reset the port hard. */ /** * Listener used for handling the overweigth message. @@ -110,10 +111,11 @@ void PlayerHandler::handleMessage(MessageIn *msg) switch (msg->getId()) { case SMSG_WALK_RESPONSE: - // It is assumed by the client any request to walk actually - // succeeds on the server. The plan is to have a correction - // message when the server senses the client has the wrong - // idea. + /* + * This client assumes that all walk messages succeed, + * and that the server will send a correction notice + * otherwise. + */ break; case SMSG_PLAYER_WARP: @@ -132,6 +134,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) player_node->stopAttack(); nearby = (engine->getCurrentMapName() == mapPath); + // Switch the actual map, deleting the previous one if necessary engine->changeMap(mapPath); @@ -143,7 +146,8 @@ void PlayerHandler::handleMessage(MessageIn *msg) /* Scroll if neccessary */ if (!nearby || (abs(x - player_node->mX) > MAP_TELEPORT_SCROLL_DISTANCE) - || (abs(y - player_node->mY) > MAP_TELEPORT_SCROLL_DISTANCE)) { + || (abs(y - player_node->mY) > MAP_TELEPORT_SCROLL_DISTANCE)) + { scrollOffsetX = (x - player_node->mX) * 32; scrollOffsetY = (y - player_node->mY) * 32; } @@ -173,6 +177,9 @@ void PlayerHandler::handleMessage(MessageIn *msg) case 0x0006: player_node->mMaxHp = value; break; case 0x0007: player_node->mMp = value; break; case 0x0008: player_node->mMaxMp = value; break; + case 0x0009: + player_node->mStatsPointsToAttribute = value; + break; case 0x000b: player_node->mLevel = value; break; case 0x000c: player_node->mSkillPoint = value; @@ -183,20 +190,16 @@ void PlayerHandler::handleMessage(MessageIn *msg) player_node->mTotalWeight < player_node->mMaxWeight / 2) { - weightNotice = new OkDialog("Message", - "You are carrying more then half " - "your weight. You are unable to " - "regain health."); + weightNotice = new OkDialog(_("Message"), + _("You are carrying more then " + "half your weight. You are " + "unable to regain health.")); weightNotice->addActionListener( &weightListener); } player_node->mTotalWeight = value; break; case 0x0019: player_node->mMaxWeight = value; break; - case 0x0037: player_node->mJobLevel = value; break; - case 0x0009: - player_node->mStatsPointsToAttribute = value; - break; case 0x0029: player_node->ATK = value; break; case 0x002b: player_node->MATK = value; break; case 0x002d: player_node->DEF = value; break; @@ -205,12 +208,44 @@ void PlayerHandler::handleMessage(MessageIn *msg) case 0x0031: player_node->HIT = value; break; case 0x0032: player_node->FLEE = value; break; case 0x0035: player_node->mAttackSpeed = value; break; + case 0x0037: player_node->mJobLevel = value; break; } if (player_node->mHp == 0 && deathNotice == NULL) { - deathNotice = new OkDialog("Message", - "You're now dead, press ok to restart"); + static char const *const deadMsg[] = + { + _("You are dead."), + _("We regret to inform you that your character was killed in battle."), + _("You are not that alive anymore."), + _("The cold hands of the grim reaper are grabbing for your soul."), + _("Game Over!"), + _("Insert coin to continue"), + _("No, kids. Your character did not really die. It... err... went to a better place."), + _("Your plan of breaking your enemies weapon by bashing it with your throat failed."), + _("I guess this did not run too well."), + _("Do you want your possessions identified?"), // Nethack reference + _("Sadly, no trace of you was ever found..."), // Secret of Mana reference + _("Annihilated."), // Final Fantasy VI reference + _("Looks like you got your head handed to you."), //Earthbound reference + _("You screwed up again, dump your body down the tubes and get you another one."), // Leisure Suit Larry 1 Reference + _("You're not dead yet. You're just resting."), // Monty Python reference from a couple of skits + _("You are no more."), // Monty Python reference from the dead parrot sketch starting now + _("You have ceased to be."), + _("You've expired and gone to meet your maker."), + _("You're a stiff."), + _("Bereft of life, you rest in peace."), + _("If you weren't so animated, you'd be pushing up the daisies."), + _("Your metabolic processes are now history."), + _("You're off the twig."), + _("You've kicked the bucket."), + _("You've shuffled off your mortal coil, run down the curtain and joined the bleedin' choir invisibile."), + _("You are an ex-player."), + _("You're pining for the fjords.") // Monty Python reference from the dead parrot sketch + }; + std::string message(deadMsg[rand()%27]); + + deathNotice = new OkDialog(_("Message"), message); deathNotice->addActionListener(&deathListener); player_node->setAction(Being::DEAD); } @@ -229,7 +264,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) Uint32 curGp = player_node->mGp; player_node->mGp = msg->readInt32(); if (player_node->mGp > curGp) - chatWindow->chatLog("You picked up " + + chatWindow->chatLog(_("You picked up ") + toString(player_node->mGp - curGp) + " GP", BY_SERVER); } @@ -293,7 +328,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) } break; - // Updates stats and status points + // Updates stats and status points case SMSG_PLAYER_STAT_UPDATE_5: player_node->mStatsPointsToAttribute = msg->readInt16(); player_node->mAttr[LocalPlayer::STR] = msg->readInt8(); @@ -352,7 +387,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) switch (type) { case 0: - chatWindow->chatLog("Equip arrows first", + chatWindow->chatLog(_("Equip arrows first"), BY_SERVER); break; default: @@ -361,18 +396,5 @@ void PlayerHandler::handleMessage(MessageIn *msg) } } break; - - //Stop walking - //case 0x0088: // Disabled because giving some problems - //if (being = beingManager->findBeing(readInt32(2))) { - // if (being->getId() != player_node->getId()) { - // being->action = STAND; - // being->mFrame = 0; - // set_coordinates(being->coordinates, - // readWord(6), readWord(8), - // get_direction(being->coordinates)); - // } - //} - //break; } } diff --git a/src/net/protocol.h b/src/net/protocol.h index b70834c6..e9053451 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -22,8 +22,12 @@ #ifndef PROTOCOL_ #define PROTOCOL_ -// Packets from server to client +/********************************* + * Packets from server to client * + *********************************/ #define SMSG_LOGIN_SUCCESS 0x0073 /**< Contains starting location */ +#define SMSG_SERVER_PING 0x007f /**< Contains server tick */ +#define SMSG_CONNECTION_PROBLEM 0x0081 #define SMSG_UPDATE_HOST 0x0063 /**< Custom update host packet */ #define SMSG_PLAYER_UPDATE_1 0x01d8 #define SMSG_PLAYER_UPDATE_2 0x01d9 @@ -66,6 +70,7 @@ #define SMSG_BEING_ACTION 0x008a /**< Attack, sit, stand up, ... */ #define SMSG_BEING_CHAT 0x008d /**< A being talks */ #define SMSG_BEING_NAME_RESPONSE 0x0095 /**< Has to be requested */ + #define SMSG_NPC_MESSAGE 0x00b4 #define SMSG_NPC_NEXT 0x00b5 #define SMSG_NPC_CLOSE 0x00b6 @@ -82,6 +87,7 @@ #define SMSG_WHISPER_RESPONSE 0x0098 #define SMSG_GM_CHAT 0x009a /**< GM announce */ #define SMSG_WALK_RESPONSE 0x0087 + #define SMSG_TRADE_REQUEST 0x00e5 /**< Receiving a request to trade */ #define SMSG_TRADE_RESPONSE 0x00e7 #define SMSG_TRADE_ITEM_ADD 0x00e9 @@ -90,7 +96,27 @@ #define SMSG_TRADE_CANCEL 0x00ee #define SMSG_TRADE_COMPLETE 0x00f0 -// Packets from client to server +#define SMSG_PARTY_CREATE 0x00fa +#define SMSG_PARTY_INFO 0x00fb +#define SMSG_PARTY_INVITE 0x00fd +#define SMSG_PARTY_INVITED 0x00fe +#define SMSG_PARTY_SETTINGS 0x0102 +#define SMSG_PARTY_MEMBER_INFO 0x0104 +#define SMSG_PARTY_LEAVE 0x0105 +#define SMSG_PARTY_UPDATE_HP 0x0106 +#define SMSG_PARTY_UPDATE_COORDS 0x0107 +#define SMSG_PARTY_MESSAGE 0x0109 + +#define SMSG_PLAYER_STORAGE_ITEMS 0x01f0 /**< Item list for storage */ +#define SMSG_PLAYER_STORAGE_EQUIP 0x00a6 /**< Equipment list for storage */ +#define SMSG_PLAYER_STORAGE_STATUS 0x00f2 /**< Slots used and total slots */ +#define SMSG_PLAYER_STORAGE_ADD 0x00f4 /**< Add item/equip to storage */ +#define SMSG_PLAYER_STORAGE_REMOVE 0x00f6 /**< Remove item/equip from storage */ +#define SMSG_PLAYER_STORAGE_CLOSE 0x00f8 /**< Storage access closed */ + +/********************************** + * Packets from client to server * + **********************************/ #define CMSG_CLIENT_PING 0x007e /**< Send to server with tick */ #define CMSG_TRADE_RESPONSE 0x00e6 #define CMSG_ITEM_PICKUP 0x009f @@ -99,6 +125,8 @@ #define CMSG_NPC_BUY_SELL_REQUEST 0x00c5 #define CMSG_CHAT_MESSAGE 0x008c #define CMSG_CHAT_WHISPER 0x0096 +#define CMSG_CHAT_ANNOUNCE 0x0099 +#define CMSG_CHAT_WHO 0x00c1 #define CMSG_NPC_LIST_CHOICE 0x00b8 #define CMSG_NPC_NEXT_REQUEST 0x00b9 #define CMSG_NPC_SELL_REQUEST 0x00c9 @@ -117,6 +145,17 @@ #define CMSG_PLAYER_EQUIP 0x00a9 #define CMSG_PLAYER_UNEQUIP 0x00ab +#define CMSG_PARTY_CREATE 0x00f9 +#define CMSG_PARTY_INVITE 0x00fc +#define CMSG_PARTY_INVITED 0x00ff +#define CMSG_PARTY_LEAVE 0x0100 /** Undocumented */ +#define CMSG_PARTY_SETTINGS 0x0101 +#define CMSG_PARTY_MESSAGE 0x0108 + +#define CMSG_MOVE_TO_STORAGE 0x00f3 /** Move item to storage */ +#define CSMG_MOVE_FROM_STORAGE 0x00f5 /** Remove item from storage */ +#define CMSG_CLOSE_STORAGE 0x00f7 /** Request storage close */ + /** Encodes coords and direction in 3 bytes data */ void set_coordinates(char *data, unsigned short x, unsigned short y, unsigned char direction); diff --git a/src/net/skillhandler.cpp b/src/net/skillhandler.cpp index 17b1f117..e2185524 100644 --- a/src/net/skillhandler.cpp +++ b/src/net/skillhandler.cpp @@ -19,10 +19,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "skillhandler.h" - #include "messagein.h" #include "protocol.h" +#include "skillhandler.h" #include "../log.h" diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp index da493302..c5465835 100644 --- a/src/net/tradehandler.cpp +++ b/src/net/tradehandler.cpp @@ -19,10 +19,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "tradehandler.h" - #include "messagein.h" #include "protocol.h" +#include "tradehandler.h" #include "../inventory.h" #include "../item.h" @@ -33,6 +32,8 @@ #include "../gui/confirm_dialog.h" #include "../gui/trade.h" +#include "../utils/gettext.h" + std::string tradePartnerName; /** @@ -87,9 +88,9 @@ void TradeHandler::handleMessage(MessageIn *msg) player_node->setTrading(true); ConfirmDialog *dlg; - dlg = new ConfirmDialog("Request for trade", + dlg = new ConfirmDialog(_("Request for trade"), tradePartnerName + - " wants to trade with you, do you accept?"); + _(" wants to trade with you, do you accept?")); dlg->addActionListener(&listener); } else @@ -103,37 +104,35 @@ void TradeHandler::handleMessage(MessageIn *msg) switch (msg->readInt8()) { case 0: // Too far away - chatWindow->chatLog("Trading isn't possible. " - "Trade partner is too far away.", + chatWindow->chatLog(_("Trading isn't possible. Trade partner is too far away."), BY_SERVER); break; case 1: // Character doesn't exist - chatWindow->chatLog("Trading isn't possible. " - "Character doesn't exist.", + chatWindow->chatLog(_("Trading isn't possible. Character doesn't exist."), BY_SERVER); break; case 2: // Invite request check failed... - chatWindow->chatLog("Trade cancelled due to an " - "unknown reason.", BY_SERVER); + chatWindow->chatLog(_("Trade cancelled due to an unknown reason."), + BY_SERVER); break; case 3: // Trade accepted tradeWindow->reset(); tradeWindow->setCaption( - "Trade: You and " + tradePartnerName); + _("Trade: You and ") + tradePartnerName); tradeWindow->setVisible(true); break; case 4: // Trade cancelled if (player_relations.hasPermission(tradePartnerName, PlayerRelation::SPEECH_LOG)) - chatWindow->chatLog("Trade with " + tradePartnerName + - " cancelled", BY_SERVER); + chatWindow->chatLog(_("Trade with ") + tradePartnerName + + _(" cancelled"), BY_SERVER); // otherwise ignore silently tradeWindow->setVisible(false); player_node->setTrading(false); break; default: // Shouldn't happen as well, but to be sure - chatWindow->chatLog("Unhandled trade cancel packet", + chatWindow->chatLog(_("Unhandled trade cancel packet"), BY_SERVER); break; } @@ -183,19 +182,17 @@ void TradeHandler::handleMessage(MessageIn *msg) break; case 1: // Add item failed - player overweighted - chatWindow->chatLog("Failed adding item. Trade " - "partner is over weighted.", + chatWindow->chatLog(_("Failed adding item. Trade partner is over weighted."), BY_SERVER); break; case 2: - // Add item failed - player has no free slot - chatWindow->chatLog("Failed adding item. Trade " - "partner has no free slot.", - BY_SERVER); - break; + // Add item failed - player has no free slot + chatWindow->chatLog(_("Failed adding item. Trade partner has no free slot."), + BY_SERVER); + break; default: - chatWindow->chatLog("Failed adding item for " - "unknown reason.", BY_SERVER); + chatWindow->chatLog(_("Failed adding item for unknown reason."), + BY_SERVER); break; } } @@ -207,14 +204,14 @@ void TradeHandler::handleMessage(MessageIn *msg) break; case SMSG_TRADE_CANCEL: - chatWindow->chatLog("Trade canceled.", BY_SERVER); + chatWindow->chatLog(_("Trade canceled."), BY_SERVER); tradeWindow->setVisible(false); tradeWindow->reset(); player_node->setTrading(false); break; case SMSG_TRADE_COMPLETE: - chatWindow->chatLog("Trade completed.", BY_SERVER); + chatWindow->chatLog(_("Trade completed."), BY_SERVER); tradeWindow->setVisible(false); tradeWindow->reset(); player_node->setTrading(false); |