summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
Diffstat (limited to 'src/net')
-rw-r--r--src/net/charhandler.h2
-rw-r--r--src/net/download.cpp18
-rw-r--r--src/net/inventoryhandler.h44
-rw-r--r--src/net/logindata.h4
-rw-r--r--src/net/manaserv/beinghandler.cpp25
-rw-r--r--src/net/manaserv/charhandler.cpp24
-rw-r--r--src/net/manaserv/charhandler.h2
-rw-r--r--src/net/manaserv/chathandler.cpp6
-rw-r--r--src/net/manaserv/connection.cpp8
-rw-r--r--src/net/manaserv/effecthandler.cpp4
-rw-r--r--src/net/manaserv/guildhandler.cpp22
-rw-r--r--src/net/manaserv/inventoryhandler.cpp30
-rw-r--r--src/net/manaserv/inventoryhandler.h12
-rw-r--r--src/net/manaserv/loginhandler.cpp2
-rw-r--r--src/net/manaserv/manaserv_protocol.h14
-rw-r--r--src/net/manaserv/network.cpp20
-rw-r--r--src/net/manaserv/npchandler.cpp2
-rw-r--r--src/net/manaserv/partyhandler.cpp4
-rw-r--r--src/net/manaserv/playerhandler.cpp30
-rw-r--r--src/net/net.cpp5
-rw-r--r--src/net/playerhandler.h7
-rw-r--r--src/net/tmwa/abilityhandler.cpp2
-rw-r--r--src/net/tmwa/beinghandler.cpp20
-rw-r--r--src/net/tmwa/buysellhandler.cpp2
-rw-r--r--src/net/tmwa/charserverhandler.cpp18
-rw-r--r--src/net/tmwa/charserverhandler.h3
-rw-r--r--src/net/tmwa/chathandler.cpp5
-rw-r--r--src/net/tmwa/gamehandler.cpp6
-rw-r--r--src/net/tmwa/generalhandler.cpp2
-rw-r--r--src/net/tmwa/gui/partytab.cpp3
-rw-r--r--src/net/tmwa/inventoryhandler.cpp22
-rw-r--r--src/net/tmwa/inventoryhandler.h7
-rw-r--r--src/net/tmwa/loginhandler.cpp18
-rw-r--r--src/net/tmwa/messagein.cpp2
-rw-r--r--src/net/tmwa/messageout.cpp5
-rw-r--r--src/net/tmwa/network.cpp47
-rw-r--r--src/net/tmwa/network.h2
-rw-r--r--src/net/tmwa/partyhandler.cpp4
-rw-r--r--src/net/tmwa/playerhandler.cpp116
-rw-r--r--src/net/tmwa/playerhandler.h13
-rw-r--r--src/net/tmwa/protocol.h20
-rw-r--r--src/net/tmwa/token.h22
42 files changed, 380 insertions, 244 deletions
diff --git a/src/net/charhandler.h b/src/net/charhandler.h
index 3f0c096f..c04cf81e 100644
--- a/src/net/charhandler.h
+++ b/src/net/charhandler.h
@@ -62,7 +62,7 @@ class CharHandler
virtual void chooseCharacter(Net::Character *character) = 0;
virtual void newCharacter(const std::string &name, int slot,
- bool gender, int hairstyle, int hairColor,
+ Gender gender, int hairstyle, int hairColor,
const std::vector<int> &stats) = 0;
virtual void deleteCharacter(Net::Character *character) = 0;
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/inventoryhandler.h b/src/net/inventoryhandler.h
index 323dec6c..995e54d9 100644
--- a/src/net/inventoryhandler.h
+++ b/src/net/inventoryhandler.h
@@ -22,16 +22,14 @@
#pragma once
#include "equipment.h"
-#include "inventory.h"
-#include "item.h"
#include "position.h"
-#include <iosfwd>
+#include <string>
namespace Net {
// Default positions of the boxes, 2nd dimension is X and Y respectively.
-const int fallBackBoxesPosition[][2] = {
+constexpr Position fallBackBoxPositions[] = {
{ 90, 40 }, // EQUIP_TORSO_SLOT
{ 8, 78 }, // EQUIP_GLOVES_SLOT
{ 70, 0 }, // EQUIP_HEAD_SLOT
@@ -45,21 +43,21 @@ const int fallBackBoxesPosition[][2] = {
{ 129, 78 } // EQUIP_PROJECTILE_SLOT
};
-const std::string fallBackBoxesBackground[] = {
- "equip-box-chest.png",
- "equip-box-hands.png",
- "equip-box-head.png",
- "equip-box-legs.png",
- "equip-box-feet.png",
- "equip-box-ring.png",
- "equip-box-ring.png",
- "equip-box-neck.png",
- "equip-box-weapon.png",
- "equip-box-shield.png",
- "equip-box-ammo.png"
+const std::string fallBackBoxIcons[] = {
+ "equip-box-chest",
+ "equip-box-hands",
+ "equip-box-head",
+ "equip-box-legs",
+ "equip-box-feet",
+ "equip-box-ring",
+ "equip-box-ring",
+ "equip-box-neck",
+ "equip-box-weapon",
+ "equip-box-shield",
+ "equip-box-ammo"
};
-static const std::string empty = std::string();
+static const std::string empty;
class InventoryHandler
{
@@ -80,17 +78,15 @@ class InventoryHandler
virtual Position getBoxPosition(unsigned int slotIndex) const
{
- if (slotIndex < (sizeof(fallBackBoxesPosition)
- / sizeof(fallBackBoxesPosition[0][0])))
- return Position(fallBackBoxesPosition[slotIndex][0],
- fallBackBoxesPosition[slotIndex][1]);
+ if (slotIndex < sizeof(fallBackBoxPositions) / sizeof(fallBackBoxPositions[0]))
+ return fallBackBoxPositions[slotIndex];
return Position(0,0);
}
- virtual const std::string& getBoxBackground(unsigned int slotIndex) const
+ virtual const std::string& getBoxIcon(unsigned int slotIndex) const
{
- if (slotIndex < sizeof(fallBackBoxesBackground))
- return fallBackBoxesBackground[slotIndex];
+ if (slotIndex < sizeof(fallBackBoxIcons) / sizeof(fallBackBoxIcons[0]))
+ return fallBackBoxIcons[slotIndex];
return empty; // The empty string
}
};
diff --git a/src/net/logindata.h b/src/net/logindata.h
index 4af402ec..36d197e7 100644
--- a/src/net/logindata.h
+++ b/src/net/logindata.h
@@ -39,7 +39,7 @@ public:
std::string email;
std::string captchaResponse;
- Gender gender = Gender::Unspecified;
+ Gender gender = Gender::Neutral;
bool remember; /**< Whether to store the username. */
bool registerLogin; /**< Whether an account is being registered. */
@@ -63,7 +63,7 @@ public:
updateHost.clear();
email.clear();
captchaResponse.clear();
- gender = Gender::Unspecified;
+ gender = Gender::Neutral;
resetCharacterSlots();
}
};
diff --git a/src/net/manaserv/beinghandler.cpp b/src/net/manaserv/beinghandler.cpp
index 9bb52ac1..6caa90d4 100644
--- a/src/net/manaserv/beinghandler.cpp
+++ b/src/net/manaserv/beinghandler.cpp
@@ -146,24 +146,13 @@ static void handleLooks(Being *being, MessageIn &msg)
void BeingHandler::handleBeingEnterMessage(MessageIn &msg)
{
- int type = msg.readInt8();
- int id = msg.readInt16();
- auto action = (Being::Action)msg.readInt8();
- int px = msg.readInt16();
- int py = msg.readInt16();
- auto direction = (BeingDirection)msg.readInt8();
-
- Gender gender = Gender::Unspecified;
- switch (getGender(msg.readInt8())) {
- case GENDER_MALE:
- gender = Gender::Male;
- break;
- case GENDER_FEMALE:
- gender = Gender::Female;
- break;
- case GENDER_UNSPECIFIED:
- break;
- }
+ const int type = msg.readInt8();
+ const int id = msg.readInt16();
+ const auto action = static_cast<Being::Action>(msg.readInt8());
+ const int px = msg.readInt16();
+ const int py = msg.readInt16();
+ const auto direction = static_cast<BeingDirection>(msg.readInt8());
+ const Gender gender = getGender(msg.readInt8());
Being *being;
diff --git a/src/net/manaserv/charhandler.cpp b/src/net/manaserv/charhandler.cpp
index 98591669..215cf380 100644
--- a/src/net/manaserv/charhandler.cpp
+++ b/src/net/manaserv/charhandler.cpp
@@ -106,17 +106,7 @@ void CharHandler::handleCharacterInfo(MessageIn &msg)
info.slot = msg.readInt8();
info.name = msg.readString();
- switch (getGender(msg.readInt8())) {
- case GENDER_MALE:
- info.gender = Gender::Male;
- break;
- case GENDER_FEMALE:
- info.gender = Gender::Female;
- break;
- case GENDER_UNSPECIFIED:
- info.gender = Gender::Unspecified;
- break;
- }
+ info.gender = getGender(msg.readInt8());
info.hairStyle = msg.readInt8();
info.hairColor = msg.readInt8();
info.characterPoints = msg.readInt16();
@@ -264,10 +254,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;
@@ -339,7 +329,7 @@ void CharHandler::chooseCharacter(Net::Character *character)
void CharHandler::newCharacter(const std::string &name,
int slot,
- bool gender,
+ Gender gender,
int hairstyle,
int hairColor,
const std::vector<int> &stats)
@@ -349,7 +339,7 @@ void CharHandler::newCharacter(const std::string &name,
msg.writeString(name);
msg.writeInt8(hairstyle);
msg.writeInt8(hairColor);
- msg.writeInt8(gender);
+ msg.writeInt8(gender == Gender::Female);
msg.writeInt8(slot);
for (int stat : stats)
diff --git a/src/net/manaserv/charhandler.h b/src/net/manaserv/charhandler.h
index e962bdfa..c26194ee 100644
--- a/src/net/manaserv/charhandler.h
+++ b/src/net/manaserv/charhandler.h
@@ -59,7 +59,7 @@ class CharHandler final : public MessageHandler, public Net::CharHandler
void chooseCharacter(Net::Character *character) override;
void newCharacter(const std::string &name, int slot,
- bool gender, int hairstyle, int hairColor,
+ Gender gender, int hairstyle, int hairColor,
const std::vector<int> &stats) override;
void deleteCharacter(Net::Character *character) override;
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 e1dc5dea..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;
}
@@ -197,11 +196,10 @@ void EquipBackend::readBoxNode(XML::Node slotNode)
const int x = boxNode.getProperty("x" , 0);
const int y = boxNode.getProperty("y" , 0);
- mBoxesPositions.emplace_back(x, y);
+ mBoxPositions.emplace_back(x, y);
- std::string backgroundFile =
- boxNode.getProperty("background" , std::string());
- mBoxesBackgroundFile.push_back(backgroundFile);
+ const auto icon = boxNode.getProperty("icon", std::string());
+ mBoxIcons.push_back(icon);
}
}
@@ -227,15 +225,15 @@ bool EquipBackend::isAmmoSlot(int slotTypeId) const
Position EquipBackend::getBoxPosition(unsigned int slotIndex) const
{
- if (slotIndex < mBoxesPositions.size())
- return mBoxesPositions.at(slotIndex);
+ if (slotIndex < mBoxPositions.size())
+ return mBoxPositions.at(slotIndex);
return Position(0, 0);
}
-const std::string &EquipBackend::getBoxBackground(unsigned int slotIndex) const
+const std::string &EquipBackend::getBoxIcon(unsigned int slotIndex) const
{
- if (slotIndex < mBoxesBackgroundFile.size())
- return mBoxesBackgroundFile.at(slotIndex);
+ if (slotIndex < mBoxIcons.size())
+ return mBoxIcons.at(slotIndex);
return Net::empty;
}
diff --git a/src/net/manaserv/inventoryhandler.h b/src/net/manaserv/inventoryhandler.h
index 02ce90df..b72922b3 100644
--- a/src/net/manaserv/inventoryhandler.h
+++ b/src/net/manaserv/inventoryhandler.h
@@ -27,6 +27,8 @@
#include "net/manaserv/messagehandler.h"
+#include "utils/xml.h"
+
#include <map>
#include <vector>
@@ -59,7 +61,7 @@ class EquipBackend final : public Equipment::Backend, public EventListener
Position getBoxPosition(unsigned int slotIndex) const;
- const std::string &getBoxBackground(unsigned int slotIndex) const;
+ const std::string &getBoxIcon(unsigned int slotIndex) const;
private:
void readEquipFile() override;
@@ -95,8 +97,8 @@ class EquipBackend final : public Equipment::Backend, public EventListener
// slot client index, slot info
std::map<unsigned int, Slot> mSlots;
- std::vector<Position> mBoxesPositions;
- std::vector<std::string> mBoxesBackgroundFile;
+ std::vector<Position> mBoxPositions;
+ std::vector<std::string> mBoxIcons;
};
class InventoryHandler final : public MessageHandler, Net::InventoryHandler,
@@ -126,8 +128,8 @@ class InventoryHandler final : public MessageHandler, Net::InventoryHandler,
Position getBoxPosition(unsigned int slotIndex) const override
{ return mEquipBackend.getBoxPosition(slotIndex); }
- const std::string& getBoxBackground(unsigned int slotIndex) const override
- { return mEquipBackend.getBoxBackground(slotIndex); }
+ const std::string& getBoxIcon(unsigned int slotIndex) const override
+ { return mEquipBackend.getBoxIcon(slotIndex); }
private:
EquipBackend mEquipBackend;
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/manaserv_protocol.h b/src/net/manaserv/manaserv_protocol.h
index cb27d6f4..5ade87bc 100644
--- a/src/net/manaserv/manaserv_protocol.h
+++ b/src/net/manaserv/manaserv_protocol.h
@@ -21,6 +21,8 @@
#pragma once
+#include "being.h"
+
namespace ManaServ {
enum {
@@ -464,16 +466,16 @@ enum BeingGender
/**
* Helper function for getting gender by int
*/
-inline ManaServ::BeingGender getGender(int gender)
+inline Gender getGender(int gender)
{
switch (gender)
{
- case 0:
- return ManaServ::GENDER_MALE;
- case 1:
- return ManaServ::GENDER_FEMALE;
+ case GENDER_MALE:
+ return Gender::Male;
+ case GENDER_FEMALE:
+ return Gender::Female;
default:
- return ManaServ::GENDER_UNSPECIFIED;
+ return Gender::Neutral;
}
}
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/npchandler.cpp b/src/net/manaserv/npchandler.cpp
index 44729654..df139d23 100644
--- a/src/net/manaserv/npchandler.cpp
+++ b/src/net/manaserv/npchandler.cpp
@@ -101,7 +101,7 @@ void NpcHandler::handleMessage(MessageIn &msg)
break;
case GPMSG_NPC_ERROR:
- event = new Event(Event::End);
+ event = new Event(Event::CloseDialog);
event->setInt("id", npcId);
event->trigger(Event::NpcChannel);
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..d2fd4695 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;
}
@@ -211,7 +217,8 @@ void BeingHandler::handleMessage(MessageIn &msg)
return;
int id;
- short job, gender;
+ short job;
+ SEX sex;
float speed;
Uint16 headTop, headMid, headBottom;
Uint16 shoes, gloves;
@@ -299,12 +306,11 @@ void BeingHandler::handleMessage(MessageIn &msg)
msg.readInt16(); // manner
opt3 = msg.readInt16();
msg.readInt8(); // karma
- gender = msg.readInt8();
+ sex = static_cast<SEX>(msg.readInt8());
if (dstBeing->getType() == ActorSprite::PLAYER)
{
- dstBeing->setGender(gender == 0 ? Gender::Female
- : Gender::Male);
+ dstBeing->setGender(sexToGender(sex));
// Set these after the gender, as the sprites may be gender-specific
dstBeing->setSprite(SPRITE_HAIR, hairStyle * -1,
hairDB.getHairColor(hairColor));
@@ -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..f248388b 100644
--- a/src/net/tmwa/charserverhandler.cpp
+++ b/src/net/tmwa/charserverhandler.cpp
@@ -36,6 +36,7 @@
#include "net/tmwa/messageout.h"
#include "net/tmwa/network.h"
#include "net/tmwa/protocol.h"
+#include "net/tmwa/token.h"
#include "resources/attributes.h"
#include "resources/chardb.h"
@@ -89,8 +90,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);
@@ -241,7 +242,7 @@ void CharServerHandler::readPlayerData(MessageIn &msg, Net::Character *character
const uint16_t weapon = msg.readInt16();
auto *tempPlayer = new LocalPlayer(id, race);
- tempPlayer->setGender(token.sex);
+ tempPlayer->setGender(sexToGender(token.sex));
tempPlayer->setSprite(SPRITE_SHOE, shoe);
tempPlayer->setSprite(SPRITE_GLOVES, gloves);
@@ -267,8 +268,7 @@ void CharServerHandler::readPlayerData(MessageIn &msg, Net::Character *character
character->data.mStats[i + STRENGTH].base = msg.readInt8();
character->slot = msg.readInt8(); // character slot
- const uint8_t sex = msg.readInt8();
- tempPlayer->setGender(sex ? Gender::Male : Gender::Female);
+ tempPlayer->setGender(sexToGender(static_cast<SEX>(msg.readInt8())));
}
void CharServerHandler::setCharSelectDialog(CharSelectDialog *window)
@@ -306,7 +306,9 @@ void CharServerHandler::setCharCreateDialog(CharCreateDialog *window)
sumStat = Attributes::getCreationPoints();
mCharCreateDialog->setAttributes(attributes, sumStat, minStat, maxStat);
- mCharCreateDialog->setDefaultGender(token.sex);
+
+ if (token.sex != SEX::UNSPECIFIED)
+ mCharCreateDialog->setDefaultGender(sexToGender(token.sex));
}
void CharServerHandler::requestCharacters()
@@ -324,7 +326,7 @@ void CharServerHandler::chooseCharacter(Net::Character *character)
}
void CharServerHandler::newCharacter(const std::string &name, int slot,
- bool gender, int hairstyle, int hairColor,
+ Gender /*gender*/, int hairstyle, int hairColor,
const std::vector<int> &stats)
{
MessageOut outMsg(CMSG_CHAR_CREATE);
@@ -400,7 +402,7 @@ void CharServerHandler::connect()
// [Fate] The next word is unused by the old char server, so we squeeze in
// mana client version information
outMsg.writeInt16(CLIENT_PROTOCOL_VERSION);
- outMsg.writeInt8(token.sex == Gender::Male ? 1 : 0);
+ outMsg.writeInt8(static_cast<uint8_t>(token.sex));
// We get 4 useless bytes before the real answer comes in (what are these?)
mNetwork->skip(4);
diff --git a/src/net/tmwa/charserverhandler.h b/src/net/tmwa/charserverhandler.h
index b0d3e970..cb79f969 100644
--- a/src/net/tmwa/charserverhandler.h
+++ b/src/net/tmwa/charserverhandler.h
@@ -24,7 +24,6 @@
#include "net/charhandler.h"
#include "net/tmwa/messagehandler.h"
-#include "net/tmwa/token.h"
class LoginData;
@@ -53,7 +52,7 @@ class CharServerHandler final : public MessageHandler, public Net::CharHandler
void chooseCharacter(Net::Character *character) override;
- void newCharacter(const std::string &name, int slot, bool gender,
+ void newCharacter(const std::string &name, int slot, Gender gender,
int hairstyle, int hairColor,
const std::vector<int> &stats) override;
diff --git a/src/net/tmwa/chathandler.cpp b/src/net/tmwa/chathandler.cpp
index f9061f63..cce5a41d 100644
--- a/src/net/tmwa/chathandler.cpp
+++ b/src/net/tmwa/chathandler.cpp
@@ -193,7 +193,10 @@ void ChatHandler::handleMessage(MessageIn &msg)
trim(chatMsg);
std::string reducedMessage = chatMsg;
- chatMsg = removeColors(sender_name) + " : " + reducedMessage;
+ chatMsg = sender_name;
+ removeColors(chatMsg);
+ chatMsg += " : ";
+ chatMsg += reducedMessage;
Event event(Event::Being);
event.setString("message", chatMsg);
diff --git a/src/net/tmwa/gamehandler.cpp b/src/net/tmwa/gamehandler.cpp
index 0a3bb9d9..f16a133b 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.
@@ -140,7 +140,7 @@ void GameHandler::connect()
outMsg.writeInt32(mCharID);
outMsg.writeInt32(token.session_ID1);
outMsg.writeInt32(token.session_ID2);
- outMsg.writeInt8(token.sex == Gender::Male ? 1 : 0);
+ outMsg.writeInt8(static_cast<uint8_t>(token.sex));
// We get 4 useless bytes before the real answer comes in (what are these?)
mNetwork->skip(4);
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/gui/partytab.cpp b/src/net/tmwa/gui/partytab.cpp
index 418e0843..ee29757a 100644
--- a/src/net/tmwa/gui/partytab.cpp
+++ b/src/net/tmwa/gui/partytab.cpp
@@ -32,14 +32,13 @@
#include "resources/theme.h"
#include "utils/gettext.h"
-#include "utils/stringutils.h"
namespace TmwAthena {
PartyTab::PartyTab() :
ChatTab(_("Party"))
{
- setTabColor(&Theme::getThemeColor(Theme::PARTY_CHAT_TAB));
+ setTabColor(&Theme::getThemeColor(Theme::PARTY_TAB));
}
void PartyTab::handleInput(const std::string &msg)
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 47226bea..cde1235b 100644
--- a/src/net/tmwa/inventoryhandler.h
+++ b/src/net/tmwa/inventoryhandler.h
@@ -23,6 +23,7 @@
#include "eventlistener.h"
#include "inventory.h"
+#include "item.h"
#include "log.h"
#include "playerinfo.h"
@@ -107,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..fba8c9f8 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;
}
@@ -124,7 +124,7 @@ void LoginHandler::handleMessage(MessageIn &msg)
mToken.account_ID = msg.readInt32();
mToken.session_ID2 = msg.readInt32();
msg.skip(30); // unused
- mToken.sex = msg.readInt8() ? Gender::Male : Gender::Female;
+ mToken.sex = static_cast<SEX>(msg.readInt8());
for (int i = 0; i < worldCount; i++)
{
@@ -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 12c9419a..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>
@@ -31,6 +33,9 @@ namespace TmwAthena {
MessageOut::MessageOut(uint16_t id)
{
+#ifdef DEBUG
+ 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 353495da..9e010f7c 100644
--- a/src/net/tmwa/network.cpp
+++ b/src/net/tmwa/network.cpp
@@ -45,9 +45,9 @@ struct PacketInfo
};
// indicator for a variable-length packet
-const uint16_t VAR = 1;
+constexpr uint16_t VAR = 1;
-static const PacketInfo packet_infos[] = {
+static constexpr PacketInfo packet_infos[] = {
// login server messages
{ SMSG_UPDATE_HOST, VAR, "SMSG_UPDATE_HOST" },
{ CMSG_LOGIN_REGISTER, 55, "CMSG_LOGIN_REGISTER" },
@@ -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;
@@ -353,6 +353,15 @@ void Network::clearHandlers()
mMessageHandlers.clear();
}
+const char *Network::messageName(uint16_t id) const
+{
+ auto packetInfoIt = mPacketInfo.find(id);
+ if (packetInfoIt != mPacketInfo.end())
+ return packetInfoIt->second->name;
+
+ return "Unknown";
+}
+
void Network::dispatchMessages()
{
MutexLocker lock(&mMutex);
@@ -367,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;
}
@@ -386,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;
}
}
@@ -404,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);
@@ -465,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;
}
@@ -474,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;
@@ -513,7 +520,7 @@ void Network::receive()
switch (numReady)
{
case -1:
- logger->log("Error: SDLNet_CheckSockets");
+ Log::error("SDLNet_CheckSockets");
// FALLTHROUGH
case 0:
break;
@@ -528,7 +535,7 @@ void Network::receive()
{
// We got disconnected
mState = IDLE;
- logger->log("Disconnected.");
+ Log::info("Disconnected.");
}
else if (ret < 0)
{
@@ -569,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);
@@ -577,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/network.h b/src/net/tmwa/network.h
index 53f15761..b27d1eda 100644
--- a/src/net/tmwa/network.h
+++ b/src/net/tmwa/network.h
@@ -66,6 +66,8 @@ class Network
void clearHandlers();
+ const char *messageName(uint16_t id) const;
+
int getState() const { return mState; }
const std::string &getError() const { return mError; }
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 &currentMapName = 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
diff --git a/src/net/tmwa/protocol.h b/src/net/tmwa/protocol.h
index 532ac90e..b93c81e1 100644
--- a/src/net/tmwa/protocol.h
+++ b/src/net/tmwa/protocol.h
@@ -21,6 +21,8 @@
#pragma once
+#include "being.h"
+
#include <cstdint>
namespace TmwAthena {
@@ -93,6 +95,24 @@ enum class DIR : uint8_t
COUNT,
};
+enum class SEX : uint8_t
+{
+ FEMALE = 0,
+ MALE = 1,
+ UNSPECIFIED = 2,
+ NEUTRAL = 3,
+};
+
+inline Gender sexToGender(SEX sex)
+{
+ switch (sex)
+ {
+ case SEX::FEMALE: return Gender::Female;
+ case SEX::MALE: return Gender::Male;
+ default: return Gender::Neutral;
+ }
+}
+
enum NpcCommand
{
NPC_REQUEST_LANG = 0,
diff --git a/src/net/tmwa/token.h b/src/net/tmwa/token.h
index b563bf65..c24fbebb 100644
--- a/src/net/tmwa/token.h
+++ b/src/net/tmwa/token.h
@@ -19,22 +19,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "being.h"
+#include "net/tmwa/protocol.h"
#pragma once
+namespace TmwAthena {
+
struct Token
{
- int account_ID;
- int session_ID1;
- int session_ID2;
- Gender sex;
-
- void clear()
- {
- account_ID = 0;
- session_ID1 = 0;
- session_ID2 = 0;
- sex = Gender::Unspecified;
- }
+ int account_ID = 0;
+ int session_ID1 = 0;
+ int session_ID2 = 0;
+ SEX sex = SEX::UNSPECIFIED;
};
+
+} // namespace TmwAthena