Skip to content

Commit

Permalink
remove otcv8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
MillhioreBT committed Mar 15, 2024
1 parent 7b5481a commit 324c47b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 119 deletions.
44 changes: 4 additions & 40 deletions src/luanetworkmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ using namespace Lua;
// NetworkMessage
int luaNetworkMessageCreate(lua_State* L)
{
// NetworkMessage([player])
// NetworkMessage()
pushUserdata<NetworkMessage>(L, new NetworkMessage);
setMetatable(L, -1, "NetworkMessage");

if (const auto player = getPlayer(L, 1)) {
lua_pushinteger(L, player->getID());
lua_setiuservalue(L, 2, 1);
}
return 1;
}

Expand Down Expand Up @@ -216,18 +211,7 @@ int luaNetworkMessageAddItem(lua_State* L)

NetworkMessage* message = getUserdata<NetworkMessage>(L, 1);
if (message) {
if (getAssociatedValue(L, 1, 1)) {
if (const auto player = getPlayer(L, -1)) {
message->addItem(item, player->isOTCv8());
} else {
reportErrorFunc(L, LuaScriptInterface::getErrorDesc(LuaErrorCode::PLAYER_NOT_FOUND));
lua_pushnil(L);
return 1;
}
} else {
message->addItem(item, false);
}

message->addItem(item);
pushBoolean(L, true);
} else {
lua_pushnil(L);
Expand Down Expand Up @@ -255,18 +239,7 @@ int luaNetworkMessageAddItemId(lua_State* L)
}
}

if (getAssociatedValue(L, 1, 1)) {
if (const auto player = getPlayer(L, -1)) {
message->addItemId(itemId, player->isOTCv8());
} else {
reportErrorFunc(L, LuaScriptInterface::getErrorDesc(LuaErrorCode::PLAYER_NOT_FOUND));
lua_pushnil(L);
return 1;
}
} else {
message->addItemId(itemId, false);
}

message->addItemId(itemId);
pushBoolean(L, true);
return 1;
}
Expand Down Expand Up @@ -343,21 +316,12 @@ int luaNetworkMessageSendToPlayer(lua_State* L)
return 1;
}

Player* player = getPlayer(L, 2);
if (player) {
if (Player* player = getPlayer(L, 2)) {
player->sendNetworkMessage(*message);
pushBoolean(L, true);
return 1;
}

if (getAssociatedValue(L, 1, 1)) {
if (const auto p = getPlayer(L, -1)) {
p->sendNetworkMessage(*message);
pushBoolean(L, true);
return 1;
}
}

reportErrorFunc(L, LuaScriptInterface::getErrorDesc(LuaErrorCode::PLAYER_NOT_FOUND));
lua_pushnil(L);
return 1;
Expand Down
17 changes: 6 additions & 11 deletions src/networkmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,15 @@ void NetworkMessage::addPosition(const Position& pos)
addByte(pos.z);
}

void NetworkMessage::addItemId(uint16_t itemId, bool isOTCv8)
void NetworkMessage::addItemId(uint16_t itemId)
{
const ItemType& it = Item::items[itemId];
uint16_t clientId = it.clientId;
if (isOTCv8 && itemId > 12660) {
clientId = it.stackable ? 3031 : 105;
}

add<uint16_t>(clientId);
add<uint16_t>(it.clientId);
}

void NetworkMessage::addItem(uint16_t id, uint8_t count, bool isOTCv8)
void NetworkMessage::addItem(uint16_t id, uint8_t count)
{
addItemId(id, isOTCv8);
addItemId(id);

const ItemType& it = Item::items[id];
if (it.stackable) {
Expand All @@ -103,9 +98,9 @@ void NetworkMessage::addItem(uint16_t id, uint8_t count, bool isOTCv8)
}
}

void NetworkMessage::addItem(const Item* item, bool isOTCv8)
void NetworkMessage::addItem(const Item* item)
{
addItemId(item->getID(), isOTCv8);
addItemId(item->getID());

const ItemType& it = Item::items[item->getID()];
if (it.stackable) {
Expand Down
6 changes: 3 additions & 3 deletions src/networkmessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ class NetworkMessage

// write functions for complex types
void addPosition(const Position& pos);
void addItemId(uint16_t itemId, bool isOTCv8);
void addItem(uint16_t id, uint8_t count, bool isOTCv8);
void addItem(const Item* item, bool isOTCv8);
void addItemId(uint16_t itemId);
void addItem(uint16_t id, uint8_t count);
void addItem(const Item* item);

MsgSize_t getLength() const { return info.length; }

Expand Down
2 changes: 0 additions & 2 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -955,8 +955,6 @@ class Player final : public Creature, public Cylinder

bool hasDebugAssertSent() const { return client ? client->debugAssertSent : false; }

bool isOTCv8() const { return client ? client->isOTCv8 : false; }

static uint32_t playerAutoID;

private:
Expand Down
82 changes: 21 additions & 61 deletions src/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,6 @@ void ProtocolGame::onRecvFirstMessage(NetworkMessage& msg)
return;
}

// OTCv8 version detection
auto OTCv8StringLen = msg.get<uint16_t>();
if (OTCv8StringLen == 5 && msg.getString(OTCv8StringLen) == "OTCv8") {
OTCv8 = msg.get<uint16_t>();
isOTCv8 = OTCv8 != 0;
fmt::print("Client OTCv8 version: {:d}\n", OTCv8);
}

if (version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX) {
disconnectClient(fmt::format("Only clients with protocol {:s} allowed!", CLIENT_VERSION_STR));
return;
Expand Down Expand Up @@ -763,7 +755,7 @@ void ProtocolGame::GetTileDescription(const Tile* tile, NetworkMessage& msg)
{
int32_t count = 0;
if (const auto ground = tile->getGround()) {
msg.addItem(ground, isOTCv8);
msg.addItem(ground);
++count;
}

Expand All @@ -772,7 +764,7 @@ void ProtocolGame::GetTileDescription(const Tile* tile, NetworkMessage& msg)
const TileItemVector* items = tile->getItemList();
if (items) {
for (auto it = items->getBeginTopItem(), end = items->getEndTopItem(); it != end; ++it) {
msg.addItem(*it, isOTCv8);
msg.addItem(*it);

if (++count == 9 && isStacked) {
break;
Expand Down Expand Up @@ -806,7 +798,7 @@ void ProtocolGame::GetTileDescription(const Tile* tile, NetworkMessage& msg)

if (items) {
for (auto it = items->getBeginDownItem(), end = items->getEndDownItem(); it != end; ++it) {
msg.addItem(*it, isOTCv8);
msg.addItem(*it);

if (++count == MAX_STACKPOS_THINGS) {
return;
Expand Down Expand Up @@ -856,12 +848,12 @@ void ProtocolGame::GetFloorDescription(NetworkMessage& msg, int32_t x, int32_t y

skip = 0;
GetTileDescription(tile, msg);
} else if (skip == 0xFE) {
msg.addByte(0xFF);
msg.addByte(0xFF);
skip = -1;
} else {
if (++skip == 0xFF) {
msg.addByte(0xFF);
msg.addByte(0xFF);
skip = -1;
}
++skip;
}
}
}
Expand Down Expand Up @@ -1039,7 +1031,6 @@ void ProtocolGame::parseSetOutfit(NetworkMessage& msg)
newOutfit.lookLegs = msg.getByte();
newOutfit.lookFeet = msg.getByte();
newOutfit.lookAddons = msg.getByte();
newOutfit.lookMount = isOTCv8 ? msg.get<uint16_t>() : 0;
g_dispatcher.addTask([=, playerID = player->getID()]() { g_game.playerChangeOutfit(playerID, newOutfit); });
}

Expand Down Expand Up @@ -1348,10 +1339,6 @@ void ProtocolGame::parseEnableSharedPartyExperience(NetworkMessage& msg)

void ProtocolGame::parseModalWindowAnswer(NetworkMessage& msg)
{
if (isOTCv8) {
return;
}

uint32_t id = msg.get<uint32_t>();
uint8_t button = msg.getByte();
uint8_t choice = msg.getByte();
Expand Down Expand Up @@ -1559,7 +1546,7 @@ void ProtocolGame::sendContainer(uint8_t cid, const Container* container, bool h

msg.addByte(cid);

msg.addItem(container, isOTCv8);
msg.addItem(container);
msg.addString(container->getName());

msg.addByte(static_cast<uint8_t>(container->capacity()));
Expand All @@ -1572,7 +1559,7 @@ void ProtocolGame::sendContainer(uint8_t cid, const Container* container, bool h
const ItemDeque& itemList = container->getItemList();
for (ItemDeque::const_iterator cit = itemList.begin() + firstIndex, end = itemList.end(); i < 0xFF && cit != end;
++cit, ++i) {
msg.addItem(*cit, isOTCv8);
msg.addItem(*cit);
}
writeToOutputBuffer(msg);
}
Expand Down Expand Up @@ -1674,7 +1661,7 @@ void ProtocolGame::sendSaleItemList(const std::list<ShopInfo>& shop)

uint8_t i = 0;
for (std::map<uint16_t, uint32_t>::const_iterator it = saleMap.begin(); i < itemsToSend; ++it, ++i) {
msg.addItemId(it->first, isOTCv8);
msg.addItemId(it->first);
msg.addByte(static_cast<uint8_t>(std::min<uint32_t>(it->second, std::numeric_limits<uint8_t>::max())));
}

Expand Down Expand Up @@ -1711,11 +1698,11 @@ void ProtocolGame::sendTradeItemRequest(std::string_view traderName, const Item*

msg.addByte(itemList.size());
for (const Item* listItem : itemList) {
msg.addItem(listItem, isOTCv8);
msg.addItem(listItem);
}
} else {
msg.addByte(0x01);
msg.addItem(item, isOTCv8);
msg.addItem(item);
}
writeToOutputBuffer(msg);
}
Expand Down Expand Up @@ -1947,7 +1934,7 @@ void ProtocolGame::sendAddTileItem(const Position& pos, uint32_t stackpos, const
msg.addByte(0x6A);
msg.addPosition(pos);
msg.addByte(static_cast<uint8_t>(stackpos));
msg.addItem(item, isOTCv8);
msg.addItem(item);
writeToOutputBuffer(msg);
}

Expand All @@ -1961,7 +1948,7 @@ void ProtocolGame::sendUpdateTileItem(const Position& pos, uint32_t stackpos, co
msg.addByte(0x6B);
msg.addPosition(pos);
msg.addByte(static_cast<uint8_t>(stackpos));
msg.addItem(item, isOTCv8);
msg.addItem(item);
writeToOutputBuffer(msg);
}

Expand Down Expand Up @@ -2169,7 +2156,7 @@ void ProtocolGame::sendInventoryItem(slots_t slot, const Item* item)
if (item) {
msg.addByte(0x78);
msg.addByte(slot);
msg.addItem(item, isOTCv8);
msg.addItem(item);
} else {
msg.addByte(0x79);
msg.addByte(slot);
Expand All @@ -2179,10 +2166,6 @@ void ProtocolGame::sendInventoryItem(slots_t slot, const Item* item)

void ProtocolGame::sendModalWindow(const ModalWindow& modalWindow)
{
if (isOTCv8) {
return;
}

NetworkMessage msg;
msg.addByte(0xFA);

Expand Down Expand Up @@ -2214,7 +2197,7 @@ void ProtocolGame::sendAddContainerItem(uint8_t cid, const Item* item)
NetworkMessage msg;
msg.addByte(0x70);
msg.addByte(cid);
msg.addItem(item, isOTCv8);
msg.addItem(item);
writeToOutputBuffer(msg);
}

Expand All @@ -2224,7 +2207,7 @@ void ProtocolGame::sendUpdateContainerItem(uint8_t cid, uint16_t slot, const Ite
msg.addByte(0x71);
msg.addByte(cid);
msg.addByte(slot);
msg.addItem(item, isOTCv8);
msg.addItem(item);
writeToOutputBuffer(msg);
}

Expand All @@ -2242,7 +2225,7 @@ void ProtocolGame::sendTextWindow(uint32_t windowTextId, Item* item, uint16_t ma
NetworkMessage msg;
msg.addByte(0x96);
msg.add<uint32_t>(windowTextId);
msg.addItem(item, isOTCv8);
msg.addItem(item);

if (canWrite) {
msg.add<uint16_t>(maxlen);
Expand Down Expand Up @@ -2275,7 +2258,7 @@ void ProtocolGame::sendTextWindow(uint32_t windowTextId, uint16_t itemId, std::s
NetworkMessage msg;
msg.addByte(0x96);
msg.add<uint32_t>(windowTextId);
msg.addItem(itemId, 1, isOTCv8);
msg.addItem(itemId, 1);
msg.add<uint16_t>(text.size());
msg.addString(text);
msg.add<uint16_t>(0x00);
Expand Down Expand Up @@ -2350,21 +2333,6 @@ void ProtocolGame::sendOutfitWindow()
msg.addByte(outfit.addons);
}

if (isOTCv8) {
std::vector<const Mount*> mounts;
for (const Mount& mount : g_game.mounts.getMounts()) {
if (player->hasMount(&mount)) {
mounts.push_back(&mount);
}
}

msg.addByte(mounts.size());
for (const Mount* mount : mounts) {
msg.add<uint16_t>(mount->clientId);
msg.addString(mount->name);
}
}

writeToOutputBuffer(msg);
}

Expand Down Expand Up @@ -2501,10 +2469,6 @@ void ProtocolGame::AddPlayerSkills(NetworkMessage& msg)
void ProtocolGame::AddOutfit(NetworkMessage& msg, const Outfit_t& outfit)
{
uint16_t lookType = outfit.lookType;
if (isOTCv8 && lookType >= 367) {
lookType = 128;
}

msg.add<uint16_t>(lookType);

if (lookType != 0) {
Expand All @@ -2514,11 +2478,7 @@ void ProtocolGame::AddOutfit(NetworkMessage& msg, const Outfit_t& outfit)
msg.addByte(outfit.lookFeet);
msg.addByte(outfit.lookAddons);
} else {
msg.addItemId(outfit.lookTypeEx, isOTCv8);
}

if (isOTCv8) {
msg.add<uint16_t>(outfit.lookMount);
msg.addItemId(outfit.lookTypeEx);
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/protocolgame.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,9 @@ class ProtocolGame final : public Protocol
uint32_t eventConnect = 0;
uint32_t challengeTimestamp = 0;
uint16_t version = CLIENT_VERSION_MIN;
uint16_t OTCv8 = 0;

uint8_t challengeRandom = 0;

bool isOTCv8 = false;
bool debugAssertSent = false;
bool acceptPackets = false;
};
Expand Down

0 comments on commit 324c47b

Please sign in to comment.