From 3553f1e11f7f4478c4c64192f6455d528c7dffda Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Tue, 28 Dec 2010 00:48:05 +0100 Subject: Made the client handle the characters slots properly for Manaserv. Reviewed-by: Crush. --- src/gui/charcreatedialog.cpp | 10 ++++++++-- src/gui/charselectdialog.cpp | 11 +++++++++-- src/net/manaserv/charhandler.cpp | 6 +++++- src/net/manaserv/protocol.h | 11 ++++++----- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 2db25a35..746295b5 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -156,7 +156,8 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "create") { - if (getName().length() >= 4) + if (Net::getNetworkType() == ServerInfo::MANASERV + || getName().length() >= 4) { // Attempt to create the character mCreateButton->setEnabled(false); @@ -167,7 +168,12 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) atts.push_back((int) mAttributeSlider[i]->getValue()); } - Net::getCharHandler()->newCharacter(getName(), mSlot, + int characterSlot = mSlot; + // On Manaserv, the slots start at 1, so we offset them. + if (Net::getNetworkType() == ServerInfo::MANASERV) + ++characterSlot; + + Net::getCharHandler()->newCharacter(getName(), characterSlot, mFemale->isSelected(), mHairStyle, mHairColor, atts); diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index 1fe7d3ba..42c514ec 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -281,13 +281,20 @@ void CharSelectDialog::setCharacters(const Net::Characters &characters) for (i = characters.begin(); i != i_end; ++i) { Net::Character *character = *i; - if (character->slot >= (int)mCharacterEntries.size()) + + // Slots Number start at 1 for Manaserv, so we offset them by one. + int characterSlot = character->slot; + if (Net::getNetworkType() == ServerInfo::MANASERV + && characterSlot > 0) + --characterSlot; + + if (characterSlot >= (int)mCharacterEntries.size()) { logger->log("Warning: slot out of range: %d", character->slot); continue; } - mCharacterEntries[character->slot]->setCharacter(character); + mCharacterEntries[characterSlot]->setCharacter(character); } } diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp index 6f2b4377..14bf51ed 100644 --- a/src/net/manaserv/charhandler.cpp +++ b/src/net/manaserv/charhandler.cpp @@ -167,6 +167,9 @@ void CharHandler::handleCharacterCreateResponse(Net::MessageIn &msg) Attributes::getAttributeMinimum(), Attributes::getAttributeMaximum()); break; + case CREATE_INVALID_SLOT: + errorMessage = _("Invalid slot number."); + break; default: errorMessage = _("Unknown error."); break; @@ -296,7 +299,7 @@ void CharHandler::chooseCharacter(Net::Character *character) } void CharHandler::newCharacter(const std::string &name, - int /* slot */, + int slot, bool gender, int hairstyle, int hairColor, @@ -308,6 +311,7 @@ void CharHandler::newCharacter(const std::string &name, msg.writeInt8(hairstyle); msg.writeInt8(hairColor); msg.writeInt8(gender); + msg.writeInt8(slot); std::vector::const_iterator it, it_end; for (it = stats.begin(), it_end = stats.end(); it != it_end; it++) diff --git a/src/net/manaserv/protocol.h b/src/net/manaserv/protocol.h index a49b2dd8..2b5efd69 100644 --- a/src/net/manaserv/protocol.h +++ b/src/net/manaserv/protocol.h @@ -53,15 +53,15 @@ enum { APMSG_LOGIN_RESPONSE = 0x0012, // B error, S updatehost, S Client data URL, B Character slots PAMSG_LOGOUT = 0x0013, // - APMSG_LOGOUT_RESPONSE = 0x0014, // B error - PAMSG_CHAR_CREATE = 0x0020, // S name, B hair style, B hair color, B gender, W*6 stats + PAMSG_CHAR_CREATE = 0x0020, // S name, B hair style, B hair color, B gender, B slot, W*6 stats APMSG_CHAR_CREATE_RESPONSE = 0x0021, // B error - PAMSG_CHAR_DELETE = 0x0022, // B index + PAMSG_CHAR_DELETE = 0x0022, // B slot APMSG_CHAR_DELETE_RESPONSE = 0x0023, // B error - // B index, S name, B gender, B hair style, B hair color, W level, + // B slot, S name, B gender, B hair style, B hair color, W level, // W character points, W correction points, // {D attr id, D base value (in 1/256ths) D mod value (in 256ths) }* APMSG_CHAR_INFO = 0x0024, // ^ - PAMSG_CHAR_SELECT = 0x0026, // B index + PAMSG_CHAR_SELECT = 0x0026, // B slot APMSG_CHAR_SELECT_RESPONSE = 0x0027, // B error, B*32 token, S game address, W game port, S chat address, W chat port PAMSG_EMAIL_CHANGE = 0x0030, // S email APMSG_EMAIL_CHANGE_RESPONSE = 0x0031, // B error @@ -307,7 +307,8 @@ enum { CREATE_ATTRIBUTES_TOO_LOW, CREATE_ATTRIBUTES_OUT_OF_RANGE, CREATE_EXISTS_NAME, - CREATE_TOO_MUCH_CHARACTERS + CREATE_TOO_MUCH_CHARACTERS, + CREATE_INVALID_SLOT }; // Character attribute modification specific return value -- cgit v1.2.3-60-g2f50