diff options
Diffstat (limited to 'src/net')
28 files changed, 257 insertions, 133 deletions
diff --git a/src/net/download.cpp b/src/net/download.cpp index 7aab3b2f..571af7a4 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -108,13 +108,13 @@ bool Download::start() { assert(!mThread); // Download already started - logger->log("Starting download: %s", mUrl.c_str()); + Log::info("Starting download: %s", mUrl.c_str()); mThread = SDL_CreateThread(downloadThread, "Download", this); if (!mThread) { - logger->log("%s", DOWNLOAD_ERROR_MESSAGE_THREAD); + Log::info("%s", DOWNLOAD_ERROR_MESSAGE_THREAD); strncpy(mError, DOWNLOAD_ERROR_MESSAGE_THREAD, CURL_ERROR_SIZE - 1); mState.lock()->status = DownloadStatus::Error; return false; @@ -125,7 +125,7 @@ bool Download::start() void Download::cancel() { - logger->log("Canceling download: %s", mUrl.c_str()); + Log::info("Canceling download: %s", mUrl.c_str()); mCancel = true; } @@ -186,7 +186,7 @@ int Download::downloadThread(void *ptr) if (!curl) break; - logger->log("Downloading: %s", d->mUrl.c_str()); + Log::info("Downloading: %s", d->mUrl.c_str()); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, d->mHeaders); @@ -236,8 +236,8 @@ int Download::downloadThread(void *ptr) if (res != CURLE_OK) { - logger->log("curl error %d: %s host: %s", - res, d->mError, d->mUrl.c_str()); + Log::info("curl error %d: %s host: %s", + res, d->mError, d->mUrl.c_str()); if (file) { @@ -262,9 +262,9 @@ int Download::downloadThread(void *ptr) // Remove the corrupted file ::remove(outFilename.c_str()); - logger->log("Checksum for file %s failed: (%lx/%lx)", - d->mFileName.c_str(), - adler, *d->mAdler); + Log::info("Checksum for file %s failed: (%lx/%lx)", + d->mFileName.c_str(), + adler, *d->mAdler); continue; // Bail out here to avoid the renaming } diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp index 98591669..cc0ea17e 100644 --- a/src/net/manaserv/charhandler.cpp +++ b/src/net/manaserv/charhandler.cpp @@ -264,10 +264,10 @@ void CharHandler::handleCharacterSelectResponse(MessageIn &msg) chatServer.hostname.assign(msg.readString()); chatServer.port = msg.readInt16(); - logger->log("Game server: %s:%d", gameServer.hostname.c_str(), - gameServer.port); - logger->log("Chat server: %s:%d", chatServer.hostname.c_str(), - chatServer.port); + Log::info("Game server: %s:%d", gameServer.hostname.c_str(), + gameServer.port); + Log::info("Chat server: %s:%d", chatServer.hostname.c_str(), + chatServer.port); // Prevent the selected local player from being deleted local_player = mSelectedCharacter->dummy; diff --git a/src/net/manaserv/chathandler.cpp b/src/net/manaserv/chathandler.cpp index dca556c2..436da820 100644 --- a/src/net/manaserv/chathandler.cpp +++ b/src/net/manaserv/chathandler.cpp @@ -158,8 +158,8 @@ void ChatHandler::handleGameChatMessage(MessageIn &msg) if (!being) { - logger->log("Warning: Received GPMSG_SAY for unknown being with id %i." - " (Message is: %s)", id, chatMsg.c_str()); + Log::warn("Received GPMSG_SAY for unknown being with id %i." + " (Message is: %s)", id, chatMsg.c_str()); return; } @@ -262,7 +262,7 @@ void ChatHandler::handleChatMessage(MessageIn &msg) else { // Can't find channel - logger->log("Couldn't find chat channel id: %hi", channelId); + Log::info("Couldn't find chat channel id: %hi", channelId); } } diff --git a/src/net/manaserv/connection.cpp b/src/net/manaserv/connection.cpp index 1b6f757a..2eb5b4bf 100644 --- a/src/net/manaserv/connection.cpp +++ b/src/net/manaserv/connection.cpp @@ -44,13 +44,13 @@ Connection::~Connection() bool Connection::connect(const std::string &address, enet_uint16 port) { - logger->log("Net::Connection::connect(%s, %i)", address.c_str(), port); + Log::info("Net::Connection::connect(%s, %i)", address.c_str(), port); if (mConnection) disconnect(); if (address.empty()) { - logger->log("Net::Connection::connect() got empty address!"); + Log::info("Net::Connection::connect() got empty address!"); mState = NET_ERROR; return false; } @@ -65,7 +65,7 @@ bool Connection::connect(const std::string &address, enet_uint16 port) if (!mConnection) { - logger->log("Unable to initiate connection to the server."); + Log::info("Unable to initiate connection to the server."); mState = NET_ERROR; return false; } @@ -96,7 +96,7 @@ void Connection::send(const ManaServ::MessageOut &msg) { if (!isConnected()) { - logger->log("Warning: cannot send message to not connected server!"); + Log::warn("Cannot send message to not connected server!"); return; } diff --git a/src/net/manaserv/effecthandler.cpp b/src/net/manaserv/effecthandler.cpp index 22d1f9cf..afd7cd5c 100644 --- a/src/net/manaserv/effecthandler.cpp +++ b/src/net/manaserv/effecthandler.cpp @@ -82,7 +82,7 @@ void EffectHandler::handleCreateEffectBeing(MessageIn &msg) if (b) effectManager->trigger(eid, b); else - logger->log("Warning: CreateEffect called for unknown being #%d", bid); + Log::warn("CreateEffect called for unknown being #%d", bid); } void EffectHandler::handleCreateTextParticle(MessageIn &msg) @@ -120,7 +120,7 @@ void EffectHandler::handleShake(MessageIn &msg) viewport->shakeScreen(intensityX, intensityY, decay, duration); break; default: - logger->log("Warning: Received GPMSG_SHAKE message with unexpected length of %d bytes", msg.getUnreadLength()); + Log::warn("Received GPMSG_SHAKE message with unexpected length of %d bytes", msg.getUnreadLength()); } } diff --git a/src/net/manaserv/guildhandler.cpp b/src/net/manaserv/guildhandler.cpp index 9fdbafc2..bae38c37 100644 --- a/src/net/manaserv/guildhandler.cpp +++ b/src/net/manaserv/guildhandler.cpp @@ -73,7 +73,7 @@ void GuildHandler::handleMessage(MessageIn &msg) { case CPMSG_GUILD_CREATE_RESPONSE: { - logger->log("Received CPMSG_GUILD_CREATE_RESPONSE"); + Log::info("Received CPMSG_GUILD_CREATE_RESPONSE"); if (msg.readInt8() == ERRMSG_OK) { // TODO - Acknowledge guild was created @@ -88,7 +88,7 @@ void GuildHandler::handleMessage(MessageIn &msg) case CPMSG_GUILD_INVITE_RESPONSE: { - logger->log("Received CPMSG_GUILD_INVITE_RESPONSE"); + Log::info("Received CPMSG_GUILD_INVITE_RESPONSE"); const unsigned char response = msg.readInt8(); if (response == ERRMSG_OK) { @@ -111,7 +111,7 @@ void GuildHandler::handleMessage(MessageIn &msg) case CPMSG_GUILD_ACCEPT_RESPONSE: { - logger->log("Received CPMSG_GUILD_ACCEPT_RESPONSE"); + Log::info("Received CPMSG_GUILD_ACCEPT_RESPONSE"); if (msg.readInt8() == ERRMSG_OK) { // TODO - Acknowledge accepted into guild @@ -121,7 +121,7 @@ void GuildHandler::handleMessage(MessageIn &msg) case CPMSG_GUILD_GET_MEMBERS_RESPONSE: { - logger->log("Received CPMSG_GUILD_GET_MEMBERS_RESPONSE"); + Log::info("Received CPMSG_GUILD_GET_MEMBERS_RESPONSE"); if (msg.readInt8() == ERRMSG_OK) { std::string name; @@ -152,7 +152,7 @@ void GuildHandler::handleMessage(MessageIn &msg) case CPMSG_GUILD_UPDATE_LIST: { - logger->log("Received CPMSG_GUILD_UPDATE_LIST"); + Log::info("Received CPMSG_GUILD_UPDATE_LIST"); short guildId = msg.readInt16(); std::string name = msg.readString(); char eventId = msg.readInt8(); @@ -189,14 +189,14 @@ void GuildHandler::handleMessage(MessageIn &msg) break; default: - logger->log("Invalid guild event"); + Log::info("Invalid guild event"); } } } break; case CPMSG_GUILD_INVITED: { - logger->log("Received CPMSG_GUILD_INVITED"); + Log::info("Received CPMSG_GUILD_INVITED"); std::string inviterName = msg.readString(); std::string guildName = msg.readString(); int guildId = msg.readInt16(); @@ -207,7 +207,7 @@ void GuildHandler::handleMessage(MessageIn &msg) case CPMSG_GUILD_PROMOTE_MEMBER_RESPONSE: { - logger->log("Received CPMSG_GUILD_PROMOTE_MEMBER_RESPONSE"); + Log::info("Received CPMSG_GUILD_PROMOTE_MEMBER_RESPONSE"); if (msg.readInt8() == ERRMSG_OK) { @@ -223,14 +223,14 @@ void GuildHandler::handleMessage(MessageIn &msg) case CPMSG_GUILD_REJOIN: { - logger->log("Received CPMSG_GUILD_REJOIN"); + Log::info("Received CPMSG_GUILD_REJOIN"); joinedGuild(msg); } break; case CPMSG_GUILD_QUIT_RESPONSE: { - logger->log("Received CPMSG_GUILD_QUIT_RESPONSE"); + Log::info("Received CPMSG_GUILD_QUIT_RESPONSE"); if (msg.readInt8() == ERRMSG_OK) { @@ -247,7 +247,7 @@ void GuildHandler::handleMessage(MessageIn &msg) } break; case CPMSG_GUILD_KICK_NOTIFICATION: { - logger->log("Received CPMSG_GUILD_KICK_NOTIFICATION"); + Log::info("Received CPMSG_GUILD_KICK_NOTIFICATION"); const int guildId = msg.readInt16(); std::string player = msg.readString(); diff --git a/src/net/manaserv/inventoryhandler.cpp b/src/net/manaserv/inventoryhandler.cpp index 58a495af..fa31b32a 100644 --- a/src/net/manaserv/inventoryhandler.cpp +++ b/src/net/manaserv/inventoryhandler.cpp @@ -88,9 +88,8 @@ void EquipBackend::equip(int inventorySlot, int equipmentSlot) auto slotIt = mSlots.find(equipmentSlot); if (slotIt == mSlots.end()) { - logger->log("ManaServ::EquipBackend: Equipment slot %i" - " is not existing.", - equipmentSlot); + Log::info("ManaServ::EquipBackend: Equipment slot %i" + " is not existing.", equipmentSlot); return; } @@ -115,8 +114,8 @@ void EquipBackend::unequip(int inventorySlot) } } - logger->log("ManaServ::EquipBackend: No equipped item found at inventory " - "slot %i!", inventorySlot); + Log::info("ManaServ::EquipBackend: No equipped item found at inventory " + "slot %i!", inventorySlot); } void EquipBackend::event(Event::Channel, const Event &event) @@ -134,8 +133,8 @@ void EquipBackend::readEquipFile() if (!rootNode || rootNode.name() != "equip-slots") { - logger->log("ManaServ::EquipBackend: Error while reading " - EQUIP_FILE "!"); + Log::info("ManaServ::EquipBackend: Error while reading " + EQUIP_FILE "!"); return; } diff --git a/src/net/manaserv/loginhandler.cpp b/src/net/manaserv/loginhandler.cpp index 1c398990..9828af29 100644 --- a/src/net/manaserv/loginhandler.cpp +++ b/src/net/manaserv/loginhandler.cpp @@ -342,7 +342,7 @@ void LoginHandler::readServerInfo(MessageIn &msg) if (!updateHost.empty()) mLoginData->updateHost = updateHost; else - logger->log("Warning: server does not have an update host set!"); + Log::warn("Server does not have an update host set!"); // Read the client data folder for dynamic data loading. // This is only used by the Qt client. diff --git a/src/net/manaserv/network.cpp b/src/net/manaserv/network.cpp index d69d3397..cb9f76a0 100644 --- a/src/net/manaserv/network.cpp +++ b/src/net/manaserv/network.cpp @@ -48,14 +48,14 @@ void initialize() { if (enet_initialize()) { - logger->error("Failed to initialize ENet."); + Log::critical("Failed to initialize ENet."); } client = enet_host_create(nullptr, 3, 0, 0, 0); if (!client) { - logger->error("Failed to create the local host."); + Log::critical("Failed to create the local host."); } } @@ -66,7 +66,7 @@ void finalize() if (connections) { - logger->error("Tried to shutdown the network subsystem while there " + Log::critical("Tried to shutdown the network subsystem while there " "are network connections left!"); } @@ -78,7 +78,7 @@ Connection *getConnection() { if (!client) { - logger->error("Tried to instantiate a network object before " + Log::critical("Tried to instantiate a network object before " "initializing the network subsystem!"); } @@ -117,14 +117,14 @@ namespace if (iter != mMessageHandlers.end()) { - //logger->log("Received packet %x (%i B)", - // msg.getId(), msg.getLength()); + //Log::info("Received packet %x (%i B)", + // msg.getId(), msg.getLength()); iter->second->handleMessage(msg); } else { - logger->log("Unhandled packet %x (%i B)", - msg.getId(), msg.getLength()); + Log::info("Unhandled packet %x (%i B)", + msg.getId(), msg.getLength()); } // Clean up the packet now that we're done using it. @@ -142,7 +142,7 @@ void flush() switch (event.type) { case ENET_EVENT_TYPE_CONNECT: - logger->log("Connected to port %d.", event.peer->address.port); + Log::info("Connected to port %d.", event.peer->address.port); // Store any relevant server information here. event.peer->data = nullptr; break; @@ -152,7 +152,7 @@ void flush() break; case ENET_EVENT_TYPE_DISCONNECT: - logger->log("Disconnected."); + Log::info("Disconnected."); // Reset the server information. event.peer->data = nullptr; break; diff --git a/src/net/manaserv/partyhandler.cpp b/src/net/manaserv/partyhandler.cpp index e2a021cd..23ea7aa5 100644 --- a/src/net/manaserv/partyhandler.cpp +++ b/src/net/manaserv/partyhandler.cpp @@ -103,7 +103,7 @@ void PartyHandler::handleMessage(MessageIn &msg) "inviter has left the game.")); break; default: - logger->log("Unknown CPMSG_PARTY_INVITE_ANSWER_RESPONSE."); + Log::info("Unknown CPMSG_PARTY_INVITE_ANSWER_RESPONSE."); break; } } break; @@ -161,7 +161,7 @@ void PartyHandler::handleMessage(MessageIn &msg) name.c_str())); break; default: - logger->log("Unknown CPMSG_PARTY_REJECTED."); + Log::info("Unknown CPMSG_PARTY_REJECTED."); break; } } break; diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index 8ee9ed80..edae6be6 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -96,7 +96,7 @@ void PlayerHandler::handleMessage(MessageIn &msg) netToken = msg.readString(32); std::string address = msg.readString(); int port = msg.readInt16(); - logger->log("Changing server to %s:%d", address.c_str(), port); + Log::info("Changing server to %s:%d", address.c_str(), port); gameServer.hostname = address; gameServer.port = port; @@ -147,14 +147,14 @@ void PlayerHandler::handleMessage(MessageIn &msg) } break; case ATTRIBMOD_INVALID_ATTRIBUTE: { - logger->log("Warning: Server denied increase of attribute %d (unknown attribute) ", attrNum); + Log::warn("Server denied increase of attribute %d (unknown attribute) ", attrNum); } break; case ATTRIBMOD_NO_POINTS_LEFT: { // when the server says "you got no points" it // has to be correct. The server is always right! // undo attribute change and set points to 0 - logger->log("Warning: Server denied increase of attribute %d (no points left) ", attrNum); + Log::warn("Server denied increase of attribute %d (no points left) ", attrNum); int attrValue = PlayerInfo::getStatBase(attrNum) - 1; PlayerInfo::setAttribute(CHAR_POINTS, 0); PlayerInfo::setStatBase(attrNum, attrValue); @@ -162,7 +162,7 @@ void PlayerHandler::handleMessage(MessageIn &msg) case ATTRIBMOD_DENIED: { // undo attribute change - logger->log("Warning: Server denied increase of attribute %d (reason unknown) ", attrNum); + Log::warn("Server denied increase of attribute %d (reason unknown) ", attrNum); int points = PlayerInfo::getAttribute(CHAR_POINTS) - 1; PlayerInfo::setAttribute(CHAR_POINTS, points); @@ -184,14 +184,14 @@ void PlayerHandler::handleMessage(MessageIn &msg) } break; case ATTRIBMOD_INVALID_ATTRIBUTE: { - logger->log("Warning: Server denied reduction of attribute %d (unknown attribute) ", attrNum); + Log::warn("Server denied reduction of attribute %d (unknown attribute) ", attrNum); } break; case ATTRIBMOD_NO_POINTS_LEFT: { // when the server says "you got no points" it // has to be correct. The server is always right! // undo attribute change and set points to 0 - logger->log("Warning: Server denied reduction of attribute %d (no points left) ", attrNum); + Log::warn("Server denied reduction of attribute %d (no points left) ", attrNum); int attrValue = PlayerInfo::getStatBase(attrNum) + 1; // TODO are these right? PlayerInfo::setAttribute(CHAR_POINTS, 0); @@ -201,7 +201,7 @@ void PlayerHandler::handleMessage(MessageIn &msg) case ATTRIBMOD_DENIED: { // undo attribute change - logger->log("Warning: Server denied reduction of attribute %d (reason unknown) ", attrNum); + Log::warn("Server denied reduction of attribute %d (reason unknown) ", attrNum); int charaPoints = PlayerInfo::getAttribute(CHAR_POINTS) - 1; PlayerInfo::setAttribute(CHAR_POINTS, charaPoints); @@ -245,7 +245,7 @@ void PlayerHandler::handleMessage(MessageIn &msg) BY_SERVER); break; default: - logger->log("0x013b: Unhandled message %i", type); + Log::info("0x013b: Unhandled message %i", type); break; } } @@ -263,7 +263,7 @@ void PlayerHandler::handleMapChangeMessage(MessageIn &msg) Game *game = Game::instance(); const bool sameMap = (game->getCurrentMapName() == mapName); - logger->log("Changing map to %s (%d, %d)", mapName.c_str(), x, y); + Log::info("Changing map to %s (%d, %d)", mapName.c_str(), x, y); // Switch the actual map, deleting the previous one game->changeMap(mapName); @@ -285,8 +285,8 @@ void PlayerHandler::handleMapChangeMessage(MessageIn &msg) local_player->setPosition(x, y); local_player->setDestination(x, y); - logger->log("Adjust scrolling by %d,%d", (int) scrollOffsetX, - (int) scrollOffsetY); + Log::info("Adjust scrolling by %d,%d", (int) scrollOffsetX, + (int) scrollOffsetY); viewport->scrollBy(scrollOffsetX, scrollOffsetY); } @@ -295,7 +295,7 @@ void PlayerHandler::attack(int id) auto ability = AbilityDB::find("Strike"); if (!ability) { - logger->log("PlayerHandler::attack: 'Strike' ability not found."); + Log::info("PlayerHandler::attack: 'Strike' ability not found."); return; } @@ -304,7 +304,7 @@ void PlayerHandler::attack(int id) abilityHandler->useOn(ability->id, id); break; case AbilityInfo::TARGET_POINT: - logger->log("PlayerHandler::attack: Unsupported target mode 'point' for 'Strike' ability."); + Log::info("PlayerHandler::attack: Unsupported target mode 'point' for 'Strike' ability."); break; case AbilityInfo::TARGET_DIRECTION: abilityHandler->useInDirection(ability->id, local_player->getDirection()); @@ -420,8 +420,8 @@ Vector PlayerHandler::getPixelsPerSecondMoveSpeed(const Vector &speed, Map *map) if (!map) { - logger->log("Manaserv::PlayerHandler: Speed wasn't given back" - " because Map not initialized."); + Log::info("Manaserv::PlayerHandler: Speed wasn't given back" + " because Map not initialized."); return speedInPixels; } diff --git a/src/net/net.cpp b/src/net/net.cpp index 1d157b3d..443a739c 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -138,7 +138,7 @@ void connectToServer(ServerInfo &server) else if (server.port == 9601) server.type = ServerType::ManaServ; else - logger->error(_("Unknown Server Type! Exiting.")); + Log::critical(_("Unknown Server Type! Exiting.")); } if (networkType == server.type && getGeneralHandler() != nullptr) @@ -160,7 +160,7 @@ void connectToServer(ServerInfo &server) generalHandler = new TmwAthena::GeneralHandler; break; default: - logger->error(_("Server protocol unsupported")); + Log::critical(_("Server protocol unsupported")); break; } @@ -203,4 +203,3 @@ ServerType getNetworkType() } } // namespace Net - diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h index b9cf1abf..e5b86b2e 100644 --- a/src/net/playerhandler.h +++ b/src/net/playerhandler.h @@ -24,6 +24,8 @@ #include "being.h" #include "flooritem.h" +#include "resources/questdb.h" + namespace Net { class PlayerHandler @@ -80,6 +82,11 @@ class PlayerHandler * Return false when tiles-center positions only are to be used. */ virtual bool usePixelPrecision() = 0; + + const QuestVars &getQuestVars() const { return mQuestVars; } + + protected: + QuestVars mQuestVars; }; } // namespace Net diff --git a/src/net/tmwa/abilityhandler.cpp b/src/net/tmwa/abilityhandler.cpp index ab891b40..fea492ef 100644 --- a/src/net/tmwa/abilityhandler.cpp +++ b/src/net/tmwa/abilityhandler.cpp @@ -129,7 +129,7 @@ void AbilityHandler::handleMessage(MessageIn &msg) auto type = msg.readInt8(); if (btype == BSKILL_EMOTE) { - logger->log("Action: %d", btype); + Log::info("Action: %d", btype); } std::string msg; diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index c5979e9f..690b0d87 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -33,9 +33,9 @@ #include "playerrelations.h" #include "net/net.h" -#include "net/playerhandler.h" #include "net/tmwa/messagein.h" #include "net/tmwa/messageout.h" +#include "net/tmwa/playerhandler.h" #include "net/tmwa/protocol.h" #include "resources/emotedb.h" @@ -107,6 +107,12 @@ static Being *createBeing(int id, short job) outMsg.writeInt32(id); } + if (type == ActorSprite::NPC) + { + auto playerHandler = static_cast<TmwAthena::PlayerHandler*>(Net::getPlayerHandler()); + playerHandler->applyQuestStatusEffects(being); + } + return being; } @@ -525,8 +531,8 @@ void BeingHandler::handleMessage(MessageIn &msg) dstBeing->setSprite(SPRITE_MISC2, id); break; default: - logger->log("SMSG_BEING_CHANGE_LOOKS2: unsupported type: " - "%d, id: %d", static_cast<int>(type), id); + Log::info("SMSG_BEING_CHANGE_LOOKS2: unsupported type: " + "%d, id: %d", static_cast<int>(type), id); break; } } diff --git a/src/net/tmwa/buysellhandler.cpp b/src/net/tmwa/buysellhandler.cpp index 1fdf1ffe..d7acd674 100644 --- a/src/net/tmwa/buysellhandler.cpp +++ b/src/net/tmwa/buysellhandler.cpp @@ -99,7 +99,7 @@ void BuySellHandler::handleMessage(MessageIn &msg) Item *item = PlayerInfo::getInventory()->getItem(index); - if (item && !(item->isEquipped())) + if (item && !item->isEquipped()) dialog->addItem(item, value); } } diff --git a/src/net/tmwa/charserverhandler.cpp b/src/net/tmwa/charserverhandler.cpp index 0ecbb135..fcd47b74 100644 --- a/src/net/tmwa/charserverhandler.cpp +++ b/src/net/tmwa/charserverhandler.cpp @@ -89,8 +89,8 @@ void CharServerHandler::handleMessage(MessageIn &msg) auto *character = new Net::Character; readPlayerData(msg, character); mCharacters.push_back(character); - logger->log("CharServer: Player: %s (%d)", - character->dummy->getName().c_str(), character->slot); + Log::info("CharServer: Player: %s (%d)", + character->dummy->getName().c_str(), character->slot); } Client::setState(STATE_CHAR_SELECT); diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp index 0a3bb9d9..a88e377e 100644 --- a/src/net/tmwa/gamehandler.cpp +++ b/src/net/tmwa/gamehandler.cpp @@ -68,8 +68,8 @@ void GameHandler::handleMessage(MessageIn &msg) msg.readInt32(); // server tick msg.readCoordinates(x, y, direction); msg.skip(2); // unknown - logger->log("Protocol: Player start position: (%d, %d), Direction: %d", - x, y, direction); + Log::info("Protocol: Player start position: (%d, %d), Direction: %d", + x, y, direction); // Switch now or we'll have problems Client::setState(STATE_GAME); // Stores the position until the map is loaded. diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index d6eb3b34..1f52c3db 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -117,7 +117,7 @@ void GeneralHandler::handleMessage(MessageIn &msg) { case SMSG_CONNECTION_PROBLEM: code = msg.readInt8(); - logger->log("Connection problem: %i", code); + Log::info("Connection problem: %i", code); switch (code) { diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp index 0d8e3005..73d967a6 100644 --- a/src/net/tmwa/inventoryhandler.cpp +++ b/src/net/tmwa/inventoryhandler.cpp @@ -157,10 +157,10 @@ void InventoryHandler::handleMessage(MessageIn &msg) if (debugInventory) { - 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]); + Log::info("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]); } if (msg.getId() == SMSG_PLAYER_INVENTORY) @@ -191,10 +191,10 @@ void InventoryHandler::handleMessage(MessageIn &msg) if (debugInventory) { - 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]); + Log::info("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]); } mInventoryItems.push_back( @@ -419,8 +419,8 @@ void InventoryHandler::handleMessage(MessageIn &msg) } else { - logger->log("Couldn't set attacke range due to the lack" - "of an initialized map."); + Log::info("Couldn't set attacke range due to the lack" + "of an initialized map."); local_player->setAttackRange(-1); } } @@ -434,7 +434,7 @@ void InventoryHandler::handleMessage(MessageIn &msg) index -= INVENTORY_OFFSET; - logger->log("Arrows equipped: %i", index); + Log::info("Arrows equipped: %i", index); mEquips.setEquipment(EQUIP_PROJECTILE_SLOT, index); break; } diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h index f5ef4492..cde1235b 100644 --- a/src/net/tmwa/inventoryhandler.h +++ b/src/net/tmwa/inventoryhandler.h @@ -108,9 +108,9 @@ class EquipBackend final : public Equipment::Backend if (!newItem && inventoryIndex >= 0) { - logger->log("EquipBackend: Warning, trying to equip " - "non-existing item from inventory index %i at " - "equipment slot %i.", inventoryIndex, index); + Log::info("EquipBackend: Warning, trying to equip " + "non-existing item from inventory index %i at " + "equipment slot %i.", inventoryIndex, index); return; } diff --git a/src/net/tmwa/loginhandler.cpp b/src/net/tmwa/loginhandler.cpp index a7162ee6..b6e3d518 100644 --- a/src/net/tmwa/loginhandler.cpp +++ b/src/net/tmwa/loginhandler.cpp @@ -108,7 +108,7 @@ void LoginHandler::handleMessage(MessageIn &msg) mUpdateHost = msg.readString(len); loginData.updateHost = mUpdateHost; - logger->log("Received update host \"%s\" from login server.", + Log::info("Received update host \"%s\" from login server.", mUpdateHost.c_str()); break; } @@ -138,10 +138,10 @@ void LoginHandler::handleMessage(MessageIn &msg) msg.readInt16(); // maintenance msg.readInt16(); // is_new - logger->log("Network: Server: %s (%s:%d)", - world->name.c_str(), - ipToString(world->address), - world->port); + Log::info("Network: Server: %s (%s:%d)", + world->name.c_str(), + ipToString(world->address), + world->port); mWorlds.push_back(world); } @@ -150,7 +150,7 @@ void LoginHandler::handleMessage(MessageIn &msg) case SMSG_LOGIN_ERROR: code = msg.readInt8(); - logger->log("Login::error code: %i", code); + Log::info("Login::error code: %i", code); switch (code) { @@ -212,9 +212,9 @@ void LoginHandler::handleMessage(MessageIn &msg) mServerVersion = 0; if (mServerVersion > 0) - logger->log("TMW server version: x%06x", mServerVersion); + Log::info("TMW server version: x%06x", mServerVersion); else - logger->log("Server without version"); + Log::info("Server without version"); mRegistrationEnabled = (options & FLAG_REGISTRATION); diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index c0db0fca..2630c511 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -26,9 +26,11 @@ #include <SDL_endian.h> +#ifndef MAKEWORD #define MAKEWORD(low,high) \ ((unsigned short)(((unsigned char)(low)) | \ ((unsigned short)((unsigned char)(high))) << 8)) +#endif namespace TmwAthena { diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp index a886fb4d..7758e306 100644 --- a/src/net/tmwa/messageout.cpp +++ b/src/net/tmwa/messageout.cpp @@ -23,6 +23,8 @@ #include "net/tmwa/network.h" +#include "log.h" + #include <SDL_endian.h> #include <cstring> @@ -32,7 +34,7 @@ namespace TmwAthena { MessageOut::MessageOut(uint16_t id) { #ifdef DEBUG - logger->log("Sending %s (0x%x)", Network::mInstance->messageName(id), id); + Log::info("Sending %s (0x%x)", Network::mInstance->messageName(id), id); #endif writeInt16(id); } diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index b448dc4f..9e010f7c 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -279,7 +279,7 @@ bool Network::connect(const ServerInfo &server) { if (mState != IDLE && mState != NET_ERROR) { - logger->log("Tried to connect an already connected socket!"); + Log::info("Tried to connect an already connected socket!"); assert(false); return false; } @@ -290,8 +290,8 @@ bool Network::connect(const ServerInfo &server) return false; } - logger->log("Network::Connecting to %s:%i", server.hostname.c_str(), - server.port); + Log::info("Network::Connecting to %s:%i", server.hostname.c_str(), + server.port); mServer.hostname = server.hostname; mServer.port = server.port; @@ -376,8 +376,7 @@ void Network::dispatchMessages() auto packetInfoIt = mPacketInfo.find(msgId); if (packetInfoIt == mPacketInfo.end()) { - auto error = strprintf("Unknown packet 0x%x received.", msgId); - logger->error(error); + Log::critical(strprintf("Unknown packet 0x%x received.", msgId)); break; } @@ -395,9 +394,8 @@ void Network::dispatchMessages() if (len < 4) { - auto error = strprintf("Variable length packet 0x%x has invalid length %d.", - msgId, len); - logger->error(error); + Log::critical(strprintf("Variable length packet 0x%x has invalid length %d.", + msgId, len)); break; } } @@ -413,14 +411,14 @@ void Network::dispatchMessages() if (iter != mMessageHandlers.end()) { #ifdef DEBUG - logger->log("Handling %s (0x%x) of length %d", packetInfo->name, msgId, len); + Log::info("Handling %s (0x%x) of length %d", packetInfo->name, msgId, len); #endif iter->second->handleMessage(message); } else { - logger->log("Unhandled %s (0x%x) of length %d", packetInfo->name, msgId, len); + Log::info("Unhandled %s (0x%x) of length %d", packetInfo->name, msgId, len); } skip(len); @@ -474,7 +472,7 @@ bool Network::realConnect() std::string errorMessage = strprintf(_("Unable to resolve host \"%s\""), mServer.hostname.c_str()); setError(errorMessage); - logger->log("SDLNet_ResolveHost: %s", errorMessage.c_str()); + Log::info("SDLNet_ResolveHost: %s", errorMessage.c_str()); return false; } @@ -483,13 +481,13 @@ bool Network::realConnect() mSocket = SDLNet_TCP_Open(&ipAddress); if (!mSocket) { - logger->log("Error in SDLNet_TCP_Open(): %s", SDLNet_GetError()); + Log::info("Error in SDLNet_TCP_Open(): %s", SDLNet_GetError()); setError(SDLNet_GetError()); return false; } - logger->log("Network::Started session with %s:%i", - ipToString(ipAddress.host), ipAddress.port); + Log::info("Network::Started session with %s:%i", + ipToString(ipAddress.host), ipAddress.port); mState = CONNECTED; @@ -522,7 +520,7 @@ void Network::receive() switch (numReady) { case -1: - logger->log("Error: SDLNet_CheckSockets"); + Log::error("SDLNet_CheckSockets"); // FALLTHROUGH case 0: break; @@ -537,7 +535,7 @@ void Network::receive() { // We got disconnected mState = IDLE; - logger->log("Disconnected."); + Log::info("Disconnected."); } else if (ret < 0) { @@ -578,7 +576,7 @@ void Network::receive() if (SDLNet_TCP_DelSocket(set, mSocket) == -1) { - logger->log("Error in SDLNet_DelSocket(): %s", SDLNet_GetError()); + Log::info("Error in SDLNet_DelSocket(): %s", SDLNet_GetError()); } SDLNet_FreeSocketSet(set); @@ -586,7 +584,7 @@ void Network::receive() void Network::setError(const std::string &error) { - logger->log("Network error: %s", error.c_str()); + Log::info("Network error: %s", error.c_str()); mError = error; mState = NET_ERROR; } diff --git a/src/net/tmwa/partyhandler.cpp b/src/net/tmwa/partyhandler.cpp index 2b256cd5..78dfd7a0 100644 --- a/src/net/tmwa/partyhandler.cpp +++ b/src/net/tmwa/partyhandler.cpp @@ -184,7 +184,7 @@ void PartyHandler::handleMessage(MessageIn &msg) partyTab->chatLog(_("Experience sharing not possible."), BY_SERVER); break; default: - logger->log("Unknown party exp option: %d", exp); + Log::info("Unknown party exp option: %d", exp); } switch (item) @@ -208,7 +208,7 @@ void PartyHandler::handleMessage(MessageIn &msg) partyTab->chatLog(_("Item sharing not possible."), BY_SERVER); break; default: - logger->log("Unknown party item option: %d", exp); + Log::info("Unknown party item option: %d", exp); } break; } diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index f6f6ef41..44b0efd3 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -21,8 +21,11 @@ #include "net/tmwa/playerhandler.h" +#include "actorspritemanager.h" +#include "being.h" #include "client.h" #include "configuration.h" +#include "effectmanager.h" #include "game.h" #include "localplayer.h" #include "log.h" @@ -55,7 +58,7 @@ const int MAP_TELEPORT_SCROLL_DISTANCE = 8; namespace { /** - * Listener used for handling the overweigth message. + * Listener used for handling the overweight message. */ struct WeightListener : public gcn::ActionListener { @@ -126,7 +129,7 @@ static const char *randomDeathMessage() N_("You're off the twig."), N_("You've kicked the bucket."), N_("You've shuffled off your mortal coil, run down the " - "curtain and joined the bleedin' choir invisibile."), + "curtain and joined the bleedin' choir invisible."), N_("You are an ex-player."), N_("You're pining for the fjords.") }; @@ -152,10 +155,14 @@ PlayerHandler::PlayerHandler() SMSG_PLAYER_STAT_UPDATE_6, SMSG_PLAYER_ARROW_MESSAGE, SMSG_MAP_MASK, + SMSG_QUEST_SET_VAR, + SMSG_QUEST_PLAYER_VARS, 0 }; handledMessages = _messages; playerHandler = this; + + listen(Event::GameChannel); } void PlayerHandler::handleMessage(MessageIn &msg) @@ -179,7 +186,7 @@ void PlayerHandler::handleMessage(MessageIn &msg) int x = msg.readInt16(); int y = msg.readInt16(); - logger->log("Warping to %s (%d, %d)", mapPath.c_str(), x, y); + Log::info("Warping to %s (%d, %d)", mapPath.c_str(), x, y); /* * We must clear the local player's target *before* the call @@ -217,8 +224,8 @@ void PlayerHandler::handleMessage(MessageIn &msg) // Stop movement local_player->setDestination(pos.x, pos.y); - logger->log("Adjust scrolling by %d:%d", (int) scrollOffsetX, - (int) scrollOffsetY); + Log::info("Adjust scrolling by %d:%d", (int) scrollOffsetX, + (int) scrollOffsetY); viewport->scrollBy(scrollOffsetX, scrollOffsetY); } @@ -499,7 +506,7 @@ void PlayerHandler::handleMessage(MessageIn &msg) serverNotice(_("Equip arrows first.")); break; default: - logger->log("0x013b: Unhandled message %i", type); + Log::info("0x013b: Unhandled message %i", type); break; } } @@ -514,6 +521,49 @@ void PlayerHandler::handleMessage(MessageIn &msg) map->setMask(mask); } break; + + case SMSG_QUEST_SET_VAR: + { + int variable = msg.readInt16(); + int value = msg.readInt32(); + int oldValue = mQuestVars.get(variable); + + mQuestVars.set(variable, value); + updateQuestStatusEffects(); + Event::trigger(Event::QuestsChannel, Event::QuestVarsChanged); + + if (effectManager && local_player) + { + switch (QuestDB::questChange(variable, oldValue, value)) + { + case QuestChange::None: + break; + case QuestChange::New: + effectManager->trigger(paths.getIntValue("newQuestEffectId"), local_player); + break; + case QuestChange::Completed: + effectManager->trigger(paths.getIntValue("completeQuestEffectId"), local_player); + break; + } + } + break; + } + + case SMSG_QUEST_PLAYER_VARS: + { + msg.readInt16(); // length + mQuestVars.clear(); + unsigned int count = (msg.getLength() - 4) / 6; + for (unsigned int i = 0; i < count; ++i) + { + int variable = msg.readInt16(); + int value = msg.readInt32(); + mQuestVars.set(variable, value); + } + updateQuestStatusEffects(); + Event::trigger(Event::QuestsChannel, Event::QuestVarsChanged); + break; + } } } @@ -649,8 +699,8 @@ Vector PlayerHandler::getPixelsPerSecondMoveSpeed(const Vector &speed, Map *map) if (!map || speed.x == 0 || speed.y == 0) { - logger->log("TmwAthena::PlayerHandler: Speed set to default: " - "Map not yet initialized or invalid speed."); + Log::info("TmwAthena::PlayerHandler: Speed set to default: " + "Map not yet initialized or invalid speed."); return getDefaultMoveSpeed(); } @@ -664,4 +714,54 @@ Vector PlayerHandler::getPixelsPerSecondMoveSpeed(const Vector &speed, Map *map) return pixelsPerSecond; } +void PlayerHandler::event(Event::Channel channel, const Event &event) +{ + if (channel == Event::GameChannel) + { + if (event.getType() == Event::MapLoaded) + { + updateQuestStatusEffects(); + } + } +} + +void PlayerHandler::applyQuestStatusEffects(Being *npc) +{ + const auto npcId = npc->getSubType(); + const auto effect = mActiveQuestEffects.get(npcId); + if (effect != 0) + npc->setStatusEffect(effect, true); +} + +void PlayerHandler::updateQuestStatusEffects() +{ + auto game = Game::instance(); + if (!game) + return; + + const auto ¤tMapName = game->getCurrentMapName(); + auto updatedQuestEffects = QuestDB::getActiveEffects(mQuestVars, currentMapName); + + // Loop over all NPCs, disabling no longer active effects and enabling new ones + for (auto actor : actorSpriteManager->getAll()) { + if (actor->getType() != ActorSprite::NPC) + continue; + + auto *npc = static_cast<Being *>(actor); + const auto npcId = npc->getSubType(); + const auto oldEffect = mActiveQuestEffects.get(npcId); + const auto newEffect = updatedQuestEffects.get(npcId); + + if (oldEffect != newEffect) + { + if (oldEffect != 0) + npc->setStatusEffect(oldEffect, false); + if (newEffect != 0) + npc->setStatusEffect(newEffect, true); + } + } + + std::swap(mActiveQuestEffects, updatedQuestEffects); +} + } // namespace TmwAthena diff --git a/src/net/tmwa/playerhandler.h b/src/net/tmwa/playerhandler.h index f1a67e94..49990d85 100644 --- a/src/net/tmwa/playerhandler.h +++ b/src/net/tmwa/playerhandler.h @@ -28,7 +28,8 @@ namespace TmwAthena { -class PlayerHandler final : public MessageHandler, public Net::PlayerHandler +class PlayerHandler final : public MessageHandler, public Net::PlayerHandler, + public EventListener { public: PlayerHandler(); @@ -63,6 +64,16 @@ class PlayerHandler final : public MessageHandler, public Net::PlayerHandler bool usePixelPrecision() override { return false; } + + // EventListener + void event(Event::Channel channel, const Event &event) override; + + void applyQuestStatusEffects(Being *npc); + + private: + void updateQuestStatusEffects(); + + QuestEffectMap mActiveQuestEffects; }; } // namespace TmwAthena |