Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ include_directories(PUBLIC ${CMAKE_SOURCE_DIR}/ExternalLibraries)
add_subdirectory(Common)
add_subdirectory(AuthServer)
add_subdirectory(CastServer)
add_subdirectory(MainServer)
add_subdirectory(MainServer)
4 changes: 2 additions & 2 deletions MainServer/include/Handlers/Item/GeneralItemHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace Main
const auto& userItems = session->getPlayer().getItems();
if (auto it = userItems.find(boxData.serialInfo.itemNumber); it != userItems.end())
{
const Main::Structures::Item& boxItem = it->second;
const Main::Structures::Item boxItem = it->second;

if (auto callbackIt = generalItemCallbacks.find(boxItem.itemId.itemId); callbackIt != generalItemCallbacks.end())
{ // "normal" general item, e.g. K/D reset, battery
Expand All @@ -80,11 +80,11 @@ namespace Main
{
if (auto callbackIt = cashItemCallbacks.find(currentWonItemId); callbackIt != cashItemCallbacks.end())
{ // cash item: mp/coin/coupon
callbackIt->second(session);
if (!session->deleteItem(boxItem.serialInfo, "The item was deleted after being used (example: MP/coin/coupon items"))
{
session->sendMessage("Debug) Error while deleting opened cash item");
}
callbackIt->second(session);
}
else
{ // normal won item
Expand Down
2 changes: 2 additions & 0 deletions MainServer/include/Handlers/Room/MatchLeaveHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ namespace Main
room->setStateFor(uniqueId, Common::Enums::STATE_WAITING);
}
}

session->flushPendingFriendRequests();
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions MainServer/include/Network/MainSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,12 @@ namespace Main

void acceptFriendRequest(std::shared_ptr<Main::Network::Session> senderSession, const Main::Structures::Friend& target, const std::uint8_t* const data);

void flushPendingFriendRequests();

bool removeBossBattleTicket();

private:
std::vector<Main::Structures::Friend> m_pendingFriendRequestsQueue{};
void handleOfflineFriendRequest(const AccountInfo& accountInfo, const char* nickname);
void handleOnlineFriendRequest(std::shared_ptr<Main::Network::Session> targetSession, const AccountInfo& accountInfo);

Expand Down
23 changes: 22 additions & 1 deletion MainServer/src/Network/MainSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,28 @@ namespace Main
Main::Structures::Friend friendStruct{ accountInfo.uniqueId, accountInfo.accountID };
std::memcpy(friendStruct.targetNickname, m_player.getPlayerName(), 16);
m_packet.setData(reinterpret_cast<std::uint8_t*>(&friendStruct), sizeof(friendStruct));
targetSession->asyncWrite(m_packet);

if (targetSession->getPlayer().isInMatch())
{
targetSession->m_pendingFriendRequestsQueue.push_back(friendStruct);
}
else
{
targetSession->asyncWrite(m_packet);
}
}

void Session::flushPendingFriendRequests()
{
if (m_pendingFriendRequestsQueue.empty()) return;
m_packet.setTcpHeader(m_id, Common::Enums::NO_ENCRYPTION);
m_packet.setCommand(61, 0, Main::Enums::AddFriendServerExtra::SEND_REQUEST_TO_TARGET, 2);
for (auto& friendStruct : m_pendingFriendRequestsQueue)
{
m_packet.setData(reinterpret_cast<std::uint8_t*>(&friendStruct), sizeof(friendStruct));
asyncWrite(m_packet);
}
m_pendingFriendRequestsQueue.clear();
}

bool Session::removeBossBattleTicket()
Expand Down