diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-04-27 23:56:42 +0200 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-04-27 23:56:42 +0200 |
commit | 3179b1c83663e51dd594fbaf926d8122b355c747 (patch) | |
tree | 57d9d318df0a6f013163008356a3ab06564bbda4 | |
parent | 5bfc376d1cee0f941657a771b87a3ee030d31c56 (diff) | |
download | manaserv-3179b1c83663e51dd594fbaf926d8122b355c747.tar.gz manaserv-3179b1c83663e51dd594fbaf926d8122b355c747.tar.bz2 manaserv-3179b1c83663e51dd594fbaf926d8122b355c747.tar.xz manaserv-3179b1c83663e51dd594fbaf926d8122b355c747.zip |
Revert "Hacked away the selection of attributes at char creation"
This reverts commit d9d5ebbcd623e97f9b13a9c1046b08be34e1302e.
Conflicts:
src/account-server/accounthandler.cpp
-rw-r--r-- | src/account-server/accounthandler.cpp | 103 |
1 files changed, 66 insertions, 37 deletions
diff --git a/src/account-server/accounthandler.cpp b/src/account-server/accounthandler.cpp index 70984cc1..76a427ea 100644 --- a/src/account-server/accounthandler.cpp +++ b/src/account-server/accounthandler.cpp @@ -346,7 +346,7 @@ void AccountHandler::handleLoginMessage(AccountClient &client, MessageIn &msg) // Check whether the last login attempt for this IP is still too fresh const int address = client.getIP(); - const time_t now = time(nullptr); + const time_t now = time(NULL); IPsToTime::const_iterator it = mLastLoginAttemptForIP.find(address); if (it != mLastLoginAttemptForIP.end()) { @@ -693,7 +693,8 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, // Avoid creation of character from old clients. int slot = -1; - slot = msg.readInt8(); + if (msg.getUnreadLength() > 7) + slot = msg.readInt8(); MessageOut reply(APMSG_CHAR_CREATE_RESPONSE); @@ -759,48 +760,76 @@ void AccountHandler::handleCharacterCreateMessage(AccountClient &client, // Customization of character's attributes... std::vector<int> attributes = std::vector<int>(mModifiableAttributes.size(), 0); for (unsigned i = 0; i < mModifiableAttributes.size(); ++i) - attributes[i] = 5; + attributes[i] = msg.readInt16(); - CharacterData *newCharacter = new CharacterData(name); - - // Set the initial attributes provided by the client + int totalAttributes = 0; for (unsigned i = 0; i < mModifiableAttributes.size(); ++i) { - newCharacter->mAttributes.insert( - std::make_pair(mModifiableAttributes.at(i), attributes[i])); + // For good total attributes check. + totalAttributes += attributes.at(i); + + // For checking if all stats are >= min and <= max. + if (attributes.at(i) < mAttributeMinimum + || attributes.at(i) > mAttributeMaximum) + { + reply.writeInt8(CREATE_ATTRIBUTES_OUT_OF_RANGE); + client.send(reply); + return; + } } - newCharacter->mAttributes.insert(mDefaultAttributes.begin(), - mDefaultAttributes.end()); - newCharacter->setAccount(acc); - newCharacter->setCharacterSlot(slot); - newCharacter->setGender(gender); - newCharacter->setHairStyle(hairStyle); - newCharacter->setHairColor(hairColor); - newCharacter->setMapId(Configuration::getValue("char_startMap", 1)); - Point startingPos(Configuration::getValue("char_startX", 1024), - Configuration::getValue("char_startY", 1024)); - newCharacter->setPosition(startingPos); - acc->addCharacter(newCharacter); - - LOG_INFO("Character " << name << " was created for " - << acc->getName() << "'s account."); - - storage->flush(acc); // flush changes - - // log transaction - Transaction trans; - trans.mCharacterId = newCharacter->getDatabaseID(); - trans.mAction = TRANS_CHAR_CREATE; - trans.mMessage = acc->getName() + " created character "; - trans.mMessage.append("called " + name); - storage->addTransaction(trans); + if (totalAttributes > mStartingPoints) + { + reply.writeInt8(CREATE_ATTRIBUTES_TOO_HIGH); + } + else if (totalAttributes < mStartingPoints) + { + reply.writeInt8(CREATE_ATTRIBUTES_TOO_LOW); + } + else + { + CharacterData *newCharacter = new CharacterData(name); - reply.writeInt8(ERRMSG_OK); - client.send(reply); + // Set the initial attributes provided by the client + for (unsigned i = 0; i < mModifiableAttributes.size(); ++i) + { + newCharacter->mAttributes.insert( + std::make_pair(mModifiableAttributes.at(i), attributes[i])); + } - // Send new characters infos back to client - sendCharacterData(client, *chars[slot]); + newCharacter->mAttributes.insert(mDefaultAttributes.begin(), + mDefaultAttributes.end()); + newCharacter->setAccount(acc); + newCharacter->setCharacterSlot(slot); + newCharacter->setGender(gender); + newCharacter->setHairStyle(hairStyle); + newCharacter->setHairColor(hairColor); + newCharacter->setMapId(Configuration::getValue("char_startMap", 1)); + Point startingPos(Configuration::getValue("char_startX", 1024), + Configuration::getValue("char_startY", 1024)); + newCharacter->setPosition(startingPos); + acc->addCharacter(newCharacter); + + LOG_INFO("Character " << name << " was created for " + << acc->getName() << "'s account."); + + storage->flush(acc); // flush changes + + // log transaction + Transaction trans; + trans.mCharacterId = newCharacter->getDatabaseID(); + trans.mAction = TRANS_CHAR_CREATE; + trans.mMessage = acc->getName() + " created character "; + trans.mMessage.append("called " + name); + storage->addTransaction(trans); + + reply.writeInt8(ERRMSG_OK); + client.send(reply); + + // Send new characters infos back to client + sendCharacterData(client, *chars[slot]); + return; + } } client.send(reply); |