diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/accounthandler.cpp | 43 | ||||
-rw-r--r-- | src/connectionhandler.cpp | 10 | ||||
-rw-r--r-- | src/dalstorage.cpp | 10 | ||||
-rw-r--r-- | src/defines.h | 2 |
4 files changed, 47 insertions, 18 deletions
diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp index c7a7dd15..e0250dfc 100644 --- a/src/accounthandler.cpp +++ b/src/accounthandler.cpp @@ -284,6 +284,22 @@ void AccountHandler::processMessage(NetComputer *comp, MessageIn &message) store.flush(computer.getAccount()); // flush changes result.writeByte(ERRMSG_OK); + computer.send(result.getPacket()); + + // Send new characters infos back to client + MessageOut charInfo(APMSG_CHAR_INFO); + int slot = chars.size() - 1; + charInfo.writeByte(slot); + charInfo.writeString(chars[slot]->getName()); + charInfo.writeByte(unsigned(short(chars[slot]->getGender()))); + charInfo.writeByte(chars[slot]->getHairStyle()); + charInfo.writeByte(chars[slot]->getHairColor()); + charInfo.writeByte(chars[slot]->getLevel()); + charInfo.writeShort(chars[slot]->getMoney()); + for (int j = 0; j < NB_RSTAT; ++j) + charInfo.writeShort(chars[slot]->getRawStat(j)); + computer.send(charInfo.getPacket()); + return; } break; @@ -371,7 +387,7 @@ void AccountHandler::processMessage(NetComputer *comp, MessageIn &message) } break; - case PAMSG_CHAR_LIST: + /*case PAMSG_CHAR_LIST: { result.writeShort(APMSG_CHAR_LIST_RESPONSE); @@ -410,7 +426,7 @@ void AccountHandler::processMessage(NetComputer *comp, MessageIn &message) charStats += "."; LOG_INFO(charStats.c_str(), 1); } - break; + break;*/ case PAMSG_ENTER_WORLD: { @@ -533,23 +549,30 @@ AccountHandler::handleLoginMessage(AccountClient &computer, MessageIn &msg) computer.setAccount(acc); reply.writeByte(ERRMSG_OK); + computer.send(reply.getPacket()); // Return information about available characters Players &chars = computer.getAccount()->getCharacters(); - reply.writeByte(chars.size()); LOG_INFO(username << "'s account has " << chars.size() << " character(s).", 1); - + + // Send characters list for (unsigned int i = 0; i < chars.size(); i++) { - reply.writeString(chars[i]->getName()); - reply.writeByte(unsigned(short(chars[i]->getGender()))); - reply.writeByte(chars[i]->getHairStyle()); - reply.writeByte(chars[i]->getHairColor()); - reply.writeByte(chars[i]->getLevel()); - reply.writeShort(chars[i]->getMoney()); + MessageOut charInfo(APMSG_CHAR_INFO); + charInfo.writeByte(i); // Slot + charInfo.writeString(chars[i]->getName()); + charInfo.writeByte(unsigned(short(chars[i]->getGender()))); + charInfo.writeByte(chars[i]->getHairStyle()); + charInfo.writeByte(chars[i]->getHairColor()); + charInfo.writeByte(chars[i]->getLevel()); + charInfo.writeShort(chars[i]->getMoney()); + for (int j = 0; j < NB_RSTAT; ++j) + charInfo.writeShort(chars[i]->getRawStat(j)); + computer.send(charInfo.getPacket()); } + return; } } diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp index 8b4d7a9f..75bfe06e 100644 --- a/src/connectionhandler.cpp +++ b/src/connectionhandler.cpp @@ -119,8 +119,12 @@ void ConnectionHandler::process() case ENET_EVENT_TYPE_RECEIVE: { + // Convert the client IP address to string + // representation + std::string ipaddr = ip4ToString(event.peer->address.host); + LOG_INFO("A packet of length " << event.packet->dataLength << - " was received from " << event.peer->address.host, 2); + " was received from " << ipaddr, 2); NetComputer *comp = (NetComputer *)event.peer->data; @@ -136,10 +140,6 @@ void ConnectionHandler::process() // If the scripting subsystem didn't hook the message // it will be handled by the default message handler. - // Convert the client IP address to string - // representation - std::string ipaddr = ip4ToString(event.peer->address.host); - // Make sure that the packet is big enough (> short) if (event.packet->dataLength >= 2) { Packet *packet = new Packet((char *)event.packet->data, diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp index 349666bf..c158fd53 100644 --- a/src/dalstorage.cpp +++ b/src/dalstorage.cpp @@ -656,8 +656,14 @@ void DALStorage::flush(AccountPtr const &account) sql2 << "select id from " << CHARACTERS_TBL_NAME << " where name = \"" << (*it)->getName() << "\";"; RecordSet const &charInfo = mDb->execSql(sql2.str()); - string_to<unsigned int> toUint; - (*it)->setID(toUint(charInfo(0, 0))); + if (charInfo.isEmpty()) { + (*it)->setID(1); + } + else + { + string_to<unsigned int> toUint; + (*it)->setID(toUint(charInfo(0, 0))); + } } else { sql3 << "update " << CHARACTERS_TBL_NAME << " set name = \"" << (*it)->getName() << "\", " diff --git a/src/defines.h b/src/defines.h index 0c0f95f9..a79ff99e 100644 --- a/src/defines.h +++ b/src/defines.h @@ -124,7 +124,7 @@ enum { APMSG_CHAR_CREATE_RESPONSE = 0x0021, // B error PAMSG_CHAR_DELETE = 0x0022, // B index APMSG_CHAR_DELETE_RESPONSE = 0x0023, // B error - PAMSG_CHAR_LIST = 0x0024, // - + APMSG_CHAR_INFO = 0x0024, // B index, S name, B gender, B hair style, B hair color, B level, W money, W*6 stats, S mapname, W*2 position APMSG_CHAR_LIST_RESPONSE = 0x0025, // B number, { B index, S name, B gender, B hair style, B hair color, B level, W money, W*6 stats, S mapname, W*2 position }* PAMSG_CHAR_SELECT = 0x0026, // B index APMSG_CHAR_SELECT_RESPONSE = 0x0027, // B error, S mapname, W*2 position |