MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / ServerHandleMapRequest

Method ServerHandleMapRequest

src/openrct2/network/NetworkBase.cpp:2615–2671  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2613 }
2614
2615 void NetworkBase::ServerHandleMapRequest(Connection& connection, Packet& packet)
2616 {
2617 uint32_t size;
2618 packet >> size;
2619 LOG_VERBOSE("Client requested %u objects", size);
2620 auto& repo = GetContext().GetObjectRepository();
2621 for (uint32_t i = 0; i < size; i++)
2622 {
2623 uint8_t generation{};
2624 packet >> generation;
2625
2626 std::string objectName;
2627 const ObjectRepositoryItem* item{};
2628 if (generation == static_cast<uint8_t>(ObjectGeneration::DAT))
2629 {
2630 const auto* entry = reinterpret_cast<const RCTObjectEntry*>(packet.read(sizeof(RCTObjectEntry)));
2631 if (entry == nullptr)
2632 break;
2633
2634 objectName = std::string(entry->GetName());
2635 LOG_VERBOSE("Client requested object %s", objectName.c_str());
2636 item = repo.FindObject(entry);
2637 }
2638 else
2639 {
2640 auto name = packet.readString();
2641 if (name.empty())
2642 break;
2643
2644 objectName = std::string(name);
2645 LOG_VERBOSE("Client requested object %s", objectName.c_str());
2646 item = repo.FindObject(objectName);
2647 }
2648
2649 if (item == nullptr)
2650 {
2651 LOG_WARNING("Client tried getting non-existent object %s from us.", objectName.c_str());
2652 }
2653 else
2654 {
2655 connection.requestedObjects.push_back(item);
2656 }
2657 }
2658
2659 if (connection.player == nullptr)
2660 {
2661 LOG_WARNING(
2662 "Connection %s requested map but has no player, disconnecting.", connection.socket->GetIpAddress().c_str());
2663 connection.disconnect();
2664 return;
2665 }
2666
2667 auto player_name = connection.player->name.c_str();
2668 ServerSendMap(&connection);
2669 ServerSendEventPlayerJoined(player_name);
2670 ServerSendGroupList(connection);
2671 }
2672

Callers 1

TEST_FFunction · 0.80

Calls 9

GetContextFunction · 0.85
FindObjectMethod · 0.80
disconnectMethod · 0.80
readMethod · 0.45
GetNameMethod · 0.45
readStringMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45
GetIpAddressMethod · 0.45

Tested by 1

TEST_FFunction · 0.64