diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-10-08 02:04:33 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-10-08 02:04:33 +0300 |
commit | 96d877fa2b9bbec546b83cbbc6d16664116e1fb9 (patch) | |
tree | 5b75c3f10217c8515a8e2809892f7526e6efd66f /src | |
parent | 29187a2582c04e3ede63f9c58f09dbbe34834a30 (diff) | |
download | manaverse-96d877fa2b9bbec546b83cbbc6d16664116e1fb9.tar.gz manaverse-96d877fa2b9bbec546b83cbbc6d16664116e1fb9.tar.bz2 manaverse-96d877fa2b9bbec546b83cbbc6d16664116e1fb9.tar.xz manaverse-96d877fa2b9bbec546b83cbbc6d16664116e1fb9.zip |
Add checks and fix code style.
Diffstat (limited to 'src')
-rw-r--r-- | src/net/tmwa/beinghandler.cpp | 14 | ||||
-rw-r--r-- | src/net/tmwa/charserverhandler.cpp | 16 | ||||
-rw-r--r-- | src/net/tmwa/chathandler.cpp | 3 | ||||
-rw-r--r-- | src/net/tmwa/gamehandler.cpp | 11 | ||||
-rw-r--r-- | src/net/tmwa/generalhandler.cpp | 4 | ||||
-rw-r--r-- | src/net/tmwa/generalhandler.h | 2 | ||||
-rw-r--r-- | src/net/tmwa/guildhandler.cpp | 4 | ||||
-rw-r--r-- | src/net/tmwa/inventoryhandler.h | 3 | ||||
-rw-r--r-- | src/net/tmwa/loginhandler.cpp | 8 | ||||
-rw-r--r-- | src/net/tmwa/messageout.cpp | 1 | ||||
-rw-r--r-- | src/net/tmwa/messageout.h | 1 | ||||
-rw-r--r-- | src/net/tmwa/network.cpp | 87 | ||||
-rw-r--r-- | src/net/tmwa/specialhandler.cpp | 3 |
13 files changed, 77 insertions, 80 deletions
diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 845c30f19..02267e20e 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -132,20 +132,16 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) break; case SMSG_SKILL_DAMAGE: - { processSkillDamage(msg); break; - } + case SMSG_BEING_ACTION: - { processBeingAction(msg); break; - } + case SMSG_BEING_SELFEFFECT: - { processBeingSelfEffect(msg); break; - } case SMSG_BEING_EMOTION: processBeingEmotion(msg); @@ -509,13 +505,9 @@ void BeingHandler::processPlayerMoveUpdate(Net::MessageIn &msg, int msgType) if (!guildManager || !GuildManager::getEnableGuildBot()) { if (guild == 0) - { dstBeing->clearGuilds(); - } else - { dstBeing->setGuild(Guild::getGuild(static_cast<short>(guild))); - } } msg.readInt16(); // emblem @@ -659,6 +651,4 @@ void BeingHandler::processPlayerMoveUpdate(Net::MessageIn &msg, int msgType) dstBeing->setMoveTime(); } - - } // namespace TmwAthena diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp index 7aa68e617..03b63aa16 100644 --- a/src/net/tmwa/charserverhandler.cpp +++ b/src/net/tmwa/charserverhandler.cpp @@ -157,7 +157,7 @@ void CharServerHandler::handleMessage(Net::MessageIn &msg) break; default: - break; + break; } } @@ -165,8 +165,11 @@ void CharServerHandler::readPlayerData(Net::MessageIn &msg, Net::Character *character, bool withColors) { + if (!character) + return; + const Token &token = - static_cast<LoginHandler*>(Net::getLoginHandler())->getToken(); + static_cast<LoginHandler*>(Net::getLoginHandler())->getToken(); LocalPlayer *tempPlayer = new LocalPlayer(msg.readInt32(), 0); tempPlayer->setGender(token.sex); @@ -264,6 +267,9 @@ void CharServerHandler::readPlayerData(Net::MessageIn &msg, void CharServerHandler::chooseCharacter(Net::Character *character) { + if (!character) + return; + mSelectedCharacter = character; mCharSelectDialog = 0; @@ -338,10 +344,8 @@ void CharServerHandler::processCharLogin(Net::MessageIn &msg) msg.skip(2); // Length word int slots = msg.readInt16(); if (slots > 0 && slots < 30) - { - loginData.characterSlots - = static_cast<short unsigned int>(slots); - } + loginData.characterSlots = static_cast<short unsigned int>(slots); + bool version = msg.readInt8() == 1 && serverVersion > 0; msg.skip(17); // Unused diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp index 90acf0f90..4e4318595 100644 --- a/src/net/tmwa/chathandler.cpp +++ b/src/net/tmwa/chathandler.cpp @@ -107,7 +107,6 @@ void ChatHandler::talk(const std::string &text) return; std::string mes = player_node->getName() + " : " + text; -// std::string mes = player_node->getName() + "zzzz : " + text; MessageOut outMsg(CMSG_CHAT_MESSAGE); // Added + 1 in order to let eAthena parse admin commands correctly @@ -227,7 +226,7 @@ void ChatHandler::processRaw(MessageOut &outMsg, std::string &line) if (pos != std::string::npos) { unsigned short x = static_cast<unsigned short>( - atoi(data.substr(0, pos).c_str())); + atoi(data.substr(0, pos).c_str())); data = data.substr(pos + 1); pos = line.find(","); if (pos == std::string::npos) diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp index 242e9f9de..adaaa067b 100644 --- a/src/net/tmwa/gamehandler.cpp +++ b/src/net/tmwa/gamehandler.cpp @@ -107,9 +107,16 @@ void GameHandler::connect() if (Client::getState() == STATE_CONNECT_GAME) { - mCharID = player_node->getId(); // Change the player's ID to the account ID to match what eAthena uses - player_node->setId(token.account_ID); + if (player_node) + { + mCharID = player_node->getId(); + player_node->setId(token.account_ID); + } + else + { + mCharID = 0; + } } // Send login infos diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index c6ebc000c..0a9541477 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -143,10 +143,14 @@ void GeneralHandler::handleMessage(Net::MessageIn &msg) break; case 2: if (Client::getState() == STATE_GAME) + { errorMessage = _("Someone else is trying to use this " "account."); + } else + { errorMessage = _("This account is already logged in."); + } break; case 3: errorMessage = _("Speed hack detected."); diff --git a/src/net/tmwa/generalhandler.h b/src/net/tmwa/generalhandler.h index 5e6c9f18f..9ab8d64b4 100644 --- a/src/net/tmwa/generalhandler.h +++ b/src/net/tmwa/generalhandler.h @@ -40,7 +40,7 @@ namespace TmwAthena { class GeneralHandler : public MessageHandler, public Net::GeneralHandler, - public Mana::Listener + public Mana::Listener { public: GeneralHandler(); diff --git a/src/net/tmwa/guildhandler.cpp b/src/net/tmwa/guildhandler.cpp index 640a6fd78..7ea97eb49 100644 --- a/src/net/tmwa/guildhandler.cpp +++ b/src/net/tmwa/guildhandler.cpp @@ -79,8 +79,6 @@ GuildHandler::~GuildHandler() void GuildHandler::handleMessage(Net::MessageIn &msg) { - DEBUGLOG("guild message"); - switch (msg.getId()) { case SMSG_GUILD_CREATE_RESPONSE: @@ -92,10 +90,8 @@ void GuildHandler::handleMessage(Net::MessageIn &msg) break; case SMSG_GUILD_MEMBER_LOGIN: - { processGuildMemberLogin(msg); break; - } case SMSG_GUILD_MASTER_OR_MEMBER: processGuildMasterOrMember(msg); diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h index 9a0978bd0..989ced27a 100644 --- a/src/net/tmwa/inventoryhandler.h +++ b/src/net/tmwa/inventoryhandler.h @@ -59,8 +59,7 @@ class InventoryHandler : public MessageHandler, public Ea::InventoryHandler void closeStorage(int type); - void moveItem(int source, int slot, int amount, - int destination); + void moveItem(int source, int slot, int amount, int destination); }; } // namespace TmwAthena diff --git a/src/net/tmwa/loginhandler.cpp b/src/net/tmwa/loginhandler.cpp index 029c379a0..cac8df623 100644 --- a/src/net/tmwa/loginhandler.cpp +++ b/src/net/tmwa/loginhandler.cpp @@ -146,12 +146,10 @@ ServerInfo *LoginHandler::getCharServer() void LoginHandler::processServerVersion(Net::MessageIn &msg) { - // TODO: verify these! - char b1 = msg.readInt8(); // -1 - char b2 = msg.readInt8(); // T - char b3 = msg.readInt8(); // M - char b4 = msg.readInt8(); // W + char b2 = msg.readInt8(); // E + char b3 = msg.readInt8(); // V + char b4 = msg.readInt8(); // L if (b1 == -1 && b2 == 'E' && b3 == 'V' && b4 == 'L') { unsigned int options = msg.readInt8(); diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp index 6071e0ab6..d5d9d82f9 100644 --- a/src/net/tmwa/messageout.cpp +++ b/src/net/tmwa/messageout.cpp @@ -46,6 +46,7 @@ MessageOut::MessageOut(short id): { mNetwork = TmwAthena::Network::instance(); mData = mNetwork->mOutBuffer + mNetwork->mOutSize; + writeInt16(id); } diff --git a/src/net/tmwa/messageout.h b/src/net/tmwa/messageout.h index 32cb803e2..da86f06f6 100644 --- a/src/net/tmwa/messageout.h +++ b/src/net/tmwa/messageout.h @@ -47,6 +47,7 @@ class MessageOut : public Net::MessageOut MessageOut(short id); void writeInt16(Sint16 value); /**< Writes a short. */ + void writeInt32(Sint32 value); /**< Writes a long. */ /** diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index 8ecf04d36..d98d3fd47 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -42,49 +42,49 @@ short packet_lengths[] = { - 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // #0x0040 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 50, 3, -1, 55, 17, 3, 37, 46, -1, 23, -1, 3, 108, 3, 2, - 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 50, 3, -1, 55, 17, 3, 37, 46, -1, 23, -1, 3, 108, 3, 2, + 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6, // #0x0080 - 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 23, -1, -1, -1, 0, - 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6, - 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6, - 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3, + 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 23, -1, -1, -1, 0, + 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6, + 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6, + 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3, // #0x00C0 - 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 6, 2, 27, - 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1, - 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2, - 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10, + 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 6, 2, 27, + 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1, + 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2, + 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10, // #0x0100 - 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1, - 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16, - 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1, - 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26, + 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1, + 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16, + 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1, + 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26, // #0x0140 - 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6, - 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42, - -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14, 186, 182, - 14, 30, 10, 3, -1, 6, 106, -1, 4, 5, 4, -1, 6, 7, -1, -1, + 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6, + 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42, + -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14, 186, 182, + 14, 30, 10, 3, -1, 6, 106, -1, 4, 5, 4, -1, 6, 7, -1, -1, // #0x0180 - 6, 3, 106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6, - 90, 86, 24, 6, 30, 102, 9, 4, 8, 4, 14, 10, 4, 6, 2, 6, - 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4, - 11, 7, -1, 67, 12, 18, 114, 6, 3, 6, 26, 26, 26, 26, 2, 3, + 6, 3, 106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6, + 90, 86, 24, 6, 30, 102, 9, 4, 8, 4, 14, 10, 4, 6, 2, 6, + 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4, + 11, 7, -1, 67, 12, 18, 114, 6, 3, 6, 26, 26, 26, 26, 2, 3, // #0x01C0 - 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 0, 9, 9, 29, 6, 28, - 8, 14, 10, 35, 6, 8, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6, - 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1, - -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10, + 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 0, 9, 9, 29, 6, 28, + 8, 14, 10, 35, 6, 8, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6, + 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1, + -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10, // #0x0200 - 26, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 19, 10, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - -1,122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 26, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 19, 10, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -1, 122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; const unsigned int BUFFER_SIZE = 655360; @@ -106,7 +106,7 @@ int networkThread(void *data) Network *Network::mInstance = 0; -Network::Network(): +Network::Network() : mSocket(0), mInBuffer(new char[BUFFER_SIZE]), mOutBuffer(new char[BUFFER_SIZE]), @@ -153,8 +153,8 @@ bool Network::connect(ServerInfo server) return false; } - logger->log("Network::Connecting to %s:%i", server.hostname.c_str(), - server.port); + logger->log("Network::Connecting to %s:%i", + server.hostname.c_str(), server.port); mServer.hostname = server.hostname; mServer.port = server.port; @@ -263,7 +263,7 @@ void Network::flush() if (ret < static_cast<int>(mOutSize)) { setError("Error in SDLNet_TCP_Send(): " + - std::string(SDLNet_GetError())); + std::string(SDLNet_GetError())); } mOutSize = 0; SDL_mutexV(mMutex); @@ -308,7 +308,6 @@ bool Network::messageReady() if (len == -1 && mInSize > 4) len = readWord(2); - } bool ret = (mInSize >= static_cast<unsigned int>(len)); @@ -354,7 +353,7 @@ bool Network::realConnect() mServer.port) == -1) { std::string errorMessage = _("Unable to resolve host \"") + - mServer.hostname + "\""; + mServer.hostname + "\""; setError(errorMessage); logger->log("SDLNet_ResolveHost: %s", errorMessage.c_str()); return false; @@ -371,7 +370,7 @@ bool Network::realConnect() } logger->log("Network::Started session with %s:%i", - ipToString(ipAddress.host), ipAddress.port); + ipToString(ipAddress.host), ipAddress.port); mState = CONNECTED; @@ -385,14 +384,14 @@ void Network::receive() if (!(set = SDLNet_AllocSocketSet(1))) { setError("Error in SDLNet_AllocSocketSet(): " + - std::string(SDLNet_GetError())); + std::string(SDLNet_GetError())); return; } if (SDLNet_TCP_AddSocket(set, mSocket) == -1) { setError("Error in SDLNet_AddSocket(): " + - std::string(SDLNet_GetError())); + std::string(SDLNet_GetError())); } while (mState == CONNECTED) diff --git a/src/net/tmwa/specialhandler.cpp b/src/net/tmwa/specialhandler.cpp index 509c5ecd1..c75d954dc 100644 --- a/src/net/tmwa/specialhandler.cpp +++ b/src/net/tmwa/specialhandler.cpp @@ -53,10 +53,9 @@ void SpecialHandler::handleMessage(Net::MessageIn &msg) switch (msg.getId()) { case SMSG_PLAYER_SKILLS: - { processPlayerSkills(msg); break; - } + case SMSG_PLAYER_SKILL_UP: processPlayerSkillUp(msg); break; |